@simplysm/sd-cli 6.4.3 → 7.0.6

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 (182) hide show
  1. package/.eslintrc.cjs +11 -0
  2. package/dist/bin/sd-cli.d.ts +1 -0
  3. package/dist/bin/sd-cli.mjs +60 -0
  4. package/dist/build-tool/SdCliCacheCompilerHost.d.ts +10 -0
  5. package/dist/build-tool/SdCliCacheCompilerHost.mjs +44 -0
  6. package/dist/build-tool/SdCliNgCacheCompilerHost.d.ts +11 -0
  7. package/dist/build-tool/SdCliNgCacheCompilerHost.mjs +36 -0
  8. package/dist/build-tool/SdCliPackageLinter.d.ts +8 -0
  9. package/dist/build-tool/SdCliPackageLinter.mjs +41 -0
  10. package/dist/builder/SdCliJsLibBuilder.d.ts +14 -0
  11. package/dist/builder/SdCliJsLibBuilder.mjs +50 -0
  12. package/dist/builder/SdCliTsLibBuilder.d.ts +27 -0
  13. package/dist/builder/SdCliTsLibBuilder.mjs +226 -0
  14. package/dist/commons.d.ts +43 -0
  15. package/dist/commons.mjs +2 -0
  16. package/dist/entry-points/SdCliWorkspace.d.ts +17 -0
  17. package/dist/entry-points/SdCliWorkspace.mjs +186 -0
  18. package/dist/packages/SdCliPackage.d.ts +19 -0
  19. package/dist/packages/SdCliPackage.mjs +89 -0
  20. package/dist/utils/SdBuildResultUtil.d.ts +6 -0
  21. package/dist/utils/SdBuildResultUtil.mjs +38 -0
  22. package/lib/ts-node-esm-paths.mjs +15 -0
  23. package/package.json +27 -58
  24. package/src/bin/sd-cli.ts +54 -220
  25. package/src/build-tool/SdCliCacheCompilerHost.ts +71 -0
  26. package/src/build-tool/SdCliNgCacheCompilerHost.ts +50 -0
  27. package/src/build-tool/SdCliPackageLinter.ts +54 -0
  28. package/src/builder/SdCliJsLibBuilder.ts +66 -0
  29. package/src/builder/SdCliTsLibBuilder.ts +335 -0
  30. package/src/commons.ts +15 -124
  31. package/src/entry-points/SdCliWorkspace.ts +222 -0
  32. package/src/packages/SdCliPackage.ts +111 -0
  33. package/src/utils/SdBuildResultUtil.ts +43 -0
  34. package/tsconfig-build.json +9 -0
  35. package/tsconfig.json +7 -18
  36. package/.eslintrc.js +0 -19
  37. package/dist-node/bin/sd-cli.js +0 -197
  38. package/dist-node/bin/sd-cli.js.map +0 -1
  39. package/dist-node/build-tools/SdCliCordova.js +0 -144
  40. package/dist-node/build-tools/SdCliCordova.js.map +0 -1
  41. package/dist-node/build-tools/SdCliIndexFileGenerator.js +0 -51
  42. package/dist-node/build-tools/SdCliIndexFileGenerator.js.map +0 -1
  43. package/dist-node/build-tools/SdCliNgModuleFilesGenerator.js +0 -675
  44. package/dist-node/build-tools/SdCliNgModuleFilesGenerator.js.map +0 -1
  45. package/dist-node/build-tools/metadata/SdAotMetadataReader.js +0 -274
  46. package/dist-node/build-tools/metadata/SdAotMetadataReader.js.map +0 -1
  47. package/dist-node/build-tools/metadata/SdIvyMetadataReader.js +0 -124
  48. package/dist-node/build-tools/metadata/SdIvyMetadataReader.js.map +0 -1
  49. package/dist-node/build-tools/metadata/SdMetadataError.js +0 -13
  50. package/dist-node/build-tools/metadata/SdMetadataError.js.map +0 -1
  51. package/dist-node/build-tools/metadata/SdMyMetadataReader.js +0 -321
  52. package/dist-node/build-tools/metadata/SdMyMetadataReader.js.map +0 -1
  53. package/dist-node/builders/SdCliJavascriptLinter.js +0 -65
  54. package/dist-node/builders/SdCliJavascriptLinter.js.map +0 -1
  55. package/dist-node/builders/SdCliNgClientBuilder.js +0 -637
  56. package/dist-node/builders/SdCliNgClientBuilder.js.map +0 -1
  57. package/dist-node/builders/SdCliNgLibraryBuilder.js +0 -217
  58. package/dist-node/builders/SdCliNgLibraryBuilder.js.map +0 -1
  59. package/dist-node/builders/SdCliPublisher.js +0 -129
  60. package/dist-node/builders/SdCliPublisher.js.map +0 -1
  61. package/dist-node/builders/SdCliServerBuilder.js +0 -452
  62. package/dist-node/builders/SdCliServerBuilder.js.map +0 -1
  63. package/dist-node/builders/SdCliTypescriptBuilder.js +0 -347
  64. package/dist-node/builders/SdCliTypescriptBuilder.js.map +0 -1
  65. package/dist-node/commons.js +0 -3
  66. package/dist-node/commons.js.map +0 -1
  67. package/dist-node/entry-points/SdCliLocalUpdater.js +0 -88
  68. package/dist-node/entry-points/SdCliLocalUpdater.js.map +0 -1
  69. package/dist-node/entry-points/SdCliPrepare.js +0 -56
  70. package/dist-node/entry-points/SdCliPrepare.js.map +0 -1
  71. package/dist-node/entry-points/SdCliProject.js +0 -302
  72. package/dist-node/entry-points/SdCliProject.js.map +0 -1
  73. package/dist-node/packages/SdCliClientPackage.js +0 -91
  74. package/dist-node/packages/SdCliClientPackage.js.map +0 -1
  75. package/dist-node/packages/SdCliLibraryPackage.js +0 -99
  76. package/dist-node/packages/SdCliLibraryPackage.js.map +0 -1
  77. package/dist-node/packages/SdCliPackageBase.js +0 -33
  78. package/dist-node/packages/SdCliPackageBase.js.map +0 -1
  79. package/dist-node/packages/SdCliServerPackage.js +0 -69
  80. package/dist-node/packages/SdCliServerPackage.js.map +0 -1
  81. package/dist-node/packages/SdCliUnknownPackage.js +0 -15
  82. package/dist-node/packages/SdCliUnknownPackage.js.map +0 -1
  83. package/dist-node/utils/SdCliFileCrypto.js +0 -76
  84. package/dist-node/utils/SdCliFileCrypto.js.map +0 -1
  85. package/dist-node/utils/SdProjectConfigUtil.js +0 -62
  86. package/dist-node/utils/SdProjectConfigUtil.js.map +0 -1
  87. package/dist-node/utils/SdTsDiagnosticUtil.js +0 -45
  88. package/dist-node/utils/SdTsDiagnosticUtil.js.map +0 -1
  89. package/dist-node/utils/SdWebpackUtil.js +0 -63
  90. package/dist-node/utils/SdWebpackUtil.js.map +0 -1
  91. package/dist-node/workers/client-ng-gen-worker.js +0 -57
  92. package/dist-node/workers/client-ng-gen-worker.js.map +0 -1
  93. package/dist-node/workers/lib-build-worker.js +0 -88
  94. package/dist-node/workers/lib-build-worker.js.map +0 -1
  95. package/dist-types/bin/sd-cli.d.ts +0 -3
  96. package/dist-types/bin/sd-cli.d.ts.map +0 -1
  97. package/dist-types/build-tools/SdCliCordova.d.ts +0 -15
  98. package/dist-types/build-tools/SdCliCordova.d.ts.map +0 -1
  99. package/dist-types/build-tools/SdCliIndexFileGenerator.d.ts +0 -13
  100. package/dist-types/build-tools/SdCliIndexFileGenerator.d.ts.map +0 -1
  101. package/dist-types/build-tools/SdCliNgModuleFilesGenerator.d.ts +0 -43
  102. package/dist-types/build-tools/SdCliNgModuleFilesGenerator.d.ts.map +0 -1
  103. package/dist-types/build-tools/metadata/SdAotMetadataReader.d.ts +0 -58
  104. package/dist-types/build-tools/metadata/SdAotMetadataReader.d.ts.map +0 -1
  105. package/dist-types/build-tools/metadata/SdIvyMetadataReader.d.ts +0 -43
  106. package/dist-types/build-tools/metadata/SdIvyMetadataReader.d.ts.map +0 -1
  107. package/dist-types/build-tools/metadata/SdMetadataError.d.ts +0 -7
  108. package/dist-types/build-tools/metadata/SdMetadataError.d.ts.map +0 -1
  109. package/dist-types/build-tools/metadata/SdMyMetadataReader.d.ts +0 -59
  110. package/dist-types/build-tools/metadata/SdMyMetadataReader.d.ts.map +0 -1
  111. package/dist-types/builders/SdCliJavascriptLinter.d.ts +0 -14
  112. package/dist-types/builders/SdCliJavascriptLinter.d.ts.map +0 -1
  113. package/dist-types/builders/SdCliNgClientBuilder.d.ts +0 -29
  114. package/dist-types/builders/SdCliNgClientBuilder.d.ts.map +0 -1
  115. package/dist-types/builders/SdCliNgLibraryBuilder.d.ts +0 -30
  116. package/dist-types/builders/SdCliNgLibraryBuilder.d.ts.map +0 -1
  117. package/dist-types/builders/SdCliPublisher.d.ts +0 -9
  118. package/dist-types/builders/SdCliPublisher.d.ts.map +0 -1
  119. package/dist-types/builders/SdCliServerBuilder.d.ts +0 -31
  120. package/dist-types/builders/SdCliServerBuilder.d.ts.map +0 -1
  121. package/dist-types/builders/SdCliTypescriptBuilder.d.ts +0 -56
  122. package/dist-types/builders/SdCliTypescriptBuilder.d.ts.map +0 -1
  123. package/dist-types/commons.d.ts +0 -134
  124. package/dist-types/commons.d.ts.map +0 -1
  125. package/dist-types/entry-points/SdCliLocalUpdater.d.ts +0 -12
  126. package/dist-types/entry-points/SdCliLocalUpdater.d.ts.map +0 -1
  127. package/dist-types/entry-points/SdCliPrepare.d.ts +0 -6
  128. package/dist-types/entry-points/SdCliPrepare.d.ts.map +0 -1
  129. package/dist-types/entry-points/SdCliProject.d.ts +0 -32
  130. package/dist-types/entry-points/SdCliProject.d.ts.map +0 -1
  131. package/dist-types/packages/SdCliClientPackage.d.ts +0 -17
  132. package/dist-types/packages/SdCliClientPackage.d.ts.map +0 -1
  133. package/dist-types/packages/SdCliLibraryPackage.d.ts +0 -20
  134. package/dist-types/packages/SdCliLibraryPackage.d.ts.map +0 -1
  135. package/dist-types/packages/SdCliPackageBase.d.ts +0 -11
  136. package/dist-types/packages/SdCliPackageBase.d.ts.map +0 -1
  137. package/dist-types/packages/SdCliServerPackage.d.ts +0 -16
  138. package/dist-types/packages/SdCliServerPackage.d.ts.map +0 -1
  139. package/dist-types/packages/SdCliUnknownPackage.d.ts +0 -9
  140. package/dist-types/packages/SdCliUnknownPackage.d.ts.map +0 -1
  141. package/dist-types/utils/SdCliFileCrypto.d.ts +0 -8
  142. package/dist-types/utils/SdCliFileCrypto.d.ts.map +0 -1
  143. package/dist-types/utils/SdProjectConfigUtil.d.ts +0 -7
  144. package/dist-types/utils/SdProjectConfigUtil.d.ts.map +0 -1
  145. package/dist-types/utils/SdTsDiagnosticUtil.d.ts +0 -6
  146. package/dist-types/utils/SdTsDiagnosticUtil.d.ts.map +0 -1
  147. package/dist-types/utils/SdWebpackUtil.d.ts +0 -7
  148. package/dist-types/utils/SdWebpackUtil.d.ts.map +0 -1
  149. package/dist-types/workers/client-ng-gen-worker.d.ts +0 -2
  150. package/dist-types/workers/client-ng-gen-worker.d.ts.map +0 -1
  151. package/dist-types/workers/lib-build-worker.d.ts +0 -2
  152. package/dist-types/workers/lib-build-worker.d.ts.map +0 -1
  153. package/schema/schema.json +0 -447
  154. package/sd-tsconfig.node.json +0 -18
  155. package/src/build-tools/SdCliCordova.ts +0 -240
  156. package/src/build-tools/SdCliIndexFileGenerator.ts +0 -61
  157. package/src/build-tools/SdCliNgModuleFilesGenerator.ts +0 -894
  158. package/src/build-tools/metadata/SdAotMetadataReader.ts +0 -374
  159. package/src/build-tools/metadata/SdIvyMetadataReader.ts +0 -183
  160. package/src/build-tools/metadata/SdMetadataError.ts +0 -7
  161. package/src/build-tools/metadata/SdMyMetadataReader.ts +0 -407
  162. package/src/builders/SdCliJavascriptLinter.ts +0 -81
  163. package/src/builders/SdCliNgClientBuilder.ts +0 -794
  164. package/src/builders/SdCliNgLibraryBuilder.ts +0 -301
  165. package/src/builders/SdCliPublisher.ts +0 -144
  166. package/src/builders/SdCliServerBuilder.ts +0 -555
  167. package/src/builders/SdCliTypescriptBuilder.ts +0 -552
  168. package/src/entry-points/SdCliLocalUpdater.ts +0 -114
  169. package/src/entry-points/SdCliPrepare.ts +0 -104
  170. package/src/entry-points/SdCliProject.ts +0 -405
  171. package/src/packages/SdCliClientPackage.ts +0 -111
  172. package/src/packages/SdCliLibraryPackage.ts +0 -118
  173. package/src/packages/SdCliPackageBase.ts +0 -34
  174. package/src/packages/SdCliServerPackage.ts +0 -85
  175. package/src/packages/SdCliUnknownPackage.ts +0 -14
  176. package/src/utils/SdCliFileCrypto.ts +0 -87
  177. package/src/utils/SdCliUtils.ts +0 -56
  178. package/src/utils/SdProjectConfigUtil.ts +0 -145
  179. package/src/utils/SdTsDiagnosticUtil.ts +0 -46
  180. package/src/utils/SdWebpackUtil.ts +0 -71
  181. package/src/workers/client-ng-gen-worker.ts +0 -63
  182. package/src/workers/lib-build-worker.ts +0 -97
