emnj-tool 1.0.4 → 1.1.0

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
+ };
@@ -0,0 +1 @@
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,21 +11,12 @@ 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";
16
+ import { version } from "./constant.js";
15
17
  const program = new Command();
16
18
  const log = console.log;
17
- program.name("项目初始化").description("CLI to Initialize some project").version("0.0.1");
18
- // program
19
- // .command("split")
20
- // .description("Split a string into an array of strings using a separator.")
21
- // .argument("<string>", "The string to split")
22
- // .option("--first", "display just the first substring")
23
- // .option("-s, --separator <char>", "separator character", ",")
24
- // .action((str, options) => {
25
- // console.log("---->> ", options);
26
- // const limit = options.first ? 1 : undefined;
27
- // console.log(str.split(options.separator, limit));
28
- // });
19
+ program.name("项目初始化").description("CLI to Initialize some project").version(version);
29
20
  program
30
21
  .command("init")
31
22
  .description("初始化项目,支持H5,Web等")
@@ -34,7 +25,11 @@ program
34
25
  .action((options) => __awaiter(void 0, void 0, void 0, function* () {
35
26
  // 如果没有配置argument,则第一个参数就是options
36
27
  if (options.h5 === false && options.web === false) {
37
- 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
+ "来初始化项目");
38
33
  process.exit(1);
39
34
  }
40
35
  try {
@@ -43,8 +38,8 @@ program
43
38
  type: "confirm",
44
39
  name: "confirmAction",
45
40
  message: `确认初始化一个${options.h5 ? "H5" : "Web"}工程项目`,
46
- default: true,
47
- },
41
+ default: true
42
+ }
48
43
  ]);
49
44
  if (!confirmAnswers.confirmAction) {
50
45
  const message = "取消初始化";
@@ -56,37 +51,41 @@ program
56
51
  type: "input",
57
52
  name: "name",
58
53
  message: "请输入名称:",
59
- default: "h5-project",
54
+ default: `${options.h5 ? "h5" : "web"}-project`,
60
55
  validate: function (value) {
61
56
  return true;
62
- },
57
+ }
63
58
  },
64
59
  {
65
60
  type: "input",
66
61
  name: "version",
67
62
  message: "请输入版本:",
68
- default: "0.0.1",
63
+ default: "0.0.1"
69
64
  },
70
65
  {
71
66
  type: "input",
72
67
  name: "description",
73
68
  message: "请输入项目描述:",
74
- default: "这是一个H5项目",
69
+ default: `这是一个${options.h5 ? "H5" : "Web"}项目`
75
70
  },
76
71
  {
77
72
  type: "list",
78
73
  name: "language",
79
74
  message: "是否使用typescript",
80
75
  default: true,
81
- choices: ["typescript", "javascript"],
82
- },
76
+ choices: options.h5 ? ["typescript", "javascript"] : ["typescript"]
77
+ }
83
78
  ]);
84
79
  if (options.h5 === true) {
85
80
  const h5 = new CreateH5(actionAnswers);
86
81
  h5.init();
87
82
  }
88
83
  else if (options.web === true) {
89
- log("初始化web项目");
84
+ const web = new CreateWeb(actionAnswers);
85
+ web.init();
86
+ }
87
+ else {
88
+ log(chalk.redBright("暂不支持创建H5和Web之外的项目"));
90
89
  }
91
90
  }
