@simplysm/sd-cli 7.0.24 → 7.0.38

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 (35) hide show
  1. package/dist/bin/sd-cli.mjs +2 -1
  2. package/dist/build-tool/SdCliNgCacheCompilerHost.mjs +2 -2
  3. package/dist/builder/SdCliClientBuilder.d.ts +20 -0
  4. package/dist/builder/SdCliClientBuilder.mjs +417 -0
  5. package/dist/builder/SdCliJsLibBuilder.mjs +2 -2
  6. package/dist/builder/SdCliServerBuilder.d.ts +7 -4
  7. package/dist/builder/SdCliServerBuilder.mjs +232 -92
  8. package/dist/builder/SdCliTsLibBuilder.d.ts +5 -3
  9. package/dist/builder/SdCliTsLibBuilder.mjs +17 -18
  10. package/dist/commons.d.ts +13 -1
  11. package/dist/entry-points/SdCliLocalUpdate.mjs +15 -9
  12. package/dist/entry-points/SdCliNpm.mjs +8 -4
  13. package/dist/entry-points/SdCliPrepare.mjs +3 -2
  14. package/dist/entry-points/SdCliWorkspace.d.ts +1 -0
  15. package/dist/entry-points/SdCliWorkspace.mjs +55 -23
  16. package/dist/packages/SdCliPackage.d.ts +5 -4
  17. package/dist/packages/SdCliPackage.mjs +27 -28
  18. package/dist/utils/SdCliBuildResultUtil.mjs +3 -4
  19. package/dist/utils/SdCliNpmConfigUtil.d.ts +4 -1
  20. package/dist/utils/SdCliNpmConfigUtil.mjs +12 -8
  21. package/package.json +19 -8
  22. package/src/bin/sd-cli.ts +1 -0
  23. package/src/build-tool/SdCliNgCacheCompilerHost.ts +1 -1
  24. package/src/builder/SdCliClientBuilder.ts +451 -0
  25. package/src/builder/SdCliJsLibBuilder.ts +1 -1
  26. package/src/builder/SdCliServerBuilder.ts +260 -91
  27. package/src/builder/SdCliTsLibBuilder.ts +26 -21
  28. package/src/commons.ts +10 -1
  29. package/src/entry-points/SdCliLocalUpdate.ts +14 -8
  30. package/src/entry-points/SdCliNpm.ts +7 -3
  31. package/src/entry-points/SdCliPrepare.ts +2 -1
  32. package/src/entry-points/SdCliWorkspace.ts +63 -24
  33. package/src/packages/SdCliPackage.ts +29 -34
  34. package/src/utils/SdCliBuildResultUtil.ts +2 -3
  35. package/src/utils/SdCliNpmConfigUtil.ts +11 -7
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@simplysm/sd-cli",
3
- "version": "7.0.24",
3
+ "version": "7.0.38",
4
4
  "description": "심플리즘 패키지 - CLI",
5
5
  "author": "김석래",
6
6
  "repository": {
@@ -21,7 +21,6 @@
21
21
  },
22
22
  "dependencies": {
23
23
  "@angular/compiler-cli": "^13.2.0",
24
- "chokidar": "^3.5.3",
25
24
  "eslint": "^8.7.0",
26
25
  "sass": "^1.49.0",
27
26
  "semver": "^7.3.5",
@@ -32,19 +31,31 @@
32
31
  "yargs": "^17.3.1",
33
32
  "webpack": "^5.68.0",
34
33
  "ts-loader": "^9.2.6",
35
- "webpack-merge": "^5.8.0",
36
34
  "terser-webpack-plugin": "^5.3.1",
37
35
  "copy-webpack-plugin": "^10.2.4",
38
36
  "eslint-webpack-plugin": "^3.1.1",
39
- "source-map-loader": "^3.0.1"
37
+ "source-map-loader": "^3.0.1",
38
+ "license-webpack-plugin": "^4.0.1",
39
+ "@angular-devkit/build-angular": "^13.2.2",
40
+ "browserslist": "^4.19.1",
41
+ "mini-css-extract-plugin": "^2.5.3",
42
+ "@ngtools/webpack": "^13.2.2",
43
+ "webpack-dev-middleware": "^5.3.1",
44
+ "webpack-hot-middleware": "^2.25.1",
45
+ "css-loader": "^6.6.0",
46
+ "resolve-url-loader": "^5.0.0",
47
+ "sass-loader": "^12.4.0",
48
+ "connect": "^3.7.0"
40
49
  },