package/src/bin/sd-cli.ts CHANGED
@@ -1,235 +1,69 @@
1
- #!/usr/bin/env node
2
-
3
- process.setMaxListeners(0);
4
-
5
- import * as os from "os";
6
- import * as yargs from "yargs";
7
- import { EventEmitter } from "events";
1
+ import yargs from "yargs";
2
+ import { hideBin } from "yargs/helpers";
8
3
  import { Logger, LoggerSeverity } from "@simplysm/sd-core-node";
9
- import { SdCliProject } from "../entry-points/SdCliProject";
10
- import { SdCliLocalUpdater } from "../entry-points/SdCliLocalUpdater";
11
- import { SdCliFileCrypto } from "../utils/SdCliFileCrypto";
12
- import { SdCliCordova } from "../build-tools/SdCliCordova";
13
- import { SdCliPrepare } from "../entry-points/SdCliPrepare";
4
+ import { SdCliWorkspace } from "../entry-points/SdCliWorkspace";
14
5
 
15
- EventEmitter.defaultMaxListeners = 0;
6
+ Error.stackTraceLimit = Infinity;
16
7
 
17
- const logger = Logger.get(["simplysm", "sd-cli"]);
8
+ const argv = yargs(hideBin(process.argv))
9
+ .version(false)
10
+ .help("help", "도움말")
11
+ .alias("help", "h")
12
+ .options({
13
+ debug: {
14
+ type: "boolean",
15
+ describe: "디버그 로그를 표시할 것인지 여부",
16
+ default: false
17
+ }
18
+ })
19
+ .command("watch", "프로젝트의 각 패키지에 대한 변경감지 빌드를 수행합니다.")
20
+ .command("build", "프로젝트의 각 패키지에 대한 빌드를 수행합니다.")
21
+ .command(
22
+ "publish",
23
+ "프로젝트의 각 패키지를 배포합니다.",
24
+ (cmd) => cmd
25
+ .options({
26
+ "noBuild":{
27
+ type: "boolean",
28
+ describe: "빌드를 하지않고 배포합니다.",
29
+ default: false
30
+ }
31
+ })
32
+ )
33
+ .parseSync();
18
34
 
