intools-cli 1.0.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.
Binary file
@@ -0,0 +1,111 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || (function () {
19
+ var ownKeys = function(o) {
20
+ ownKeys = Object.getOwnPropertyNames || function (o) {
21
+ var ar = [];
22
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
+ return ar;
24
+ };
25
+ return ownKeys(o);
26
+ };
27
+ return function (mod) {
28
+ if (mod && mod.__esModule) return mod;
29
+ var result = {};
30
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
+ __setModuleDefault(result, mod);
32
+ return result;
33
+ };
34
+ })();
35
+ var __importDefault = (this && this.__importDefault) || function (mod) {
36
+ return (mod && mod.__esModule) ? mod : { "default": mod };
37
+ };
38
+ Object.defineProperty(exports, "__esModule", { value: true });
39
+ exports.build = build;
40
+ const fs = __importStar(require("fs-extra"));
41
+ const path = __importStar(require("path"));
42
+ const esbuild = __importStar(require("esbuild"));
43
+ const chalk_1 = __importDefault(require("chalk"));
44
+ const child_process_1 = require("child_process");
45
+ async function build() {
46
+ const cwd = process.cwd();
47
+ const manifestPath = path.join(cwd, 'manifest.json');
48
+ if (!fs.existsSync(manifestPath)) {
49
+ console.log(chalk_1.default.red('错误: 未找到 manifest.json'));
50
+ process.exit(1);
51
+ }
52
+ const manifest = fs.readJsonSync(manifestPath);
53
+ const hasUI = !!manifest.ui;
54
+ console.log(chalk_1.default.blue('构建插件...'));
55
+ console.log();
56
+ // 1. 构建后端
57
+ await buildBackend(cwd);
58
+ // 2. 构建 UI(如果有)
59
+ if (hasUI) {
60
+ await buildUI(cwd);
61
+ }
62
+ console.log();
63
+ console.log(chalk_1.default.green('✓ 构建完成'));
64
+ }
65
+ async function buildBackend(cwd) {
66
+ const entryPoint = path.join(cwd, 'src/main.ts');
67
+ if (!fs.existsSync(entryPoint)) {
68
+ console.log(chalk_1.default.yellow('跳过后端构建: 未找到 src/main.ts'));
69
+ return;
70
+ }
71
+ fs.ensureDirSync(path.join(cwd, 'dist'));
72
+ try {
73
+ await esbuild.build({
74
+ entryPoints: [entryPoint],
75
+ bundle: true,
76
+ platform: 'node',
77
+ outfile: path.join(cwd, 'dist/main.js'),
78
+ minify: true
79
+ });
80
+ console.log(chalk_1.default.green(' ✓ 后端构建: dist/main.js'));
81
+ }
82
+ catch (err) {
83
+ console.log(chalk_1.default.red('后端构建失败:'), err);
84
+ process.exit(1);
85
+ }
86
+ }
87
+ async function buildUI(cwd) {
88
+ const viteConfig = path.join(cwd, 'vite.config.ts');
89
+ if (!fs.existsSync(viteConfig)) {
90
+ console.log(chalk_1.default.yellow('跳过 UI 构建: 未找到 vite.config.ts'));
91
+ return;
92
+ }
93
+ console.log(chalk_1.default.blue(' 构建 UI...'));
94
+ return new Promise((resolve, reject) => {
95
+ const vite = (0, child_process_1.spawn)('npx', ['vite', 'build'], {
96
+ cwd,
97
+ stdio: 'inherit',
98
+ shell: true
99
+ });
100
+ vite.on('close', (code) => {
101
+ if (code === 0) {
102
+ console.log(chalk_1.default.green(' ✓ UI 构建: ui/'));
103
+ resolve();
104
+ }
105
+ else {
106
+ reject(new Error(`Vite 构建失败,退出码: ${code}`));
107
+ }
108
+ });
109
+ vite.on('error', reject);
110
+ });
111
+ }