@xiguanpm/inkos-web 1.0.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/LICENSE +21 -0
- package/bin/cli.js +124 -0
- package/dist/assets/index-Qa7RFOD5.css +1 -0
- package/dist/assets/index-ReWNfPBN.js +540 -0
- package/dist/index.html +14 -0
- package/dist-server/index.js +104 -0
- package/dist-server/routes/inkos.js +1022 -0
- package/dist-server/utils/cli.js +202 -0
- package/package.json +57 -0
|
@@ -0,0 +1,202 @@
|
|
|
1
|
+
const { spawn } = require('child_process');
|
|
2
|
+
const path = require('path');
|
|
3
|
+
const fs = require('fs');
|
|
4
|
+
|
|
5
|
+
let currentWorkDir = process.env.INKOS_WORK_DIR || process.cwd();
|
|
6
|
+
|
|
7
|
+
function setWorkDir(dir) {
|
|
8
|
+
if (fs.existsSync(dir)) {
|
|
9
|
+
currentWorkDir = dir;
|
|
10
|
+
return true;
|
|
11
|
+
}
|
|
12
|
+
return false;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
function getWorkDir() {
|
|
16
|
+
return currentWorkDir;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
function quoteArg(arg) {
|
|
20
|
+
if (process.platform === 'win32') {
|
|
21
|
+
if (arg.includes(' ') || /[^\x00-\x7F]/.test(arg)) {
|
|
22
|
+
return `"${arg}"`;
|
|
23
|
+
}
|
|
24
|
+
return arg;
|
|
25
|
+
}
|
|
26
|
+
return arg;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
function execInkos(command, args = [], options = {}) {
|
|
30
|
+
return new Promise((resolve, reject) => {
|
|
31
|
+
let fullArgs;
|
|
32
|
+
|
|
33
|
+
if (Array.isArray(command)) {
|
|
34
|
+
fullArgs = [...command];
|
|
35
|
+
} else {
|
|
36
|
+
fullArgs = command.split(' ');
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
if (Array.isArray(args) && args.length > 0) {
|
|
40
|
+
fullArgs.push(...args);
|
|
41
|
+
} else if (typeof args === 'object' && args !== null) {
|
|
42
|
+
options = args;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
if (options.json !== false && !fullArgs.includes('--json')) {
|
|
46
|
+
fullArgs.push('--json');
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
const cwd = options.cwd || currentWorkDir;
|
|
50
|
+
|
|
51
|
+
const displayArgs = fullArgs.map(arg => quoteArg(arg)).join(' ');
|
|
52
|
+
console.log(`[CLI] Executing: inkos ${displayArgs} in ${cwd}`);
|
|
53
|
+
|
|
54
|
+
let proc;
|
|
55
|
+
if (process.platform === 'win32') {
|
|
56
|
+
const cmdArgs = fullArgs.map(arg => quoteArg(arg));
|
|
57
|
+
proc = spawn('inkos', cmdArgs, {
|
|
58
|
+
encoding: 'utf-8',
|
|
59
|
+
cwd: cwd,
|
|
60
|
+
shell: true,
|
|
61
|
+
env: { ...process.env, ...options.env },
|
|
62
|
+
});
|
|
63
|
+
} else {
|
|
64
|
+
proc = spawn('inkos', fullArgs, {
|
|
65
|
+
encoding: 'utf-8',
|
|
66
|
+
cwd: cwd,
|
|
67
|
+
shell: process.platform === 'win32',
|
|
68
|
+
env: { ...process.env, ...options.env },
|
|
69
|
+
});
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
let stdout = '';
|
|
73
|
+
let stderr = '';
|
|
74
|
+
|
|
75
|
+
proc.stdout.on('data', (data) => {
|
|
76
|
+
const str = data.toString();
|
|
77
|
+
stdout += str;
|
|
78
|
+
if (options.onStdout) {
|
|
79
|
+
options.onStdout(str);
|
|
80
|
+
}
|
|
81
|
+
});
|
|
82
|
+
|
|
83
|
+
proc.stderr.on('data', (data) => {
|
|
84
|
+
const str = data.toString();
|
|
85
|
+
stderr += str;
|
|
86
|
+
if (options.onStderr) {
|
|
87
|
+
options.onStderr(str);
|
|
88
|
+
}
|
|
89
|
+
});
|
|
90
|
+
|
|
91
|
+
proc.on('close', (code) => {
|
|
92
|
+
console.log(`[CLI] Exit code: ${code}`);
|
|
93
|
+
|
|
94
|
+
if (code === 0) {
|
|
95
|
+
try {
|
|
96
|
+
const trimmed = stdout.trim();
|
|
97
|
+
if (trimmed) {
|
|
98
|
+
const json = JSON.parse(trimmed);
|
|
99
|
+
resolve({ success: true, data: json, stdout });
|
|
100
|
+
} else {
|
|
101
|
+
resolve({ success: true, data: {}, stdout });
|
|
102
|
+
}
|
|
103
|
+
} catch (error) {
|
|
104
|
+
resolve({ success: true, data: stdout, stdout });
|
|
105
|
+
}
|
|
106
|
+
} else {
|
|
107
|
+
const errorMsg = stderr || stdout || `Command failed with code ${code}`;
|
|
108
|
+
resolve({ success: false, error: errorMsg, stderr, stdout, code });
|
|
109
|
+
}
|
|
110
|
+
});
|
|
111
|
+
|
|
112
|
+
proc.on('error', (error) => {
|
|
113
|
+
console.error(`[CLI] Error: ${error.message}`);
|
|
114
|
+
resolve({ success: false, error: error.message, stderr: error.message });
|
|
115
|
+
});
|
|
116
|
+
|
|
117
|
+
if (options.timeout) {
|
|
118
|
+
setTimeout(() => {
|
|
119
|
+
proc.kill();
|
|
120
|
+
resolve({ success: false, error: 'Command timed out', stderr: 'Command timed out' });
|
|
121
|
+
}, options.timeout);
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
if (options.stdin) {
|
|
125
|
+
proc.stdin.write(options.stdin);
|
|
126
|
+
proc.stdin.end();
|
|
127
|
+
}
|
|
128
|
+
});
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
function execInkosStream(command, args = [], options = {}) {
|
|
132
|
+
let fullArgs;
|
|
133
|
+
|
|
134
|
+
if (Array.isArray(command)) {
|
|
135
|
+
fullArgs = [...command];
|
|
136
|
+
} else {
|
|
137
|
+
fullArgs = command.split(' ');
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
if (Array.isArray(args) && args.length > 0) {
|
|
141
|
+
fullArgs.push(...args);
|
|
142
|
+
} else if (typeof args === 'object' && args !== null) {
|
|
143
|
+
options = args;
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
if (options.json !== false && !fullArgs.includes('--json')) {
|
|
147
|
+
fullArgs.push('--json');
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
const cwd = options.cwd || currentWorkDir;
|
|
151
|
+
|
|
152
|
+
const displayArgs = fullArgs.map(arg => quoteArg(arg)).join(' ');
|
|
153
|
+
console.log(`[CLI] Streaming: inkos ${displayArgs} in ${cwd}`);
|
|
154
|
+
|
|
155
|
+
let proc;
|
|
156
|
+
if (process.platform === 'win32') {
|
|
157
|
+
const cmdArgs = fullArgs.map(arg => quoteArg(arg));
|
|
158
|
+
proc = spawn('inkos', cmdArgs, {
|
|
159
|
+
encoding: 'utf-8',
|
|
160
|
+
cwd: cwd,
|
|
161
|
+
shell: true,
|
|
162
|
+
env: { ...process.env, ...options.env },
|
|
163
|
+
});
|
|
164
|
+
} else {
|
|
165
|
+
proc = spawn('inkos', fullArgs, {
|
|
166
|
+
encoding: 'utf-8',
|
|
167
|
+
cwd: cwd,
|
|
168
|
+
shell: process.platform === 'win32',
|
|
169
|
+
env: { ...process.env, ...options.env },
|
|
170
|
+
});
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
return proc;
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
function parseTextOutput(text) {
|
|
177
|
+
const lines = text.split('\n').filter(line => line.trim());
|
|
178
|
+
return lines;
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
function parseKeyValueOutput(text) {
|
|
182
|
+
const result = {};
|
|
183
|
+
const lines = text.split('\n');
|
|
184
|
+
|
|
185
|
+
for (const line of lines) {
|
|
186
|
+
const match = line.match(/^([^:]+):\s*(.+)$/);
|
|
187
|
+
if (match) {
|
|
188
|
+
result[match[1].trim()] = match[2].trim();
|
|
189
|
+
}
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
return result;
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
module.exports = {
|
|
196
|
+
execInkos,
|
|
197
|
+
execInkosStream,
|
|
198
|
+
setWorkDir,
|
|
199
|
+
getWorkDir,
|
|
200
|
+
parseTextOutput,
|
|
201
|
+
parseKeyValueOutput,
|
|
202
|
+
};
|
package/package.json
ADDED
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@xiguanpm/inkos-web",
|
|
3
|
+
"version": "1.0.6",
|
|
4
|
+
"description": "InkOS Web 小说写作管理系统",
|
|
5
|
+
"main": "dist-server/index.js",
|
|
6
|
+
"bin": {
|
|
7
|
+
"inkos-web": "bin/cli.js"
|
|
8
|
+
},
|
|
9
|
+
"scripts": {
|
|
10
|
+
"dev": "vite",
|
|
11
|
+
"build": "tsc && vite build",
|
|
12
|
+
"build:server": "node scripts/build-server.js",
|
|
13
|
+
"build:all": "npm run build && npm run build:server",
|
|
14
|
+
"preview": "vite preview",
|
|
15
|
+
"server": "node server/index.js",
|
|
16
|
+
"server:dev": "node server/index.js",
|
|
17
|
+
"start": "concurrently \"npm run server\" \"npm run dev\""
|
|
18
|
+
},
|
|
19
|
+
"dependencies": {
|
|
20
|
+
"multer": "^2.0.0",
|
|
21
|
+
"express": "^4.18.0",
|
|
22
|
+
"cors": "^2.8.5",
|
|
23
|
+
"body-parser": "^1.20.0",
|
|
24
|
+
"concurrently": "^8.2.0"
|
|
25
|
+
},
|
|
26
|
+
"devDependencies": {
|
|
27
|
+
"@types/react": "^18.2.0",
|
|
28
|
+
"@types/react-dom": "^18.2.0",
|
|
29
|
+
"@vitejs/plugin-react": "^4.2.0",
|
|
30
|
+
"typescript": "^5.3.0",
|
|
31
|
+
"vite": "^5.1.0",
|
|
32
|
+
"react": "^18.2.0",
|
|
33
|
+
"react-dom": "^18.2.0",
|
|
34
|
+
"react-router-dom": "^6.22.0",
|
|
35
|
+
"antd": "^5.14.0",
|
|
36
|
+
"@ant-design/icons": "^5.3.0",
|
|
37
|
+
"axios": "^1.6.0",
|
|
38
|
+
"echarts": "^5.5.0",
|
|
39
|
+
"echarts-for-react": "^3.0.2",
|
|
40
|
+
"@microlink/react-json-view": "^1.23.0"
|
|
41
|
+
},
|
|
42
|
+
"files": [
|
|
43
|
+
"dist",
|
|
44
|
+
"dist-server",
|
|
45
|
+
"bin",
|
|
46
|
+
"LICENSE"
|
|
47
|
+
],
|
|
48
|
+
"keywords": [
|
|
49
|
+
"inkos",
|
|
50
|
+
"web",
|
|
51
|
+
"visualization",
|
|
52
|
+
"management"
|
|
53
|
+
],
|
|
54
|
+
"engines": {
|
|
55
|
+
"node": ">=16.0.0"
|
|
56
|
+
}
|
|
57
|
+
}
|