19
- (async (): Promise<void> => {
20
- const argv = await yargs.version(false)
21
- .help("help", "도움말")
22
- .alias("help", "h")
23
- .options({
24
- debug: {
25
- type: "boolean",
26
- describe: "디버그 로그를 표시할 것인지 여부",
27
- default: false
28
- }
29
- })
30
- .command(
31
- "watch",
32
- "프로젝트의 각 패키지에 대한 변경감지 빌드를 수행합니다.",
33
- (cmd) => cmd
34
- .options({
35
- packages: {
36
- type: "string",
37
- describe: "수행할 패키지 설정",
38
- array: true
39
- },
40
- config: {
41
- type: "string",
42
- describe: "simplysm.json 파일 경로"
43
- },
44
- noLint: {
45
- type: "boolean",
46
- describe: `lint 작업을 수행하지 않음`
47
- },
48
- options: {
49
- type: "string",
50
- describe: "옵션 설정 (설정파일에서 @로 시작하는 부분)",
51
- array: true
52
- }
53
- })
54
- )
55
- .command(
56
- "run-device <cordovaPath> <target> <url>",
57
- "변경감지중인 플랫폼을 디바이스에 앱 형태로 띄웁니다.",
58
- (cmd) => cmd
59
- .positional("cordovaPath", {
60
- type: "string",
61
- describe: "CORDOVA 프로젝트 경로",
62
- demandOption: true
63
- })
64
- .positional("target", {
65
- type: "string",
66
- describe: "빌드타겟(android,...)",
67
- demandOption: true
68
- })
69
- .positional("url", {
70
- type: "string",
71
- describe: "Webview로 오픈할 URL",
72
- demandOption: true
73
- })
74
- )
75
- .command(
76
- "build",
77
- "프로젝트의 각 패키지에 대한 빌드를 수행합니다.",
78
- (cmd) => cmd
79
- .options({
80
- packages: {
81
- type: "string",
82
- describe: "수행할 패키지 설정",
83
- array: true
84
- },
85
- config: {
86
- type: "string",
87
- describe: "simplysm.json 파일 경로"
88
- },
89
- noLint: {
90
- type: "boolean",
91
- describe: `lint 작업을 수행하지 않음`
92
- },
93
- options: {
94
- type: "string",
95
- describe: "옵션 설정 (설정파일에서 @로 시작하는 부분)",
96
- array: true
97
- }
98
- })
99
- )
100
- .command(
101
- "publish",
102
- "프로젝트의 각 패키지를 배포합니다.",
103
- (cmd) => cmd.version(false)
104
- .options({
105
- build: {
106
- type: "boolean",
107
- describe: "새로 빌드한 후에 배포합니다",
108
- default: false
109
- },
110
- noLint: {
111
- type: "boolean",
112
- describe: `빌드시, lint 작업을 수행하지 않음`
113
- },
114
- packages: {
115
- type: "string",
116
- describe: "수행할 패키지 설정",
117
- array: true
118
- },
119
- config: {
120
- type: "string",
121
- describe: "simplysm.json 파일 경로"
122
- },
123
- options: {
124
- type: "string",
125
- describe: "옵션 설정 (설정파일에서 @로 시작하는 부분)",
126
- array: true
127
- }
128
- })
129
- )
130
- .command(
131
- "local-update",
132
- "로컬 라이브러리 업데이트를 수행합니다.",
133
- (cmd) => cmd.version(false)
134
- .options({
135
- config: {
136
- type: "string",
137
- describe: "simplysm.json 파일 경로"
138
- }
139
- })
140
- )
141
- .command(
142
- "enc-file <file>",
143
- "파일을 암호화 합니다.",
144
- (cmd) => cmd.version(false)
145
- .positional("file", {
146
- type: "string",
147
- describe: "암호화할 파일명"
148
- })
149
- )
150
- .command(
151
- "dec-file <file>",
152
- "파일을 복호화 합니다.",
153
- (cmd) => cmd.version(false)
154
- .positional("file", {
155
- type: "string",
156
- describe: "암호화된 파일명"
157
- })
158
- )
159
- .command(
160
- "prepare",
161
- "sd-cli 준비"
162
- )
163
- .parse();
35
+ if (argv.debug) {
36
+ process.env["SD_CLI_LOGGER_SEVERITY"] = "DEBUG";
164
37
 
165
- if (argv.debug) {
166
- Error.stackTraceLimit = 100; //Infinity;
38
+ Logger.setConfig({
39
+ console: {
40
+ level: LoggerSeverity.debug
41
+ }
42
+ });
43
+ }
44
+ else {
45
+ Logger.setConfig({
46
+ dot: true
47
+ });
48
+ }
167
49
 
168
- process.env.SD_CLI_LOGGER_SEVERITY = "DEBUG";
50
+ const logger = Logger.get(["simplysm", "sd-cli", "bin", "sd-cli"]);
169
51
 
170
- Logger.setConfig(["simplysm", "sd-cli"], {
171
- console: {
172
- level: LoggerSeverity.debug
173
- }
174
- });
175
- }
176
- else {
177
- Logger.setConfig(["simplysm", "sd-cli"], {
178
- dot: true
179
- });
52
+ (async () => {
53
+ if (argv._[0] === "watch") {
54
+ await new SdCliWorkspace(process.cwd()).watchAsync();
180
55
  }
181
-
182
- const args = argv._;
183
-
184
- if (args[0] === "build") {
185
- await new SdCliProject(process.cwd())
186
- .buildAsync({
187
- packages: argv.packages,
188
- config: argv.config,
189
- options: argv.options,
190
- skipProcesses: argv.noLint ? ["lint"] : undefined
191
- });
192
- process.exit(0);
56
+ else if (argv._[0] === "build") {
57
+ await new SdCliWorkspace(process.cwd()).buildAsync();
193
58
  }
194
- else if (args[0] === "watch") {
195
- await new SdCliProject(process.cwd())
196
- .buildAsync({
197
- watch: true,
198
- packages: argv.packages,
199
- config: argv.config,
200
- options: argv.options,
201
- skipProcesses: argv.noLint ? ["lint"] : undefined
202
- });
203
- }
204
- else if (args[0] === "run-device") {
205
- await SdCliCordova.runWebviewOnDeviceAsync(argv.cordovaPath, argv.target, argv.url);
206
- }
207
- else if (args[0] === "local-update") {
208
- await new SdCliLocalUpdater(process.cwd()).localUpdateAsync(false, { config: argv.config });
209
- }
210
- else if (args[0] === "publish") {
211
- await new SdCliProject(process.cwd())
212
- .publishAsync({
213
- build: argv.build,
214
- packages: argv.packages,
215
- config: argv.config,
216
- options: argv.options
217
- });
218
- process.exit(0);
219
- }
220
- else if (args[0] === "enc-file") {
221
- await new SdCliFileCrypto().encryptAsync(argv.file!);
222
- }
223
- else if (args[0] === "dec-file") {
224
- await new SdCliFileCrypto().decryptAsync(argv.file!);
225
- }
226
- else if (args[0] === "prepare") {
227
- await new SdCliPrepare().prepareAsync();
59
+ else if (argv._[0] === "publish") {
60
+ await new SdCliWorkspace(process.cwd()).publishAsync({
61
+ noBuild: argv.noBuild
62
+ });
228
63
  }
229
64
  else {
230
- throw new Error(`명령어가 잘못되었습니다.${os.EOL + os.EOL}\t${argv._[0]}${os.EOL}`);
65
+ throw new Error(`명령어가 잘못 되었습니다.\n\t${argv._[0]}\n`);
231
66
  }
232
67
  })().catch((err) => {
233
68
  logger.error(err);
234
- process.exit(1);
235
69
  });
@@ -0,0 +1,71 @@
1
+ import ts from "typescript";
2
+ import { PathUtil } from "@simplysm/sd-core-node";
3
+
4
+ export class SdCliCacheCompilerHost {
5
+ public static create(parsedTsconfig: ts.ParsedCommandLine,
6
+ moduleResolutionCache: ts.ModuleResolutionCache,
7
+ sourceFileCache: Map<string, IFileCache>,
8
+ outputFileCache: Map<string, string>): ts.CompilerHost {
9
+ const compilerHost = ts.createIncrementalCompilerHost(parsedTsconfig.options);
10
+
11
+ const cacheCompilerHost = { ...compilerHost };
12
+
13
+ cacheCompilerHost.fileExists = (fileName: string) => {
14
+ const cache = sourceFileCache.getOrCreate(PathUtil.posix(fileName), {});
15
+ if (cache.exists === undefined) {
16
+ cache.exists = compilerHost.fileExists.call(cacheCompilerHost, fileName);
17
+ }
18
+ return cache.exists;
19
+ };
20
+
21
+ cacheCompilerHost.getSourceFile = (fileName: string, languageVersion: ts.ScriptTarget) => {
22
+ const cache = sourceFileCache.getOrCreate(PathUtil.posix(fileName), {});
23
+ if (!cache.sourceFile) {
24
+ cache.sourceFile = compilerHost.getSourceFile.call(cacheCompilerHost, fileName, languageVersion);
25
+ }
26
+ return cache.sourceFile;
27
+ };
28
+
29
+ cacheCompilerHost.writeFile = (fileName: string,
30
+ data: string,
31
+ writeByteOrderMark: boolean,
32
+ onError?: (message: string) => void,
33
+ sourceFiles?: readonly ts.SourceFile[]) => {
34
+ fileName = fileName.replace(/\.js(\.map)?$/, ".mjs$1");
35
+
36
+ const writeCache = outputFileCache.get(PathUtil.posix(fileName));
37
+ if (writeCache !== data) {
38
+ outputFileCache.set(PathUtil.posix(fileName), data);
39
+ compilerHost.writeFile.call(cacheCompilerHost, fileName, data, writeByteOrderMark, onError, sourceFiles);
40
+ }
41
+ };
42
+
43
+ cacheCompilerHost.readFile = (fileName: string) => {
44
+ const cache = sourceFileCache.getOrCreate(PathUtil.posix(fileName), {});
45
+ if (cache.content === undefined) {
46
+ cache.content = compilerHost.readFile.call(cacheCompilerHost, fileName);
47
+ }
48
+ return cache.content;
49
+ };
50
+
51
+ cacheCompilerHost.resolveModuleNames = (moduleNames: string[], containingFile: string) => {
52
+ return moduleNames.map((moduleName) => {
53
+ return ts.resolveModuleName(
54
+ moduleName,
55
+ PathUtil.posix(containingFile),
56
+ parsedTsconfig.options,
57
+ compilerHost,
58
+ moduleResolutionCache
59
+ ).resolvedModule;
60
+ });
61
+ };
62
+
63
+ return cacheCompilerHost;
64
+ }
65
+ }
66
+
67
+ interface IFileCache {
68
+ exists?: boolean;
69
+ sourceFile?: ts.SourceFile;
70
+ content?: string;
71
+ }
@@ -0,0 +1,50 @@
1
+ import ts from "typescript";
2
+ import { PathUtil } from "@simplysm/sd-core-node";
3
+ import sass from "sass";
4
+ import { pathToFileURL, URL } from "url";
5
+
6
+ export class SdCliNgCacheCompilerHost {
7
+ public static wrap(compilerHost: ts.CompilerHost,
8
+ sourceFileCache: Map<string, IFileCache>): ts.CompilerHost {
9
+ const cacheCompilerHost = { ...compilerHost };
10
+
11
+ cacheCompilerHost["readResource"] = (fileName: string) => {
12
+ const cache = sourceFileCache.getOrCreate(PathUtil.posix(fileName), {});
13
+ if (cache.content === undefined) {
14
+ cache.content = compilerHost.readFile.call(cacheCompilerHost, fileName);
15
+ }
16
+ return cache.content;
17
+ };
18
+
19
+ cacheCompilerHost["transformResource"] = async (data, context) => {
20
+ if (context.resourceFile || context.type !== "style") {
21
+ return null;
22
+ }
23
+
24
+ const cache = sourceFileCache.getOrCreate(PathUtil.posix(context.containingFile), {});
25
+ if (cache.styleContent === undefined) {
26
+ cache.styleContent = (
27
+ await sass.compileStringAsync(data, {
28
+ url: new URL(context.containingFile + ".sd.scss"),
29
+ importer: {
30
+ findFileUrl: (url) => {
31
+ if (!url.startsWith("~")) return undefined;
32
+ return new URL(url.substring(1), pathToFileURL("node_modules"));
33
+ }
34
+ }
35
+ })
36
+ ).css.toString();
37
+ }
38
+ return { content: cache.styleContent };
39
+ };
40
+
41
+ return cacheCompilerHost;
42
+ }
43
+ }
44
+
45
+ interface IFileCache {
46
+ exists?: boolean;
47
+ sourceFile?: ts.SourceFile;
48
+ content?: string;
49
+ styleContent?: string;
50
+ }
@@ -0,0 +1,54 @@
1
+ import { ISdCliPackageBuildResult } from "../commons";
2
+ import ts from "typescript";
3
+ import { FsUtil } from "@simplysm/sd-core-node";
4
+ import path from "path";
5
+ import { ESLint } from "eslint";
6
+
7
+ export class SdCliPackageLinter {
8
+ private readonly _lintResultCache = new Map<string, ISdCliPackageBuildResult[]>();
9
+
10
+ public constructor(private readonly _rootPath: string) {
11
+ }
12
+
13
+ public async lintAsync(filePaths: string[], program?: ts.Program): Promise<ISdCliPackageBuildResult[]> {
14
+ if (!FsUtil.exists(path.resolve(this._rootPath, ".eslintrc.cjs"))) return [];
15
+
16
+ const linter = new ESLint(
17
+ program && filePaths.some((item) => item.endsWith(".ts")) ? {
18
+ overrideConfig: {
19
+ parserOptions: { program }
20
+ }
21
+ } : {}
22
+ );
23
+
24
+ const lintFilePaths = await filePaths
25
+ .filterAsync(async (filePath) => (
26
+ !filePath.endsWith(".d.ts") &&
27
+ !(await linter.isPathIgnored(filePath))
28
+ ));
29
+ for (const lintFilePath of lintFilePaths) {
30
+ this._lintResultCache.delete(lintFilePath);
31
+ }
32
+
33
+ const lintResults = await linter.lintFiles(lintFilePaths);
34
+
35
+
36
+ const result = lintResults.map((lintResult) => ({
37
+ filePath: lintResult.filePath,
38
+ results: lintResult.messages.map((msg) => ({
39
+ filePath: lintResult.filePath,
40
+ line: msg.line,
41
+ char: msg.column,
42
+ code: msg.ruleId ?? undefined,
43
+ severity: msg.severity === 1 ? "warning" as const : "error" as const,
44
+ message: msg.message
45
+ }))
46
+ }));
47
+
48
+ for (const resultItem of result) {
49
+ this._lintResultCache.set(resultItem.filePath, resultItem.results);
50
+ }
51
+
52
+ return Array.from(this._lintResultCache.values()).mapMany();
53
+ }
54
+ }
@@ -0,0 +1,66 @@
1
+ import { ISdCliPackageBuildResult } from "../commons";
2
+ import { EventEmitter } from "events";
3
+ import { FsUtil, Logger, SdFsWatcher } from "@simplysm/sd-core-node";
4
+ import * as path from "path";
5
+ import { SdCliPackageLinter } from "../build-tool/SdCliPackageLinter";
6
+
7
+ export class SdCliJsLibBuilder extends EventEmitter {
8
+ private readonly _logger = Logger.get(["simplysm", "sd-cli", this.constructor.name]);
9
+
10
+ private readonly _linter: SdCliPackageLinter;
11
+
12
+ public constructor(private readonly _rootPath: string) {
13
+ super();
14
+ this._linter = new SdCliPackageLinter(this._rootPath);
15
+ }
16
+
17
+ public override on(event: "change", listener: () => void): this;
18
+ public override on(event: "complete", listener: (results: ISdCliPackageBuildResult[]) => void): this;
19
+ public override on(event: string | symbol, listener: (...args: any[]) => void): this {
20
+ return super.on(event, listener);
21
+ }
22
+
23
+ public async watchAsync(): Promise<void> {
24
+ this.emit("change");
25
+
26
+ const relatedPaths = await this.getRelatedPathsAsync();
27
+ const watcher = SdFsWatcher.watch(relatedPaths);
28
+ watcher.onChange(async (changeInfos) => {
29
+ const changeFilePaths = changeInfos.filter((item) => ["add", "change", "unlink"].includes(item.event)).map((item) => item.path);
30
+ if(changeFilePaths.length === 0) return;
31
+
32
+ this._logger.debug("파일 변경 감지", changeInfos);
33
+ this.emit("change");
34
+
35
+ const watchBuildResults = await this._linter.lintAsync(changeFilePaths);
36
+
37
+ const watchRelatedPaths = await this.getRelatedPathsAsync();
38
+ watcher.add(watchRelatedPaths);
39
+
40
+ this.emit("complete", watchBuildResults);
41
+ });
42
+
43
+ // 빌드
44
+ const buildResults = await this._linter.lintAsync(relatedPaths);
45
+
46
+ this.emit("complete", buildResults);
47
+ }
48
+
49
+ public async buildAsync(): Promise<ISdCliPackageBuildResult[]> {
50
+ const relatedPaths = await this.getRelatedPathsAsync();
51
+ return await this._linter.lintAsync(relatedPaths);
52
+ }
53
+
54
+ private async getRelatedPathsAsync(): Promise<string[]> {
55
+ const mySourceGlobPath = path.resolve(this._rootPath, "**", "+(*.js|*.cjs|*.mjs|*.ts)");
56
+ const mySourceFilePaths = await FsUtil.globAsync(mySourceGlobPath, {
57
+ ignore: [
58
+ "**/node_modules/**",
59
+ "**/dist/**",
60
+ "**/.*/**"
61
+ ]
62
+ });
63
+
64
+ return [...mySourceFilePaths, path.resolve(this._rootPath, ".eslintrc.cjs")].distinct();
65
+ }
66
+ }