@wavemaker/angular-codegen 11.10.0-next.25079 → 11.10.0-next.27705

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,9 +1,12 @@
1
- import "jest-preset-angular/setup-jest";
1
+ // This file is automatically loaded when running `jest` commands
2
+ import { setupZoneTestEnv } from 'jest-preset-angular/setup-env/zone';
2
3
  import { ToastrModule } from 'ngx-toastr';
3
4
  import { TestBed } from '@angular/core/testing';
4
5
  import _ from 'lodash-es';
5
6
  import 'jest-canvas-mock';
6
7
 
8
+ setupZoneTestEnv();
9
+
7
10
  // Mock global objects if necessary
8
11
  global.jQuery = require("jquery");
9
12
  global.$ = global.jQuery;
@@ -13,13 +13,24 @@
13
13
  * optimizeUIBuild : By default this flag will be true. If it's windows platform we are making the flag to false, it means no optimisation for windows.
14
14
  */
15
15
  const fs = require('fs');
16
+ const rimraf = require('rimraf');
16
17
  const { downloadNPMPackage } = require('./download-packages');
18
+ const { generateRandomHash } = require('./src/wm-utils');
17
19
  const archiver = require('archiver');
18
20
  const path = require("path");
19
21
  const { executeSyncCmd, MSG_NG_RUNTIME_LOG, MSG_NG_RUNTIME_SUCCESS } = require('./build-util');
20
22
  const os = require("os");
23
+ const cheerio = require(`cheerio`);
21
24
 
22
25
  const NPM_PACKAGE_SCOPE = '@wavemaker';
26
+ const BUILD_TYPE = { WM: 'wm', ANGULAR: 'angular' };
27
+
28
+ const UI_BUILD_ERROR_LOG = 'UI BUILD ERROR';
29
+ const MSG_CODEGEN_LOG = 'CODEGEN ANGULAR APP: ';
30
+ const MSG_APP_RUNTIME_WM_BUILD_LOG = 'APP RUNTIME WM BUILD : ';
31
+ const MSG_APP_RUNTIME_WM_BUILD_SUCCESS = 'WAVEMAKER_APP_RUNTIME_WM_BUILD_SUCCESS';
32
+
33
+ const ANGULAR_APP_TEMPLATE_NAME = "angular-app";
23
34
 
24
35
  /**
25
36
  * @TODO: This is a temporary workaround to extract deploy-url from 'ngBuildParams', need to be replaced in future.
@@ -28,11 +39,11 @@ const updateDeployUrl = (args) => {
28
39
  let buildArgs = args.ngBuildParams.split(' ');
29
40
  const deployParam = buildArgs.find(i => i.startsWith("--deploy-url="));
30
41
  if(!deployParam) {
31
- buildArgs.push("--deploy-url=ng-bundle/");
42
+ buildArgs.push(`--deploy-url=ng-bundle/${global.randomHash}/`);
32
43
  } else {
33
44
  buildArgs.filter((param, index) => {
34
45
  if (param.includes('--deploy-url=_cdnUrl_')) {
35
- buildArgs[index] = "--deploy-url=_cdnUrl_/ng-bundle/"
46
+ buildArgs[index] = `--deploy-url=_cdnUrl_/ng-bundle/${global.randomHash}/`
36
47
  return true;
37
48
  }
38
49
  });
@@ -40,6 +51,52 @@ const updateDeployUrl = (args) => {
40
51
  buildArgs.push(args.nodeVMArgs);
41
52
  return buildArgs.join(" ");
42
53
  };
54
+ /**
55
+ *
56
+ * @param sourcePath
57
+ * @param targetPath
58
+ * @param packageName
59
+ * @param isOptimized
60
+ */
61
+ const processAngularAppPackage = (sourcePath, targetPath, packageName, isOptimized) => {
62
+ const ANGULAR_APP_TARBALL_NAME = 'wavemaker' + '-' + ANGULAR_APP_TEMPLATE_NAME + '-' + global.buildConfigObj.runtimeUIVersion + '.tgz';
63
+ try {
64
+ // Download the package as a tarball
65
+ executeSyncCmd(
66
+ `cd ${sourcePath} && npm pack ${packageName}`,
67
+ (e) => { throw new Error(`Failed to download package: ${packageName}, Error: ${e}`); },
68
+ `Downloading tarball - ${packageName} to ${sourcePath}`
69
+ );
70
+ // Extract the tarball
71
+ executeSyncCmd(
72
+ `cd ${sourcePath} && tar -xvf ${ANGULAR_APP_TARBALL_NAME}`,
73
+ (e) => { throw new Error(`Failed to extract package: ${packageName}, Error: ${e}`); },
74
+ `Unzipping tarball - ${ANGULAR_APP_TARBALL_NAME}`
75
+ );
76
+
77
+ // Copy essential files
78
+ ['package.json', 'package-lock.json', '.npmrc'].forEach(file => {
79
+ fs.copyFileSync( path.join(sourcePath, 'package', file), path.join(targetPath, file) );
80
+ });
81
+
82
+ // Install dependencies
83
+ const installPath = isOptimized ? sourcePath : targetPath;
84
+ let npmCommnd = `npm install --prefix ${installPath}`
85
+ // For windows platforms, npm install command needs to be executed in the same directory as package.json file
86
+ if (os.platform() === 'win32') {
87
+ npmCommnd = `cd ${installPath} && ${npmCommnd}`
88
+ }
89
+ executeSyncCmd(
90
+ `${npmCommnd}`,
91
+ (e) => { throw new Error(`Failed to install dependencies: ${packageName}, Error: ${e}`); },
92
+ `Installing app dependencies to ${installPath}`
93
+ );
94
+ } catch (error) {
95
+ if (isOptimized) rimraf.sync(`${sourcePath}/node_modules`);
96
+ throw new Error(`Something went wrong : ${packageName}, Error: ${error}`);
97
+ }
98
+ };
99
+
43
100
 
