@zwa73/dev-utils 1.0.5 → 1.0.13
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/dist/Command/Init.js +5 -7
- package/dist/Command/Release.js +15 -13
- package/dist/Command/RouteInterface.js +0 -4
- package/package.json +2 -2
- package/scripts/compile.ps1 +4 -4
- package/scripts/release.ps1 +4 -0
- package/scripts/watch.ps1 +9 -9
- package/src/Command/Init.ts +7 -9
- package/src/Command/Release.ts +13 -13
- package/src/Command/RouteInterface.ts +1 -5
- package/release.bat +0 -2
- package/release.js +0 -16
package/dist/Command/Init.js
CHANGED
@@ -45,7 +45,7 @@ async function copyData() {
|
|
45
45
|
}
|
46
46
|
/**安装npm包 */
|
47
47
|
async function installPackage() {
|
48
|
-
const install = async (name) => await utils_1.UtilFunc.exec(`npm i ${name}`);
|
48
|
+
const install = async (name) => await utils_1.UtilFunc.exec(`npm i --registry ${RouteInterface_1.MIRROR_SOURCE} ${name}`);
|
49
49
|
const packageList = ['@zwa73/utils'];
|
50
50
|
for (const name of packageList) {
|
51
51
|
utils_1.SLogger.info(`正在安装 ${name}`);
|
@@ -59,11 +59,9 @@ const CmdInit = (program) => program
|
|
59
59
|
.action(async (opt) => {
|
60
60
|
(0, RouteInterface_1.checkProject)();
|
61
61
|
utils_1.SLogger.info(`开始初始化设置当前目录 ${RouteInterface_1.PROJECT_PATH}`);
|
62
|
-
await
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
]);
|
67
|
-
});
|
62
|
+
await Promise.all([
|
63
|
+
copyData(),
|
64
|
+
installPackage(),
|
65
|
+
]);
|
68
66
|
});
|
69
67
|
exports.CmdInit = CmdInit;
|
package/dist/Command/Release.js
CHANGED
@@ -54,18 +54,20 @@ const CmdRelease = (program) => program
|
|
54
54
|
.action(async (opt) => {
|
55
55
|
(0, RouteInterface_1.checkProject)();
|
56
56
|
utils_1.SLogger.info(`开始发布项目`);
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
utils_1.SLogger.
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
57
|
+
try {
|
58
|
+
const newVersion = await updateVersion(opt.version);
|
59
|
+
utils_1.SLogger.info(`新版本号: ${newVersion}`);
|
60
|
+
utils_1.SLogger.info("正在发布...");
|
61
|
+
const cmd = `npm publish --registry ${RouteInterface_1.OFFICIAL_SOURCE} --access ${opt.access}`;
|
62
|
+
const { stderr, stdout } = await utils_1.UtilFunc.exec(cmd);
|
63
|
+
if (stderr)
|
64
|
+
utils_1.SLogger.error(stderr);
|
65
|
+
else
|
66
|
+
utils_1.SLogger.info(stdout);
|
67
|
+
utils_1.SLogger.info("发布完成");
|
68
|
+
}
|
69
|
+
catch (error) {
|
70
|
+
utils_1.SLogger.error(error);
|
71
|
+
}
|
70
72
|
});
|
71
73
|
exports.CmdRelease = CmdRelease;
|
@@ -61,11 +61,9 @@ async function withMirrorSource(func) {
|
|
61
61
|
const OriginSource = out.stdout.trim(); //?
|
62
62
|
utils_1.SLogger.info(`正在修改npm源为 镜像源: ${exports.MIRROR_SOURCE}`);
|
63
63
|
await utils_1.UtilFunc.exec(`npm config set registry ${exports.MIRROR_SOURCE}`);
|
64
|
-
utils_1.SLogger.info(`成功修改npm源为 镜像源: ${exports.MIRROR_SOURCE}`);
|
65
64
|
await func();
|
66
65
|
utils_1.SLogger.info(`正在修改npm源为 原始源: ${OriginSource}`);
|
67
66
|
await utils_1.UtilFunc.exec(`npm config set registry ${OriginSource}`);
|
68
|
-
utils_1.SLogger.info(`成功修改npm源为 原始源: ${OriginSource}`);
|
69
67
|
}
|
70
68
|
exports.withMirrorSource = withMirrorSource;
|
71
69
|
/**在官方源内镜像操作 */
|
@@ -74,11 +72,9 @@ async function withOfficialSource(func) {
|
|
74
72
|
const OriginSource = out.stdout.trim(); //?
|
75
73
|
utils_1.SLogger.info(`正在修改npm源为 官方源: ${exports.OFFICIAL_SOURCE}`);
|
76
74
|
await utils_1.UtilFunc.exec(`npm config set registry ${exports.OFFICIAL_SOURCE}`);
|
77
|
-
utils_1.SLogger.info(`成功修改npm源为 官方源: ${exports.OFFICIAL_SOURCE}`);
|
78
75
|
await func();
|
79
76
|
utils_1.SLogger.info(`正在修改npm源为 原始源: ${OriginSource}`);
|
80
77
|
await utils_1.UtilFunc.exec(`npm config set registry ${OriginSource}`);
|
81
|
-
utils_1.SLogger.info(`成功修改npm源为 原始源: ${OriginSource}`);
|
82
78
|
}
|
83
79
|
exports.withOfficialSource = withOfficialSource;
|
84
80
|
/**检查目录是否为项目 */
|
package/package.json
CHANGED
@@ -1,11 +1,11 @@
|
|
1
1
|
{
|
2
2
|
"name": "@zwa73/dev-utils",
|
3
|
-
"version": "1.0.
|
3
|
+
"version": "1.0.13",
|
4
4
|
"description": "编译与调试工具",
|
5
5
|
"main": "index.js",
|
6
6
|
"scripts": {
|
7
7
|
"test": "call npm run compile && jest",
|
8
|
-
"release": "
|
8
|
+
"release": "powershell scripts/release",
|
9
9
|
"compile": "powershell scripts/compile",
|
10
10
|
"watch": "powershell scripts/watch"
|
11
11
|
},
|
package/scripts/compile.ps1
CHANGED
@@ -1,5 +1,5 @@
|
|
1
|
-
Write-Output 开始删除原dist
|
2
|
-
Remove-Item -Recurse -Force dist
|
3
|
-
Write-Output 开始编译
|
4
|
-
tsc -p tsconfig.compile.json
|
1
|
+
Write-Output 开始删除原dist
|
2
|
+
Remove-Item -Recurse -Force dist
|
3
|
+
Write-Output 开始编译
|
4
|
+
tsc -p tsconfig.compile.json
|
5
5
|
tsc-alias -p tsconfig.compile.json
|
package/scripts/watch.ps1
CHANGED
@@ -1,10 +1,10 @@
|
|
1
|
-
# 定义一个函数来运行脚本
|
2
|
-
function New-Script {
|
3
|
-
param($command)
|
4
|
-
# 在后台运行命令
|
5
|
-
Start-Process -NoNewWindow -FilePath "powershell" -ArgumentList "-Command", $command
|
6
|
-
}
|
7
|
-
|
8
|
-
# 开始运行脚本
|
9
|
-
New-Script "tsc -w -p tsconfig.compile.json"
|
1
|
+
# 定义一个函数来运行脚本
|
2
|
+
function New-Script {
|
3
|
+
param($command)
|
4
|
+
# 在后台运行命令
|
5
|
+
Start-Process -NoNewWindow -FilePath "powershell" -ArgumentList "-Command", $command
|
6
|
+
}
|
7
|
+
|
8
|
+
# 开始运行脚本
|
9
|
+
New-Script "tsc -w -p tsconfig.compile.json"
|
10
10
|
New-Script "tsc-alias -w -p tsconfig.compile.json"
|
package/src/Command/Init.ts
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
import * as path from 'path';
|
2
|
-
import {
|
2
|
+
import { SLogger, UtilFT, UtilFunc } from '@zwa73/utils';
|
3
3
|
import * as fs from 'fs';
|
4
|
-
import { DATA_PATH, MIRROR_SOURCE, PROJECT_PATH, checkProject
|
4
|
+
import { DATA_PATH, MIRROR_SOURCE, PROJECT_PATH, checkProject } from './RouteInterface';
|
5
5
|
import { Command } from 'commander';
|
6
6
|
|
7
7
|
|
@@ -25,7 +25,7 @@ async function copyData() {
|
|
25
25
|
/**安装npm包 */
|
26
26
|
async function installPackage() {
|
27
27
|
const install = async (name:string)=>
|
28
|
-
await UtilFunc.exec(`npm i ${name}`);
|
28
|
+
await UtilFunc.exec(`npm i --registry ${MIRROR_SOURCE} ${name}`);
|
29
29
|
const packageList = ['@zwa73/utils'];
|
30
30
|
for(const name of packageList){
|
31
31
|
SLogger.info(`正在安装 ${name}`);
|
@@ -40,10 +40,8 @@ export const CmdInit = (program:Command)=>program
|
|
40
40
|
.action(async (opt) => {
|
41
41
|
checkProject();
|
42
42
|
SLogger.info(`开始初始化设置当前目录 ${PROJECT_PATH}`);
|
43
|
-
await
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
]);
|
48
|
-
});
|
43
|
+
await Promise.all([
|
44
|
+
copyData(),
|
45
|
+
installPackage(),
|
46
|
+
]);
|
49
47
|
});
|
package/src/Command/Release.ts
CHANGED
@@ -2,7 +2,7 @@ import { Command } from "commander";
|
|
2
2
|
import fs from "fs";
|
3
3
|
import path from "path";
|
4
4
|
import { SLogger, UtilFT, UtilFunc, throwError } from "@zwa73/utils";
|
5
|
-
import { PROJECT_PATH, checkProject, withOfficialSource } from "./RouteInterface";
|
5
|
+
import { OFFICIAL_SOURCE, PROJECT_PATH, checkProject, withOfficialSource } from "./RouteInterface";
|
6
6
|
|
7
7
|
/**解析版本号为number数组 */
|
8
8
|
function parseVersion(version: string){
|
@@ -50,16 +50,16 @@ export const CmdRelease = (program: Command) =>program
|
|
50
50
|
.action(async (opt) => {
|
51
51
|
checkProject();
|
52
52
|
SLogger.info(`开始发布项目`);
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
}
|
53
|
+
try {
|
54
|
+
const newVersion = await updateVersion(opt.version);
|
55
|
+
SLogger.info(`新版本号: ${newVersion}`);
|
56
|
+
SLogger.info("正在发布...");
|
57
|
+
const cmd = `npm publish --registry ${OFFICIAL_SOURCE} --access ${opt.access}`;
|
58
|
+
const {stderr,stdout} = await UtilFunc.exec(cmd);
|
59
|
+
if(stderr) SLogger.error(stderr);
|
60
|
+
else SLogger.info(stdout);
|
61
|
+
SLogger.info("发布完成");
|
62
|
+
} catch (error) {
|
63
|
+
SLogger.error(error);
|
64
|
+
}
|
65
65
|
});
|
@@ -1,4 +1,4 @@
|
|
1
|
-
import { SLogger, UtilFT, UtilFunc, throwError } from "@zwa73/utils";
|
1
|
+
import { SLogger, UtilFT, UtilFunc, sleep, throwError } from "@zwa73/utils";
|
2
2
|
import { Command, OptionValues } from "commander";
|
3
3
|
import * as path from 'path';
|
4
4
|
|
@@ -40,11 +40,9 @@ export async function withMirrorSource(func:(()=>any)){
|
|
40
40
|
const OriginSource = out.stdout.trim()//?
|
41
41
|
SLogger.info(`正在修改npm源为 镜像源: ${MIRROR_SOURCE}`);
|
42
42
|
await UtilFunc.exec(`npm config set registry ${MIRROR_SOURCE}`);
|
43
|
-
SLogger.info(`成功修改npm源为 镜像源: ${MIRROR_SOURCE}`);
|
44
43
|
await func();
|
45
44
|
SLogger.info(`正在修改npm源为 原始源: ${OriginSource}`);
|
46
45
|
await UtilFunc.exec(`npm config set registry ${OriginSource}`);
|
47
|
-
SLogger.info(`成功修改npm源为 原始源: ${OriginSource}`);
|
48
46
|
}
|
49
47
|
|
50
48
|
/**在官方源内镜像操作 */
|
@@ -53,11 +51,9 @@ export async function withOfficialSource(func:(()=>any)){
|
|
53
51
|
const OriginSource = out.stdout.trim()//?
|
54
52
|
SLogger.info(`正在修改npm源为 官方源: ${OFFICIAL_SOURCE}`);
|
55
53
|
await UtilFunc.exec(`npm config set registry ${OFFICIAL_SOURCE}`);
|
56
|
-
SLogger.info(`成功修改npm源为 官方源: ${OFFICIAL_SOURCE}`);
|
57
54
|
await func();
|
58
55
|
SLogger.info(`正在修改npm源为 原始源: ${OriginSource}`);
|
59
56
|
await UtilFunc.exec(`npm config set registry ${OriginSource}`);
|
60
|
-
SLogger.info(`成功修改npm源为 原始源: ${OriginSource}`);
|
61
57
|
}
|
62
58
|
|
63
59
|
/**检查目录是否为项目 */
|
package/release.bat
DELETED
package/release.js
DELETED
@@ -1,16 +0,0 @@
|
|
1
|
-
const fs = require('fs');
|
2
|
-
const path = require('path');
|
3
|
-
|
4
|
-
// 读取并更新包配置文件中的版本号
|
5
|
-
function updateVersion() {
|
6
|
-
const packagePath = path.join(__dirname, 'package.json');
|
7
|
-
const packageData = JSON.parse(fs.readFileSync(packagePath));
|
8
|
-
const version = packageData.version.split('.');
|
9
|
-
version[2] = parseInt(version[2]) + 1;
|
10
|
-
packageData.version = version.join('.');
|
11
|
-
fs.writeFileSync(packagePath, JSON.stringify(packageData, null, 2));
|
12
|
-
return packageData.version;
|
13
|
-
}
|
14
|
-
|
15
|
-
|
16
|
-
updateVersion();
|