@simplysm/sd-cli 7.3.2 → 10.0.4

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 (217) hide show
  1. package/.eslintrc.cjs +18 -0
  2. package/dist/build-cluster.js +75 -0
  3. package/dist/build-cluster.js.map +1 -0
  4. package/dist/builders/SdCliJsLibLinter.d.ts +18 -0
  5. package/dist/builders/SdCliJsLibLinter.js +69 -0
  6. package/dist/builders/SdCliJsLibLinter.js.map +1 -0
  7. package/dist/builders/SdCliTsLibBuilder.d.ts +20 -0
  8. package/dist/builders/SdCliTsLibBuilder.js +205 -0
  9. package/dist/builders/SdCliTsLibBuilder.js.map +1 -0
  10. package/dist/commons.d.ts +3 -117
  11. package/dist/commons.js +2 -0
  12. package/dist/commons.js.map +1 -0
  13. package/dist/entry/SdCliProject.d.ts +28 -0
  14. package/dist/entry/SdCliProject.js +269 -0
  15. package/dist/entry/SdCliProject.js.map +1 -0
  16. package/dist/sd-cli.js +118 -0
  17. package/dist/sd-cli.js.map +1 -0
  18. package/dist/utils/SdCliBuildResultUtil.d.ts +1 -4
  19. package/dist/utils/SdCliBuildResultUtil.js +37 -0
  20. package/dist/utils/SdCliBuildResultUtil.js.map +1 -0
  21. package/dist/utils/SdCliConfigUtil.js +69 -0
  22. package/dist/utils/SdCliConfigUtil.js.map +1 -0
  23. package/package.json +10 -59
  24. package/src/build-cluster.ts +82 -0
  25. package/src/builders/SdCliJsLibLinter.ts +84 -0
  26. package/src/builders/SdCliTsLibBuilder.ts +265 -0
  27. package/src/commons.ts +3 -123
  28. package/src/entry/SdCliProject.ts +351 -0
  29. package/src/sd-cli.ts +135 -0
  30. package/src/utils/SdCliBuildResultUtil.ts +5 -38
  31. package/tsconfig.json +18 -0
  32. package/README.md +0 -105
  33. package/assets/client-files/assets/icons/icon-128x128.png +0 -0
  34. package/assets/client-files/assets/icons/icon-144x144.png +0 -0
  35. package/assets/client-files/assets/icons/icon-152x152.png +0 -0
  36. package/assets/client-files/assets/icons/icon-192x192.png +0 -0
  37. package/assets/client-files/assets/icons/icon-384x384.png +0 -0
  38. package/assets/client-files/assets/icons/icon-512x512.png +0 -0
  39. package/assets/client-files/assets/icons/icon-72x72.png +0 -0
  40. package/assets/client-files/assets/icons/icon-96x96.png +0 -0
  41. package/assets/client-files/favicon.ico +0 -0
  42. package/dist/SdCliBuildResultError.d.ts +0 -5
  43. package/dist/SdCliBuildResultError.mjs +0 -8
  44. package/dist/bin/sd-cli.d.ts +0 -2
  45. package/dist/bin/sd-cli.mjs +0 -410
  46. package/dist/build-tool/SdCliCacheCompilerHost.d.ts +0 -10
  47. package/dist/build-tool/SdCliCacheCompilerHost.mjs +0 -51
  48. package/dist/build-tool/SdCliCordova.d.ts +0 -16
  49. package/dist/build-tool/SdCliCordova.mjs +0 -212
  50. package/dist/build-tool/SdCliElectron.d.ts +0 -9
  51. package/dist/build-tool/SdCliElectron.mjs +0 -71
  52. package/dist/build-tool/SdCliGithubApi.d.ts +0 -13
  53. package/dist/build-tool/SdCliGithubApi.mjs +0 -92
  54. package/dist/build-tool/SdCliIndexFileGenerator.d.ts +0 -13
  55. package/dist/build-tool/SdCliIndexFileGenerator.mjs +0 -62
  56. package/dist/build-tool/SdCliNgCacheCompilerHost.d.ts +0 -12
  57. package/dist/build-tool/SdCliNgCacheCompilerHost.mjs +0 -43
  58. package/dist/build-tool/SdCliPackageLinter.d.ts +0 -8
  59. package/dist/build-tool/SdCliPackageLinter.mjs +0 -62
  60. package/dist/builder/SdCliClientBuilder.d.ts +0 -26
  61. package/dist/builder/SdCliClientBuilder.mjs +0 -761
  62. package/dist/builder/SdCliJsLibBuilder.d.ts +0 -14
  63. package/dist/builder/SdCliJsLibBuilder.mjs +0 -54
  64. package/dist/builder/SdCliServerBuilder.d.ts +0 -28
  65. package/dist/builder/SdCliServerBuilder.mjs +0 -482
  66. package/dist/builder/SdCliTsLibBuilder.d.ts +0 -35
  67. package/dist/builder/SdCliTsLibBuilder.mjs +0 -317
  68. package/dist/commons.mjs +0 -2
  69. package/dist/entry-points/SdCliFileCrypto.d.ts +0 -7
  70. package/dist/entry-points/SdCliFileCrypto.mjs +0 -72
  71. package/dist/entry-points/SdCliLocalUpdate.d.ts +0 -13
  72. package/dist/entry-points/SdCliLocalUpdate.mjs +0 -100
  73. package/dist/entry-points/SdCliPrepare.d.ts +0 -5
  74. package/dist/entry-points/SdCliPrepare.mjs +0 -86
  75. package/dist/entry-points/SdCliProject.d.ts +0 -34
  76. package/dist/entry-points/SdCliProject.mjs +0 -416
  77. package/dist/entry-points/SdCliProjectGenerator.d.ts +0 -44
  78. package/dist/entry-points/SdCliProjectGenerator.mjs +0 -326
  79. package/dist/entry-points/file/base/fc_package_eslintrc.d.ts +0 -3
  80. package/dist/entry-points/file/base/fc_package_eslintrc.mjs +0 -31
  81. package/dist/entry-points/file/base/fc_package_npmconfig.d.ts +0 -9
  82. package/dist/entry-points/file/base/fc_package_npmconfig.mjs +0 -32
  83. package/dist/entry-points/file/base/fc_package_tsconfig.d.ts +0 -5
  84. package/dist/entry-points/file/base/fc_package_tsconfig.mjs +0 -13
  85. package/dist/entry-points/file/client/fc_package_AppModule.d.ts +0 -1
  86. package/dist/entry-points/file/client/fc_package_AppModule.mjs +0 -37
  87. package/dist/entry-points/file/client/fc_package_AppPage.d.ts +0 -1
  88. package/dist/entry-points/file/client/fc_package_AppPage.mjs +0 -14
  89. package/dist/entry-points/file/client/fc_package_Page.d.ts +0 -4
  90. package/dist/entry-points/file/client/fc_package_Page.mjs +0 -19
  91. package/dist/entry-points/file/client/fc_package_client_main.d.ts +0 -1
  92. package/dist/entry-points/file/client/fc_package_client_main.mjs +0 -19
  93. package/dist/entry-points/file/client/fc_package_index.d.ts +0 -3
  94. package/dist/entry-points/file/client/fc_package_index.mjs +0 -88
  95. package/dist/entry-points/file/client/fc_package_manifest.d.ts +0 -5
  96. package/dist/entry-points/file/client/fc_package_manifest.mjs +0 -54
  97. package/dist/entry-points/file/client/fc_package_polyfills.d.ts +0 -1
  98. package/dist/entry-points/file/client/fc_package_polyfills.mjs +0 -11
  99. package/dist/entry-points/file/client/fc_package_styles.d.ts +0 -1
  100. package/dist/entry-points/file/client/fc_package_styles.mjs +0 -7
  101. package/dist/entry-points/file/db/fc_package_DbContext.d.ts +0 -3
  102. package/dist/entry-points/file/db/fc_package_DbContext.mjs +0 -14
  103. package/dist/entry-points/file/db/fc_package_DbModel.d.ts +0 -4
  104. package/dist/entry-points/file/db/fc_package_DbModel.mjs +0 -12
  105. package/dist/entry-points/file/project/fc_project_editor_config.d.ts +0 -1
  106. package/dist/entry-points/file/project/fc_project_editor_config.mjs +0 -22
  107. package/dist/entry-points/file/project/fc_project_eslintrc.d.ts +0 -1
  108. package/dist/entry-points/file/project/fc_project_eslintrc.mjs +0 -30
  109. package/dist/entry-points/file/project/fc_project_gitattributes.d.ts +0 -1
  110. package/dist/entry-points/file/project/fc_project_gitattributes.mjs +0 -6
  111. package/dist/entry-points/file/project/fc_project_gitignore.d.ts +0 -1
  112. package/dist/entry-points/file/project/fc_project_gitignore.mjs +0 -27
  113. package/dist/entry-points/file/project/fc_project_npmconfig.d.ts +0 -7
  114. package/dist/entry-points/file/project/fc_project_npmconfig.mjs +0 -37
  115. package/dist/entry-points/file/project/fc_project_readme.d.ts +0 -3
  116. package/dist/entry-points/file/project/fc_project_readme.mjs +0 -13
  117. package/dist/entry-points/file/project/fc_project_simplysm.d.ts +0 -1
  118. package/dist/entry-points/file/project/fc_project_simplysm.mjs +0 -2
  119. package/dist/entry-points/file/project/fc_project_tsconfig.d.ts +0 -1
  120. package/dist/entry-points/file/project/fc_project_tsconfig.mjs +0 -25
  121. package/dist/entry-points/file/server/fc_package_server_main.d.ts +0 -5
  122. package/dist/entry-points/file/server/fc_package_server_main.mjs +0 -60
  123. package/dist/index.d.ts +0 -54
  124. package/dist/index.mjs +0 -55
  125. package/dist/ng-tools/SdCliNgModuleGenerator.d.ts +0 -29
  126. package/dist/ng-tools/SdCliNgModuleGenerator.mjs +0 -502
  127. package/dist/ng-tools/babel/SdCliBbFileMetadata.d.ts +0 -25
  128. package/dist/ng-tools/babel/SdCliBbFileMetadata.mjs +0 -539
  129. package/dist/ng-tools/babel/SdCliBbRootMetadata.d.ts +0 -23
  130. package/dist/ng-tools/babel/SdCliBbRootMetadata.mjs +0 -247
  131. package/dist/ng-tools/babel/SdCliBbUtil.d.ts +0 -5
  132. package/dist/ng-tools/babel/SdCliBbUtil.mjs +0 -14
  133. package/dist/ng-tools/babel/TSdCliBbNgMetadata.d.ts +0 -42
  134. package/dist/ng-tools/babel/TSdCliBbNgMetadata.mjs +0 -216
  135. package/dist/ng-tools/babel/TSdCliBbTypeMetadata.d.ts +0 -55
  136. package/dist/ng-tools/babel/TSdCliBbTypeMetadata.mjs +0 -151
  137. package/dist/ng-tools/commons.d.ts +0 -9
  138. package/dist/ng-tools/commons.mjs +0 -2
  139. package/dist/ng-tools/typescript/SdCliTsFileMetadata.d.ts +0 -61
  140. package/dist/ng-tools/typescript/SdCliTsFileMetadata.mjs +0 -325
  141. package/dist/ng-tools/typescript/SdCliTsRootMetadata.d.ts +0 -8
  142. package/dist/ng-tools/typescript/SdCliTsRootMetadata.mjs +0 -28
  143. package/dist/ng-tools/typescript/SdCliTsUtil.d.ts +0 -5
  144. package/dist/ng-tools/typescript/SdCliTsUtil.mjs +0 -28
  145. package/dist/packages/SdCliPackage.d.ts +0 -22
  146. package/dist/packages/SdCliPackage.mjs +0 -206
  147. package/dist/utils/SdCliBuildResultUtil.mjs +0 -63
  148. package/dist/utils/SdCliConfigUtil.mjs +0 -69
  149. package/dist/utils/SdCliNpmConfigUtil.d.ts +0 -7
  150. package/dist/utils/SdCliNpmConfigUtil.mjs +0 -15
  151. package/dist/worker/build-worker.mjs +0 -67
  152. package/dist/worker/server-worker.mjs +0 -67
  153. package/docs/client-add-page.md +0 -8
  154. package/docs/client-router.md +0 -85
  155. package/docs/client-sw.md +0 -101
  156. package/docs/conf-orm.md +0 -81
  157. package/docs/conf-usage.md +0 -5
  158. package/docs/lib-local-update.md +0 -50
  159. package/docs/lib-ts-paths.md +0 -25
  160. package/lib/cordova-entry.js +0 -22
  161. package/src/SdCliBuildResultError.ts +0 -9
  162. package/src/bin/sd-cli.ts +0 -493
  163. package/src/build-tool/SdCliCacheCompilerHost.ts +0 -79
  164. package/src/build-tool/SdCliCordova.ts +0 -263
  165. package/src/build-tool/SdCliElectron.ts +0 -84
  166. package/src/build-tool/SdCliGithubApi.ts +0 -111
  167. package/src/build-tool/SdCliIndexFileGenerator.ts +0 -79
  168. package/src/build-tool/SdCliNgCacheCompilerHost.ts +0 -58
  169. package/src/build-tool/SdCliPackageLinter.ts +0 -74
  170. package/src/builder/SdCliClientBuilder.ts +0 -871
  171. package/src/builder/SdCliJsLibBuilder.ts +0 -70
  172. package/src/builder/SdCliServerBuilder.ts +0 -552
  173. package/src/builder/SdCliTsLibBuilder.ts +0 -450
  174. package/src/entry-points/SdCliFileCrypto.ts +0 -87
  175. package/src/entry-points/SdCliLocalUpdate.ts +0 -121
  176. package/src/entry-points/SdCliPrepare.ts +0 -86
  177. package/src/entry-points/SdCliProject.ts +0 -491
  178. package/src/entry-points/SdCliProjectGenerator.ts +0 -402
  179. package/src/entry-points/file/base/fc_package_eslintrc.ts +0 -30
  180. package/src/entry-points/file/base/fc_package_npmconfig.ts +0 -43
  181. package/src/entry-points/file/base/fc_package_tsconfig.ts +0 -12
  182. package/src/entry-points/file/client/fc_package_AppModule.ts +0 -36
  183. package/src/entry-points/file/client/fc_package_AppPage.ts +0 -13
  184. package/src/entry-points/file/client/fc_package_Page.ts +0 -19
  185. package/src/entry-points/file/client/fc_package_client_main.ts +0 -18
  186. package/src/entry-points/file/client/fc_package_index.ts +0 -87
  187. package/src/entry-points/file/client/fc_package_manifest.ts +0 -53
  188. package/src/entry-points/file/client/fc_package_polyfills.ts +0 -10
  189. package/src/entry-points/file/client/fc_package_styles.ts +0 -6
  190. package/src/entry-points/file/db/fc_package_DbContext.ts +0 -14
  191. package/src/entry-points/file/db/fc_package_DbModel.ts +0 -11
  192. package/src/entry-points/file/project/fc_project_editor_config.ts +0 -21
  193. package/src/entry-points/file/project/fc_project_eslintrc.ts +0 -29
  194. package/src/entry-points/file/project/fc_project_gitattributes.ts +0 -5
  195. package/src/entry-points/file/project/fc_project_gitignore.ts +0 -26
  196. package/src/entry-points/file/project/fc_project_npmconfig.ts +0 -36
  197. package/src/entry-points/file/project/fc_project_readme.ts +0 -12
  198. package/src/entry-points/file/project/fc_project_simplysm.ts +0 -1
  199. package/src/entry-points/file/project/fc_project_tsconfig.ts +0 -24
  200. package/src/entry-points/file/server/fc_package_server_main.ts +0 -62
  201. package/src/index.ts +0 -54
  202. package/src/ng-tools/SdCliNgModuleGenerator.ts +0 -672
  203. package/src/ng-tools/babel/SdCliBbFileMetadata.ts +0 -629
  204. package/src/ng-tools/babel/SdCliBbRootMetadata.ts +0 -292
  205. package/src/ng-tools/babel/SdCliBbUtil.ts +0 -15
  206. package/src/ng-tools/babel/TSdCliBbNgMetadata.ts +0 -251
  207. package/src/ng-tools/babel/TSdCliBbTypeMetadata.ts +0 -212
  208. package/src/ng-tools/commons.ts +0 -3
  209. package/src/ng-tools/typescript/SdCliTsFileMetadata.ts +0 -384
  210. package/src/ng-tools/typescript/SdCliTsRootMetadata.ts +0 -32
  211. package/src/ng-tools/typescript/SdCliTsUtil.ts +0 -29
  212. package/src/packages/SdCliPackage.ts +0 -259
  213. package/src/utils/SdCliNpmConfigUtil.ts +0 -16
  214. package/src/worker/build-worker.ts +0 -73
  215. package/src/worker/server-worker.ts +0 -72
  216. /package/dist/{worker/build-worker.d.ts → build-cluster.d.ts} +0 -0
  217. /package/dist/{worker/server-worker.d.ts → sd-cli.d.ts} +0 -0
