@rife/cli 0.0.6-beta.7 → 0.0.6-beta.9

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 (43) 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 +1 -2
  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/plugin/commander.js +2 -0
  10. package/dist/plugin/commander.js.map +1 -1
  11. package/dist/plugin/compiler/index.js +3 -3
  12. package/dist/plugin/compiler/index.js.map +1 -1
  13. package/dist/plugin/compiler/swc.js +2 -1
  14. package/dist/plugin/compiler/swc.js.map +1 -1
  15. package/dist/plugin/compiler/swc2.js +65 -0
  16. package/dist/plugin/compiler/swc2.js.map +1 -0
  17. package/dist/plugin/config.js +20 -5
  18. package/dist/plugin/config.js.map +1 -1
  19. package/dist/plugin/index.js +1 -0
  20. package/dist/plugin/index.js.map +1 -1
  21. package/dist/plugin/release.js +38 -24
  22. package/dist/plugin/release.js.map +1 -1
  23. package/dist/runner.js +9 -3
  24. package/dist/runner.js.map +1 -1
  25. package/dist/sync.js +3 -3
  26. package/dist/sync.js.map +1 -1
  27. package/dist/tsconfig.tsbuildinfo +1 -1
  28. package/dist/util.js +14 -0
  29. package/dist/util.js.map +1 -0
  30. package/package.json +23 -23
  31. package/src/cli.ts +1 -2
  32. package/src/index.ts +4 -0
  33. package/src/plugin/commander.ts +2 -0
  34. package/src/plugin/compiler/index.ts +115 -115
  35. package/src/plugin/compiler/swc.ts +2 -1
  36. package/src/plugin/config.ts +78 -64
  37. package/src/plugin/index.ts +1 -0
  38. package/src/plugin/release.ts +42 -26
  39. package/src/runner.ts +10 -3
  40. package/src/sync.ts +3 -3
  41. package/src/util.ts +9 -0
  42. package/src/pnpmfile.ts +0 -147
  43. package/src/test/pnpmfile.test.ts +0 -223
@@ -1,115 +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, fs } = 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
-
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
+ 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
+ }
@@ -35,8 +35,9 @@ export async function swc(options: SwcConfig) {
35
35
  outDir,
36
36
  watch,
37
37
  filenames: ['./src'],
38
- extensions: ['.ts', '.tsx'],
38
+ extensions: ['.ts', '.tsx', '.js', '.jsx'],
39
39
  stripLeadingPaths: true,
40
+ copyFiles: true,
40
41
  },
41
42
  swcOptions,
