Repository navigation
Expand file tree
/
Copy pathbuild.update.js
More file actions
240 lines (192 loc) · 10.4 KB
/
Copy pathbuild.update.js
File metadata and controls
240 lines (192 loc) · 10.4 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
"use strict";
require('shelljs/global');
const fs = require('fs');
const path = require('path');
const colors = require('colors');
const clim = require('clim');
const cons = clim();
const utils = require('./build.utils.js');
const prompt = require('prompt');
let lib = false;
let useVersion = null;
let cliVersion = null;
let includeLib = false;
let hasWarning = false;
let dynamicRoutes = false;
let validateEntry = function (value) {
if (value === 'true' ||
value === true ||
value === 'lazy' ||
value === 'Y' ||
value === 'y' ||
value === 'YES' ||
value === 'yes') {
return true;
} else {
return false;
}
};
/* Test for arguments the ngr cli spits out */
process.argv.forEach((arg) => {
if (arg.includes('version')) {
useVersion = arg.toString().split('=')[1];
}
if (arg.includes('cliVersion')) {
console.log(arg.toString());
cliVersion = arg.toString().split('=')[1];
}
if (arg.includes('lib')) {
includeLib = arg.toString().split('=')[1];
}
if (arg.includes('dynamicRoutes')) {
dynamicRoutes = arg.toString().split('=')[1];
}
});
/*
Copy Tasks
- file: Copies a file to /dist
*/
const copy = {
file: (filePath, fileName, force) => {
if (fs.existsSync(utils.config.projectRoot +'/'+ filePath) && force !== true) {
utils.warn(filePath + ' already exists');
hasWarning = true;
} else {
cp(utils.config.cliRoot + '/' + filePath, utils.config.projectRoot + '/' + filePath);
utils.log(fileName, 'copied to', path.dirname(process.cwd()) + '/' + path.basename(process.cwd()) + '/');
}
},
newFile: (p) => {
if (fs.existsSync(path.dirname(process.cwd()) + '/' + path.basename(process.cwd()) + '/' + p.split('/')[p.split('/').length - 1])) {
utils.warn(p.split('/')[p.split('/').length - 1] + ' already exists');
hasWarning = true;
} else {
cp('-R', p, path.dirname(process.cwd()) + '/' + path.basename(process.cwd()) + '/');
utils.log(p.split('/')[p.split('/').length - 1], 'copied to', path.dirname(process.cwd()) + '/' + path.basename(process.cwd()) + '/');
}
}
};
let init = function () {
if (includeLib) {
cp('-R', utils.config.cliRoot + '/src/lib/', utils.config.projectRoot + '/src');
}
if (dynamicRoutes) {
utils.console.warn(utils.colors.red('Update to dynamic routing will overwrite existing files'));
utils.console.log('It is recommended to backup lazy.config.json, app.routes.ts, and app.module.ts prior to update');
prompt.message = '';
prompt.start();
prompt.get(['Are you sure?'], function (err, result) {
if (validateEntry(result['Are you sure?'])) {
if (fs.existsSync(utils.config.projectRoot + '/src/app/app.config.ts')) {
rm(utils.config.projectRoot + '/src/app/app.config.ts');
}
if (fs.existsSync(utils.config.projectRoot + '/lazy.config.json')) {
rm(utils.config.projectRoot + '/lazy.config.json');
}
if (fs.existsSync(utils.config.projectRoot + '/src/app/app.routes.ts')) {
rm(utils.config.projectRoot + '/src/app/app.routes.ts');
}
rm(utils.config.projectRoot + '/src/app/app.module.ts');
cp(utils.config.cliRoot + '/lazy.routes.config.json', utils.config.projectRoot + '/lazy.config.json');
cp(utils.config.cliRoot + '/src-dynamic-route/app/app.routes.ts', utils.config.projectRoot + '/src/app/app.routes.ts');
cp(utils.config.cliRoot + '/src-dynamic-route/app/app.config.ts', utils.config.projectRoot + '/src/app/app.config.ts');
cp(utils.config.cliRoot + '/src-dynamic-route/app/app.module.ts', utils.config.projectRoot + '/src/app/app.module.ts');
utils.console.log('routes updated to support dynamic config');
}
});
}
if (cliVersion) {
utils.log('Review changes to angular-rollup in the CHANGELOG (https://github.com/steveblue/angular2-rollup/blob/master/CHANGELOG.md)');
if (cliVersion === '1.0.0-beta.10') {
copy.file('lazy.config.json', 'lazy.config.json');
copy.file('src/public/system.polyfill.js', 'system.polyfill.js');
copy.file('src/public/system.import.js', 'system.import.js');
copy.file('src/public/system.config.prod.js', 'system.config.prod.js');
copy.file('src/public/index.html', 'index.html');
if (hasWarning) {
utils.warn('Please move or delete existing files to prevent overwiting. Use a diff tool to track project specific changes.');
return;
}
}
}
if (useVersion === '5.0.0') {
copy.file('karma-test-shim.js', 'karma-test-shim.js', true);
utils.warn('ngr overwrote karma-test-shim.js');
copy.file('karma.conf.js', 'karma.conf.js', true);
utils.warn('ngr overwrote karma.conf.js');
rm(utils.config.projectRoot + '/tsconfig.prod.lazy.json');
utils.warn('ngr deleted tsconfig.prod.lazy.json because it is not needed anymore');
rm(utils.config.projectRoot + '/main.prod.ts');
utils.warn('ngr deleted main.prod.ts because it is not needed anymore, please remove main.prod.ts from any tsconfig');
}
if (!useVersion) {
return;
}
fs.readFile(path.dirname(process.cwd()) + '/' + path.basename(process.cwd()) + '/package.json', (err, script) => {
if (err) throw err;
script = JSON.parse(script);
Object.keys(script.dependencies).forEach((dep) => {
if (dep.includes('@angular')) {
script.dependencies[dep] = useVersion;
}
});
Object.keys(script.devDependencies).forEach((dep) => {
if (dep.includes('@angular')) {
script.devDependencies[dep] = useVersion;
}
});
if (useVersion === '5.0.0') {
script['scripts']['bundle:closure'] = 'java -jar node_modules/google-closure-compiler/compiler.jar --warning_level=QUIET --flagfile closure.conf --js_output_file ./build/bundle.js --output_manifest=closure/manifest.MF';
script.dependencies['core-js'] = '^2.5.1';
script.dependencies['zone.js'] = '^0.8.18';
script.devDependencies.typescript = '2.4.2';
script.devDependencies.tslib = '^1.6.1';
script.devDependencies['@types/jasmine'] = '^2.6.3';
script.devDependencies['@types/karma'] = '^1.7.1';
script.devDependencies['jasmine-core'] = '^2.8.0';
script.devDependencies['jasmine-spec-reporter'] = '^4.2.0';
script.devDependencies['karma-remap-coverage'] = '^0.1.4';
script.devDependencies['karma-coverage'] = '^1.1.1';
script.devDependencies['karma-jasmine-html-reporter'] = '^0.2.2';
script.devDependencies['karma-chrome-launcher'] = '^2.2.0';
script.devDependencies['karma-jasmine'] = '^1.1.0';
script.devDependencies['google-closure-compiler'] = 'git+https://github.com/gregmagolan/closure-compiler.git#20170919.angular.dist';
delete script.devDependencies['google-closure-compiler-js'];
script.dependencies.rxjs = '^5.5.2';
}
// script['main'] = './main.electron.js',
// script['scripts'].electron = 'electron ./main.electron.js';
fs.writeFile(path.dirname(process.cwd()) + '/' + path.basename(process.cwd()) + '/package.json', JSON.stringify(script, null, 4), function (err) {
if (err) log(err);
if (useVersion === '5.0.0') {
utils.alert('AOT in watch mode is now the default dev environment');
utils.alert('Remove any deprecated properties in tslint.json');
utils.alert('If you have any lazyloaded modules listed in the files array of tsconfig.prod.json, migrate them to tsconfig.dev.json');
utils.alert('If you have any lazyloaded modules, you need to update thier mappings in src/public/system.config.js');
utils.alert('Http will be deprecated in Angular 6.0.0, migrate all instances of Http to HttpClient in your app and add "tslib/tslib.js" to build.config.js');
utils.alert('RxJs has been updated to 5.5.2, please update your app accordingly. Please change the mappings in system.config.js to something like below:');
utils.alert("\n// other libraries \n"+
"'rxjs/Observable': 'lib:rxjs/Observable', \n"+
"'rxjs/observable/merge': 'lib:rxjs/observable/merge', \n"+
"'rxjs/Subject': 'lib:rxjs/Subject', \n"+
"'rxjs/BehaviorSubject': 'lib:rxjs/BehaviorSubject', \n"+
"'rxjs/Subscription': 'lib:rxjs/Subscription', \n"+
"'rxjs/Observer': 'lib:rxjs/Observer', \n"+
"'rxjs/operators': 'lib:rxjs/operators/index.js', \n"+
"'rxjs/operator': 'lib:rxjs/operator', \n"+
"'rxjs/add/operator': 'lib:rxjs/add/operator', \n"+
"'rxjs/add/operators': 'lib:rxjs/operators/index.js', \n"+
"'rxjs/util/EmptyError': 'lib:rxjs/util/EmptyError', \n"+
"'tslib': 'lib:tslib/tslib.js'");
utils.alert('closure.conf and closure.lazy.conf must be updated to support --package_json_entry_names');
utils.alert('For an example closure.conf visit https://gist.github.com/steveblue/4ab4c826793b9a395e8751489c6f606e');
utils.alert('For an example closure.lazy.conf visit https://gist.github.com/steveblue/60cbb7faf58249dd8da5788409205cea')
utils.alert('For more information, read the official blog post about Angular 5.0.0 https://blog.angular.io/version-5-0-0-of-angular-now-available-37e414935ced');
utils.alert('Use the Angular Update Guide for more help updating to 5.0.0 https://angular-update-guide.firebaseapp.com');
}
utils.alert('ngr updated ' + colors.bold(colors.red('@angular')), '=> ' + colors.bold(colors.white(useVersion)));
utils.alert('run npm install or yarn install');
});
});
};
init();