@rife/cli 0.0.6-beta.2 → 0.0.6-beta.21

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 (71) hide show
  1. package/dist/cjs/cli.cjs +25 -0
  2. package/dist/cjs/index.cjs +79 -0
  3. package/dist/cjs/logger.cjs +48 -0
  4. package/dist/cjs/plugin/commander.cjs +66 -0
  5. package/dist/cjs/plugin/config.cjs +109 -0
  6. package/dist/cjs/plugin/index.cjs +79 -0
  7. package/dist/cjs/plugin/package.cjs +71 -0
  8. package/dist/cjs/plugin/release.cjs +129 -0
  9. package/dist/cjs/runner.cjs +141 -0
  10. package/dist/{sync.js → cjs/sync.cjs} +12 -23
  11. package/dist/cjs/util.cjs +67 -0
  12. package/dist/esm/cli.mjs +21 -0
  13. package/dist/esm/index.mjs +6 -0
  14. package/dist/esm/logger.mjs +16 -0
  15. package/dist/esm/plugin/commander.mjs +34 -0
  16. package/dist/esm/plugin/config.mjs +67 -0
  17. package/dist/esm/plugin/index.mjs +6 -0
  18. package/dist/{plugin/package.js → esm/plugin/package.mjs} +10 -13
  19. package/dist/esm/plugin/release.mjs +97 -0
  20. package/dist/esm/runner.mjs +96 -0
  21. package/dist/esm/sync.mjs +46 -0
  22. package/dist/esm/util.mjs +12 -0
  23. package/package.json +29 -27
  24. package/src/cli.ts +23 -19
  25. package/src/index.ts +4 -3
  26. package/src/logger.ts +17 -34
  27. package/src/plugin/commander.ts +51 -44
  28. package/src/plugin/config.ts +26 -9
  29. package/src/plugin/index.ts +1 -1
  30. package/src/plugin/package.ts +0 -3
  31. package/src/plugin/release.ts +113 -32
  32. package/src/runner.ts +134 -88
  33. package/src/sync.ts +63 -63
  34. package/src/util.ts +14 -0
  35. package/dist/build.js +0 -3
  36. package/dist/build.js.map +0 -1
  37. package/dist/cli.js +0 -18
  38. package/dist/cli.js.map +0 -1
  39. package/dist/index.js +0 -7
  40. package/dist/index.js.map +0 -1
  41. package/dist/logger.js +0 -26
  42. package/dist/logger.js.map +0 -1
  43. package/dist/plugin/commander.js +0 -42
  44. package/dist/plugin/commander.js.map +0 -1
  45. package/dist/plugin/compiler/compiler.js +0 -166
  46. package/dist/plugin/compiler/compiler.js.map +0 -1
  47. package/dist/plugin/compiler/index.js +0 -83
  48. package/dist/plugin/compiler/index.js.map +0 -1
  49. package/dist/plugin/compiler/swc.js +0 -47
  50. package/dist/plugin/compiler/swc.js.map +0 -1
  51. package/dist/plugin/compiler/tsc.js +0 -75
  52. package/dist/plugin/compiler/tsc.js.map +0 -1
  53. package/dist/plugin/config.js +0 -61
  54. package/dist/plugin/config.js.map +0 -1
  55. package/dist/plugin/index.js +0 -8
  56. package/dist/plugin/index.js.map +0 -1
  57. package/dist/plugin/package.js.map +0 -1
  58. package/dist/plugin/release.js +0 -32
  59. package/dist/plugin/release.js.map +0 -1
  60. package/dist/pnpmfile.js +0 -153
  61. package/dist/runner.js +0 -53
  62. package/dist/runner.js.map +0 -1
  63. package/dist/sync.js.map +0 -1
  64. package/dist/tsconfig.tsbuildinfo +0 -1
  65. package/src/build.ts +0 -0
  66. package/src/plugin/compiler/compiler.ts +0 -198
  67. package/src/plugin/compiler/index.ts +0 -109
  68. package/src/plugin/compiler/swc.ts +0 -55
  69. package/src/plugin/compiler/tsc.ts +0 -101
  70. package/src/pnpmfile.ts +0 -147
  71. package/src/test/pnpmfile.test.ts +0 -223
