@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.
Files changed (138) hide show
  1. package/README.md +95 -0
  2. package/assets/client-files/assets/icons/icon-128x128.png +0 -0
  3. package/assets/client-files/assets/icons/icon-144x144.png +0 -0
  4. package/assets/client-files/assets/icons/icon-152x152.png +0 -0
  5. package/assets/client-files/assets/icons/icon-192x192.png +0 -0
  6. package/assets/client-files/assets/icons/icon-384x384.png +0 -0
  7. package/assets/client-files/assets/icons/icon-512x512.png +0 -0
  8. package/assets/client-files/assets/icons/icon-72x72.png +0 -0
  9. package/assets/client-files/assets/icons/icon-96x96.png +0 -0
  10. package/assets/client-files/favicon.ico +0 -0
  11. package/dist/bin/sd-cli.mjs +212 -15
  12. package/dist/build-tool/SdCliCordova.mjs +3 -3
  13. package/dist/build-tool/SdCliElectron.mjs +3 -2
  14. package/dist/build-tool/SdCliIndexFileGenerator.mjs +2 -3
  15. package/dist/builder/SdCliClientBuilder.d.ts +2 -0
  16. package/dist/builder/SdCliClientBuilder.mjs +57 -20
  17. package/dist/builder/SdCliServerBuilder.d.ts +2 -0
  18. package/dist/builder/SdCliServerBuilder.mjs +27 -13
  19. package/dist/builder/SdCliTsLibBuilder.mjs +18 -12
  20. package/dist/commons.d.ts +6 -1
  21. package/dist/entry-points/SdCliPrepare.mjs +34 -34
  22. package/dist/entry-points/SdCliProjectGenerator.d.ts +44 -0
  23. package/dist/entry-points/SdCliProjectGenerator.mjs +320 -0
  24. package/dist/entry-points/SdCliWorkspace.d.ts +6 -6
  25. package/dist/entry-points/SdCliWorkspace.mjs +61 -107
  26. package/dist/entry-points/file/base/fc_package_eslintrc.d.ts +3 -0
  27. package/dist/entry-points/file/base/fc_package_eslintrc.mjs +31 -0
  28. package/dist/entry-points/file/base/fc_package_npmconfig.d.ts +9 -0
  29. package/dist/entry-points/file/base/fc_package_npmconfig.mjs +32 -0
  30. package/dist/entry-points/file/base/fc_package_tsconfig.d.ts +5 -0
  31. package/dist/entry-points/file/base/fc_package_tsconfig.mjs +13 -0
  32. package/dist/entry-points/file/client/fc_package_AppModule.d.ts +1 -0
  33. package/dist/entry-points/file/client/fc_package_AppModule.mjs +37 -0
  34. package/dist/entry-points/file/client/fc_package_AppPage.d.ts +1 -0
  35. package/dist/entry-points/file/client/fc_package_AppPage.mjs +14 -0
  36. package/dist/entry-points/file/client/fc_package_Page.d.ts +4 -0
  37. package/dist/entry-points/file/client/fc_package_Page.mjs +19 -0
  38. package/dist/entry-points/file/client/fc_package_client_main.d.ts +1 -0
  39. package/dist/entry-points/file/client/fc_package_client_main.mjs +19 -0
  40. package/dist/entry-points/file/client/fc_package_index.d.ts +3 -0
  41. package/dist/entry-points/file/client/fc_package_index.mjs +88 -0
  42. package/dist/entry-points/file/client/fc_package_manifest.d.ts +5 -0
  43. package/dist/entry-points/file/client/fc_package_manifest.mjs +54 -0
  44. package/dist/entry-points/file/client/fc_package_polyfills.d.ts +1 -0
  45. package/dist/entry-points/file/client/fc_package_polyfills.mjs +11 -0
  46. package/dist/entry-points/file/client/fc_package_styles.d.ts +1 -0
  47. package/dist/entry-points/file/client/fc_package_styles.mjs +7 -0
  48. package/dist/entry-points/file/db/fc_package_DbContext.d.ts +3 -0
  49. package/dist/entry-points/file/db/fc_package_DbContext.mjs +14 -0
  50. package/dist/entry-points/file/db/fc_package_DbModel.d.ts +4 -0
  51. package/dist/entry-points/file/db/fc_package_DbModel.mjs +12 -0
  52. package/dist/entry-points/file/project/fc_project_editor_config.d.ts +1 -0
  53. package/dist/entry-points/file/project/fc_project_editor_config.mjs +22 -0
  54. package/dist/entry-points/file/project/fc_project_eslintrc.d.ts +1 -0
  55. package/dist/entry-points/file/project/fc_project_eslintrc.mjs +30 -0
  56. package/dist/entry-points/file/project/fc_project_gitattributes.d.ts +1 -0
  57. package/dist/entry-points/file/project/fc_project_gitattributes.mjs +6 -0
  58. package/dist/entry-points/file/project/fc_project_gitignore.d.ts +1 -0
  59. package/dist/entry-points/file/project/fc_project_gitignore.mjs +17 -0
  60. package/dist/entry-points/file/project/fc_project_npmconfig.d.ts +7 -0
  61. package/dist/entry-points/file/project/fc_project_npmconfig.mjs +35 -0
  62. package/dist/entry-points/file/project/fc_project_readme.d.ts +3 -0
  63. package/dist/entry-points/file/project/fc_project_readme.mjs +13 -0
  64. package/dist/entry-points/file/project/fc_project_simplysm.d.ts +1 -0
  65. package/dist/entry-points/file/project/fc_project_simplysm.mjs +2 -0
  66. package/dist/entry-points/file/project/fc_project_tsconfig.d.ts +1 -0
  67. package/dist/entry-points/file/project/fc_project_tsconfig.mjs +25 -0
  68. package/dist/entry-points/file/server/fc_package_server_main.d.ts +4 -0
  69. package/dist/entry-points/file/server/fc_package_server_main.mjs +60 -0
  70. package/dist/index.d.ts +23 -0
  71. package/dist/index.mjs +24 -1
  72. package/dist/ng-tools/SdCliNgModuleGenerator.mjs +35 -36
  73. package/dist/packages/SdCliPackage.d.ts +1 -0
  74. package/dist/packages/SdCliPackage.mjs +69 -63
  75. package/dist/utils/SdCliBuildResultUtil.mjs +2 -2
  76. package/docs/client-add-page.md +8 -0
  77. package/docs/client-router.md +85 -0
  78. package/docs/client-sw.md +101 -0
  79. package/docs/conf-orm.md +81 -0
  80. package/docs/conf-usage.md +5 -0
  81. package/docs/lib-local-update.md +50 -0
  82. package/docs/lib-ts-paths.md +25 -0
  83. package/package.json +10 -8
  84. package/src/SdCliBuildResultError.ts +9 -9
  85. package/src/bin/sd-cli.ts +244 -15
  86. package/src/build-tool/SdCliCacheCompilerHost.ts +77 -77
  87. package/src/build-tool/SdCliCordova.ts +2 -2
  88. package/src/build-tool/SdCliElectron.ts +2 -1
  89. package/src/build-tool/SdCliGithubApi.ts +110 -110
  90. package/src/build-tool/SdCliIndexFileGenerator.ts +79 -80
  91. package/src/build-tool/SdCliNgCacheCompilerHost.ts +58 -58
  92. package/src/build-tool/SdCliPackageLinter.ts +74 -74
  93. package/src/builder/SdCliClientBuilder.ts +73 -22
  94. package/src/builder/SdCliJsLibBuilder.ts +70 -70
  95. package/src/builder/SdCliServerBuilder.ts +34 -14
  96. package/src/builder/SdCliTsLibBuilder.ts +450 -445
  97. package/src/commons.ts +6 -1
  98. package/src/entry-points/SdCliFileCrypto.ts +87 -87
  99. package/src/entry-points/SdCliPrepare.ts +55 -55
  100. package/src/entry-points/SdCliProjectGenerator.ts +395 -0
  101. package/src/entry-points/SdCliWorkspace.ts +74 -122
  102. package/src/entry-points/file/base/fc_package_eslintrc.ts +30 -0
  103. package/src/entry-points/file/base/fc_package_npmconfig.ts +43 -0
  104. package/src/entry-points/file/base/fc_package_tsconfig.ts +12 -0
  105. package/src/entry-points/file/client/fc_package_AppModule.ts +36 -0
  106. package/src/entry-points/file/client/fc_package_AppPage.ts +13 -0
  107. package/src/entry-points/file/client/fc_package_Page.ts +19 -0
  108. package/src/entry-points/file/client/fc_package_client_main.ts +18 -0
  109. package/src/entry-points/file/client/fc_package_index.ts +87 -0
  110. package/src/entry-points/file/client/fc_package_manifest.ts +53 -0
  111. package/src/entry-points/file/client/fc_package_polyfills.ts +10 -0
  112. package/src/entry-points/file/client/fc_package_styles.ts +6 -0
  113. package/src/entry-points/file/db/fc_package_DbContext.ts +14 -0
  114. package/src/entry-points/file/db/fc_package_DbModel.ts +11 -0
  115. package/src/entry-points/file/project/fc_project_editor_config.ts +21 -0
  116. package/src/entry-points/file/project/fc_project_eslintrc.ts +29 -0
  117. package/src/entry-points/file/project/fc_project_gitattributes.ts +5 -0
  118. package/src/entry-points/file/project/fc_project_gitignore.ts +16 -0
  119. package/src/entry-points/file/project/fc_project_npmconfig.ts +34 -0
  120. package/src/entry-points/file/project/fc_project_readme.ts +12 -0
  121. package/src/entry-points/file/project/fc_project_simplysm.ts +1 -0
  122. package/src/entry-points/file/project/fc_project_tsconfig.ts +24 -0
  123. package/src/entry-points/file/server/fc_package_server_main.ts +62 -0
  124. package/src/index.ts +55 -32
  125. package/src/ng-tools/SdCliNgModuleGenerator.ts +639 -640
  126. package/src/ng-tools/babel/SdCliBbFileMetadata.ts +568 -568
  127. package/src/ng-tools/babel/SdCliBbRootMetadata.ts +239 -239
  128. package/src/ng-tools/babel/SdCliBbUtil.ts +15 -15
  129. package/src/ng-tools/babel/TSdCliBbNgMetadata.ts +234 -234
  130. package/src/ng-tools/babel/TSdCliBbTypeMetadata.ts +177 -177
  131. package/src/ng-tools/commons.ts +3 -3
  132. package/src/ng-tools/typescript/SdCliTsFileMetadata.ts +384 -384
  133. package/src/ng-tools/typescript/SdCliTsRootMetadata.ts +32 -32
  134. package/src/ng-tools/typescript/SdCliTsUtil.ts +29 -29
  135. package/src/packages/SdCliPackage.ts +76 -59
  136. package/src/utils/SdCliBuildResultUtil.ts +76 -76
  137. package/src/utils/SdCliConfigUtil.ts +94 -94
  138. 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._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());
