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

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 +3 -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 +8 -4
  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 -4
  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 +27 -26
  35. package/src/cli.ts +23 -19
  36. package/src/index.ts +13 -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 +130 -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/logger.ts CHANGED
@@ -1,34 +1,16 @@
1
- import { createConsola } from 'consola';
2
-
3
- export interface Logger {
4
- debug: (message: string, ...args: any[]) => any;
5
- info: (message: string, ...args: any[]) => any;
6
- error: (message: string, ...args: any[]) => any;
7
- success: (message: string, ...args: any[]) => any;
8
- fail: (message: string, ...args: any[]) => any;
9
- withTag: (tag: string) => Logger;
10
- }
11
-
12
- export function createLogger() {
13
- const instance = createConsola({
14
- level: 4,
15
- // fancy: false,
16
- formatOptions: {
17
- // columns: 80,
18
- // colors: false,
19
- compact: false,
20
- date: false,
21
- },
22
- });
23
-
24
- const logger: Logger = {
25
- debug: (message, ...args) => instance.info(message, ...args),
26
- info: (message, ...args) => instance.info(message, ...args),
27
- error: (message, ...args) => instance.error(message, ...args),
28
- success: (message, ...args) => instance.success(message, ...args),
29
- fail: (message, ...args) => instance.fail(message, ...args),
30
- withTag: tag => instance.withTag(tag),
31
- };
32
-
33
- return logger;
34
- }
1
+ import { createConsola } from 'consola';
2
+
3
+ export function createLogger(options?: { debug?: boolean }) {
4
+ const instance = createConsola({
5
+ level: options?.debug ? 4 : 3,
6
+ // fancy: false,
7
+ formatOptions: {
8
+ // columns: 80,
9
+ // colors: false,
10
+ compact: false,
11
+ date: false,
12
+ },
13
+ });
14
+
15
+ return instance;
16
+ }
@@ -1,44 +1,49 @@
1
- import type { Plugin } from '../runner';
2
-
3
- export function pluginCommander() {
4
- const plugin: Plugin = {
5
- name: pluginCommander.name,
6
- apply: runner => {
7
- const { hook, config, z } = runner;
8
-
9
- hook.startCommand.tapPromise(pluginCommander.name, async () => {
10
- const { Command } = require('commander') as typeof import('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
-
21
- program
22
- .command('build')
23
- .option('-n, --name <string>', '', '')
24
- .description('构建项目')
25
- .action(async options => {
26
- await hook.applyConfig.promise(options);
27
- await hook.build.promise();
28
- });
29
-
30
- program
31
- .command('release')
32
- .option('-n, --name <string>', '', '')
33
- .description('发布包')
34
- .action(async options => {
35
- await hook.applyConfig.promise(options);
36
- await hook.release.promise();
37
- });
38
-
39
- program.parseAsync(process.argv);
40
- });
41
- },
42
- };
43
- return plugin;
44
- }
1
+ import type { Plugin } from '../runner';
2
+
3
+ export function pluginCommander() {
4
+ const plugin: Plugin = {
5
+ name: pluginCommander.name,
6
+ apply: runner => {
7
+ const { hook, command, config, z, logger } = runner;
8
+ const log = logger.withTag(pluginCommander.name);
9
+ hook.registerCommand.tapPromise(pluginCommander.name, async () => {
10
+ command
11
+ .command('dev')
12
+ .description('启动开发')
13
+ .action(async () => {
14
+ process.env.NODE_ENV = 'development';
15
+ await hook.dev.promise();
16
+ });
17
+
18
+ command
19
+ .command('build')
20
+ .description('构建项目')
21
+ .action(async () => {
22
+ process.env.NODE_ENV = 'production';
23
+ await hook.build.promise();
24
+ });
25
+
26
+ command
27
+ .command('release')
28
+ .description('发布包')
29
+ .action(async () => {
30
+ await hook.release.promise();
31
+ });
32
+
33
+ command
34
+ .command('deploy')
35
+ .description('部署项目')
36
+ .action(async () => {
37
+ await hook.deploy.promise().catch(e => {
38
+ log.fail(`部署失败,${runner.duration},${e.message}`);
39
+ });
40
+ });
41
+ });
42
+
43
+ hook.startCommand.tapPromise(pluginCommander.name, async () => {
44
+ await command.parseAsync(process.argv);
45
+ });
46
+ },
47
+ };
48
+ return plugin;
49
+ }
@@ -1,109 +1,115 @@
1
- import type { ChildProcess } from 'child_process';
2
-
3
- import { AsyncSeriesHook } from 'tapable';
4
-
5
- import { TsxConfig, checkAndEmitType, compileTs, formatDiagnostic } from './compiler';
6
- import type { Plugin } from '../../runner';
7
-
8
- declare module '../../runner' {
9
- interface Runner {
10
- compiler: {
11
- fail: boolean;
12
- process: ChildProcess | null;
13
- hook: {
14
- checkAndEmitType: AsyncSeriesHook<[]>;
15
- execMain: AsyncSeriesHook<[]>;
16
- };
17
- tsx: TsxConfig;
18
- };
19
- }
20
- }
21
-
22
- export interface pluginCompilerOptions {
23
- tsx?: Partial<TsxConfig>;
24
- less?: {};
25
- }
26
-
27
- export function pluginCompiler(options?: pluginCompilerOptions) {
28
- const plugin: Plugin = {
29
- name: pluginCompiler.name,
30
- apply: runner => {
31
- const { hook, logger, z, tapable } = runner;
32
- const log = logger.withTag(pluginCompiler.name);
33
- const validation = z
34
- .object({
35
- tsx: z
36
- .object({
37
- type: z.enum(['tsc', 'swc']).default('swc'),
38
- rootDir: z.string().trim().min(1).default('.'),
39
- outDir: z.string().trim().min(1).default('./dist/'),
40
- clean: z.boolean().default(true),
41
- main: z.string().trim().optional(),
42
- options: z.object({}).passthrough().optional(),
43
- })
44
- .default({}),
45
- })
46
- .optional()
47
- .default({})
48
- .safeParse(options);
49
-
50
- if (!validation.success) {
51
- log.error('配置错误\n', validation.error.message);
52
- process.exit(1);
53
- }
54
-
55
- runner.compiler = {
56
- fail: false,
57
- process: null,
58
- hook: {
59
- checkAndEmitType: new tapable.AsyncSeriesHook(),
60
- execMain: new tapable.AsyncSeriesHook(),
61
- },
62
- tsx: validation.data.tsx,
63
- };
64
-
65
- hook.dev.tapPromise(pluginCompiler.name, async () => {
66
- const tsxConfig: TsxConfig = validation.data.tsx;
67
- compileTs(runner, tsxConfig, { dev: true });
68
- });
69
-
70
- hook.build.tapPromise(pluginCompiler.name, async () => {
71
- const perfStart = performance.now();
72
- const tsxConfig: TsxConfig = validation.data.tsx;
73
- await compileTs(runner, tsxConfig, { build: true });
74
- const duration = ((performance.now() - perfStart) / 1000).toFixed(3);
75
- if (runner.compiler.fail) {
76
- log.fail(`构建失败,耗时 ${duration} s`);
77
- process.exit(1);
78
- } else {
79
- log.success(`构建成功,耗时 ${duration} s`);
80
- }
81
- });
82
-
83
- runner.compiler.hook.checkAndEmitType.tapPromise(pluginCompiler.name, async () => {
84
- const { diagnostics, duration } = checkAndEmitType();
85
- if (diagnostics.length) {
86
- log.error(`类型检查失败,耗时 ${duration} s\n\n%s`, formatDiagnostic(diagnostics));
87
- runner.compiler.fail = true;
88
- } else {
89
- log.success(`类型检查成功,耗时 ${duration} s`);
90
- }
91
- });
92
-
93
- runner.compiler.hook.execMain.tapPromise(pluginCompiler.name, async () => {
94
- const compiler = runner.compiler;
95
- const { main } = compiler.tsx;
96
- if (!main) {
97
- log.debug('没有指定 main');
98
- return;
99
- }
100
- log.info(`启动文件 node %s`, main);
101
-
102
- const { fork } = require('child_process') as typeof import('child_process');
103
- compiler.process?.kill();
104
- compiler.process = fork(main, { stdio: 'inherit' });
105
- });
106
- },
107
- };
108
- return plugin;
109
- }
1
+ import type { ChildProcess } from 'child_process';
2
+
3
+ import { AsyncSeriesHook } from 'tapable';
4
+
5
+ import { TsxConfig, checkAndEmitType, compileTs, formatDiagnostic } from './compiler';
6
+ import type { Plugin } from '../../runner';
7
+ import { getDuration } from '../../util';
8
+
9
+ declare module '../../runner' {
10
+ interface Runner {
11
+ compiler: {
12
+ fail: boolean;
13
+ process: ChildProcess | null;
14
+ hook: {
15
+ checkAndEmitType: AsyncSeriesHook<[]>;
16
+ execMain: AsyncSeriesHook<[]>;
17
+ };
18
+ tsx: TsxConfig;
19
+ };
20
+ }
21
+ }
22
+
23
+ export interface pluginCompilerOptions {
24
+ tsx?: Partial<TsxConfig>;
25
+ less?: {};
26
+ }
27
+
28
+ export function pluginCompiler(options?: pluginCompilerOptions) {
29
+ const plugin: Plugin = {
30
+ name: pluginCompiler.name,
31
+ apply: runner => {
32
+ const { hook, logger, z, tapable, fs } = runner;
33
+ const log = logger.withTag(pluginCompiler.name);
34
+ const validation = z
35
+ .object({
36
+ tsx: z
37
+ .object({
38
+ type: z.enum(['tsc', 'swc']).default('swc'),
39
+ rootDir: z.string().trim().min(1).default('.'),
40
+ outDir: z.string().trim().min(1).default('./dist/'),
41
+ clean: z.boolean().default(true),
42
+ main: z.string().trim().optional(),
43
+ options: z.object({}).passthrough().optional(),
44
+ })
45
+ .default({}),
46
+ })
47
+ .optional()
48
+ .default({})
49
+ .safeParse(options);
50
+
51
+ if (!validation.success) {
52
+ log.error('配置错误\n', validation.error.message);
53
+ process.exit(1);
54
+ }
55
+
56
+ runner.compiler = {
57
+ fail: false,
58
+ process: null,
59
+ hook: {
60
+ checkAndEmitType: new tapable.AsyncSeriesHook(),
61
+ execMain: new tapable.AsyncSeriesHook(),
62
+ },
63
+ tsx: validation.data.tsx,
64
+ };
65
+
66
+ hook.dev.tapPromise(pluginCompiler.name, async () => {
67
+ const tsxConfig: TsxConfig = validation.data.tsx;
68
+ compileTs(runner, tsxConfig, { dev: true });
69
+ });
70
+
71
+ hook.build.tapPromise(pluginCompiler.name, async () => {
72
+ const perfStart = performance.now();
73
+ const tsxConfig: TsxConfig = validation.data.tsx;
74
+ await compileTs(runner, tsxConfig, { build: true });
75
+ if (runner.compiler.fail) {
76
+ log.fail(`构建失败,${getDuration(perfStart)}`);
77
+ process.exit(1);
78
+ } else {
79
+ log.success(`构建成功,${getDuration(perfStart)}`);
80
+ }
81
+ });
82
+
83
+ runner.compiler.hook.checkAndEmitType.tapPromise(pluginCompiler.name, async () => {
84
+ const { diagnostics, duration } = checkAndEmitType();
85
+ if (diagnostics.length) {
86
+ log.error(`类型检查失败,耗时 ${duration} s\n\n%s`, formatDiagnostic(diagnostics));
87
+ runner.compiler.fail = true;
88
+ } else {
89
+ log.success(`类型检查成功,耗时 ${duration} s`);
90
+ }
91
+ });
92
+
93
+ runner.compiler.hook.execMain.tapPromise(pluginCompiler.name, async () => {
94
+ const compiler = runner.compiler;
95
+ const { main } = compiler.tsx;
96
+ if (!main) {
97
+ log.debug('没有指定 main');
98
+ return;
99
+ }
100
+
101
+ if (!(await fs.exists(main))) {
102
+ log.warn(`启动文件不存在 %s`, main);
103
+ return;
104
+ }
105
+
106
+ log.info(`启动文件 node %s`, main);
107
+
108
+ const { fork } = require('child_process') as typeof import('child_process');
109
+ compiler.process?.kill();
110
+ compiler.process = fork(main, { stdio: 'inherit' });
111
+ });
112
+ },
113
+ };
114
+ return plugin;
115
+ }
@@ -1,55 +1,56 @@
1
- import type { TsxConfig } from './compiler';
2
-
3
- export interface SwcConfig extends TsxConfig {
4
- watch?: boolean;
5
- options?: any;
6
- onSuccess?: (data: { watch: boolean; first: boolean; duration: number }) => any;
7
- onFail?: (data: { watch: boolean; first: boolean; duration: number; reasons: Map<string, string> }) => any;
8
- }
9
-
10
- export async function swc(options: SwcConfig) {
11
- const { watch = false, outDir } = options;
12
- const { swcDir } = require('@swc/cli');
13
-
14
- // https://swc.rs/docs/configuration/swcrc
15
- const swcOptions = {
16
- jsc: {
17
- parser: {
18
- syntax: 'typescript',
19
- },
20
- target: 'esnext',
21
- externalHelpers: true,
22
- },
23
- module: {
24
- type: 'commonjs',
25
- // type: 'es6',
26
- ignoreDynamic: true,
27
- },
28
- sourceMaps: true,
29
- };
30
-
31
- let first = true;
32
-
33
- await swcDir({
34
- cliOptions: {
35
- outDir,
36
- watch,
37
- filenames: ['./src'],
38
- extensions: ['.ts', '.tsx'],
39
- stripLeadingPaths: true,
40
- },
41
- swcOptions,
42
- callbacks: {
43
- onSuccess: ({ duration }: any) => {
44
- options?.onSuccess?.({ watch, first, duration });
45
- first = false;
46
- },
47
- onFail: (e: any) => {
48
- options?.onFail?.({ ...e, watch, first });
49
- // 不退出,下次修复报错后清空屏幕
50
- first = false;
51
- },
52
- onWatchReady: () => {},
53
- },
54
- });
55
- }
1
+ import type { TsxConfig } from './compiler';
2
+
3
+ export interface SwcConfig extends TsxConfig {
4
+ watch?: boolean;
5
+ options?: any;
6
+ onSuccess?: (data: { watch: boolean; first: boolean; duration: number }) => any;
7
+ onFail?: (data: { watch: boolean; first: boolean; duration: number; reasons: Map<string, string> }) => any;
8
+ }
9
+
10
+ export async function swc(options: SwcConfig) {
11
+ const { watch = false, outDir } = options;
12
+ const { swcDir } = require('@swc/cli');
13
+
14
+ // https://swc.rs/docs/configuration/swcrc
15
+ const swcOptions = {
16
+ jsc: {
17
+ parser: {
18
+ syntax: 'typescript',
19
+ },
20
+ target: 'esnext',
21
+ externalHelpers: true,
22
+ },
23
+ module: {
24
+ type: 'commonjs',
25
+ // type: 'es6',
26
+ ignoreDynamic: true,
27
+ },
28
+ sourceMaps: true,
29
+ };
30
+
31
+ let first = true;
32
+
33
+ await swcDir({
34
+ cliOptions: {
35
+ outDir,
36
+ watch,
37
+ filenames: ['./src'],
38
+ extensions: ['.ts', '.tsx', '.js', '.jsx'],
39
+ stripLeadingPaths: true,
40
+ copyFiles: true,
41
+ },
42
+ swcOptions,
43
+ callbacks: {
44
+ onSuccess: ({ duration }: any) => {
45
+ options?.onSuccess?.({ watch, first, duration });
46
+ first = false;
47
+ },
48
+ onFail: (e: any) => {
49
+ options?.onFail?.({ ...e, watch, first });
50
+ // 不退出,下次修复报错后清空屏幕
51
+ first = false;
52
+ },
53
+ onWatchReady: () => {},
54
+ },
55
+ });
56
+ }