forked from SAP/spartacus
-
Notifications
You must be signed in to change notification settings - Fork 0
/
configure-shellapp.js
118 lines (104 loc) · 3.15 KB
/
configure-shellapp.js
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
/**
* This script is used by generate-shellapp.sh to
* update the storefrontshellapp's configuration once all
* files are copied to the dist folder.
*/
let filesystem = require('fs');
main();
/****************
* Functions *
****************/
function main() {
const shellappPath =
process.argv.slice(2)[0] || './dist/storefrontshellapp/storefrontapp';
const configurationJsonData = filesystem.readFileSync(
`./configure-shellapp.json`
);
const configurationData = JSON.parse(configurationJsonData);
updateAngularJsonFile(shellappPath);
updateTsconfigJsonFile(shellappPath + '/tsconfig.json');
updateTsconfigJsonFile(
shellappPath + '/projects/storefrontapp/tsconfig.app.prod.json'
);
updatePackageJsonFile(shellappPath, configurationData);
}
function updateAngularJsonFile(shellappPath) {
const angularJsonPath = `${shellappPath}/angular.json`;
console.log(`Updating ${angularJsonPath}`);
//Modify the copied angular.json file
const angularJsonDistFile = filesystem.readFileSync(angularJsonPath);
const AngularJsonDistData = JSON.parse(angularJsonDistFile);
const storefrontAppConfig = {
storefrontapp: AngularJsonDistData.projects.storefrontapp
};
console.log(` Removing all projects except "storefrontapp".`);
AngularJsonDistData['projects'] = {};
AngularJsonDistData.projects = storefrontAppConfig;
//Save changes to the copied Angular.json file
filesystem.writeFileSync(
angularJsonPath,
JSON.stringify(AngularJsonDistData, null, 2),
err => {
if (err) {
return console.error(err);
}
console.log(`Done.`);
}
);
}
function updateTsconfigJsonFile(tsConfigPath) {
console.log(`Updating ${tsConfigPath}`);
//Get the json from the tsconfig.file
const file = filesystem.readFileSync(tsConfigPath);
const tsConfigData = JSON.parse(file);
console.log(` Removing "paths".`);
//apply modifications to the tsconfig.json
delete tsConfigData.compilerOptions['paths'];
//save modification
filesystem.writeFileSync(
tsConfigPath,
JSON.stringify(tsConfigData, null, 2),
err => {
if (err) {
return console.error(err);
}
console.log(`Done.`);
}
);
}
function updatePackageJsonFile(shellappPath, configurationData) {
const packageJsonPath = `${shellappPath}/package.json`;
console.log(`Updating ${packageJsonPath}`);
//Get the package.json data
const packageJsonFile = filesystem.readFileSync(packageJsonPath);
const packageJsonData = JSON.parse(packageJsonFile);
console.log(
' Adding dependencies: ',
configurationData.package_json.dependencies
);
// SPA-1289
// packageJsonData.dependencies = {
// ...configurationData.package_json.dependencies,
// ...packageJsonData.dependencies
// };
packageJsonData.scripts = {
// setting default package.json scripts
ng: 'ng',
start: 'ng serve',
build: 'ng build',
test: 'ng test',
lint: 'ng lint',
e2e: 'ng e2e'
};
//save modification
filesystem.writeFileSync(
packageJsonPath,
JSON.stringify(packageJsonData, null, 2),
err => {
if (err) {
return console.error(err);
}
console.log(`Done.`);
}
);
}