@@ -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 os from "os";
5
- import chokidar from "chokidar";
6
-
7
- export class SdCliIndexFileGenerator {
8
- private readonly _indexFilePath = path.resolve(this.rootPath, "src/index.ts");
9
- private _contentCache: string | undefined;
10
-
11
- public constructor(public readonly rootPath: string,
12
- public readonly config: ISdAutoIndexConfig) {
13
- this._contentCache = FsUtil.exists(this._indexFilePath) ? FsUtil.readFile(this._indexFilePath) : undefined;
14
- }
15
-
16
- public async watchAsync(): Promise<void> {
17
- const watcher = chokidar.watch([path.resolve(this.rootPath, "src")], { persistent: true });
18
- watcher.on("add", async (filePath) => {
19
- if (filePath.endsWith(".ts")) {
20
- await this.runAsync();
21
- }
22
- });
23
- watcher.on("unlink", async (filePath) => {
24
- if (filePath.endsWith(".ts")) {
25
- await this.runAsync();
26
- }
27
- });
28
-
29
- await this.runAsync();
30
- }
31
-
32
- public async runAsync(): Promise<void> {
33
- const importTexts: string[] = [];
34
-
35
- // 옵션의 polyfills 를 모두 import
36
- if (this.config.polyfills) {
37
- for (const polyfill of this.config.polyfills) {
38
- importTexts.push(`import "${polyfill}";`);
39
- }
40
- }
41
-
42
- // 내부 파일들 import
43
- const filePaths = await this._getFilePathsAsync();
44
- for (const filePath of filePaths) {
45
- const requirePath = PathUtil.posix(path.relative(path.dirname(this._indexFilePath), filePath))
46
- .replace(/\.ts$/, "")
47
- .replace(/\/index$/, "");
48
-
49
- const sourceTsFileContent = await FsUtil.readFileAsync(filePath);
50
- if (sourceTsFileContent.split("\n").some((line) => line.startsWith("export "))) {
51
- importTexts.push(`export * from "./${requirePath}";`);
52
- }
53
- else {
54
- importTexts.push(`import "./${requirePath}";`);
55
- }
56
- }
57
-
58
- const content = importTexts.join(os.EOL) + os.EOL;
59
- const prevContent = this._contentCache;
60
- this._contentCache = content;
61
- if (content.trim() !== prevContent?.trim()) {
62
- await FsUtil.writeFileAsync(this._indexFilePath, content);
63
- }
64
- }
65
-
66
- private async _getFilePathsAsync(): Promise<string[]> {
67
- const tsconfig: ITsconfig = await FsUtil.readJsonAsync(path.resolve(this.rootPath, "tsconfig.json"));
68
- const entryFilePaths = tsconfig.files?.map((item) => path.resolve(this.rootPath, item)) ?? [];
69
-
70
- return (await FsUtil.globAsync(path.resolve(this.rootPath, "src/**/*.ts"), { nodir: true }))
71
- .filter((item) => (
72
- !entryFilePaths.includes(item)
73
- && item !== this._indexFilePath
74
- ));
75
- }
76
- }
77
-
78
- export interface ISdAutoIndexConfig {
79
- polyfills?: string[];
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
+ }