41
50
  "devDependencies": {
42
51
  "@types/semver": "^7.3.9",
43
- "@types/yargs": "^17.0.8"
52
+ "@types/yargs": "^17.0.8",
53
+ "@types/webpack-hot-middleware": "^2.25.5",
54
+ "@types/connect": "^3.4.35"
44
55
  },
45
56
  "peerDependencies": {
46
- "@simplysm/sd-core-common": "7.0.24",
47
- "@simplysm/sd-core-node": "7.0.24",
48
- "@simplysm/sd-service": "7.0.24"
57
+ "@simplysm/sd-core-common": "7.0.38",
58
+ "@simplysm/sd-core-node": "7.0.38",
59
+ "@simplysm/sd-service": "7.0.38"
49
60
  }
50
61
  }
package/src/bin/sd-cli.ts CHANGED
@@ -145,6 +145,7 @@ const logger = Logger.get(["simplysm", "sd-cli", "bin", "sd-cli"]);
145
145
  confFileRelPath: argv.config ?? "simplysm.json",
146
146
  optNames: argv.options ?? []
147
147
  });
148
+ process.exit(0);
148
149
  }
149
150
  else if (argv._[0] === "publish") {
150
151
  await new SdCliWorkspace(process.cwd())
@@ -17,7 +17,7 @@ export class SdCliNgCacheCompilerHost {
17
17
  };
18
18
 
19
19
  cacheCompilerHost["transformResource"] = async (data, context) => {
20
- if (context.resourceFile || context.type !== "style") {
20
+ if (context.resourceFile != null || context.type !== "style") {
21
21
  return null;
22
22
  }
23
23
 
@@ -0,0 +1,451 @@
1
+ import { INpmConfig, ISdCliClientPackageConfig, ISdCliPackageBuildResult } 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
+ AnyComponentStyleBudgetChecker,
11
+ CommonJsUsageWarnPlugin,
12
+ DedupeModuleResolvePlugin,
13
+ SuppressExtractedTextChunksWebpackPlugin
14
+ } from "@angular-devkit/build-angular/src/webpack/plugins";
15
+ import CopyWebpackPlugin from "copy-webpack-plugin";
16
+ import MiniCssExtractPlugin from "mini-css-extract-plugin";
17
+ import { AngularWebpackPlugin } from "@ngtools/webpack";
18
+ import { IndexHtmlWebpackPlugin } from "@angular-devkit/build-angular/src/webpack/plugins/index-html-webpack-plugin";
19
+ import { createHash } from "crypto";
20
+ import { SassWorkerImplementation } from "@angular-devkit/build-angular/src/sass/sass-service";
21
+ import { HmrLoader } from "@angular-devkit/build-angular/src/webpack/plugins/hmr/hmr-loader";
22
+ import wdm from "webpack-dev-middleware";
23
+ import whm from "webpack-hot-middleware";
24
+ import { NextHandleFunction } from "connect";
25
+ import { LicenseWebpackPlugin } from "license-webpack-plugin";
26
+ import { Type } from "@angular-devkit/build-angular";
27
+
28
+ export class SdCliClientBuilder extends EventEmitter {
29
+ private readonly _logger = Logger.get(["simplysm", "sd-cli", this.constructor.name]);
30
+
31
+ private readonly _tsconfigFilePath: string;
32
+ private readonly _parsedTsconfig: ts.ParsedCommandLine;
33
+ private readonly _npmConfigMap = new Map<string, INpmConfig>();
34
+
35
+ public constructor(private readonly _rootPath: string,
36
+ private readonly _config: ISdCliClientPackageConfig,
37
+ private readonly _workspaceRootPath: string) {
38
+ super();
39
+
40
+ // tsconfig
41
+ this._tsconfigFilePath = path.resolve(this._rootPath, "tsconfig-build.json");
42
+ const tsconfig = FsUtil.readJson(this._tsconfigFilePath);
43
+ this._parsedTsconfig = ts.parseJsonConfigFileContent(tsconfig, ts.sys, this._rootPath);
44
+ }
45
+
46
+ public override on(event: "change", listener: () => void): this;
47
+ public override on(event: "complete", listener: (results: ISdCliPackageBuildResult[]) => void): this;
48
+ public override on(event: string | symbol, listener: (...args: any[]) => void): this {
49
+ return super.on(event, listener);
50
+ }
51
+
52
+ public async watchAsync(): Promise<NextHandleFunction[]> {
53
+ // DIST 비우기
54
+ await FsUtil.removeAsync(this._parsedTsconfig.options.outDir!);
55
+
56
+ // 빌드 준비
57
+ const webpackConfig = this._getWebpackConfig(true);
58
+ const compiler = webpack(webpackConfig);
59
+ return await new Promise<NextHandleFunction[]>((resolve, reject) => {
60
+ compiler.hooks.watchRun.tapAsync(this.constructor.name, (args, callback) => {
61
+ this.emit("change");
62
+ callback();
63
+
64
+ this._logger.debug("Webpack 빌드 수행...");
65
+ });
66
+
67
+ compiler.hooks.failed.tap(this.constructor.name, (err) => {
68
+ reject(err);
69
+ return;
70
+ });
71
+
72
+ compiler.hooks.done.tap(this.constructor.name, (stats) => {
73
+ // 결과 반환
74
+ const results = SdCliBuildResultUtil.convertFromWebpackStats(stats);
75
+ this.emit("complete", results);
76
+
77
+ // 마무리
78
+ this._logger.debug("Webpack 빌드 완료");
79
+ resolve([devMiddleware, hotMiddleware]);
80
+ });
81
+
82
+ const devMiddleware = wdm(compiler, {
83
+ publicPath: webpackConfig.output!.publicPath as string,
84
+ index: "index.html",
85
+ stats: false
86
+ });
87
+
88
+ const hotMiddleware = whm(compiler, {
89
+ path: `${webpackConfig.output!.publicPath as string}__webpack_hmr`,
90
+ log: false
91
+ });
92
+ });
93
+ }
94
+
95
+ public async buildAsync(): Promise<ISdCliPackageBuildResult[]> {
96
+ // DIST 비우기
97
+ await FsUtil.removeAsync(this._parsedTsconfig.options.outDir!);
98
+
99
+ // 빌드
100
+ this._logger.debug("Webpack 빌드 수행...");
101
+ const webpackConfig = this._getWebpackConfig(false);
102
+ const compiler = webpack(webpackConfig);
103
+ const buildResults = await new Promise<ISdCliPackageBuildResult[]>((resolve, reject) => {
104
+ compiler.run((err, stats) => {
105
+ if (err != null || stats == null) {
106
+ reject(err);
107
+ return;
108
+ }
109
+
110
+ // 결과 반환
111
+ const results = SdCliBuildResultUtil.convertFromWebpackStats(stats);
112
+ resolve(results);
113
+ });
114
+ });
115
+
116
+ // 마무리
117
+ this._logger.debug("Webpack 빌드 완료");
118
+ return buildResults;
119
+ }
120
+
121
+ private _getWebpackConfig(watch: boolean): webpack.Configuration {
122
+ const npmConfig = this._getNpmConfig(this._rootPath)!;
123
+ const pkgVersion = npmConfig.version;
124
+
125
+ const pkgKey = npmConfig.name.split("/").last()!;
126
+ const publicPath = `/${pkgKey}/`;
127
+
128
+ const cacheBasePath = path.resolve(this._rootPath, ".angular");
129
+ const cachePath = path.resolve(cacheBasePath, pkgVersion);
130
+
131
+ const distPath = this._parsedTsconfig.options.outDir;
132
+
133
+ const sassImplementation = new SassWorkerImplementation();
134
+
135
+ const mainFilePath = path.resolve(this._rootPath, "src/main.ts");
136
+ const polyfillsFilePath = path.resolve(this._rootPath, "src/polyfills.ts");
137
+ const stylesFilePath = path.resolve(this._rootPath, "src/styles.scss");
138
+
139
+ return {
140
+ mode: watch ? "development" : "production",
141
+ devtool: false,
142
+ target: ["web", "es2015"],
143
+ profile: false,
144
+ resolve: {
145
+ roots: [this._rootPath],
146
+ extensions: [".ts", ".tsx", ".mjs", ".js"],
147
+ symlinks: true,
148
+ modules: [this._workspaceRootPath, "node_modules"],
149
+ mainFields: ["es2015", "browser", "module", "main"],
150
+ conditionNames: ["es2015", "..."]
151
+ },
152
+ resolveLoader: {
153
+ symlinks: true
154
+ },
155
+ context: this._workspaceRootPath,
156
+ entry: {
157
+ main: [
158
+ ...watch ? [
159
+ `webpack-hot-middleware/client?path=${publicPath}__webpack_hmr&timeout=20000&reload=true&overlay=true`,
160
+ ] : [],
161
+ mainFilePath
162
+ ],
163
+ ...FsUtil.exists(polyfillsFilePath) ? { polyfills: polyfillsFilePath } : {},
164
+ ...FsUtil.exists(stylesFilePath) ? { styles: stylesFilePath } : {}
165
+ },
166
+ output: {
167
+ uniqueName: pkgKey,
168
+ hashFunction: "xxhash64",
169
+ clean: true,
170
+ path: distPath,
171
+ publicPath,
172
+ filename: "[name].js",
173
+ chunkFilename: "[name].js",
174
+ libraryTarget: undefined,
175
+ crossOriginLoading: false,
176
+ trustedTypes: "angular#bundler",
177
+ scriptType: "module",
178
+ },
179
+ watch: false,
180
+ watchOptions: { poll: undefined, ignored: undefined },
181
+ performance: { hints: false },
182
+ ignoreWarnings: [
183
+ /Failed to parse source map from/,
184
+ /Add postcss as project dependency/,
185
+ /"@charset" must be the first rule in the file/,
186
+ ],
187
+ experiments: { backCompat: false, syncWebAssembly: true, asyncWebAssembly: true },
188
+ infrastructureLogging: { level: "error" },
189
+ stats: "errors-warnings",
190
+ cache: {
191
+ type: "filesystem",
192
+ profile: watch ? undefined : false,
193
+ cacheDirectory: path.resolve(cachePath, "angular-webpack"),
194
+ maxMemoryGenerations: 1,
195
+ name: createHash("sha1").update(pkgVersion).digest("hex")
196
+ },
197
+ node: false,
198
+ optimization: {
199
+ minimizer: [],
200
+ moduleIds: "deterministic",
201
+ chunkIds: watch ? "named" : "deterministic",
202
+ emitOnErrors: watch,
203
+ runtimeChunk: "single",
204
+ splitChunks: {
205
+ maxAsyncRequests: Infinity,
206
+ cacheGroups: {
207
+ default: {
208
+ chunks: "async",
209
+ minChunks: 2,
210
+ priority: 10
211
+ },
212
+ common: {
213
+ name: "common",
214
+ chunks: "async",
215
+ minChunks: 2,
216
+ enforce: true,
217
+ priority: 5
218
+ },
219
+ vendors: false,
220
+ defaultVendors: watch ? {
221
+ name: "vendor",
222
+ chunks: (chunk) => chunk.name === "main",
223
+ enforce: true,
224
+ test: /[\\/]node_modules[\\/]/
225
+ } : false
226
+ }
227
+ }
228
+ },
229
+ plugins: [
230
+ new NamedChunksPlugin(),
231
+ new DedupeModuleResolvePlugin(),
232
+ /*new webpack.ProgressPlugin({
233
+ handler: (per: number, msg: string, ...args: string[]) => {
234
+ const phaseText = msg ? ` - phase: ${msg}` : "";
235
+ const argsText = args.length > 0 ? ` - args: [${args.join(", ")}]` : "";
236
+ this._logger.debug(`Webpack 빌드 수행중...(${Math.round(per * 100)}%)${phaseText}${argsText}`);
237
+ }
238
+ }),*/
239
+ new CommonJsUsageWarnPlugin(),
240
+ ...watch ? [] : [
241
+ new LicenseWebpackPlugin({
242
+ stats: { warnings: false, errors: false, },
243
+ perChunkOutput: false,
244
+ outputFilename: "3rdpartylicenses.txt",
245
+ skipChildCompilers: true
246
+ })
247
+ ],
248
+ new CopyWebpackPlugin({
249
+ patterns: [
250
+ ...["favicon.ico", "assets/", "manifest.webmanifest"].map((item) => ({
251
+ context: this._rootPath,
252
+ to: item,
253
+ from: `src/${item}`,
254
+ noErrorOnMissing: true,
255
+ force: true,
256
+ globOptions: {
257
+ dot: true,
258
+ followSymbolicLinks: false,
259
+ ignore: [
260
+ ".gitkeep",
261
+ "**/.DS_Store",
262
+ "**/Thumbs.db"
263
+ ].map((i) => PathUtil.posix(this._rootPath, i))
264
+ },
265
+ priority: 0
266
+ }))
267
+ ]
268
+ }),
269
+ ...watch ? [
270
+ new webpack.SourceMapDevToolPlugin({
271
+ filename: "[file].map",
272
+ include: [/js$/, /css$/],
273
+ sourceRoot: "webpack:///",
274
+ moduleFilenameTemplate: "[resource-path]",
275
+ append: undefined,
276
+ })
277
+ ] : [],
278
+ new AngularWebpackPlugin({
279
+ tsconfig: this._tsconfigFilePath,
280
+ compilerOptions: {
281
+ sourceMap: watch,
282
+ declaration: false,
283
+ declarationMap: false,
284
+ preserveSymlinks: false
285
+ },
286
+ jitMode: false,
287
+ emitNgModuleScope: watch,
288
+ inlineStyleFileExtension: "scss"
289
+ }),
290
+ new AnyComponentStyleBudgetChecker(watch ? [] : [
291
+ { type: Type.AnyComponentStyle, maximumWarning: "2kb", maximumError: "4kb" }
292
+ ]),
293
+ {
294
+ apply: (compiler: webpack.Compiler) => {
295
+ compiler.hooks.shutdown.tap("sass-worker", () => {
296
+ sassImplementation.close();
297
+ });
298
+ }
299
+ },
300
+ new MiniCssExtractPlugin({ filename: "[name].css" }),
301
+ new SuppressExtractedTextChunksWebpackPlugin(),
302
+ // NgBuildAnalyticsPlugin,
303
+ new IndexHtmlWebpackPlugin({
304
+ indexPath: path.resolve(this._rootPath, "src/index.html"),
305
+ outputPath: "index.html",
306
+ baseHref: publicPath,
307
+ entrypoints: [
308
+ ["runtime", true],
309
+ ["polyfills", true],
310
+ ["styles", false],
311
+ ["vendor", true],
312
+ ["main", true]
313
+ ],
314
+ deployUrl: undefined,
315
+ sri: false,
316
+ cache: {
317
+ enabled: true,
318
+ basePath: cacheBasePath,
319
+ path: cachePath
320
+ },
321
+ postTransform: undefined,
322
+ optimization: {
323
+ scripts: !watch,
324
+ styles: { minify: !watch, inlineCritical: !watch },
325
+ fonts: { inline: !watch }
326
+ },
327
+ crossOrigin: "none",
328
+ lang: undefined
329
+ }),
330
+ ...watch ? [
331
+ new webpack.HotModuleReplacementPlugin()
332
+ ] : []
333
+ ] as any[],
334
+ module: {
335
+ strictExportPresence: true,
336
+ parser: { javascript: { url: false, worker: false } },
337
+ rules: [
338
+ {
339
+ test: /\.?(svg|html)$/,
340
+ resourceQuery: /\?ngResource/,
341
+ type: "asset/source"
342
+ },
343
+ {
344
+ test: /[/\\]rxjs[/\\]add[/\\].+\.js$/,
345
+ sideEffects: true,
346
+ },
347
+ {
348
+ test: /\.[cm]?[tj]sx?$/,
349
+ resolve: { fullySpecified: false },
350
+ exclude: [/[/\\](?:core-js|@babel|tslib|web-animations-js|web-streams-polyfill)[/\\]/],
351
+ use: [
352
+ {
353
+ loader: "@angular-devkit/build-angular/src/babel/webpack-loader",
354
+ options: {
355
+ cacheDirectory: path.resolve(cachePath, "babel-webpack"),
356
+ scriptTarget: ts.ScriptTarget.ES2017,
357
+ aot: true,
358
+ optimize: !watch,
359
+ instrumentCode: undefined
360
+ }
361
+ }
362
+ ],
363
+ },
364
+ ...watch ? [
365
+ {
366
+ test: /\.[cm]?jsx?$/,
367
+ enforce: "pre" as const,
368
+ loader: "source-map-loader",
369
+ options: {
370
+ filterSourceMappingUrl: (_mapUri: string, resourcePath: string) => {
371
+ return !resourcePath.includes("node_modules") || (/@simplysm[\\/]sd/).test(resourcePath);
372
+ }
373
+ }
374
+ }
375
+ ] : [],
376
+ {
377
+ test: /\.[cm]?tsx?$/,
378
+ loader: "@ngtools/webpack",
379
+ exclude: [/[/\\](?:css-loader|mini-css-extract-plugin|webpack-dev-server|webpack)[/\\]/],
380
+ },
381
+ {
382
+ test: /\.css$/i,
383
+ type: "asset/source"
384
+ },
385
+ {
386
+ test: /\.scss$/i,
387
+ rules: [
388
+ {
389
+ oneOf: [
390
+ {
391
+ use: [
392
+ {
393
+ loader: MiniCssExtractPlugin.loader
394
+ },
395
+ {
396
+ loader: "css-loader",
397
+ options: { url: false, sourceMap: watch }
398
+ }
399
+ ],
400
+ include: [stylesFilePath],
401
+ resourceQuery: { not: [/\?ngResource/] }
402
+ },
403
+ {
404
+ type: "asset/source",
405
+ resourceQuery: /\?ngResource/
406
+ }
407
+ ]
408
+ },
409
+ {
410
+ use: [
411
+ {
412
+ loader: "resolve-url-loader",
413
+ options: { sourceMap: watch }
414
+ },
415
+ {
416
+ loader: "sass-loader",
417
+ options: {
418
+ implementation: sassImplementation,
419
+ sourceMap: true,
420
+ sassOptions: {
421
+ fiber: false,
422
+ precision: 8,
423
+ includePaths: [],
424
+ outputStyle: "expanded",
425
+ quietDeps: true,
426
+ verbose: watch ? undefined : false
427
+ }
428
+ }
429
+ }
430
+ ]
431
+ }
432
+ ]
433
+ },
434
+ ...watch ? [
435
+ {
436
+ loader: HmrLoader,
437
+ include: [mainFilePath]
438
+ }
439
+ ] : []
440
+ ]
441
+ },
442
+ };
443
+ }
444
+
445
+ private _getNpmConfig(pkgPath: string): INpmConfig | undefined {
446
+ if (!this._npmConfigMap.has(pkgPath)) {
447
+ this._npmConfigMap.set(pkgPath, FsUtil.readJson(path.resolve(pkgPath, "package.json")));
448
+ }
449
+ return this._npmConfigMap.get(pkgPath);
450
+ }
451
+ }
@@ -25,7 +25,7 @@ export class SdCliJsLibBuilder extends EventEmitter {
25
25
 
26
26
  const relatedPaths = await this.getRelatedPathsAsync();
27
27
  const watcher = SdFsWatcher.watch(relatedPaths);
28
- watcher.onChange(async (changeInfos) => {
28
+ watcher.onChange({}, async (changeInfos) => {
29
29
  const changeFilePaths = changeInfos.filter((item) => ["add", "change", "unlink"].includes(item.event)).map((item) => item.path);
30
30
  if(changeFilePaths.length === 0) return;
31
31