@zwa73/dev-utils 1.0.83 → 1.0.85

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 CHANGED
@@ -1,5 +1,5 @@
1
- #!/usr/bin/env node
1
+ #!/usr/bin/env node
2
2
 
3
- const {cliRoute} = await import('../dist/mjs/index.js');
3
+ const {cliRoute} = require('../dist/cjs/index.js');
4
4
 
5
5
  cliRoute();
@@ -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(RouteInterface_1.PROJECT_PATH, fileName);
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(dep, devDep) {
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 packageList = ['@zwa73/utils'];
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 devPackList) {
34
+ for (const name of devDepList) {
37
35
  utils_1.SLogger.info(`正在安装 ${name}`);
38
36
  await installdev(name);
39
37
  }
@@ -44,13 +42,19 @@ const CmdGenTemplate = (program) => program
44
42
  .alias("gentemplate")
45
43
  .description("生成项目模板")
46
44
  .argument("<template>", "项目模板 可用 base|electron")
47
- .action(async (templateName) => {
48
- await (0, RouteInterface_1.checkProject)();
49
- const templatePath = pathe_1.default.join(RouteInterface_1.ROOT_PATH, 'template', templateName);
45
+ .requiredOption("-n, --projectName <name>", "项目名称")
46
+ .requiredOption("-d, --projectDescription <description>", "项目描述")
47
+ .requiredOption("-a, --authorName <name>", "作者名")
48
+ .action(async (templateName, opt) => {
49
+ const templatePath = pathe_1.default.join(RouteInterface_1.TEMPLATE_PATH, templateName);
50
50
  if (!await utils_1.UtilFT.pathExists(templatePath))
51
51
  utils_1.SLogger.error(`模板 ${templateName} 不存在`);
52
- await copyData(pathe_1.default.join(RouteInterface_1.ROOT_PATH, 'template', templateName));
53
- await installPackage(['@zwa73/utils'], ['@types/node']);
52
+ const projectPath = pathe_1.default.join(process.cwd(), opt.projectName);
53
+ await utils_1.UtilFT.ensurePathExists(projectPath, { dir: true });
54
+ await copyData(templatePath, projectPath);
55
+ await installPackage(projectPath, ['@zwa73/utils'], ['@types/node']);
56
+ if (await utils_1.UtilFT.pathExists(pathe_1.default.join(projectPath, "gitignore")))
57
+ await fs_1.default.promises.rename(pathe_1.default.join(projectPath, "gitignore"), pathe_1.default.join(projectPath, ".gitignore"));
54
58
  switch (templateName) {
55
59
  case 'base': break;
56
60
  case 'electron': break;
@@ -32,7 +32,7 @@ function checkVersion(oldVersion, newVersion) {
32
32
  }
33
33
  /**更新版本号 */
34
34
  async function updateVersion(newVersion) {
35
- const packagePath = pathe_1.default.join(RouteInterface_1.PROJECT_PATH, "package.json");
35
+ const packagePath = pathe_1.default.join(RouteInterface_1.PROCESS_PATH, "package.json");
36
36
  const packageData = await (0, utils_1.memoize)(utils_1.UtilFT.loadJSONFile)(packagePath);
37
37
  if (newVersion) {
38
38
  checkVersion(packageData.version, newVersion);
@@ -48,7 +48,7 @@ async function updateVersion(newVersion) {
48
48
  }
49
49
  /**获取包名 */
50
50
  async function getPackName() {
51
- const packagePath = pathe_1.default.join(RouteInterface_1.PROJECT_PATH, "package.json");
51
+ const packagePath = pathe_1.default.join(RouteInterface_1.PROCESS_PATH, "package.json");
52
52
  const packageData = await (0, utils_1.memoize)(utils_1.UtilFT.loadJSONFile)(packagePath);
53
53
  return packageData.name
54
54
  .replace(/\//g, '-')
@@ -8,8 +8,8 @@ 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;
11
+ /**当前路径 */
12
+ export declare const PROCESS_PATH: string;
13
13
  /** 检测非浮点的整数类型 */
14
14
  export declare function parseInteger(value: string): number;
15
15
  /** 检测任意数字类型 */
@@ -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.PROJECT_PATH = exports.TEMPLATE_PATH = exports.DATA_PATH = exports.ROOT_PATH = exports.OFFICIAL_SOURCE = exports.MIRROR_SOURCE = void 0;
6
+ exports.PROCESS_PATH = 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,8 @@ 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();
25
+ /**当前路径 */
26
+ exports.PROCESS_PATH = process.cwd();
27
27
  /** 检测非浮点的整数类型 */
28
28
  function parseInteger(value) {
29
29
  const num = Number(value);
@@ -64,7 +64,7 @@ async function withOfficialSource(func) {
64
64
  }
65
65
  /**检查目录是否为项目 */
66
66
  async function checkProject() {
67
- const filePath = pathe_1.default.join(exports.PROJECT_PATH, "package.json");
67
+ const filePath = pathe_1.default.join(exports.PROCESS_PATH, "package.json");
68
68
  if (!(await utils_1.UtilFT.pathExists(filePath)))
69
- (0, utils_1.throwError)(`当前目录: ${exports.PROJECT_PATH} 不是npm项目目录, 请先使用 npm init`);
69
+ (0, utils_1.throwError)(`当前目录: ${exports.PROCESS_PATH} 不是npm项目目录, 请先使用 npm init`);
70
70
  }
@@ -1,14 +1,14 @@
1
1
  import path from 'pathe';
2
- import { checkProject, MIRROR_SOURCE, PROJECT_PATH, ROOT_PATH } from "./RouteInterface.js";
2
+ import { MIRROR_SOURCE, TEMPLATE_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(PROJECT_PATH, fileName);
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(dep, devDep) {
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 packageList = ['@zwa73/utils'];
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 devPackList) {
28
+ for (const name of devDepList) {
31
29
  SLogger.info(`正在安装 ${name}`);
32
30
  await installdev(name);
33
31
  }
@@ -38,13 +36,19 @@ export const CmdGenTemplate = (program) => program
38
36
  .alias("gentemplate")
39
37
  .description("生成项目模板")
40
38
  .argument("<template>", "项目模板 可用 base|electron")
41
- .action(async (templateName) => {
42
- await checkProject();
43
- const templatePath = path.join(ROOT_PATH, 'template', templateName);
39
+ .requiredOption("-n, --projectName <name>", "项目名称")
40
+ .requiredOption("-d, --projectDescription <description>", "项目描述")
41
+ .requiredOption("-a, --authorName <name>", "作者名")
42
+ .action(async (templateName, opt) => {
43
+ const templatePath = path.join(TEMPLATE_PATH, templateName);
44
44
  if (!await UtilFT.pathExists(templatePath))
45
45
  SLogger.error(`模板 ${templateName} 不存在`);
46
- await copyData(path.join(ROOT_PATH, 'template', templateName));
47
- await installPackage(['@zwa73/utils'], ['@types/node']);
46
+ const projectPath = path.join(process.cwd(), opt.projectName);
47
+ await UtilFT.ensurePathExists(projectPath, { dir: true });
48
+ await copyData(templatePath, projectPath);
49
+ await installPackage(projectPath, ['@zwa73/utils'], ['@types/node']);
50
+ if (await UtilFT.pathExists(path.join(projectPath, "gitignore")))
51
+ await fs.promises.rename(path.join(projectPath, "gitignore"), path.join(projectPath, ".gitignore"));
48
52
  switch (templateName) {
49
53
  case 'base': break;
50
54
  case 'electron': break;
@@ -1,6 +1,6 @@
1
1
  import path from 'pathe';
2
2
  import { memoize, SLogger, throwError, UtilFT, UtilFunc } from '@zwa73/utils';
3
- import { checkProject, OFFICIAL_SOURCE, PROJECT_PATH } from './RouteInterface.js';
3
+ import { checkProject, OFFICIAL_SOURCE, PROCESS_PATH } from './RouteInterface.js';
4
4
  import fs from 'fs';
5
5
  /**解析版本号为number数组 */
6
6
  function parseVersion(version) {
@@ -26,7 +26,7 @@ function checkVersion(oldVersion, newVersion) {
26
26
  }
27
27
  /**更新版本号 */
28
28
  async function updateVersion(newVersion) {
29
- const packagePath = path.join(PROJECT_PATH, "package.json");
29
+ const packagePath = path.join(PROCESS_PATH, "package.json");
30
30
  const packageData = await memoize(UtilFT.loadJSONFile)(packagePath);
31
31
  if (newVersion) {
32
32
  checkVersion(packageData.version, newVersion);
@@ -42,7 +42,7 @@ async function updateVersion(newVersion) {
42
42
  }
43
43
  /**获取包名 */
44
44
  async function getPackName() {
45
- const packagePath = path.join(PROJECT_PATH, "package.json");
45
+ const packagePath = path.join(PROCESS_PATH, "package.json");
46
46
  const packageData = await memoize(UtilFT.loadJSONFile)(packagePath);
47
47
  return packageData.name
48
48
  .replace(/\//g, '-')
@@ -8,8 +8,8 @@ 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;
11
+ /**当前路径 */
12
+ export declare const PROCESS_PATH: string;
13
13
  /** 检测非浮点的整数类型 */
14
14
  export declare function parseInteger(value: string): number;
15
15
  /** 检测任意数字类型 */
@@ -10,8 +10,8 @@ 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();
13
+ /**当前路径 */
14
+ export const PROCESS_PATH = process.cwd();
15
15
  /** 检测非浮点的整数类型 */
16
16
  export function parseInteger(value) {
17
17
  const num = Number(value);
@@ -52,7 +52,7 @@ export async function withOfficialSource(func) {
52
52
  }
53
53
  /**检查目录是否为项目 */
54
54
  export async function checkProject() {
55
- const filePath = path.join(PROJECT_PATH, "package.json");
55
+ const filePath = path.join(PROCESS_PATH, "package.json");
56
56
  if (!(await UtilFT.pathExists(filePath)))
57
- throwError(`当前目录: ${PROJECT_PATH} 不是npm项目目录, 请先使用 npm init`);
57
+ throwError(`当前目录: ${PROCESS_PATH} 不是npm项目目录, 请先使用 npm init`);
58
58
  }
package/package.json CHANGED
@@ -1,14 +1,14 @@
1
1
  {
2
2
  "name": "@zwa73/dev-utils",
3
- "version": "1.0.83",
3
+ "version": "1.0.85",
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",