emnj-tool 1.0.2 → 1.0.3

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/README.md ADDED
@@ -0,0 +1,36 @@
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/h5.js ADDED
@@ -0,0 +1,54 @@
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/index.js CHANGED
@@ -1,42 +1,44 @@
1
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
+ };
2
11
  import { Command } from "commander";
3
12
  import inquirer from "inquirer";
4
- import InitH5 from "./h5/h5.js";
13
+ import CreateH5 from "./h5.js";
5
14
  import chalk from "chalk";
6
15
  const program = new Command();
7
16
  const log = console.log;
8
- program
9
- .name("project cli")
10
- .description("CLI to Initialize some project")
11
- .version("0.0.1");
12
- program
13
- .command("split")
14
- .description("Split a string into an array of strings using a separator.")
15
- .argument("<string>", "The string to split")
16
- .option("--first", "display just the first substring")
17
- .option("-s, --separator <char>", "separator character", ",")
18
- .action((str, options) => {
19
- console.log("---->> ", options);
20
- const limit = options.first ? 1 : undefined;
21
- console.log(str.split(options.separator, limit));
22
- });
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
+ // });
23
29
  program
24
30
  .command("init")
25
31
  .description("初始化项目,支持H5,Web等")
26
32
  .option("-h5, --h5", "Initialize an H5 project.", false)
27
33
  .option("-w, --web", "Initialize a Web project.", false)
