@rife/cli 0.0.6-beta.1 → 0.0.6-beta.11

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.
Files changed (62) hide show
  1. package/dist/1.js +24 -0
  2. package/dist/1.mjs +20 -0
  3. package/dist/cjs/1.js +24 -0
  4. package/dist/cli.js +4 -0
  5. package/dist/cli.js.map +1 -1
  6. package/dist/esm/1.mjs +20 -0
  7. package/dist/index.js +4 -0
  8. package/dist/index.js.map +1 -1
  9. package/dist/logger.js +3 -11
  10. package/dist/logger.js.map +1 -1
  11. package/dist/plugin/commander.js +22 -17
  12. package/dist/plugin/commander.js.map +1 -1
  13. package/dist/plugin/compiler/index.js +11 -6
  14. package/dist/plugin/compiler/index.js.map +1 -1
  15. package/dist/plugin/compiler/swc.js +2 -1
  16. package/dist/plugin/compiler/swc.js.map +1 -1
  17. package/dist/plugin/compiler/swc2.js +65 -0
  18. package/dist/plugin/compiler/swc2.js.map +1 -0
  19. package/dist/plugin/config.js +25 -9
  20. package/dist/plugin/config.js.map +1 -1
  21. package/dist/plugin/index.js +1 -0
  22. package/dist/plugin/index.js.map +1 -1
  23. package/dist/plugin/package copy.js.map +1 -1
  24. package/dist/plugin/package.js.map +1 -1
  25. package/dist/plugin/release.js +84 -14
  26. package/dist/plugin/release.js.map +1 -1
  27. package/dist/runner.js +33 -5
  28. package/dist/runner.js.map +1 -1
  29. package/dist/sync.js +4 -3
  30. package/dist/sync.js.map +1 -1
  31. package/dist/tsconfig.tsbuildinfo +1 -1
  32. package/dist/util.js +14 -0
  33. package/dist/util.js.map +1 -0
  34. package/package.json +28 -26
  35. package/src/cli.ts +23 -19
  36. package/src/index.ts +15 -3
  37. package/src/logger.ts +16 -34
  38. package/src/plugin/commander.ts +49 -44
  39. package/src/plugin/compiler/index.ts +115 -109
  40. package/src/plugin/compiler/swc.ts +56 -55
  41. package/src/plugin/compiler/tsc.ts +101 -101
  42. package/src/plugin/config.ts +78 -63
  43. package/src/plugin/index.ts +1 -0
  44. package/src/plugin/package.ts +0 -3
  45. package/src/plugin/release.ts +113 -32
  46. package/src/runner.ts +128 -88
  47. package/src/sync.ts +63 -62
  48. package/src/util.ts +9 -0
  49. package/dist/build.js +0 -3
  50. package/dist/build.js.map +0 -1
  51. package/dist/compiler.js +0 -82
  52. package/dist/compiler.js.map +0 -1
  53. package/dist/plugin.js +0 -161
  54. package/dist/plugin.js.map +0 -1
  55. package/dist/pnpmfile.js +0 -144
  56. package/dist/swc.js +0 -78
  57. package/dist/swc.js.map +0 -1
  58. package/dist/tsc.js +0 -94
  59. package/dist/tsc.js.map +0 -1
  60. package/src/build.ts +0 -0
  61. package/src/pnpmfile.ts +0 -121
  62. package/src/test/pnpmfile.test.ts +0 -223