92
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,6 +1,6 @@
1
1
  {
2
2
  "name": "emnj-tool",
3
- "version": "1.0.4",
3
+ "version": "1.1.0",
4
4
  "description": "一个工具,用来初始化项目",
5
5
  "type": "module",
6
6
  "exports": "./index.js",
@@ -31,6 +31,7 @@
31
31
  "chalk": "^5.3.0",
32
32
  "commander": "^12.0.0",
33
33
  "download-git-repo": "^3.0.2",
34
+ "extract-zip": "^2.0.1",
34
35
  "fs-extra": "^11.2.0",
35
36
  "inquirer": "^9.2.16",
36
37
  "unzipper": "^0.10.14"
Binary file
Binary file
Binary file
@@ -0,0 +1 @@
1
+ export declare const version = "0.0.3";
package/types/h5.d.ts ADDED
@@ -0,0 +1,10 @@
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
+ }
@@ -0,0 +1,2 @@
1
+ #! /usr/bin/env node
2
+ export {};
@@ -0,0 +1 @@
1
+ export declare function sum(a: number, b: number): number;
package/README.md DELETED
@@ -1,36 +0,0 @@
1
- # 脚手架工具
2
-
3
- 该脚手架工具的主要目的是为了在新建项目过程摈弃繁琐的的配置,可以直接使用模版进入开发阶段
4
-
5
- ## H5项目
6
-
7
- 目标:快速进入H5项目开发
8
-
9
- 支持:
10
-
11
- 1. 低版本系统支持:iOS系统 >= iOS8,Android系统 >= Android5.0
12
- 2. 支持typescript开发
13
- 3. 使用vue2.7.15版本,并支持Composition API
14
- 4. 使用pinia作为状态库管理
15
-
16
- ## 管理后台项目
17
-
18
- 目标:快速进入管理系统的项目开发
19
-
20
- 支持:
21
-
22
- 1. 使用typescript + vue3.x + pinia + element plus开发
23
- 2. 支持选择使用oa/账号密码进行登录
24
-
25
- ## 如何使用
26
-
27
- ```shell
28
- # 安装emnj-tool
29
- npm install emnj-tool -g
30
-
31
- # 初始化h5项目
32
- emnj-tool init --h5
33
-
34
- # 初始化web项目
35
- emnj-tool init --web
36
- ```
package/dist/package.json DELETED
@@ -1,38 +0,0 @@
1
- {
2
- "name": "emnj-tool",
3
- "version": "1.0.4",
4
- "description": "一个工具,用来初始化项目",
5
- "type": "module",
6
- "exports": "./index.js",
7
- "engines": {
8
- "node": ">=16.0.0"
9
- },
10
- "scripts": {
11
- "test": "echo \"Error: no test specified\" && exit 1",
12
- "build": "npx tsc"
13
- },
14
- "bin": {
15
- "emnj-tool": "./dist/index.js"
16
- },
17
- "keywords": [
18
- "emnj-tool"
19
- ],
20
- "author": "",
21
- "license": "ISC",
22
- "devDependencies": {
23
- "@types/fs-extra": "^11.0.4",
24
- "@types/inquirer": "^9.0.7",
25
- "@types/node": "^20.11.28",
26
- "ts-node": "^10.9.2",
27
- "typescript": "^5.4.2"
28
- },
29
- "dependencies": {
30
- "@types/unzipper": "^0.10.9",
31
- "chalk": "^5.3.0",
32
- "commander": "^12.0.0",
33
- "download-git-repo": "^3.0.2",
34
- "fs-extra": "^11.2.0",
35
- "inquirer": "^9.2.16",
36
- "unzipper": "^0.10.14"
37
- }
38
- }
package/dist/src/h5.js DELETED
@@ -1,54 +0,0 @@
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 * as unzipper from "unzipper";
13
- import { fileURLToPath } from "url";
14
- const log = console.log;
15
- export default class CreateH5 {
16
- constructor(answerOptions) {
17
- this.answerOptions = answerOptions;
18
- }
19
- init() {
20
- return __awaiter(this, void 0, void 0, function* () {
21
- console.log("init h5", this.answerOptions);
22
- const dirPath = yield this.mkdir();
23
- this.unzipH5Template(dirPath);
24
- });
25
- }
26
- mkdir() {
27
- return __awaiter(this, void 0, void 0, function* () {
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
- }
34
- /**
35
- * unzip h5 template to current workspace path
36
- */
37
- 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 });
52
- });
53
- }
54
- }
package/dist/src/index.js DELETED
@@ -1,97 +0,0 @@
1
- #! /usr/bin/env node
2
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
- return new (P || (P = Promise))(function (resolve, reject) {
5
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
- step((generator = generator.apply(thisArg, _arguments || [])).next());
9
- });
10
- };
11
- import { Command } from "commander";
12
- import inquirer from "inquirer";
13
- import CreateH5 from "./h5.js";
14
- import chalk from "chalk";
15
- import pkg from "../package.json";
16
- const program = new Command();
17
- const log = console.log;
18
- program.name("项目初始化").description("CLI to Initialize some project").version(pkg.version);
19
- // program
20
- // .command("split")
21
- // .description("Split a string into an array of strings using a separator.")
22
- // .argument("<string>", "The string to split")
23
- // .option("--first", "display just the first substring")
24
- // .option("-s, --separator <char>", "separator character", ",")
25
- // .action((str, options) => {
26
- // console.log("---->> ", options);
27
- // const limit = options.first ? 1 : undefined;
28
- // console.log(str.split(options.separator, limit));
29
- // });
30
- program
31
- .command("init")
32
- .description("初始化项目,支持H5,Web等")
33
- .option("-h5, --h5", "Initialize an H5 project.", false)
34
- .option("-w, --web", "Initialize a Web project.", false)
35
- .action((options) => __awaiter(void 0, void 0, void 0, function* () {
36
- // 如果没有配置argument,则第一个参数就是options
37
- if (options.h5 === false && options.web === false) {
38
- log("请使用" + chalk.bgBlackBright.bold("emnj init --h5") + "或者" + chalk.bgBlackBright.bold("emnj init --web") + "来初始化项目");
39
- process.exit(1);
40
- }
41
- try {
42
- const confirmAnswers = yield inquirer.prompt([
43
- {
44
- type: "confirm",
45
- name: "confirmAction",
46
- message: `确认初始化一个${options.h5 ? "H5" : "Web"}工程项目`,
47
- default: true,
48
- },
49
- ]);
50
- if (!confirmAnswers.confirmAction) {
51
- const message = "取消初始化";
52
- log(chalk.redBright(message));
53
- throw new Error(message);
54
- }
55
- const actionAnswers = yield inquirer.prompt([
56
- {
57
- type: "input",
58
- name: "name",
59
- message: "请输入名称:",
60
- default: "h5-project",
61
- validate: function (value) {
62
- return true;
63
- },
64
- },
65
- {
66
- type: "input",
67
- name: "version",
68
- message: "请输入版本:",
69
- default: "0.0.1",
70
- },
71
- {
72
- type: "input",
73
- name: "description",
74
- message: "请输入项目描述:",
75
- default: "这是一个H5项目",
76
- },
77
- {
78
- type: "list",
79
- name: "language",
80
- message: "是否使用typescript",
81
- default: true,
82
- choices: ["typescript", "javascript"],
83
- },
84
- ]);
85
- if (options.h5 === true) {
86
- const h5 = new CreateH5(actionAnswers);
87
- h5.init();
88
- }
89
- else if (options.web === true) {
90
- log("初始化web项目");
91
- }
92
- }
93
- catch (error) {
94
- process.exit(1);
95
- }
96
- }));
97
- program.parse(process.argv);
package/dist/src/util.js DELETED
@@ -1,3 +0,0 @@
1
- export function sum(a, b) {
2
- return a + b;
3
- }