28
- .action(async (options) => {
34
+ .action((options) => __awaiter(void 0, void 0, void 0, function* () {
29
35
  // 如果没有配置argument,则第一个参数就是options
30
36
  if (options.h5 === false && options.web === false) {
31
- log("请使用" +
32
- chalk.bgRed.bold("emnj init --h5") +
33
- "或者" +
34
- chalk.bgRed.bold("emnj init --web") +
35
- "来初始化项目");
37
+ log("请使用" + chalk.bgBlackBright.bold("emnj init --h5") + "或者" + chalk.bgBlackBright.bold("emnj init --web") + "来初始化项目");
36
38
  process.exit(1);
37
39
  }
38
40
  try {
39
- const confirmAnswers = await inquirer.prompt([
41
+ const confirmAnswers = yield inquirer.prompt([
40
42
  {
41
43
  type: "confirm",
42
44
  name: "confirmAction",
@@ -49,7 +51,7 @@ program
49
51
  log(chalk.redBright(message));
50
52
  throw new Error(message);
51
53
  }
52
- const actionAnswers = await inquirer.prompt([
54
+ const actionAnswers = yield inquirer.prompt([
53
55
  {
54
56
  type: "input",
55
57
  name: "name",
@@ -80,17 +82,15 @@ program
80
82
  },
81
83
  ]);
82
84
  if (options.h5 === true) {
83
- const initH5 = new InitH5(actionAnswers);
84
- initH5.init();
85
- return;
85
+ const h5 = new CreateH5(actionAnswers);
86
+ h5.init();
86
87
  }
87
- if (options.web === true) {
88
+ else if (options.web === true) {
88
89
  log("初始化web项目");
89
- return;
90
90
  }
91
91
  }
92
92
  catch (error) {
93
93
  process.exit(1);
94
94
  }
95
- });
95
+ }));
96
96
  program.parse(process.argv);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "emnj-tool",
3
- "version": "1.0.2",
3
+ "version": "1.0.3",
4
4
  "description": "一个工具,用来初始化项目",
5
5
  "type": "module",
6
6
  "exports": "./index.js",
@@ -14,7 +14,9 @@
14
14
  "bin": {
15
15
  "emnj-tool": "./dist/index.js"
16
16
  },
17
- "keywords": [],
17
+ "keywords": [
18
+ "emnj-tool"
19
+ ],
18
20
  "author": "",
19
21
  "license": "ISC",
20
22
  "devDependencies": {
Binary file
package/tsconfig.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "compilerOptions": {
3
- "target": "ESNext",
3
+ "target": "ES2015",
4
4
  "module": "Node16",
5
5
  "moduleResolution": "Node16",
6
6
  "esModuleInterop": true,
package/dist/h5/h5.js DELETED
@@ -1,43 +0,0 @@
1
- import fse from "fs-extra";
2
- import path from "path";
3
- import unzipper from "unzipper";
4
- export default class InitH5 {
5
- answerOptions;
6
- constructor(answerOptions) {
7
- this.answerOptions = answerOptions;
8
- }
9
- init() {
10
- console.log("init h5", this.answerOptions);
11
- this.mkdir();
12
- }
13
- async mkdir() {
14
- // create dir in current workspace use option name
15
- const targetDirPath = path.join(process.cwd(), this.answerOptions.name);
16
- fse.ensureDirSync(targetDirPath);
17
- this.unzipH5Template(targetDirPath);
18
- }
19
- /**
20
- * unzip h5 template to current workspace path
21
- */
22
- unzipH5Template(targetDirPath) {
23
- // process.cwd() 获取当前执行node命令时候的文件夹(工作区)目录名
24
- // 获取当前执行文件的目录,即CLI工具的目录
25
- const rootDir = __dirname;
26
- const templatePath = path.join(rootDir, "./templates/ts-h5.zip");
27
- fse
28
- .createReadStream(templatePath)
29
- .pipe(unzipper.Extract({ path: targetDirPath }))
30
- .on("close", () => {
31
- const json = fse.readJSONSync(path.join(targetDirPath, "package.json"), {
32
- encoding: "utf8",
33
- });
34
- const packageJson = {
35
- ...json,
36
- name: this.answerOptions.name,
37
- version: this.answerOptions.version,
38
- description: this.answerOptions.description,
39
- };
40
- fse.writeJSONSync(path.join(targetDirPath, "package.json"), packageJson, { encoding: "utf8", flag: "w", spaces: 2 });
41
- });
42
- }
43
- }
package/src/h5/h5.ts DELETED
@@ -1,54 +0,0 @@
1
- import fse from "fs-extra";
2
- import path from "path";
3
- import unzipper from "unzipper";
4
-
5
- export default class InitH5 {
6
- private answerOptions: InquirerPromptQuestions;
7
- constructor(answerOptions: InquirerPromptQuestions) {
8
- this.answerOptions = answerOptions;
9
- }
10
-
11
- init() {
12
- console.log("init h5", this.answerOptions);
13
- this.mkdir();
14
- }
15
-
16
- async mkdir() {
17
- // create dir in current workspace use option name
18
- const targetDirPath = path.join(process.cwd(), this.answerOptions.name);
19
- fse.ensureDirSync(targetDirPath);
20
- this.unzipH5Template(targetDirPath);
21
- }
22
- /**
23
- * unzip h5 template to current workspace path
24
- */
25
- unzipH5Template(targetDirPath: string) {
26
- // process.cwd() 获取当前执行node命令时候的文件夹(工作区)目录名
27
- // 获取当前执行文件的目录,即CLI工具的目录
28
- const rootDir = __dirname;
29
- const templatePath = path.join(rootDir, "./templates/ts-h5.zip");
30
-
31
- fse
32
- .createReadStream(templatePath)
33
- .pipe(unzipper.Extract({ path: targetDirPath }))
34
- .on("close", () => {
35
- const json = fse.readJSONSync(
36
- path.join(targetDirPath, "package.json"),
37
- {
38
- encoding: "utf8",
39
- }
40
- );
41
- const packageJson = {
42
- ...json,
43
- name: this.answerOptions.name,
44
- version: this.answerOptions.version,
45
- description: this.answerOptions.description,
46
- };
47
- fse.writeJSONSync(
48
- path.join(targetDirPath, "package.json"),
49
- packageJson,
50
- { encoding: "utf8", flag: "w", spaces: 2 }
51
- );
52
- });
53
- }
54
- }
package/src/index.ts DELETED
@@ -1,106 +0,0 @@
1
- #! /usr/bin/env node
2
-
3
- import { Command } from "commander";
4
- import inquirer from "inquirer";
5
- import InitH5 from "./h5/h5.js";
6
- import chalk from "chalk";
7
-
8
- const program = new Command();
9
-
10
- const log = console.log;
11
-
12
- program
13
- .name("project cli")
14
- .description("CLI to Initialize some project")
15
- .version("0.0.1");
16
-
17
- program
18
- .command("split")
19
- .description("Split a string into an array of strings using a separator.")
20
- .argument("<string>", "The string to split")
21
- .option("--first", "display just the first substring")
22
- .option("-s, --separator <char>", "separator character", ",")
23
- .action((str, options) => {
24
- console.log("---->> ", options);
25
- const limit = options.first ? 1 : undefined;
26
- console.log(str.split(options.separator, limit));
27
- });
28
-
29
- program
30
- .command("init")
31
- .description("初始化项目,支持H5,Web等")
32
- .option("-h5, --h5", "Initialize an H5 project.", false)
33
- .option("-w, --web", "Initialize a Web project.", false)
34
- .action(async (options: InitOptions) => {
35
- // 如果没有配置argument,则第一个参数就是options
36
- if (options.h5 === false && options.web === false) {
37
- log(
38
- "请使用" +
39
- chalk.bgRed.bold("emnj init --h5") +
40
- "或者" +
41
- chalk.bgRed.bold("emnj init --web") +
42
- "来初始化项目"
43
- );
44
- process.exit(1);
45
- }
46
-
47
- try {
48
- const confirmAnswers = await inquirer.prompt([
49
- {
50
- type: "confirm",
51
- name: "confirmAction",
52
- message: `确认初始化一个${options.h5 ? "H5" : "Web"}工程项目`,
53
- default: true,
54
- },
55
- ]);
56
- if (!confirmAnswers.confirmAction) {
57
- const message = "取消初始化";
58
- log(chalk.redBright(message));
59
- throw new Error(message);
60
- }
61
-
62
- const actionAnswers: InquirerPromptQuestions = await inquirer.prompt([
63
- {
64
- type: "input",
65
- name: "name",
66
- message: "请输入名称:",
67
- default: "h5-project",
68
- validate: function (value) {
69
- return true;
70
- },
71
- },
72
- {
73
- type: "input",
74
- name: "version",
75
- message: "请输入版本:",
76
- default: "0.0.1",
77
- },
78
- {
79
- type: "input",
80
- name: "description",
81
- message: "请输入项目描述:",
82
- default: "这是一个H5项目",
83
- },
84
- {
85
- type: "list",
86
- name: "language",
87
- message: "是否使用typescript",
88
- default: true,
89
- choices: ["typescript", "javascript"],
90
- },
91
- ]);
92
- if (options.h5 === true) {
93
- const initH5 = new InitH5(actionAnswers);
94
- initH5.init();
95
- return;
96
- }
97
- if (options.web === true) {
98
- log("初始化web项目");
99
- return;
100
- }
101
- } catch (error) {
102
- process.exit(1);
103
- }
104
- });
105
-
106
- program.parse(process.argv);
@@ -1,16 +0,0 @@
1
- /**
2
- * 初始化项目选项的定义
3
- */
4
- interface InitOptions {
5
- h5: boolean;
6
- web: boolean;
7
- }
8
- /**
9
- * 初始化项目询问选项
10
- */
11
- interface InquirerPromptQuestions {
12
- name: string;
13
- version: string;
14
- description: string;
15
- language: "typescript" | "javascript";
16
- }
package/src/util.ts DELETED
@@ -1,3 +0,0 @@
1
- export function sum(a: number, b: number): number {
2
- return a + b;
3
- }