/
update-6-1-6.ts
103 lines (93 loc) · 3.42 KB
/
update-6-1-6.ts
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
import {
chain,
Rule,
SchematicContext,
Tree
} from '@angular-devkit/schematics';
import { join } from 'path';
import * as fs from 'fs';
import {
getJsonFromFile,
updateJsonFile,
createOrUpdate
} from '@nstudio/xplat';
function updateNativeScriptApps(tree: Tree, context: SchematicContext) {
const appsDir = tree.getDir('apps');
const appFolders = appsDir.subdirs;
const cwd = process.cwd();
const webpackConfigPath = join(
cwd,
'node_modules/@nstudio/schematics/src/app.nativescript/_files/webpack.config.js'
);
// console.log('webpackConfigPath:', webpackConfigPath);
const webpackConfig = fs.readFileSync(webpackConfigPath, 'UTF-8');
// console.log('webpackConfig:',webpackConfig);
const ngAppFactoryPath = join(
cwd,
'node_modules/@nstudio/schematics/src/app.nativescript/_files/app/app.module.ngfactory.d.ts'
);
// console.log('webpackConfigPath:', webpackConfigPath);
const ngAppFactory = fs.readFileSync(ngAppFactoryPath, 'UTF-8');
// update {N} apps and configs
for (const dir of appFolders) {
// console.log(dir);
if (dir.indexOf('nativescript-') === 0) {
const appDir = `${appsDir.path}/${dir}`;
// console.log('appDir:', appDir);
createOrUpdate(tree, `${appDir}/webpack.config.js`, webpackConfig);
createOrUpdate(
tree,
`${appDir}/app/app.module.ngfactory.d.ts`,
ngAppFactory
);
// update {N} app deps
const packagePath = `${appDir}/package.json`;
const packageJson = getJsonFromFile(tree, packagePath);
if (packageJson) {
packageJson.dependencies = packageJson.dependencies || {};
packageJson.devDependencies = packageJson.devDependencies || {};
packageJson.devDependencies = {
...packageJson.devDependencies,
'@angular/compiler-cli':
'file:../../node_modules/@angular/compiler-cli',
'@angular/language-service':
'file:../../node_modules/@angular/language-service',
'@ngtools/webpack': '6.1.0-beta.1',
'babel-traverse': '6.26.0',
'babel-types': '6.26.0',
babylon: '6.18.0',
'clean-webpack-plugin': '~0.1.19',
codelyzer: 'file:../../node_modules/codelyzer',
'copy-webpack-plugin': '~4.5.1',
'css-loader': '~0.28.11',
'extract-text-webpack-plugin': '~3.0.2',
lazy: '1.0.11',
'nativescript-css-loader': '~0.26.0',
'nativescript-dev-typescript': '~0.7.1',
'nativescript-dev-webpack': '~0.14.1',
'nativescript-worker-loader': '~0.9.0',
'raw-loader': '~0.5.1',
'resolve-url-loader': '~2.3.0',
'sass-loader': '^7.0.2',
'tns-platform-declarations':
'file:../../node_modules/tns-platform-declarations',
typescript: 'file:../../node_modules/typescript',
'uglifyjs-webpack-plugin': '~1.2.5',
webpack: '~4.12.0',
'webpack-bundle-analyzer': '~2.13.0',
'webpack-cli': '~3.0.7',
'webpack-sources': '~1.1.0'
};
// ensure dev sass is removed
delete packageJson.devDependencies['nativescript-dev-sass'];
// console.log('path:',path);
// console.log('packageJson overwrite:', JSON.stringify(packageJson));
tree = updateJsonFile(tree, packagePath, packageJson);
}
}
}
return tree;
}
export default function(): Rule {
return chain([updateNativeScriptApps]);
}