@wavemaker/angular-codegen 11.10.0-next.47275 → 11.10.0-rc.198

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.
Files changed (187) hide show
  1. {angular-codegen → package}/angular-app/angular.json +36 -10
  2. {angular-codegen → package}/angular-app/build-scripts/build.js +1 -0
  3. {angular-codegen → package}/angular-app/build-scripts/post-build.js +18 -15
  4. package/angular-app/dependency-report.html +124 -0
  5. package/angular-app/generate-dependency-report.js +240 -0
  6. package/angular-app/npm-shrinkwrap.json +25443 -0
  7. {angular-codegen → package}/angular-app/package-lock.json +13046 -12950
  8. {angular-codegen → package}/angular-app/package.json +37 -25
  9. package/angular-app/src/assets/styles/css/wm-style.css +1 -0
  10. package/angular-app/src/framework/services/customwidget-config-provider.service.ts +13 -0
  11. package/angular-app/src/framework/util/page-util.ts +7 -0
  12. package/angular-app/src/main.ts +67 -0
  13. {angular-codegen → package}/angular-app/src/setup-jest.js +4 -1
  14. {angular-codegen → package}/angular-app/tsconfig.json +3 -0
  15. package/build-angular-app.js +463 -0
  16. package/dependencies/custom-widgets-bundle.cjs.js +415 -0
  17. {angular-codegen → package}/dependencies/expression-parser.cjs.js +13909 -17363
  18. {angular-codegen → package}/dependencies/pipe-provider.cjs.js +38215 -37593
  19. {angular-codegen → package}/dependencies/transpilation-mobile.cjs.js +23855 -23466
  20. {angular-codegen → package}/dependencies/transpilation-web.cjs.js +23872 -23482
  21. {angular-codegen → package}/download-packages.js +13 -1
  22. {angular-codegen → package}/generate-angular-app.js +3 -1
  23. package/npm-shrinkwrap.json +8071 -0
  24. package/package-lock.json +8071 -0
  25. {angular-codegen → package}/package.json +8 -3
  26. package/src/codegen-args-cli.js +1 -0
  27. package/src/codegen-cli.js +1 -0
  28. package/src/codegen.js +1 -0
  29. package/src/copy-utils.js +1 -0
  30. package/src/gen-app-skeleton.js +1 -0
  31. package/src/gen-components.js +1 -0
  32. package/src/gen-customwidget-config.js +1 -0
  33. package/src/gen-index-html.js +1 -0
  34. package/src/handlebar-helpers.js +1 -0
  35. package/src/pages-util.js +1 -0
  36. {angular-codegen → package}/src/project-meta.js +1 -1
  37. package/src/update-angular-json.js +1 -0
  38. package/src/wm-utils.js +1 -0
  39. {angular-codegen → package}/templates/app.module.ts.hbs +5 -1
  40. package/templates/component.config.ts.hbs +1 -0
  41. package/templates/customwidget/customwidget-config.ts.hbs +6 -0
  42. package/templates/customwidget/customwidget.component.script.js.hbs +3 -0
  43. package/templates/customwidget/customwidget.component.ts.hbs +43 -0
  44. {angular-codegen → package}/templates/page/page.module.ts.hbs +11 -0
  45. angular-codegen/angular-app/src/assets/styles/css/wm-style.css +0 -1
  46. angular-codegen/angular-app/src/framework/util/page-util.ts +0 -5
  47. angular-codegen/angular-app/src/main.ts +0 -30
  48. angular-codegen/build-angular-app.js +0 -102
  49. angular-codegen/package-lock.json +0 -6494
  50. angular-codegen/src/codegen-args-cli.js +0 -1
  51. angular-codegen/src/codegen-cli.js +0 -1
  52. angular-codegen/src/codegen.js +0 -1
  53. angular-codegen/src/gen-app-skeleton.js +0 -1
  54. angular-codegen/src/gen-components.js +0 -1
  55. angular-codegen/src/gen-index-html.js +0 -1
  56. angular-codegen/src/handlebar-helpers.js +0 -1
  57. angular-codegen/src/pages-util.js +0 -1
  58. angular-codegen/src/update-angular-json.js +0 -1
  59. angular-codegen/src/wm-utils.js +0 -1
  60. {angular-codegen → package}/.npmrc +0 -0
  61. {angular-codegen → package}/angular-app/.npmrc +0 -0
  62. {angular-codegen → package}/angular-app/build-scripts/index-html-transform.js +0 -0
  63. {angular-codegen → package}/angular-app/build-scripts/optimize-css.gulpfile.js +0 -0
  64. {angular-codegen → package}/angular-app/build-scripts/update-version.js +0 -0
  65. {angular-codegen → package}/angular-app/src/.browserslistrc +0 -0
  66. {angular-codegen → package}/angular-app/src/app/app-codegen.module.ts +0 -0
  67. {angular-codegen → package}/angular-app/src/app/app.component.css +0 -0
  68. {angular-codegen → package}/angular-app/src/app/app.component.script.js +0 -0
  69. {angular-codegen → package}/angular-app/src/app/app.component.variables.ts +0 -0
  70. {angular-codegen → package}/angular-app/src/app/app.routes.ts +0 -0
  71. {angular-codegen → package}/angular-app/src/app/lazy-load-scripts.resolve.ts +0 -0
  72. {angular-codegen → package}/angular-app/src/app/prefabs/prefab-config.js +0 -0
  73. {angular-codegen → package}/angular-app/src/app/wm-project-properties.ts +0 -0
  74. {angular-codegen → package}/angular-app/src/assets/.gitkeep +0 -0
  75. {angular-codegen → package}/angular-app/src/assets/print.css +0 -0
  76. {angular-codegen → package}/angular-app/src/assets/styles/css/bootstrap.css.map +0 -0
  77. {angular-codegen → package}/angular-app/src/assets/styles/css/font/summernote.eot +0 -0
  78. {angular-codegen → package}/angular-app/src/assets/styles/css/font/summernote.ttf +0 -0
  79. {angular-codegen → package}/angular-app/src/assets/styles/css/font/summernote.woff +0 -0
  80. {angular-codegen → package}/angular-app/src/assets/styles/css/images/ui-bg_flat_0_aaaaaa_40x100.png +0 -0
  81. {angular-codegen → package}/angular-app/src/assets/styles/css/images/ui-bg_flat_75_ffffff_40x100.png +0 -0
  82. {angular-codegen → package}/angular-app/src/assets/styles/css/images/ui-bg_glass_55_fbf9ee_1x400.png +0 -0
  83. {angular-codegen → package}/angular-app/src/assets/styles/css/images/ui-bg_glass_65_ffffff_1x400.png +0 -0
  84. {angular-codegen → package}/angular-app/src/assets/styles/css/images/ui-bg_glass_75_dadada_1x400.png +0 -0
  85. {angular-codegen → package}/angular-app/src/assets/styles/css/images/ui-bg_glass_75_e6e6e6_1x400.png +0 -0
  86. {angular-codegen → package}/angular-app/src/assets/styles/css/images/ui-bg_glass_95_fef1ec_1x400.png +0 -0
  87. {angular-codegen → package}/angular-app/src/assets/styles/css/images/ui-bg_highlight-soft_75_cccccc_1x100.png +0 -0
  88. {angular-codegen → package}/angular-app/src/assets/styles/css/images/ui-icons_222222_256x240.png +0 -0
  89. {angular-codegen → package}/angular-app/src/assets/styles/css/images/ui-icons_2e83ff_256x240.png +0 -0
  90. {angular-codegen → package}/angular-app/src/assets/styles/css/images/ui-icons_444444_256x240.png +0 -0
  91. {angular-codegen → package}/angular-app/src/assets/styles/css/images/ui-icons_454545_256x240.png +0 -0
  92. {angular-codegen → package}/angular-app/src/assets/styles/css/images/ui-icons_555555_256x240.png +0 -0
  93. {angular-codegen → package}/angular-app/src/assets/styles/css/images/ui-icons_777620_256x240.png +0 -0
  94. {angular-codegen → package}/angular-app/src/assets/styles/css/images/ui-icons_777777_256x240.png +0 -0
  95. {angular-codegen → package}/angular-app/src/assets/styles/css/images/ui-icons_888888_256x240.png +0 -0
  96. {angular-codegen → package}/angular-app/src/assets/styles/css/images/ui-icons_cc0000_256x240.png +0 -0
  97. {angular-codegen → package}/angular-app/src/assets/styles/css/images/ui-icons_cd0a0a_256x240.png +0 -0
  98. {angular-codegen → package}/angular-app/src/assets/styles/css/images/ui-icons_ffffff_256x240.png +0 -0
  99. {angular-codegen → package}/angular-app/src/assets/styles/css/wm-responsive.css +0 -0
  100. {angular-codegen → package}/angular-app/src/assets/styles/fonts/FontAwesome.otf +0 -0
  101. {angular-codegen → package}/angular-app/src/assets/styles/fonts/fontawesome-webfont.eot +0 -0
  102. {angular-codegen → package}/angular-app/src/assets/styles/fonts/fontawesome-webfont.svg +0 -0
  103. {angular-codegen → package}/angular-app/src/assets/styles/fonts/fontawesome-webfont.ttf +0 -0
  104. {angular-codegen → package}/angular-app/src/assets/styles/fonts/fontawesome-webfont.woff +0 -0
  105. {angular-codegen → package}/angular-app/src/assets/styles/fonts/fontawesome-webfont.woff2 +0 -0
  106. {angular-codegen → package}/angular-app/src/assets/styles/fonts/glyphicons-halflings-regular.eot +0 -0
  107. {angular-codegen → package}/angular-app/src/assets/styles/fonts/glyphicons-halflings-regular.svg +0 -0
  108. {angular-codegen → package}/angular-app/src/assets/styles/fonts/glyphicons-halflings-regular.ttf +0 -0
  109. {angular-codegen → package}/angular-app/src/assets/styles/fonts/glyphicons-halflings-regular.woff +0 -0
  110. {angular-codegen → package}/angular-app/src/assets/styles/fonts/glyphicons-halflings-regular.woff2 +0 -0
  111. {angular-codegen → package}/angular-app/src/assets/styles/fonts/wavicon.eot +0 -0
  112. {angular-codegen → package}/angular-app/src/assets/styles/fonts/wavicon.ttf +0 -0
  113. {angular-codegen → package}/angular-app/src/assets/styles/fonts/wavicon.woff +0 -0
  114. {angular-codegen → package}/angular-app/src/assets/styles/fonts/wm-streamline-light-icon.eot +0 -0
  115. {angular-codegen → package}/angular-app/src/assets/styles/fonts/wm-streamline-light-icon.ttf +0 -0
  116. {angular-codegen → package}/angular-app/src/assets/styles/fonts/wm-streamline-light-icon.woff +0 -0
  117. {angular-codegen → package}/angular-app/src/assets/styles/fonts/wm-streamline-regular-icon.eot +0 -0
  118. {angular-codegen → package}/angular-app/src/assets/styles/fonts/wm-streamline-regular-icon.ttf +0 -0
  119. {angular-codegen → package}/angular-app/src/assets/styles/fonts/wm-streamline-regular-icon.woff +0 -0
  120. {angular-codegen → package}/angular-app/src/assets/styles/images/live-sync-icon.png +0 -0
  121. {angular-codegen → package}/angular-app/src/assets/styles/images/live-sync-touch-icon.png +0 -0
  122. {angular-codegen → package}/angular-app/src/assets/styles/images/loader.gif +0 -0
  123. {angular-codegen → package}/angular-app/src/assets/styles/images/spinner-small.gif +0 -0
  124. {angular-codegen → package}/angular-app/src/assets/styles/images/ui-icons.png +0 -0
  125. {angular-codegen → package}/angular-app/src/environments/environment.dev.ts +0 -0
  126. {angular-codegen → package}/angular-app/src/environments/environment.prod.ts +0 -0
  127. {angular-codegen → package}/angular-app/src/environments/environment.ts +0 -0
  128. {angular-codegen → package}/angular-app/src/framework/angular1.polyfills.ts +0 -0
  129. {angular-codegen → package}/angular-app/src/framework/services/app-extension.service.ts +0 -0
  130. {angular-codegen → package}/angular-app/src/framework/services/app-js-provider.service.ts +0 -0
  131. {angular-codegen → package}/angular-app/src/framework/services/app-variables-provider.service.ts +0 -0
  132. {angular-codegen → package}/angular-app/src/framework/services/component-ref-provider.service.ts +0 -0
  133. {angular-codegen → package}/angular-app/src/framework/services/lazy-component-ref-provider.service.ts +0 -0
  134. {angular-codegen → package}/angular-app/src/framework/services/prefab-config-provider.service.ts +0 -0
  135. {angular-codegen → package}/angular-app/src/framework/util/lazy-module-routes.ts +0 -0
  136. {angular-codegen → package}/angular-app/src/index.html +0 -0
  137. {angular-codegen → package}/angular-app/src/polyfills.ts +0 -0
  138. {angular-codegen → package}/angular-app/src/styles.css +0 -0
  139. {angular-codegen → package}/angular-app/src/tsconfig.app.json +0 -0
  140. {angular-codegen → package}/angular-app/src/tslint.json +0 -0
  141. {angular-codegen → package}/angular-app/tsconfig.web-app.json +0 -0
  142. {angular-codegen → package}/angular-app/wm-custom-webpack.config.js +0 -0
  143. {angular-codegen → package}/build-util.js +0 -0
  144. {angular-codegen → package}/dependencies/app.component.html +0 -0
  145. {angular-codegen → package}/pwa-assets/icons/icon-128x128.png +0 -0
  146. {angular-codegen → package}/pwa-assets/icons/icon-144x144.png +0 -0
  147. {angular-codegen → package}/pwa-assets/icons/icon-152x152.png +0 -0
  148. {angular-codegen → package}/pwa-assets/icons/icon-192x192.png +0 -0
  149. {angular-codegen → package}/pwa-assets/icons/icon-384x384.png +0 -0
  150. {angular-codegen → package}/pwa-assets/icons/icon-512x512.png +0 -0
  151. {angular-codegen → package}/pwa-assets/icons/icon-72x72.png +0 -0
  152. {angular-codegen → package}/pwa-assets/icons/icon-96x96.png +0 -0
  153. {angular-codegen → package}/pwa-assets/manifest.json +0 -0
  154. {angular-codegen → package}/pwa-assets/ngsw-config.json +0 -0
  155. {angular-codegen → package}/pwa-assets/wmsw-worker.js +0 -0
  156. {angular-codegen → package}/src/expr-parser-utils.js +0 -0
  157. {angular-codegen → package}/src/gen-app-codegen-module.js +0 -0
  158. {angular-codegen → package}/src/gen-app-js.js +0 -0
  159. {angular-codegen → package}/src/gen-app-prefabs-module.js +0 -0
  160. {angular-codegen → package}/src/gen-app-routes.js +0 -0
  161. {angular-codegen → package}/src/gen-app-variables.js +0 -0
  162. {angular-codegen → package}/src/gen-layouts.js +0 -0
  163. {angular-codegen → package}/src/gen-lazy-module-routes.js +0 -0
  164. {angular-codegen → package}/src/gen-prefabs.js +0 -0
  165. {angular-codegen → package}/src/gen-pwa-files.js +0 -0
  166. {angular-codegen → package}/src/gen-tsconfig.js +0 -0
  167. {angular-codegen → package}/src/gen-wm-project-properties.js +0 -0
  168. {angular-codegen → package}/templates/app-codegen.module.ts.hbs +0 -0
  169. {angular-codegen → package}/templates/app-prefabs.module.ts.hbs +0 -0
  170. {angular-codegen → package}/templates/app-routes.ts.hbs +0 -0
  171. {angular-codegen → package}/templates/app.component.script.js.hbs +0 -0
  172. {angular-codegen → package}/templates/component.expressions.ts.hbs +0 -0
  173. {angular-codegen → package}/templates/component.variables.ts.hbs +0 -0
  174. {angular-codegen → package}/templates/expr-vs-fn.hbs +0 -0
  175. {angular-codegen → package}/templates/layout/layout.component.ts.hbs +0 -0
  176. {angular-codegen → package}/templates/layout/layout.module.ts.hbs +0 -0
  177. {angular-codegen → package}/templates/lazy-module-routes.ts.hbs +0 -0
  178. {angular-codegen → package}/templates/page/page.component.script.js.hbs +0 -0
  179. {angular-codegen → package}/templates/page/page.component.ts.hbs +0 -0
  180. {angular-codegen → package}/templates/partial/partial.component.script.js.hbs +0 -0
  181. {angular-codegen → package}/templates/partial/partial.component.ts.hbs +0 -0
  182. {angular-codegen → package}/templates/partial/partial.module.ts.hbs +0 -0
  183. {angular-codegen → package}/templates/prefab/prefab-config.ts.hbs +0 -0
  184. {angular-codegen → package}/templates/prefab/prefab.component.script.js.hbs +0 -0
  185. {angular-codegen → package}/templates/prefab/prefab.component.ts.hbs +0 -0
  186. {angular-codegen → package}/templates/prefab/prefab.module.ts.hbs +0 -0
  187. {angular-codegen → package}/templates/wm-project-properties.ts.hbs +0 -0
