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.
- package/README.md +780 -0
- package/assets/default-icon.png +0 -0
- package/dist/commands/build.js +111 -0
- package/dist/commands/create.js +1038 -0
- package/dist/commands/dev.js +117 -0
- package/dist/commands/pack.js +91 -0
- package/dist/index.js +31 -0
- package/package.json +31 -0
|
@@ -0,0 +1,117 @@
|
|
|
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.dev = dev;
|
|
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
|
+
let viteProcess = null;
|
|
46
|
+
async function dev() {
|
|
47
|
+
const cwd = process.cwd();
|
|
48
|
+
const manifestPath = path.join(cwd, 'manifest.json');
|
|
49
|
+
if (!fs.existsSync(manifestPath)) {
|
|
50
|
+
console.log(chalk_1.default.red('错误: 未找到 manifest.json'));
|
|
51
|
+
process.exit(1);
|
|
52
|
+
}
|
|
53
|
+
const manifest = fs.readJsonSync(manifestPath);
|
|
54
|
+
const hasUI = !!manifest.ui;
|
|
55
|
+
const entryPoint = path.join(cwd, 'src/main.ts');
|
|
56
|
+
console.log(chalk_1.default.blue('启动开发模式...'));
|
|
57
|
+
console.log();
|
|
58
|
+
// 确保 dist 目录存在
|
|
59
|
+
fs.ensureDirSync(path.join(cwd, 'dist'));
|
|
60
|
+
// 1. 启动后端监听
|
|
61
|
+
if (fs.existsSync(entryPoint)) {
|
|
62
|
+
await startBackendWatch(cwd, entryPoint);
|
|
63
|
+
}
|
|
64
|
+
// 2. 启动 UI 开发服务器(如果有)
|
|
65
|
+
if (hasUI) {
|
|
66
|
+
await startViteDevServer(cwd);
|
|
67
|
+
}
|
|
68
|
+
console.log();
|
|
69
|
+
console.log(chalk_1.default.gray('按 Ctrl+C 退出'));
|
|
70
|
+
// 处理退出
|
|
71
|
+
process.on('SIGINT', cleanup);
|
|
72
|
+
process.on('SIGTERM', cleanup);
|
|
73
|
+
}
|
|
74
|
+
async function startBackendWatch(cwd, entryPoint) {
|
|
75
|
+
const ctx = await esbuild.context({
|
|
76
|
+
entryPoints: [entryPoint],
|
|
77
|
+
bundle: true,
|
|
78
|
+
platform: 'node',
|
|
79
|
+
outfile: path.join(cwd, 'dist/main.js'),
|
|
80
|
+
sourcemap: true
|
|
81
|
+
});
|
|
82
|
+
await ctx.watch();
|
|
83
|
+
console.log(chalk_1.default.green('✓ 后端监听已启动'));
|
|
84
|
+
// 监听文件变化并输出日志
|
|
85
|
+
const chokidar = await Promise.resolve().then(() => __importStar(require('chokidar')));
|
|
86
|
+
const watcher = chokidar.watch(['src/main.ts', 'src/**/*.ts'], {
|
|
87
|
+
cwd,
|
|
88
|
+
ignoreInitial: true,
|
|
89
|
+
ignored: ['src/ui/**']
|
|
90
|
+
});
|
|
91
|
+
watcher.on('change', (file) => {
|
|
92
|
+
console.log(chalk_1.default.yellow(`[后端] 文件变化: ${file}`));
|
|
93
|
+
});
|
|
94
|
+
}
|
|
95
|
+
async function startViteDevServer(cwd) {
|
|
96
|
+
const viteConfig = path.join(cwd, 'vite.config.ts');
|
|
97
|
+
if (!fs.existsSync(viteConfig)) {
|
|
98
|
+
console.log(chalk_1.default.yellow('跳过 UI 开发服务器: 未找到 vite.config.ts'));
|
|
99
|
+
return;
|
|
100
|
+
}
|
|
101
|
+
console.log(chalk_1.default.blue('启动 Vite 开发服务器...'));
|
|
102
|
+
viteProcess = (0, child_process_1.spawn)('npx', ['vite', '--host'], {
|
|
103
|
+
cwd,
|
|
104
|
+
stdio: 'inherit',
|
|
105
|
+
shell: true
|
|
106
|
+
});
|
|
107
|
+
viteProcess.on('error', (err) => {
|
|
108
|
+
console.log(chalk_1.default.red('Vite 启动失败:'), err);
|
|
109
|
+
});
|
|
110
|
+
}
|
|
111
|
+
function cleanup() {
|
|
112
|
+
console.log(chalk_1.default.blue('\n停止开发模式...'));
|
|
113
|
+
if (viteProcess) {
|
|
114
|
+
viteProcess.kill();
|
|
115
|
+
}
|
|
116
|
+
process.exit(0);
|
|
117
|
+
}
|
|
@@ -0,0 +1,91 @@
|
|
|
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.pack = pack;
|
|
40
|
+
const fs = __importStar(require("fs-extra"));
|
|
41
|
+
const path = __importStar(require("path"));
|
|
42
|
+
const archiver_1 = __importDefault(require("archiver"));
|
|
43
|
+
const chalk_1 = __importDefault(require("chalk"));
|
|
44
|
+
async function pack() {
|
|
45
|
+
const cwd = process.cwd();
|
|
46
|
+
const manifestPath = path.join(cwd, 'manifest.json');
|
|
47
|
+
if (!fs.existsSync(manifestPath)) {
|
|
48
|
+
console.log(chalk_1.default.red('错误: 未找到 manifest.json'));
|
|
49
|
+
process.exit(1);
|
|
50
|
+
}
|
|
51
|
+
const manifest = fs.readJsonSync(manifestPath);
|
|
52
|
+
const distMain = path.join(cwd, 'dist/main.js');
|
|
53
|
+
if (!fs.existsSync(distMain)) {
|
|
54
|
+
console.log(chalk_1.default.red('错误: 未找到 dist/main.js,请先运行 build'));
|
|
55
|
+
process.exit(1);
|
|
56
|
+
}
|
|
57
|
+
const outputName = `${manifest.name}-${manifest.version}.inplugin`;
|
|
58
|
+
const outputPath = path.join(cwd, outputName);
|
|
59
|
+
console.log(chalk_1.default.blue(`打包插件: ${outputName}`));
|
|
60
|
+
await createArchive(cwd, outputPath, manifest);
|
|
61
|
+
console.log(chalk_1.default.green(`✓ 打包成功: ${outputName}`));
|
|
62
|
+
}
|
|
63
|
+
async function createArchive(cwd, outputPath, manifest) {
|
|
64
|
+
return new Promise((resolve, reject) => {
|
|
65
|
+
const output = fs.createWriteStream(outputPath);
|
|
66
|
+
const archive = (0, archiver_1.default)('zip', { zlib: { level: 9 } });
|
|
67
|
+
output.on('close', () => resolve());
|
|
68
|
+
archive.on('error', (err) => reject(err));
|
|
69
|
+
archive.pipe(output);
|
|
70
|
+
// 添加 manifest.json
|
|
71
|
+
archive.file(path.join(cwd, 'manifest.json'), { name: 'manifest.json' });
|
|
72
|
+
// 添加打包后的 main.js
|
|
73
|
+
archive.file(path.join(cwd, 'dist/main.js'), { name: 'main.js' });
|
|
74
|
+
// 添加图标(如果存在)
|
|
75
|
+
const iconPath = path.join(cwd, 'icon.png');
|
|
76
|
+
if (fs.existsSync(iconPath)) {
|
|
77
|
+
archive.file(iconPath, { name: 'icon.png' });
|
|
78
|
+
}
|
|
79
|
+
// 添加 UI 目录(如果存在)
|
|
80
|
+
const uiDir = path.join(cwd, 'ui');
|
|
81
|
+
if (fs.existsSync(uiDir)) {
|
|
82
|
+
archive.directory(uiDir, 'ui');
|
|
83
|
+
}
|
|
84
|
+
// 添加 README.md(如果存在)
|
|
85
|
+
const readmePath = path.join(cwd, 'README.md');
|
|
86
|
+
if (fs.existsSync(readmePath)) {
|
|
87
|
+
archive.file(readmePath, { name: 'README.md' });
|
|
88
|
+
}
|
|
89
|
+
archive.finalize();
|
|
90
|
+
});
|
|
91
|
+
}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
"use strict";
|
|
3
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
+
const commander_1 = require("commander");
|
|
5
|
+
const create_1 = require("./commands/create");
|
|
6
|
+
const build_1 = require("./commands/build");
|
|
7
|
+
const pack_1 = require("./commands/pack");
|
|
8
|
+
const dev_1 = require("./commands/dev");
|
|
9
|
+
const program = new commander_1.Command();
|
|
10
|
+
program
|
|
11
|
+
.name('intools')
|
|
12
|
+
.description('InTools 插件开发 CLI 工具')
|
|
13
|
+
.version('1.0.0');
|
|
14
|
+
program
|
|
15
|
+
.command('create <name>')
|
|
16
|
+
.description('创建新插件项目')
|
|
17
|
+
.option('-t, --template <template>', '模板类型: react (默认) | basic', 'react')
|
|
18
|
+
.action(create_1.create);
|
|
19
|
+
program
|
|
20
|
+
.command('build')
|
|
21
|
+
.description('构建插件')
|
|
22
|
+
.action(build_1.build);
|
|
23
|
+
program
|
|
24
|
+
.command('pack')
|
|
25
|
+
.description('打包成 .inplugin 文件')
|
|
26
|
+
.action(pack_1.pack);
|
|
27
|
+
program
|
|
28
|
+
.command('dev')
|
|
29
|
+
.description('开发模式(热重载)')
|
|
30
|
+
.action(dev_1.dev);
|
|
31
|
+
program.parse();
|
package/package.json
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "intools-cli",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"description": "InTools 插件开发 CLI 工具",
|
|
5
|
+
"main": "dist/index.js",
|
|
6
|
+
"files": [
|
|
7
|
+
"dist",
|
|
8
|
+
"assets"
|
|
9
|
+
],
|
|
10
|
+
"bin": {
|
|
11
|
+
"intools": "./dist/index.js"
|
|
12
|
+
},
|
|
13
|
+
"scripts": {
|
|
14
|
+
"build": "tsc",
|
|
15
|
+
"dev": "tsc -w"
|
|
16
|
+
},
|
|
17
|
+
"dependencies": {
|
|
18
|
+
"commander": "^12.0.0",
|
|
19
|
+
"esbuild": "^0.20.0",
|
|
20
|
+
"archiver": "^7.0.0",
|
|
21
|
+
"chalk": "^4.1.2",
|
|
22
|
+
"fs-extra": "^11.2.0",
|
|
23
|
+
"chokidar": "^3.6.0"
|
|
24
|
+
},
|
|
25
|
+
"devDependencies": {
|
|
26
|
+
"@types/node": "^20.0.0",
|
|
27
|
+
"@types/archiver": "^6.0.0",
|
|
28
|
+
"@types/fs-extra": "^11.0.0",
|
|
29
|
+
"typescript": "^5.0.0"
|
|
30
|
+
}
|
|
31
|
+
}
|