@vureact/compiler-core 1.2.1 → 1.4.0
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/README.md +1 -1
- package/README.zh.md +1 -1
- package/lib/{chunk-SQRJUILR.js → chunk-IVRFEV6H.js} +1411 -1249
- package/lib/{chunk-7FIMRVQS.esm.js → chunk-NF5BSPYE.esm.js} +1352 -1190
- package/lib/cli.d.cts +1 -2
- package/lib/cli.d.ts +1 -2
- package/lib/cli.esm.js +104 -47
- package/lib/cli.js +106 -49
- package/lib/compiler-core.d.cts +1117 -1179
- package/lib/compiler-core.d.ts +1117 -1179
- package/lib/compiler-core.esm.js +2 -2
- package/lib/compiler-core.js +3 -3
- package/package.json +99 -83
package/lib/cli.d.cts
CHANGED
|
@@ -1,2 +1 @@
|
|
|
1
|
-
|
|
2
|
-
export { }
|
|
1
|
+
#!/usr/bin/env node
|
package/lib/cli.d.ts
CHANGED
|
@@ -1,2 +1 @@
|
|
|
1
|
-
|
|
2
|
-
export { }
|
|
1
|
+
#!/usr/bin/env node
|
package/lib/cli.esm.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
/**
|
|
3
|
-
* @vureact/compiler-core v1.
|
|
3
|
+
* @vureact/compiler-core v1.4.0
|
|
4
4
|
* (c) 2025-present Ruihong Zhong (Ryan John)
|
|
5
5
|
* @license MIT
|
|
6
6
|
*/
|
|
@@ -10,76 +10,70 @@ import {
|
|
|
10
10
|
VuReact,
|
|
11
11
|
bin,
|
|
12
12
|
calcElapsedTime,
|
|
13
|
+
getDirname,
|
|
13
14
|
normalizePath,
|
|
14
15
|
version
|
|
15
|
-
} from "./chunk-
|
|
16
|
+
} from "./chunk-NF5BSPYE.esm.js";
|
|
16
17
|
|
|
17
18
|
// src/cli/index.ts
|
|
18
19
|
import { cac } from "cac";
|
|
19
20
|
|
|
20
|
-
// src/cli/action.ts
|
|
21
|
-
import
|
|
21
|
+
// src/cli/action/index.ts
|
|
22
|
+
import kleur3 from "kleur";
|
|
23
|
+
import path3 from "path";
|
|
24
|
+
|
|
25
|
+
// src/cli/action/config-loader.ts
|
|
22
26
|
import { existsSync } from "fs";
|
|
23
27
|
import kleur from "kleur";
|
|
24
|
-
import ora from "ora";
|
|
25
28
|
import path from "path";
|
|
26
29
|
import { pathToFileURL } from "url";
|
|
27
|
-
async function
|
|
28
|
-
const
|
|
29
|
-
const
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
if (
|
|
34
|
-
|
|
35
|
-
console.info(
|
|
36
|
-
kleur.dim(`
|
|
37
|
-
${(/* @__PURE__ */ new Date()).toLocaleTimeString()}`),
|
|
38
|
-
kleur.bold(kleur.magenta("[hrm]")),
|
|
39
|
-
kleur.gray(`Watching for file changes...
|
|
40
|
-
`)
|
|
41
|
-
);
|
|
30
|
+
async function loadUserConfig(root) {
|
|
31
|
+
const tsConfigPath = path.resolve(root, "vureact.config.ts");
|
|
32
|
+
const jsConfigPath = path.resolve(root, "vureact.config.js");
|
|
33
|
+
if (existsSync(tsConfigPath)) {
|
|
34
|
+
return await resolveConfig("TypeScript", tsConfigPath);
|
|
35
|
+
}
|
|
36
|
+
if (existsSync(jsConfigPath)) {
|
|
37
|
+
return await resolveConfig("JavaScript", jsConfigPath);
|
|
42
38
|
}
|
|
39
|
+
return {};
|
|
43
40
|
}
|
|
44
|
-
async function
|
|
45
|
-
const configPath = path.resolve(root, "vureact.config.js");
|
|
46
|
-
if (!existsSync(configPath)) return {};
|
|
41
|
+
async function resolveConfig(type, configPath) {
|
|
47
42
|
try {
|
|
43
|
+
if (type === "TypeScript") {
|
|
44
|
+
const { register } = await import("tsx/esm/api");
|
|
45
|
+
register();
|
|
46
|
+
}
|
|
48
47
|
const configUrl = pathToFileURL(configPath).href;
|
|
49
48
|
const module = await import(configUrl);
|
|
50
49
|
return module.default || module;
|
|
51
50
|
} catch (err) {
|
|
52
|
-
console.warn(
|
|
53
|
-
|
|
54
|
-
`Load config failed at ${configPath}, using default options`,
|
|
55
|
-
err
|
|
56
|
-
);
|
|
51
|
+
console.warn(kleur.yellow(`\u26A0\uFE0F Load ${type} config failed, using default options.`));
|
|
52
|
+
console.error(err);
|
|
57
53
|
return {};
|
|
58
54
|
}
|
|
59
55
|
}
|
|
56
|
+
|
|
57
|
+
// src/cli/action/config-merger.ts
|
|
60
58
|
function mergeConfig(projectRoot, options, userConfig) {
|
|
61
59
|
const merged = {
|
|
62
60
|
...userConfig,
|
|
63
61
|
...options,
|
|
64
62
|
root: projectRoot
|
|
65
63
|
};
|
|
66
|
-
if (options.exclude) {
|
|
67
|
-
merged.exclude = Array.isArray(options.exclude) ? options.exclude : [options.exclude];
|
|
68
|
-
} else if (userConfig.exclude) {
|
|
69
|
-
merged.exclude = userConfig.exclude;
|
|
70
|
-
}
|
|
71
64
|
merged.output = {
|
|
72
65
|
...userConfig.output,
|
|
73
66
|
workspace: options.workspace ?? userConfig.output?.workspace,
|
|
74
|
-
outDir: options.outDir ?? userConfig.output?.outDir
|
|
75
|
-
bootstrapVite: options.bootstrapVite ?? userConfig.output?.bootstrapVite
|
|
76
|
-
};
|
|
77
|
-
merged.format = {
|
|
78
|
-
enabled: options.format ?? userConfig.format?.enabled,
|
|
79
|
-
formatter: options.formatter ?? userConfig.format?.formatter
|
|
67
|
+
outDir: options.outDir ?? userConfig.output?.outDir
|
|
80
68
|
};
|
|
81
69
|
return merged;
|
|
82
70
|
}
|
|
71
|
+
|
|
72
|
+
// src/cli/action/file-watcher.ts
|
|
73
|
+
import chokidar from "chokidar";
|
|
74
|
+
import kleur2 from "kleur";
|
|
75
|
+
import ora from "ora";
|
|
76
|
+
import path2 from "path";
|
|
83
77
|
function setupWatcher(compiler, config) {
|
|
84
78
|
const spinner = ora();
|
|
85
79
|
const cmpHelper = new Helper(config);
|
|
@@ -110,7 +104,7 @@ function setupWatcher(compiler, config) {
|
|
|
110
104
|
".scss": (p) => compiler.processStyle(p)
|
|
111
105
|
};
|
|
112
106
|
const onRecompile = async (event, filePath) => {
|
|
113
|
-
const ext =
|
|
107
|
+
const ext = path2.extname(filePath);
|
|
114
108
|
if (ext in processors) {
|
|
115
109
|
spinner.start("Recompiling...");
|
|
116
110
|
const startTime = performance.now();
|
|
@@ -125,21 +119,21 @@ function setupWatcher(compiler, config) {
|
|
|
125
119
|
spinner.start("Updating assets...");
|
|
126
120
|
await compiler.processAsset(filePath);
|
|
127
121
|
cmpHelper.print(
|
|
128
|
-
|
|
129
|
-
|
|
122
|
+
kleur2.blue("Copied Asset"),
|
|
123
|
+
kleur2.dim(normalizePath(cmpHelper.relativePath(filePath)))
|
|
130
124
|
);
|
|
131
125
|
}
|
|
132
126
|
spinner.stop();
|
|
133
127
|
};
|
|
134
128
|
const onRemoveFile = async (type, filePath) => {
|
|
135
|
-
const ext =
|
|
129
|
+
const ext = path2.extname(filePath);
|
|
136
130
|
const scriptExtRegex = /\.(js|ts)$/i;
|
|
137
|
-
const styleExtRegex = /\.(less|sass|scss)$/i;
|
|
131
|
+
const styleExtRegex = /\.(css|less|sass|scss)$/i;
|
|
138
132
|
const removeFile = async (type2) => {
|
|
139
133
|
await compiler.removeOutputPath(filePath, type2);
|
|
140
134
|
cmpHelper.print(
|
|
141
|
-
|
|
142
|
-
|
|
135
|
+
kleur2.yellow("Removed"),
|
|
136
|
+
kleur2.dim(normalizePath(cmpHelper.relativePath(filePath)))
|
|
143
137
|
);
|
|
144
138
|
};
|
|
145
139
|
if (type === "unlink") {
|
|
@@ -167,14 +161,77 @@ function setupWatcher(compiler, config) {
|
|
|
167
161
|
};
|
|
168
162
|
}
|
|
169
163
|
|
|
164
|
+
// src/cli/action/index.ts
|
|
165
|
+
async function resolveAction(root, options) {
|
|
166
|
+
const projectRoot = root ? path3.resolve(process.cwd(), root) : process.cwd();
|
|
167
|
+
const userConfig = await loadUserConfig(projectRoot);
|
|
168
|
+
const finalConfig = mergeConfig(projectRoot, options, userConfig);
|
|
169
|
+
const compiler = new VuReact(finalConfig);
|
|
170
|
+
await compiler.execute();
|
|
171
|
+
if (finalConfig.watch) {
|
|
172
|
+
setupWatcher(compiler, finalConfig);
|
|
173
|
+
console.info(
|
|
174
|
+
kleur3.dim(`
|
|
175
|
+
${(/* @__PURE__ */ new Date()).toLocaleTimeString()}`),
|
|
176
|
+
kleur3.bold(kleur3.magenta("[hrm]")),
|
|
177
|
+
kleur3.gray(`Watching for file changes...
|
|
178
|
+
`)
|
|
179
|
+
);
|
|
180
|
+
}
|
|
181
|
+
}
|
|
182
|
+
|
|
170
183
|
// src/cli/option.ts
|
|
171
184
|
function resolveOptions(command) {
|
|
172
|
-
return command.option("-i, --input <dir>", "Input directory (relative to root)").option("-o, --outDir <dir>", "Output directory name").option("--workspace <dir>", "The workspace directory for cache and output")
|
|
185
|
+
return command.option("-i, --input <dir>", "Input directory (relative to root)").option("-o, --outDir <dir>", "Output directory name").option("--workspace <dir>", "The workspace directory for cache and output");
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
// src/cli/update-check.ts
|
|
189
|
+
import { existsSync as existsSync2, readFileSync } from "fs";
|
|
190
|
+
import { join } from "path";
|
|
191
|
+
import updateNotifier from "update-notifier";
|
|
192
|
+
var __dirname = getDirname(import.meta.url);
|
|
193
|
+
function checkForUpdates() {
|
|
194
|
+
try {
|
|
195
|
+
const possiblePaths = [
|
|
196
|
+
"./package.json",
|
|
197
|
+
// 当前目录
|
|
198
|
+
"package.json",
|
|
199
|
+
// 当前目录(另一种写法)
|
|
200
|
+
"../package.json",
|
|
201
|
+
// 上一级目录(构建环境)
|
|
202
|
+
"../../package.json"
|
|
203
|
+
// 上两级目录(开发环境)
|
|
204
|
+
];
|
|
205
|
+
let pkgPath = "";
|
|
206
|
+
for (const relPath of possiblePaths) {
|
|
207
|
+
const testPath = join(__dirname, relPath);
|
|
208
|
+
if (existsSync2(testPath)) {
|
|
209
|
+
pkgPath = testPath;
|
|
210
|
+
break;
|
|
211
|
+
}
|
|
212
|
+
}
|
|
213
|
+
if (!pkgPath) {
|
|
214
|
+
return;
|
|
215
|
+
}
|
|
216
|
+
const pkg = JSON.parse(readFileSync(pkgPath, "utf-8"));
|
|
217
|
+
const notifier = updateNotifier({
|
|
218
|
+
pkg,
|
|
219
|
+
updateCheckInterval: 1e3 * 60 * 60 * 24,
|
|
220
|
+
// 每天检查一次 (24小时)
|
|
221
|
+
shouldNotifyInNpmScript: true
|
|
222
|
+
});
|
|
223
|
+
notifier.notify();
|
|
224
|
+
} catch (error) {
|
|
225
|
+
if (process.env.NODE_ENV === "development") {
|
|
226
|
+
console.debug("Update check failed:", error);
|
|
227
|
+
}
|
|
228
|
+
}
|
|
173
229
|
}
|
|
174
230
|
|
|
175
231
|
// src/cli/index.ts
|
|
176
232
|
var [programName] = Object.keys(bin);
|
|
177
233
|
var cli = cac(programName);
|
|
234
|
+
checkForUpdates();
|
|
178
235
|
var buildCommand = cli.command("build [root]", "Compile Vue3 to React (one-time)");
|
|
179
236
|
resolveOptions(buildCommand).action((root, options) => {
|
|
180
237
|
resolveAction(root, { ...options, watch: false });
|
package/lib/cli.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
"use strict"; function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { newObj[key] = obj[key]; } } } newObj.default = obj; return newObj; } } function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } function _nullishCoalesce(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return rhsFn(); } } function _optionalChain(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; }/**
|
|
3
|
-
* @vureact/compiler-core v1.
|
|
3
|
+
* @vureact/compiler-core v1.4.0
|
|
4
4
|
* (c) 2025-present Ruihong Zhong (Ryan John)
|
|
5
5
|
* @license MIT
|
|
6
6
|
*/
|
|
@@ -12,77 +12,71 @@
|
|
|
12
12
|
|
|
13
13
|
|
|
14
14
|
|
|
15
|
-
|
|
15
|
+
|
|
16
|
+
var _chunkIVRFEV6Hjs = require('./chunk-IVRFEV6H.js');
|
|
16
17
|
|
|
17
18
|
// src/cli/index.ts
|
|
18
19
|
var _cac = require('cac');
|
|
19
20
|
|
|
20
|
-
// src/cli/action.ts
|
|
21
|
-
var _chokidar = require('chokidar'); var _chokidar2 = _interopRequireDefault(_chokidar);
|
|
22
|
-
var _fs = require('fs');
|
|
21
|
+
// src/cli/action/index.ts
|
|
23
22
|
var _kleur = require('kleur'); var _kleur2 = _interopRequireDefault(_kleur);
|
|
24
|
-
var _ora = require('ora'); var _ora2 = _interopRequireDefault(_ora);
|
|
25
23
|
var _path = require('path'); var _path2 = _interopRequireDefault(_path);
|
|
24
|
+
|
|
25
|
+
// src/cli/action/config-loader.ts
|
|
26
|
+
var _fs = require('fs');
|
|
27
|
+
|
|
28
|
+
|
|
26
29
|
var _url = require('url');
|
|
27
|
-
async function
|
|
28
|
-
const
|
|
29
|
-
const
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
if (
|
|
34
|
-
|
|
35
|
-
console.info(
|
|
36
|
-
_kleur2.default.dim(`
|
|
37
|
-
${(/* @__PURE__ */ new Date()).toLocaleTimeString()}`),
|
|
38
|
-
_kleur2.default.bold(_kleur2.default.magenta("[hrm]")),
|
|
39
|
-
_kleur2.default.gray(`Watching for file changes...
|
|
40
|
-
`)
|
|
41
|
-
);
|
|
30
|
+
async function loadUserConfig(root) {
|
|
31
|
+
const tsConfigPath = _path2.default.resolve(root, "vureact.config.ts");
|
|
32
|
+
const jsConfigPath = _path2.default.resolve(root, "vureact.config.js");
|
|
33
|
+
if (_fs.existsSync.call(void 0, tsConfigPath)) {
|
|
34
|
+
return await resolveConfig("TypeScript", tsConfigPath);
|
|
35
|
+
}
|
|
36
|
+
if (_fs.existsSync.call(void 0, jsConfigPath)) {
|
|
37
|
+
return await resolveConfig("JavaScript", jsConfigPath);
|
|
42
38
|
}
|
|
39
|
+
return {};
|
|
43
40
|
}
|
|
44
|
-
async function
|
|
45
|
-
const configPath = _path2.default.resolve(root, "vureact.config.js");
|
|
46
|
-
if (!_fs.existsSync.call(void 0, configPath)) return {};
|
|
41
|
+
async function resolveConfig(type, configPath) {
|
|
47
42
|
try {
|
|
43
|
+
if (type === "TypeScript") {
|
|
44
|
+
const { register } = await Promise.resolve().then(() => _interopRequireWildcard(require("tsx/esm/api")));
|
|
45
|
+
register();
|
|
46
|
+
}
|
|
48
47
|
const configUrl = _url.pathToFileURL.call(void 0, configPath).href;
|
|
49
48
|
const module = await Promise.resolve().then(() => _interopRequireWildcard(require(configUrl)));
|
|
50
49
|
return module.default || module;
|
|
51
50
|
} catch (err) {
|
|
52
|
-
console.warn(
|
|
53
|
-
|
|
54
|
-
`Load config failed at ${configPath}, using default options`,
|
|
55
|
-
err
|
|
56
|
-
);
|
|
51
|
+
console.warn(_kleur2.default.yellow(`\u26A0\uFE0F Load ${type} config failed, using default options.`));
|
|
52
|
+
console.error(err);
|
|
57
53
|
return {};
|
|
58
54
|
}
|
|
59
55
|
}
|
|
56
|
+
|
|
57
|
+
// src/cli/action/config-merger.ts
|
|
60
58
|
function mergeConfig(projectRoot, options, userConfig) {
|
|
61
59
|
const merged = {
|
|
62
60
|
...userConfig,
|
|
63
61
|
...options,
|
|
64
62
|
root: projectRoot
|
|
65
63
|
};
|
|
66
|
-
if (options.exclude) {
|
|
67
|
-
merged.exclude = Array.isArray(options.exclude) ? options.exclude : [options.exclude];
|
|
68
|
-
} else if (userConfig.exclude) {
|
|
69
|
-
merged.exclude = userConfig.exclude;
|
|
70
|
-
}
|
|
71
64
|
merged.output = {
|
|
72
65
|
...userConfig.output,
|
|
73
66
|
workspace: _nullishCoalesce(options.workspace, () => ( _optionalChain([userConfig, 'access', _ => _.output, 'optionalAccess', _2 => _2.workspace]))),
|
|
74
|
-
outDir: _nullishCoalesce(options.outDir, () => ( _optionalChain([userConfig, 'access', _3 => _3.output, 'optionalAccess', _4 => _4.outDir])))
|
|
75
|
-
bootstrapVite: _nullishCoalesce(options.bootstrapVite, () => ( _optionalChain([userConfig, 'access', _5 => _5.output, 'optionalAccess', _6 => _6.bootstrapVite])))
|
|
76
|
-
};
|
|
77
|
-
merged.format = {
|
|
78
|
-
enabled: _nullishCoalesce(options.format, () => ( _optionalChain([userConfig, 'access', _7 => _7.format, 'optionalAccess', _8 => _8.enabled]))),
|
|
79
|
-
formatter: _nullishCoalesce(options.formatter, () => ( _optionalChain([userConfig, 'access', _9 => _9.format, 'optionalAccess', _10 => _10.formatter])))
|
|
67
|
+
outDir: _nullishCoalesce(options.outDir, () => ( _optionalChain([userConfig, 'access', _3 => _3.output, 'optionalAccess', _4 => _4.outDir])))
|
|
80
68
|
};
|
|
81
69
|
return merged;
|
|
82
70
|
}
|
|
71
|
+
|
|
72
|
+
// src/cli/action/file-watcher.ts
|
|
73
|
+
var _chokidar = require('chokidar'); var _chokidar2 = _interopRequireDefault(_chokidar);
|
|
74
|
+
|
|
75
|
+
var _ora = require('ora'); var _ora2 = _interopRequireDefault(_ora);
|
|
76
|
+
|
|
83
77
|
function setupWatcher(compiler, config) {
|
|
84
78
|
const spinner = _ora2.default.call(void 0, );
|
|
85
|
-
const cmpHelper = new (0,
|
|
79
|
+
const cmpHelper = new (0, _chunkIVRFEV6Hjs.Helper)(config);
|
|
86
80
|
const watcher = _chokidar2.default.watch(cmpHelper.getInputPath(), {
|
|
87
81
|
ignored: cmpHelper.getExcludes(),
|
|
88
82
|
persistent: true,
|
|
@@ -117,16 +111,16 @@ function setupWatcher(compiler, config) {
|
|
|
117
111
|
const fn = processors[ext];
|
|
118
112
|
const unit = await fn(filePath);
|
|
119
113
|
cmpHelper.printCoreLogs();
|
|
120
|
-
cmpHelper.printCompileInfo(filePath,
|
|
114
|
+
cmpHelper.printCompileInfo(filePath, _chunkIVRFEV6Hjs.calcElapsedTime.call(void 0, startTime));
|
|
121
115
|
if (unit) {
|
|
122
|
-
await _optionalChain([config, 'access',
|
|
116
|
+
await _optionalChain([config, 'access', _5 => _5.onChange, 'optionalCall', _6 => _6(event, unit)]);
|
|
123
117
|
}
|
|
124
118
|
} else {
|
|
125
119
|
spinner.start("Updating assets...");
|
|
126
120
|
await compiler.processAsset(filePath);
|
|
127
121
|
cmpHelper.print(
|
|
128
122
|
_kleur2.default.blue("Copied Asset"),
|
|
129
|
-
_kleur2.default.dim(
|
|
123
|
+
_kleur2.default.dim(_chunkIVRFEV6Hjs.normalizePath.call(void 0, cmpHelper.relativePath(filePath)))
|
|
130
124
|
);
|
|
131
125
|
}
|
|
132
126
|
spinner.stop();
|
|
@@ -134,12 +128,12 @@ function setupWatcher(compiler, config) {
|
|
|
134
128
|
const onRemoveFile = async (type, filePath) => {
|
|
135
129
|
const ext = _path2.default.extname(filePath);
|
|
136
130
|
const scriptExtRegex = /\.(js|ts)$/i;
|
|
137
|
-
const styleExtRegex = /\.(less|sass|scss)$/i;
|
|
131
|
+
const styleExtRegex = /\.(css|less|sass|scss)$/i;
|
|
138
132
|
const removeFile = async (type2) => {
|
|
139
133
|
await compiler.removeOutputPath(filePath, type2);
|
|
140
134
|
cmpHelper.print(
|
|
141
135
|
_kleur2.default.yellow("Removed"),
|
|
142
|
-
_kleur2.default.dim(
|
|
136
|
+
_kleur2.default.dim(_chunkIVRFEV6Hjs.normalizePath.call(void 0, cmpHelper.relativePath(filePath)))
|
|
143
137
|
);
|
|
144
138
|
};
|
|
145
139
|
if (type === "unlink") {
|
|
@@ -167,14 +161,77 @@ function setupWatcher(compiler, config) {
|
|
|
167
161
|
};
|
|
168
162
|
}
|
|
169
163
|
|
|
164
|
+
// src/cli/action/index.ts
|
|
165
|
+
async function resolveAction(root, options) {
|
|
166
|
+
const projectRoot = root ? _path2.default.resolve(process.cwd(), root) : process.cwd();
|
|
167
|
+
const userConfig = await loadUserConfig(projectRoot);
|
|
168
|
+
const finalConfig = mergeConfig(projectRoot, options, userConfig);
|
|
169
|
+
const compiler = new (0, _chunkIVRFEV6Hjs.VuReact)(finalConfig);
|
|
170
|
+
await compiler.execute();
|
|
171
|
+
if (finalConfig.watch) {
|
|
172
|
+
setupWatcher(compiler, finalConfig);
|
|
173
|
+
console.info(
|
|
174
|
+
_kleur2.default.dim(`
|
|
175
|
+
${(/* @__PURE__ */ new Date()).toLocaleTimeString()}`),
|
|
176
|
+
_kleur2.default.bold(_kleur2.default.magenta("[hrm]")),
|
|
177
|
+
_kleur2.default.gray(`Watching for file changes...
|
|
178
|
+
`)
|
|
179
|
+
);
|
|
180
|
+
}
|
|
181
|
+
}
|
|
182
|
+
|
|
170
183
|
// src/cli/option.ts
|
|
171
184
|
function resolveOptions(command) {
|
|
172
|
-
return command.option("-i, --input <dir>", "Input directory (relative to root)").option("-o, --outDir <dir>", "Output directory name").option("--workspace <dir>", "The workspace directory for cache and output")
|
|
185
|
+
return command.option("-i, --input <dir>", "Input directory (relative to root)").option("-o, --outDir <dir>", "Output directory name").option("--workspace <dir>", "The workspace directory for cache and output");
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
// src/cli/update-check.ts
|
|
189
|
+
|
|
190
|
+
|
|
191
|
+
var _updatenotifier = require('update-notifier'); var _updatenotifier2 = _interopRequireDefault(_updatenotifier);
|
|
192
|
+
var __dirname = _chunkIVRFEV6Hjs.getDirname.call(void 0, import.meta.url);
|
|
193
|
+
function checkForUpdates() {
|
|
194
|
+
try {
|
|
195
|
+
const possiblePaths = [
|
|
196
|
+
"./package.json",
|
|
197
|
+
// 当前目录
|
|
198
|
+
"package.json",
|
|
199
|
+
// 当前目录(另一种写法)
|
|
200
|
+
"../package.json",
|
|
201
|
+
// 上一级目录(构建环境)
|
|
202
|
+
"../../package.json"
|
|
203
|
+
// 上两级目录(开发环境)
|
|
204
|
+
];
|
|
205
|
+
let pkgPath = "";
|
|
206
|
+
for (const relPath of possiblePaths) {
|
|
207
|
+
const testPath = _path.join.call(void 0, __dirname, relPath);
|
|
208
|
+
if (_fs.existsSync.call(void 0, testPath)) {
|
|
209
|
+
pkgPath = testPath;
|
|
210
|
+
break;
|
|
211
|
+
}
|
|
212
|
+
}
|
|
213
|
+
if (!pkgPath) {
|
|
214
|
+
return;
|
|
215
|
+
}
|
|
216
|
+
const pkg = JSON.parse(_fs.readFileSync.call(void 0, pkgPath, "utf-8"));
|
|
217
|
+
const notifier = _updatenotifier2.default.call(void 0, {
|
|
218
|
+
pkg,
|
|
219
|
+
updateCheckInterval: 1e3 * 60 * 60 * 24,
|
|
220
|
+
// 每天检查一次 (24小时)
|
|
221
|
+
shouldNotifyInNpmScript: true
|
|
222
|
+
});
|
|
223
|
+
notifier.notify();
|
|
224
|
+
} catch (error) {
|
|
225
|
+
if (process.env.NODE_ENV === "development") {
|
|
226
|
+
console.debug("Update check failed:", error);
|
|
227
|
+
}
|
|
228
|
+
}
|
|
173
229
|
}
|
|
174
230
|
|
|
175
231
|
// src/cli/index.ts
|
|
176
|
-
var [programName] = Object.keys(
|
|
232
|
+
var [programName] = Object.keys(_chunkIVRFEV6Hjs.bin);
|
|
177
233
|
var cli = _cac.cac.call(void 0, programName);
|
|
234
|
+
checkForUpdates();
|
|
178
235
|
var buildCommand = cli.command("build [root]", "Compile Vue3 to React (one-time)");
|
|
179
236
|
resolveOptions(buildCommand).action((root, options) => {
|
|
180
237
|
resolveAction(root, { ...options, watch: false });
|
|
@@ -183,4 +240,4 @@ var watchCommand = cli.command("watch [root]", "Compile Vue3 to React and watch
|
|
|
183
240
|
resolveOptions(watchCommand).action((root, options) => {
|
|
184
241
|
resolveAction(root, { ...options, watch: true });
|
|
185
242
|
});
|
|
186
|
-
cli.help().version(
|
|
243
|
+
cli.help().version(_chunkIVRFEV6Hjs.version).parse();
|