@zwa73/dev-utils 1.0.83 → 1.0.84
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/bin/cli +2 -2
- package/dist/cjs/Command/GenTemplate.js +14 -13
- package/dist/cjs/Command/RouteInterface.d.ts +0 -2
- package/dist/cjs/Command/RouteInterface.js +3 -5
- package/dist/mjs/Command/GenTemplate.js +15 -14
- package/dist/mjs/Command/RouteInterface.d.ts +0 -2
- package/dist/mjs/Command/RouteInterface.js +2 -4
- package/package.json +2 -2
package/bin/cli
CHANGED
@@ -9,12 +9,12 @@ const RouteInterface_1 = require("./RouteInterface");
|
|
9
9
|
const utils_1 = require("@zwa73/utils");
|
10
10
|
const fs_1 = __importDefault(require("fs"));
|
11
11
|
/**复制基础文件 */
|
12
|
-
async function copyData(templatePath) {
|
12
|
+
async function copyData(templatePath, projectPath) {
|
13
13
|
const filelist = await fs_1.default.promises.readdir(templatePath);
|
14
14
|
const plist = filelist.map(async (fileName) => {
|
15
15
|
utils_1.SLogger.info(`正在复制 ${fileName}`);
|
16
16
|
const filePath = pathe_1.default.join(templatePath, fileName);
|
17
|
-
const targetPath = pathe_1.default.join(
|
17
|
+
const targetPath = pathe_1.default.join(projectPath, fileName);
|
18
18
|
if (!await utils_1.UtilFT.pathExists(targetPath))
|
19
19
|
await fs_1.default.promises.cp(filePath, targetPath, { recursive: true });
|
20
20
|
else
|
@@ -24,16 +24,14 @@ async function copyData(templatePath) {
|
|
24
24
|
await Promise.all(plist);
|
25
25
|
}
|
26
26
|
/**安装npm包 */
|
27
|
-
async function installPackage(
|
28
|
-
const install = async (name) => await utils_1.UtilFunc.exec(`npm i --registry ${RouteInterface_1.MIRROR_SOURCE} ${name}
|
29
|
-
const installdev = async (name) => await utils_1.UtilFunc.exec(`npm i --registry ${RouteInterface_1.MIRROR_SOURCE} --save-dev ${name}
|
30
|
-
const
|
31
|
-
const devPackList = ['@types/node'];
|
32
|
-
for (const name of packageList) {
|
27
|
+
async function installPackage(projectPath, depList, devDepList) {
|
28
|
+
const install = async (name) => await utils_1.UtilFunc.exec(`npm i --registry ${RouteInterface_1.MIRROR_SOURCE} ${name}`, { cwd: projectPath });
|
29
|
+
const installdev = async (name) => await utils_1.UtilFunc.exec(`npm i --registry ${RouteInterface_1.MIRROR_SOURCE} --save-dev ${name}`, { cwd: projectPath });
|
30
|
+
for (const name of depList) {
|
33
31
|
utils_1.SLogger.info(`正在安装 ${name}`);
|
34
32
|
await install(name);
|
35
33
|
}
|
36
|
-
for (const name of
|
34
|
+
for (const name of devDepList) {
|
37
35
|
utils_1.SLogger.info(`正在安装 ${name}`);
|
38
36
|
await installdev(name);
|
39
37
|
}
|
@@ -44,13 +42,16 @@ const CmdGenTemplate = (program) => program
|
|
44
42
|
.alias("gentemplate")
|
45
43
|
.description("生成项目模板")
|
46
44
|
.argument("<template>", "项目模板 可用 base|electron")
|
47
|
-
.
|
48
|
-
|
45
|
+
.requiredOption("-n, --projectName <name>", "项目名称")
|
46
|
+
.requiredOption("-d, --projectDescription <description>", "项目描述")
|
47
|
+
.requiredOption("-a, --authorName <name>", "作者名")
|
48
|
+
.action(async (templateName, opt) => {
|
49
49
|
const templatePath = pathe_1.default.join(RouteInterface_1.ROOT_PATH, 'template', templateName);
|
50
50
|
if (!await utils_1.UtilFT.pathExists(templatePath))
|
51
51
|
utils_1.SLogger.error(`模板 ${templateName} 不存在`);
|
52
|
-
|
53
|
-
await
|
52
|
+
const projectPath = pathe_1.default.join(process.cwd(), opt.projectName);
|
53
|
+
await copyData(pathe_1.default.join(RouteInterface_1.ROOT_PATH, 'template', templateName), projectPath);
|
54
|
+
await installPackage(projectPath, ['@zwa73/utils'], ['@types/node']);
|
54
55
|
switch (templateName) {
|
55
56
|
case 'base': break;
|
56
57
|
case 'electron': break;
|
@@ -8,8 +8,6 @@ export declare const ROOT_PATH: string;
|
|
8
8
|
export declare const DATA_PATH: string;
|
9
9
|
/**template文件夹路径 */
|
10
10
|
export declare const TEMPLATE_PATH: string;
|
11
|
-
/**项目路径 */
|
12
|
-
export declare const PROJECT_PATH: string;
|
13
11
|
/** 检测非浮点的整数类型 */
|
14
12
|
export declare function parseInteger(value: string): number;
|
15
13
|
/** 检测任意数字类型 */
|
@@ -3,7 +3,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
4
4
|
};
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
6
|
-
exports.
|
6
|
+
exports.TEMPLATE_PATH = exports.DATA_PATH = exports.ROOT_PATH = exports.OFFICIAL_SOURCE = exports.MIRROR_SOURCE = void 0;
|
7
7
|
exports.parseInteger = parseInteger;
|
8
8
|
exports.parseNumber = parseNumber;
|
9
9
|
exports.parseBoolean = parseBoolean;
|
@@ -22,8 +22,6 @@ exports.ROOT_PATH = pathe_1.default.join(__dirname, '..', '..', '..');
|
|
22
22
|
exports.DATA_PATH = pathe_1.default.join(exports.ROOT_PATH, 'data');
|
23
23
|
/**template文件夹路径 */
|
24
24
|
exports.TEMPLATE_PATH = pathe_1.default.join(exports.DATA_PATH, 'template');
|
25
|
-
/**项目路径 */
|
26
|
-
exports.PROJECT_PATH = process.cwd();
|
27
25
|
/** 检测非浮点的整数类型 */
|
28
26
|
function parseInteger(value) {
|
29
27
|
const num = Number(value);
|
@@ -64,7 +62,7 @@ async function withOfficialSource(func) {
|
|
64
62
|
}
|
65
63
|
/**检查目录是否为项目 */
|
66
64
|
async function checkProject() {
|
67
|
-
const filePath = pathe_1.default.join(
|
65
|
+
const filePath = pathe_1.default.join(process.cwd(), "package.json");
|
68
66
|
if (!(await utils_1.UtilFT.pathExists(filePath)))
|
69
|
-
(0, utils_1.throwError)(`当前目录: ${
|
67
|
+
(0, utils_1.throwError)(`当前目录: ${process.cwd()} 不是npm项目目录, 请先使用 npm init`);
|
70
68
|
}
|
@@ -1,14 +1,14 @@
|
|
1
1
|
import path from 'pathe';
|
2
|
-
import {
|
2
|
+
import { MIRROR_SOURCE, ROOT_PATH } from "./RouteInterface.js";
|
3
3
|
import { SLogger, UtilFT, UtilFunc } from "@zwa73/utils";
|
4
4
|
import fs from 'fs';
|
5
5
|
/**复制基础文件 */
|
6
|
-
async function copyData(templatePath) {
|
6
|
+
async function copyData(templatePath, projectPath) {
|
7
7
|
const filelist = await fs.promises.readdir(templatePath);
|
8
8
|
const plist = filelist.map(async (fileName) => {
|
9
9
|
SLogger.info(`正在复制 ${fileName}`);
|
10
10
|
const filePath = path.join(templatePath, fileName);
|
11
|
-
const targetPath = path.join(
|
11
|
+
const targetPath = path.join(projectPath, fileName);
|
12
12
|
if (!await UtilFT.pathExists(targetPath))
|
13
13
|
await fs.promises.cp(filePath, targetPath, { recursive: true });
|
14
14
|
else
|
@@ -18,16 +18,14 @@ async function copyData(templatePath) {
|
|
18
18
|
await Promise.all(plist);
|
19
19
|
}
|
20
20
|
/**安装npm包 */
|
21
|
-
async function installPackage(
|
22
|
-
const install = async (name) => await UtilFunc.exec(`npm i --registry ${MIRROR_SOURCE} ${name}
|
23
|
-
const installdev = async (name) => await UtilFunc.exec(`npm i --registry ${MIRROR_SOURCE} --save-dev ${name}
|
24
|
-
const
|
25
|
-
const devPackList = ['@types/node'];
|
26
|
-
for (const name of packageList) {
|
21
|
+
async function installPackage(projectPath, depList, devDepList) {
|
22
|
+
const install = async (name) => await UtilFunc.exec(`npm i --registry ${MIRROR_SOURCE} ${name}`, { cwd: projectPath });
|
23
|
+
const installdev = async (name) => await UtilFunc.exec(`npm i --registry ${MIRROR_SOURCE} --save-dev ${name}`, { cwd: projectPath });
|
24
|
+
for (const name of depList) {
|
27
25
|
SLogger.info(`正在安装 ${name}`);
|
28
26
|
await install(name);
|
29
27
|
}
|
30
|
-
for (const name of
|
28
|
+
for (const name of devDepList) {
|
31
29
|
SLogger.info(`正在安装 ${name}`);
|
32
30
|
await installdev(name);
|
33
31
|
}
|
@@ -38,13 +36,16 @@ export const CmdGenTemplate = (program) => program
|
|
38
36
|
.alias("gentemplate")
|
39
37
|
.description("生成项目模板")
|
40
38
|
.argument("<template>", "项目模板 可用 base|electron")
|
41
|
-
.
|
42
|
-
|
39
|
+
.requiredOption("-n, --projectName <name>", "项目名称")
|
40
|
+
.requiredOption("-d, --projectDescription <description>", "项目描述")
|
41
|
+
.requiredOption("-a, --authorName <name>", "作者名")
|
42
|
+
.action(async (templateName, opt) => {
|
43
43
|
const templatePath = path.join(ROOT_PATH, 'template', templateName);
|
44
44
|
if (!await UtilFT.pathExists(templatePath))
|
45
45
|
SLogger.error(`模板 ${templateName} 不存在`);
|
46
|
-
|
47
|
-
await
|
46
|
+
const projectPath = path.join(process.cwd(), opt.projectName);
|
47
|
+
await copyData(path.join(ROOT_PATH, 'template', templateName), projectPath);
|
48
|
+
await installPackage(projectPath, ['@zwa73/utils'], ['@types/node']);
|
48
49
|
switch (templateName) {
|
49
50
|
case 'base': break;
|
50
51
|
case 'electron': break;
|
@@ -8,8 +8,6 @@ export declare const ROOT_PATH: string;
|
|
8
8
|
export declare const DATA_PATH: string;
|
9
9
|
/**template文件夹路径 */
|
10
10
|
export declare const TEMPLATE_PATH: string;
|
11
|
-
/**项目路径 */
|
12
|
-
export declare const PROJECT_PATH: string;
|
13
11
|
/** 检测非浮点的整数类型 */
|
14
12
|
export declare function parseInteger(value: string): number;
|
15
13
|
/** 检测任意数字类型 */
|
@@ -10,8 +10,6 @@ export const ROOT_PATH = path.join(`${process.platform === 'win32' ? '' : '/'}${
|
|
10
10
|
export const DATA_PATH = path.join(ROOT_PATH, 'data');
|
11
11
|
/**template文件夹路径 */
|
12
12
|
export const TEMPLATE_PATH = path.join(DATA_PATH, 'template');
|
13
|
-
/**项目路径 */
|
14
|
-
export const PROJECT_PATH = process.cwd();
|
15
13
|
/** 检测非浮点的整数类型 */
|
16
14
|
export function parseInteger(value) {
|
17
15
|
const num = Number(value);
|
@@ -52,7 +50,7 @@ export async function withOfficialSource(func) {
|
|
52
50
|
}
|
53
51
|
/**检查目录是否为项目 */
|
54
52
|
export async function checkProject() {
|
55
|
-
const filePath = path.join(
|
53
|
+
const filePath = path.join(process.cwd(), "package.json");
|
56
54
|
if (!(await UtilFT.pathExists(filePath)))
|
57
|
-
throwError(`当前目录: ${
|
55
|
+
throwError(`当前目录: ${process.cwd()} 不是npm项目目录, 请先使用 npm init`);
|
58
56
|
}
|
package/package.json
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
{
|
2
2
|
"name": "@zwa73/dev-utils",
|
3
|
-
"version": "1.0.
|
3
|
+
"version": "1.0.84",
|
4
4
|
"description": "编译与调试工具",
|
5
|
-
"type": "module",
|
6
5
|
"exports": {
|
7
6
|
".": {
|
8
7
|
"require": "./dist/cjs/index.js",
|
9
8
|
"import": "./dist/mjs/index.js"
|
10
9
|
}
|
11
10
|
},
|
11
|
+
"types": "./dist/mjs/index.d.ts",
|
12
12
|
"scripts": {
|
13
13
|
"test": "jest",
|
14
14
|
"release": "powershell scripts/release",
|