@simplysm/sd-cli 7.0.81 → 7.0.100
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.
- package/dist/bin/sd-cli.mjs +13 -3
- package/dist/build-tool/SdCliCordova.d.ts +4 -4
- package/dist/build-tool/SdCliCordova.mjs +105 -105
- package/dist/build-tool/SdCliElectron.d.ts +3 -0
- package/dist/build-tool/SdCliElectron.mjs +21 -0
- package/dist/builder/SdCliClientBuilder.mjs +123 -53
- package/dist/commons.d.ts +25 -10
- package/dist/entry-points/SdCliWorkspace.mjs +21 -4
- package/dist/index.d.ts +1 -0
- package/dist/index.mjs +2 -1
- package/dist/ng-tools/babel/SdCliBbFileMetadata.mjs +2 -2
- package/dist/ng-tools/babel/SdCliBbRootMetadata.d.ts +1 -0
- package/dist/ng-tools/babel/SdCliBbRootMetadata.mjs +29 -3
- package/package.json +11 -7
- package/src/bin/sd-cli.ts +18 -4
- package/src/build-tool/SdCliCordova.ts +130 -140
- package/src/build-tool/SdCliElectron.ts +25 -0
- package/src/builder/SdCliClientBuilder.ts +136 -54
- package/src/commons.ts +28 -10
- package/src/entry-points/SdCliWorkspace.ts +19 -3
- package/src/index.ts +1 -0
- package/src/ng-tools/babel/SdCliBbFileMetadata.ts +1 -1
- package/src/ng-tools/babel/SdCliBbRootMetadata.ts +30 -2
- package/tsconfig.json +3 -0
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import { INpmConfig,
|
|
1
|
+
import { INpmConfig, ISdCliClientBuilderCordovaConfig } from "../commons";
|
|
2
2
|
import * as path from "path";
|
|
3
3
|
import { FsUtil, Logger, SdProcess } from "@simplysm/sd-core-node";
|
|
4
|
-
import { NotImplementError } from "@simplysm/sd-core-common";
|
|
5
4
|
import JSZip from "jszip";
|
|
5
|
+
import xml2js from "xml2js";
|
|
6
6
|
|
|
7
7
|
export class SdCliCordova {
|
|
8
8
|
protected readonly _logger: Logger;
|
|
@@ -12,11 +12,14 @@ export class SdCliCordova {
|
|
|
12
12
|
public readonly cordovaPath = path.resolve(this._rootPath, ".cordova");
|
|
13
13
|
private readonly _binPath = path.resolve(process.cwd(), "node_modules/.bin/cordova.cmd");
|
|
14
14
|
|
|
15
|
-
public get platforms():
|
|
16
|
-
return
|
|
15
|
+
public get platforms(): ("browser" | "android")[] {
|
|
16
|
+
return [
|
|
17
|
+
...this._config.targets?.browser ? ["browser" as const] : [],
|
|
18
|
+
...this._config.targets?.android ? ["android" as const] : []
|
|
19
|
+
];
|
|
17
20
|
}
|
|
18
21
|
|
|
19
|
-
public constructor(private readonly _rootPath: string, private readonly _config:
|
|
22
|
+
public constructor(private readonly _rootPath: string, private readonly _config: ISdCliClientBuilderCordovaConfig) {
|
|
20
23
|
this._npmConfig = FsUtil.readJson(path.resolve(this._rootPath, "package.json"));
|
|
21
24
|
this._logger = Logger.get(["simplysm", "sd-cli", this.constructor.name, this._npmConfig.name]);
|
|
22
25
|
}
|
|
@@ -52,156 +55,156 @@ export class SdCliCordova {
|
|
|
52
55
|
}
|
|
53
56
|
}
|
|
54
57
|
|
|
55
|
-
//
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
: undefined;
|
|
60
|
-
const alreadyPlugins = pluginsFetch != undefined
|
|
61
|
-
? Object.values(pluginsFetch)
|
|
62
|
-
.map((item: any) => (item.source.id !== undefined ? item.source.id.replace(/@.*$/, "") : item.source.url))
|
|
63
|
-
: [];
|
|
64
|
-
|
|
65
|
-
for (const plugin of this._config.plugins.distinct()) {
|
|
66
|
-
if (!alreadyPlugins.includes(plugin)) {
|
|
67
|
-
await this._execAsync(`${this._binPath} plugin add ${plugin}`, this.cordovaPath);
|
|
68
|
-
}
|
|
58
|
+
// 설치 미빌드 플랫폼 삭제
|
|
59
|
+
for (const alreadyPlatform of alreadyPlatforms) {
|
|
60
|
+
if (this._config[alreadyPlatform] == null) {
|
|
61
|
+
await this._execAsync(`${this._binPath} platform remove ${alreadyPlatform}`, this.cordovaPath);
|
|
69
62
|
}
|
|
70
63
|
}
|
|
71
64
|
|
|
72
|
-
//
|
|
73
|
-
|
|
74
|
-
await FsUtil.
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
if (this._config.icon !== undefined && !configFileContent.includes("<icon")) {
|
|
86
|
-
configFileContent = configFileContent.replace("</widget>", " <icon src=\"res/icon/icon.png\" />\r\n</widget>");
|
|
65
|
+
// 미설치 플러그인들 설치
|
|
66
|
+
const pluginsFetch = FsUtil.exists(path.resolve(this.cordovaPath, "plugins/fetch.json"))
|
|
67
|
+
? await FsUtil.readJsonAsync(path.resolve(this.cordovaPath, "plugins/fetch.json"))
|
|
68
|
+
: undefined;
|
|
69
|
+
const alreadyPlugins = pluginsFetch != undefined
|
|
70
|
+
? Object.values(pluginsFetch)
|
|
71
|
+
.map((item: any) => (item.source.id !== undefined ? item.source.id.replace(/@.*$/, "") : item.source.url))
|
|
72
|
+
: [];
|
|
73
|
+
|
|
74
|
+
for (const plugin of this._config.plugins?.distinct() ?? []) {
|
|
75
|
+
if (!alreadyPlugins.includes(plugin)) {
|
|
76
|
+
await this._execAsync(`${this._binPath} plugin add ${plugin}`, this.cordovaPath);
|
|
77
|
+
}
|
|
87
78
|
}
|
|
88
79
|
|
|
89
|
-
//
|
|
90
|
-
|
|
91
|
-
if (!
|
|
92
|
-
|
|
93
|
-
"xmlns=\"http://www.w3.org/ns/widgets\"",
|
|
94
|
-
`xmlns="http://www.w3.org/ns/widgets" xmlns:android="http://schemas.android.com/apk/res/android"`
|
|
95
|
-
);
|
|
96
|
-
}
|
|
97
|
-
if (!configFileContent.includes("application android:usesCleartextTraffic=\"true\" />")) {
|
|
98
|
-
if (configFileContent.includes("<platform name=\"android\">")) {
|
|
99
|
-
configFileContent = configFileContent.replace("<platform name=\"android\">", `<platform name="android">
|
|
100
|
-
<edit-config file="app/src/main/AndroidManifest.xml" mode="merge" target="/manifest/application">
|
|
101
|
-
<application android:usesCleartextTraffic="true" />
|
|
102
|
-
</edit-config>`);
|
|
103
|
-
}
|
|
104
|
-
else {
|
|
105
|
-
configFileContent = configFileContent.replace("<content src=\"index.html\" />", `<content src="index.html" />
|
|
106
|
-
<platform name="android">
|
|
107
|
-
<edit-config file="app/src/main/AndroidManifest.xml" mode="merge" target="/manifest/application">
|
|
108
|
-
<application android:usesCleartextTraffic="true" />
|
|
109
|
-
</edit-config>
|
|
110
|
-
</platform>`);
|
|
111
|
-
}
|
|
80
|
+
// 설치된 미사용 플러그인 삭제
|
|
81
|
+
for (const alreadyPlugin of alreadyPlugins) {
|
|
82
|
+
if (!(this._config.plugins?.distinct() ?? []).includes(alreadyPlugin)) {
|
|
83
|
+
await this._execAsync(`${this._binPath} plugin remove ${alreadyPlugin}`, this.cordovaPath);
|
|
112
84
|
}
|
|
113
85
|
}
|
|
114
86
|
|
|
115
|
-
//
|
|
116
|
-
|
|
117
|
-
}
|
|
118
|
-
|
|
119
|
-
public async buildAsync(outPath: string): Promise<void> {
|
|
120
|
-
const packageType = this._config.buildOption?.bundle ? "bundle" : "apk";
|
|
121
|
-
|
|
122
|
-
// ANDROID 서명 처리
|
|
123
|
-
if (this._config.buildOption?.sign?.android) {
|
|
87
|
+
// ANDROID SIGN 파일 복사
|
|
88
|
+
if (this._config.targets?.android?.sign) {
|
|
124
89
|
await FsUtil.copyAsync(
|
|
125
|
-
path.resolve(this._rootPath, this._config.
|
|
126
|
-
path.resolve(this.cordovaPath,
|
|
90
|
+
path.resolve(this._rootPath, this._config.targets.android.sign.keystore),
|
|
91
|
+
path.resolve(this.cordovaPath, "android.keystore")
|
|
127
92
|
);
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
93
|
+
}
|
|
94
|
+
else {
|
|
95
|
+
await FsUtil.removeAsync(path.resolve(this.cordovaPath, "android.keystore"));
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
// 빌드 옵션 파일 생성
|
|
99
|
+
await FsUtil.writeJsonAsync(
|
|
100
|
+
path.resolve(this.cordovaPath, "build.json"),
|
|
101
|
+
{
|
|
102
|
+
...this._config.targets?.android ? {
|
|
131
103
|
android: {
|
|
132
104
|
release: {
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
105
|
+
packageType: this._config.targets.android.bundle ? "bundle" : "apk",
|
|
106
|
+
...this._config.targets.android.sign ? {
|
|
107
|
+
keystore: path.resolve(this.cordovaPath, "android.keystore"),
|
|
108
|
+
storePassword: this._config.targets.android.sign.storePassword,
|
|
109
|
+
alias: this._config.targets.android.sign.alias,
|
|
110
|
+
password: this._config.targets.android.sign.password,
|
|
111
|
+
keystoreType: this._config.targets.android.sign.keystoreType
|
|
112
|
+
} : {}
|
|
139
113
|
}
|
|
140
114
|
}
|
|
141
|
-
}
|
|
142
|
-
|
|
115
|
+
} : {}
|
|
116
|
+
}
|
|
117
|
+
);
|
|
118
|
+
|
|
119
|
+
// ICON 파일 복사
|
|
120
|
+
if (this._config.icon !== undefined) {
|
|
121
|
+
await FsUtil.copyAsync(path.resolve(this._rootPath, this._config.icon), path.resolve(this.cordovaPath, "res", "icon.png"));
|
|
122
|
+
}
|
|
123
|
+
else {
|
|
124
|
+
await FsUtil.removeAsync(path.resolve(this.cordovaPath, "res", "icon.png"));
|
|
143
125
|
}
|
|
144
126
|
|
|
145
|
-
// CONFIG
|
|
127
|
+
// CONFIG: 초기값 백업
|
|
146
128
|
const configFilePath = path.resolve(this.cordovaPath, "config.xml");
|
|
147
|
-
|
|
129
|
+
const configBackFilePath = path.resolve(this.cordovaPath, "config.xml.bak");
|
|
130
|
+
if (!FsUtil.exists(configBackFilePath)) {
|
|
131
|
+
await FsUtil.copyAsync(configFilePath, configBackFilePath);
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
// CONFIG: 초기값 읽기
|
|
135
|
+
const configFileContent = await FsUtil.readFileAsync(configBackFilePath);
|
|
136
|
+
const configXml = await xml2js.parseStringPromise(configFileContent);
|
|
137
|
+
|
|
138
|
+
|
|
139
|
+
// CONFIG: 버전 설정
|
|
140
|
+
configXml.widget.$.version = this._npmConfig.version;
|
|
141
|
+
|
|
142
|
+
// CONFIG: ICON 설정
|
|
143
|
+
if (this._config.icon !== undefined) {
|
|
144
|
+
configXml["widget"]["icon"] = [{ "$": { "src": "res/icon.png" } }];
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
// CONFIG: 접근허용 세팅
|
|
148
|
+
configXml["widget"]["allow-navigation"] = [{ "$": { "href": "*://*/*" } }];
|
|
148
149
|
|
|
149
|
-
// CONFIG:
|
|
150
|
-
|
|
150
|
+
// CONFIG: ANDROID usesCleartextTraffic 설정
|
|
151
|
+
if (this._config.targets?.android) {
|
|
152
|
+
configXml.widget.$["xmlns:android"] = "http://schemas.android.com/apk/res/android";
|
|
153
|
+
|
|
154
|
+
configXml["widget"]["platform"] = configXml["widget"]["platform"] ?? [];
|
|
155
|
+
configXml["widget"]["platform"].push({
|
|
156
|
+
"$": {
|
|
157
|
+
"name": "android"
|
|
158
|
+
},
|
|
159
|
+
"edit-config": [{
|
|
160
|
+
"$": {
|
|
161
|
+
"file": "app/src/main/AndroidManifest.xml",
|
|
162
|
+
"mode": "merge",
|
|
163
|
+
"target": "/manifest/application"
|
|
164
|
+
},
|
|
165
|
+
"application": [{
|
|
166
|
+
"android:usesCleartextTraffic": "true"
|
|
167
|
+
}]
|
|
168
|
+
}]
|
|
169
|
+
});
|
|
170
|
+
}
|
|
151
171
|
|
|
152
|
-
// CONFIG:
|
|
153
|
-
|
|
172
|
+
// CONFIG: 파일 새로 쓰기
|
|
173
|
+
const configResultContent = new xml2js.Builder().buildObject(configXml);
|
|
174
|
+
await FsUtil.writeFileAsync(configFilePath, configResultContent);
|
|
154
175
|
|
|
155
|
-
//
|
|
156
|
-
await
|
|
176
|
+
// 각 플랫폼 www 준비
|
|
177
|
+
await this._execAsync(`${this._binPath} prepare`, this.cordovaPath);
|
|
178
|
+
}
|
|
157
179
|
|
|
180
|
+
public async buildAsync(outPath: string): Promise<void> {
|
|
158
181
|
// 실행
|
|
159
|
-
const buildType = this._config.
|
|
182
|
+
const buildType = this._config.debug ? "debug" : "release";
|
|
160
183
|
for (const platform of this.platforms) {
|
|
161
|
-
await this._execAsync(`${this._binPath} build ${platform} --${buildType}
|
|
184
|
+
await this._execAsync(`${this._binPath} build ${platform} --${buildType}`, this.cordovaPath);
|
|
162
185
|
}
|
|
163
186
|
|
|
164
|
-
// 결과물
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
);
|
|
180
|
-
}
|
|
181
|
-
else if (platform === "electron") {
|
|
182
|
-
const targetOutPath = path.resolve(outPath, platform);
|
|
183
|
-
const outFileName = `${this._config.appName} Setup ${this._npmConfig.version}.exe`;
|
|
184
|
-
const distFileName = outFileName;
|
|
185
|
-
const latestDistFileName = `${this._config.appName} Setup latest.exe`;
|
|
186
|
-
await FsUtil.mkdirsAsync(targetOutPath);
|
|
187
|
-
await FsUtil.copyAsync(
|
|
188
|
-
path.resolve(this.cordovaPath, "platforms/electron/build/", outFileName),
|
|
189
|
-
path.resolve(targetOutPath, distFileName)
|
|
190
|
-
);
|
|
191
|
-
await FsUtil.copyAsync(
|
|
192
|
-
path.resolve(this.cordovaPath, "platforms/electron/build/", outFileName),
|
|
193
|
-
path.resolve(targetOutPath, latestDistFileName)
|
|
194
|
-
);
|
|
195
|
-
}
|
|
196
|
-
else {
|
|
197
|
-
throw new NotImplementError();
|
|
198
|
-
}
|
|
187
|
+
// 결과물 복사: ANDROID
|
|
188
|
+
if (this._config.targets?.android) {
|
|
189
|
+
const targetOutPath = path.resolve(outPath, "android");
|
|
190
|
+
const apkFileName = this._config.targets.android.sign ? `app-${buildType}.apk` : `app-${buildType}-unsigned.apk`;
|
|
191
|
+
const distApkFileName = path.basename(`${this._config.appName}${this._config.targets.android.sign ? "" : "-unsigned"}-v${this._npmConfig.version}.apk`);
|
|
192
|
+
const latestDistApkFileName = path.basename(`${this._config.appName}${this._config.targets.android.sign ? "" : "-unsigned"}-latest.apk`);
|
|
193
|
+
await FsUtil.mkdirsAsync(targetOutPath);
|
|
194
|
+
await FsUtil.copyAsync(
|
|
195
|
+
path.resolve(this.cordovaPath, "platforms/android/app/build/outputs/apk", buildType, apkFileName),
|
|
196
|
+
path.resolve(targetOutPath, distApkFileName)
|
|
197
|
+
);
|
|
198
|
+
await FsUtil.copyAsync(
|
|
199
|
+
path.resolve(this.cordovaPath, "platforms/android/app/build/outputs/apk", buildType, apkFileName),
|
|
200
|
+
path.resolve(targetOutPath, latestDistApkFileName)
|
|
201
|
+
);
|
|
199
202
|
}
|
|
200
203
|
|
|
201
|
-
if (this.
|
|
204
|
+
if (this._config.targets?.android) {
|
|
202
205
|
// 자동업데이트를 위한 zip 파일 쓰기
|
|
203
206
|
const zip = new JSZip();
|
|
204
|
-
const resultFiles = await FsUtil.globAsync(path.resolve(this.cordovaPath, "www", "**/*"), {
|
|
207
|
+
const resultFiles = await FsUtil.globAsync(path.resolve(this.cordovaPath, "platforms", "android", "app", "src", "main", "assets", "www", "**/*"), {
|
|
205
208
|
dot: true,
|
|
206
209
|
nodir: true
|
|
207
210
|
});
|
|
@@ -218,24 +221,11 @@ export class SdCliCordova {
|
|
|
218
221
|
}
|
|
219
222
|
}
|
|
220
223
|
|
|
221
|
-
public static async runWebviewOnDeviceAsync(cordovaPath: string, platform:
|
|
224
|
+
public static async runWebviewOnDeviceAsync(cordovaPath: string, platform: "browser" | "android", url: string): Promise<void> {
|
|
222
225
|
await FsUtil.removeAsync(path.resolve(cordovaPath, "www"));
|
|
223
226
|
await FsUtil.mkdirsAsync(path.resolve(cordovaPath, "www"));
|
|
224
227
|
await FsUtil.writeFileAsync(path.resolve(cordovaPath, "www/index.html"), `'${url}'로 이동중... <script>setTimeout(function () {window.location.href = "${url}"}, 3000);</script>`.trim());
|
|
225
228
|
|
|
226
|
-
// CONFIG
|
|
227
|
-
const configFilePath = path.resolve(cordovaPath, "config.xml");
|
|
228
|
-
let configFileContent = await FsUtil.readFileAsync(configFilePath);
|
|
229
|
-
|
|
230
|
-
// CONFIG: 접근허용 일단 모두 지우기
|
|
231
|
-
configFileContent = configFileContent.replace(/ {4}<allow-navigation href="[^"]*" \/>\n/g, "");
|
|
232
|
-
|
|
233
|
-
// CONFIG: 접근허용 등록
|
|
234
|
-
configFileContent = configFileContent.replace("</widget>", ` <allow-navigation href="*://*/*" />\n</widget>`);
|
|
235
|
-
|
|
236
|
-
// CONFIG: 파일쓰기
|
|
237
|
-
await FsUtil.writeFileAsync(configFilePath, configFileContent);
|
|
238
|
-
|
|
239
229
|
const binPath = path.resolve(process.cwd(), "node_modules/.bin/cordova.cmd");
|
|
240
230
|
await SdProcess.spawnAsync(`${binPath} run ${platform} --device`, { cwd: cordovaPath }, true);
|
|
241
231
|
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { FsUtil, SdProcess } from "@simplysm/sd-core-node";
|
|
2
|
+
import { INpmConfig } from "../commons";
|
|
3
|
+
import path from "path";
|
|
4
|
+
|
|
5
|
+
export class SdCliElectron {
|
|
6
|
+
public static async runWebviewOnDeviceAsync(rootPath: string, pkgName: string): Promise<void> {
|
|
7
|
+
const electronPath = path.resolve(rootPath, `packages/${pkgName}/.electron`);
|
|
8
|
+
|
|
9
|
+
const npmConfig = (await FsUtil.readJsonAsync(path.resolve(rootPath, `packages/${pkgName}/package.json`))) as INpmConfig;
|
|
10
|
+
await FsUtil.writeJsonAsync(path.resolve(electronPath, `package.json`), {
|
|
11
|
+
name: npmConfig.name,
|
|
12
|
+
version: npmConfig.version,
|
|
13
|
+
description: npmConfig.description,
|
|
14
|
+
main: "electron.js",
|
|
15
|
+
author: npmConfig.author,
|
|
16
|
+
license: npmConfig.license
|
|
17
|
+
});
|
|
18
|
+
|
|
19
|
+
await FsUtil.copyAsync(path.resolve(rootPath, `packages/${pkgName}/src/electron.dev.js`), path.resolve(electronPath, "electron.js"));
|
|
20
|
+
|
|
21
|
+
await SdProcess.spawnAsync(`electron "${electronPath}"`, {
|
|
22
|
+
cwd: rootPath
|
|
23
|
+
}, true);
|
|
24
|
+
}
|
|
25
|
+
}
|