44
101
  /**
45
102
  * Download the app runtime package
@@ -47,46 +104,37 @@ const updateDeployUrl = (args) => {
47
104
  * Run the ng build and post build for the project
48
105
  */
49
106
  const buildAngularApp = (args) => {
50
- const HOME_DIR = os.homedir(), ANGULAR_APP_TEMPLATE_NAME = "angular-app";
51
- const TARBALL_DOWNLOAD_PATH = (HOME_DIR + '/.wm/node_modules') + '/' + ANGULAR_APP_TEMPLATE_NAME + '/' + args.runtimeUIVersion;
52
- const PACKAGE_NAME = NPM_PACKAGE_SCOPE + '/' + ANGULAR_APP_TEMPLATE_NAME + '@' + args.runtimeUIVersion;
53
- const TARBALL_NAME = 'wavemaker' + '-' + ANGULAR_APP_TEMPLATE_NAME + '-' + args.runtimeUIVersion + '.tgz';
107
+ const HOME_DIR = os.homedir();
108
+ let TARBALL_DOWNLOAD_PATH = path.join((path.join(HOME_DIR, '.wm', 'node_modules')), ANGULAR_APP_TEMPLATE_NAME, args.runtimeUIVersion);
109
+ const PACKAGE_NAME = NPM_PACKAGE_SCOPE + '/' + ANGULAR_APP_TEMPLATE_NAME + '@' + global.buildConfigObj.runtimeUIVersion;
110
+ const SUCCESS_FILE = path.join(TARBALL_DOWNLOAD_PATH, ".SUCCESS");
54
111
 
55
- fs.mkdirSync(TARBALL_DOWNLOAD_PATH, { recursive: true });
56
- //npm pack will download the given package as a tar file
57
- executeSyncCmd('cd ' + TARBALL_DOWNLOAD_PATH + ` && npm pack ${PACKAGE_NAME}`, null, `Downloading tarball - ${PACKAGE_NAME} to the location - ${TARBALL_DOWNLOAD_PATH}`);
58
- executeSyncCmd('cd ' + TARBALL_DOWNLOAD_PATH + ` && tar -xvf ${TARBALL_NAME}`, null, `Unzipping the tarball - ${TARBALL_NAME}`);
112
+ //to handle windows build(optimizeUIBuild will be false for windows)
113
+ TARBALL_DOWNLOAD_PATH = args.optimizeUIBuild ? TARBALL_DOWNLOAD_PATH : args.appTarget;
114
+ const ANGULAR_APP_TARBALL_NAME = 'wavemaker' + '-' + ANGULAR_APP_TEMPLATE_NAME + '-' + global.buildConfigObj.runtimeUIVersion + '.tgz';
59
115
 
60
- let packageInfo = {
61
- scope: NPM_PACKAGE_SCOPE,
62
- name: ANGULAR_APP_TEMPLATE_NAME,
63
- version: args.runtimeUIVersion,
64
- packageJsonFile: `${TARBALL_DOWNLOAD_PATH}/package/package.json`,
65
- packageJsonLockFile: `${TARBALL_DOWNLOAD_PATH}/package/package-lock.json`,
66
- successMsg: MSG_NG_RUNTIME_SUCCESS,
67
- infoMsg: MSG_NG_RUNTIME_LOG
68
- }
116
+ fs.mkdirSync(TARBALL_DOWNLOAD_PATH, { recursive: true });
69
117
 
70
118
  try {
71
119
  if (args.optimizeUIBuild) {
72
- fs.copyFileSync(TARBALL_DOWNLOAD_PATH + `/package/package.json`, TARBALL_DOWNLOAD_PATH + '/package.json');
73
- fs.copyFileSync(TARBALL_DOWNLOAD_PATH + `/package/package-lock.json`, TARBALL_DOWNLOAD_PATH + '/package-lock.json');
74
- fs.copyFileSync(TARBALL_DOWNLOAD_PATH + `/package/.npmrc`, TARBALL_DOWNLOAD_PATH + '/.npmrc');
75
-
76
- // Download angular-app node_modules
77
- executeSyncCmd('cd ' + TARBALL_DOWNLOAD_PATH + ' && npm install --prefix ' + TARBALL_DOWNLOAD_PATH, null, "Installing app dependencies...");
78
-
79
- // Symlink to reuse the existing node_modules
80
- fs.symlinkSync(TARBALL_DOWNLOAD_PATH + `/node_modules`, args.appTarget + '/node_modules', 'dir');
120
+ if (!fs.existsSync(SUCCESS_FILE)) {
121
+ processAngularAppPackage(TARBALL_DOWNLOAD_PATH, TARBALL_DOWNLOAD_PATH, PACKAGE_NAME, true);
122
+ fs.writeFileSync(SUCCESS_FILE, "SUCCESS");
123
+ } else {
124
+ console.log(`node_modules for angular-app already installed - ${TARBALL_DOWNLOAD_PATH}`);
125
+ }
126
+ console.log(`Symlinking the node_modules to angular-app - ${args.appTarget}`);
127
+ fs.symlinkSync( `${TARBALL_DOWNLOAD_PATH}/node_modules`,`${args.appTarget}/node_modules`,'dir');
81
128
  } else {
82
- fs.copyFileSync(TARBALL_DOWNLOAD_PATH + `/package/package/package.json`, args.appTarget + '/package.json');
83
- fs.copyFileSync(TARBALL_DOWNLOAD_PATH + `/package/package-lock.json`, args.appTarget + '/package-lock.json');
84
- fs.copyFileSync(TARBALL_DOWNLOAD_PATH + `/package/.npmrc`, args.appTarget + '/.npmrc');
85
- executeSyncCmd('cd ' + args.appTarget + ` && npm install `, null, MSG_NG_RUNTIME_LOG);
129
+ processAngularAppPackage(TARBALL_DOWNLOAD_PATH, args.appTarget, PACKAGE_NAME, false);
86
130
  }
87
131
  } catch (err) {
88
- console.log(MSG_NG_RUNTIME_LOG + 'FAILED the symlink for the node_modules', err);
132
+ deleteFiles([SUCCESS_FILE])
133
+ console.log(MSG_NG_RUNTIME_LOG + 'Something went wrong - ', err);
89
134
  process.exit(err.code || err.pid);
135
+ } finally {
136
+ //cleanup : in windows / optimizeUIBuild is false, we need to delete the temp downloaded package
137
+ deleteFiles([path.join(TARBALL_DOWNLOAD_PATH, 'package'), path.join(TARBALL_DOWNLOAD_PATH, ANGULAR_APP_TARBALL_NAME)])
90
138
  }
91
139
 
92
140
  let ngBuildParams = updateDeployUrl(args);
@@ -95,6 +143,21 @@ const buildAngularApp = (args) => {
95
143
  executeSyncCmd('cd ' + args.appTarget + ' && node ./build-scripts/build.js ' + ngBuildParams, null, MSG_NG_RUNTIME_LOG, false, NG_BUILD_MSG);
96
144
  }
97
145
 
146
+ /**
147
+ *
148
+ */
149
+ const deleteFiles = (files) => {
150
+ files.forEach(file => {
151
+ try {
152
+ rimraf.sync(file);
153
+ console.log(`Successfully deleted file - ${file}`);
154
+ } catch (err) {
155
+ console.error(`Error while deleting file ${file}`, err);
156
+ throw new Error(`Error while deleting file: ${file}, Error: ${err}`);
157
+ }
158
+ });
159
+ }
160
+
98
161
  const generateUiZip = async( sourceDir ) => {
99
162
  return new Promise((resolve, reject) => {
100
163
  const distDir = path.resolve(sourceDir + '/target/ui-build/output-files');
@@ -117,7 +180,284 @@ const generateUiZip = async( sourceDir ) => {
117
180
  });
118
181
  }
119
182
 
183
+ const updateWarIndexHtml = async( sourceDir ) => {
184
+ const destDir = path.resolve(sourceDir + '/target/ui-build/output-files');
185
+ let indexHtml = fs.readFileSync(destDir + '/index.html', 'utf8');
186
+
187
+ const $ = cheerio.load(indexHtml);
188
+ const cdnMetaTag = $('meta[name="cdnUrl"]');
189
+ const cdnUrl = cdnMetaTag.length > 0 ? cdnMetaTag.attr('content') : `ng-bundle/${global.randomHash}/`;
190
+
191
+ $('*').each((_, element) => {
192
+ if (element.tagName === 'meta' && $(element).attr('name') === 'cdnUrl') {
193
+ $(element).attr('content', `ng-bundle/${global.randomHash}/`)
194
+ return;
195
+ }
196
+ const attributes = element.attribs;
197
+ for (const attrName in attributes) {
198
+ if (attributes[attrName].includes(cdnUrl)) {
199
+ attributes[attrName] = attributes[attrName].replace(cdnUrl, `_cdnUrl_/ng-bundle/${global.randomHash}/`);
200
+ }
201
+ }
202
+ });
203
+
204
+ const updatedHtml = $.html();
205
+ fs.writeFileSync(destDir + '/index.html', updatedHtml);
206
+ console.log(`✅ Updated index.html in the war file`);
207
+ }
208
+
209
+ /**
210
+ * sample obj param structure
211
+ * buildConfigObj = {
212
+ * runtimeUIVersion: args.runtimeUIVersion ,
213
+ * codegenPath: pathAngularCodegen,
214
+ * optimizeUIBuild: angularBuildConfig.optimizeUIBuild,
215
+ * appTarget: angularBuildConfig.appTarget,
216
+ * appSrc: angularBuildConfig.sourceDir,
217
+ * nodeVMArgs: args.nodeVMArgs,
218
+ * ngBuildParams: ngBuildParams
219
+ * }
220
+ * @param buildConfigObj
221
+ * @returns {Promise<void>}
222
+ */
223
+ const postBuild = async( buildConfigObj ) => {
224
+ console.log(`Running post build ops with the build config ${JSON.stringify(buildConfigObj)}`);
225
+ await generateUiZip(buildConfigObj.appSrc);
226
+ await updateWarIndexHtml(buildConfigObj.appSrc);
227
+ }
228
+
229
+ /**
230
+ * Read the console arguments and prepare the object.
231
+ * @returns console arguments as key value pairs
232
+ */
233
+ const getArgs = (customArgs) => {
234
+ const args = {};
235
+ let arguments = customArgs || process.argv;
236
+ arguments = customArgs ? customArgs : arguments.slice(2, arguments.length);
237
+ arguments.forEach(arg => {
238
+ if (arg.slice(0, 2) === '--') {
239
+ const longArg = arg.split('=');
240
+ const longArgFlag = longArg[0].slice(2, longArg[0].length);
241
+ let longArgValue = longArg.length > 2 ? longArg.slice(1, longArg.length).join('=') : longArg[1];
242
+ if (longArgFlag === "cdnUrl") {
243
+ longArgValue = longArgValue === "" ? "./" : longArgValue;
244
+ }
245
+ args[longArgFlag] = longArgValue;
246
+ }
247
+ });
248
+ return args;
249
+ }
250
+
251
+ /**
252
+ * Copy source to destination each file by navigating to the folder recursively
253
+ * @param {string} src Source folder to copy.
254
+ * @param {string} dest Destination folder to copy.
255
+ */
256
+ const copyRecursiveSync = (src, dest) => {
257
+ let exists = fs.existsSync(src), stats = exists && fs.statSync(src), isDirectory = exists && stats.isDirectory();
258
+ if (isDirectory) {
259
+ if (!fs.existsSync(dest)) {
260
+ fs.mkdirSync(dest, { recursive: true });
261
+ }
262
+ fs.readdirSync(src).forEach(function (childItemName) {
263
+ copyRecursiveSync(src + '/' + childItemName, dest + '/' + childItemName);
264
+ });
265
+ } else {
266
+ fs.copyFileSync(src, dest);
267
+ }
268
+ };
269
+
270
+ /**
271
+ * Check the app-runtime-wm-build npm package already installed or not.
272
+ * Install the app-runtime-wm-build if package not yet installed.
273
+ * Based on the platform type copy the bundle script into '/src/main/webapp'
274
+ * @param {*} sourceDir
275
+ * @returns
276
+ */
277
+ const buildAppInWMMode = (sourceDir, baseDir) => {
278
+
279
+ /**
280
+ * Download app-runtime-wm-build package and install if it doesn't exist
281
+ */
282
+ let appRuntimeWMBuildPackageInfo = {
283
+ scope: NPM_PACKAGE_SCOPE,
284
+ version: global.buildConfigObj.runtimeUIVersion,
285
+ name: 'app-runtime-wm-build',
286
+ packageJsonFile: '',
287
+ successMsg: MSG_APP_RUNTIME_WM_BUILD_SUCCESS,
288
+ infoMsg: MSG_APP_RUNTIME_WM_BUILD_LOG
289
+ };
290
+
291
+ appRuntimeWMBuildPackageInfo.baseDir = baseDir;
292
+ const PATH_WAVEMAKER_APP_RUNTIME_WM_BUILD = downloadNPMPackage(appRuntimeWMBuildPackageInfo);
293
+
294
+ const FILE_PATH_WAVEMAKER_APP_RUNTIME_WM_BUILD = PATH_WAVEMAKER_APP_RUNTIME_WM_BUILD + '/node_modules/' + appRuntimeWMBuildPackageInfo.scope + '/' + appRuntimeWMBuildPackageInfo.name + '/';
295
+
296
+ const PLATFORM_TYPE = { WEB: 'wmapp', MOBILE: 'wmmobile' }
297
+ let bundleFolder = '';
298
+ if (global.buildConfigObj.platformType === PLATFORM_TYPE.WEB) {
299
+ bundleFolder = 'wmapp/';
300
+ } else if (global.buildConfigObj.platformType = PLATFORM_TYPE.MOBILE) {
301
+ bundleFolder = 'wmmobile/';
302
+ } else {
303
+ console.log(UI_BUILD_ERROR_LOG + ' Invalid script path!');
304
+ return;
305
+ }
306
+ copyRecursiveSync(FILE_PATH_WAVEMAKER_APP_RUNTIME_WM_BUILD + bundleFolder, sourceDir + '/target/ui-build/output-files/' + bundleFolder);
307
+ }
308
+
309
+ /**
310
+ *
311
+ * @param {*} sourceDir project source directory to generate the angular app
312
+ * @param {*} ngBuildParams angular app build params along with cdn URL
313
+ * @param {*} codegenPath codegen path to generate the angular app
314
+ * Generate the angular app from codegen in target folder
315
+ */
316
+ const generateAngularApp = async (sourceDir, ngBuildParams, codegenPath, appTarget) => {
317
+ const CODEGEN_PATH = codegenPath + 'src/codegen-cli.js';
318
+ if (fs.existsSync(CODEGEN_PATH)) {
319
+ let deployUrl = `ng-bundle/${global.randomHash}/`;
320
+ if(ngBuildParams) {
321
+ let buildArgs = getArgs(ngBuildParams.split(' '));
322
+ if (buildArgs && buildArgs["deploy-url"]) {
323
+ deployUrl = buildArgs["deploy-url"];
324
+ }
325
+ }
326
+ const { generateCodegenAngularApp } = require(CODEGEN_PATH);
327
+ console.log(MSG_CODEGEN_LOG + 'Generating the angular App...');
328
+ let apiUrl = global.buildConfigObj.apiUrl && global.buildConfigObj.apiUrl.trim() !== "" ? global.buildConfigObj.apiUrl.trim() : "./";
329
+ console.log("API-Url - ", apiUrl, " - CDN-Url - ", deployUrl);
330
+ await generateCodegenAngularApp(sourceDir, appTarget, deployUrl, (global.buildConfigObj.pwa === 'true' ? true : false), codegenPath, global.buildConfigObj.csp === 'true', global.buildConfigObj.spa === 'true', apiUrl);
331
+ console.log(MSG_CODEGEN_LOG + 'Angular app generated !');
332
+ } else {
333
+ console.log(MSG_CODEGEN_LOG + " : CODEGEN-CLI not found");
334
+ }
335
+ }
336
+
337
+ /**
338
+ *
339
+ * @param {*} sourceDir
340
+ * @param {*} appTarget
341
+ * @param {*} generate_page The generated page name
342
+ * @param {*} codegenPath
343
+ */
344
+ const generateAngularAppPage = async (sourceDir, appTarget, generate_page, codegenPath) => {
345
+ const CODEGEN_PATH = codegenPath + 'src/codegen-cli.js';
346
+ if (fs.existsSync(CODEGEN_PATH)) {
347
+ const { generatePage } = require(CODEGEN_PATH);
348
+ await generatePage(sourceDir, appTarget, generate_page, codegenPath, global.buildConfigObj.csp === 'true');
349
+ } else {
350
+ console.log(MSG_CODEGEN_LOG + " : CODEGEN-CLI not found")
351
+ }
352
+
353
+ }
354
+
355
+ /**
356
+ * validate the cdn url and returns the angular build params
357
+ * @returns build params
358
+ */
359
+ const getNgBuildParams = () => {
360
+ let cdnUrl = global.buildConfigObj.cdnUrl && global.buildConfigObj.cdnUrl.trim() !== "" ? global.buildConfigObj.cdnUrl.trim() : "./";
361
+ let ngBuildParams = global.buildConfigObj.ngBuildParams;
362
+ // if the cdn url doesn't contain ng-bundle append it
363
+ // this is required for BE/FE separation. Now index.html file gets served directly from cdn bucket so there is no replacement
364
+ // happening from the server. So need to validate and properly create the URL from cdnUrl param passed and append ng-bundle
365
+ if (cdnUrl) {
366
+ cdnUrl = (cdnUrl.slice(-1) === "/" ? cdnUrl.slice(0, -1) : cdnUrl);
367
+ cdnUrl = cdnUrl + `/ng-bundle/${global.randomHash}/`;
368
+ ngBuildParams += ` --deploy-url=${cdnUrl}`;
369
+ }
370
+ return ngBuildParams;
371
+ }
372
+
373
+ /**
374
+ * Check codegen npm package already installed or not.
375
+ * Install the codegen if package not yet installed.
376
+ * Run generate and build angular script.
377
+ * Prepare the ng-build params deploy url if cdn url present in arguments
378
+ * @param {*} angularBuildConfig
379
+ * Properties: sourceDir,appTarget, baseDir
380
+ */
381
+ const buildAppInAngularMode = async (angularBuildConfig) => {
382
+ let ngBuildParams = getNgBuildParams();
383
+ let buildConfigObj = {
384
+ runtimeUIVersion: global.buildConfigObj.runtimeUIVersion,
385
+ codegenPath: global.buildConfigObj.codegenPath,
386
+ optimizeUIBuild: global.buildConfigObj.optimizeUIBuild,
387
+ appTarget: angularBuildConfig.appTarget,
388
+ appSrc: angularBuildConfig.sourceDir,
389
+ nodeVMArgs: global.buildConfigObj.nodeVMArgs,
390
+ ngBuildParams: ngBuildParams
391
+ }
392
+ buildAngularApp(buildConfigObj);
393
+ copyRecursiveSync(angularBuildConfig.sourceDir + '/target/ui-build/generated-app/dist/', angularBuildConfig.sourceDir + '/target/ui-build/output-files/');
394
+
395
+ await postBuild(buildConfigObj)
396
+ }
397
+
398
+ /**
399
+ *
400
+ * @param
401
+ * @returns {Promise<void>}
402
+ */
403
+ const buildAsWebComponent = async () => {
404
+ let wcCommand = "npx --yes @wavemaker/webcomponents-cli -s ."
405
+ executeSyncCmd(wcCommand, () => {
406
+ console.log('Something wrong with WebComponent build');
407
+ }, 'Building WebComponent');
408
+ }
409
+
410
+ const initBuild = async (buildConfigObj) => {
411
+ global.randomHash = generateRandomHash();
412
+ //making it global
413
+ global.buildConfigObj = buildConfigObj;
414
+
415
+ let buildType = buildConfigObj.buildType, isWebComponentBuild = buildConfigObj.exportWebComponent === 'true';
416
+ if(isWebComponentBuild) {
417
+ buildType = BUILD_TYPE.ANGULAR;
418
+ }
419
+ let CODEGEN_INSTALLATION = buildConfigObj.codegenPath
420
+ const sourceDir = buildConfigObj.appSrc;
421
+ let appTarget = buildConfigObj.appTarget;
422
+
423
+ let baseDir = buildConfigObj.optimizeUIBuild ? undefined : appTarget.split('/').slice(0, 2).join('/') + '/';
424
+ if (buildConfigObj.generate_page) {
425
+ // To generate the angular app specific page
426
+ await generateAngularAppPage(sourceDir, appTarget, buildConfigObj.generate_page, CODEGEN_INSTALLATION);
427
+ } else if (buildConfigObj.generateAngularApp) {
428
+ // TO generate the angular app
429
+ console.log('Angular app generation mode');
430
+ await generateAngularApp(sourceDir, getNgBuildParams(), CODEGEN_INSTALLATION, appTarget);
431
+ } else if (buildType === BUILD_TYPE.WM) {
432
+ buildAppInWMMode(sourceDir, baseDir);
433
+ } else if (buildType === BUILD_TYPE.ANGULAR) {
434
+ if(!isWebComponentBuild) {
435
+ await generateAngularApp(sourceDir, getNgBuildParams(), CODEGEN_INSTALLATION, appTarget);
436
+ }
437
+
438
+ //pre - run the custom for this project
439
+ await global.buildConfigObj.hooks.preBuildHook();
440
+
441
+ if(!isWebComponentBuild) {
442
+ const { generateOverrideCSS } = require(CODEGEN_INSTALLATION + 'src/codegen-cli.js');
443
+ await generateOverrideCSS(buildConfigObj, sourceDir, baseDir);
444
+ }
445
+
446
+ let angularBuildConfig = {
447
+ sourceDir: sourceDir,
448
+ appTarget: appTarget,
449
+ baseDir: baseDir,
450
+ };
451
+ if(isWebComponentBuild) {
452
+ await buildAsWebComponent();
453
+ } else {
454
+ await buildAppInAngularMode(angularBuildConfig);
455
+ }
456
+ //post - run the custom for this project
457
+ await global.buildConfigObj.hooks.postBuildHook();
458
+ }
459
+ }
460
+
120
461
  module.exports = {
121
- buildAngularApp,
122
- generateUiZip
462
+ initBuild
123
463
  }
@@ -12,6 +12,7 @@
12
12
  */
13
13
 
14
14
  const {args, executeSyncCmd, MSG_CODEGEN_LOG, getArgs} = require('./build-util');
15
+ const { generateRandomHash } = require('./src/wm-utils');
15
16
 
16
17
  /**
17
18
  * From codegen-cli generate angular app into the target directory
@@ -19,7 +20,8 @@ const {args, executeSyncCmd, MSG_CODEGEN_LOG, getArgs} = require('./build-util')
19
20
  const generateAngularApp = () => {
20
21
  console.log(MSG_CODEGEN_LOG + 'Generating the angular App...');
21
22
  let buildArgs = getArgs(args.ngBuildParams.split(' '));
22
- let deployUrl = 'ng-bundle/';
23
+ global.randomHash = global.randomHash ? global.randomHash : generateRandomHash();
24
+ let deployUrl = `ng-bundle/${global.randomHash}/`;
23
25
  if(buildArgs && buildArgs["deploy-url"]){
24
26
  deployUrl = buildArgs["deploy-url"];
25
27
  }