emnj-tool 1.0.5 → 1.1.1

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/.eslintignore ADDED
@@ -0,0 +1,5 @@
1
+ # 忽略build目录下类型为js的文件的语法检查
2
+ public/*.js
3
+ public/**/*.js
4
+ dist/*.js
5
+ dist/**/*.js
package/.eslintrc.cjs ADDED
@@ -0,0 +1,19 @@
1
+ /* eslint-env node */
2
+ require("@rushstack/eslint-patch/modern-module-resolution");
3
+
4
+ module.exports = {
5
+ root: true,
6
+ ignorePatterns: ["./public/*/**/*.js"],
7
+ extends: [
8
+ "plugin:vue/essential",
9
+ "eslint:recommended",
10
+ "@vue/eslint-config-typescript/recommended",
11
+ "@vue/eslint-config-prettier"
12
+ ],
13
+ rules: {
14
+ "prettier/prettier": "error",
15
+ "@typescript-eslint/no-empty-interface": "off",
16
+ "@typescript-eslint/no-explicit-any": "off",
17
+ "comma-dangle": ["error", "never"]
18
+ }
19
+ };
package/dist/constant.js CHANGED
@@ -1 +1 @@
1
- export const version = "0.0.3";
1
+ export const version = "0.0.5";
package/dist/h5.js CHANGED
@@ -9,16 +9,17 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
9
9
  };
10
10
  import fse from "fs-extra";
11
11
  import path from "path";
12
- import * as unzipper from "unzipper";
13
12
  import { fileURLToPath } from "url";
14
- const log = console.log;
13
+ import extract from "extract-zip";
14
+ import Tip from "./tips.js";
15
+ import { log } from "console";
16
+ import chalk from "chalk";
15
17
  export default class CreateH5 {
16
18
  constructor(answerOptions) {
17
19
  this.answerOptions = answerOptions;
18
20
  }
19
21
  init() {
20
22
  return __awaiter(this, void 0, void 0, function* () {
21
- console.log("init h5", this.answerOptions);
22
23
  const dirPath = yield this.mkdir();
23
24
  this.unzipH5Template(dirPath);
24
25
  });
@@ -35,20 +36,35 @@ export default class CreateH5 {
35
36
  * unzip h5 template to current workspace path
36
37
  */
37
38
  unzipH5Template(targetDirPath) {
38
- // process.cwd() 获取当前执行node命令时候的文件夹(工作区)目录名
39
- // 获取当前执行文件的目录,即CLI工具的目录
40
- const __filename = fileURLToPath(import.meta.url);
41
- const dirname = path.dirname(__filename);
42
- const templatePath = path.join(dirname, "../templates/ts-h5.zip");
43
- fse
44
- .createReadStream(templatePath)
45
- .pipe(unzipper.Extract({ path: targetDirPath }))
46
- .on("close", () => {
47
- const json = fse.readJSONSync(path.join(targetDirPath, "package.json"), {
48
- encoding: "utf8",
49
- });
50
- const packageJson = Object.assign(Object.assign({}, json), { name: this.answerOptions.name, version: this.answerOptions.version, description: this.answerOptions.description });
51
- fse.writeJSONSync(path.join(targetDirPath, "package.json"), packageJson, { encoding: "utf8", flag: "w", spaces: 2 });
39
+ return __awaiter(this, void 0, void 0, function* () {
40
+ // process.cwd() 获取当前执行node命令时候的文件夹(工作区)目录名
41
+ // 获取当前执行文件的目录,即CLI工具的目录
42
+ const __filename = fileURLToPath(import.meta.url);
43
+ const dirname = path.dirname(__filename);
44
+ let templatePath = path.join(dirname, "../templates/ts-h5.zip");
45
+ if (this.answerOptions.language === "typescript") {
46
+ templatePath = path.join(dirname, "../templates/ts-h5.zip");
47
+ }
48
+ else {
49
+ templatePath = path.join(dirname, "../templates/js-h5.zip");
50
+ }
51
+ try {
52
+ yield extract(templatePath, { dir: targetDirPath });
53
+ const json = fse.readJSONSync(path.join(targetDirPath, "package.json"), {
54
+ encoding: "utf8"
55
+ });
56
+ const packageJson = Object.assign(Object.assign({}, json), { name: this.answerOptions.name, version: this.answerOptions.version, description: this.answerOptions.description });
57
+ fse.writeJSONSync(path.join(targetDirPath, "package.json"), packageJson, {
58
+ encoding: "utf8",
59
+ flag: "w",
60
+ spaces: 2
61
+ });
62
+ const tip = new Tip(this.answerOptions);
63
+ tip.install();
64
+ }
65
+ catch (error) {
66
+ log(chalk.redBright("创建失败"));
67
+ }
52
68
  });
53
69
  }
54
70
  }
package/dist/index.js CHANGED
@@ -11,6 +11,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
11
11
  import { Command } from "commander";
12
12
  import inquirer from "inquirer";
13
13
  import CreateH5 from "./h5.js";
14
+ import CreateWeb from "./web.js";
14
15
  import chalk from "chalk";
15
16
  import { version } from "./constant.js";
16
17
  const program = new Command();
@@ -24,7 +25,11 @@ program
24
25
  .action((options) => __awaiter(void 0, void 0, void 0, function* () {
25
26
  // 如果没有配置argument,则第一个参数就是options
26
27
  if (options.h5 === false && options.web === false) {
27
- log("请使用" + chalk.bgBlackBright.bold("emnj init --h5") + "或者" + chalk.bgBlackBright.bold("emnj init --web") + "来初始化项目");
28
+ log("请使用" +
29
+ chalk.redBright.bold("emnj-tool init --h5") +
30
+ "或者" +
31
+ chalk.redBright.bold("emnj-tool init --web") +
32
+ "来初始化项目");
28
33
  process.exit(1);
29
34
  }
30
35
  try {
@@ -33,8 +38,8 @@ program
33
38
  type: "confirm",
34
39
  name: "confirmAction",
35
40
  message: `确认初始化一个${options.h5 ? "H5" : "Web"}工程项目`,
36
- default: true,
37
- },
41
+ default: true
42
+ }
38
43
  ]);
39
44
  if (!confirmAnswers.confirmAction) {
40
45
  const message = "取消初始化";
@@ -46,37 +51,41 @@ program
46
51
  type: "input",
47
52
  name: "name",
48
53
  message: "请输入名称:",
49
- default: "h5-project",
54
+ default: `${options.h5 ? "h5" : "web"}-project`,
50
55
  validate: function (value) {
51
56
  return true;
52
- },
57
+ }
53
58
  },
54
59
  {
55
60
  type: "input",
56
61
  name: "version",
57
62
  message: "请输入版本:",
58
- default: "0.0.1",
63
+ default: "0.0.1"
59
64
  },
60
65
  {
61
66
  type: "input",
62
67
  name: "description",
63
68
  message: "请输入项目描述:",
64
- default: "这是一个H5项目",
69
+ default: `这是一个${options.h5 ? "H5" : "Web"}项目`
65
70
  },
66
71
  {
67
72
  type: "list",
68
73
  name: "language",
69
74
  message: "是否使用typescript",
70
75
  default: true,
71
- choices: ["typescript", "javascript"],
72
- },
76
+ choices: options.h5 ? ["typescript", "javascript"] : ["typescript"]
77
+ }
73
78
  ]);
