@zwa73/dev-utils 1.0.82 → 1.0.83

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.
@@ -7,6 +7,37 @@ exports.CmdGenTemplate = void 0;
7
7
  const pathe_1 = __importDefault(require("pathe"));
8
8
  const RouteInterface_1 = require("./RouteInterface");
9
9
  const utils_1 = require("@zwa73/utils");
10
+ const fs_1 = __importDefault(require("fs"));
11
+ /**复制基础文件 */
12
+ async function copyData(templatePath) {
13
+ const filelist = await fs_1.default.promises.readdir(templatePath);
14
+ const plist = filelist.map(async (fileName) => {
15
+ utils_1.SLogger.info(`正在复制 ${fileName}`);
16
+ const filePath = pathe_1.default.join(templatePath, fileName);
17
+ const targetPath = pathe_1.default.join(RouteInterface_1.PROJECT_PATH, fileName);
18
+ if (!await utils_1.UtilFT.pathExists(targetPath))
19
+ await fs_1.default.promises.cp(filePath, targetPath, { recursive: true });
20
+ else
21
+ utils_1.SLogger.info(`${fileName} 已存在 跳过`);
22
+ return null;
23
+ });
24
+ await Promise.all(plist);
25
+ }
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) {
33
+ utils_1.SLogger.info(`正在安装 ${name}`);
34
+ await install(name);
35
+ }
36
+ for (const name of devPackList) {
37
+ utils_1.SLogger.info(`正在安装 ${name}`);
38
+ await installdev(name);
39
+ }
40
+ }
10
41
  /**生成schema */
11
42
  const CmdGenTemplate = (program) => program
12
43
  .command("Gen-Template")
@@ -14,12 +45,15 @@ const CmdGenTemplate = (program) => program
14
45
  .description("生成项目模板")
15
46
  .argument("<template>", "项目模板 可用 base|electron")
16
47
  .action(async (templateName) => {
17
- const yeoman = (await utils_1.UtilFunc.dynamicImport("yeoman-environment")).default;
18
- const env = new yeoman();
19
- const namespace = `utildt:${templateName}`;
20
- // 注册生成器
21
- env.register(pathe_1.default.join(RouteInterface_1.ROOT_PATH, "dist", "mjs", "Generator", templateName, "index.js"), { namespace });
22
- // 运行生成器
23
- env.run([namespace], {});
48
+ await (0, RouteInterface_1.checkProject)();
49
+ const templatePath = pathe_1.default.join(RouteInterface_1.ROOT_PATH, 'template', templateName);
50
+ if (!await utils_1.UtilFT.pathExists(templatePath))
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']);
54
+ switch (templateName) {
55
+ case 'base': break;
56
+ case 'electron': break;
57
+ }
24
58
  });
25
59
  exports.CmdGenTemplate = CmdGenTemplate;
@@ -1,6 +1,37 @@
1
1
  import path from 'pathe';
2
- import { ROOT_PATH } from "./RouteInterface.js";
3
- import { UtilFunc } from "@zwa73/utils";
2
+ import { checkProject, MIRROR_SOURCE, PROJECT_PATH, ROOT_PATH } from "./RouteInterface.js";
3
+ import { SLogger, UtilFT, UtilFunc } from "@zwa73/utils";
4
+ import fs from 'fs';
5
+ /**复制基础文件 */
6
+ async function copyData(templatePath) {
7
+ const filelist = await fs.promises.readdir(templatePath);
8
+ const plist = filelist.map(async (fileName) => {
9
+ SLogger.info(`正在复制 ${fileName}`);
10
+ const filePath = path.join(templatePath, fileName);
11
+ const targetPath = path.join(PROJECT_PATH, fileName);
12
+ if (!await UtilFT.pathExists(targetPath))
13
+ await fs.promises.cp(filePath, targetPath, { recursive: true });
14
+ else
15
+ SLogger.info(`${fileName} 已存在 跳过`);
16
+ return null;
17
+ });
18
+ await Promise.all(plist);
19
+ }
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) {
27
+ SLogger.info(`正在安装 ${name}`);
28
+ await install(name);
29
+ }
30
+ for (const name of devPackList) {
31
+ SLogger.info(`正在安装 ${name}`);
32
+ await installdev(name);
33
+ }
34
+ }
4
35
  /**生成schema */
5
36
  export const CmdGenTemplate = (program) => program
6
37
  .command("Gen-Template")
