@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.
- package/dist/1.js +24 -0
- package/dist/1.mjs +20 -0
- package/dist/cjs/1.js +24 -0
- package/dist/cli.js +4 -0
- package/dist/cli.js.map +1 -1
- package/dist/esm/1.mjs +20 -0
- package/dist/index.js +3 -0
- package/dist/index.js.map +1 -1
- package/dist/logger.js +3 -11
- package/dist/logger.js.map +1 -1
- package/dist/plugin/commander.js +22 -17
- package/dist/plugin/commander.js.map +1 -1
- package/dist/plugin/compiler/index.js +8 -4
- package/dist/plugin/compiler/index.js.map +1 -1
- package/dist/plugin/compiler/swc.js +2 -1
- package/dist/plugin/compiler/swc.js.map +1 -1
- package/dist/plugin/compiler/swc2.js +65 -0
- package/dist/plugin/compiler/swc2.js.map +1 -0
- package/dist/plugin/config.js +25 -9
- package/dist/plugin/config.js.map +1 -1
- package/dist/plugin/index.js +1 -0
- package/dist/plugin/index.js.map +1 -1
- package/dist/plugin/package copy.js.map +1 -1
- package/dist/plugin/package.js.map +1 -1
- package/dist/plugin/release.js +84 -14
- package/dist/plugin/release.js.map +1 -1
- package/dist/runner.js +33 -4
- package/dist/runner.js.map +1 -1
- package/dist/sync.js +4 -3
- package/dist/sync.js.map +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/dist/util.js +14 -0
- package/dist/util.js.map +1 -0
- package/package.json +27 -26
- package/src/cli.ts +23 -19
- package/src/index.ts +13 -3
- package/src/logger.ts +16 -34
- package/src/plugin/commander.ts +49 -44
- package/src/plugin/compiler/index.ts +115 -109
- package/src/plugin/compiler/swc.ts +56 -55
- package/src/plugin/compiler/tsc.ts +101 -101
- package/src/plugin/config.ts +78 -63
- package/src/plugin/index.ts +1 -0
- package/src/plugin/package.ts +0 -3
- package/src/plugin/release.ts +113 -32
- package/src/runner.ts +130 -88
- package/src/sync.ts +63 -62
- package/src/util.ts +9 -0
- package/dist/build.js +0 -3
- package/dist/build.js.map +0 -1
- package/dist/compiler.js +0 -82
- package/dist/compiler.js.map +0 -1
- package/dist/plugin.js +0 -161
- package/dist/plugin.js.map +0 -1
- package/dist/pnpmfile.js +0 -144
- package/dist/swc.js +0 -78
- package/dist/swc.js.map +0 -1
- package/dist/tsc.js +0 -94
- package/dist/tsc.js.map +0 -1
- package/src/build.ts +0 -0
- package/src/pnpmfile.ts +0 -121
- 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
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
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
|
+
}
|
package/src/plugin/commander.ts
CHANGED
|
@@ -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.
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
.
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
.
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
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
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
const
|
|
33
|
-
const
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
.
|
|
48
|
-
.
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
const
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
if (runner.compiler.fail) {
|
|
76
|
-
log.fail(
|
|
77
|
-
process.exit(1);
|
|
78
|
-
} else {
|
|
79
|
-
log.success(
|
|
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
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
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
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
first
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
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
|
+
}
|