@@ -0,0 +1,13 @@
1
+ import { Injectable } from '@angular/core';
2
+
3
+ import { CustomwidgetConfigProvider } from '@wm/runtime/base';
4
+
5
+ import { getCustomWidgetConfig } from '../util/page-util';
6
+
7
+ @Injectable()
8
+ export class CustomwidgetConfigProviderService extends CustomwidgetConfigProvider {
9
+
10
+ public getConfig(widgetname: string): Promise<any> {
11
+ return Promise.resolve(getCustomWidgetConfig(widgetname));
12
+ }
13
+ }
@@ -0,0 +1,7 @@
1
+ const prefabConfigs = new Map<string, any>();
2
+ const customWidgetConfigs = new Map<string, any>();
3
+
4
+ export const registerPrefabConfig = (prefabName: string, config: any) => prefabConfigs.set(prefabName, config);
5
+ export const getPrefabConfig = prefabName => prefabConfigs.get(prefabName);
6
+ export const registerCustomWidgetConfig = (customWidget: string, config: any) => customWidgetConfigs.set(customWidget, config);
7
+ export const getCustomWidgetConfig = customWidget => customWidgetConfigs.get(customWidget);
@@ -0,0 +1,67 @@
1
+ import { ApplicationRef, enableProdMode, NgModuleRef } from '@angular/core';
2
+ import { platformBrowserDynamic } from '@angular/platform-browser-dynamic';
3
+
4
+ import { AppModule } from './app/app.module';
5
+ import { environment } from './environments/environment';
6
+
7
+ import initWmProjectProperties from './app/wm-project-properties';
8
+ import { WMAppProperties } from './app/wmProperties';
9
+ import * as fontConfig from './font.config';
10
+
11
+
12
+ let formatAcceptHeader = (languages: any) => {
13
+ let result: string[] = [];
14
+ let addedLanguages = new Set<string>(); // To track already added languages
15
+ let qValue = 1.0;
16
+
17
+ languages.forEach((lang: any) => {
18
+ if (!addedLanguages.has(lang)) {
19
+ // Add the full language (e.g., en-US or en) if not already added
20
+ result.push(`${lang}${qValue === 1.0 ? '' : `;q=${qValue.toFixed(1)}`}`);
21
+ addedLanguages.add(lang);
22
+ // Decrease qValue for the next language
23
+ qValue = Math.max(0.1, qValue - 0.1); // Decrease qValue, minimum is 0.1
24
+ }
25
+
26
+ // If language has a region code (e.g., en-US), also add the base language (e.g., en)
27
+ if (lang.includes('-')) {
28
+ const baseLang = lang.split('-')[0];
29
+ if (!addedLanguages.has(baseLang)) {
30
+ result.push(`${baseLang};q=${qValue.toFixed(1)}`);
31
+ addedLanguages.add(baseLang);
32
+
33
+ // Decrease qValue for the next language
34
+ qValue = Math.max(0.1, qValue - 0.1);
35
+ }
36
+ }
37
+ });
38
+
39
+ return result.join(',');
40
+ }
41
+ WMAppProperties['preferredLanguage'] = formatAcceptHeader(navigator.languages);
42
+ WMAppProperties['fontConfig'] = fontConfig;
43
+
44
+
45
+ (window as any)._WM_APP_PROPERTIES = WMAppProperties
46
+ initWmProjectProperties();
47
+
48
+ if (environment.production) {
49
+ enableProdMode();
50
+ }
51
+
52
+ document.addEventListener('DOMContentLoaded', () => {
53
+ new Promise<Event | void>( resolve => {
54
+ if (window['cordova']) {
55
+ document.addEventListener('deviceready', resolve);
56
+ } else {
57
+ resolve();
58
+ }
59
+ }).then(() => platformBrowserDynamic().bootstrapModule(AppModule))
60
+ .then((appModuleRef: NgModuleRef<AppModule>) => {
61
+ const applicationRef = appModuleRef.injector.get(ApplicationRef);
62
+ window.addEventListener('unload', () => {
63
+ applicationRef.components.map(c => c && c.destroy());
64
+ });
65
+ console.timeEnd('bootstrap'), err => console.log(err);
66
+ }, err => console.log(err));
67
+ });
@@ -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;
@@ -41,6 +41,9 @@
41
41
  "@wavemaker/variables": [
42
42
  "node_modules/@wavemaker/variables/"
43
43
  ],
