@simplysm/sd-cli 7.0.263 → 7.0.266

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 (78) hide show
  1. package/README.md +69 -22
  2. package/{src/entry-points/file/assets → assets/client-files}/assets/icons/icon-128x128.png +0 -0
  3. package/{src/entry-points/file/assets → assets/client-files}/assets/icons/icon-144x144.png +0 -0
  4. package/{src/entry-points/file/assets → assets/client-files}/assets/icons/icon-152x152.png +0 -0
  5. package/{src/entry-points/file/assets → assets/client-files}/assets/icons/icon-192x192.png +0 -0
  6. package/{src/entry-points/file/assets → assets/client-files}/assets/icons/icon-384x384.png +0 -0
  7. package/{src/entry-points/file/assets → assets/client-files}/assets/icons/icon-512x512.png +0 -0
  8. package/{src/entry-points/file/assets → assets/client-files}/assets/icons/icon-72x72.png +0 -0
  9. package/{src/entry-points/file/assets → assets/client-files}/assets/icons/icon-96x96.png +0 -0
  10. package/{src/entry-points/file/assets → assets/client-files}/favicon.ico +0 -0
  11. package/dist/bin/sd-cli.mjs +44 -5
  12. package/dist/build-tool/SdCliCordova.mjs +3 -3
  13. package/dist/build-tool/SdCliIndexFileGenerator.mjs +2 -3
  14. package/dist/builder/SdCliClientBuilder.d.ts +2 -0
  15. package/dist/builder/SdCliClientBuilder.mjs +45 -12
  16. package/dist/builder/SdCliServerBuilder.d.ts +2 -0
  17. package/dist/builder/SdCliServerBuilder.mjs +27 -13
  18. package/dist/entry-points/SdCliPrepare.mjs +34 -34
  19. package/dist/entry-points/SdCliProjectGenerator.d.ts +7 -0
  20. package/dist/entry-points/SdCliProjectGenerator.mjs +65 -33
  21. package/dist/entry-points/file/base/fc_package_eslintrc.mjs +11 -11
  22. package/dist/entry-points/file/base/fc_package_tsconfig.d.ts +1 -0
  23. package/dist/entry-points/file/base/fc_package_tsconfig.mjs +3 -2
  24. package/dist/entry-points/file/client/fc_package_AppModule.mjs +1 -1
  25. package/dist/entry-points/file/client/fc_package_AppPage.mjs +2 -22
  26. package/dist/entry-points/file/client/fc_package_Page.d.ts +4 -0
  27. package/dist/entry-points/file/client/fc_package_Page.mjs +19 -0
  28. package/dist/entry-points/file/project/fc_project_gitignore.mjs +1 -1
  29. package/dist/entry-points/file/project/fc_project_readme.mjs +3 -2
  30. package/dist/index.d.ts +1 -1
  31. package/dist/index.mjs +2 -2
  32. package/dist/ng-tools/SdCliNgModuleGenerator.mjs +35 -36
  33. package/dist/packages/SdCliPackage.mjs +2 -2
  34. package/docs/client-add-page.md +8 -0
  35. package/docs/client-router.md +85 -0
  36. package/docs/client-sw.md +101 -0
  37. package/docs/conf-orm.md +81 -0
  38. package/docs/conf-usage.md +5 -0
  39. package/docs/lib-local-update.md +50 -0
  40. package/docs/lib-ts-paths.md +25 -0
  41. package/package.json +6 -6
  42. package/src/SdCliBuildResultError.ts +9 -9
  43. package/src/bin/sd-cli.ts +48 -5
  44. package/src/build-tool/SdCliCacheCompilerHost.ts +77 -77
  45. package/src/build-tool/SdCliCordova.ts +2 -2
  46. package/src/build-tool/SdCliGithubApi.ts +110 -110
  47. package/src/build-tool/SdCliIndexFileGenerator.ts +79 -80
  48. package/src/build-tool/SdCliNgCacheCompilerHost.ts +58 -58
  49. package/src/build-tool/SdCliPackageLinter.ts +74 -74
  50. package/src/builder/SdCliClientBuilder.ts +58 -13
  51. package/src/builder/SdCliServerBuilder.ts +34 -14
  52. package/src/entry-points/SdCliFileCrypto.ts +87 -87
  53. package/src/entry-points/SdCliPrepare.ts +55 -55
  54. package/src/entry-points/SdCliProjectGenerator.ts +80 -38
  55. package/src/entry-points/file/base/fc_package_eslintrc.ts +10 -10
  56. package/src/entry-points/file/base/fc_package_tsconfig.ts +3 -2
  57. package/src/entry-points/file/client/fc_package_AppModule.ts +1 -1
  58. package/src/entry-points/file/client/fc_package_AppPage.ts +1 -21
  59. package/src/entry-points/file/client/fc_package_Page.ts +19 -0
  60. package/src/entry-points/file/project/fc_project_gitignore.ts +1 -1
  61. package/src/entry-points/file/project/fc_project_readme.ts +2 -1
  62. package/src/index.ts +55 -55
  63. package/src/ng-tools/SdCliNgModuleGenerator.ts +639 -640
  64. package/src/ng-tools/babel/SdCliBbFileMetadata.ts +568 -568
  65. package/src/ng-tools/babel/SdCliBbRootMetadata.ts +239 -239
  66. package/src/ng-tools/babel/SdCliBbUtil.ts +15 -15
  67. package/src/ng-tools/babel/TSdCliBbNgMetadata.ts +234 -234
  68. package/src/ng-tools/babel/TSdCliBbTypeMetadata.ts +177 -177
  69. package/src/ng-tools/commons.ts +3 -3
  70. package/src/ng-tools/typescript/SdCliTsFileMetadata.ts +384 -384
  71. package/src/ng-tools/typescript/SdCliTsRootMetadata.ts +32 -32
  72. package/src/ng-tools/typescript/SdCliTsUtil.ts +29 -29
  73. package/src/packages/SdCliPackage.ts +1 -1
  74. package/src/utils/SdCliConfigUtil.ts +94 -94
  75. package/src/utils/SdCliNpmConfigUtil.ts +16 -16
  76. package/dist/entry-points/file/client/fc_package_appicons.d.ts +0 -1
  77. package/dist/entry-points/file/client/fc_package_appicons.mjs +0 -6
  78. package/src/entry-points/file/client/fc_package_appicons.ts +0 -5
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@simplysm/sd-cli",
3
- "version": "7.0.263",
3
+ "version": "7.0.266",
4
4
  "description": "심플리즘 패키지 - CLI",
