webide-cli 0.0.1-beta.2 → 0.0.1-beta.3
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/.vscode/settings.json +3 -0
- package/README.md +23 -1
- package/index.js +100 -1
- package/package.json +1 -1
- package/webapp.json +1 -0
package/README.md
CHANGED
|
@@ -23,4 +23,26 @@ webide -v
|
|
|
23
23
|
```bash
|
|
24
24
|
webide -h
|
|
25
25
|
```
|
|
26
|
-
> 安装过程如有问题,请加Q群反馈
|
|
26
|
+
> 安装过程如有问题,请加Q群反馈
|
|
27
|
+
|
|
28
|
+
# 使用方法
|
|
29
|
+
```bash
|
|
30
|
+
# 列出WebIDE CLI相关信息
|
|
31
|
+
webide info
|
|
32
|
+
# 显示当前工作目录
|
|
33
|
+
webide workdir
|
|
34
|
+
# 添加第三方库
|
|
35
|
+
webide add <name>
|
|
36
|
+
# 移除第三方库
|
|
37
|
+
webide remove <name>
|
|
38
|
+
# 设置相关配置
|
|
39
|
+
webide config set <key> <value>
|
|
40
|
+
# 获取相关配置
|
|
41
|
+
webide config get <key>
|
|
42
|
+
# 删除相关配置
|
|
43
|
+
webide config delete <key>
|
|
44
|
+
# 列出所有配置项
|
|
45
|
+
webide config list
|
|
46
|
+
# 显示所有第三方库需引入的文件
|
|
47
|
+
webide imports
|
|
48
|
+
```
|
package/index.js
CHANGED
|
@@ -3,6 +3,7 @@ const { program } = require('commander');
|
|
|
3
3
|
const { version } = require('./package.json');
|
|
4
4
|
const { createClient } = require('@supabase/supabase-js');
|
|
5
5
|
const fs = require('fs');
|
|
6
|
+
const os = require('os');
|
|
6
7
|
const path = require('path');
|
|
7
8
|
const readline = require('readline');
|
|
8
9
|
|
|
@@ -20,7 +21,8 @@ const workdir = process.cwd();
|
|
|
20
21
|
const workspacedir = process.env.WEBIDE_WORKSPACE;
|
|
21
22
|
const webideVersionName = process.env.WEBIDE_VERSION_NAME || 'Unknown';
|
|
22
23
|
const webideVersionCode = process.env.WEBIDE_VERSION_CODE || 'Unknown';
|
|
23
|
-
|
|
24
|
+
const homedir = process.env.HOME || os.homedir();
|
|
25
|
+
const configdir = path.join(homedir, '.webide.json');
|
|
24
26
|
|
|
25
27
|
program
|
|
26
28
|
.name('webide')
|
|
@@ -142,6 +144,103 @@ program
|
|
|
142
144
|
}
|
|
143
145
|
});
|
|
144
146
|
|
|
147
|
+
const configCmd = program
|
|
148
|
+
.command('config')
|
|
149
|
+
.description('Configuration management');
|
|
150
|
+
|
|
151
|
+
configCmd
|
|
152
|
+
.command('set <key> <value>')
|
|
153
|
+
.description('Set a configuration value')
|
|
154
|
+
.action(function (key, value) {
|
|
155
|
+
const config = fs.existsSync(configdir) ? JSON.parse(fs.readFileSync(configdir, 'utf8')) : {};
|
|
156
|
+
config[key] = value;
|
|
157
|
+
fs.writeFileSync(configdir, JSON.stringify(config, null, 4));
|
|
158
|
+
console.log(`Configuration "${key}" set to "${value}".`);
|
|
159
|
+
});
|
|
160
|
+
|
|
161
|
+
configCmd
|
|
162
|
+
.command('get <key>')
|
|
163
|
+
.description('Get a configuration value.')
|
|
164
|
+
.action(function (key) {
|
|
165
|
+
if (!fs.existsSync(configdir)) {
|
|
166
|
+
fs.writeFileSync(configdir, '{}');
|
|
167
|
+
}
|
|
168
|
+
const config = JSON.parse(fs.readFileSync(configdir, 'utf8'));
|
|
169
|
+
if (config.hasOwnProperty(key)) {
|
|
170
|
+
console.log(`${key}=${config[key]}`);
|
|
171
|
+
} else {
|
|
172
|
+
console.error(`Configuration "${key}" does not exist.`);
|
|
173
|
+
}
|
|
174
|
+
});
|
|
175
|
+
|
|
176
|
+
configCmd
|
|
177
|
+
.command('delete <key>')
|
|
178
|
+
.description('Delete a configuration')
|
|
179
|
+
.action(function (key) {
|
|
180
|
+
if (!fs.existsSync(configdir)) {
|
|
181
|
+
fs.writeFileSync(configdir, '{}');
|
|
182
|
+
}
|
|
183
|
+
let config = JSON.parse(fs.readFileSync(configdir));
|
|
184
|
+
if (config.hasOwnProperty(key)) {
|
|
185
|
+
delete config[key];
|
|
186
|
+
fs.writeFileSync(configdir, JSON.stringify(config, null, 4));
|
|
187
|
+
console.log(`Deleted configuration "${key}".`);
|
|
188
|
+
} else {
|
|
189
|
+
console.error(`Configuration "${key}" does not exist.`);
|
|
190
|
+
}
|
|
191
|
+
});
|
|
192
|
+
|
|
193
|
+
configCmd
|
|
194
|
+
.command('list')
|
|
195
|
+
.description('List all configurations')
|
|
196
|
+
.action(function () {
|
|
197
|
+
if (!fs.existsSync(configdir)) {
|
|
198
|
+
fs.writeFileSync(configdir, '{}');
|
|
199
|
+
}
|
|
200
|
+
const config = JSON.parse(fs.readFileSync(configdir, 'utf8'));
|
|
201
|
+
for (const key in config) {
|
|
202
|
+
console.log(`${key}=${config[key]}`);
|
|
203
|
+
}
|
|
204
|
+
});
|
|
205
|
+
|
|
206
|
+
program
|
|
207
|
+
.command('imports')
|
|
208
|
+
.description('List all imports')
|
|
209
|
+
.action(function () {
|
|
210
|
+
fs.access(workdir + "/webapp.json", fs.constants.F_OK, (err) => {
|
|
211
|
+
if (err) {
|
|
212
|
+
console.error("webapp.json not found in current directory. Please make sure you are in a WebIDE project directory.");
|
|
213
|
+
process.exit(114514);
|
|
214
|
+
}
|
|
215
|
+
const libsDir = path.join(workdir, 'libs');
|
|
216
|
+
const files = [];
|
|
217
|
+
if (!fs.existsSync(libsDir)) {
|
|
218
|
+
console.log("No libraries imported.");
|
|
219
|
+
process.exit(0);
|
|
220
|
+
}
|
|
221
|
+
const libnames = fs.readdirSync(libsDir);
|
|
222
|
+
if (libnames.length === 0) {
|
|
223
|
+
console.log("No libraries imported.");
|
|
224
|
+
process.exit(0);
|
|
225
|
+
}
|
|
226
|
+
console.log("Libraries import files:");
|
|
227
|
+
for (const libname of libnames) {
|
|
228
|
+
console.log(` ${libname}`);
|
|
229
|
+
const libPath = path.join(libsDir, libname, 'lib.json');
|
|
230
|
+
const libJson = JSON.parse(fs.readFileSync(libPath));
|
|
231
|
+
const imports = libJson.imports || [];
|
|
232
|
+
if (imports.length > 0) {
|
|
233
|
+
for (let i = 0; i < imports.length; i++) {
|
|
234
|
+
const importPath = path.join(libsDir, libname, imports[i]);
|
|
235
|
+
files.push(encodeURIComponent(imports[i]));
|
|
236
|
+
console.log(` ${i == imports.length - 1 ? '└──' : '├──'} ${importPath}`);
|
|
237
|
+
}
|
|
238
|
+
}
|
|
239
|
+
}
|
|
240
|
+
fs.writeFileSync(path.join(workdir, 'imports.txt'), files.join('\n'));
|
|
241
|
+
});
|
|
242
|
+
});
|
|
243
|
+
|
|
145
244
|
program
|
|
146
245
|
.parse(process.argv);
|
|
147
246
|
|
package/package.json
CHANGED
package/webapp.json
CHANGED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{}
|