package/src/runner.ts CHANGED
@@ -1,88 +1,134 @@
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
+ throwError: (message?: string, options?: ErrorOptions) => never;
46
+ }
47
+
48
+ export interface Plugin {
49
+ name: string;
50
+ apply: (runner: Runner) => any;
51
+ }
52
+
53
+ if (typeof Promise.withResolvers === 'undefined') {
54
+ Promise.withResolvers = <T>() => {
55
+ let resolve: (value: T | PromiseLike<T>) => void;
56
+ let reject: (reason?: unknown) => void;
57
+ const promise = new Promise<T>((res, rej) => {
58
+ resolve = res;
59
+ reject = rej;
60
+ });
61
+ return { promise, resolve: resolve!, reject: reject! };
62
+ };
63
+ }
64
+
65
+ export function createRunner() {
66
+ const perfStart = performance.now();
67
+
68
+ const { Command } = require('commander') as typeof import('commander');
69
+ const command = new Command();
70
+
71
+ command.option('--debug', '打开调试日志');
72
+ command.option('-n, --name <string>', '执行指定配置');
73
+ command.option('-h, --help', '帮助');
74
+ // command.parse();
75
+
76
+ const args = zod
77
+ .object({
78
+ debug: zod.boolean(),
79
+ })
80
+ .default({
81
+ debug: false,
82
+ })
83
+ .safeParse(command.opts());
84
+
85
+ const runner: Runner = {
86
+ env: 'prod',
87
+ hook: {
88
+ loadPackage: new AsyncSeriesHook([]),
89
+ loadConfig: new AsyncSeriesHook([]),
90
+ validateConfig: new AsyncSeriesHook([]),
91
+ applyConfig: new AsyncSeriesHook([]),
92
+ validatePlugin: new AsyncSeriesHook([]),
93
+ registerCommand: new AsyncSeriesHook([]),
94
+ startCommand: new AsyncSeriesHook([]),
95
+ finishCommand: new AsyncSeriesHook([]),
96
+ dev: new AsyncSeriesHook([]),
97
+ build: new AsyncSeriesHook([]),
98
+ test: new AsyncSeriesHook([]),
99
+ release: new AsyncSeriesHook([]),
100
+ deploy: new AsyncSeriesHook([]),
101
+ lint: new AsyncSeriesHook([]),
102
+ },
103
+ logger: createLogger(args.data),
104
+ command,
105
+ config: {
106
+ all: [],
107
+ // @ts-expect-error
108
+ current: undefined,
109
+ },
110
+ package: {},
111
+ z: zod,
112
+ fs,
113
+ glob: glob.glob,
114
+ get duration() {
115
+ const duration = ((performance.now() - perfStart) / 1000).toFixed(3);
116
+ return `耗时 ${duration} s`;
117
+ },
118
+ tempDir: './node_modules/.rife/',
119
+ clear: () => {
120
+ console.clear();
121
+ process.stdout.write('\x1b[3J');
122
+ console.log(`${colors.bgBlue(' 项目名称 ')} ${runner.package.name} \n`);
123
+ },
124
+ throwError: (message?: string, options?: ErrorOptions) => {
125
+ throw new Error(message, options);
126
+ },
127
+ };
128
+
129
+ return runner;
130
+ }
131
+
132
+ export function defineConfig(all: Config[]) {
133
+ return all;
134
+ }
package/src/sync.ts CHANGED
@@ -1,63 +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/cli', //
28
- // '@rife/infra',
29
- '@rife/logger',
30
- // '@rife/react',
31
- // '@rife/next',
32
- // '@rife/nest',
33
- // '@rife/wxa',
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
- }
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,14 @@
1
+ import { fileURLToPath } from 'node:url';
2
+ import path from 'path';
3
+
4
+ import fs from 'fs-extra';
5
+ import * as glob from 'glob';
6
+
7
+ export { fs, glob };
8
+
9
+ export const getDuration = (perfStart: number) => {
10
+ const duration = ((performance.now() - perfStart) / 1000).toFixed(3);
11
+ return `耗时 ${duration} s`;
12
+ };
13
+
14
+ export const resolve = (...args: string[]) => path.resolve(path.dirname(fileURLToPath(import.meta.url)), ...args);
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/cli.js DELETED
@@ -1,18 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- const plugin_1 = require("./plugin");
4
- const runner_1 = require("./runner");
5
- const plugins = [
6
- (0, plugin_1.pluginPackage)(), //
7
- (0, plugin_1.pluginConfig)(),
8
- (0, plugin_1.pluginCommander)(),
9
- ];
10
- const runner = (0, runner_1.createRunner)();
11
- plugins.forEach(plugin => plugin.apply(runner));
12
- (async () => {
13
- await runner.hook.loadPackage.promise();
14
- await runner.hook.loadConfig.promise();
15
- await runner.hook.validateConfig.promise();
16
- await runner.hook.startCommand.promise();
17
- })();
18
- //# sourceMappingURL=cli.js.map
package/dist/cli.js.map DELETED
@@ -1 +0,0 @@
1
- {"version":3,"file":"cli.js","sourceRoot":"","sources":["../src/cli.ts"],"names":[],"mappings":";;AAAA,qCAAwE;AACxE,qCAAgD;AAEhD,MAAM,OAAO,GAAa;IACtB,IAAA,sBAAa,GAAE,EAAE,EAAE;IACnB,IAAA,qBAAY,GAAE;IACd,IAAA,wBAAe,GAAE;CACpB,CAAC;AAEF,MAAM,MAAM,GAAG,IAAA,qBAAY,GAAE,CAAC;AAE9B,OAAO,CAAC,OAAO,CAAC,MAAM,CAAC,EAAE,CAAC,MAAM,CAAC,KAAK,CAAC,MAAM,CAAC,CAAC,CAAC;AAEhD,CAAC,KAAK,IAAI,EAAE;IACR,MAAM,MAAM,CAAC,IAAI,CAAC,WAAW,CAAC,OAAO,EAAE,CAAC;IACxC,MAAM,MAAM,CAAC,IAAI,CAAC,UAAU,CAAC,OAAO,EAAE,CAAC;IACvC,MAAM,MAAM,CAAC,IAAI,CAAC,cAAc,CAAC,OAAO,EAAE,CAAC;IAC3C,MAAM,MAAM,CAAC,IAAI,CAAC,YAAY,CAAC,OAAO,EAAE,CAAC;AAC7C,CAAC,CAAC,EAAE,CAAC"}
package/dist/index.js DELETED
@@ -1,7 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- const tslib_1 = require("tslib");
4
- tslib_1.__exportStar(require("./runner"), exports);
5
- tslib_1.__exportStar(require("./plugin"), exports);
6
- tslib_1.__exportStar(require("./logger"), exports);
7
- //# sourceMappingURL=index.js.map
package/dist/index.js.map DELETED
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;AAAA,mDAAyB;AACzB,mDAAyB;AACzB,mDAAyB"}
package/dist/logger.js DELETED
@@ -1,26 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.createLogger = createLogger;
4
- const consola_1 = require("consola");
5
- function createLogger() {
6
- const instance = (0, consola_1.createConsola)({
7
- level: 4,
8
- // fancy: false,
9
- formatOptions: {
10
- // columns: 80,
11
- // colors: false,
12
- compact: false,
13
- date: false,
14
- },
15
- });
16
- const logger = {
17
- debug: (message, ...args) => instance.info(message, ...args),
18
- info: (message, ...args) => instance.info(message, ...args),
19
- error: (message, ...args) => instance.error(message, ...args),
20
- success: (message, ...args) => instance.success(message, ...args),
21
- fail: (message, ...args) => instance.fail(message, ...args),
22
- withTag: tag => instance.withTag(tag),
23
- };
24
- return logger;
25
- }
26
- //# sourceMappingURL=logger.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"logger.js","sourceRoot":"","sources":["../src/logger.ts"],"names":[],"mappings":";;AAWA,oCAsBC;AAjCD,qCAAwC;AAWxC,SAAgB,YAAY;IACxB,MAAM,QAAQ,GAAG,IAAA,uBAAa,EAAC;QAC3B,KAAK,EAAE,CAAC;QACR,gBAAgB;QAChB,aAAa,EAAE;YACX,eAAe;YACf,iBAAiB;YACjB,OAAO,EAAE,KAAK;YACd,IAAI,EAAE,KAAK;SACd;KACJ,CAAC,CAAC;IAEH,MAAM,MAAM,GAAW;QACnB,KAAK,EAAE,CAAC,OAAO,EAAE,GAAG,IAAI,EAAE,EAAE,CAAC,QAAQ,CAAC,IAAI,CAAC,OAAO,EAAE,GAAG,IAAI,CAAC;QAC5D,IAAI,EAAE,CAAC,OAAO,EAAE,GAAG,IAAI,EAAE,EAAE,CAAC,QAAQ,CAAC,IAAI,CAAC,OAAO,EAAE,GAAG,IAAI,CAAC;QAC3D,KAAK,EAAE,CAAC,OAAO,EAAE,GAAG,IAAI,EAAE,EAAE,CAAC,QAAQ,CAAC,KAAK,CAAC,OAAO,EAAE,GAAG,IAAI,CAAC;QAC7D,OAAO,EAAE,CAAC,OAAO,EAAE,GAAG,IAAI,EAAE,EAAE,CAAC,QAAQ,CAAC,OAAO,CAAC,OAAO,EAAE,GAAG,IAAI,CAAC;QACjE,IAAI,EAAE,CAAC,OAAO,EAAE,GAAG,IAAI,EAAE,EAAE,CAAC,QAAQ,CAAC,IAAI,CAAC,OAAO,EAAE,GAAG,IAAI,CAAC;QAC3D,OAAO,EAAE,GAAG,CAAC,EAAE,CAAC,QAAQ,CAAC,OAAO,CAAC,GAAG,CAAC;KACxC,CAAC;IAEF,OAAO,MAAM,CAAC;AAClB,CAAC"}
@@ -1,42 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.pluginCommander = pluginCommander;
4
- function pluginCommander() {
5
- const plugin = {
6
- name: pluginCommander.name,
7
- apply: runner => {
8
- const { hook, config, z } = runner;
9
- hook.startCommand.tapPromise(pluginCommander.name, async () => {
10
- const { Command } = require('commander');
11
- const program = new Command();
12
- program
13
- .command('dev')
14
- .option('-n, --name <string>', '', '')
15
- .description('启动开发')
16
- .action(async (options) => {
17
- await hook.applyConfig.promise(options);
18
- await hook.dev.promise();
19
- });
20
- program
21
- .command('build')
22
- .option('-n, --name <string>', '', '')
23
- .description('构建项目')
24
- .action(async (options) => {
25
- await hook.applyConfig.promise(options);
26
- await hook.build.promise();
27
- });
28
- program
29
- .command('release')
30
- .option('-n, --name <string>', '', '')
31
- .description('发布包')
32
- .action(async (options) => {
33
- await hook.applyConfig.promise(options);
34
- await hook.release.promise();
35
- });
36
- program.parseAsync(process.argv);
37
- });
38
- },
39
- };
40
- return plugin;
41
- }
42
- //# sourceMappingURL=commander.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"commander.js","sourceRoot":"","sources":["../../src/plugin/commander.ts"],"names":[],"mappings":";;AAEA,0CAyCC;AAzCD,SAAgB,eAAe;IAC3B,MAAM,MAAM,GAAW;QACnB,IAAI,EAAE,eAAe,CAAC,IAAI;QAC1B,KAAK,EAAE,MAAM,CAAC,EAAE;YACZ,MAAM,EAAE,IAAI,EAAE,MAAM,EAAE,CAAC,EAAE,GAAG,MAAM,CAAC;YAEnC,IAAI,CAAC,YAAY,CAAC,UAAU,CAAC,eAAe,CAAC,IAAI,EAAE,KAAK,IAAI,EAAE;gBAC1D,MAAM,EAAE,OAAO,EAAE,GAAG,OAAO,CAAC,WAAW,CAA+B,CAAC;gBACvE,MAAM,OAAO,GAAG,IAAI,OAAO,EAAE,CAAC;gBAC9B,OAAO;qBACF,OAAO,CAAC,KAAK,CAAC;qBACd,MAAM,CAAC,qBAAqB,EAAE,EAAE,EAAE,EAAE,CAAC;qBACrC,WAAW,CAAC,MAAM,CAAC;qBACnB,MAAM,CAAC,KAAK,EAAC,OAAO,EAAC,EAAE;oBACpB,MAAM,IAAI,CAAC,WAAW,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC;oBACxC,MAAM,IAAI,CAAC,GAAG,CAAC,OAAO,EAAE,CAAC;gBAC7B,CAAC,CAAC,CAAC;gBAEP,OAAO;qBACF,OAAO,CAAC,OAAO,CAAC;qBAChB,MAAM,CAAC,qBAAqB,EAAE,EAAE,EAAE,EAAE,CAAC;qBACrC,WAAW,CAAC,MAAM,CAAC;qBACnB,MAAM,CAAC,KAAK,EAAC,OAAO,EAAC,EAAE;oBACpB,MAAM,IAAI,CAAC,WAAW,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC;oBACxC,MAAM,IAAI,CAAC,KAAK,CAAC,OAAO,EAAE,CAAC;gBAC/B,CAAC,CAAC,CAAC;gBAEP,OAAO;qBACF,OAAO,CAAC,SAAS,CAAC;qBAClB,MAAM,CAAC,qBAAqB,EAAE,EAAE,EAAE,EAAE,CAAC;qBACrC,WAAW,CAAC,KAAK,CAAC;qBAClB,MAAM,CAAC,KAAK,EAAC,OAAO,EAAC,EAAE;oBACpB,MAAM,IAAI,CAAC,WAAW,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC;oBACxC,MAAM,IAAI,CAAC,OAAO,CAAC,OAAO,EAAE,CAAC;gBACjC,CAAC,CAAC,CAAC;gBAEP,OAAO,CAAC,UAAU,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC;YACrC,CAAC,CAAC,CAAC;QACP,CAAC;KACJ,CAAC;IACF,OAAO,MAAM,CAAC;AAClB,CAAC"}
@@ -1,166 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.compileTs = compileTs;
4
- exports.checkAndEmitType = checkAndEmitType;
5
- exports.formatDiagnostic = formatDiagnostic;
6
- const tslib_1 = require("tslib");
7
- const path_1 = tslib_1.__importDefault(require("path"));
8
- const utils_1 = require("consola/utils");
9
- const swc_1 = require("./swc");
10
- const tsc_1 = require("./tsc");
11
- const clear = () => {
12
- console.clear();
13
- process.stdout.write('\x1b[3J');
14
- };
15
- async function compileTs(runner, tsxConfig, { dev, build } = { dev: false, build: true }) {
16
- const { logger, fs } = runner;
17
- const log = logger.withTag(compileTs.name);
18
- log.debug('tsxConfig %j', tsxConfig);
19
- if (tsxConfig.clean) {
20
- log.info('清空目录 %s', tsxConfig.outDir);
21
- await fs.emptyDir(tsxConfig.outDir);
22
- }
23
- const showProjectName = () => {
24
- clear();
25
- console.log(`${utils_1.colors.bgBlue(' 项目名称 ')} ${runner.package.name} \n`);
26
- };
27
- if (tsxConfig.type === 'tsc') {
28
- const diagnostics = [];
29
- let perfStart = performance.now();
30
- (0, tsc_1.tsc)({
31
- ...tsxConfig,
32
- watch: dev,
33
- onWatchStatusChanged: data => {
34
- switch (data.status) {
35
- case 'startWatch': {
36
- diagnostics.length = 0;
37
- perfStart = performance.now();
38
- break;
39
- }
40
- case 'reCompile': {
41
- diagnostics.length = 0;
42
- perfStart = performance.now();
43
- if (dev) {
44
- // watch 模式下,第二次编译清空一下屏幕
45
- showProjectName();
46
- }
47
- break;
48
- }
49
- case 'error': {
50
- const duration = ((performance.now() - perfStart) / 1000).toFixed(3);
51
- log.error(`类型检查失败,耗时 ${duration} s\n\n%s`, formatDiagnostic(diagnostics));
52
- break;
53
- }
54
- case 'success': {
55
- const duration = ((performance.now() - perfStart) / 1000).toFixed(3);
56
- log.success(`编译成功,耗时 ${duration} s`);
57
- break;
58
- }
59
- default: {
60
- console.log(data);
61
- process.exit(1);
62
- }
63
- }
64
- },
65
- onReportDiagnostic: ({ diagnostic }) => {
66
- diagnostics.push(diagnostic);
67
- },
68
- onEmitDiagnostics: ({ diagnostics }) => {
69
- const duration = ((performance.now() - perfStart) / 1000).toFixed(3);
70
- if (diagnostics.length) {
71
- log.error(`编译失败,耗时 ${duration} s\n\n%s`, formatDiagnostic(diagnostics));
72
- runner.compiler.fail = true;
73
- }
74
- else {
75
- log.success(`编译成功,耗时 ${duration} s`);
76
- }
77
- },
78
- });
79
- return;
80
- }
81
- if (tsxConfig.type === 'swc') {
82
- const { promise, resolve } = Promise.withResolvers();
83
- (0, swc_1.swc)({
84
- ...tsxConfig,
85
- watch: dev,
86
- onSuccess: async ({ watch, first, duration }) => {
87
- if (watch && !first) {
88
- // watch 模式下,第二次编译清空一下屏幕
89
- showProjectName();
90
- }
91
- log.success(`编译成功,耗时 ${(duration / 1000).toFixed(3)} s`);
92
- if (dev) {
93
- // 启动文件钩子
94
- runner.compiler.hook.execMain.promise();
95
- }
96
- // 检查类型
97
- await runner.compiler.hook.checkAndEmitType.promise();
98
- resolve();
99
- },
100
- onFail: ({ watch, first, duration, reasons }) => {
101
- if (watch && !first) {
102
- // watch 模式下,第二次编译清空一下屏幕
103
- showProjectName();
104
- }
105
- const message = [...reasons.entries()]
106
- .map(([key, value]) => {
107
- const index = value.indexOf(key);
108
- if (index > -1) {
109
- return value.replace(key, path_1.default.resolve(key));
110
- }
111
- return `${value}`;
112
- })
113
- .join('\n');
114
- log.error(`编译失败,耗时 ${(duration / 1000).toFixed(3)} s\n\n%s`, message);
115
- runner.compiler.fail = true;
116
- resolve();
117
- },
118
- });
119
- if (build) {
120
- return promise;
121
- }
122
- return;
123
- }
124
- log.error(`compiler type '${tsxConfig.type}' 不存在`);
125
- process.exit(1);
126
- }
127
- function checkAndEmitType() {
128
- const perfStart = performance.now();
129
- const ts = require('typescript');
130
- const tsConfigPath = path_1.default.resolve('tsconfig.json');
131
- // 读取 tsconfig.json 文件
132
- const configFile = ts.readConfigFile(tsConfigPath, ts.sys.readFile);
133
- // 解析 tsconfig.json 文件
134
- const compilerOptions = ts.parseJsonConfigFileContent(configFile.config, ts.sys, path_1.default.dirname(tsConfigPath), {
135
- noEmit: true,
136
- incremental: false,
137
- });
138
- if (compilerOptions.options.declaration === true) {
139
- compilerOptions.options.noEmit = false;
140
- compilerOptions.options.emitDeclarationOnly = true;
141
- }
142
- // 获取编译器实例
143
- const host = ts.createCompilerHost(compilerOptions.options);
144
- const program = ts.createProgram(compilerOptions.fileNames, compilerOptions.options, host);
145
- // 执行编译
146
- const emitResult = program.emit();
147
- // 处理编译结果
148
- const diagnostics = ts.getPreEmitDiagnostics(program).concat(emitResult.diagnostics);
149
- const duration = ((performance.now() - perfStart) / 1000).toFixed(3);
150
- return { diagnostics, duration };
151
- }
152
- function formatDiagnostic(diagnostics) {
153
- const ts = require('typescript');
154
- const { colors } = require('consola/utils');
155
- return diagnostics
156
- .map(diagnostic => {
157
- const message = ts.flattenDiagnosticMessageText(diagnostic.messageText, '\n');
158
- if (diagnostic.file) {
159
- const { line, character } = diagnostic.file.getLineAndCharacterOfPosition(diagnostic.start);
160
- return `${colors.gray(diagnostic.file.fileName)} ${colors.yellow(`(${line + 1},${character + 1})`)}: ${colors.white(message)}`;
161
- }
162
- return message;
163
- })
164
- .join('\n');
165
- }
166
- //# sourceMappingURL=compiler.js.map