@simplysm/sd-cli 7.0.224 → 7.0.231
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/.eslintrc.cjs +21 -21
- package/dist/bin/sd-cli.mjs +2 -2
- package/dist/builder/SdCliClientBuilder.mjs +4 -3
- package/dist/builder/SdCliServerBuilder.mjs +2 -2
- package/dist/entry-points/SdCliNpm.mjs +2 -8
- package/dist/packages/SdCliPackage.mjs +2 -2
- package/package.json +37 -38
- package/src/bin/sd-cli.ts +274 -274
- package/src/build-tool/SdCliElectron.ts +81 -81
- package/src/builder/SdCliClientBuilder.ts +737 -736
- package/src/builder/SdCliServerBuilder.ts +483 -483
- package/src/commons.ts +138 -135
- package/src/entry-points/SdCliNpm.ts +19 -26
- package/src/packages/SdCliPackage.ts +242 -242
|
@@ -1,242 +1,242 @@
|
|
|
1
|
-
import { INpmConfig, ISdCliPackageBuildResult, ITsconfig, TSdCliPackageConfig } from "../commons";
|
|
2
|
-
import path from "path";
|
|
3
|
-
import { FsUtil, PathUtil, SdProcess } from "@simplysm/sd-core-node";
|
|
4
|
-
import { EventEmitter } from "events";
|
|
5
|
-
import { JsonConvert, NeverEntryError, ObjectUtil, StringUtil } from "@simplysm/sd-core-common";
|
|
6
|
-
import { SdCliNpmConfigUtil } from "../utils/SdCliNpmConfigUtil";
|
|
7
|
-
import { SdStorage } from "@simplysm/sd-storage";
|
|
8
|
-
import ts from "typescript";
|
|
9
|
-
import { SdCliGithubApi } from "../build-tool/SdCliGithubApi";
|
|
10
|
-
import cp from "child_process";
|
|
11
|
-
import { fileURLToPath } from "url";
|
|
12
|
-
|
|
13
|
-
export class SdCliPackage extends EventEmitter {
|
|
14
|
-
private readonly _npmConfig: INpmConfig;
|
|
15
|
-
|
|
16
|
-
public get basename(): string {
|
|
17
|
-
return path.basename(this._workspaceRootPath);
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
public get name(): string {
|
|
21
|
-
return this._npmConfig.name;
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
public get main(): string | undefined {
|
|
25
|
-
return this._npmConfig.main;
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
public get allDependencies(): string[] {
|
|
29
|
-
return [
|
|
30
|
-
...SdCliNpmConfigUtil.getDependencies(this._npmConfig).defaults,
|
|
31
|
-
...SdCliNpmConfigUtil.getDependencies(this._npmConfig).optionals
|
|
32
|
-
].distinct();
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
public constructor(private readonly _workspaceRootPath: string,
|
|
36
|
-
public readonly rootPath: string,
|
|
37
|
-
public readonly config: TSdCliPackageConfig) {
|
|
38
|
-
super();
|
|
39
|
-
|
|
40
|
-
const npmConfigFilePath = path.resolve(this.rootPath, "package.json");
|
|
41
|
-
this._npmConfig = FsUtil.readJson(npmConfigFilePath);
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
public override on(event: "change", listener: () => void): this;
|
|
45
|
-
public override on(event: "complete", listener: (results: ISdCliPackageBuildResult[]) => void): this;
|
|
46
|
-
public override on(event: string | symbol, listener: (...args: any[]) => void): this {
|
|
47
|
-
return super.on(event, listener);
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
public async setNewVersionAsync(newVersion: string, pkgNames: string[]): Promise<void> {
|
|
51
|
-
this._npmConfig.version = newVersion;
|
|
52
|
-
|
|
53
|
-
const updateDepVersion = (deps: Record<string, string> | undefined): void => {
|
|
54
|
-
if (!deps) return;
|
|
55
|
-
for (const depName of Object.keys(deps)) {
|
|
56
|
-
if (pkgNames.includes(depName)) {
|
|
57
|
-
deps[depName] = newVersion;
|
|
58
|
-
}
|
|
59
|
-
}
|
|
60
|
-
};
|
|
61
|
-
updateDepVersion(this._npmConfig.dependencies);
|
|
62
|
-
updateDepVersion(this._npmConfig.optionalDependencies);
|
|
63
|
-
updateDepVersion(this._npmConfig.devDependencies);
|
|
64
|
-
updateDepVersion(this._npmConfig.peerDependencies);
|
|
65
|
-
|
|
66
|
-
const npmConfigFilePath = path.resolve(this.rootPath, "package.json");
|
|
67
|
-
await FsUtil.writeJsonAsync(npmConfigFilePath, this._npmConfig, { space: 2 });
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
public async watchAsync(): Promise<void> {
|
|
71
|
-
const isTs = FsUtil.exists(path.resolve(this.rootPath, "tsconfig.json"));
|
|
72
|
-
|
|
73
|
-
if (isTs) {
|
|
74
|
-
await this._genBuildTsconfigAsync();
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
const workerPath = fileURLToPath(await import.meta.resolve!("../worker/build-worker"));
|
|
78
|
-
await new Promise<void>((resolve, reject) => {
|
|
79
|
-
const worker = cp.fork(workerPath, [
|
|
80
|
-
"watch",
|
|
81
|
-
this.rootPath,
|
|
82
|
-
JsonConvert.stringify(this.config),
|
|
83
|
-
this._workspaceRootPath
|
|
84
|
-
], {
|
|
85
|
-
stdio: ["pipe", "pipe", "pipe", "ipc"],
|
|
86
|
-
env: process.env
|
|
87
|
-
});
|
|
88
|
-
|
|
89
|
-
worker.on("error", (err) => {
|
|
90
|
-
reject(err);
|
|
91
|
-
});
|
|
92
|
-
|
|
93
|
-
worker.stdout!.pipe(process.stdout);
|
|
94
|
-
worker.stderr!.pipe(process.stderr);
|
|
95
|
-
|
|
96
|
-
worker.on("message", (json: string) => {
|
|
97
|
-
const msg = JsonConvert.parse(json);
|
|
98
|
-
if (msg.event === "ready") {
|
|
99
|
-
resolve();
|
|
100
|
-
}
|
|
101
|
-
else if (msg.event === "change") {
|
|
102
|
-
this.emit("change");
|
|
103
|
-
}
|
|
104
|
-
else if (msg.event === "complete") {
|
|
105
|
-
this.emit("complete", msg.body);
|
|
106
|
-
}
|
|
107
|
-
else {
|
|
108
|
-
throw new NeverEntryError();
|
|
109
|
-
}
|
|
110
|
-
});
|
|
111
|
-
});
|
|
112
|
-
}
|
|
113
|
-
|
|
114
|
-
public async buildAsync(): Promise<ISdCliPackageBuildResult[]> {
|
|
115
|
-
const isTs = FsUtil.exists(path.resolve(this.rootPath, "tsconfig.json"));
|
|
116
|
-
|
|
117
|
-
if (isTs) {
|
|
118
|
-
await this._genBuildTsconfigAsync();
|
|
119
|
-
}
|
|
120
|
-
|
|
121
|
-
const workerPath = fileURLToPath(await import.meta.resolve!("../worker/build-worker"));
|
|
122
|
-
return await new Promise<ISdCliPackageBuildResult[]>((resolve, reject) => {
|
|
123
|
-
const worker = cp.fork(workerPath, [
|
|
124
|
-
"build",
|
|
125
|
-
this.rootPath,
|
|
126
|
-
JsonConvert.stringify(this.config),
|
|
127
|
-
this._workspaceRootPath
|
|
128
|
-
], {
|
|
129
|
-
stdio: ["pipe", "pipe", "pipe", "ipc"],
|
|
130
|
-
env: process.env
|
|
131
|
-
});
|
|
132
|
-
|
|
133
|
-
worker.on("error", (err) => {
|
|
134
|
-
reject(err);
|
|
135
|
-
});
|
|
136
|
-
|
|
137
|
-
worker.stdout!.pipe(process.stdout);
|
|
138
|
-
worker.stderr!.pipe(process.stderr);
|
|
139
|
-
|
|
140
|
-
let result: ISdCliPackageBuildResult[] = [];
|
|
141
|
-
|
|
142
|
-
worker.on("message", (json: string) => {
|
|
143
|
-
result = JsonConvert.parse(json);
|
|
144
|
-
});
|
|
145
|
-
|
|
146
|
-
worker.on("exit", (code) => {
|
|
147
|
-
if (code !== 0) {
|
|
148
|
-
reject(new Error(`오류와 함께 닫힘 (${code})`));
|
|
149
|
-
return;
|
|
150
|
-
}
|
|
151
|
-
|
|
152
|
-
resolve(result);
|
|
153
|
-
});
|
|
154
|
-
});
|
|
155
|
-
}
|
|
156
|
-
|
|
157
|
-
public async publishAsync(): Promise<void> {
|
|
158
|
-
if (this.config.publish !== undefined) {
|
|
159
|
-
if (this.config.type === "library") {
|
|
160
|
-
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
|
|
161
|
-
if (this.config.publish === "npm") {
|
|
162
|
-
await SdProcess.spawnAsync("npm publish --
|
|
163
|
-
}
|
|
164
|
-
else {
|
|
165
|
-
throw new NeverEntryError();
|
|
166
|
-
}
|
|
167
|
-
}
|
|
168
|
-
else {
|
|
169
|
-
if (this.config.publish.type === "github") {
|
|
170
|
-
const repoUrl = typeof this._npmConfig.repository === "string" ? this._npmConfig.repository : this._npmConfig.repository.url;
|
|
171
|
-
const repoOwner = repoUrl.split("/").slice(-2)[0];
|
|
172
|
-
const repoName = repoUrl.split("/").slice(-2)[1].replace(/\..*/g, "");
|
|
173
|
-
|
|
174
|
-
const github = new SdCliGithubApi(
|
|
175
|
-
this.config.publish.apiKey,
|
|
176
|
-
repoOwner,
|
|
177
|
-
repoName
|
|
178
|
-
);
|
|
179
|
-
|
|
180
|
-
await github.uploadAsync(this._npmConfig.version, this.config.publish.files.map((item) => ({
|
|
181
|
-
buffer: FsUtil.readFileBuffer(path.resolve(this.rootPath, "dist", item.from)),
|
|
182
|
-
name: item.to
|
|
183
|
-
})));
|
|
184
|
-
}
|
|
185
|
-
else if (this.config.publish.type === "ftp" || this.config.publish.type === "ftps" || this.config.publish.type === "sftp") {
|
|
186
|
-
const tsconfigPath = path.resolve(this.rootPath, "tsconfig-build.json");
|
|
187
|
-
const tsconfig = FsUtil.readJson(tsconfigPath);
|
|
188
|
-
const parsedTsconfig = ts.parseJsonConfigFileContent(tsconfig, ts.sys, this.rootPath, tsconfig.angularCompilerOptions);
|
|
189
|
-
|
|
190
|
-
const ftp = await SdStorage.connectAsync(this.config.publish.type, {
|
|
191
|
-
host: this.config.publish.host,
|
|
192
|
-
port: this.config.publish.port,
|
|
193
|
-
user: this.config.publish.user,
|
|
194
|
-
pass: this.config.publish.pass
|
|
195
|
-
});
|
|
196
|
-
await ftp.uploadDirAsync(parsedTsconfig.options.outDir!, this.config.publish.path);
|
|
197
|
-
await ftp.closeAsync();
|
|
198
|
-
}
|
|
199
|
-
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
|
|
200
|
-
else if (this.config.publish.type === "local-directory") {
|
|
201
|
-
const tsconfigPath = path.resolve(this.rootPath, "tsconfig-build.json");
|
|
202
|
-
const tsconfig = FsUtil.readJson(tsconfigPath);
|
|
203
|
-
const parsedTsconfig = ts.parseJsonConfigFileContent(tsconfig, ts.sys, this.rootPath, tsconfig.angularCompilerOptions);
|
|
204
|
-
|
|
205
|
-
const targetRootPath = this.config.publish.path.replace(/%([^%]*)%/g, (item) => {
|
|
206
|
-
const envName = item.replace(/%/g, "");
|
|
207
|
-
if (!StringUtil.isNullOrEmpty(this._npmConfig.version) && envName === "SD_VERSION") {
|
|
208
|
-
return this._npmConfig.version;
|
|
209
|
-
}
|
|
210
|
-
return process.env[envName] ?? item;
|
|
211
|
-
});
|
|
212
|
-
|
|
213
|
-
const filePaths = await FsUtil.globAsync(path.resolve(this.rootPath, "**", "*"), {
|
|
214
|
-
dot: true,
|
|
215
|
-
nodir: true
|
|
216
|
-
});
|
|
217
|
-
|
|
218
|
-
await filePaths.parallelAsync(async (filePath) => {
|
|
219
|
-
const relativeFilePath = path.relative(parsedTsconfig.options.outDir!, filePath);
|
|
220
|
-
const targetPath = PathUtil.posix(targetRootPath, relativeFilePath);
|
|
221
|
-
await FsUtil.copyAsync(filePath, targetPath);
|
|
222
|
-
});
|
|
223
|
-
}
|
|
224
|
-
}
|
|
225
|
-
}
|
|
226
|
-
}
|
|
227
|
-
|
|
228
|
-
private async _genBuildTsconfigAsync(): Promise<void> {
|
|
229
|
-
const baseTsconfigFilePath = path.resolve(this.rootPath, "tsconfig.json");
|
|
230
|
-
const baseTsconfig: ITsconfig = await FsUtil.readJsonAsync(baseTsconfigFilePath);
|
|
231
|
-
|
|
232
|
-
const buildTsconfig: ITsconfig = ObjectUtil.clone(baseTsconfig);
|
|
233
|
-
buildTsconfig.compilerOptions = buildTsconfig.compilerOptions ?? {};
|
|
234
|
-
delete buildTsconfig.compilerOptions.baseUrl;
|
|
235
|
-
delete buildTsconfig.compilerOptions.paths;
|
|
236
|
-
|
|
237
|
-
buildTsconfig.compilerOptions.declaration = Boolean(this._npmConfig.types);
|
|
238
|
-
|
|
239
|
-
const buildTsconfigFilePath = path.resolve(this.rootPath, "tsconfig-build.json");
|
|
240
|
-
await FsUtil.writeJsonAsync(buildTsconfigFilePath, buildTsconfig, { space: 2 });
|
|
241
|
-
}
|
|
242
|
-
}
|
|
1
|
+
import { INpmConfig, ISdCliPackageBuildResult, ITsconfig, TSdCliPackageConfig } from "../commons";
|
|
2
|
+
import path from "path";
|
|
3
|
+
import { FsUtil, PathUtil, SdProcess } from "@simplysm/sd-core-node";
|
|
4
|
+
import { EventEmitter } from "events";
|
|
5
|
+
import { JsonConvert, NeverEntryError, ObjectUtil, StringUtil } from "@simplysm/sd-core-common";
|
|
6
|
+
import { SdCliNpmConfigUtil } from "../utils/SdCliNpmConfigUtil";
|
|
7
|
+
import { SdStorage } from "@simplysm/sd-storage";
|
|
8
|
+
import ts from "typescript";
|
|
9
|
+
import { SdCliGithubApi } from "../build-tool/SdCliGithubApi";
|
|
10
|
+
import cp from "child_process";
|
|
11
|
+
import { fileURLToPath } from "url";
|
|
12
|
+
|
|
13
|
+
export class SdCliPackage extends EventEmitter {
|
|
14
|
+
private readonly _npmConfig: INpmConfig;
|
|
15
|
+
|
|
16
|
+
public get basename(): string {
|
|
17
|
+
return path.basename(this._workspaceRootPath);
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
public get name(): string {
|
|
21
|
+
return this._npmConfig.name;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
public get main(): string | undefined {
|
|
25
|
+
return this._npmConfig.main;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
public get allDependencies(): string[] {
|
|
29
|
+
return [
|
|
30
|
+
...SdCliNpmConfigUtil.getDependencies(this._npmConfig).defaults,
|
|
31
|
+
...SdCliNpmConfigUtil.getDependencies(this._npmConfig).optionals
|
|
32
|
+
].distinct();
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
public constructor(private readonly _workspaceRootPath: string,
|
|
36
|
+
public readonly rootPath: string,
|
|
37
|
+
public readonly config: TSdCliPackageConfig) {
|
|
38
|
+
super();
|
|
39
|
+
|
|
40
|
+
const npmConfigFilePath = path.resolve(this.rootPath, "package.json");
|
|
41
|
+
this._npmConfig = FsUtil.readJson(npmConfigFilePath);
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
public override on(event: "change", listener: () => void): this;
|
|
45
|
+
public override on(event: "complete", listener: (results: ISdCliPackageBuildResult[]) => void): this;
|
|
46
|
+
public override on(event: string | symbol, listener: (...args: any[]) => void): this {
|
|
47
|
+
return super.on(event, listener);
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
public async setNewVersionAsync(newVersion: string, pkgNames: string[]): Promise<void> {
|
|
51
|
+
this._npmConfig.version = newVersion;
|
|
52
|
+
|
|
53
|
+
const updateDepVersion = (deps: Record<string, string> | undefined): void => {
|
|
54
|
+
if (!deps) return;
|
|
55
|
+
for (const depName of Object.keys(deps)) {
|
|
56
|
+
if (pkgNames.includes(depName)) {
|
|
57
|
+
deps[depName] = newVersion;
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
};
|
|
61
|
+
updateDepVersion(this._npmConfig.dependencies);
|
|
62
|
+
updateDepVersion(this._npmConfig.optionalDependencies);
|
|
63
|
+
updateDepVersion(this._npmConfig.devDependencies);
|
|
64
|
+
updateDepVersion(this._npmConfig.peerDependencies);
|
|
65
|
+
|
|
66
|
+
const npmConfigFilePath = path.resolve(this.rootPath, "package.json");
|
|
67
|
+
await FsUtil.writeJsonAsync(npmConfigFilePath, this._npmConfig, { space: 2 });
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
public async watchAsync(): Promise<void> {
|
|
71
|
+
const isTs = FsUtil.exists(path.resolve(this.rootPath, "tsconfig.json"));
|
|
72
|
+
|
|
73
|
+
if (isTs) {
|
|
74
|
+
await this._genBuildTsconfigAsync();
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
const workerPath = fileURLToPath(await import.meta.resolve!("../worker/build-worker"));
|
|
78
|
+
await new Promise<void>((resolve, reject) => {
|
|
79
|
+
const worker = cp.fork(workerPath, [
|
|
80
|
+
"watch",
|
|
81
|
+
this.rootPath,
|
|
82
|
+
JsonConvert.stringify(this.config),
|
|
83
|
+
this._workspaceRootPath
|
|
84
|
+
], {
|
|
85
|
+
stdio: ["pipe", "pipe", "pipe", "ipc"],
|
|
86
|
+
env: process.env
|
|
87
|
+
});
|
|
88
|
+
|
|
89
|
+
worker.on("error", (err) => {
|
|
90
|
+
reject(err);
|
|
91
|
+
});
|
|
92
|
+
|
|
93
|
+
worker.stdout!.pipe(process.stdout);
|
|
94
|
+
worker.stderr!.pipe(process.stderr);
|
|
95
|
+
|
|
96
|
+
worker.on("message", (json: string) => {
|
|
97
|
+
const msg = JsonConvert.parse(json);
|
|
98
|
+
if (msg.event === "ready") {
|
|
99
|
+
resolve();
|
|
100
|
+
}
|
|
101
|
+
else if (msg.event === "change") {
|
|
102
|
+
this.emit("change");
|
|
103
|
+
}
|
|
104
|
+
else if (msg.event === "complete") {
|
|
105
|
+
this.emit("complete", msg.body);
|
|
106
|
+
}
|
|
107
|
+
else {
|
|
108
|
+
throw new NeverEntryError();
|
|
109
|
+
}
|
|
110
|
+
});
|
|
111
|
+
});
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
public async buildAsync(): Promise<ISdCliPackageBuildResult[]> {
|
|
115
|
+
const isTs = FsUtil.exists(path.resolve(this.rootPath, "tsconfig.json"));
|
|
116
|
+
|
|
117
|
+
if (isTs) {
|
|
118
|
+
await this._genBuildTsconfigAsync();
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
const workerPath = fileURLToPath(await import.meta.resolve!("../worker/build-worker"));
|
|
122
|
+
return await new Promise<ISdCliPackageBuildResult[]>((resolve, reject) => {
|
|
123
|
+
const worker = cp.fork(workerPath, [
|
|
124
|
+
"build",
|
|
125
|
+
this.rootPath,
|
|
126
|
+
JsonConvert.stringify(this.config),
|
|
127
|
+
this._workspaceRootPath
|
|
128
|
+
], {
|
|
129
|
+
stdio: ["pipe", "pipe", "pipe", "ipc"],
|
|
130
|
+
env: process.env
|
|
131
|
+
});
|
|
132
|
+
|
|
133
|
+
worker.on("error", (err) => {
|
|
134
|
+
reject(err);
|
|
135
|
+
});
|
|
136
|
+
|
|
137
|
+
worker.stdout!.pipe(process.stdout);
|
|
138
|
+
worker.stderr!.pipe(process.stderr);
|
|
139
|
+
|
|
140
|
+
let result: ISdCliPackageBuildResult[] = [];
|
|
141
|
+
|
|
142
|
+
worker.on("message", (json: string) => {
|
|
143
|
+
result = JsonConvert.parse(json);
|
|
144
|
+
});
|
|
145
|
+
|
|
146
|
+
worker.on("exit", (code) => {
|
|
147
|
+
if (code !== 0) {
|
|
148
|
+
reject(new Error(`오류와 함께 닫힘 (${code})`));
|
|
149
|
+
return;
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
resolve(result);
|
|
153
|
+
});
|
|
154
|
+
});
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
public async publishAsync(): Promise<void> {
|
|
158
|
+
if (this.config.publish !== undefined) {
|
|
159
|
+
if (this.config.type === "library") {
|
|
160
|
+
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
|
|
161
|
+
if (this.config.publish === "npm") {
|
|
162
|
+
await SdProcess.spawnAsync("yarn npm publish --access public", { cwd: this.rootPath });
|
|
163
|
+
}
|
|
164
|
+
else {
|
|
165
|
+
throw new NeverEntryError();
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
else {
|
|
169
|
+
if (this.config.publish.type === "github") {
|
|
170
|
+
const repoUrl = typeof this._npmConfig.repository === "string" ? this._npmConfig.repository : this._npmConfig.repository.url;
|
|
171
|
+
const repoOwner = repoUrl.split("/").slice(-2)[0];
|
|
172
|
+
const repoName = repoUrl.split("/").slice(-2)[1].replace(/\..*/g, "");
|
|
173
|
+
|
|
174
|
+
const github = new SdCliGithubApi(
|
|
175
|
+
this.config.publish.apiKey,
|
|
176
|
+
repoOwner,
|
|
177
|
+
repoName
|
|
178
|
+
);
|
|
179
|
+
|
|
180
|
+
await github.uploadAsync(this._npmConfig.version, this.config.publish.files.map((item) => ({
|
|
181
|
+
buffer: FsUtil.readFileBuffer(path.resolve(this.rootPath, "dist", item.from)),
|
|
182
|
+
name: item.to
|
|
183
|
+
})));
|
|
184
|
+
}
|
|
185
|
+
else if (this.config.publish.type === "ftp" || this.config.publish.type === "ftps" || this.config.publish.type === "sftp") {
|
|
186
|
+
const tsconfigPath = path.resolve(this.rootPath, "tsconfig-build.json");
|
|
187
|
+
const tsconfig = FsUtil.readJson(tsconfigPath);
|
|
188
|
+
const parsedTsconfig = ts.parseJsonConfigFileContent(tsconfig, ts.sys, this.rootPath, tsconfig.angularCompilerOptions);
|
|
189
|
+
|
|
190
|
+
const ftp = await SdStorage.connectAsync(this.config.publish.type, {
|
|
191
|
+
host: this.config.publish.host,
|
|
192
|
+
port: this.config.publish.port,
|
|
193
|
+
user: this.config.publish.user,
|
|
194
|
+
pass: this.config.publish.pass
|
|
195
|
+
});
|
|
196
|
+
await ftp.uploadDirAsync(parsedTsconfig.options.outDir!, this.config.publish.path);
|
|
197
|
+
await ftp.closeAsync();
|
|
198
|
+
}
|
|
199
|
+
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
|
|
200
|
+
else if (this.config.publish.type === "local-directory") {
|
|
201
|
+
const tsconfigPath = path.resolve(this.rootPath, "tsconfig-build.json");
|
|
202
|
+
const tsconfig = FsUtil.readJson(tsconfigPath);
|
|
203
|
+
const parsedTsconfig = ts.parseJsonConfigFileContent(tsconfig, ts.sys, this.rootPath, tsconfig.angularCompilerOptions);
|
|
204
|
+
|
|
205
|
+
const targetRootPath = this.config.publish.path.replace(/%([^%]*)%/g, (item) => {
|
|
206
|
+
const envName = item.replace(/%/g, "");
|
|
207
|
+
if (!StringUtil.isNullOrEmpty(this._npmConfig.version) && envName === "SD_VERSION") {
|
|
208
|
+
return this._npmConfig.version;
|
|
209
|
+
}
|
|
210
|
+
return process.env[envName] ?? item;
|
|
211
|
+
});
|
|
212
|
+
|
|
213
|
+
const filePaths = await FsUtil.globAsync(path.resolve(this.rootPath, "**", "*"), {
|
|
214
|
+
dot: true,
|
|
215
|
+
nodir: true
|
|
216
|
+
});
|
|
217
|
+
|
|
218
|
+
await filePaths.parallelAsync(async (filePath) => {
|
|
219
|
+
const relativeFilePath = path.relative(parsedTsconfig.options.outDir!, filePath);
|
|
220
|
+
const targetPath = PathUtil.posix(targetRootPath, relativeFilePath);
|
|
221
|
+
await FsUtil.copyAsync(filePath, targetPath);
|
|
222
|
+
});
|
|
223
|
+
}
|
|
224
|
+
}
|
|
225
|
+
}
|
|
226
|
+
}
|
|
227
|
+
|
|
228
|
+
private async _genBuildTsconfigAsync(): Promise<void> {
|
|
229
|
+
const baseTsconfigFilePath = path.resolve(this.rootPath, "tsconfig.json");
|
|
230
|
+
const baseTsconfig: ITsconfig = await FsUtil.readJsonAsync(baseTsconfigFilePath);
|
|
231
|
+
|
|
232
|
+
const buildTsconfig: ITsconfig = ObjectUtil.clone(baseTsconfig);
|
|
233
|
+
buildTsconfig.compilerOptions = buildTsconfig.compilerOptions ?? {};
|
|
234
|
+
delete buildTsconfig.compilerOptions.baseUrl;
|
|
235
|
+
delete buildTsconfig.compilerOptions.paths;
|
|
236
|
+
|
|
237
|
+
buildTsconfig.compilerOptions.declaration = Boolean(this._npmConfig.types);
|
|
238
|
+
|
|
239
|
+
const buildTsconfigFilePath = path.resolve(this.rootPath, "tsconfig-build.json");
|
|
240
|
+
await FsUtil.writeJsonAsync(buildTsconfigFilePath, buildTsconfig, { space: 2 });
|
|
241
|
+
}
|
|
242
|
+
}
|