@heathenjs/taro-router-cli 1.0.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/dist/cli.d.ts ADDED
@@ -0,0 +1,2 @@
1
+ #!/usr/bin/env node
2
+ export {};
package/dist/cli.js ADDED
@@ -0,0 +1,58 @@
1
+ #!/usr/bin/env node
2
+ "use strict";
3
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
4
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
5
+ return new (P || (P = Promise))(function (resolve, reject) {
6
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
7
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
8
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
9
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
10
+ });
11
+ };
12
+ var __importDefault = (this && this.__importDefault) || function (mod) {
13
+ return (mod && mod.__esModule) ? mod : { "default": mod };
14
+ };
15
+ Object.defineProperty(exports, "__esModule", { value: true });
16
+ const taro_router_generator_1 = require("@heathen/taro-router-generator");
17
+ const commander_1 = require("commander");
18
+ const fs_1 = __importDefault(require("fs"));
19
+ const path_1 = __importDefault(require("path"));
20
+ const register_options_1 = require("./register-options");
21
+ const program = new commander_1.Command();
22
+ const CONFIG_FILE_NAME = 'router.config.json';
23
+ // -------------------------------------------- update --------------------------------------------
24
+ (() => {
25
+ const UPDATE_OPTIONS = [
26
+ {
27
+ name: 'config',
28
+ params: [{ name: 'configFilePath', required: true }],
29
+ shortcut: 'c',
30
+ description: '指定配置文件',
31
+ },
32
+ ];
33
+ const updateCommand = program.command('update');
34
+ (0, register_options_1.registerOptions)(updateCommand, UPDATE_OPTIONS);
35
+ updateCommand.action((options) => __awaiter(void 0, void 0, void 0, function* () {
36
+ let configFilePath = path_1.default.resolve(process.cwd(), `./${CONFIG_FILE_NAME}`);
37
+ if (options.config) {
38
+ if (path_1.default.isAbsolute(options.config)) {
39
+ configFilePath = options.config;
40
+ }
41
+ else {
42
+ configFilePath = path_1.default.resolve(process.cwd(), options.config);
43
+ }
44
+ }
45
+ const isConfigFileExist = fs_1.default.existsSync(configFilePath);
46
+ if (isConfigFileExist) {
47
+ const configSource = fs_1.default.readFileSync(configFilePath, { encoding: 'utf8' });
48
+ const config = JSON.parse(configSource);
49
+ const generator = new taro_router_generator_1.Generator(config);
50
+ generator.generateRouter();
51
+ }
52
+ else {
53
+ throw `找不到 ${configFilePath},请检查配置文件及执行路径。`;
54
+ }
55
+ }));
56
+ })();
57
+ program.parse();
58
+ //# sourceMappingURL=cli.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"cli.js","sourceRoot":"","sources":["../src/cli.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AACA,0EAA2D;AAC3D,yCAAoC;AACpC,4CAAoB;AACpB,gDAAwB;AACxB,yDAAmF;AAEnF,MAAM,OAAO,GAAG,IAAI,mBAAO,EAAE,CAAC;AAC9B,MAAM,gBAAgB,GAAG,oBAAoB,CAAC;AAE9C,mGAAmG;AACnG,CAAC,GAAG,EAAE;IACJ,MAAM,cAAc,GAAG;QACrB;YACE,IAAI,EAAE,QAAiB;YACvB,MAAM,EAAE,CAAC,EAAE,IAAI,EAAE,gBAAgB,EAAE,QAAQ,EAAE,IAAI,EAAE,CAAC;YACpD,QAAQ,EAAE,GAAG;YACb,WAAW,EAAE,QAAQ;SACtB;KACoB,CAAC;IAExB,MAAM,aAAa,GAAG,OAAO,CAAC,OAAO,CAAC,QAAQ,CAAC,CAAC;IAChD,IAAA,kCAAe,EAAC,aAAa,EAAE,cAAc,CAAC,CAAC;IAE/C,aAAa,CAAC,MAAM,CAAC,CAAO,OAA4C,EAAE,EAAE;QAC1E,IAAI,cAAc,GAAG,cAAI,CAAC,OAAO,CAAC,OAAO,CAAC,GAAG,EAAE,EAAE,KAAK,gBAAgB,EAAE,CAAC,CAAC;QAC1E,IAAI,OAAO,CAAC,MAAM,EAAE,CAAC;YACnB,IAAI,cAAI,CAAC,UAAU,CAAC,OAAO,CAAC,MAAM,CAAC,EAAE,CAAC;gBACpC,cAAc,GAAG,OAAO,CAAC,MAAM,CAAC;YAClC,CAAC;iBAAM,CAAC;gBACN,cAAc,GAAG,cAAI,CAAC,OAAO,CAAC,OAAO,CAAC,GAAG,EAAE,EAAE,OAAO,CAAC,MAAM,CAAC,CAAC;YAC/D,CAAC;QACH,CAAC;QAED,MAAM,iBAAiB,GAAG,YAAE,CAAC,UAAU,CAAC,cAAc,CAAC,CAAC;QAExD,IAAI,iBAAiB,EAAE,CAAC;YACtB,MAAM,YAAY,GAAG,YAAE,CAAC,YAAY,CAAC,cAAc,EAAE,EAAE,QAAQ,EAAE,MAAM,EAAE,CAAC,CAAC;YAE3E,MAAM,MAAM,GAAG,IAAI,CAAC,KAAK,CAAC,YAAY,CAAC,CAAC;YAExC,MAAM,SAAS,GAAG,IAAI,iCAAS,CAAC,MAAM,CAAC,CAAC;YACxC,SAAS,CAAC,cAAc,EAAE,CAAC;QAC7B,CAAC;aAAM,CAAC;YACN,MAAM,OAAO,cAAc,gBAAgB,CAAC;QAC9C,CAAC;IACH,CAAC,CAAA,CAAC,CAAC;AACL,CAAC,CAAC,EAAE,CAAC;AAEL,OAAO,CAAC,KAAK,EAAE,CAAC"}
@@ -0,0 +1,13 @@
1
+ import { Command } from 'commander';
2
+ export type CliOptionParam = {
3
+ name: string;
4
+ required?: boolean;
5
+ };
6
+ export type CliOption = {
7
+ name: string;
8
+ shortcut: string;
9
+ params: CliOptionParam[];
10
+ description: string;
11
+ };
12
+ export type InputOptions<T extends CliOption[]> = Record<T[number]['name'], string>;
13
+ export declare const registerOptions: (command: Command, options: CliOption[]) => void;
@@ -0,0 +1,15 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.registerOptions = void 0;
4
+ const registerOptions = (command, options) => {
5
+ options.forEach((option) => {
6
+ const paramList = option.params
7
+ .map((param) => {
8
+ return param.required ? `<${param.name}>` : `[${param.name}]`;
9
+ })
10
+ .join(' ');
11
+ command.option(`-${option.shortcut}, --${option.name}${paramList ? ` ${paramList}` : ''}`, option.description);
12
+ });
13
+ };
14
+ exports.registerOptions = registerOptions;
15
+ //# sourceMappingURL=register-options.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"register-options.js","sourceRoot":"","sources":["../src/register-options.ts"],"names":[],"mappings":";;;AAgBO,MAAM,eAAe,GAAG,CAAC,OAAgB,EAAE,OAAoB,EAAE,EAAE;IACxE,OAAO,CAAC,OAAO,CAAC,CAAC,MAAM,EAAE,EAAE;QACzB,MAAM,SAAS,GAAG,MAAM,CAAC,MAAM;aAC5B,GAAG,CAAC,CAAC,KAAK,EAAE,EAAE;YACb,OAAO,KAAK,CAAC,QAAQ,CAAC,CAAC,CAAC,IAAI,KAAK,CAAC,IAAI,GAAG,CAAC,CAAC,CAAC,IAAI,KAAK,CAAC,IAAI,GAAG,CAAC;QAChE,CAAC,CAAC;aACD,IAAI,CAAC,GAAG,CAAC,CAAC;QACb,OAAO,CAAC,MAAM,CAAC,IAAI,MAAM,CAAC,QAAQ,OAAO,MAAM,CAAC,IAAI,GAAG,SAAS,CAAC,CAAC,CAAC,IAAI,SAAS,EAAE,CAAC,CAAC,CAAC,EAAE,EAAE,EAAE,MAAM,CAAC,WAAW,CAAC,CAAC;IACjH,CAAC,CAAC,CAAC;AACL,CAAC,CAAC;AATW,QAAA,eAAe,mBAS1B"}
package/package.json ADDED
@@ -0,0 +1,24 @@
1
+ {
2
+ "name": "@heathenjs/taro-router-cli",
3
+ "version": "1.0.0",
4
+ "description": "",
5
+ "bin": {
6
+ "taro-router-helper": "./dist/cli.js"
7
+ },
8
+ "scripts": {
9
+ "prod": "tsc -p ./tsconfig.json",
10
+ "clean": "rimraf dist",
11
+ "build": "pnpm run clean && pnpm run prod",
12
+ "tsc": "tsc -p ./tsconfig.json --noEmit",
13
+ "lint": "eslint --ext .ts --max-warnings 0 \"./src\" "
14
+ },
15
+ "files": [
16
+ "dist",
17
+ "package.json",
18
+ "README.md"
19
+ ],
20
+ "dependencies": {
21
+ "commander": "^13.1.0",
22
+ "@heathenjs/taro-router-generator": "workspace:*"
23
+ }
24
+ }