@rife/cli 0.0.6-beta.4 → 0.0.6-beta.6
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/cli.js +5 -0
- package/dist/cli.js.map +1 -1
- package/dist/logger.js +3 -11
- package/dist/logger.js.map +1 -1
- package/dist/plugin/commander.js +20 -17
- package/dist/plugin/commander.js.map +1 -1
- package/dist/plugin/compiler/index.js +5 -1
- package/dist/plugin/compiler/index.js.map +1 -1
- package/dist/plugin/config.js +5 -4
- package/dist/plugin/config.js.map +1 -1
- package/dist/plugin/package copy.js +32 -0
- package/dist/plugin/package copy.js.map +1 -0
- package/dist/plugin/package.js.map +1 -1
- package/dist/plugin/release.js +66 -14
- package/dist/plugin/release.js.map +1 -1
- package/dist/runner.js +26 -3
- package/dist/runner.js.map +1 -1
- package/dist/sync.js +1 -1
- package/dist/sync.js.map +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +6 -5
- package/src/cli.ts +5 -0
- package/src/index.ts +6 -0
- package/src/logger.ts +3 -21
- package/src/plugin/commander.ts +21 -18
- package/src/plugin/compiler/index.ts +7 -1
- package/src/plugin/config.ts +5 -4
- package/src/plugin/package.ts +0 -3
- package/src/plugin/release.ts +73 -16
- package/src/runner.ts +42 -7
- package/src/sync.ts +1 -1
- package/dist/build.js +0 -3
- package/dist/build.js.map +0 -1
- package/dist/pnpmfile.js +0 -153
- package/src/build.ts +0 -0
package/src/plugin/release.ts
CHANGED
|
@@ -1,7 +1,4 @@
|
|
|
1
|
-
import
|
|
2
|
-
import path from 'path';
|
|
3
|
-
|
|
4
|
-
import { AsyncSeriesHook } from 'tapable';
|
|
1
|
+
import { exec, execSync } from 'child_process';
|
|
5
2
|
|
|
6
3
|
import type { Plugin } from '../runner';
|
|
7
4
|
|
|
@@ -11,20 +8,80 @@ export function pluginRelease() {
|
|
|
11
8
|
apply: runner => {
|
|
12
9
|
const { logger, hook, fs } = runner;
|
|
13
10
|
const log = logger.withTag(pluginRelease.name);
|
|
14
|
-
hook.
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
11
|
+
hook.release.tapPromise(pluginRelease.name, async () => {
|
|
12
|
+
await hook.build.promise();
|
|
13
|
+
|
|
14
|
+
const packageVersion = runner.package.version;
|
|
15
|
+
const packageName = runner.package.name;
|
|
16
|
+
const url = `https://registry.npmjs.org/${packageName}`;
|
|
17
|
+
let nextVersion = packageVersion;
|
|
18
|
+
log.debug(`查询版本号 ${packageVersion} 是否存在`);
|
|
19
|
+
const res = await (await fetch(url)).json();
|
|
20
|
+
const exist = res?.versions?.[packageVersion];
|
|
21
|
+
if (exist) {
|
|
22
|
+
const split = packageVersion.split('.');
|
|
23
|
+
split[split.length - 1] = Number(split[split.length - 1]) + 1;
|
|
24
|
+
nextVersion = split.join('.');
|
|
25
|
+
log.debug(`版本号 ${packageVersion} 存在,更新版本号为 ${nextVersion}`);
|
|
26
|
+
const text = fs.readFileSync('./package.json').toString();
|
|
27
|
+
const nextText = text.replace(new RegExp(`"version":\\s*"${packageVersion}"`), `"version": "${nextVersion}"`);
|
|
28
|
+
fs.writeFileSync('./package.json', nextText);
|
|
20
29
|
}
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
30
|
+
log.debug(`版本号 ${packageVersion} 不存在`);
|
|
31
|
+
log.info(`开始发布,版本号为 ${nextVersion}`);
|
|
32
|
+
|
|
33
|
+
const tempDir = `./node_modules/.temp/`;
|
|
34
|
+
log.info(`清空目录 ${tempDir}`);
|
|
35
|
+
fs.emptyDirSync(tempDir);
|
|
36
|
+
|
|
37
|
+
const pack = `pnpm pack --pack-destination ${tempDir} --json`;
|
|
38
|
+
log.info(`打包文件 ${pack}`);
|
|
39
|
+
const packOutput = JSON.parse(execSync(pack).toString());
|
|
40
|
+
const filename = packOutput.filename;
|
|
41
|
+
for (const item of packOutput.files) {
|
|
42
|
+
log.debug(item.path);
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
const publish = `pnpm publish ${filename} --registry https://registry.npmjs.org --no-git-checks --dry-run`;
|
|
46
|
+
log.info(`发布文件 ${publish}`);
|
|
47
|
+
execSync(publish, { stdio: 'inherit' });
|
|
48
|
+
log.success(`发布成功,${runner.duration}`);
|
|
49
|
+
|
|
50
|
+
log.info('同步版本');
|
|
51
|
+
while (true) {
|
|
52
|
+
const res = await (await fetch(`https://registry.npmmirror.com/${packageName}`)).json();
|
|
53
|
+
const exist = Boolean(res?.versions?.[nextVersion]);
|
|
54
|
+
if (exist) {
|
|
55
|
+
log.debug(`同步版本存在`);
|
|
56
|
+
break;
|
|
57
|
+
}
|
|
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);
|
|
81
|
+
}
|
|
82
|
+
await new Promise(resolve => setTimeout(resolve, 1000));
|
|
27
83
|
}
|
|
84
|
+
log.success(`同步成功,${runner.duration}`);
|
|
28
85
|
});
|
|
29
86
|
},
|
|
30
87
|
};
|
package/src/runner.ts
CHANGED
|
@@ -1,7 +1,9 @@
|
|
|
1
|
+
import type { ConsolaInstance } from 'consola';
|
|
2
|
+
import * as glob from 'glob';
|
|
1
3
|
import { AsyncSeriesHook } from 'tapable';
|
|
2
4
|
import zod from 'zod';
|
|
3
5
|
|
|
4
|
-
import {
|
|
6
|
+
import { createLogger } from './logger';
|
|
5
7
|
|
|
6
8
|
export interface Config {
|
|
7
9
|
name: string;
|
|
@@ -14,25 +16,31 @@ export interface Runner {
|
|
|
14
16
|
loadPackage: AsyncSeriesHook<[]>;
|
|
15
17
|
loadConfig: AsyncSeriesHook<[]>;
|
|
16
18
|
validateConfig: AsyncSeriesHook<[]>;
|
|
17
|
-
applyConfig: AsyncSeriesHook<[
|
|
19
|
+
applyConfig: AsyncSeriesHook<[]>;
|
|
20
|
+
validatePlugin: AsyncSeriesHook<[]>;
|
|
21
|
+
registerCommand: AsyncSeriesHook<[]>;
|
|
18
22
|
startCommand: AsyncSeriesHook<[]>;
|
|
19
23
|
finishCommand: AsyncSeriesHook<[]>;
|
|
20
24
|
dev: AsyncSeriesHook<[]>;
|
|
21
25
|
build: AsyncSeriesHook<[]>;
|
|
22
26
|
test: AsyncSeriesHook<[]>;
|
|
23
27
|
release: AsyncSeriesHook<[]>;
|
|
24
|
-
deploy: AsyncSeriesHook<[
|
|
28
|
+
deploy: AsyncSeriesHook<[]>;
|
|
25
29
|
lint: AsyncSeriesHook<[]>;
|
|
26
30
|
};
|
|
27
|
-
logger:
|
|
31
|
+
logger: ConsolaInstance;
|
|
28
32
|
config: {
|
|
29
33
|
all: Config[];
|
|
30
34
|
current: Config;
|
|
31
35
|
};
|
|
36
|
+
command: import('commander').Command;
|
|
32
37
|
package: any;
|
|
33
38
|
z: typeof zod;
|
|
34
39
|
fs: typeof import('fs-extra');
|
|
40
|
+
glob: (typeof import('glob'))['glob'];
|
|
35
41
|
tapable: typeof import('tapable');
|
|
42
|
+
duration: string;
|
|
43
|
+
tempDir: string;
|
|
36
44
|
}
|
|
37
45
|
|
|
38
46
|
export interface Plugin {
|
|
@@ -53,23 +61,43 @@ if (typeof Promise.withResolvers === 'undefined') {
|
|
|
53
61
|
}
|
|
54
62
|
|
|
55
63
|
export function createRunner() {
|
|
64
|
+
const perfStart = performance.now();
|
|
65
|
+
|
|
66
|
+
const { Command } = require('commander') as typeof import('commander');
|
|
67
|
+
const command = new Command();
|
|
68
|
+
|
|
69
|
+
command.option('--debug', '打开调试日志');
|
|
70
|
+
command.option('-n, --name <string>', '执行指定配置');
|
|
71
|
+
command.option('-h, --help', '帮助');
|
|
72
|
+
command.parse();
|
|
73
|
+
|
|
74
|
+
const args = zod
|
|
75
|
+
.object({
|
|
76
|
+
debug: zod.boolean().default(false),
|
|
77
|
+
})
|
|
78
|
+
.default({})
|
|
79
|
+
.safeParse(command.opts());
|
|
80
|
+
|
|
56
81
|
const runner: Runner = {
|
|
57
82
|
env: 'prod',
|
|
58
83
|
hook: {
|
|
59
84
|
loadPackage: new AsyncSeriesHook([]),
|
|
60
85
|
loadConfig: new AsyncSeriesHook([]),
|
|
61
86
|
validateConfig: new AsyncSeriesHook([]),
|
|
62
|
-
applyConfig: new AsyncSeriesHook([
|
|
87
|
+
applyConfig: new AsyncSeriesHook([]),
|
|
88
|
+
validatePlugin: new AsyncSeriesHook([]),
|
|
89
|
+
registerCommand: new AsyncSeriesHook([]),
|
|
63
90
|
startCommand: new AsyncSeriesHook([]),
|
|
64
91
|
finishCommand: new AsyncSeriesHook([]),
|
|
65
92
|
dev: new AsyncSeriesHook([]),
|
|
66
93
|
build: new AsyncSeriesHook([]),
|
|
67
94
|
test: new AsyncSeriesHook([]),
|
|
68
95
|
release: new AsyncSeriesHook([]),
|
|
69
|
-
deploy: new AsyncSeriesHook([
|
|
96
|
+
deploy: new AsyncSeriesHook([]),
|
|
70
97
|
lint: new AsyncSeriesHook([]),
|
|
71
98
|
},
|
|
72
|
-
logger: createLogger(),
|
|
99
|
+
logger: createLogger(args.data),
|
|
100
|
+
command,
|
|
73
101
|
config: {
|
|
74
102
|
all: [],
|
|
75
103
|
// @ts-expect-error
|
|
@@ -78,8 +106,15 @@ export function createRunner() {
|
|
|
78
106
|
package: {},
|
|
79
107
|
z: zod,
|
|
80
108
|
fs: require('fs-extra') as typeof import('fs-extra'),
|
|
109
|
+
glob: glob.glob,
|
|
81
110
|
tapable: require('tapable') as typeof import('tapable'),
|
|
111
|
+
get duration() {
|
|
112
|
+
const duration = ((performance.now() - perfStart) / 1000).toFixed(3);
|
|
113
|
+
return `耗时 ${duration} s`;
|
|
114
|
+
},
|
|
115
|
+
tempDir: './node_modules/.temp/',
|
|
82
116
|
};
|
|
117
|
+
|
|
83
118
|
return runner;
|
|
84
119
|
}
|
|
85
120
|
|
package/src/sync.ts
CHANGED
package/dist/build.js
DELETED
package/dist/build.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"build.js","sourceRoot":"","sources":["../src/build.ts"],"names":[],"mappings":""}
|
package/dist/pnpmfile.js
DELETED
|
@@ -1,153 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __defProp = Object.defineProperty;
|
|
3
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
-
var __export = (target, all) => {
|
|
7
|
-
for (var name in all)
|
|
8
|
-
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
-
};
|
|
10
|
-
var __copyProps = (to, from, except, desc) => {
|
|
11
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
-
for (let key of __getOwnPropNames(from))
|
|
13
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
-
}
|
|
16
|
-
return to;
|
|
17
|
-
};
|
|
18
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
-
|
|
20
|
-
// src/pnpmfile.ts
|
|
21
|
-
var pnpmfile_exports = {};
|
|
22
|
-
__export(pnpmfile_exports, {
|
|
23
|
-
afterAllResolved: () => afterAllResolved,
|
|
24
|
-
parseVersion: () => parseVersion,
|
|
25
|
-
readPackage: () => readPackage,
|
|
26
|
-
testCompareObject: () => testCompareObject,
|
|
27
|
-
testReadPackage: () => testReadPackage
|
|
28
|
-
});
|
|
29
|
-
module.exports = __toCommonJS(pnpmfile_exports);
|
|
30
|
-
var https = require("https");
|
|
31
|
-
var r = https.request;
|
|
32
|
-
https.request = function request(...args) {
|
|
33
|
-
if (args[0].path.startsWith("/@rife")) {
|
|
34
|
-
console.log(1);
|
|
35
|
-
args[0].headers["accept"] = "application/json";
|
|
36
|
-
}
|
|
37
|
-
return r(...args);
|
|
38
|
-
};
|
|
39
|
-
var root;
|
|
40
|
-
var exit;
|
|
41
|
-
var origin = {};
|
|
42
|
-
function parseVersion(version) {
|
|
43
|
-
const [_, a = "", b = "", c = "", d = ""] = /(\d+?)\.(\d+?)\.(\d+?)\D*(\d+)?/.exec(version) || [];
|
|
44
|
-
if (!a || !b || !c) {
|
|
45
|
-
exit(`version ${version}`);
|
|
46
|
-
}
|
|
47
|
-
return [a, b, c, d].map((t) => t.padStart(3, "0")).join(".");
|
|
48
|
-
}
|
|
49
|
-
function compareVersion(v1, v2) {
|
|
50
|
-
const v = [v1, v2].filter((t) => Boolean(t));
|
|
51
|
-
if (v.length === 0) {
|
|
52
|
-
exit("version empty");
|
|
53
|
-
}
|
|
54
|
-
if (v.length === 1) {
|
|
55
|
-
return v[0];
|
|
56
|
-
}
|
|
57
|
-
return parseVersion(v1) > parseVersion(v2) ? v1 : v2;
|
|
58
|
-
}
|
|
59
|
-
function updateRoot(type, name, version) {
|
|
60
|
-
if (origin[type][name]) return;
|
|
61
|
-
if (!root[type]) {
|
|
62
|
-
root[type] = {};
|
|
63
|
-
}
|
|
64
|
-
const dependencies = root[type];
|
|
65
|
-
dependencies[name] = compareVersion(version, dependencies[name]);
|
|
66
|
-
}
|
|
67
|
-
var readPackage = (pkg, context) => {
|
|
68
|
-
if (!exit) {
|
|
69
|
-
exit = (message) => {
|
|
70
|
-
context.log(message);
|
|
71
|
-
process.exit(1);
|
|
72
|
-
};
|
|
73
|
-
}
|
|
74
|
-
if (!root) {
|
|
75
|
-
root = pkg;
|
|
76
|
-
origin.dependencies = { ...root.dependencies };
|
|
77
|
-
origin.devDependencies = { ...root.devDependencies };
|
|
78
|
-
}
|
|
79
|
-
const dependencies = pkg.dependencies || {};
|
|
80
|
-
const devDependencies = pkg.devDependencies || {};
|
|
81
|
-
if (!pkg.rife || pkg === root) return;
|
|
82
|
-
const { hostDependencies = {} } = pkg.rife;
|
|
83
|
-
Object.keys(hostDependencies).forEach((name) => {
|
|
84
|
-
const version = dependencies[name] || devDependencies[name];
|
|
85
|
-
if (!version) {
|
|
86
|
-
exit("cannot not found version");
|
|
87
|
-
}
|
|
88
|
-
const isDev = Boolean(devDependencies[name]);
|
|
89
|
-
if (isDev) {
|
|
90
|
-
updateRoot("devDependencies", name, version);
|
|
91
|
-
} else {
|
|
92
|
-
updateRoot("dependencies", name, version);
|
|
93
|
-
}
|
|
94
|
-
});
|
|
95
|
-
};
|
|
96
|
-
var logDiff = (type, diff, context) => {
|
|
97
|
-
if (diff.desc) {
|
|
98
|
-
context.log(`${type} is wrong, ${diff.desc}.`);
|
|
99
|
-
}
|
|
100
|
-
};
|
|
101
|
-
var afterAllResolved = (lockfile, context) => {
|
|
102
|
-
const fact = lockfile.importers["."];
|
|
103
|
-
const diff = compareObject(fact.dependencies, root.dependencies);
|
|
104
|
-
const diffDev = compareObject(fact.devDependencies, root.devDependencies);
|
|
105
|
-
logDiff("dependencies", diff, context);
|
|
106
|
-
logDiff("devDependencies", diffDev, context);
|
|
107
|
-
return lockfile;
|
|
108
|
-
};
|
|
109
|
-
function testReadPackage(list) {
|
|
110
|
-
root = null;
|
|
111
|
-
origin = {};
|
|
112
|
-
list.map((t) => readPackage(t, { log: console.log }));
|
|
113
|
-
return root;
|
|
114
|
-
}
|
|
115
|
-
function compareObject(fact = {}, expect = {}) {
|
|
116
|
-
const more = [];
|
|
117
|
-
const less = [];
|
|
118
|
-
Object.keys(fact).forEach((name) => {
|
|
119
|
-
if (fact[name] !== expect[name]) {
|
|
120
|
-
more.push({ name, version: fact[name] });
|
|
121
|
-
}
|
|
122
|
-
});
|
|
123
|
-
Object.keys(expect).forEach((name) => {
|
|
124
|
-
if (fact[name] !== expect[name]) {
|
|
125
|
-
less.push({ name, version: expect[name] });
|
|
126
|
-
}
|
|
127
|
-
});
|
|
128
|
-
const desc = [];
|
|
129
|
-
if (more.length) {
|
|
130
|
-
desc.push(`${more.map((t) => `${t.name}@${t.version}`).join(" ")} is redundant`);
|
|
131
|
-
}
|
|
132
|
-
if (less.length) {
|
|
133
|
-
desc.push(`cannot found ${less.map((t) => `${t.name}@${t.version}`).join(" ")}`);
|
|
134
|
-
}
|
|
135
|
-
return {
|
|
136
|
-
more,
|
|
137
|
-
//
|
|
138
|
-
less,
|
|
139
|
-
desc: desc.join(", ")
|
|
140
|
-
};
|
|
141
|
-
}
|
|
142
|
-
function testCompareObject(fact = {}, expect = {}) {
|
|
143
|
-
const { more, less } = compareObject(fact, expect);
|
|
144
|
-
return { more, less };
|
|
145
|
-
}
|
|
146
|
-
// Annotate the CommonJS export names for ESM import in node:
|
|
147
|
-
0 && (module.exports = {
|
|
148
|
-
afterAllResolved,
|
|
149
|
-
parseVersion,
|
|
150
|
-
readPackage,
|
|
151
|
-
testCompareObject,
|
|
152
|
-
testReadPackage
|
|
153
|
-
});
|
package/src/build.ts
DELETED
|
File without changes
|