5
5
  "author": "김석래",
6
6
  "repository": {
@@ -23,11 +23,11 @@
23
23
  "@babel/parser": "^7.17.0",
24
24
  "@babel/types": "^7.17.0",
25
25
  "@ngtools/webpack": "^13.2.2",
26
- "@simplysm/sd-core-common": "7.0.263",
27
- "@simplysm/sd-core-node": "7.0.263",
28
- "@simplysm/sd-service-common": "7.0.263",
29
- "@simplysm/sd-service-server": "7.0.263",
30
- "@simplysm/sd-storage": "7.0.263",
26
+ "@simplysm/sd-core-common": "7.0.266",
27
+ "@simplysm/sd-core-node": "7.0.266",
28
+ "@simplysm/sd-service-common": "7.0.266",
29
+ "@simplysm/sd-service-server": "7.0.266",
30
+ "@simplysm/sd-storage": "7.0.266",
31
31
  "browserslist": "^4.19.1",
32
32
  "chokidar": "^3.5.3",
33
33
  "connect": "^3.7.0",
@@ -1,9 +1,9 @@
1
- import { SdError } from "@simplysm/sd-core-common";
2
- import { ISdCliPackageBuildResult } from "./commons";
3
- import { SdCliBuildResultUtil } from "./utils/SdCliBuildResultUtil";
4
-
5
- export class SdCliBuildResultError extends SdError {
6
- public constructor(buildResult: ISdCliPackageBuildResult) {
7
- super(SdCliBuildResultUtil.getMessage(buildResult));
8
- }
9
- }
1
+ import { SdError } from "@simplysm/sd-core-common";
2
+ import { ISdCliPackageBuildResult } from "./commons";
3
+ import { SdCliBuildResultUtil } from "./utils/SdCliBuildResultUtil";
4
+
5
+ export class SdCliBuildResultError extends SdError {
6
+ public constructor(buildResult: ISdCliPackageBuildResult) {
7
+ super(SdCliBuildResultUtil.getMessage(buildResult));
8
+ }
9
+ }
package/src/bin/sd-cli.ts CHANGED
@@ -14,7 +14,7 @@ import { SdCliProjectGenerator } from "../entry-points/SdCliProjectGenerator";
14
14
 
15
15
  Error.stackTraceLimit = Infinity;
16
16
 
17
- const argv = yargs(hideBin(process.argv))
17
+ const argv = (yargs(hideBin(process.argv)) as any)
18
18
  .help("help", "도움말")
19
19
  .alias("help", "h")
20
20
  .options({
@@ -229,6 +229,11 @@ const argv = yargs(hideBin(process.argv))
229
229
  type: "boolean",
230
230
  describe: "DOM객체(window, document 등) 사용 여부",
231
231
  default: false
232
+ },
233
+ isForAngular: {
234
+ type: "boolean",
235
+ describe: "Angular 라이브러리 여부 (useDom 옵션을 덮어씁니다)",
236
+ default: false
232
237
  }
233
238
  })
