emnj-tool 1.0.4 → 1.0.5

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.
@@ -0,0 +1 @@
1
+ export const version = "0.0.3";
package/dist/index.js CHANGED
@@ -12,20 +12,10 @@ import { Command } from "commander";
12
12
  import inquirer from "inquirer";
13
13
  import CreateH5 from "./h5.js";
14
14
  import chalk from "chalk";
15
+ import { version } from "./constant.js";
15
16
  const program = new Command();
16
17
  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
- // });
18
+ program.name("项目初始化").description("CLI to Initialize some project").version(version);
29
19
  program
30
20
  .command("init")
31
21
  .description("初始化项目,支持H5,Web等")
package/package.json CHANGED
@@ -1,15 +1,15 @@
1
1
  {
2
2
  "name": "emnj-tool",
3
- "version": "1.0.4",
3
+ "version": "1.0.5",
4
4
  "description": "一个工具,用来初始化项目",
5
5
  "type": "module",
6
- "exports": "./index.js",
7
6
  "engines": {
8
7
  "node": ">=16.0.0"
9
8
  },
10
9
  "scripts": {
11
10
  "test": "echo \"Error: no test specified\" && exit 1",
12
- "build": "npx tsc"
11
+ "build": "pnpm run clean && npx tsc",
12
+ "clean": "rimraf dist"
13
13
  },
14
14
  "bin": {
15
15
  "emnj-tool": "./dist/index.js"
@@ -17,13 +17,21 @@
17
17
  "keywords": [
18
18
  "emnj-tool"
19
19
  ],
20
- "author": "",
20
+ "author": "beyond",
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",
23
27
  "@types/fs-extra": "^11.0.4",
24
28
  "@types/inquirer": "^9.0.7",
25
29
  "@types/node": "^20.11.28",
30
+ "rimraf": "^5.0.7",
31
+ "rollup": "^4.17.2",
32
+ "rollup-plugin-typescript2": "^0.36.0",
26
33
  "ts-node": "^10.9.2",
34
+ "tslib": "^2.6.2",
27
35
  "typescript": "^5.4.2"
28
36
  },
29
37
  "dependencies": {
package/tsconfig.json CHANGED
@@ -1,15 +1,22 @@
1
1
  {
2
2
  "compilerOptions": {
3
- "target": "ES2015",
4
- "module": "Node16",
5
- "moduleResolution": "Node16",
6
- "esModuleInterop": true,
3
+ "module": "ES2020", // 或者 "ES2015", "ESNext" 等
4
+ "moduleResolution": "node", // 确保模块解析适合Node.js
5
+ "target": "es6", // Node.js支持的最低版本
6
+ "lib": ["esnext", "dom"],
7
7
  "strict": true,
8
- "skipLibCheck": true,
9
- "forceConsistentCasingInFileNames": true,
8
+ "esModuleInterop": true,
9
+ "outDir": "dist",
10
+ "declaration": true,
11
+ "declarationDir": "types",
10
12
  "resolveJsonModule": true,
11
- "outDir": "./dist",
12
- "typeRoots": ["./node_modules/@types", "./src/types"]
13
+ "jsx": "preserve",
14
+ "jsxImportSource": "vue",
15
+ "allowJs": true,
16
+ "baseUrl": "./",
17
+ "paths": {},
18
+ "types": []
13
19
  },
14
- "include": ["src/**/*.ts"]
20
+ "include": ["src/**/*.js", "src/**/*.ts"],
21
+ "exclude": ["node_modules", "build", "dist", "example", "rollup.config.js"]
15
22
  }
@@ -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,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;
@@ -0,0 +1 @@
1
+ export declare function sum(a: number, b: number): number;
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
- }