42
43
  callbacks: {
@@ -1,64 +1,78 @@
1
- import path from 'path';
2
-
3
- import type { Config, Plugin } from '../runner';
4
-
5
- export function pluginConfig() {
6
- const plugin: Plugin = {
7
- name: pluginConfig.name,
8
- apply: runner => {
9
- const { logger, hook, config, command, fs, z } = runner;
10
- const log = logger.withTag(pluginConfig.name);
11
-
12
- hook.loadConfig.tapPromise(pluginConfig.name, async () => {
13
- const fileName = '.app.js';
14
- const filePath = path.posix.resolve(fileName);
15
- log.debug(`filePath %s`, filePath);
16
- if (!fs.existsSync(filePath)) {
17
- log.error(`找不到配置文件 ${fileName}`);
18
- process.exit(1);
19
- }
20
- const all: Config[] = require(filePath);
21
- runner.config.all = all;
22
- });
23
-
24
- hook.validateConfig.tapPromise(pluginConfig.name, async () => {
25
- const validation = z
26
- .array(
27
- z.object({
28
- name: z.string().trim().min(1),
29
- }),
30
- )
31
- .min(1)
32
- .safeParse(config.all);
33
- if (!validation.success) {
34
- log.error(validation.error.message);
35
- process.exit(1);
36
- }
37
- });
38
-
39
- hook.applyConfig.tapPromise(pluginConfig.name, async () => {
40
- const result = z
41
- .object({
42
- name: z.string().trim().default(''),
43
- })
44
- .default({})
45
- .safeParse(command.opts());
46
- const name = result.data?.name;
47
- if (!name) {
48
- log.debug('没有指定 --name,默认使用列表第一个');
49
- config.current = config.all[0];
50
- } else {
51
- log.debug(`指定 --name ${name}`);
52
- const find = config.all.find(t => t.name === name);
53
- if (!find) {
54
- log.error(`未找到 name '%s'`, name);
55
- process.exit(1);
56
- }
57
- config.current = find;
58
- }
59
- config.current.plugins.forEach(plugin => plugin.apply(runner));
60
- });
61
- },
62
- };
63
- return plugin;
64
- }
1
+ import path from 'path';
2
+
3
+ import type { Config, Plugin } from '../runner';
4
+
5
+ export function pluginConfig() {
6
+ const plugin: Plugin = {
7
+ name: pluginConfig.name,
8
+ apply: runner => {
9
+ const { logger, hook, config, command, fs, z } = runner;
10
+ const log = logger.withTag(pluginConfig.name);
11
+
12
+ hook.loadConfig.tapPromise(pluginConfig.name, async () => {
13
+ let filePath = '';
14
+ const mjs = 'app.mjs';
15
+ const fileNames = ['app.js', 'app.cjs', mjs];
16
+ let isEsm = false;
17
+ for (const fileName of fileNames) {
18
+ if (await fs.exists(fileName)) {
19
+ filePath = path.posix.resolve(fileName);
20
+ isEsm = fileName === mjs;
21
+ break;
22
+ }
23
+ }
24
+ log.debug(`filePath %s`, filePath);
25
+ if (!filePath) {
26
+ log.error(`找不到配置文件 app.(c|m)?js`);
27
+ process.exit(1);
28
+ }
29
+ let all: Config[] = [];
30
+ if (isEsm) {
31
+ all = (await import(filePath)).default;
32
+ } else {
33
+ all = require(filePath);
34
+ }
35
+ runner.config.all = all;
36
+ });
37
+
38
+ hook.validateConfig.tapPromise(pluginConfig.name, async () => {
39
+ const validation = z
40
+ .array(
41
+ z.object({
42
+ name: z.string().trim().min(1),
43
+ }),
44
+ )
45
+ .min(1)
46
+ .safeParse(config.all);
47
+ if (!validation.success) {
48
+ log.error(validation.error.message);
49
+ process.exit(1);
50
+ }
51
+ });
52
+
53
+ hook.applyConfig.tapPromise(pluginConfig.name, async () => {
54
+ const result = z
55
+ .object({
56
+ name: z.string().trim().default(''),
57
+ })
58
+ .default({})
59
+ .safeParse(command.opts());
60
+ const name = result.data?.name;
61
+ if (!name) {
62
+ log.debug('没有指定 --name,默认使用列表第一个');
63
+ config.current = config.all[0];
64
+ } else {
65
+ log.debug(`指定 --name ${name}`);
66
+ const find = config.all.find(t => t.name === name);
67
+ if (!find) {
68
+ log.error(`未找到 name '%s'`, name);
69
+ process.exit(1);
70
+ }
71
+ config.current = find;
72
+ }
73
+ config.current.plugins.forEach(plugin => plugin.apply(runner));
74
+ });
75
+ },
76
+ };
77
+ return plugin;
78
+ }
@@ -2,3 +2,4 @@ export * from './config';
2
2
  export * from './package';
3
3
  export * from './commander';
4
4
  export * from './compiler';
5
+ export * from './release';
@@ -1,4 +1,4 @@
1
- import { exec, execSync } from 'child_process';
1
+ import { execSync } from 'child_process';
2
2
 
3
3
  import type { Plugin } from '../runner';
4
4
 
@@ -48,38 +48,27 @@ export function pluginRelease() {
48
48
  log.success(`发布成功,${runner.duration}`);
49
49
 
50
50
  log.info('同步版本');
51
+ let hasSync = false;
51
52
  while (true) {
52
- const res = await (await fetch(`https://registry.npmmirror.com/${packageName}`)).json();
53
+ const res = await queryVersion(packageName);
53
54
  const exist = Boolean(res?.versions?.[nextVersion]);
55
+ const latest = res?.['dist-tags']?.latest;
54
56
  if (exist) {
55
57
  log.debug(`同步版本存在`);
56
58
  break;
57
59
  }
58
- log.debug(`同步版本不存在,开始同步`);
59
- const sync = await (
60
- await fetch(`https://registry-direct.npmmirror.com/-/package/${packageName}/syncs`, {
61
- headers: {
62
- accept: '*/*',
63
- 'accept-language': 'zh-CN,zh;q=0.9,en;q=0.8',
64
- 'sec-ch-ua': '"Not_A Brand";v="8", "Chromium";v="120", "Google Chrome";v="120"',
65
- 'sec-ch-ua-mobile': '?0',
66
- 'sec-ch-ua-platform': '"Windows"',
67
- 'sec-fetch-dest': 'empty',
68
- 'sec-fetch-mode': 'cors',
69
- 'sec-fetch-site': 'same-site',
70
- Referer: 'https://npmmirror.com/',
71
- 'Referrer-Policy': 'strict-origin-when-cross-origin',
72
- },
73
- body: null,
74
- method: 'PUT',
75
- })
76
- ).json();
77
- if (sync.ok === true) {
78
- log.debug(`同步成功`);
79
- } else {
80
- log.debug(`同步失败,%j`, sync);
60
+ log.info(`同步版本 ${nextVersion} 不存在,最新版本为 ${latest}`);
61
+ if (!hasSync) {
62
+ log.debug(`开始同步`);
63
+ const sync = await syncVersion(packageName);
64
+ if (sync.ok === true) {
65
+ log.debug(`调用同步接口成功`);
66
+ hasSync = true;
67
+ } else {
68
+ log.debug(`调用同步接口失败,%j`, sync);
69
+ }
81
70
  }
82
- await new Promise(resolve => setTimeout(resolve, 1000));
71
+ await new Promise(resolve => setTimeout(resolve, 500));
83
72
  }
84
73
  log.success(`同步成功,${runner.duration}`);
85
74
  });
@@ -87,3 +76,30 @@ export function pluginRelease() {
87
76
  };
88
77
  return plugin;
89
78
  }