234
239
  .example([
@@ -250,7 +255,7 @@ const argv = yargs(hideBin(process.argv))
250
255
  ])
251
256
  )
252
257
  .command(
253
- "db-model <dbName> <category> <name> <description>",
258
+ "db-model <dbName> <category></category> <name> <description>",
254
259
  "DB 패키지에 모델를 추가합니다.",
255
260
  (cmd1) => cmd1.version(false).hide("help").hide("debug")
256
261
  .positional("dbName", {
@@ -316,10 +321,39 @@ const argv = yargs(hideBin(process.argv))
316
321
  ["$0 add client admin 관리자 server"]
317
322
  ])
318
323
  )
324
+ .command(
325
+ "page <pkgName> <name> [category]",
326
+ "패키지에 페이지를 추가합니다.",
327
+ (cmd1) => cmd1.version(false).hide("help").hide("debug")
328
+ .positional("pkgName", {
329
+ type: "string",
330
+ describe: "패키지명",
331
+ demandOption: true
332
+ })
333
+ .positional("name", {
334
+ type: "string",
335
+ describe: "페이지명",
336
+ demandOption: true
337
+ })
338
+ .positional("category", {
339
+ type: "string",
340
+ describe: "추가할 페이지의 분류명"
341
+ })
342
+ .options({
343
+ isRouteParent: {
344
+ type: "boolean",
345
+ describe: "router-outlet 포함 여부",
346
+ default: false
347
+ }
348
+ })
349
+ .example([
350
+ ["$0 add page admin Employee home/base"]
351
+ ])
352
+ )
319
353
  )
320
354
  .parseSync();
321
355
 
322
- if (argv.debug) {
356
+ if (Boolean(argv.debug)) {
323
357
  process.env["SD_CLI_LOGGER_SEVERITY"] = "DEBUG";
324
358
 
325
359
  Logger.setConfig({
@@ -395,7 +429,7 @@ const logger = Logger.get(["simplysm", "sd-cli", "bin", "sd-cli"]);
395
429
  optNames: argv.options ?? [],
396
430
  pkgs: argv.packages ?? []
397
431
  });
398
- if (!argv.noBuild) {
432
+ if (!Boolean(argv.noBuild)) {
399
433
  process.exit(0);
400
434
  }
401
435
  }
@@ -418,7 +452,8 @@ const logger = Logger.get(["simplysm", "sd-cli", "bin", "sd-cli"]);
418
452
  await new SdCliProjectGenerator(process.cwd()).addTsLibAsync({
419
453
  name: argv.name!,
420
454
  description: argv.description!,
421
- useDom: argv.useDom
455
+ useDom: argv.useDom,
456
+ isForAngular: argv.isForAngular
422
457
  });
423
458
  }
424
459
  else if (argv._[1] === "db-lib") {
@@ -434,6 +469,14 @@ const logger = Logger.get(["simplysm", "sd-cli", "bin", "sd-cli"]);
434
469
  description: argv.description!
435
470
  });
436
471
  }
472
+ else if (argv._[1] === "page") {
473
+ await new SdCliProjectGenerator(process.cwd()).addPageAsync({
474
+ pkgName: argv.pkgName,
475
+ category: argv.category,
476
+ name: argv.name!,
477
+ isRouteParent: argv.isRouteParent
478
+ });
479
+ }
437
480
  else if (argv._[1] === "server") {
438
481
  await new SdCliProjectGenerator(process.cwd()).addServerAsync({
439
482
  name: argv.name,
@@ -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._rootPath);
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());
@@ -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
  }