@simplysm/sd-cli 7.0.249 → 7.0.267
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/README.md +95 -0
- package/assets/client-files/assets/icons/icon-128x128.png +0 -0
- package/assets/client-files/assets/icons/icon-144x144.png +0 -0
- package/assets/client-files/assets/icons/icon-152x152.png +0 -0
- package/assets/client-files/assets/icons/icon-192x192.png +0 -0
- package/assets/client-files/assets/icons/icon-384x384.png +0 -0
- package/assets/client-files/assets/icons/icon-512x512.png +0 -0
- package/assets/client-files/assets/icons/icon-72x72.png +0 -0
- package/assets/client-files/assets/icons/icon-96x96.png +0 -0
- package/assets/client-files/favicon.ico +0 -0
- package/dist/bin/sd-cli.mjs +212 -15
- package/dist/build-tool/SdCliCordova.mjs +3 -3
- package/dist/build-tool/SdCliElectron.mjs +3 -2
- package/dist/build-tool/SdCliIndexFileGenerator.mjs +2 -3
- package/dist/builder/SdCliClientBuilder.d.ts +2 -0
- package/dist/builder/SdCliClientBuilder.mjs +57 -20
- package/dist/builder/SdCliServerBuilder.d.ts +2 -0
- package/dist/builder/SdCliServerBuilder.mjs +27 -13
- package/dist/builder/SdCliTsLibBuilder.mjs +18 -12
- package/dist/commons.d.ts +6 -1
- package/dist/entry-points/SdCliPrepare.mjs +34 -34
- package/dist/entry-points/SdCliProjectGenerator.d.ts +44 -0
- package/dist/entry-points/SdCliProjectGenerator.mjs +320 -0
- package/dist/entry-points/SdCliWorkspace.d.ts +6 -6
- package/dist/entry-points/SdCliWorkspace.mjs +61 -107
- package/dist/entry-points/file/base/fc_package_eslintrc.d.ts +3 -0
- package/dist/entry-points/file/base/fc_package_eslintrc.mjs +31 -0
- package/dist/entry-points/file/base/fc_package_npmconfig.d.ts +9 -0
- package/dist/entry-points/file/base/fc_package_npmconfig.mjs +32 -0
- package/dist/entry-points/file/base/fc_package_tsconfig.d.ts +5 -0
- package/dist/entry-points/file/base/fc_package_tsconfig.mjs +13 -0
- package/dist/entry-points/file/client/fc_package_AppModule.d.ts +1 -0
- package/dist/entry-points/file/client/fc_package_AppModule.mjs +37 -0
- package/dist/entry-points/file/client/fc_package_AppPage.d.ts +1 -0
- package/dist/entry-points/file/client/fc_package_AppPage.mjs +14 -0
- package/dist/entry-points/file/client/fc_package_Page.d.ts +4 -0
- package/dist/entry-points/file/client/fc_package_Page.mjs +19 -0
- package/dist/entry-points/file/client/fc_package_client_main.d.ts +1 -0
- package/dist/entry-points/file/client/fc_package_client_main.mjs +19 -0
- package/dist/entry-points/file/client/fc_package_index.d.ts +3 -0
- package/dist/entry-points/file/client/fc_package_index.mjs +88 -0
- package/dist/entry-points/file/client/fc_package_manifest.d.ts +5 -0
- package/dist/entry-points/file/client/fc_package_manifest.mjs +54 -0
- package/dist/entry-points/file/client/fc_package_polyfills.d.ts +1 -0
- package/dist/entry-points/file/client/fc_package_polyfills.mjs +11 -0
- package/dist/entry-points/file/client/fc_package_styles.d.ts +1 -0
- package/dist/entry-points/file/client/fc_package_styles.mjs +7 -0
- package/dist/entry-points/file/db/fc_package_DbContext.d.ts +3 -0
- package/dist/entry-points/file/db/fc_package_DbContext.mjs +14 -0
- package/dist/entry-points/file/db/fc_package_DbModel.d.ts +4 -0
- package/dist/entry-points/file/db/fc_package_DbModel.mjs +12 -0
- package/dist/entry-points/file/project/fc_project_editor_config.d.ts +1 -0
- package/dist/entry-points/file/project/fc_project_editor_config.mjs +22 -0
- package/dist/entry-points/file/project/fc_project_eslintrc.d.ts +1 -0
- package/dist/entry-points/file/project/fc_project_eslintrc.mjs +30 -0
- package/dist/entry-points/file/project/fc_project_gitattributes.d.ts +1 -0
- package/dist/entry-points/file/project/fc_project_gitattributes.mjs +6 -0
- package/dist/entry-points/file/project/fc_project_gitignore.d.ts +1 -0
- package/dist/entry-points/file/project/fc_project_gitignore.mjs +17 -0
- package/dist/entry-points/file/project/fc_project_npmconfig.d.ts +7 -0
- package/dist/entry-points/file/project/fc_project_npmconfig.mjs +35 -0
- package/dist/entry-points/file/project/fc_project_readme.d.ts +3 -0
- package/dist/entry-points/file/project/fc_project_readme.mjs +13 -0
- package/dist/entry-points/file/project/fc_project_simplysm.d.ts +1 -0
- package/dist/entry-points/file/project/fc_project_simplysm.mjs +2 -0
- package/dist/entry-points/file/project/fc_project_tsconfig.d.ts +1 -0
- package/dist/entry-points/file/project/fc_project_tsconfig.mjs +25 -0
- package/dist/entry-points/file/server/fc_package_server_main.d.ts +4 -0
- package/dist/entry-points/file/server/fc_package_server_main.mjs +60 -0
- package/dist/index.d.ts +23 -0
- package/dist/index.mjs +24 -1
- package/dist/ng-tools/SdCliNgModuleGenerator.mjs +35 -36
- package/dist/packages/SdCliPackage.d.ts +1 -0
- package/dist/packages/SdCliPackage.mjs +69 -63
- package/dist/utils/SdCliBuildResultUtil.mjs +2 -2
- package/docs/client-add-page.md +8 -0
- package/docs/client-router.md +85 -0
- package/docs/client-sw.md +101 -0
- package/docs/conf-orm.md +81 -0
- package/docs/conf-usage.md +5 -0
- package/docs/lib-local-update.md +50 -0
- package/docs/lib-ts-paths.md +25 -0
- package/package.json +10 -8
- package/src/SdCliBuildResultError.ts +9 -9
- package/src/bin/sd-cli.ts +244 -15
- package/src/build-tool/SdCliCacheCompilerHost.ts +77 -77
- package/src/build-tool/SdCliCordova.ts +2 -2
- package/src/build-tool/SdCliElectron.ts +2 -1
- package/src/build-tool/SdCliGithubApi.ts +110 -110
- package/src/build-tool/SdCliIndexFileGenerator.ts +79 -80
- package/src/build-tool/SdCliNgCacheCompilerHost.ts +58 -58
- package/src/build-tool/SdCliPackageLinter.ts +74 -74
- package/src/builder/SdCliClientBuilder.ts +73 -22
- package/src/builder/SdCliJsLibBuilder.ts +70 -70
- package/src/builder/SdCliServerBuilder.ts +34 -14
- package/src/builder/SdCliTsLibBuilder.ts +450 -445
- package/src/commons.ts +6 -1
- package/src/entry-points/SdCliFileCrypto.ts +87 -87
- package/src/entry-points/SdCliPrepare.ts +55 -55
- package/src/entry-points/SdCliProjectGenerator.ts +395 -0
- package/src/entry-points/SdCliWorkspace.ts +74 -122
- package/src/entry-points/file/base/fc_package_eslintrc.ts +30 -0
- package/src/entry-points/file/base/fc_package_npmconfig.ts +43 -0
- package/src/entry-points/file/base/fc_package_tsconfig.ts +12 -0
- package/src/entry-points/file/client/fc_package_AppModule.ts +36 -0
- package/src/entry-points/file/client/fc_package_AppPage.ts +13 -0
- package/src/entry-points/file/client/fc_package_Page.ts +19 -0
- package/src/entry-points/file/client/fc_package_client_main.ts +18 -0
- package/src/entry-points/file/client/fc_package_index.ts +87 -0
- package/src/entry-points/file/client/fc_package_manifest.ts +53 -0
- package/src/entry-points/file/client/fc_package_polyfills.ts +10 -0
- package/src/entry-points/file/client/fc_package_styles.ts +6 -0
- package/src/entry-points/file/db/fc_package_DbContext.ts +14 -0
- package/src/entry-points/file/db/fc_package_DbModel.ts +11 -0
- package/src/entry-points/file/project/fc_project_editor_config.ts +21 -0
- package/src/entry-points/file/project/fc_project_eslintrc.ts +29 -0
- package/src/entry-points/file/project/fc_project_gitattributes.ts +5 -0
- package/src/entry-points/file/project/fc_project_gitignore.ts +16 -0
- package/src/entry-points/file/project/fc_project_npmconfig.ts +34 -0
- package/src/entry-points/file/project/fc_project_readme.ts +12 -0
- package/src/entry-points/file/project/fc_project_simplysm.ts +1 -0
- package/src/entry-points/file/project/fc_project_tsconfig.ts +24 -0
- package/src/entry-points/file/server/fc_package_server_main.ts +62 -0
- package/src/index.ts +55 -32
- package/src/ng-tools/SdCliNgModuleGenerator.ts +639 -640
- package/src/ng-tools/babel/SdCliBbFileMetadata.ts +568 -568
- package/src/ng-tools/babel/SdCliBbRootMetadata.ts +239 -239
- package/src/ng-tools/babel/SdCliBbUtil.ts +15 -15
- package/src/ng-tools/babel/TSdCliBbNgMetadata.ts +234 -234
- package/src/ng-tools/babel/TSdCliBbTypeMetadata.ts +177 -177
- package/src/ng-tools/commons.ts +3 -3
- package/src/ng-tools/typescript/SdCliTsFileMetadata.ts +384 -384
- package/src/ng-tools/typescript/SdCliTsRootMetadata.ts +32 -32
- package/src/ng-tools/typescript/SdCliTsUtil.ts +29 -29
- package/src/packages/SdCliPackage.ts +76 -59
- package/src/utils/SdCliBuildResultUtil.ts +76 -76
- package/src/utils/SdCliConfigUtil.ts +94 -94
- package/src/utils/SdCliNpmConfigUtil.ts +16 -16
|
@@ -1,77 +1,77 @@
|
|
|
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
|
-
if (parsedTsconfig.options.module === ts.ModuleKind.CommonJS) {
|
|
35
|
-
fileName = fileName.replace(/\.js(\.map)?$/, ".cjs$1");
|
|
36
|
-
}
|
|
37
|
-
else {
|
|
38
|
-
fileName = fileName.replace(/\.js(\.map)?$/, ".mjs$1");
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
const writeCache = outputFileCache.get(PathUtil.posix(fileName));
|
|
43
|
-
if (writeCache !== data) {
|
|
44
|
-
outputFileCache.set(PathUtil.posix(fileName), data);
|
|
45
|
-
compilerHost.writeFile.call(cacheCompilerHost, fileName, data, writeByteOrderMark, onError, sourceFiles);
|
|
46
|
-
}
|
|
47
|
-
};
|
|
48
|
-
|
|
49
|
-
cacheCompilerHost.readFile = (fileName: string) => {
|
|
50
|
-
const cache = sourceFileCache.getOrCreate(PathUtil.posix(fileName), {});
|
|
51
|
-
if (cache.content === undefined) {
|
|
52
|
-
cache.content = compilerHost.readFile.call(cacheCompilerHost, fileName);
|
|
53
|
-
}
|
|
54
|
-
return cache.content;
|
|
55
|
-
};
|
|
56
|
-
|
|
57
|
-
cacheCompilerHost.resolveModuleNames = (moduleNames: string[], containingFile: string) => {
|
|
58
|
-
return moduleNames.map((moduleName) => {
|
|
59
|
-
return ts.resolveModuleName(
|
|
60
|
-
moduleName,
|
|
61
|
-
PathUtil.posix(containingFile),
|
|
62
|
-
parsedTsconfig.options,
|
|
63
|
-
compilerHost,
|
|
64
|
-
moduleResolutionCache
|
|
65
|
-
).resolvedModule;
|
|
66
|
-
});
|
|
67
|
-
};
|
|
68
|
-
|
|
69
|
-
return cacheCompilerHost;
|
|
70
|
-
}
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
interface IFileCache {
|
|
74
|
-
exists?: boolean;
|
|
75
|
-
sourceFile?: ts.SourceFile;
|
|
76
|
-
content?: string;
|
|
77
|
-
}
|
|
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
|
+
if (parsedTsconfig.options.module === ts.ModuleKind.CommonJS) {
|
|
35
|
+
fileName = fileName.replace(/\.js(\.map)?$/, ".cjs$1");
|
|
36
|
+
}
|
|
37
|
+
else {
|
|
38
|
+
fileName = fileName.replace(/\.js(\.map)?$/, ".mjs$1");
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
|
|
42
|
+
const writeCache = outputFileCache.get(PathUtil.posix(fileName));
|
|
43
|
+
if (writeCache !== data) {
|
|
44
|
+
outputFileCache.set(PathUtil.posix(fileName), data);
|
|
45
|
+
compilerHost.writeFile.call(cacheCompilerHost, fileName, data, writeByteOrderMark, onError, sourceFiles);
|
|
46
|
+
}
|
|
47
|
+
};
|
|
48
|
+
|
|
49
|
+
cacheCompilerHost.readFile = (fileName: string) => {
|
|
50
|
+
const cache = sourceFileCache.getOrCreate(PathUtil.posix(fileName), {});
|
|
51
|
+
if (cache.content === undefined) {
|
|
52
|
+
cache.content = compilerHost.readFile.call(cacheCompilerHost, fileName);
|
|
53
|
+
}
|
|
54
|
+
return cache.content;
|
|
55
|
+
};
|
|
56
|
+
|
|
57
|
+
cacheCompilerHost.resolveModuleNames = (moduleNames: string[], containingFile: string) => {
|
|
58
|
+
return moduleNames.map((moduleName) => {
|
|
59
|
+
return ts.resolveModuleName(
|
|
60
|
+
moduleName,
|
|
61
|
+
PathUtil.posix(containingFile),
|
|
62
|
+
parsedTsconfig.options,
|
|
63
|
+
compilerHost,
|
|
64
|
+
moduleResolutionCache
|
|
65
|
+
).resolvedModule;
|
|
66
|
+
});
|
|
67
|
+
};
|
|
68
|
+
|
|
69
|
+
return cacheCompilerHost;
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
interface IFileCache {
|
|
74
|
+
exists?: boolean;
|
|
75
|
+
sourceFile?: ts.SourceFile;
|
|
76
|
+
content?: string;
|
|
77
|
+
}
|
|
@@ -8,7 +8,7 @@ export class SdCliCordova {
|
|
|
8
8
|
|
|
9
9
|
private readonly _npmConfig: INpmConfig;
|
|
10
10
|
|
|
11
|
-
public readonly cordovaPath = path.resolve(this._rootPath, ".cordova");
|
|
11
|
+
public readonly cordovaPath = path.resolve(this._rootPath, ".cache", "cordova");
|
|
12
12
|
private readonly _binPath = path.resolve(process.cwd(), "node_modules/.bin/cordova.cmd");
|
|
13
13
|
|
|
14
14
|
public get platforms(): ("browser" | "android")[] {
|
|
@@ -34,7 +34,7 @@ export class SdCliCordova {
|
|
|
34
34
|
this._logger.log("이미 생성되어있는 '.cordova'를 사용합니다.");
|
|
35
35
|
}
|
|
36
36
|
else {
|
|
37
|
-
await this._execAsync(`${this._binPath} telemetry on`, this.
|
|
37
|
+
await this._execAsync(`${this._binPath} telemetry on`, this.cordovaPath);
|
|
38
38
|
|
|
39
39
|
// 프로젝트 생성
|
|
40
40
|
await this._execAsync(`${this._binPath} create "${this.cordovaPath}" "${this._config.appId}" "${this._config.appName}"`, process.cwd());
|
|
@@ -68,7 +68,8 @@ export class SdCliElectron {
|
|
|
68
68
|
`SD_VERSION=${npmConfig.version}`,
|
|
69
69
|
`SD_ELECTRON_DEV_URL=${url.replace(/\/$/, "")}/${pkgName}/electron/`,
|
|
70
70
|
(electronConfig.icon !== undefined) ? `SD_ELECTRON_ICON=${electronConfig.icon}` : `SD_ELECTRON_ICON=favicon.ico`,
|
|
71
|
-
...(pkgConfig.env !== undefined) ? Object.keys(pkgConfig.env).map((key) => `${key}=${pkgConfig.env![key]}`) : []
|
|
71
|
+
...(pkgConfig.env !== undefined) ? Object.keys(pkgConfig.env).map((key) => `${key}=${pkgConfig.env![key]}`) : [],
|
|
72
|
+
...(electronConfig.env !== undefined) ? Object.keys(electronConfig.env).map((key) => `${key}=${electronConfig.env![key]}`) : [],
|
|
72
73
|
].filterExists().join("\n"));
|
|
73
74
|
|
|
74
75
|
let electronTsFileContent = await FsUtil.readFileAsync(path.resolve(pkgRootPath, `src/electron.ts`));
|
|
@@ -1,111 +1,111 @@
|
|
|
1
|
-
import https from "https";
|
|
2
|
-
import { SdProcess } from "@simplysm/sd-core-node";
|
|
3
|
-
import mime from "mime";
|
|
4
|
-
|
|
5
|
-
export class SdCliGithubApi {
|
|
6
|
-
public constructor(private readonly _apiKey: string,
|
|
7
|
-
private readonly _repoOwner: string,
|
|
8
|
-
private readonly _repoName: string) {
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
public async uploadAsync(version: string, files: { name: string; buffer: Buffer }[]): Promise<void> {
|
|
12
|
-
const releaseId = await this._createReleaseTagAsync(version);
|
|
13
|
-
|
|
14
|
-
for (const file of files) {
|
|
15
|
-
await this._uploadFileAsync(releaseId, file.name, file.buffer);
|
|
16
|
-
}
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
private async _uploadFileAsync(releaseId: number, fileName: string, buffer: Buffer): Promise<void> {
|
|
20
|
-
const contentLength = buffer.length;
|
|
21
|
-
|
|
22
|
-
await new Promise<void>((resolve, reject) => {
|
|
23
|
-
const req = https.request(
|
|
24
|
-
`https://uploads.github.com/repos/${this._repoOwner}/${this._repoName}/releases/${releaseId}/assets?name=${fileName}&label=${fileName}`,
|
|
25
|
-
{
|
|
26
|
-
method: "POST",
|
|
27
|
-
headers: {
|
|
28
|
-
"Authorization": `token ${this._apiKey}`,
|
|
29
|
-
"Accept": "application/vnd.github.v3+json",
|
|
30
|
-
"User-Agent": "@simplysm/sd-cli:publish",
|
|
31
|
-
"Content-Length": contentLength,
|
|
32
|
-
"Content-Type": mime.getType(fileName)!
|
|
33
|
-
}
|
|
34
|
-
},
|
|
35
|
-
(res) => {
|
|
36
|
-
let dataBuffer = Buffer.from([]);
|
|
37
|
-
res.on("data", data => {
|
|
38
|
-
dataBuffer = Buffer.concat([dataBuffer, data]);
|
|
39
|
-
});
|
|
40
|
-
|
|
41
|
-
res.on("end", () => {
|
|
42
|
-
if (res.statusCode !== 201) {
|
|
43
|
-
const errObj = JSON.parse(dataBuffer.toString());
|
|
44
|
-
throw new Error(errObj.message + "(" + errObj.documentation_url + ")");
|
|
45
|
-
}
|
|
46
|
-
else {
|
|
47
|
-
resolve();
|
|
48
|
-
}
|
|
49
|
-
});
|
|
50
|
-
}
|
|
51
|
-
);
|
|
52
|
-
|
|
53
|
-
req.on("error", (error) => {
|
|
54
|
-
reject(error);
|
|
55
|
-
});
|
|
56
|
-
req.write(buffer);
|
|
57
|
-
req.end();
|
|
58
|
-
});
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
private async _createReleaseTagAsync(ver: string): Promise<number> {
|
|
62
|
-
const currentBranch = (await SdProcess.spawnAsync("git branch --show-current")).trim();
|
|
63
|
-
|
|
64
|
-
return await new Promise<number>((resolve, reject) => {
|
|
65
|
-
const req = https.request(
|
|
66
|
-
`https://api.github.com/repos/${this._repoOwner}/${this._repoName}/releases`,
|
|
67
|
-
{
|
|
68
|
-
method: "POST",
|
|
69
|
-
headers: {
|
|
70
|
-
"Authorization": `token ${this._apiKey}`,
|
|
71
|
-
"Accept": "application/vnd.github.v3+json",
|
|
72
|
-
"User-Agent": "@simplysm/sd-cli:publish"
|
|
73
|
-
}
|
|
74
|
-
},
|
|
75
|
-
(res) => {
|
|
76
|
-
let dataBuffer = Buffer.from([]);
|
|
77
|
-
res.on("data", data => {
|
|
78
|
-
dataBuffer = Buffer.concat([dataBuffer, data]);
|
|
79
|
-
});
|
|
80
|
-
|
|
81
|
-
res.on("end", () => {
|
|
82
|
-
if (res.statusCode !== 201) {
|
|
83
|
-
const errObj = JSON.parse(dataBuffer.toString());
|
|
84
|
-
throw new Error(errObj.message + "(" + errObj.documentation_url + ")");
|
|
85
|
-
}
|
|
86
|
-
else {
|
|
87
|
-
// console.log(JSON.parse(dataBuffer.toString()));
|
|
88
|
-
const resData = JSON.parse(dataBuffer.toString());
|
|
89
|
-
resolve(resData.id);
|
|
90
|
-
}
|
|
91
|
-
});
|
|
92
|
-
}
|
|
93
|
-
);
|
|
94
|
-
|
|
95
|
-
req.on("error", (error) => {
|
|
96
|
-
reject(error);
|
|
97
|
-
});
|
|
98
|
-
|
|
99
|
-
req.write(JSON.stringify({
|
|
100
|
-
tag_name: `v${ver}`,
|
|
101
|
-
target_commitish: currentBranch,
|
|
102
|
-
name: `v${ver}`,
|
|
103
|
-
body: `v${ver}`,
|
|
104
|
-
draft: false,
|
|
105
|
-
prerelease: false
|
|
106
|
-
}));
|
|
107
|
-
|
|
108
|
-
req.end();
|
|
109
|
-
});
|
|
110
|
-
}
|
|
1
|
+
import https from "https";
|
|
2
|
+
import { SdProcess } from "@simplysm/sd-core-node";
|
|
3
|
+
import mime from "mime";
|
|
4
|
+
|
|
5
|
+
export class SdCliGithubApi {
|
|
6
|
+
public constructor(private readonly _apiKey: string,
|
|
7
|
+
private readonly _repoOwner: string,
|
|
8
|
+
private readonly _repoName: string) {
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
public async uploadAsync(version: string, files: { name: string; buffer: Buffer }[]): Promise<void> {
|
|
12
|
+
const releaseId = await this._createReleaseTagAsync(version);
|
|
13
|
+
|
|
14
|
+
for (const file of files) {
|
|
15
|
+
await this._uploadFileAsync(releaseId, file.name, file.buffer);
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
private async _uploadFileAsync(releaseId: number, fileName: string, buffer: Buffer): Promise<void> {
|
|
20
|
+
const contentLength = buffer.length;
|
|
21
|
+
|
|
22
|
+
await new Promise<void>((resolve, reject) => {
|
|
23
|
+
const req = https.request(
|
|
24
|
+
`https://uploads.github.com/repos/${this._repoOwner}/${this._repoName}/releases/${releaseId}/assets?name=${fileName}&label=${fileName}`,
|
|
25
|
+
{
|
|
26
|
+
method: "POST",
|
|
27
|
+
headers: {
|
|
28
|
+
"Authorization": `token ${this._apiKey}`,
|
|
29
|
+
"Accept": "application/vnd.github.v3+json",
|
|
30
|
+
"User-Agent": "@simplysm/sd-cli:publish",
|
|
31
|
+
"Content-Length": contentLength,
|
|
32
|
+
"Content-Type": mime.getType(fileName)!
|
|
33
|
+
}
|
|
34
|
+
},
|
|
35
|
+
(res) => {
|
|
36
|
+
let dataBuffer = Buffer.from([]);
|
|
37
|
+
res.on("data", data => {
|
|
38
|
+
dataBuffer = Buffer.concat([dataBuffer, data]);
|
|
39
|
+
});
|
|
40
|
+
|
|
41
|
+
res.on("end", () => {
|
|
42
|
+
if (res.statusCode !== 201) {
|
|
43
|
+
const errObj = JSON.parse(dataBuffer.toString());
|
|
44
|
+
throw new Error(errObj.message + "(" + errObj.documentation_url + ")");
|
|
45
|
+
}
|
|
46
|
+
else {
|
|
47
|
+
resolve();
|
|
48
|
+
}
|
|
49
|
+
});
|
|
50
|
+
}
|
|
51
|
+
);
|
|
52
|
+
|
|
53
|
+
req.on("error", (error) => {
|
|
54
|
+
reject(error);
|
|
55
|
+
});
|
|
56
|
+
req.write(buffer);
|
|
57
|
+
req.end();
|
|
58
|
+
});
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
private async _createReleaseTagAsync(ver: string): Promise<number> {
|
|
62
|
+
const currentBranch = (await SdProcess.spawnAsync("git branch --show-current")).trim();
|
|
63
|
+
|
|
64
|
+
return await new Promise<number>((resolve, reject) => {
|
|
65
|
+
const req = https.request(
|
|
66
|
+
`https://api.github.com/repos/${this._repoOwner}/${this._repoName}/releases`,
|
|
67
|
+
{
|
|
68
|
+
method: "POST",
|
|
69
|
+
headers: {
|
|
70
|
+
"Authorization": `token ${this._apiKey}`,
|
|
71
|
+
"Accept": "application/vnd.github.v3+json",
|
|
72
|
+
"User-Agent": "@simplysm/sd-cli:publish"
|
|
73
|
+
}
|
|
74
|
+
},
|
|
75
|
+
(res) => {
|
|
76
|
+
let dataBuffer = Buffer.from([]);
|
|
77
|
+
res.on("data", data => {
|
|
78
|
+
dataBuffer = Buffer.concat([dataBuffer, data]);
|
|
79
|
+
});
|
|
80
|
+
|
|
81
|
+
res.on("end", () => {
|
|
82
|
+
if (res.statusCode !== 201) {
|
|
83
|
+
const errObj = JSON.parse(dataBuffer.toString());
|
|
84
|
+
throw new Error(errObj.message + "(" + errObj.documentation_url + ")");
|
|
85
|
+
}
|
|
86
|
+
else {
|
|
87
|
+
// console.log(JSON.parse(dataBuffer.toString()));
|
|
88
|
+
const resData = JSON.parse(dataBuffer.toString());
|
|
89
|
+
resolve(resData.id);
|
|
90
|
+
}
|
|
91
|
+
});
|
|
92
|
+
}
|
|
93
|
+
);
|
|
94
|
+
|
|
95
|
+
req.on("error", (error) => {
|
|
96
|
+
reject(error);
|
|
97
|
+
});
|
|
98
|
+
|
|
99
|
+
req.write(JSON.stringify({
|
|
100
|
+
tag_name: `v${ver}`,
|
|
101
|
+
target_commitish: currentBranch,
|
|
102
|
+
name: `v${ver}`,
|
|
103
|
+
body: `v${ver}`,
|
|
104
|
+
draft: false,
|
|
105
|
+
prerelease: false
|
|
106
|
+
}));
|
|
107
|
+
|
|
108
|
+
req.end();
|
|
109
|
+
});
|
|
110
|
+
}
|
|
111
111
|
}
|
|
@@ -1,80 +1,79 @@
|
|
|
1
|
-
import { ITsconfig } from "../commons";
|
|
2
|
-
import path from "path";
|
|
3
|
-
import { FsUtil, PathUtil } from "@simplysm/sd-core-node";
|
|
4
|
-
import
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
private
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
const
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
.replace(
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
const
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
const
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
}
|
|
1
|
+
import { ITsconfig } from "../commons";
|
|
2
|
+
import path from "path";
|
|
3
|
+
import { FsUtil, PathUtil } from "@simplysm/sd-core-node";
|
|
4
|
+
import chokidar from "chokidar";
|
|
5
|
+
|
|
6
|
+
export class SdCliIndexFileGenerator {
|
|
7
|
+
private readonly _indexFilePath = path.resolve(this.rootPath, "src/index.ts");
|
|
8
|
+
private _contentCache: string | undefined;
|
|
9
|
+
|
|
10
|
+
public constructor(public readonly rootPath: string,
|
|
11
|
+
public readonly config: ISdAutoIndexConfig) {
|
|
12
|
+
this._contentCache = FsUtil.exists(this._indexFilePath) ? FsUtil.readFile(this._indexFilePath) : undefined;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
public async watchAsync(): Promise<void> {
|
|
16
|
+
const watcher = chokidar.watch([path.resolve(this.rootPath, "src")], { persistent: true });
|
|
17
|
+
watcher.on("add", async (filePath) => {
|
|
18
|
+
if (filePath.endsWith(".ts")) {
|
|
19
|
+
await this.runAsync();
|
|
20
|
+
}
|
|
21
|
+
});
|
|
22
|
+
watcher.on("unlink", async (filePath) => {
|
|
23
|
+
if (filePath.endsWith(".ts")) {
|
|
24
|
+
await this.runAsync();
|
|
25
|
+
}
|
|
26
|
+
});
|
|
27
|
+
|
|
28
|
+
await this.runAsync();
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
public async runAsync(): Promise<void> {
|
|
32
|
+
const importTexts: string[] = [];
|
|
33
|
+
|
|
34
|
+
// 옵션의 polyfills 를 모두 import
|
|
35
|
+
if (this.config.polyfills) {
|
|
36
|
+
for (const polyfill of this.config.polyfills) {
|
|
37
|
+
importTexts.push(`import "${polyfill}";`);
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
// 내부 파일들 import
|
|
42
|
+
const filePaths = await this._getFilePathsAsync();
|
|
43
|
+
for (const filePath of filePaths) {
|
|
44
|
+
const requirePath = PathUtil.posix(path.relative(path.dirname(this._indexFilePath), filePath))
|
|
45
|
+
.replace(/\.ts$/, "")
|
|
46
|
+
.replace(/\/index$/, "");
|
|
47
|
+
|
|
48
|
+
const sourceTsFileContent = await FsUtil.readFileAsync(filePath);
|
|
49
|
+
if (sourceTsFileContent.split("\n").some((line) => line.startsWith("export "))) {
|
|
50
|
+
importTexts.push(`export * from "./${requirePath}";`);
|
|
51
|
+
}
|
|
52
|
+
else {
|
|
53
|
+
importTexts.push(`import "./${requirePath}";`);
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
const content = importTexts.join("\n") + "\n";
|
|
58
|
+
const prevContent = this._contentCache;
|
|
59
|
+
this._contentCache = content;
|
|
60
|
+
if (content.trim() !== prevContent?.trim()) {
|
|
61
|
+
await FsUtil.writeFileAsync(this._indexFilePath, content);
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
private async _getFilePathsAsync(): Promise<string[]> {
|
|
66
|
+
const tsconfig: ITsconfig = await FsUtil.readJsonAsync(path.resolve(this.rootPath, "tsconfig.json"));
|
|
67
|
+
const entryFilePaths = tsconfig.files?.map((item) => path.resolve(this.rootPath, item)) ?? [];
|
|
68
|
+
|
|
69
|
+
return (await FsUtil.globAsync(path.resolve(this.rootPath, "src/**/*.ts"), { nodir: true }))
|
|
70
|
+
.filter((item) => (
|
|
71
|
+
!entryFilePaths.includes(item)
|
|
72
|
+
&& item !== this._indexFilePath
|
|
73
|
+
));
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
export interface ISdAutoIndexConfig {
|
|
78
|
+
polyfills?: string[];
|
|
79
|
+
}
|