package/src/runner.ts CHANGED
@@ -1,88 +1,128 @@
1
- import { AsyncSeriesHook } from 'tapable';
2
- import zod from 'zod';
3
-
4
- import { Logger, createLogger } from './logger';
5
-
6
- export interface Config {
7
- name: string;
8
- plugins: Plugin[];
9
- }
10
-
11
- export interface Runner {
12
- env: 'prod' | 'dev';
13
- hook: {
14
- loadPackage: AsyncSeriesHook<[]>;
15
- loadConfig: AsyncSeriesHook<[]>;
16
- validateConfig: AsyncSeriesHook<[]>;
17
- applyConfig: AsyncSeriesHook<[any]>;
18
- startCommand: AsyncSeriesHook<[]>;
19
- finishCommand: AsyncSeriesHook<[]>;
20
- dev: AsyncSeriesHook<[]>;
21
- build: AsyncSeriesHook<[]>;
22
- test: AsyncSeriesHook<[]>;
23
- release: AsyncSeriesHook<[]>;
24
- deploy: AsyncSeriesHook<[any]>;
25
- lint: AsyncSeriesHook<[]>;
26
- };
27
- logger: Logger;
28
- config: {
29
- all: Config[];
30
- current: Config;
31
- };
32
- package: any;
33
- z: typeof zod;
34
- fs: typeof import('fs-extra');
35
- tapable: typeof import('tapable');
36
- }
37
-
38
- export interface Plugin {
39
- name: string;
40
- apply: (runner: Runner) => any;
41
- }
42
-
43
- if (typeof Promise.withResolvers === 'undefined') {
44
- Promise.withResolvers = <T>() => {
45
- let resolve: (value: T | PromiseLike<T>) => void;
46
- let reject: (reason?: unknown) => void;
47
- const promise = new Promise<T>((res, rej) => {
48
- resolve = res;
49
- reject = rej;
50
- });
51
- return { promise, resolve: resolve!, reject: reject! };
52
- };
53
- }
54
-
55
- export function createRunner() {
56
- const runner: Runner = {
57
- env: 'prod',
58
- hook: {
59
- loadPackage: new AsyncSeriesHook([]),
60
- loadConfig: new AsyncSeriesHook([]),
61
- validateConfig: new AsyncSeriesHook([]),
62
- applyConfig: new AsyncSeriesHook(['options']),
63
- startCommand: new AsyncSeriesHook([]),
64
- finishCommand: new AsyncSeriesHook([]),
65
- dev: new AsyncSeriesHook([]),
66
- build: new AsyncSeriesHook([]),
67
- test: new AsyncSeriesHook([]),
68
- release: new AsyncSeriesHook([]),
69
- deploy: new AsyncSeriesHook(['options']),
70
- lint: new AsyncSeriesHook([]),
71
- },
72
- logger: createLogger(),
73
- config: {
74
- all: [],
75
- // @ts-expect-error
76
- current: undefined,
77
- },
78
- package: {},
79
- z: zod,
80
- fs: require('fs-extra') as typeof import('fs-extra'),
81
- tapable: require('tapable') as typeof import('tapable'),
82
- };
83
- return runner;
84
- }
85
-
86
- export function defineConfig(all: Config[]) {
87
- return all;
88
- }
1
+ import type { ConsolaInstance } from 'consola';
2
+ import { colors } from 'consola/utils';
3
+ import { AsyncSeriesHook } from 'tapable';
4
+ import zod from 'zod';
5
+
6
+ import { createLogger } from './logger';
7
+ import { fs, glob } from './util';
8
+
9
+ export interface Config {
10
+ name: string;
11
+ plugins: Plugin[];
12
+ }
13
+
14
+ export interface Runner {
15
+ env: 'prod' | 'dev';
16
+ hook: {
17
+ loadPackage: AsyncSeriesHook<[]>;
18
+ loadConfig: AsyncSeriesHook<[]>;
19
+ validateConfig: AsyncSeriesHook<[]>;
20
+ applyConfig: AsyncSeriesHook<[]>;
21
+ validatePlugin: AsyncSeriesHook<[]>;
22
+ registerCommand: AsyncSeriesHook<[]>;
23
+ startCommand: AsyncSeriesHook<[]>;
24
+ finishCommand: AsyncSeriesHook<[]>;
25
+ dev: AsyncSeriesHook<[]>;
26
+ build: AsyncSeriesHook<[]>;
27
+ test: AsyncSeriesHook<[]>;
28
+ release: AsyncSeriesHook<[]>;
29
+ deploy: AsyncSeriesHook<[]>;
30
+ lint: AsyncSeriesHook<[]>;
31
+ };
32
+ logger: ConsolaInstance;
33
+ config: {
34
+ all: Config[];
35
+ current: Config;
36
+ };
37
+ command: import('commander').Command;
38
+ package: any;
39
+ z: typeof zod;
40
+ fs: typeof import('fs-extra');
41
+ glob: typeof import('glob')['glob'];
42
+ duration: string;
43
+ tempDir: string;
44
+ clear: () => void;
45
+ }
46
+
47
+ export interface Plugin {
48
+ name: string;
49
+ apply: (runner: Runner) => any;
50
+ }
51
+
52
+ if (typeof Promise.withResolvers === 'undefined') {
53
+ Promise.withResolvers = <T>() => {
54
+ let resolve: (value: T | PromiseLike<T>) => void;
55
+ let reject: (reason?: unknown) => void;
56
+ const promise = new Promise<T>((res, rej) => {
57
+ resolve = res;
58
+ reject = rej;
59
+ });
60
+ return { promise, resolve: resolve!, reject: reject! };
61
+ };
62
+ }
63
+
64
+ export function createRunner() {
65
+ const perfStart = performance.now();
66
+
67
+ const { Command } = require('commander') as typeof import('commander');
68
+ const command = new Command();
69
+
70
+ command.option('--debug', '打开调试日志');
71
+ command.option('-n, --name <string>', '执行指定配置');
72
+ command.option('-h, --help', '帮助');
73
+ command.parse();
74
+
75
+ const args = zod
76
+ .object({
77
+ debug: zod.boolean().default(false),
78
+ })
79
+ .default({})
80
+ .safeParse(command.opts());
81
+
82
+ const runner: Runner = {
83
+ env: 'prod',
84
+ hook: {
85
+ loadPackage: new AsyncSeriesHook([]),
86
+ loadConfig: new AsyncSeriesHook([]),
87
+ validateConfig: new AsyncSeriesHook([]),
88
+ applyConfig: new AsyncSeriesHook([]),
89
+ validatePlugin: new AsyncSeriesHook([]),
90
+ registerCommand: new AsyncSeriesHook([]),
91
+ startCommand: new AsyncSeriesHook([]),
92
+ finishCommand: new AsyncSeriesHook([]),
93
+ dev: new AsyncSeriesHook([]),
94
+ build: new AsyncSeriesHook([]),
95
+ test: new AsyncSeriesHook([]),
96
+ release: new AsyncSeriesHook([]),
97
+ deploy: new AsyncSeriesHook([]),
98
+ lint: new AsyncSeriesHook([]),
99
+ },
100
+ logger: createLogger(args.data),
101
+ command,
102
+ config: {
103
+ all: [],
104
+ // @ts-expect-error
105
+ current: undefined,
106
+ },
107
+ package: {},
108
+ z: zod,
109
+ fs,
110
+ glob: glob.glob,
111
+ get duration() {
112
+ const duration = ((performance.now() - perfStart) / 1000).toFixed(3);
113
+ return `耗时 ${duration} s`;
114
+ },
115
+ tempDir: './node_modules/.temp/',
116
+ clear: () => {
117
+ console.clear();
118
+ process.stdout.write('\x1b[3J');
119
+ console.log(`${colors.bgBlue(' 项目名称 ')} ${runner.package.name} \n`);
120
+ },
121
+ };
122
+
123
+ return runner;
124
+ }
125
+
126
+ export function defineConfig(all: Config[]) {
127
+ return all;
128
+ }
package/src/sync.ts CHANGED
@@ -1,62 +1,63 @@
1
- async function sync(name: string) {
2
- const res = await fetch(`https://registry-direct.npmmirror.com/-/package/${name}/syncs`, {
3
- headers: {
4
- accept: '*/*',
5
- 'accept-language': 'zh-CN,zh;q=0.9,en;q=0.8',
6
- 'sec-ch-ua': '"Not_A Brand";v="8", "Chromium";v="120", "Google Chrome";v="120"',
7
- 'sec-ch-ua-mobile': '?0',
8
- 'sec-ch-ua-platform': '"Windows"',
9
- 'sec-fetch-dest': 'empty',
10
- 'sec-fetch-mode': 'cors',
11
- 'sec-fetch-site': 'same-site',
12
- Referer: 'https://npmmirror.com/',
13
- 'Referrer-Policy': 'strict-origin-when-cross-origin',
14
- },
15
- body: null,
16
- method: 'PUT',
17
- });
18
- const body = await res.json();
19
- if (body.ok === true) {
20
- console.log(`同步 ${name} 成功`);
21
- }
22
- return body;
23
- }
24
-
25
- const list = [
26
- '@rife/config', //
27
- // '@rife/infra',
28
- '@rife/logger',
29
- // '@rife/react',
30
- // '@rife/next',
31
- // '@rife/nest',
32
- // '@rife/wxa',
33
- '@rife/fast',
34
- ];
35
-
36
- async function main() {
37
- for (const item of list) {
38
- // https://registry.npmmirror.com/-/package/@rife/infra/syncs/65a255a2afa293666acf6655/log
39
- await sync(item);
40
- }
41
-
42
- poll();
43
- }
44
-
45
- main();
46
-
47
- async function get(name: string) {
48
- try {
49
- const res = await fetch(`https://r.cnpmjs.org/${name}?t=${Date.now()}&cache=0`);
50
- const data = await res.json();
51
- return `${name} ${data?.['dist-tags']?.['latest']}`;
52
- } catch (e) {
53
- return `${name} error`;
54
- }
55
- }
56
-
57
- async function poll() {
58
- const res = await Promise.all(list.map(get));
59
- console.log(`${res.join('\n')}\n`);
60
-
61
- setTimeout(poll, 1000);
62
- }
1
+ async function sync(name: string) {
2
+ const res = await fetch(`https://registry-direct.npmmirror.com/-/package/${name}/syncs`, {
3
+ headers: {
4
+ accept: '*/*',
5
+ 'accept-language': 'zh-CN,zh;q=0.9,en;q=0.8',
6
+ 'sec-ch-ua': '"Not_A Brand";v="8", "Chromium";v="120", "Google Chrome";v="120"',
7
+ 'sec-ch-ua-mobile': '?0',
8
+ 'sec-ch-ua-platform': '"Windows"',
9
+ 'sec-fetch-dest': 'empty',
10
+ 'sec-fetch-mode': 'cors',
11
+ 'sec-fetch-site': 'same-site',
12
+ Referer: 'https://npmmirror.com/',
13
+ 'Referrer-Policy': 'strict-origin-when-cross-origin',
14
+ },
15
+ body: null,
16
+ method: 'PUT',
17
+ });
18
+ const body = await res.json();
19
+ if (body.ok === true) {
20
+ console.log(`同步 ${name} 成功`);
21
+ }
22
+ return body;
23
+ }
24
+
25
+ const list = [
26
+ '@rife/config', //
27
+ '@rife/cli', //
28
+ // '@rife/infra',
29
+ // '@rife/logger',
30
+ // '@rife/react',
31
+ // '@rife/next',
32
+ // '@rife/nest',
33
+ // '@rife/plugin-deploy',
34
+ // '@rife/fast',
35
+ ];
36
+
37
+ async function main() {
38
+ for (const item of list) {
39
+ // https://registry.npmmirror.com/-/package/@rife/infra/syncs/65a255a2afa293666acf6655/log
40
+ await sync(item);
41
+ }
42
+
43
+ poll();
44
+ }
45
+
46
+ main();
47
+
48
+ async function get(name: string) {
49
+ try {
50
+ const res = await fetch(`https://r.cnpmjs.org/${name}?t=${Date.now()}&cache=0`);
51
+ const data = await res.json();
52
+ return `${name} ${data?.['dist-tags']?.['latest']}`;
53
+ } catch (e) {
54
+ return `${name} error`;
55
+ }
56
+ }
57
+
58
+ async function poll() {
59
+ const res = await Promise.all(list.map(get));
60
+ console.log(`${res.join('\n')}\n`);
61
+
62
+ setTimeout(poll, 1000);
63
+ }
package/src/util.ts ADDED
@@ -0,0 +1,9 @@
1
+ import fs from 'fs-extra';
2
+ import * as glob from 'glob';
3
+
4
+ export { fs, glob };
5
+
6
+ export const getDuration = (perfStart: number) => {
7
+ const duration = ((performance.now() - perfStart) / 1000).toFixed(3);
8
+ return `耗时 ${duration} s`;
9
+ };
package/dist/build.js DELETED
@@ -1,3 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- //# sourceMappingURL=build.js.map
package/dist/build.js.map DELETED
@@ -1 +0,0 @@
1
- {"version":3,"file":"build.js","sourceRoot":"","sources":["../src/build.ts"],"names":[],"mappings":""}
package/dist/compiler.js DELETED
@@ -1,82 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.compileTs = compileTs;
4
- const tslib_1 = require("tslib");
5
- const path_1 = tslib_1.__importDefault(require("path"));
6
- const utils_1 = require("consola/utils");
7
- const swc_1 = require("./swc");
8
- const tsc_1 = require("./tsc");
9
- const clear = () => {
10
- console.clear();
11
- process.stdout.write('\x1b[3J');
12
- };
13
- async function compileTs(runner, tsxConfig, { watch } = { watch: false }) {
14
- const { logger, fs } = runner;
15
- const log = logger.withTag(compileTs.name);
16
- log.debug('tsxConfig %j', tsxConfig);
17
- if (tsxConfig.clean) {
18
- log.info('清空目录 %s', tsxConfig.outDir);
19
- await fs.emptyDir(tsxConfig.outDir);
20
- }
21
- if (tsxConfig.type === 'tsc') {
22
- (0, tsc_1.tsc)(tsxConfig);
23
- return;
24
- }
25
- if (tsxConfig.type === 'swc') {
26
- const formatDiagnostic = (diagnostics) => {
27
- const ts = require('typescript');
28
- return diagnostics
29
- .map(diagnostic => {
30
- const message = ts.flattenDiagnosticMessageText(diagnostic.messageText, '\n');
31
- if (diagnostic.file) {
32
- const { line, character } = diagnostic.file.getLineAndCharacterOfPosition(diagnostic.start);
33
- return `${utils_1.colors.blue(diagnostic.file.fileName)} ${utils_1.colors.yellow(`(${line + 1},${character + 1})`)}: ${utils_1.colors.white(message)}`;
34
- }
35
- return message;
36
- })
37
- .join('\n');
38
- };
39
- (0, swc_1.swc)({
40
- ...tsxConfig,
41
- watch,
42
- onComplieSuccess: ({ watch, first, duration }) => {
43
- if (watch && !first) {
44
- // watch 模式下,第二次编译清空一下屏幕
45
- clear();
46
- console.log(`${utils_1.colors.bgBlue(' 项目名称 ')} ${runner.package.name} \n`);
47
- }
48
- log.success(`编译成功,耗时 ${duration.toFixed(2)} ms`);
49
- runner.compiler.hook.tsxSuccess.promise();
50
- },
51
- onComplieFail: ({ watch, first, duration, reasons }) => {
52
- if (watch && !first) {
53
- // watch 模式下,第二次编译清空一下屏幕
54
- clear();
55
- console.log(`${utils_1.colors.bgBlue(' 项目名称 ')} ${runner.package.name} \n`);
56
- }
57
- const message = [...reasons.entries()]
58
- .map(([key, value]) => {
59
- const index = value.indexOf(key);
60
- if (index > -1) {
61
- return value.replace(key, path_1.default.resolve(key));
62
- }
63
- return `${value}`;
64
- })
65
- .join('\n');
66
- log.error(`编译失败,耗时 ${duration.toFixed(2)} ms\n\n%s`, message);
67
- },
68
- onTypeCheckFinish: ({ diagnostics, duration }) => {
69
- if (diagnostics.length) {
70
- log.error(`类型检查失败,耗时 ${duration.toFixed(2)} ms\n\n%s`, formatDiagnostic(diagnostics));
71
- }
72
- else {
73
- log.success(`类型检查成功,耗时 ${duration.toFixed(2)} ms`);
74
- }
75
- },
76
- });
77
- return;
78
- }
79
- log.error(`compiler type '${tsxConfig.type}' 不存在`);
80
- process.exit(1);
81
- }
82
- //# sourceMappingURL=compiler.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"compiler.js","sourceRoot":"","sources":["../src/compiler.ts"],"names":[],"mappings":";;AAgCA,8BAoEC;;AApGD,wDAAwB;AAExB,yCAAuC;AAKvC,+BAA4B;AAC5B,+BAA4B;AAmB5B,MAAM,KAAK,GAAG,GAAG,EAAE;IACf,OAAO,CAAC,KAAK,EAAE,CAAC;IAChB,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC,SAAS,CAAC,CAAC;AACpC,CAAC,CAAC;AAEK,KAAK,UAAU,SAAS,CAAC,MAAc,EAAE,SAAoB,EAAE,EAAE,KAAK,KAAyB,EAAE,KAAK,EAAE,KAAK,EAAE;IAClH,MAAM,EAAE,MAAM,EAAE,EAAE,EAAE,GAAG,MAAM,CAAC;IAC9B,MAAM,GAAG,GAAG,MAAM,CAAC,OAAO,CAAC,SAAS,CAAC,IAAI,CAAC,CAAC;IAC3C,GAAG,CAAC,KAAK,CAAC,cAAc,EAAE,SAAS,CAAC,CAAC;IACrC,IAAI,SAAS,CAAC,KAAK,EAAE,CAAC;QAClB,GAAG,CAAC,IAAI,CAAC,SAAS,EAAE,SAAS,CAAC,MAAM,CAAC,CAAC;QACtC,MAAM,EAAE,CAAC,QAAQ,CAAC,SAAS,CAAC,MAAM,CAAC,CAAC;IACxC,CAAC;IACD,IAAI,SAAS,CAAC,IAAI,KAAK,KAAK,EAAE,CAAC;QAC3B,IAAA,SAAG,EAAC,SAAS,CAAC,CAAC;QACf,OAAO;IACX,CAAC;IACD,IAAI,SAAS,CAAC,IAAI,KAAK,KAAK,EAAE,CAAC;QAC3B,MAAM,gBAAgB,GAAG,CAAC,WAAqC,EAAE,EAAE;YAC/D,MAAM,EAAE,GAA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C,CAAC;gBACvD,CAAC;YACL,CAAC;SACJ,CAAC,CAAC;QACH,OAAO;IACX,CAAC;IACD,GAAG,CAAC,KAAK,CAAC,kBAAkB,SAAS,CAAC,IAAI,OAAO,CAAC,CAAC;IACnD,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;AACpB,CAAC"}
package/dist/plugin.js DELETED
@@ -1,161 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.pluginPackage = pluginPackage;
4
- exports.pluginConfig = pluginConfig;
5
- exports.pluginCommander = pluginCommander;
6
- exports.pluginCompiler = pluginCompiler;
7
- const tslib_1 = require("tslib");
8
- const path_1 = tslib_1.__importDefault(require("path"));
9
- const compiler_1 = require("./compiler");
10
- function pluginPackage() {
11
- const plugin = {
12
- name: pluginPackage.name,
13
- apply: runner => {
14
- const { logger, hook, fs } = runner;
15
- const log = logger.withTag(pluginPackage.name);
16
- hook.loadPackage.tapPromise(pluginPackage.name, async () => {
17
- const fileName = 'package.json';
18
- const filePath = path_1.default.resolve(fileName);
19
- if (!fs.existsSync(filePath)) {
20
- log.error(`找不到文件 ${fileName}`);
21
- process.exit(1);
22
- }
23
- try {
24
- const data = require(filePath);
25
- runner.package = data;
26
- }
27
- catch (e) {
28
- log.error(`读取文件失败`, e.message);
29
- process.exit(1);
30
- }
31
- });
32
- },
33
- };
34
- return plugin;
35
- }
36
- function pluginConfig() {
37
- const plugin = {
38
- name: pluginConfig.name,
39
- apply: runner => {
40
- const { logger, hook, config, fs, z } = runner;
41
- const log = logger.withTag(pluginConfig.name);
42
- hook.loadConfig.tapPromise(pluginConfig.name, async () => {
43
- const fileName = '.app.mjs';
44
- const filePath = path_1.default.posix.resolve(fileName);
45
- log.debug(`filePath %s`, filePath);
46
- if (!fs.existsSync(filePath)) {
47
- log.error(`找不到配置文件 ${fileName}`);
48
- process.exit(1);
49
- }
50
- const all = (await import(filePath)).default;
51
- runner.config.all = all;
52
- });
53
- hook.validateConfig.tapPromise(pluginConfig.name, async () => {
54
- const validation = z
55
- .array(z.object({
56
- name: z.string().trim().min(1),
57
- }))
58
- .min(1)
59
- .safeParse(config.all);
60
- if (!validation.success) {
61
- log.error(validation.error.message);
62
- process.exit(1);
63
- }
64
- });
65
- hook.applyConfig.tapPromise(pluginConfig.name, async (options) => {
66
- const result = z
67
- .object({
68
- name: z.string().trim().optional(),
69
- })
70
- .safeParse(options);
71
- const name = result.data?.name;
72
- if (!name) {
73
- config.current = config.all[0];
74
- }
75
- else {
76
- const find = config.all.find(t => t.name === name);
77
- if (!find) {
78
- log.error(`未找到 name '%s'`, name);
79
- process.exit(1);
80
- }
81
- config.current = find;
82
- }
83
- config.current.plugins.forEach(plugin => plugin.apply(runner));
84
- });
85
- },
86
- };
87
- return plugin;
88
- }
89
- function pluginCommander() {
90
- const plugin = {
91
- name: pluginCommander.name,
92
- apply: runner => {
93
- const { hook, config, z } = runner;
94
- hook.runCommand.tapPromise(pluginCommander.name, async () => {
95
- const { Command } = require('commander');
96
- const program = new Command();
97
- program
98
- .command('dev')
99
- .option('-n, --name <string>', '', '')
100
- .description('启动开发')
101
- .action(async (options) => {
102
- await hook.applyConfig.promise(options);
103
- await hook.dev.promise();
104
- });
105
- program
106
- .command('build')
107
- .option('-n, --name <string>', '', '')
108
- .description('构建项目')
109
- .action(async (options) => {
110
- await hook.applyConfig.promise(options);
111
- await hook.build.promise();
112
- });
113
- program.parseAsync(process.argv);
114
- });
115
- },
116
- };
117
- return plugin;
118
- }
119
- function pluginCompiler(options) {
120
- const plugin = {
121
- name: pluginCompiler.name,
122
- apply: runner => {
123
- const { hook, logger, z, tapable } = runner;
124
- const log = logger.withTag(pluginCompiler.name);
125
- const validation = z
126
- .object({
127
- tsx: z
128
- .object({
129
- type: z.enum(['tsc', 'swc']).default('swc'),
130
- rootDir: z.string().trim().min(1).default('.'),
131
- outDir: z.string().trim().min(1).default('./dist/'),
132
- clean: z.boolean().default(true),
133
- options: z.object({}).passthrough().optional(),
134
- })
135
- .default({}),
136
- })
137
- .optional()
138
- .default({})
139
- .safeParse(options);
140
- if (!validation.success) {
141
- log.error('配置错误\n', validation.error.message);
142
- process.exit(1);
143
- }
144
- runner.compiler = {
145
- hook: {
146
- tsxSuccess: new tapable.AsyncSeriesHook(),
147
- },
148
- };
149
- hook.dev.tapPromise(pluginCompiler.name, async () => {
150
- const tsxConfig = validation.data.tsx;
151
- (0, compiler_1.compileTs)(runner, tsxConfig, { watch: true });
152
- });
153
- hook.build.tapPromise(pluginCompiler.name, async () => {
154
- const tsxConfig = validation.data.tsx;
155
- (0, compiler_1.compileTs)(runner, tsxConfig, { watch: false });
156
- });
157
- },
158
- };
159
- return plugin;
160
- }
161
- //# sourceMappingURL=plugin.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"plugin.js","sourceRoot":"","sources":["../src/plugin.ts"],"names":[],"mappings":";;AAOA,sCAwBC;AAED,oCAwDC;AAED,0CAgCC;AAiBD,wCA6CC;;AAzLD,wDAAwB;AAIxB,yCAAkD;AAGlD,SAAgB,aAAa;IACzB,MAAM,MAAM,GAAW;QACnB,IAAI,EAAE,aAAa,CAAC,IAAI;QACxB,KAAK,EAAE,MAAM,CAAC,EAAE;YACZ,MAAM,EAAE,MAAM,EAAE,IAAI,EAAE,EAAE,EAAE,GAAG,MAAM,CAAC;YACpC,MAAM,GAAG,GAAG,MAAM,CAAC,OAAO,CAAC,aAAa,CAAC,IAAI,CAAC,CAAC;YAC/C,IAAI,CAAC,WAAW,CAAC,UAAU,CAAC,aAAa,CAAC,IAAI,EAAE,KAAK,IAAI,EAAE;gBACvD,MAAM,QAAQ,GAAG,cAAc,CAAC;gBAChC,MAAM,QAAQ,GAAG,cAAI,CAAC,OAAO,CAAC,QAAQ,CAAC,CAAC;gBACxC,IAAI,CAAC,EAAE,CAAC,UAAU,CAAC,QAAQ,CAAC,EAAE,CAAC;oBAC3B,GAAG,CAAC,KAAK,CAAC,SAAS,QAAQ,EAAE,CAAC,CAAC;oBAC/B,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