@simplysm/sd-cli 12.5.21 → 12.5.23

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 (195) hide show
  1. package/dist/{build-tools → entry}/SdCliCordova.d.ts +5 -6
  2. package/dist/{build-tools → entry}/SdCliCordova.js +117 -99
  3. package/dist/entry/SdCliCordova.js.map +1 -0
  4. package/dist/entry/SdCliElectron.d.ts +2 -2
  5. package/dist/entry/SdCliElectron.js +50 -40
  6. package/dist/entry/SdCliElectron.js.map +1 -1
  7. package/dist/entry/SdCliLocalUpdate.d.ts +1 -2
  8. package/dist/entry/SdCliLocalUpdate.js +26 -27
  9. package/dist/entry/SdCliLocalUpdate.js.map +1 -1
  10. package/dist/entry/SdCliProject.d.ts +1 -5
  11. package/dist/entry/SdCliProject.js +62 -288
  12. package/dist/entry/SdCliProject.js.map +1 -1
  13. package/dist/index.d.ts +23 -20
  14. package/dist/index.js +23 -20
  15. package/dist/index.js.map +1 -1
  16. package/dist/pkg-builders/SdMultiBuildRunner.d.ts +21 -0
  17. package/dist/pkg-builders/SdMultiBuildRunner.js +174 -0
  18. package/dist/pkg-builders/SdMultiBuildRunner.js.map +1 -0
  19. package/dist/pkg-builders/client/SdCliNgRoutesFileGenerator.d.ts +4 -0
  20. package/dist/{build-tools → pkg-builders/client}/SdCliNgRoutesFileGenerator.js +7 -7
  21. package/dist/pkg-builders/client/SdCliNgRoutesFileGenerator.js.map +1 -0
  22. package/dist/pkg-builders/client/SdClientBuildRunner.d.ts +20 -0
  23. package/dist/pkg-builders/client/SdClientBuildRunner.js +135 -0
  24. package/dist/pkg-builders/client/SdClientBuildRunner.js.map +1 -0
  25. package/dist/pkg-builders/client/SdNgBundler.d.ts +29 -0
  26. package/dist/{build-tools → pkg-builders/client}/SdNgBundler.js +107 -151
  27. package/dist/pkg-builders/client/SdNgBundler.js.map +1 -0
  28. package/dist/{build-tools → pkg-builders/client}/SdNgBundlerContext.d.ts +1 -2
  29. package/dist/{build-tools → pkg-builders/client}/SdNgBundlerContext.js +19 -45
  30. package/dist/pkg-builders/client/SdNgBundlerContext.js.map +1 -0
  31. package/dist/pkg-builders/client/createSdNgPlugin.d.ts +10 -0
  32. package/dist/{bundle-plugins/sdNgPlugin.js → pkg-builders/client/createSdNgPlugin.js} +32 -33
  33. package/dist/pkg-builders/client/createSdNgPlugin.js.map +1 -0
  34. package/dist/pkg-builders/lib/SdCliIndexFileGenerator.d.ts +5 -0
  35. package/dist/{build-tools → pkg-builders/lib}/SdCliIndexFileGenerator.js +11 -11
  36. package/dist/pkg-builders/lib/SdCliIndexFileGenerator.js.map +1 -0
  37. package/dist/pkg-builders/lib/SdJsLibBuildRunner.d.ts +16 -0
  38. package/dist/pkg-builders/lib/SdJsLibBuildRunner.js +81 -0
  39. package/dist/pkg-builders/lib/SdJsLibBuildRunner.js.map +1 -0
  40. package/dist/pkg-builders/lib/SdTsLibBuildRunner.d.ts +13 -0
  41. package/dist/pkg-builders/lib/SdTsLibBuildRunner.js +89 -0
  42. package/dist/pkg-builders/lib/SdTsLibBuildRunner.js.map +1 -0
  43. package/dist/pkg-builders/lib/SdTsLibBuilder.d.ts +14 -0
  44. package/dist/pkg-builders/lib/SdTsLibBuilder.js +54 -0
  45. package/dist/pkg-builders/lib/SdTsLibBuilder.js.map +1 -0
  46. package/dist/pkg-builders/server/SdServerBuildRunner.d.ts +17 -0
  47. package/dist/{builders/SdCliServerBuilder.js → pkg-builders/server/SdServerBuildRunner.js} +48 -53
  48. package/dist/pkg-builders/server/SdServerBuildRunner.js.map +1 -0
  49. package/dist/pkg-builders/server/SdServerBundler.d.ts +19 -0
  50. package/dist/{build-tools → pkg-builders/server}/SdServerBundler.js +25 -30
  51. package/dist/pkg-builders/server/SdServerBundler.js.map +1 -0
  52. package/dist/pkg-builders/server/createSdServerPlugin.d.ts +10 -0
  53. package/dist/pkg-builders/server/createSdServerPlugin.js +53 -0
  54. package/dist/pkg-builders/server/createSdServerPlugin.js.map +1 -0
  55. package/dist/sd-cli.js +61 -54
  56. package/dist/sd-cli.js.map +1 -1
  57. package/dist/ts-builder/SdTsCompileWorker.d.ts +9 -0
  58. package/dist/ts-builder/SdTsCompileWorker.js +16 -0
  59. package/dist/ts-builder/SdTsCompileWorker.js.map +1 -0
  60. package/dist/ts-builder/SdTsCompiler.d.ts +7 -0
  61. package/dist/ts-builder/SdTsCompiler.js +557 -0
  62. package/dist/ts-builder/SdTsCompiler.js.map +1 -0
  63. package/dist/types/build-plugin.type.d.ts +14 -0
  64. package/dist/types/build-plugin.type.js +2 -0
  65. package/dist/types/build-plugin.type.js.map +1 -0
  66. package/dist/types/build.type.d.ts +15 -0
  67. package/dist/types/build.type.js +2 -0
  68. package/dist/types/build.type.js.map +1 -0
  69. package/dist/types/common-configs.type.d.ts +22 -0
  70. package/dist/types/common-configs.type.js +2 -0
  71. package/dist/types/common-configs.type.js.map +1 -0
  72. package/dist/types/sd-configs.type.d.ts +99 -0
  73. package/dist/types/sd-configs.type.js +2 -0
  74. package/dist/types/sd-configs.type.js.map +1 -0
  75. package/dist/types/ts-compiler.type.d.ts +29 -0
  76. package/dist/types/ts-compiler.type.js +2 -0
  77. package/dist/types/ts-compiler.type.js.map +1 -0
  78. package/dist/types/workers.type.d.ts +49 -0
  79. package/dist/types/workers.type.js +2 -0
  80. package/dist/types/workers.type.js.map +1 -0
  81. package/dist/utils/SdCliConvertMessageUtil.d.ts +21 -0
  82. package/dist/utils/SdCliConvertMessageUtil.js +137 -0
  83. package/dist/utils/SdCliConvertMessageUtil.js.map +1 -0
  84. package/dist/workers/compile-worker.js +27 -0
  85. package/dist/workers/compile-worker.js.map +1 -0
  86. package/dist/workers/lint-worker.js +36 -0
  87. package/dist/workers/lint-worker.js.map +1 -0
  88. package/dist/workers/server-worker.d.ts +1 -0
  89. package/dist/workers/server-worker.js +49 -0
  90. package/dist/workers/server-worker.js.map +1 -0
  91. package/package.json +8 -11
  92. package/src/entry/SdCliCordova.ts +363 -0
  93. package/src/entry/SdCliElectron.ts +96 -69
  94. package/src/entry/SdCliLocalUpdate.ts +43 -44
  95. package/src/entry/SdCliProject.ts +72 -417
  96. package/src/index.ts +23 -20
  97. package/src/pkg-builders/SdMultiBuildRunner.ts +250 -0
  98. package/src/{build-tools → pkg-builders/client}/SdCliNgRoutesFileGenerator.ts +7 -7
  99. package/src/pkg-builders/client/SdClientBuildRunner.ts +191 -0
  100. package/src/{build-tools → pkg-builders/client}/SdNgBundler.ts +135 -190
  101. package/src/pkg-builders/client/SdNgBundlerContext.ts +111 -0
  102. package/src/{bundle-plugins/sdNgPlugin.ts → pkg-builders/client/createSdNgPlugin.ts} +43 -46
  103. package/src/{build-tools → pkg-builders/lib}/SdCliIndexFileGenerator.ts +11 -11
  104. package/src/pkg-builders/lib/SdJsLibBuildRunner.ts +105 -0
  105. package/src/pkg-builders/lib/SdTsLibBuildRunner.ts +128 -0
  106. package/src/pkg-builders/lib/SdTsLibBuilder.ts +69 -0
  107. package/src/{builders/SdCliServerBuilder.ts → pkg-builders/server/SdServerBuildRunner.ts} +66 -78
  108. package/src/{build-tools → pkg-builders/server}/SdServerBundler.ts +40 -41
  109. package/src/pkg-builders/server/createSdServerPlugin.ts +77 -0
  110. package/src/sd-cli.ts +197 -211
  111. package/src/ts-builder/SdTsCompileWorker.ts +21 -0
  112. package/src/ts-builder/SdTsCompiler.ts +775 -0
  113. package/src/types/build-plugin.type.ts +16 -0
  114. package/src/types/build.type.ts +17 -0
  115. package/src/types/common-configs.type.ts +27 -0
  116. package/src/types/sd-configs.type.ts +114 -0
  117. package/src/types/ts-compiler.type.ts +29 -0
  118. package/src/types/workers.type.ts +27 -0
  119. package/src/utils/SdCliConvertMessageUtil.ts +177 -0
  120. package/src/workers/compile-worker.ts +31 -0
  121. package/src/workers/lint-worker.ts +44 -0
  122. package/src/workers/server-worker.ts +52 -0
  123. package/tsconfig.json +7 -1
  124. package/dist/build-cluster.js +0 -201
  125. package/dist/build-cluster.js.map +0 -1
  126. package/dist/build-tools/SdCliCordova.js.map +0 -1
  127. package/dist/build-tools/SdCliIndexFileGenerator.d.ts +0 -5
  128. package/dist/build-tools/SdCliIndexFileGenerator.js.map +0 -1
  129. package/dist/build-tools/SdCliNgRoutesFileGenerator.d.ts +0 -4
  130. package/dist/build-tools/SdCliNgRoutesFileGenerator.js.map +0 -1
  131. package/dist/build-tools/SdLinter.d.ts +0 -5
  132. package/dist/build-tools/SdLinter.js +0 -49
  133. package/dist/build-tools/SdLinter.js.map +0 -1
  134. package/dist/build-tools/SdNgBundler.d.ts +0 -29
  135. package/dist/build-tools/SdNgBundler.js.map +0 -1
  136. package/dist/build-tools/SdNgBundlerContext.js.map +0 -1
  137. package/dist/build-tools/SdReactBundler.d.ts +0 -25
  138. package/dist/build-tools/SdReactBundler.js +0 -295
  139. package/dist/build-tools/SdReactBundler.js.map +0 -1
  140. package/dist/build-tools/SdReactBundlerContext.d.ts +0 -14
  141. package/dist/build-tools/SdReactBundlerContext.js +0 -59
  142. package/dist/build-tools/SdReactBundlerContext.js.map +0 -1
  143. package/dist/build-tools/SdServerBundler.d.ts +0 -20
  144. package/dist/build-tools/SdServerBundler.js.map +0 -1
  145. package/dist/build-tools/SdTsCompiler.d.ts +0 -34
  146. package/dist/build-tools/SdTsCompiler.js +0 -534
  147. package/dist/build-tools/SdTsCompiler.js.map +0 -1
  148. package/dist/build-tools/SdTsLibBundler.d.ts +0 -13
  149. package/dist/build-tools/SdTsLibBundler.js +0 -58
  150. package/dist/build-tools/SdTsLibBundler.js.map +0 -1
  151. package/dist/builders/SdCliClientBuilder.d.ts +0 -18
  152. package/dist/builders/SdCliClientBuilder.js +0 -172
  153. package/dist/builders/SdCliClientBuilder.js.map +0 -1
  154. package/dist/builders/SdCliJsLibLinter.d.ts +0 -13
  155. package/dist/builders/SdCliJsLibLinter.js +0 -60
  156. package/dist/builders/SdCliJsLibLinter.js.map +0 -1
  157. package/dist/builders/SdCliServerBuilder.d.ts +0 -15
  158. package/dist/builders/SdCliServerBuilder.js.map +0 -1
  159. package/dist/builders/SdCliTsLibBuilder.d.ts +0 -12
  160. package/dist/builders/SdCliTsLibBuilder.js +0 -90
  161. package/dist/builders/SdCliTsLibBuilder.js.map +0 -1
  162. package/dist/bundle-plugins/sdNgPlugin.d.ts +0 -16
  163. package/dist/bundle-plugins/sdNgPlugin.js.map +0 -1
  164. package/dist/bundle-plugins/sdReactPlugin.d.ts +0 -16
  165. package/dist/bundle-plugins/sdReactPlugin.js +0 -117
  166. package/dist/bundle-plugins/sdReactPlugin.js.map +0 -1
  167. package/dist/bundle-plugins/sdServerPlugin.d.ts +0 -16
  168. package/dist/bundle-plugins/sdServerPlugin.js +0 -63
  169. package/dist/bundle-plugins/sdServerPlugin.js.map +0 -1
  170. package/dist/commons.d.ts +0 -145
  171. package/dist/commons.js +0 -2
  172. package/dist/commons.js.map +0 -1
  173. package/dist/server-worker.js +0 -57
  174. package/dist/server-worker.js.map +0 -1
  175. package/dist/utils/SdCliBuildResultUtil.d.ts +0 -16
  176. package/dist/utils/SdCliBuildResultUtil.js +0 -54
  177. package/dist/utils/SdCliBuildResultUtil.js.map +0 -1
  178. package/src/build-cluster.ts +0 -212
  179. package/src/build-tools/SdCliCordova.ts +0 -340
  180. package/src/build-tools/SdLinter.ts +0 -65
  181. package/src/build-tools/SdNgBundlerContext.ts +0 -137
  182. package/src/build-tools/SdReactBundler.ts +0 -372
  183. package/src/build-tools/SdReactBundlerContext.ts +0 -71
  184. package/src/build-tools/SdTsCompiler.ts +0 -754
  185. package/src/build-tools/SdTsLibBundler.ts +0 -72
  186. package/src/builders/SdCliClientBuilder.ts +0 -233
  187. package/src/builders/SdCliJsLibLinter.ts +0 -72
  188. package/src/builders/SdCliTsLibBuilder.ts +0 -126
  189. package/src/bundle-plugins/sdReactPlugin.ts +0 -164
  190. package/src/bundle-plugins/sdServerPlugin.ts +0 -94
  191. package/src/commons.ts +0 -171
  192. package/src/server-worker.ts +0 -65
  193. package/src/utils/SdCliBuildResultUtil.ts +0 -63
  194. /package/dist/{build-cluster.d.ts → workers/compile-worker.d.ts} +0 -0
  195. /package/dist/{server-worker.d.ts → workers/lint-worker.d.ts} +0 -0