@@ -8,11 +39,14 @@ export const CmdGenTemplate = (program) => program
8
39
  .description("生成项目模板")
9
40
  .argument("<template>", "项目模板 可用 base|electron")
10
41
  .action(async (templateName) => {
11
- const yeoman = (await UtilFunc.dynamicImport("yeoman-environment")).default;
12
- const env = new yeoman();
13
- const namespace = `utildt:${templateName}`;
14
- // 注册生成器
15
- env.register(path.join(ROOT_PATH, "dist", "mjs", "Generator", templateName, "index.js"), { namespace });
16
- // 运行生成器
17
- env.run([namespace], {});
42
+ await checkProject();
43
+ const templatePath = path.join(ROOT_PATH, 'template', templateName);
44
+ if (!await UtilFT.pathExists(templatePath))
45
+ SLogger.error(`模板 ${templateName} 不存在`);
46
+ await copyData(path.join(ROOT_PATH, 'template', templateName));
47
+ await installPackage(['@zwa73/utils'], ['@types/node']);
48
+ switch (templateName) {
49
+ case 'base': break;
50
+ case 'electron': break;
51
+ }
18
52
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@zwa73/dev-utils",
3
- "version": "1.0.82",
3
+ "version": "1.0.83",
4
4
  "description": "编译与调试工具",
5
5
  "type": "module",
6
6
  "exports": {
@@ -28,9 +28,7 @@
28
28
  "ts-morph": "^23.0.0",
29
29
  "ts-node": "^10.9.2",
30
30
  "tsconfig-paths": "^4.2.0",
31
- "typescript-json-schema": "^0.64.0",
32
- "yeoman-environment": "^4.4.3",
33
- "yeoman-generator": "^7.4.0"
31
+ "typescript-json-schema": "^0.64.0"
34
32
  },
35
33
  "devDependencies": {
36
34
  "@types/jest": "^29.5.12",
@@ -1,2 +0,0 @@
1
- import Generator from "yeoman-generator";
2
- export declare const generatorBuilder: (templateName: string) => (new () => Generator);
@@ -1,65 +0,0 @@
1
- "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.generatorBuilder = void 0;
7
- const RouteInterface_1 = require("../Command/RouteInterface");
8
- const yeoman_generator_1 = __importDefault(require("yeoman-generator"));
9
- const fs_1 = __importDefault(require("fs"));
10
- const pathe_1 = __importDefault(require("pathe"));
11
- const utils_1 = require("@zwa73/utils");
12
- const generatorBuilder = (templateName) => class extends yeoman_generator_1.default {
13
- answers = {};
14
- // 提示用户输入
15
- async prompting() {
16
- this.answers = await this.prompt([
17
- {
18
- type: "input",
19
- name: "projectName",
20
- message: "项目名称",
21
- default: this.appname,
22
- },
23
- {
24
- type: "input",
25
- name: "projectDescription",
26
- message: "项目描述",
27
- default: "A new project",
28
- },
29
- {
30
- type: "input",
31
- name: "authorName",
32
- message: "作者名",
33
- default: "Your Name",
34
- },
35
- ]);
36
- }
37
- // 写入文件
38
- writing() {
39
- this.fs.copyTpl(this.templatePath(`${RouteInterface_1.TEMPLATE_PATH}/${templateName}/package.json`), this.destinationPath(`${this.answers.projectName}/package.json`), this.answers);
40
- this.fs.copyTpl(this.templatePath(`${RouteInterface_1.TEMPLATE_PATH}/${templateName}/**/*`), this.destinationPath(this.answers.projectName), this.answers);
41
- }
42
- // 生成结束
43
- async end() {
44
- const dependencies = ['@zwa73/utils'];
45
- const devDependencies = ['@types/node'];
46
- await this.spawn('npm', ['install', ...dependencies, `--registry=${RouteInterface_1.MIRROR_SOURCE}`], {
47
- cwd: this.destinationPath(this.answers.projectName),
48
- stdio: 'inherit'
49
- });
50
- await this.spawn('npm', ['install', ...devDependencies, `--registry=${RouteInterface_1.MIRROR_SOURCE}`, '--save-dev'], {
51
- cwd: this.destinationPath(this.answers.projectName),
52
- stdio: 'inherit'
53
- });
54
- // 重命名 gitignore 文件为 .gitignore
55
- const projectPath = this.destinationPath(this.answers.projectName);
56
- const gitignorePath = pathe_1.default.join(projectPath, 'gitignore');
57
- const dotGitignorePath = pathe_1.default.join(projectPath, '.gitignore');
58
- if (await utils_1.UtilFT.pathExists(gitignorePath)) {
59
- fs_1.default.promises.rename(gitignorePath, dotGitignorePath);
60
- this.log('gitignore 文件已重命名为 .gitignore');
61
- }
62
- this.log("All done!");
63
- }
64
- };
65
- exports.generatorBuilder = generatorBuilder;
@@ -1,3 +0,0 @@
1
- import Generator from "yeoman-generator";
2
- declare const _default: new () => Generator;
3
- export default _default;
@@ -1,4 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- const Common_1 = require("../Common");
4
- exports.default = (0, Common_1.generatorBuilder)('base');
@@ -1,3 +0,0 @@
1
- import Generator from "yeoman-generator";
2
- declare const _default: new () => Generator;
3
- export default _default;
@@ -1,4 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- const Common_1 = require("../Common");
4
- exports.default = (0, Common_1.generatorBuilder)('electron');
@@ -1,2 +0,0 @@
1
- import Generator from "yeoman-generator";
2
- export declare const generatorBuilder: (templateName: string) => (new () => Generator);
@@ -1,58 +0,0 @@
1
- import { MIRROR_SOURCE, TEMPLATE_PATH } from "../Command/RouteInterface.js";
2
- import Generator from "yeoman-generator";
3
- import fs from 'fs';
4
- import path from 'pathe';
5
- import { UtilFT } from "@zwa73/utils";
6
- export const generatorBuilder = (templateName) => class extends Generator {
7
- answers = {};
8
- // 提示用户输入
9
- async prompting() {
10
- this.answers = await this.prompt([
11
- {
12
- type: "input",
13
- name: "projectName",
14
- message: "项目名称",
15
- default: this.appname,
16
- },
17
- {
18
- type: "input",
19
- name: "projectDescription",
20
- message: "项目描述",
21
- default: "A new project",
22
- },
23
- {
24
- type: "input",
25
- name: "authorName",
26
- message: "作者名",
27
- default: "Your Name",
28
- },
29
- ]);
30
- }
31
- // 写入文件
32
- writing() {
33
- this.fs.copyTpl(this.templatePath(`${TEMPLATE_PATH}/${templateName}/package.json`), this.destinationPath(`${this.answers.projectName}/package.json`), this.answers);
34
- this.fs.copyTpl(this.templatePath(`${TEMPLATE_PATH}/${templateName}/**/*`), this.destinationPath(this.answers.projectName), this.answers);
35
- }
36
- // 生成结束
37
- async end() {
38
- const dependencies = ['@zwa73/utils'];
39
- const devDependencies = ['@types/node'];
40
- await this.spawn('npm', ['install', ...dependencies, `--registry=${MIRROR_SOURCE}`], {
41
- cwd: this.destinationPath(this.answers.projectName),
42
- stdio: 'inherit'
43
- });
44
- await this.spawn('npm', ['install', ...devDependencies, `--registry=${MIRROR_SOURCE}`, '--save-dev'], {
45
- cwd: this.destinationPath(this.answers.projectName),
46
- stdio: 'inherit'
47
- });
48
- // 重命名 gitignore 文件为 .gitignore
49
- const projectPath = this.destinationPath(this.answers.projectName);
50
- const gitignorePath = path.join(projectPath, 'gitignore');
51
- const dotGitignorePath = path.join(projectPath, '.gitignore');
52
- if (await UtilFT.pathExists(gitignorePath)) {
53
- fs.promises.rename(gitignorePath, dotGitignorePath);
54
- this.log('gitignore 文件已重命名为 .gitignore');
55
- }
56
- this.log("All done!");
57
- }
58
- };
@@ -1,3 +0,0 @@
1
- import Generator from "yeoman-generator";
2
- declare const _default: new () => Generator;
3
- export default _default;
@@ -1,2 +0,0 @@
1
- import { generatorBuilder } from "../Common.js";
2
- export default generatorBuilder('base');
@@ -1,3 +0,0 @@
1
- import Generator from "yeoman-generator";
2
- declare const _default: new () => Generator;
3
- export default _default;
@@ -1,2 +0,0 @@
1
- import { generatorBuilder } from "../Common.js";
2
- export default generatorBuilder('electron');