74
79
  if (options.h5 === true) {
75
80
  const h5 = new CreateH5(actionAnswers);
76
81
  h5.init();
77
82
  }
78
83
  else if (options.web === true) {
79
- log("初始化web项目");
84
+ const web = new CreateWeb(actionAnswers);
85
+ web.init();
86
+ }
87
+ else {
88
+ log(chalk.redBright("暂不支持创建H5和Web之外的项目"));
80
89
  }
81
90
  }
82
91
  catch (error) {
package/dist/tips.js ADDED
@@ -0,0 +1,14 @@
1
+ import chalk from "chalk";
2
+ const log = console.log;
3
+ export default class Tip {
4
+ constructor(options) {
5
+ this.options = options;
6
+ }
7
+ install() {
8
+ const name = this.options.name;
9
+ log(chalk.greenBright(`🎉 项目 ${name} 创建成功,根据如下步骤初始化`));
10
+ log(chalk.greenBright(`1. cd ${name}`));
11
+ log(chalk.greenBright(`2. pnpm install`));
12
+ log(chalk.greenBright(`3. pnpm run dev`));
13
+ }
14
+ }
package/dist/web.js ADDED
@@ -0,0 +1,59 @@
1
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
2
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
3
+ return new (P || (P = Promise))(function (resolve, reject) {
4
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
5
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
6
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
7
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
8
+ });
9
+ };
10
+ import fse from "fs-extra";
11
+ import path from "path";
12
+ import { fileURLToPath } from "url";
13
+ import extract from "extract-zip";
14
+ import Tip from "./tips.js";
15
+ import { log } from "console";
16
+ import chalk from "chalk";
17
+ export default class CreateWeb {
18
+ constructor(answerOptions) {
19
+ this.answerOptions = answerOptions;
20
+ }
21
+ init() {
22
+ return __awaiter(this, void 0, void 0, function* () {
23
+ const dirPath = yield this.mkdir();
24
+ this.unzipWebTemplate(dirPath);
25
+ });
26
+ }
27
+ mkdir() {
28
+ // create dir in current workspace use option name
29
+ const targetDirPath = path.join(process.cwd(), this.answerOptions.name);
30
+ fse.ensureDirSync(targetDirPath);
31
+ return targetDirPath;
32
+ }
33
+ unzipWebTemplate(targetDirPath) {
34
+ return __awaiter(this, void 0, void 0, function* () {
35
+ // process.cwd() 获取当前执行node命令时候的文件夹(工作区)目录名
36
+ // 获取当前执行文件的目录,即CLI工具的目录
37
+ const __filename = fileURLToPath(import.meta.url);
38
+ const dirname = path.dirname(__filename);
39
+ const templatePath = path.join(dirname, "../templates/ts-web.zip");
40
+ try {
41
+ yield extract(templatePath, { dir: targetDirPath });
42
+ const json = fse.readJSONSync(path.join(targetDirPath, "package.json"), {
43
+ encoding: "utf8"
44
+ });
45
+ const packageJson = Object.assign(Object.assign({}, json), { name: this.answerOptions.name, version: this.answerOptions.version, description: this.answerOptions.description });
46
+ fse.writeJSONSync(path.join(targetDirPath, "package.json"), packageJson, {
47
+ encoding: "utf8",
48
+ flag: "w",
49
+ spaces: 2
50
+ });
51
+ const tip = new Tip(this.answerOptions);
52
+ tip.install();
53
+ }
54
+ catch (error) {
55
+ log(chalk.redBright("创建失败"));
56
+ }
57
+ });
58
+ }
59
+ }
package/package.json CHANGED
@@ -1,15 +1,15 @@
1
1
  {
2
2
  "name": "emnj-tool",
3
- "version": "1.0.5",
4
- "description": "一个工具,用来初始化项目",
3
+ "version": "1.1.1",
4
+ "description": "一个脚手架工具,用来快速初始化创建日常需要的项目",
5
5
  "type": "module",
6
+ "exports": "./index.js",
6
7
  "engines": {
7
8
  "node": ">=16.0.0"
8
9
  },
9
10
  "scripts": {
10
11
  "test": "echo \"Error: no test specified\" && exit 1",
11
- "build": "pnpm run clean && npx tsc",
12
- "clean": "rimraf dist"
12
+ "build": "npx tsc"
13
13
  },
14
14
  "bin": {
15
15
  "emnj-tool": "./dist/index.js"
@@ -17,21 +17,13 @@
17
17
  "keywords": [
18
18
  "emnj-tool"
19
19
  ],
20
- "author": "beyond",
20
+ "author": "",
21
21
  "license": "ISC",
22
22
  "devDependencies": {
23
- "@rollup/plugin-commonjs": "^25.0.7",
24
- "@rollup/plugin-json": "^6.1.0",
25
- "@rollup/plugin-node-resolve": "^15.2.3",
26
- "@rollup/plugin-terser": "^0.4.4",
27
23
  "@types/fs-extra": "^11.0.4",
28
24
  "@types/inquirer": "^9.0.7",
29
25
  "@types/node": "^20.11.28",
30
- "rimraf": "^5.0.7",
31
- "rollup": "^4.17.2",
32
- "rollup-plugin-typescript2": "^0.36.0",
33
26
  "ts-node": "^10.9.2",
34
- "tslib": "^2.6.2",
35
27
  "typescript": "^5.4.2"
36
28
  },
37
29
  "dependencies": {
@@ -39,6 +31,7 @@
39
31
  "chalk": "^5.3.0",
40
32
  "commander": "^12.0.0",
41
33
  "download-git-repo": "^3.0.2",
34
+ "extract-zip": "^2.0.1",
42
35
  "fs-extra": "^11.2.0",
43
36
  "inquirer": "^9.2.16",
44
37
  "unzipper": "^0.10.14"
Binary file
Binary file
Binary file
package/tsconfig.json CHANGED
@@ -1,22 +1,15 @@
1
1
  {
2
2
  "compilerOptions": {
3
- "module": "ES2020", // 或者 "ES2015", "ESNext" 等
4
- "moduleResolution": "node", // 确保模块解析适合Node.js
5
- "target": "es6", // Node.js支持的最低版本
6
- "lib": ["esnext", "dom"],
7
- "strict": true,
3
+ "target": "ES2015",
4
+ "module": "Node16",
5
+ "moduleResolution": "Node16",
8
6
  "esModuleInterop": true,
9
- "outDir": "dist",
10
- "declaration": true,
11
- "declarationDir": "types",
7
+ "strict": true,
8
+ "skipLibCheck": true,
9
+ "forceConsistentCasingInFileNames": true,
12
10
  "resolveJsonModule": true,
13
- "jsx": "preserve",
14
- "jsxImportSource": "vue",
15
- "allowJs": true,
16
- "baseUrl": "./",
17
- "paths": {},
18
- "types": []
11
+ "outDir": "./dist",
12
+ "typeRoots": ["./node_modules/@types", "./src/types"]
19
13
  },
20
- "include": ["src/**/*.js", "src/**/*.ts"],
21
- "exclude": ["node_modules", "build", "dist", "example", "rollup.config.js"]
14
+ "include": ["src/**/*.ts"]
22
15
  }
package/types/src/h5.d.ts DELETED
@@ -1,10 +0,0 @@
1
- export default class CreateH5 {
2
- private answerOptions;
3
- constructor(answerOptions: InquirerPromptQuestions);
4
- init(): Promise<void>;
5
- mkdir(): Promise<string>;
6
- /**
7
- * unzip h5 template to current workspace path
8
- */
9
- unzipH5Template(targetDirPath: string): void;
10
- }
@@ -1,2 +0,0 @@
1
- #! /usr/bin/env node
2
- export {};
@@ -1 +0,0 @@
1
- export declare function sum(a: number, b: number): number;