@@ -1,340 +0,0 @@
1
- import {INpmConfig, ISdCliClientBuilderCordovaConfig} from "../commons";
2
- import * as path from "path";
3
- import {FsUtil, Logger, SdProcess} from "@simplysm/sd-core-node";
4
- import xml2js from "xml2js";
5
- import JSZip from "jszip";
6
-
7
- const BIN_PATH = path.resolve(process.cwd(), "node_modules/.bin/cordova.cmd");
8
-
9
- export class SdCliCordova {
10
- protected readonly _logger = Logger.get(["simplysm", "sd-cli", "SdCliCordova"]);
11
-
12
- private readonly _platforms: string[];
13
- private readonly _npmConfig: INpmConfig;
14
-
15
- public constructor(private readonly _opt: {
16
- pkgPath: string;
17
- config: ISdCliClientBuilderCordovaConfig
18
- }) {
19
- this._platforms = Object.keys(this._opt.config.platform ?? {browser: {}});
20
- this._npmConfig = FsUtil.readJson(path.resolve(this._opt.pkgPath, "package.json"));
21
- // this._logger = Logger.get(["simplysm", "sd-cli", this.constructor.name, this._npmConfig.name]);
22
- }
23
-
24
- private async _execAsync(cmd: string, cwd: string): Promise<void> {
25
- this._logger.debug(cmd);
26
- const msg = await SdProcess.spawnAsync(cmd, {cwd});
27
- this._logger.debug(msg);
28
- }
29
-
30
- public async initializeAsync(): Promise<void> {
31
- const cordovaPath = path.resolve(this._opt.pkgPath, ".cordova");
32
-
33
- if (FsUtil.exists(cordovaPath)) {
34
- this._logger.log("이미 생성되어있는 '.cordova'를 사용합니다.");
35
- }
36
- else {
37
- await this._execAsync(`${BIN_PATH} telemetry on`, this._opt.pkgPath);
38
-
39
- // 프로젝트 생성
40
- await this._execAsync(`${BIN_PATH} create "${cordovaPath}" "${this._opt.config.appId}" "${this._opt.config.appName}"`, process.cwd());
41
- }
42
-
43
- // platforms 폴더 혹시 없으면 생성
44
- await FsUtil.mkdirsAsync(path.resolve(cordovaPath, "platforms"));
45
-
46
- // www 폴더 혹시 없으면 생성
47
- await FsUtil.mkdirsAsync(path.resolve(cordovaPath, "www"));
48
-
49
- // 미설치 빌드 플랫폼 신규 생성
50
- const alreadyPlatforms = await FsUtil.readdirAsync(path.resolve(cordovaPath, "platforms"));
51
- for (const platform of this._platforms) {
52
- if (!alreadyPlatforms.includes(platform)) {
53
- if (platform === "android") {
54
- await this._execAsync(`${BIN_PATH} platform add ${platform}@12.0.0`, cordovaPath);
55
- }
56
- else {
57
- await this._execAsync(`${BIN_PATH} platform add ${platform}`, cordovaPath);
58
- }
59
- }
60
- }
61
-
62
- // 설치 미빌드 플랫폼 삭제
63
- for (const alreadyPlatform of alreadyPlatforms) {
64
- if (!this._platforms.includes(alreadyPlatform)) {
65
- await this._execAsync(`${BIN_PATH} platform remove ${alreadyPlatform}`, cordovaPath);
66
- }
67
- }
68
-
69
- // 설치된 미사용 플러그인 삭제
70
- const pluginsFetch = FsUtil.exists(path.resolve(cordovaPath, "plugins/fetch.json"))
71
- ? await FsUtil.readJsonAsync(path.resolve(cordovaPath, "plugins/fetch.json"))
72
- : undefined;
73
- const alreadyPluginIds = pluginsFetch != undefined
74
- ? Object.keys(pluginsFetch)
75
- // Object.values(pluginsFetch).map((item: any) => item.source.id ?? item.source.url ?? item.source.path)
76
- : [];
77
- const usePlugins = ["cordova-plugin-ionic-webview", ...this._opt.config.plugins ?? []].distinct();
78
-
79
- for (const alreadyPluginId of alreadyPluginIds) {
80
- let hasPlugin = false;
81
- for (const usePlugin of usePlugins) {
82
- if (alreadyPluginId === usePlugin) {
83
- hasPlugin = true;
84
- break;
85
- }
86
- /*if (
87
- (usePlugin.includes("@") && alreadyPluginId === usePlugin) ||
88
- (!usePlugin.includes("@") && alreadyPluginId.replace(/@.*$/, "") === usePlugin)
89
- ) {
90
- hasPlugin = true;
91
- break;
92
- }*/
93
- }
94
-
95
- if (!hasPlugin) {
96
- await this._execAsync(`${BIN_PATH} plugin remove ${alreadyPluginId}`, cordovaPath);
97
- }
98
- }
99
-
100
- // 미설치 플러그인들 설치
101
- for (const usePlugin of usePlugins) {
102
- if (
103
- (usePlugin.includes("@") && !alreadyPluginIds.includes(usePlugin)) ||
104
- (!usePlugin.includes("@") && !alreadyPluginIds.map((alreadyPluginId) => alreadyPluginId.replace(/@.*$/, "")).includes(usePlugin))
105
- ) {
106
- await this._execAsync(`${BIN_PATH} plugin add ${usePlugin}`, cordovaPath);
107
- }
108
- }
109
-
110
- // ANDROID SIGN 파일 복사
111
- if (this._opt.config.platform?.android?.sign) {
112
- await FsUtil.copyAsync(
113
- path.resolve(this._opt.pkgPath, "src", this._opt.config.platform.android.sign.keystore),
114
- path.resolve(cordovaPath, "android.keystore")
115
- );
116
- }
117
- else {
118
- await FsUtil.removeAsync(path.resolve(cordovaPath, "android.keystore"));
119
- // SIGN을 안쓸경우 아래 파일이 생성되어 있으면 오류남
120
- await FsUtil.removeAsync(path.resolve(cordovaPath, "platforms/android/release-signing.properties"));
121
- }
122
-
123
- // 빌드 옵션 파일 생성
124
- await FsUtil.writeJsonAsync(
125
- path.resolve(cordovaPath, "build.json"),
126
- {
127
- ...this._opt.config.platform?.android ? {
128
- android: {
129
- release: {
130
- packageType: this._opt.config.platform.android.bundle ? "bundle" : "apk",
131
- ...this._opt.config.platform.android.sign ? {
132
- keystore: path.resolve(cordovaPath, "android.keystore"),
133
- storePassword: this._opt.config.platform.android.sign.storePassword,
134
- alias: this._opt.config.platform.android.sign.alias,
135
- password: this._opt.config.platform.android.sign.password,
136
- keystoreType: this._opt.config.platform.android.sign.keystoreType
137
- } : {}
138
- }
139
- }
140
- } : {}
141
- }
142
- );
143
-
144
- // ICON 파일 복사
145
- if (this._opt.config.icon != null) {
146
- await FsUtil.copyAsync(path.resolve(this._opt.pkgPath, "src", this._opt.config.icon), path.resolve(cordovaPath, "res/icons", path.basename(this._opt.config.icon)));
147
- }
148
- else {
149
- await FsUtil.removeAsync(path.resolve(cordovaPath, "res/icons"));
150
- }
151
-
152
- // SplashScreen 파일 생성
153
- if (this._opt.config.platform?.android && this._opt.config.icon != null) {
154
- await FsUtil.writeFileAsync(path.resolve(cordovaPath, "res/screen/android/splashscreen.xml"), `
155
- <?xml version="1.0" encoding="utf-8"?>
156
- <layer-list xmlns:android="http://schemas.android.com/apk/res/android">
157
- <item
158
- android:width="48dp"
159
- android:height="48dp"
160
- android:drawable="@mipmap/ic_launcher"
161
- android:gravity="center" />
162
- </layer-list>`.trim());
163
- }
164
-
165
- // CONFIG: 초기값 백업
166
- const configFilePath = path.resolve(cordovaPath, "config.xml");
167
- const configBackFilePath = path.resolve(cordovaPath, "config.xml.bak");
168
- if (!FsUtil.exists(configBackFilePath)) {
169
- await FsUtil.copyAsync(configFilePath, configBackFilePath);
170
- }
171
-
172
- // CONFIG: 초기값 읽기
173
- const configFileContent = await FsUtil.readFileAsync(configBackFilePath);
174
- const configXml = await xml2js.parseStringPromise(configFileContent);
175
-
176
-
177
- // CONFIG: 버전 설정
178
- configXml.widget.$.version = this._npmConfig.version;
179
-
180
- // CONFIG: ICON 설정
181
- if (this._opt.config.icon != null) {
182
- configXml["widget"]["icon"] = [{"$": {"src": "res/icons/" + path.basename(this._opt.config.icon)}}];
183
- }
184
-
185
- // CONFIG: 접근허용 세팅
186
- configXml["widget"]["access"] = [{"$": {"origin": "*"}}];
187
- configXml["widget"]["allow-navigation"] = [{"$": {"href": "*"}}];
188
- configXml["widget"]["allow-intent"] = [{"$": {"href": "*"}}];
189
- configXml["widget"]["preference"] = [{"$": {"name": "MixedContentMode", "value": "0"}}];
190
-
191
-
192
- // CONFIG: ANDROID usesCleartextTraffic 설정 및 splashscreen 파일 설정
193
- if (this._opt.config.platform?.android) {
194
- configXml.widget.$["xmlns:android"] = "http://schemas.android.com/apk/res/android";
195
-
196
- configXml["widget"]["platform"] = configXml["widget"]["platform"] ?? [];
197
-
198
- const androidPlatform = {
199
- "$": {
200
- "name": "android"
201
- },
202
- "preference": [{
203
- "$": {
204
- "name": "AndroidWindowSplashScreenAnimatedIcon",
205
- "value": "res/screen/android/splashscreen.xml"
206
- }
207
- }],
208
- "edit-config": [{
209
- "$": {
210
- "file": "app/src/main/AndroidManifest.xml",
211
- "mode": "merge",
212
- "target": "/manifest/application"
213
- },
214
- "application": [{
215
- "$": {
216
- "android:usesCleartextTraffic": "true"
217
- }
218
- }]
219
- }]
220
- };
221
-
222
- if (this._opt.config.platform.android.sdkVersion != null) {
223
- androidPlatform.preference.push(...[{
224
- "$": {
225
- "name": "android-maxSdkVersion",
226
- "value": `${this._opt.config.platform.android.sdkVersion}`
227
- }
228
- }, {
229
- "$": {
230
- "name": "android-minSdkVersion",
231
- "value": `${this._opt.config.platform.android.sdkVersion}`
232
- }
233
- }, {
234
- "$": {
235
- "name": "android-targetSdkVersion",
236
- "value": `${this._opt.config.platform.android.sdkVersion}`
237
- }
238
- }, {
239
- "$": {
240
- "name": "android-compileSdkVersion",
241
- "value": `33`
242
- }
243
- }]);
244
- }
245
-
246
- if (this._opt.config.platform.android.permissions) {
247
- androidPlatform["config-file"] = androidPlatform["config-file"] ?? [];
248
- androidPlatform["config-file"].push({
249
- "$": {
250
- "target": "AndroidManifest.xml",
251
- "parent": "/*"
252
- },
253
- "uses-permission": this._opt.config.platform.android.permissions.map(perm => ({
254
- "$": {
255
- "android:name": `android.permission.${perm.name}`,
256
- ...perm.maxSdkVersion != null ? {
257
- "android:maxSdkVersion": `${perm.maxSdkVersion}`
258
- } : {}
259
- }
260
- }))
261
- });
262
- }
263
-
264
- configXml["widget"]["platform"].push(androidPlatform);
265
- }
266
-
267
- // CONFIG: 파일 새로 쓰기
268
- const configResultContent = new xml2js.Builder().buildObject(configXml);
269
- await FsUtil.writeFileAsync(configFilePath, configResultContent);
270
-
271
- // 각 플랫폼 www 준비
272
- await this._execAsync(`${BIN_PATH} prepare`, cordovaPath);
273
- }
274
-
275
- public async buildAsync(outPath: string): Promise<void> {
276
- const cordovaPath = path.resolve(this._opt.pkgPath, ".cordova");
277
-
278
- // 실행
279
- const buildType = this._opt.config.debug ? "debug" : "release";
280
- for (const platform of this._platforms) {
281
- await this._execAsync(`${BIN_PATH} build ${platform} --${buildType}`, cordovaPath);
282
- }
283
-
284
- for (const platform of Object.keys(this._opt.config.platform ?? {})) {
285
- const targetOutPath = path.resolve(outPath, platform);
286
-
287
- // 결과물 복사: ANDROID
288
- if (platform === "android") {
289
- const apkFileName = this._opt.config.platform!.android!.sign ? `app-${buildType}.apk` : `app-${buildType}-unsigned.apk`;
290
- const latestDistApkFileName = path.basename(`${this._opt.config.appName}${this._opt.config.platform!.android!.sign ? "" : "-unsigned"}-latest.apk`);
291
- await FsUtil.mkdirsAsync(targetOutPath);
292
- await FsUtil.copyAsync(
293
- path.resolve(cordovaPath, "platforms/android/app/build/outputs/apk", buildType, apkFileName),
294
- path.resolve(targetOutPath, latestDistApkFileName)
295
- );
296
- }
297
-
298
- // 자동업데이트를 위한 파일 쓰기 (ZIP)
299
- const zip = new JSZip();
300
- const wwwFiles = await FsUtil.globAsync(path.resolve(cordovaPath, "www/**/*"), {nodir: true});
301
- for (const wwwFile of wwwFiles) {
302
- const relFilePath = path.relative(path.resolve(cordovaPath, "www"), wwwFile);
303
- const fileBuffer = await FsUtil.readFileBufferAsync(wwwFile);
304
- zip.file(relFilePath, fileBuffer);
305
- }
306
- const platformWwwFiles = await FsUtil.globAsync(path.resolve(cordovaPath, "platforms", platform, "platform_www/**/*"), {nodir: true});
307
- for (const platformWwwFile of platformWwwFiles) {
308
- const relFilePath = path.relative(path.resolve(cordovaPath, "platforms", platform, "platform_www"), platformWwwFile);
309
- const fileBuffer = await FsUtil.readFileBufferAsync(platformWwwFile);
310
- zip.file(relFilePath, fileBuffer);
311
- }
312
-
313
- await FsUtil.writeFileAsync(
314
- path.resolve(path.resolve(outPath, platform, "updates"), this._npmConfig.version + ".zip"),
315
- await zip.generateAsync({type: "nodebuffer"})
316
- );
317
- }
318
- }
319
-
320
- public static async runWebviewOnDeviceAsync(opt: {
321
- platform: string,
322
- pkgName: string,
323
- url?: string
324
- }): Promise<void> {
325
- const cordovaPath = path.resolve(process.cwd(), `packages/${opt.pkgName}/.cordova/`);
326
-
327
- if (opt.url !== undefined) {
328
- await FsUtil.removeAsync(path.resolve(cordovaPath, "www"));
329
- await FsUtil.mkdirsAsync(path.resolve(cordovaPath, "www"));
330
- await FsUtil.writeFileAsync(path.resolve(cordovaPath, "www/index.html"), `'${opt.url}'로 이동중... <script>setTimeout(function () {window.location.href = "${opt.url.replace(/\/$/, "")}/${opt.pkgName}/cordova/"}, 3000);</script>`.trim());
331
- }
332
- /*else {
333
- await FsUtil.removeAsync(path.resolve(cordovaPath, "www"));
334
- await FsUtil.copyAsync(path.resolve(process.cwd(), `packages/${opt.pkgName}/dist/cordova`), path.resolve(cordovaPath, "www"));
335
- }*/
336
-
337
- const binPath = path.resolve(process.cwd(), "node_modules/.bin/cordova.cmd");
338
- await SdProcess.spawnAsync(`${binPath} run ${opt.platform} --device`, {cwd: cordovaPath}, true);
339
- }
340
- }
@@ -1,65 +0,0 @@
1
- import { ISdCliPackageBuildResult } from "../commons";
2
- import { ESLint } from "eslint";
3
- import ts from "typescript";
4
- import { FsUtil, PathUtil } from "@simplysm/sd-core-node";
5
- import path from "path";
6
-
7
- export abstract class SdLinter {
8
- static async lintAsync(
9
- cwd: string,
10
- fileSet: Set<string>,
11
- tsProgram: ts.Program | undefined,
12
- ): Promise<ISdCliPackageBuildResult[]> {
13
- const isTsPackage = FsUtil.exists(path.resolve(cwd, "tsconfig.json"));
14
-
15
- const lintFilePaths = Array.from(fileSet)
16
- .filter((item) => PathUtil.isChildPath(item, cwd))
17
- .filter(
18
- (item) =>
19
- (isTsPackage && !item.endsWith(".d.ts") && item.endsWith(".ts")) ||
20
- item.endsWith(".js") ||
21
- item.endsWith(".tsx") ||
22
- item.endsWith(".jsx"),
23
- )
24
- .filter((item) => FsUtil.exists(item));
25
-
26
- if (lintFilePaths.length === 0) {
27
- return [];
28
- }
29
-
30
- const linter = new ESLint({
31
- cwd,
32
- cache: false,
33
- ...(isTsPackage && tsProgram
34
- ? {
35
- overrideConfig: [
36
- {
37
- files: ["**/*.ts", "**/*.tsx"],
38
- languageOptions: {
39
- parserOptions: {
40
- programs: [tsProgram],
41
- project: null,
42
- tsconfigRootDir: null,
43
- },
44
- },
45
- },
46
- ],
47
- }
48
- : {}),
49
- });
50
-
51
- const lintResults = await linter.lintFiles(lintFilePaths);
52
-
53
- return lintResults.mapMany((lintResult) =>
54
- lintResult.messages.map((msg) => ({
55
- filePath: lintResult.filePath,
56
- line: msg.line,
57
- char: msg.column,
58
- code: msg.messageId,
59
- severity: msg.severity === 1 ? ("warning" as const) : ("error" as const),
60
- message: msg.message + (msg.ruleId != null ? ` (${msg.ruleId})` : ``),
61
- type: "lint" as const,
62
- })),
63
- );
64
- }
65
- }
@@ -1,137 +0,0 @@
1
- import esbuild from "esbuild";
2
- import path from "path";
3
- import {ISdCliPackageBuildResult} from "../commons";
4
- import {Logger} from "@simplysm/sd-core-node";
5
- import {InitialFileRecord} from "@angular/build/src/tools/esbuild/bundler-context";
6
-
7
- export class SdNgBundlerContext {
8
- readonly #logger = Logger.get(["simplysm", "sd-cli", "SdNgBundlerContext"]);
9
-
10
- private _context?: esbuild.BuildContext;
11
-
12
- public constructor(private readonly _pkgPath: string,
13
- private readonly _esbuildOptions: esbuild.BuildOptions) {
14
- }
15
-
16
- public async bundleAsync() {
17
- if (this._context == null) {
18
- this._context = await esbuild.context(this._esbuildOptions);
19
- }
20
-
21
- let buildResult: esbuild.BuildResult;
22
-
23
- try {
24
- this.#debug(`rebuild...`);
25
- buildResult = await this._context.rebuild();
26
- this.#debug(`rebuild completed`);
27
- }
28
- catch (err) {
29
- if ("warnings" in err || "errors" in err) {
30
- buildResult = err;
31
- }
32
- else {
33
- throw err;
34
- }
35
- }
36
-
37
- this.#debug(`convert results...`);
38
-
39
- const results = [
40
- ...buildResult.warnings.map((warn) => ({
41
- filePath: warn.location?.file !== undefined ? path.resolve(this._pkgPath, warn.location.file) : undefined,
42
- line: warn.location?.line,
43
- char: warn.location?.column,
44
- code: warn.text.slice(0, warn.text.indexOf(":")),
45
- severity: "warning",
46
- message: `${warn.pluginName ? `(${warn.pluginName}) ` : ""} ${warn.text.slice(warn.text.indexOf(":") + 1)}`,
47
- type: "build"
48
- })),
49
- ...buildResult.errors.map((err) => ({
50
- filePath: err.location?.file !== undefined ? path.resolve(this._pkgPath, err.location.file) : undefined,
51
- line: err.location?.line,
52
- char: err.location?.column !== undefined ? err.location.column + 1 : undefined,
53
- code: err.text.slice(0, err.text.indexOf(":")),
54
- severity: "error",
55
- message: `${err.pluginName ? `(${err.pluginName}) ` : ""} ${err.text.slice(err.text.indexOf(":") + 1)}`,
56
- type: "build"
57
- }))
58
- ] as ISdCliPackageBuildResult[];
59
-
60
- const initialFiles = new Map<string, InitialFileRecord>();
61
-
62
- for (const outputFile of buildResult.outputFiles ?? []) {
63
- const relativeFilePath = path.isAbsolute(outputFile.path) ? path.relative(this._pkgPath, outputFile.path) : outputFile.path;
64
- const entryPoint = buildResult.metafile?.outputs[relativeFilePath]?.entryPoint;
65
-
66
- outputFile.path = relativeFilePath;
67
-
68
- if (entryPoint != null) {
69
- const name = path.basename(relativeFilePath).split('.', 1)[0];
70
- const type = path.extname(relativeFilePath) === '.css' ? 'style' : 'script';
71
-
72
- if (this._esbuildOptions.entryPoints?.[name] != null) {
73
- initialFiles.set(relativeFilePath, {
74
- name,
75
- type,
76
- entrypoint: true,
77
- serverFile: false,
78
- depth: 0
79
- });
80
- }
81
- }
82
- }
83
-
84
- const files = [...initialFiles.keys()];
85
- for (const file of files) {
86
- const entryRecord = initialFiles.get(file)!;
87
-
88
- for (const initialImport of buildResult.metafile?.outputs[file]?.imports ?? []) {
89
- const existingRecord = initialFiles.get(initialImport.path);
90
- if (existingRecord) {
91
- if (existingRecord.depth > entryRecord.depth + 1) {
92
- existingRecord.depth = entryRecord.depth + 1;
93
- }
94
- continue;
95
- }
96
-
97
- if (initialImport.kind === 'import-statement' || initialImport.kind === 'import-rule') {
98
- const record: InitialFileRecord = {
99
- type: initialImport.kind === 'import-rule' ? 'style' : 'script',
100
- entrypoint: false,
101
- external: initialImport.external,
102
- serverFile: false,
103
- depth: entryRecord.depth + 1
104
- };
105
-
106
- initialFiles.set(initialImport.path, record);
107
-
108
- if (!initialImport.external) {
109
- files.push(initialImport.path);
110
- }
111
- }
112
- }
113
- }
114
-
115
- // const dependencyMap = new Map<string, Set<string>>();
116
- // if (buildResult.metafile) {
117
- // for (const [key, val] of Object.entries(buildResult.metafile.inputs)) {
118
- // for (const imp of val.imports) {
119
- // const deps = dependencyMap.getOrCreate(path.resolve(this._pkgPath, imp.path), new Set<string>());
120
- // deps.add(path.resolve(this._pkgPath, key));
121
- // }
122
- // }
123
- // }
124
-
125
- return {
126
- results,
127
- initialFiles,
128
- outputFiles: buildResult.outputFiles,
129
- // dependencyMap,
130
- metafile: buildResult.metafile
131
- };
132
- }
133
-
134
- #debug(...msg: any[]): void {
135
- this.#logger.debug(`[${path.basename(this._pkgPath)}] (${Object.keys(this._esbuildOptions.entryPoints as Record<string, any>).join(", ")})`, ...msg);
136
- }
137
- }