@@ -1,871 +0,0 @@
1
- import { INpmConfig, ISdCliClientPackageConfig, ISdCliPackageBuildResult, ITsconfig } from "../commons";
2
- import { EventEmitter } from "events";
3
- import { FsUtil, Logger, PathUtil } from "@simplysm/sd-core-node";
4
- import webpack from "webpack";
5
- import path from "path";
6
- import ts from "typescript";
7
- import { SdCliBuildResultUtil } from "../utils/SdCliBuildResultUtil";
8
- import { NamedChunksPlugin } from "@angular-devkit/build-angular/src/webpack/plugins/named-chunks-plugin";
9
- import {
10
- DedupeModuleResolvePlugin,
11
- JavaScriptOptimizerPlugin,
12
- SuppressExtractedTextChunksWebpackPlugin
13
- } from "@angular-devkit/build-angular/src/webpack/plugins";
14
- import CopyWebpackPlugin from "copy-webpack-plugin";
15
- import MiniCssExtractPlugin from "mini-css-extract-plugin";
16
- import { AngularWebpackPlugin } from "@ngtools/webpack";
17
- import { IndexHtmlWebpackPlugin } from "@angular-devkit/build-angular/src/webpack/plugins/index-html-webpack-plugin";
18
- import { SassWorkerImplementation } from "@angular-devkit/build-angular/src/sass/sass-service";
19
- import { LicenseWebpackPlugin } from "license-webpack-plugin";
20
- import NodePolyfillPlugin from "node-polyfill-webpack-plugin";
21
- import { createHash } from "crypto";
22
- import ESLintWebpackPlugin from "eslint-webpack-plugin";
23
- import os from "os";
24
- import { ESLint } from "eslint";
25
- import { TransferSizePlugin } from "@angular-devkit/build-angular/src/webpack/plugins/transfer-size-plugin";
26
- import { CssOptimizerPlugin } from "@angular-devkit/build-angular/src/webpack/plugins/css-optimizer-plugin";
27
- import browserslist from "browserslist";
28
- import { augmentAppWithServiceWorker } from "@angular-devkit/build-angular/src/utils/service-worker";
29
- import { SdCliNgModuleGenerator } from "../ng-tools/SdCliNgModuleGenerator";
30
- import { SdCliCordova } from "../build-tool/SdCliCordova";
31
- import { SdCliNpmConfigUtil } from "../utils/SdCliNpmConfigUtil";
32
- import electronBuilder from "electron-builder";
33
- import { fileURLToPath } from "url";
34
- import { Entrypoint } from "@angular-devkit/build-angular/src/utils/index-file/augment-index-html";
35
- import { StringUtil } from "@simplysm/sd-core-common";
36
- import LintResult = ESLint.LintResult;
37
-
38
- export class SdCliClientBuilder extends EventEmitter {
39
- private readonly _logger: Logger;
40
-
41
- private readonly _tsconfigFilePath: string;
42
- private readonly _parsedTsconfig: ts.ParsedCommandLine;
43
- private readonly _npmConfigMap = new Map<string, INpmConfig>();
44
- private readonly _ngModuleGenerator: SdCliNgModuleGenerator;
45
-
46
- private readonly _cordova?: SdCliCordova;
47
-
48
- private readonly _hasAngularRoute: boolean;
49
-
50
- private readonly _cacheBasePath = path.resolve(this._rootPath, ".cache");
51
-
52
- public constructor(private readonly _rootPath: string,
53
- private readonly _config: ISdCliClientPackageConfig,
54
- private readonly _projRootPath: string) {
55
- super();
56
-
57
- const npmConfig = this._getNpmConfig(this._rootPath)!;
58
- this._logger = Logger.get(["simplysm", "sd-cli", this.constructor.name, npmConfig.name]);
59
-
60
- // tsconfig
61
- this._tsconfigFilePath = path.resolve(this._rootPath, "tsconfig-build.json");
62
- const tsconfig = FsUtil.readJson(this._tsconfigFilePath) as ITsconfig;
63
- this._parsedTsconfig = ts.parseJsonConfigFileContent(tsconfig, ts.sys, this._rootPath, tsconfig.angularCompilerOptions);
64
-
65
- // isAngular
66
- this._hasAngularRoute = SdCliNpmConfigUtil.getDependencies(npmConfig).defaults.includes("@angular/router");
67
-
68
- // NgModule 생성기 초기화
69
- this._ngModuleGenerator = new SdCliNgModuleGenerator(this._rootPath, [
70
- "controls",
71
- "directives",
72
- "guards",
73
- "modals",
74
- "providers",
75
- "app",
76
- "pages",
77
- "print-templates",
78
- "toasts",
79
- "AppPage"
80
- ], this._hasAngularRoute ? {
81
- glob: "**/*Page.ts",
82
- fileEndsWith: "Page",
83
- rootClassName: "AppPage"
84
- } : undefined);
85
-
86
- // CORDOVA
87
- if (this._config.builder?.cordova) {
88
- this._cordova = new SdCliCordova(this._rootPath, this._config.builder.cordova);
89
- }
90
- }
91
-
92
- public override on(event: "change", listener: () => void): this;
93
- public override on(event: "complete", listener: (results: ISdCliPackageBuildResult[]) => void): this;
94
- public override on(event: string | symbol, listener: (...args: any[]) => void): this {
95
- return super.on(event, listener);
96
- }
97
-
98
- private async _checkCacheAsync(watch: boolean): Promise<void> {
99
- const projPkgLockContent = await FsUtil.readFileAsync(path.resolve(this._projRootPath, "yarn.lock"));
100
-
101
- // const cachePath = path.resolve(cacheBasePath, pkgVersion);
102
-
103
- const versionHash = createHash("sha1")
104
- .update(projPkgLockContent)
105
- .update(JSON.stringify(this._parsedTsconfig.options))
106
- .update(JSON.stringify(this._config))
107
- .update(watch.toString())
108
- .digest("hex");
109
- if (
110
- !FsUtil.exists(path.resolve(this._cacheBasePath, "version")) // 버전파일이 없거나
111
- || (
112
- FsUtil.exists(path.resolve(this._cacheBasePath, "version")) &&
113
- await FsUtil.readFileAsync(path.resolve(this._cacheBasePath, "version")) !== versionHash
114
- ) // 버전이 현재 버전과 다르면
115
- ) {
116
- // 캐시 삭제
117
- await FsUtil.removeAsync(path.resolve(this._cacheBasePath));
118
- }
119
- // 버전쓰기
120
- await FsUtil.writeFileAsync(path.resolve(this._cacheBasePath, "version"), versionHash);
121
- }
122
-
123
- public async watchAsync(): Promise<void> {
124
- // DIST 비우기
125
- await FsUtil.removeAsync(path.resolve(this._rootPath, ".cache", "electron"));
126
- await FsUtil.removeAsync(this._parsedTsconfig.options.outDir!);
127
-
128
- // 캐시체크
129
- await this._checkCacheAsync(true);
130
-
131
- // NgModule 생성
132
- await this._ngModuleGenerator.runAsync();
133
-
134
- // CORDOVA 초기화
135
- if (this._cordova) {
136
- this._logger.debug("CORDOVA 구성...");
137
- await this._cordova.initializeAsync();
138
- }
139
-
140
- // 빌드 준비
141
- const extModules = this._config.builder?.electron ? this._getExternalModules() : [];
142
- const webpackConfigs = await (Object.keys(this._config.builder ?? { web: {} }) as ("web" | "cordova" | "electron")[])
143
- .mapAsync(async (builderType) => await this._getWebpackConfigAsync(true, builderType, extModules));
144
- const multiCompiler = webpack(webpackConfigs);
145
- await new Promise<void>((resolve, reject) => {
146
- // const invalidFiles: string[] = [];
147
- multiCompiler.hooks.invalid.tap(this.constructor.name, (fileName) => {
148
- if (fileName != null) {
149
- this._logger.debug("파일변경 감지", fileName);
150
-
151
- // NgModule 캐시 삭제
152
- this._ngModuleGenerator.removeCaches([path.resolve(fileName)]);
153
-
154
- // invalidFiles.push(fileName);
155
- }
156
- });
157
-
158
- multiCompiler.hooks.watchRun.tapAsync(this.constructor.name, async (args, callback) => {
159
- this.emit("change");
160
-
161
- // NgModule 생성
162
- await this._ngModuleGenerator.runAsync();
163
-
164
- callback();
165
-
166
- this._logger.debug("Webpack 빌드 수행...");
167
- });
168
-
169
- multiCompiler.watch({}, async (err, multiStats) => {
170
- if (err != null || multiStats == null) {
171
- this.emit("complete", [{
172
- filePath: undefined,
173
- line: undefined,
174
- char: undefined,
175
- code: undefined,
176
- severity: "error",
177
- message: err?.stack ?? "알 수 없는 오류 (multiStats=null)"
178
- }]);
179
- reject(err);
180
- return;
181
- }
182
-
183
- // .config.json 파일 쓰기
184
- const npmConfig = this._getNpmConfig(this._rootPath)!;
185
- const packageKey = npmConfig.name.split("/").last()!;
186
-
187
- const configDistPath = typeof this._config.server === "string"
188
- ? path.resolve(this._projRootPath, "packages", this._config.server, "dist/www", packageKey, ".config.json")
189
- : path.resolve(this._parsedTsconfig.options.outDir!, ".config.json");
190
- await FsUtil.writeFileAsync(configDistPath, JSON.stringify(this._config.configs ?? {}, undefined, 2));
191
-
192
- // 완료 로그
193
- this._logger.debug("Webpack 빌드 완료");
194
-
195
- // 결과 반환
196
- const results = multiStats.stats.mapMany((stats) => SdCliBuildResultUtil.convertFromWebpackStats(stats));
197
- this.emit("complete", results);
198
-
199
- resolve();
200
- });
201
- });
202
- }
203
-
204
- public async buildAsync(): Promise<ISdCliPackageBuildResult[]> {
205
- // DIST 비우기
206
- this._logger.debug("removeAsync:1");
207
- await FsUtil.removeAsync(path.resolve(this._rootPath, ".cache", "electron"));
208
- this._logger.debug("removeAsync:2");
209
- await FsUtil.removeAsync(this._parsedTsconfig.options.outDir!);
210
-
211
- // 캐시체크
212
- await this._checkCacheAsync(false);
213
-
214
- // NgModule 생성
215
- this._logger.debug("ngModule");
216
- await this._ngModuleGenerator.runAsync();
217
-
218
- // CORDOVA 초기화
219
- if (this._cordova) {
220
- this._logger.debug("CORDOVA 구성...");
221
- await this._cordova.initializeAsync();
222
- }
223
-
224
- // 빌드
225
- this._logger.debug("Webpack 빌드 수행...");
226
- const extModules = this._config.builder?.electron ? this._getExternalModules() : [];
227
- const builderTypes = (Object.keys(this._config.builder ?? { web: {} }) as ("web" | "cordova" | "electron")[]);
228
- const webpackConfigs = await builderTypes.mapAsync(async (builderType) => await this._getWebpackConfigAsync(false, builderType, extModules));
229
- const multipleCompiler = webpack(webpackConfigs);
230
- const buildResults = await new Promise<ISdCliPackageBuildResult[]>((resolve, reject) => {
231
- multipleCompiler.run((err, multiStats) => {
232
- if (err != null || multiStats == null) {
233
- reject(err);
234
- return;
235
- }
236
-
237
- // 결과 반환
238
- const results = multiStats.stats.mapMany((stats) => SdCliBuildResultUtil.convertFromWebpackStats(stats));
239
- resolve(results);
240
- });
241
- });
242
-
243
- // .config.json 파일 쓰기
244
- const targetPath = path.resolve(this._parsedTsconfig.options.outDir!, ".config.json");
245
- await FsUtil.writeFileAsync(targetPath, JSON.stringify(this._config.configs ?? {}, undefined, 2));
246
-
247
- // service-worker 처리
248
- if (builderTypes.includes("web") && FsUtil.exists(path.resolve(this._rootPath, "ngsw-config.json"))) {
249
- const packageKey = this._getNpmConfig(this._rootPath)!.name.split("/").last()!;
250
- await augmentAppWithServiceWorker(
251
- PathUtil.posix(path.relative(this._projRootPath, this._rootPath)) as any,
252
- PathUtil.posix(this._projRootPath),
253
- PathUtil.posix(path.relative(this._projRootPath, path.resolve(this._parsedTsconfig.options.outDir!))) as any,
254
- `/${packageKey}/` as any,
255
- PathUtil.posix(path.relative(this._projRootPath, path.resolve(this._rootPath, "ngsw-config.json")))
256
- );
257
- }
258
-
259
- // CORDOVA 빌드
260
- if (this._cordova) {
261
- this._logger.debug("CORDOVA 빌드...");
262
- await this._cordova.buildAsync(this._parsedTsconfig.options.outDir!);
263
- }
264
-
265
- // ELECTRON
266
- if (this._config.builder?.electron) {
267
- const npmConfig = this._getNpmConfig(this._rootPath)!;
268
-
269
- const electronVersion = npmConfig.dependencies?.["electron"];
270
- if (electronVersion === undefined) {
271
- throw new Error("ELECTRON 빌드 패키지의 'dependencies'에는 'electron'이 반드시 포함되어야 합니다.");
272
- }
273
-
274
- const dotenvVersion = npmConfig.dependencies?.["dotenv"];
275
- if (dotenvVersion === undefined) {
276
- throw new Error("ELECTRON 빌드 패키지의 'dependencies'에는 'dotenv'가 반드시 포함되어야 합니다.");
277
- }
278
-
279
- // const remoteVersion = npmConfig.dependencies?.["@electron/remote"];
280
-
281
- const electronSrcPath = path.resolve(this._rootPath, `.cache/electron/src`);
282
- const electronDistPath = path.resolve(this._rootPath, `.cache/electron/dist`);
283
-
284
- await FsUtil.writeJsonAsync(path.resolve(electronSrcPath, `package.json`), {
285
- name: npmConfig.name,
286
- version: npmConfig.version,
287
- description: npmConfig.description,
288
- main: "electron.js",
289
- author: npmConfig.author,
290
- license: npmConfig.license/*,
291
- devDependencies: {
292
- "electron": electronVersion.replace("^", "")
293
- },
294
- dependencies: {
295
- "dotenv": dotenvVersion,
296
- ...remoteVersion !== undefined ? {
297
- "@electron/remote": remoteVersion
298
- } : {},
299
- ...extModules.filter((item) => item.exists).map((item) => item.name)
300
- .toObject((item) => item, () => "*")
301
- }*/
302
- }, { space: 2 });
303
- await FsUtil.writeFileAsync(path.resolve(electronSrcPath, "yarn.lock"), "");
304
-
305
- await FsUtil.writeFileAsync(path.resolve(electronSrcPath, `.env`), [
306
- "NODE_ENV=production",
307
- `SD_VERSION=${npmConfig.version}`,
308
- (this._config.builder.electron.icon !== undefined) ? `SD_ELECTRON_ICON=${this._config.builder.electron.icon}` : `SD_ELECTRON_ICON=favicon.ico`,
309
- ...(this._config.env !== undefined) ? Object.keys(this._config.env).map((key) => `${key}=${this._config.env![key]}`) : [],
310
- ...(this._config.builder.electron.env !== undefined) ? Object.keys(this._config.builder.electron.env).map((key) => `${key}=${this._config.builder!.electron!.env![key]}`) : []
311
- ].filterExists().join("\n"));
312
-
313
- /*let electronTsFileContent = await FsUtil.readFileAsync(path.resolve(this._rootPath, `src/electron.ts`));
314
- electronTsFileContent = "require(\"dotenv\").config({ path: `${__dirname}\\\\.env` });\n" + electronTsFileContent;
315
- const result = ts.transpileModule(electronTsFileContent, { compilerOptions: { module: ts.ModuleKind.CommonJS } });
316
- await FsUtil.writeFileAsync(path.resolve(electronSrcPath, "electron.js"), result.outputText);*/
317
-
318
- await electronBuilder.build({
319
- targets: electronBuilder.Platform.WINDOWS.createTarget(),
320
- config: {
321
- appId: this._config.builder.electron.appId,
322
- productName: npmConfig.description,
323
- // asar: false,
324
- win: {
325
- target: "nsis"
326
- },
327
- nsis: {},
328
- directories: {
329
- app: electronSrcPath,
330
- output: electronDistPath
331
- },
332
- ...this._config.builder.electron.installerIcon !== undefined ? {
333
- icon: path.resolve(this._rootPath, "src", this._config.builder.electron.installerIcon)
334
- } : {}
335
- }
336
- });
337
-
338
- await FsUtil.copyAsync(
339
- path.resolve(this._rootPath, `.cache/electron/dist/${npmConfig.description} Setup ${npmConfig.version}.exe`),
340
- path.resolve(this._parsedTsconfig.options.outDir!, `electron/${npmConfig.description}-latest.exe`)
341
- );
342
-
343
- await FsUtil.copyAsync(
344
- path.resolve(this._rootPath, `.cache/electron/dist/${npmConfig.description} Setup ${npmConfig.version}.exe`),
345
- path.resolve(this._parsedTsconfig.options.outDir!, `electron/updates/${npmConfig.version}.exe`)
346
- );
347
- }
348
-
349
- // 마무리
350
- this._logger.debug("Webpack 빌드 완료");
351
- return buildResults;
352
- }
353
-
354
- private _getInternalModuleCachePaths(projName: string): string[] {
355
- return [
356
- ...FsUtil.findAllParentChildDirPaths("node_modules/*/package.json", this._rootPath, this._projRootPath),
357
- ...FsUtil.findAllParentChildDirPaths(`node_modules/!(@simplysm|@${projName})/*/package.json`, this._rootPath, this._projRootPath),
358
- ].map((p) => path.dirname(p));
359
- }
360
-
361
- private async _getWebpackConfigAsync(watch: boolean, builderType: "web" | "cordova" | "electron", extModules: { name: string; exists: boolean }[]): Promise<webpack.Configuration> {
362
- const projNpmConfig = this._getNpmConfig(this._projRootPath)!;
363
- const projName = projNpmConfig.name;
364
-
365
- const internalModuleCachePaths = watch ? this._getInternalModuleCachePaths(projName) : undefined;
366
-
367
- const npmConfig = this._getNpmConfig(this._rootPath)!;
368
-
369
- const projPkgLockContent = FsUtil.readFile(path.resolve(this._projRootPath, "yarn.lock"));
370
-
371
- const pkgKey = npmConfig.name.split("/").last()!;
372
- const publicPath = builderType === "web" ? `/${pkgKey}/` : watch ? `/${pkgKey}/${builderType}/` : ``;
373
-
374
- const distPath = (builderType === "cordova" && !watch) ? path.resolve(this._cordova!.cordovaPath, "www")
375
- : (builderType === "electron" && !watch) ? path.resolve(this._rootPath, ".cache/electron/src")
376
- : builderType === "web" ? this._parsedTsconfig.options.outDir
377
- : `${this._parsedTsconfig.options.outDir}/${builderType}`;
378
-
379
- const sassImplementation = new SassWorkerImplementation();
380
-
381
- const mainFilePath = path.resolve(this._rootPath, "src/main.ts");
382
- const polyfillsFilePath = path.resolve(this._rootPath, "src/polyfills.ts");
383
- const stylesFilePath = path.resolve(this._rootPath, "src/styles.scss");
384
-
385
- const versionHash = createHash("sha1")
386
- .update(projPkgLockContent)
387
- .update(JSON.stringify(this._parsedTsconfig.options))
388
- .update(JSON.stringify(this._config))
389
- .update(watch.toString())
390
- .digest("hex");
391
- if (
392
- !FsUtil.exists(path.resolve(this._cacheBasePath, "version")) // 버전파일이 없거나
393
- || (
394
- FsUtil.exists(path.resolve(this._cacheBasePath, "version")) &&
395
- FsUtil.readFile(path.resolve(this._cacheBasePath, "version")) !== versionHash
396
- ) // 버전이 현재 버전과 다르면
397
- ) {
398
- // 캐시 삭제
399
- FsUtil.remove(path.resolve(this._cacheBasePath));
400
- }
401
- // 버전쓰기
402
- FsUtil.writeFile(path.resolve(this._cacheBasePath, "version"), versionHash);
403
-
404
- let prevProgressMessage = "";
405
- return {
406
- mode: watch ? "development" : "production",
407
- devtool: false,
408
- target: builderType === "electron" ? ["electron-renderer", "electron-main", "es2015"] : ["web", "es2015"],
409
- profile: false,
410
- resolve: {
411
- roots: [this._rootPath],
412
- extensions: [".ts", ".tsx", ".mjs", ".cjs", ".js", ".jsx"],
413
- symlinks: true,
414
- modules: [this._projRootPath, "node_modules"],
415
- mainFields: ["es2020", "es2015", "browser", "module", "main"],
416
- conditionNames: ["es2020", "es2015", "..."]
417
- },
418
- resolveLoader: {
419
- symlinks: true
420
- },
421
- context: this._projRootPath,
422
- entry: {
423
- main: [mainFilePath],
424
- ...FsUtil.exists(polyfillsFilePath) ? { polyfills: [polyfillsFilePath] } : {},
425
- ...FsUtil.exists(stylesFilePath) ? { styles: [stylesFilePath] } : {},
426
- ...builderType === "cordova" ? { "cordova-entry": path.resolve(path.dirname(fileURLToPath(import.meta.url)), `../../lib/cordova-entry.js`) } : {},
427
- ...builderType === "electron" ? { "electron": path.resolve(this._rootPath, "src/electron.ts") } : {}
428
- },
429
- output: {
430
- uniqueName: pkgKey,
431
- hashFunction: "xxhash64",
432
- clean: true,
433
- path: distPath,
434
- publicPath,
435
- filename: "[name].js",
436
- chunkFilename: "[name].js",
437
- libraryTarget: undefined,
438
- crossOriginLoading: false,
439
- trustedTypes: "angular#bundler",
440
- scriptType: "module"
441
- },
442
- watch: false,
443
- watchOptions: {
444
- poll: undefined,
445
- ignored: undefined
446
- },
447
- performance: { hints: false },
448
- ignoreWarnings: [
449
- /Failed to parse source map from/,
450
- /Add postcss as project dependency/,
451
- /"@charset" must be the first rule in the file/
452
- ],
453
- experiments: {
454
- backCompat: false,
455
- syncWebAssembly: true,
456
- asyncWebAssembly: true
457
- },
458
- infrastructureLogging: { level: "error" },
459
- stats: "errors-warnings",
460
- // externals: extModules.toObject((item) => item.name, (item) => item.exists ? "commonjs2 " + item.name : `var {name: '${item.name}'}`),
461
- externals: {
462
- ...extModules.toObject((item) => item.name, (item) => "commonjs2 " + item.name),
463
- ...builderType === "electron" ? {
464
- "electron": "commonjs2 electron"
465
- } : {}
466
- },
467
- cache: {
468
- type: "filesystem",
469
- profile: undefined,
470
- cacheDirectory: this._cacheBasePath,
471
- maxMemoryGenerations: 1,
472
- name: "webpack"
473
- },
474
- snapshot: {
475
- immutablePaths: internalModuleCachePaths,
476
- managedPaths: internalModuleCachePaths
477
- },
478
- node: false,
479
- optimization: {
480
- minimizer: watch ? [] : [
481
- new JavaScriptOptimizerPlugin({
482
- define: {
483
- ngDevMode: false,
484
- ngI18nClosureMode: false,
485
- ngJitMode: false
486
- },
487
- sourcemap: false,
488
- target: ts.ScriptTarget.ES2017,
489
- keepIdentifierNames: true,
490
- keepNames: true,
491
- removeLicenses: true,
492
- advanced: true
493
- }),
494
- new TransferSizePlugin(),
495
- new CssOptimizerPlugin({
496
- supportedBrowsers: browserslist([
497
- "last 1 Chrome versions",
498
- "last 2 Edge major versions"
499
- ], { path: this._projRootPath })
500
- })
501
- ] as any[],
502
- moduleIds: "deterministic",
503
- chunkIds: watch ? "named" : "deterministic",
504
- emitOnErrors: watch,
505
- runtimeChunk: "single",
506
- splitChunks: {
507
- maxAsyncRequests: Infinity,
508
- cacheGroups: {
509
- default: {
510
- chunks: "async",
511
- minChunks: 2,
512
- priority: 10
513
- },
514
- common: {
515
- name: "common",
516
- chunks: "async",
517
- minChunks: 2,
518
- enforce: true,
519
- priority: 5
520
- },
521
- vendors: false,
522
- defaultVendors: watch ? {
523
- name: "vendor",
524
- chunks: (chunk) => chunk.name === "main",
525
- enforce: true,
526
- test: /[\\/]node_modules[\\/]/
527
- } : false
528
- }
529
- }
530
- },
531
- module: {
532
- strictExportPresence: true,
533
- parser: { javascript: { url: false, worker: false } },
534
- rules: [
535
- {
536
- test: /\.?(svg|html)$/,
537
- resourceQuery: /\?ngResource/,
538
- type: "asset/source"
539
- },
540
- {
541
- test: /[/\\]rxjs[/\\]add[/\\].+\.js$/,
542
- sideEffects: true
543
- },
544
- {
545
- test: /\.[cm]?[tj]sx?$/,
546
- resolve: { fullySpecified: false },
547
- exclude: [/[/\\](?:core-js|@babel|tslib|web-animations-js|web-streams-polyfill)[/\\]/],
548
- use: [
549
- {
550
- loader: fileURLToPath(await import.meta.resolve!("@angular-devkit/build-angular/src/babel/webpack-loader")),
551
- options: {
552
- cacheDirectory: path.resolve(this._cacheBasePath, "webpack-babel"),
553
- scriptTarget: ts.ScriptTarget.ES2017,
554
- aot: true,
555
- optimize: !watch,
556
- instrumentCode: undefined
557
- }
558
- }
559
- ]
560
- },
561
- ...watch ? [
562
- {
563
- test: /\.[cm]?jsx?$/,
564
- enforce: "pre" as const,
565
- loader: fileURLToPath(await import.meta.resolve!("source-map-loader")),
566
- options: {
567
- filterSourceMappingUrl: (mapUri: string, resourcePath: string) => {
568
- const projRegex = new RegExp(`node_modules[\\\\/]@${projName}[\\\\/]`);
569
- return !resourcePath.includes("node_modules")
570
- || (/node_modules[\\/]@simplysm[\\/]/).test(resourcePath)
571
- || projRegex.test(resourcePath);
572
- }
573
- }
574
- }
575
- ] : [],
576
- {
577
- test: /\.[cm]?tsx?$/,
578
- loader: fileURLToPath(await import.meta.resolve!("@ngtools/webpack")),
579
- exclude: [/[/\\](?:css-loader|mini-css-extract-plugin|webpack)[/\\]/]
580
- },
581
- {
582
- test: /\.css$/i,
583
- type: "asset/source"
584
- },
585
- {
586
- test: /\.scss$/i,
587
- rules: [
588
- {
589
- oneOf: [
590
- {
591
- use: [
592
- {
593
- loader: MiniCssExtractPlugin.loader
594
- },
595
- {
596
- loader: fileURLToPath(await import.meta.resolve!("css-loader")),
597
- options: { url: false, sourceMap: watch }
598
- }
599
- ],
600
- include: [stylesFilePath],
601
- resourceQuery: { not: [/\?ngResource/] }
602
- },
603
- {
604
- type: "asset/source",
605
- resourceQuery: /\?ngResource/
606
- }
607
- ]
608
- },
609
- {
610
- use: [
611
- {
612
- loader: fileURLToPath(await import.meta.resolve!("resolve-url-loader")),
613
- options: { sourceMap: watch }
614
- },
615
- {
616
- loader: fileURLToPath(await import.meta.resolve!("sass-loader")),
617
- options: {
618
- implementation: sassImplementation,
619
- sourceMap: true,
620
- sassOptions: {
621
- fiber: false,
622
- precision: 8,
623
- includePaths: [],
624
- outputStyle: "expanded",
625
- quietDeps: true,
626
- verbose: watch ? undefined : false
627
- }
628
- }
629
- }
630
- ]
631
- }
632
- ]
633
- },
634
- {
635
- test: /\.(png|jpe?g|gif|svg|woff|woff2|ttf|eot|ico|otf|csv|xlsx?|pptx?|docx?|zip|pfx|pkl)$/,
636
- type: "asset/resource"
637
- }
638
- ]
639
- },
640
- plugins: [
641
- new NodePolyfillPlugin({
642
- excludeAliases: builderType === "electron" ? ["process"] : []
643
- }),
644
- new NamedChunksPlugin(),
645
- new DedupeModuleResolvePlugin(),
646
- new webpack.ProgressPlugin({
647
- handler: (per: number, msg: string, ...args: string[]) => {
648
- const phaseText = msg ? ` - phase: ${msg}` : "";
649
- const argsText = args.length > 0 ? ` - args: [${args.join(", ")}]` : "";
650
- const progressMessage = `Webpack 빌드 수행중...(${Math.round(per * 100)}%)${phaseText}${argsText}`;
651
- if (progressMessage !== prevProgressMessage) {
652
- prevProgressMessage = progressMessage;
653
- this._logger.debug(progressMessage);
654
- }
655
- }
656
- }),
657
- ...watch ? [] : [
658
- new LicenseWebpackPlugin({
659
- stats: { warnings: false, errors: false },
660
- perChunkOutput: false,
661
- outputFilename: "3rdpartylicenses.txt",
662
- skipChildCompilers: true
663
- })
664
- ],
665
- new CopyWebpackPlugin({
666
- patterns: [
667
- ...["favicon.ico", "assets/", "manifest.json"].map((item) => ({
668
- context: this._rootPath,
669
- to: item,
670
- from: `src/${item}`,
671
- noErrorOnMissing: true,
672
- force: true,
673
- globOptions: {
674
- dot: true,
675
- followSymbolicLinks: false,
676
- ignore: [
677
- ".gitkeep",
678
- "**/.DS_Store",
679
- "**/Thumbs.db"
680
- ].map((i) => PathUtil.posix(this._rootPath, i))
681
- },
682
- priority: 0
683
- })),
684
- ...builderType === "cordova" && watch ? this._cordova!.platforms.mapMany((platform) => [
685
- {
686
- context: this._cordova!.cordovaPath,
687
- to: `cordova-${platform}/plugins`,
688
- from: `platforms/${platform}/platform_www/plugins`,
689
- noErrorOnMissing: true
690
- },
691
- {
692
- context: this._cordova!.cordovaPath,
693
- to: `cordova-${platform}/cordova.js`,
694
- from: `platforms/${platform}/platform_www/cordova.js`
695
- },
696
- {
697
- context: this._cordova!.cordovaPath,
698
- to: `cordova-${platform}/cordova_plugins.js`,
699
- from: `platforms/${platform}/platform_www/cordova_plugins.js`,
700
- noErrorOnMissing: true
701
- },
702
- {
703
- context: this._cordova!.cordovaPath,
704
- to: `cordova-${platform}/config.xml`,
705
- from: `platforms/${platform}/www/config.xml`,
706
- noErrorOnMissing: true
707
- }
708
- ]) : []
709
- ]
710
- }),
711
- ...watch ? [
712
- new webpack.SourceMapDevToolPlugin({
713
- filename: "[file].map",
714
- include: [/js$/, /css$/],
715
- sourceRoot: "webpack:///",
716
- moduleFilenameTemplate: "[resource-path]",
717
- append: undefined
718
- })
719
- ] : [],
720
- new AngularWebpackPlugin({
721
- tsconfig: this._tsconfigFilePath,
722
- compilerOptions: {
723
- sourceMap: watch,
724
- declaration: false,
725
- declarationMap: false,
726
- preserveSymlinks: false
727
- },
728
- jitMode: false,
729
- emitNgModuleScope: watch,
730
- inlineStyleFileExtension: "scss"
731
- }),
732
- {
733
- apply: (compiler: webpack.Compiler) => {
734
- compiler.hooks.shutdown.tap("sass-worker", () => {
735
- sassImplementation.close();
736
- });
737
- }
738
- },
739
- new MiniCssExtractPlugin({ filename: "[name].css" }),
740
- new SuppressExtractedTextChunksWebpackPlugin(),
741
- new IndexHtmlWebpackPlugin({
742
- indexPath: path.resolve(this._rootPath, "src/index.html"),
743
- outputPath: "index.html",
744
- baseHref: publicPath,
745
- entrypoints: [
746
- ["runtime", !watch],
747
- ["polyfills", true],
748
- ["styles", false],
749
- ["vendor", true],
750
- ["main", true],
751
- ...builderType === "cordova" ? [
752
- ["cordova-entry", true] as Entrypoint
753
- ] : []
754
- ],
755
- deployUrl: undefined,
756
- sri: false,
757
- cache: {
758
- enabled: true,
759
- basePath: this._cacheBasePath,
760
- path: path.resolve(this._cacheBasePath, "webpack-html")
761
- },
762
- postTransform: undefined,
763
- optimization: {
764
- scripts: !watch,
765
- styles: { minify: !watch, inlineCritical: !watch },
766
- fonts: { inline: !watch }
767
- },
768
- crossOrigin: "none",
769
- lang: undefined
770
- }),
771
- new webpack.EnvironmentPlugin({
772
- SD_VERSION: this._getNpmConfig(this._rootPath)!.version,
773
- ...this._config.env,
774
- ...this._config.builder?.[builderType]?.env
775
- }),
776
-
777
- new ESLintWebpackPlugin({
778
- context: this._rootPath,
779
- eslintPath: path.resolve(this._projRootPath, "node_modules", "eslint"),
780
- exclude: ["node_modules"],
781
- extensions: ["ts", "js", "mjs", "cjs"],
782
- fix: false,
783
- threads: false,
784
- formatter: (results: LintResult[]) => {
785
- const resultMessages: string[] = [];
786
- for (const result of results) {
787
- for (const msg of result.messages) {
788
- const severity = msg.severity === 1 ? "warning" : msg.severity === 2 ? "error" : undefined;
789
- if (severity === undefined) continue;
790
-
791
- resultMessages.push(SdCliBuildResultUtil.getMessage({
792
- filePath: result.filePath,
793
- line: msg.line,
794
- char: msg.column,
795
- code: msg.ruleId?.toString(),
796
- severity,
797
- message: msg.message
798
- }));
799
- }
800
- }
801
- return resultMessages.join(os.EOL);
802
- }
803
- })
804
- ] as any[]
805
- };
806
- }
807
-
808
- private _getExternalModules(): { name: string; exists: boolean }[] {
809
- const loadedModuleNames: string[] = [];
810
- const results: { name: string; exists: boolean }[] = [];
811
-
812
- const fn = (currPath: string): void => {
813
- const npmConfig = this._getNpmConfig(currPath);
814
- if (!npmConfig) return;
815
-
816
- const deps = SdCliNpmConfigUtil.getDependencies(npmConfig);
817
-
818
- for (const moduleName of deps.defaults) {
819
- if (loadedModuleNames.includes(moduleName)) continue;
820
- loadedModuleNames.push(moduleName);
821
-
822
- const modulePath = FsUtil.findAllParentChildDirPaths("node_modules/" + moduleName, currPath, this._projRootPath).first();
823
- if (StringUtil.isNullOrEmpty(modulePath)) {
824
- continue;
825
- }
826
-
827
- if (FsUtil.glob(path.resolve(modulePath, "**/binding.gyp")).length > 0) {
828
- results.push({ name: moduleName, exists: true });
829
- }
830
-
831
- if (this._config.builder?.electron?.externalNodeModules?.includes(moduleName)) {
832
- results.push({ name: moduleName, exists: true });
833
- }
834
-
835
- fn(modulePath);
836
- }
837
-
838
- for (const optModuleName of deps.optionals) {
839
- if (loadedModuleNames.includes(optModuleName)) continue;
840
- loadedModuleNames.push(optModuleName);
841
-
842
- const optModulePath = FsUtil.findAllParentChildDirPaths("node_modules/" + optModuleName, currPath, this._projRootPath).first();
843
- if (StringUtil.isNullOrEmpty(optModulePath)) {
844
- results.push({ name: optModuleName, exists: false });
845
- continue;
846
- }
847
-
848
- if (FsUtil.glob(path.resolve(optModulePath, "**/binding.gyp")).length > 0) {
849
- results.push({ name: optModuleName, exists: true });
850
- }
851
-
852
- if (this._config.builder?.electron?.externalNodeModules?.includes(optModuleName)) {
853
- results.push({ name: optModuleName, exists: true });
854
- }
855
-
856
- fn(optModulePath);
857
- }
858
- };
859
-
860
- fn(this._rootPath);
861
-
862
- return results;
863
- }
864
-
865
- private _getNpmConfig(pkgPath: string): INpmConfig | undefined {
866
- if (!this._npmConfigMap.has(pkgPath)) {
867
- this._npmConfigMap.set(pkgPath, FsUtil.readJson(path.resolve(pkgPath, "package.json")));
868
- }
869
- return this._npmConfigMap.get(pkgPath);
870
- }
871
- }