44
+ "@wavemaker/custom-widgets-m3": [
45
+ "node_modules/@wavemaker/custom-widgets-m3/"
46
+ ],
44
47
  "@wm/components/base": [
45
48
  "node_modules/@wavemaker/app-ng-runtime/components/base"
46
49
  ],
@@ -0,0 +1,463 @@
1
+
2
+ /**
3
+ * Download and install the app-ng-runtime package
4
+ * Run the build and post build for the generated angular app.
5
+ *
6
+ * CONSOLE ARGUMENTS:-
7
+ * nodeVMArgs:String: Node environment params (Eg: '--max-old-space-size=2040')
8
+ * ngBuildParams:String: Anglar build params (Eg: '--prod=true --source-map=false')
9
+ * runtimeUIVersion:String: Runtime version (Eg: 10.6.6-next.10243)
10
+ * appSrc:String: Source folder to generate the angular app (current directory Eg: '.')
11
+ * appTarget:String: Target folder to save the generated app (Eg: 'target/ui-build/generated-app')
12
+ * codegenPath:String: Input to the codegen-CLI --> Codegen installation path to copy the angular-template-app
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
+ */
15
+ const fs = require('fs');
16
+ const rimraf = require('rimraf');
17
+ const { downloadNPMPackage } = require('./download-packages');
18
+ const { generateRandomHash } = require('./src/wm-utils');
19
+ const archiver = require('archiver');
20
+ const path = require("path");
21
+ const { executeSyncCmd, MSG_NG_RUNTIME_LOG, MSG_NG_RUNTIME_SUCCESS } = require('./build-util');
22
+ const os = require("os");
23
+ const cheerio = require(`cheerio`);
24
+
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";
34
+
35
+ /**
36
+ * @TODO: This is a temporary workaround to extract deploy-url from 'ngBuildParams', need to be replaced in future.
37
+ */
38
+ const updateDeployUrl = (args) => {
39
+ let buildArgs = args.ngBuildParams.split(' ');
40
+ const deployParam = buildArgs.find(i => i.startsWith("--deploy-url="));
41
+ if(!deployParam) {
42
+ buildArgs.push(`--deploy-url=ng-bundle/${global.randomHash}/`);
43
+ } else {
44
+ buildArgs.filter((param, index) => {
45
+ if (param.includes('--deploy-url=_cdnUrl_')) {
46
+ buildArgs[index] = `--deploy-url=_cdnUrl_/ng-bundle/${global.randomHash}/`
47
+ return true;
48
+ }
49
+ });
50
+ }
51
+ buildArgs.push(args.nodeVMArgs);
52
+ return buildArgs.join(" ");
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
+
100
+
101
+ /**
102
+ * Download the app runtime package
103
+ * Symlink to reuse the existing node modules (If windows optimizeUIBuild will be false and install all node modules every build )
104
+ * Run the ng build and post build for the project
105
+ */
106
+ const buildAngularApp = (args) => {
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");
111
+
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';
115
+
116
+ fs.mkdirSync(TARBALL_DOWNLOAD_PATH, { recursive: true });
117
+
118
+ try {
119
+ if (args.optimizeUIBuild) {
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');
128
+ } else {
129
+ processAngularAppPackage(TARBALL_DOWNLOAD_PATH, args.appTarget, PACKAGE_NAME, false);
130
+ }
131
+ } catch (err) {
132
+ deleteFiles([SUCCESS_FILE])
133
+ console.log(MSG_NG_RUNTIME_LOG + 'Something went wrong - ', err);
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)])
138
+ }
139
+
140
+ let ngBuildParams = updateDeployUrl(args);
141
+ const NG_BUILD_MSG = 'NG BUILD MIGHT HAVE FAILED WITH HEAP OUT OF MEMORY, RE-EXECUTE THE BUILD BY INCREASING THE MAX-OLD-SPACE-SIZE ARGUMENT VALUE FOR BUILD.UI.NODE.ARGS PROPERTY IN DEPLOYMENT PROFILE';
142
+ // Generating the angular build and post build process.
143
+ executeSyncCmd('cd ' + args.appTarget + ' && node ./build-scripts/build.js ' + ngBuildParams, null, MSG_NG_RUNTIME_LOG, false, NG_BUILD_MSG);
144
+ }
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
+
161
+ const generateUiZip = async( sourceDir ) => {
162
+ return new Promise((resolve, reject) => {
163
+ const distDir = path.resolve(sourceDir + '/target/ui-build/output-files');
164
+ const zipFile = path.resolve(sourceDir + '/target/ui-artifact.zip');
165
+
166
+ const output = fs.createWriteStream(zipFile);
167
+ const archive = archiver('zip', {
168
+ zlib: {level: 9}
169
+ });
170
+ output.on('close', () => {
171
+ console.log(`✅ ui-artifact.zip created successfully: ${zipFile}`);
172
+ resolve();
173
+ });
174
+ archive.on('error', (err) => {
175
+ reject(err);
176
+ });
177
+ archive.pipe(output);
178
+ archive.directory(distDir, false);
179
+ archive.finalize();
180
+ });
181
+ }
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
+
461
+ module.exports = {
462
+ initBuild
463
+ }