@zwa73/dev-utils 1.0.71 → 1.0.80
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/data/InitElectron/src/Backend/BridgeBackend.ts +7 -0
- package/dist/Command/Release.js +28 -3
- package/dist/UtilInterface.d.ts +4 -0
- package/dist/UtilInterface.js +2 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +1 -0
- package/package.json +1 -1
- package/src/Command/ExpandMacro.ts +1 -1
- package/src/Command/GenI18n.ts +1 -1
- package/src/Command/GenSchema.ts +1 -1
- package/src/Command/Release.ts +36 -5
- package/src/UtilInterface.ts +5 -0
- package/src/index.ts +2 -1
- package/tsconfig.json +3 -3
@@ -1,5 +1,6 @@
|
|
1
1
|
import { AllExtends, JToken, UtilFT } from "@zwa73/utils";
|
2
2
|
import { IpcMainInvokeEvent, app } from "electron";
|
3
|
+
import fs from 'fs';
|
3
4
|
|
4
5
|
/**桥函数化 */
|
5
6
|
const bridgeify = <F extends (...args: any[]) => any>(func:F):
|
@@ -17,6 +18,12 @@ const bridgeify = <F extends (...args: any[]) => any>(func:F):
|
|
17
18
|
export const BridgeBackend = {
|
18
19
|
loadJsonFile :bridgeify(UtilFT.writeJSONFile),
|
19
20
|
writeJSONFile:bridgeify(UtilFT.writeJSONFile),
|
21
|
+
async writeFile(e:IpcMainInvokeEvent,path:string,data:string){
|
22
|
+
return fs.promises.writeFile(path,data);
|
23
|
+
},
|
24
|
+
async readFile(e:IpcMainInvokeEvent,path:string){
|
25
|
+
return fs.promises.readFile(path,'utf-8');
|
26
|
+
},
|
20
27
|
getAppPath() {
|
21
28
|
return app.getAppPath();
|
22
29
|
},
|
package/dist/Command/Release.js
CHANGED
@@ -7,6 +7,7 @@ exports.CmdRelease = void 0;
|
|
7
7
|
const pathe_1 = __importDefault(require("pathe"));
|
8
8
|
const utils_1 = require("@zwa73/utils");
|
9
9
|
const RouteInterface_1 = require("./RouteInterface");
|
10
|
+
const fs_1 = __importDefault(require("fs"));
|
10
11
|
/**解析版本号为number数组 */
|
11
12
|
function parseVersion(version) {
|
12
13
|
const arr = version.split(".").map(Number);
|
@@ -32,7 +33,7 @@ function checkVersion(oldVersion, newVersion) {
|
|
32
33
|
/**更新版本号 */
|
33
34
|
async function updateVersion(newVersion) {
|
34
35
|
const packagePath = pathe_1.default.join(RouteInterface_1.PROJECT_PATH, "package.json");
|
35
|
-
const packageData = await utils_1.UtilFT.loadJSONFile(packagePath);
|
36
|
+
const packageData = await (0, utils_1.memoize)(utils_1.UtilFT.loadJSONFile)(packagePath);
|
36
37
|
if (newVersion) {
|
37
38
|
checkVersion(packageData.version, newVersion);
|
38
39
|
packageData.version = newVersion;
|
@@ -45,19 +46,43 @@ async function updateVersion(newVersion) {
|
|
45
46
|
await utils_1.UtilFT.writeJSONFile(packagePath, packageData);
|
46
47
|
return packageData.version;
|
47
48
|
}
|
49
|
+
/**获取包名 */
|
50
|
+
async function getPackName() {
|
51
|
+
const packagePath = pathe_1.default.join(RouteInterface_1.PROJECT_PATH, "package.json");
|
52
|
+
const packageData = await (0, utils_1.memoize)(utils_1.UtilFT.loadJSONFile)(packagePath);
|
53
|
+
return packageData.name
|
54
|
+
.replace(/\//g, '-')
|
55
|
+
.replace(/^@/g, '');
|
56
|
+
}
|
48
57
|
/**更新版本号并发布npm包 */
|
49
58
|
const CmdRelease = (program) => program
|
50
59
|
.command("Release")
|
51
60
|
.alias("release")
|
52
61
|
.description("更新版本号并发布包")
|
53
|
-
.option("-v, --version <version>", "指定发布的版本号 `${number}.${number}.${number}`")
|
54
|
-
.option("-a, --access <access>", "npm publish 的 access 参数", "public")
|
62
|
+
.option("-v, --version <version>", "指定发布的版本号 格式应为 `${number}.${number}.${number}`")
|
63
|
+
.option("-a, --access <access>", "npm publish 的 access 参数 默认 public", "public")
|
64
|
+
.option("-l, --local <path>", "仅打包到本地对印目录下 如./build/", undefined)
|
55
65
|
.action(async (opt) => {
|
56
66
|
(0, RouteInterface_1.checkProject)();
|
57
67
|
utils_1.SLogger.info(`开始发布项目`);
|
58
68
|
try {
|
59
69
|
const newVersion = await updateVersion(opt.version);
|
60
70
|
utils_1.SLogger.info(`新版本号: ${newVersion}`);
|
71
|
+
if (opt.local) {
|
72
|
+
utils_1.SLogger.info("正在打包...");
|
73
|
+
const fullpath = pathe_1.default.join(process.cwd(), opt.local);
|
74
|
+
await utils_1.UtilFT.ensurePathExists(fullpath, { dir: true });
|
75
|
+
await utils_1.UtilFunc.exec(`npm pack`, { errlvl: 'info' });
|
76
|
+
const packageName = await getPackName();
|
77
|
+
const filelist = await fs_1.default.promises.readdir(process.cwd());
|
78
|
+
await Promise.all(filelist
|
79
|
+
.filter(p => new RegExp(packageName).test(p))
|
80
|
+
.map(async (p) => {
|
81
|
+
const packagePath = pathe_1.default.join(fullpath, p);
|
82
|
+
await fs_1.default.promises.rename(p, packagePath);
|
83
|
+
}));
|
84
|
+
return;
|
85
|
+
}
|
61
86
|
utils_1.SLogger.info("正在发布...");
|
62
87
|
const cmd = `npm publish --registry ${RouteInterface_1.OFFICIAL_SOURCE} --access ${opt.access}`;
|
63
88
|
await utils_1.UtilFunc.exec(cmd, { errlvl: 'info' });
|
package/dist/index.d.ts
CHANGED
package/dist/index.js
CHANGED
package/package.json
CHANGED
package/src/Command/GenI18n.ts
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
import { Command } from "commander";
|
2
2
|
import { AnyFunc, I18nTextData, SI18n, UtilFT, ivk } from "@zwa73/utils";
|
3
3
|
import { Project,SyntaxKind } from 'ts-morph';
|
4
|
-
import { UtilAst } from "
|
4
|
+
import { UtilAst } from "@/src/UtilAst";
|
5
5
|
import path from 'pathe';
|
6
6
|
|
7
7
|
function format(str:string){
|
package/src/Command/GenSchema.ts
CHANGED
package/src/Command/Release.ts
CHANGED
@@ -1,9 +1,10 @@
|
|
1
1
|
import { Command } from 'commander';
|
2
2
|
import path from 'pathe';
|
3
3
|
|
4
|
-
import { SLogger, throwError, UtilFT, UtilFunc } from '@zwa73/utils';
|
4
|
+
import { memoize, SLogger, throwError, UtilFT, UtilFunc } from '@zwa73/utils';
|
5
5
|
|
6
6
|
import { checkProject, OFFICIAL_SOURCE, PROJECT_PATH } from './RouteInterface';
|
7
|
+
import fs from 'fs';
|
7
8
|
|
8
9
|
/**解析版本号为number数组 */
|
9
10
|
function parseVersion(version: string){
|
@@ -27,10 +28,11 @@ function checkVersion(oldVersion: string, newVersion: string) {
|
|
27
28
|
break;
|
28
29
|
}
|
29
30
|
}
|
31
|
+
|
30
32
|
/**更新版本号 */
|
31
33
|
async function updateVersion(newVersion?: string): Promise<string> {
|
32
34
|
const packagePath = path.join(PROJECT_PATH, "package.json");
|
33
|
-
const packageData = await UtilFT.loadJSONFile(packagePath) as any;
|
35
|
+
const packageData = await memoize(UtilFT.loadJSONFile)(packagePath) as any;
|
34
36
|
if (newVersion) {
|
35
37
|
checkVersion(packageData.version, newVersion);
|
36
38
|
packageData.version = newVersion;
|
@@ -42,19 +44,48 @@ async function updateVersion(newVersion?: string): Promise<string> {
|
|
42
44
|
await UtilFT.writeJSONFile(packagePath, packageData);
|
43
45
|
return packageData.version;
|
44
46
|
}
|
47
|
+
/**获取包名 */
|
48
|
+
async function getPackName(){
|
49
|
+
const packagePath = path.join(PROJECT_PATH, "package.json");
|
50
|
+
const packageData = await memoize(UtilFT.loadJSONFile)(packagePath) as any;
|
51
|
+
return packageData.name
|
52
|
+
.replace(/\//g,'-')
|
53
|
+
.replace(/^@/g,'');
|
54
|
+
}
|
55
|
+
|
45
56
|
/**更新版本号并发布npm包 */
|
46
57
|
export const CmdRelease = (program: Command) =>program
|
47
58
|
.command("Release")
|
48
59
|
.alias("release")
|
49
60
|
.description("更新版本号并发布包")
|
50
|
-
.option("-v, --version <version>", "指定发布的版本号 `${number}.${number}.${number}`")
|
51
|
-
.option("-a, --access <access>", "npm publish 的 access 参数","public")
|
52
|
-
.
|
61
|
+
.option("-v, --version <version>", "指定发布的版本号 格式应为 `${number}.${number}.${number}`")
|
62
|
+
.option("-a, --access <access>", "npm publish 的 access 参数 默认 public","public")
|
63
|
+
.option("-l, --local <path>", "仅打包到本地对印目录下 如./build/",undefined)
|
64
|
+
.action(async (opt:{
|
65
|
+
version?: string;
|
66
|
+
access: string;
|
67
|
+
local?: string;
|
68
|
+
}) => {
|
53
69
|
checkProject();
|
54
70
|
SLogger.info(`开始发布项目`);
|
55
71
|
try {
|
56
72
|
const newVersion = await updateVersion(opt.version);
|
57
73
|
SLogger.info(`新版本号: ${newVersion}`);
|
74
|
+
if(opt.local){
|
75
|
+
SLogger.info("正在打包...");
|
76
|
+
const fullpath = path.join(process.cwd(),opt.local);
|
77
|
+
await UtilFT.ensurePathExists(fullpath,{dir:true});
|
78
|
+
await UtilFunc.exec(`npm pack`,{errlvl:'info'});
|
79
|
+
const packageName = await getPackName();
|
80
|
+
const filelist = await fs.promises.readdir(process.cwd());
|
81
|
+
await Promise.all(filelist
|
82
|
+
.filter(p=>new RegExp(packageName).test(p))
|
83
|
+
.map(async p=>{
|
84
|
+
const packagePath = path.join(fullpath, p);
|
85
|
+
await fs.promises.rename(p, packagePath);
|
86
|
+
}))
|
87
|
+
return;
|
88
|
+
}
|
58
89
|
SLogger.info("正在发布...");
|
59
90
|
const cmd = `npm publish --registry ${OFFICIAL_SOURCE} --access ${opt.access}`;
|
60
91
|
await UtilFunc.exec(cmd,{errlvl:'info'});
|
package/src/index.ts
CHANGED
package/tsconfig.json
CHANGED
@@ -12,9 +12,9 @@
|
|
12
12
|
"emitDecoratorMetadata": true,
|
13
13
|
"experimentalDecorators": true,
|
14
14
|
"paths": {
|
15
|
-
|
16
|
-
|
17
|
-
|
15
|
+
"@/src/*" : ["./src/*"],
|
16
|
+
"@/*" : ["./*"],
|
17
|
+
"@" : ["./src/index"]
|
18
18
|
}
|
19
19
|
},
|
20
20
|
"include": ["./src/**/*.ts", "./src/**/*.js","./jest/**/*.ts"],
|