@simplysm/sd-cli 7.0.66 → 7.0.74

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.
@@ -1,14 +1,16 @@
1
1
  import { INpmConfig, ISdCliPackageBuildResult, ITsconfig, TSdCliPackageConfig } from "../commons";
2
2
  import path from "path";
3
- import { FsUtil, SdProcess } from "@simplysm/sd-core-node";
3
+ import { FsUtil, PathUtil, SdProcess } from "@simplysm/sd-core-node";
4
4
  import { EventEmitter } from "events";
5
- import { ObjectUtil } from "@simplysm/sd-core-common";
5
+ import { NeverEntryError, ObjectUtil, StringUtil } from "@simplysm/sd-core-common";
6
6
  import { SdCliTsLibBuilder } from "../builder/SdCliTsLibBuilder";
7
7
  import { SdCliJsLibBuilder } from "../builder/SdCliJsLibBuilder";
8
8
  import { SdCliServerBuilder } from "../builder/SdCliServerBuilder";
9
9
  import { SdCliNpmConfigUtil } from "../utils/SdCliNpmConfigUtil";
10
10
  import { SdCliClientBuilder } from "../builder/SdCliClientBuilder";
11
11
  import { NextHandleFunction } from "connect";
12
+ import { SdStorage } from "@simplysm/sd-storage";
13
+ import ts from "typescript";
12
14
 
13
15
  export class SdCliPackage extends EventEmitter {
14
16
  private readonly _npmConfig: INpmConfig;
@@ -83,8 +85,57 @@ export class SdCliPackage extends EventEmitter {
83
85
  }
84
86
 
85
87
  public async publishAsync(): Promise<void> {
86
- if (this.config.type === "library" && this.config.publish === "npm") {
87
- await SdProcess.spawnAsync("npm publish --quiet --access public", { cwd: this.rootPath });
88
+ if (this.config.publish !== undefined) {
89
+ if (this.config.type === "library") {
90
+ // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
91
+ if (this.config.publish === "npm") {
92
+ await SdProcess.spawnAsync("npm publish --quiet --access public", { cwd: this.rootPath });
93
+ }
94
+ else {
95
+ throw new NeverEntryError();
96
+ }
97
+ }
98
+ else {
99
+ if (this.config.publish.type === "ftp" || this.config.publish.type === "ftps" || this.config.publish.type === "sftp") {
100
+ const tsconfigPath = path.resolve(this.rootPath, "tsconfig-build.json");
101
+ const tsconfig = FsUtil.readJson(tsconfigPath);
102
+ const parsedTsconfig = ts.parseJsonConfigFileContent(tsconfig, ts.sys, this.rootPath, tsconfig.angularCompilerOptions);
103
+
104
+ const ftp = await SdStorage.connectAsync(this.config.publish.type, {
105
+ host: this.config.publish.host,
106
+ port: this.config.publish.port,
107
+ user: this.config.publish.user,
108
+ pass: this.config.publish.pass
109
+ });
110
+ await ftp.uploadDirAsync(parsedTsconfig.options.outDir!, this.config.publish.path);
111
+ await ftp.closeAsync();
112
+ }
113
+ // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
114
+ else if (this.config.publish.type === "local-directory") {
115
+ const tsconfigPath = path.resolve(this.rootPath, "tsconfig-build.json");
116
+ const tsconfig = FsUtil.readJson(tsconfigPath);
117
+ const parsedTsconfig = ts.parseJsonConfigFileContent(tsconfig, ts.sys, this.rootPath, tsconfig.angularCompilerOptions);
118
+
119
+ const targetRootPath = this.config.publish.path.replace(/%([^%]*)%/g, (item) => {
120
+ const envName = item.replace(/%/g, "");
121
+ if (!StringUtil.isNullOrEmpty(this._npmConfig.version) && envName === "SD_VERSION") {
122
+ return this._npmConfig.version;
123
+ }
124
+ return process.env[envName] ?? item;
125
+ });
126
+
127
+ const filePaths = await FsUtil.globAsync(path.resolve(this.rootPath, "**", "*"), {
128
+ dot: true,
129
+ nodir: true
130
+ });
131
+
132
+ await filePaths.parallelAsync(async (filePath) => {
133
+ const relativeFilePath = path.relative(parsedTsconfig.options.outDir!, filePath);
134
+ const targetPath = PathUtil.posix(targetRootPath, relativeFilePath);
135
+ await FsUtil.copyAsync(filePath, targetPath);
136
+ });
137
+ }
138
+ }
88
139
  }
89
140
  }
90
141
 
package/tsconfig.json CHANGED
@@ -18,6 +18,9 @@
18
18
  ],
19
19
  "@simplysm/sd-service-server": [
20
20
  "../sd-service-server/src/index.ts"
21
+ ],
22
+ "@simplysm/sd-storage": [
23
+ "../sd-storage/src/index.ts"
21
24
  ]
22
25
  }
23
26
  },