79
+
80
+ async function queryVersion(packageName: string) {
81
+ const res = await (await fetch(`https://registry.npmmirror.com/${packageName}`)).json();
82
+ return res;
83
+ }
84
+
85
+ async function syncVersion(packageName: string) {
86
+ const sync = await (
87
+ await fetch(`https://registry-direct.npmmirror.com/-/package/${packageName}/syncs`, {
88
+ headers: {
89
+ accept: '*/*',
90
+ 'accept-language': 'zh-CN,zh;q=0.9,en;q=0.8',
91
+ 'sec-ch-ua': '"Not_A Brand";v="8", "Chromium";v="120", "Google Chrome";v="120"',
92
+ 'sec-ch-ua-mobile': '?0',
93
+ 'sec-ch-ua-platform': '"Windows"',
94
+ 'sec-fetch-dest': 'empty',
95
+ 'sec-fetch-mode': 'cors',
96
+ 'sec-fetch-site': 'same-site',
97
+ Referer: 'https://npmmirror.com/',
98
+ 'Referrer-Policy': 'strict-origin-when-cross-origin',
99
+ },
100
+ body: null,
101
+ method: 'PUT',
102
+ })
103
+ ).json();
104
+ return sync;
105
+ }
package/src/runner.ts CHANGED
@@ -1,9 +1,10 @@
1
1
  import type { ConsolaInstance } from 'consola';
2
- import * as glob from 'glob';
2
+ import { colors } from 'consola/utils';
3
3
  import { AsyncSeriesHook } from 'tapable';
4
4
  import zod from 'zod';
5
5
 
6
6
  import { createLogger } from './logger';
7
+ import { fs, glob } from './util';
7
8
 
8
9
  export interface Config {
9
10
  name: string;
@@ -37,10 +38,11 @@ export interface Runner {
37
38
  package: any;
38
39
  z: typeof zod;
39
40
  fs: typeof import('fs-extra');
40
- glob: (typeof import('glob'))['glob'];
41
+ glob: typeof import('glob')['glob'];
41
42
  tapable: typeof import('tapable');
42
43
  duration: string;
43
44
  tempDir: string;
45
+ clear: () => void;
44
46
  }
45
47
 
46
48
  export interface Plugin {
@@ -105,7 +107,7 @@ export function createRunner() {
105
107
  },
106
108
  package: {},
107
109
  z: zod,
108
- fs: require('fs-extra') as typeof import('fs-extra'),
110
+ fs,
109
111
  glob: glob.glob,
110
112
  tapable: require('tapable') as typeof import('tapable'),
111
113
  get duration() {
@@ -113,6 +115,11 @@ export function createRunner() {
113
115
  return `耗时 ${duration} s`;
114
116
  },
115
117
  tempDir: './node_modules/.temp/',
118
+ clear: () => {
119
+ console.clear();
120
+ process.stdout.write('\x1b[3J');
121
+ console.log(`${colors.bgBlue(' 项目名称 ')} ${runner.package.name} \n`);
122
+ },
116
123
  };
117
124
 
118
125
  return runner;
package/src/sync.ts CHANGED
@@ -26,12 +26,12 @@ const list = [
26
26
  '@rife/config', //
27
27
  '@rife/cli', //
28
28
  // '@rife/infra',
29
- '@rife/logger',
29
+ // '@rife/logger',
30
30
  // '@rife/react',
31
31
  // '@rife/next',
32
32
  // '@rife/nest',
33
- '@rife/plugin-deploy',
34
- '@rife/fast',
33
+ // '@rife/plugin-deploy',
34
+ // '@rife/fast',
35
35
  ];
36
36
 
37
37
  async function main() {
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
+ };