-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbundle-angular-app-cli.js
More file actions
101 lines (88 loc) · 3.32 KB
/
bundle-angular-app-cli.js
File metadata and controls
101 lines (88 loc) · 3.32 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
/**
* To update the @wavemaker/app-ng-runtime package.json version
* Add the dependency of @wavemaker/app-ng-runtime in package.json file
* Update the TS config and TS config web app json with package version
*
* CONSOLE ARGUMENTS:-
* publishVersion: To generate the given version package.json file
*/
'use strict';
import fs from 'fs';
import yargs from "yargs";
import { hideBin } from "yargs/helpers";
const argv = yargs(hideBin(process.argv))
.options({
publishVersion: { type: "string" }
})
.argv;
const DEBUG_LOG = 'ANGULAR-APP: ';
/**
* To update the wavemaker version in package.json
*/
const updateWMVersion = (path, wmPackageJSON) => {
wmPackageJSON.version = argv.publishVersion;
fs.writeFileSync(path, JSON.stringify(wmPackageJSON, null, 4));
console.log(`${DEBUG_LOG} Updated package.json wm:${argv.publishVersion} for publishing to npm`);
};
/**
* To add the app-ng-runtime package as dependency in angular app package.json
*/
const addWMDependency = async () => {
const path = './dist/runtime-cli/angular-app/package.json';
const packageJSON = JSON.parse(fs.readFileSync(path, 'utf8'));
packageJSON.version = argv.publishVersion;
packageJSON["files"] = [];
packageJSON["files"].push("**/*");
packageJSON["files"].push(".npmrc");
packageJSON['dependencies']['@wavemaker/app-ng-runtime'] = argv.publishVersion;
packageJSON['dependencies']['@wavemaker/variables'] = argv.publishVersion;
console.log(`${DEBUG_LOG} Added @wavemaker/app-ng-runtime@${argv.publishVersion}, @wavemaker/variables@${argv.publishVersion} dependency to angular app`);
fs.writeFileSync(path, JSON.stringify(packageJSON, null, 4));
};
/**
* To replace the libraries with node_modules path in angular.json
* @param {*} wm_pkg_name ng runtime pm package name @wavemaker/app-ng-runtime
*/
const updateAngularJSON = async (wm_pkg_name) => {
const path = './dist/runtime-cli/angular-app/angular.json';
const json = JSON.parse(fs.readFileSync(path, 'utf8'));
const scripts = json['projects']['angular-app']['architect']['build']['options']['scripts'];
scripts.forEach((v, i) => {
if (v.startsWith('./libraries/')) {
scripts[i] = v.replace('./libraries/', `./node_modules/${wm_pkg_name}/`);
}
});
fs.writeFileSync(path, JSON.stringify(json, null, 4));
};
/**
* To update the app-ng-runtime package in TS config
* @param {*} path TS Config path
* @param {*} wm_pkg_name ng runtime pm package name @wavemaker/app-ng-runtime
*/
const updateTSConfig = async (path, wm_pkg_name) => {
const json = JSON.parse(fs.readFileSync(path, 'utf8'));
const paths = json['compilerOptions']['paths'];
for (let key in paths) {
const pathRefs = paths[key];
pathRefs.forEach((v, i) => {
if (v.startsWith('libraries/')) {
pathRefs[i] = v.replace('libraries/', `node_modules/${wm_pkg_name}/`);
}
});
}
fs.writeFileSync(path, JSON.stringify(json, null, 4));
};
/**
* Update the wavemaker version
* Add wavemaker dependency
* Update packagename and version in the angular.json
* Update TS config with package name
*/
const init = async () => {
const wm_pkg_name = '@wavemaker/app-ng-runtime';
await addWMDependency();
await updateAngularJSON(wm_pkg_name);
await updateTSConfig('./dist/runtime-cli/angular-app/tsconfig.json', wm_pkg_name);
await updateTSConfig('./dist/runtime-cli/angular-app/tsconfig.web-app.json', wm_pkg_name);
};
init();