webide-cli 0.0.1-beta.5 → 0.0.2
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 +2 -0
- package/index.js +88 -1
- package/package.json +1 -1
package/README.md
CHANGED
package/index.js
CHANGED
|
@@ -65,6 +65,26 @@ program
|
|
|
65
65
|
console.log("Current working directory:", process.cwd());
|
|
66
66
|
});
|
|
67
67
|
|
|
68
|
+
program
|
|
69
|
+
.command("checkdb")
|
|
70
|
+
.description("Check if Database connection is working.")
|
|
71
|
+
.action(async () => {
|
|
72
|
+
const load = loading("Checking database connection...");
|
|
73
|
+
try {
|
|
74
|
+
const { data, error } = await bucket.exists('.check');
|
|
75
|
+
if (error) {
|
|
76
|
+
load();
|
|
77
|
+
console.error("Database connection failed:", error.message);
|
|
78
|
+
process.exit(114514);
|
|
79
|
+
}
|
|
80
|
+
load();
|
|
81
|
+
console.log("Database connection is working.");
|
|
82
|
+
} catch (error) {
|
|
83
|
+
load();
|
|
84
|
+
console.error("Database connection failed:", error.message);
|
|
85
|
+
}
|
|
86
|
+
})
|
|
87
|
+
|
|
68
88
|
program
|
|
69
89
|
.command('add <name>')
|
|
70
90
|
.description('Add a new library.')
|
|
@@ -152,6 +172,73 @@ program
|
|
|
152
172
|
}
|
|
153
173
|
});
|
|
154
174
|
|
|
175
|
+
program
|
|
176
|
+
.command('publish <libpath>')
|
|
177
|
+
.description('Publish a library')
|
|
178
|
+
.action(async function (libpath) {
|
|
179
|
+
libpath = path.resolve(libpath);
|
|
180
|
+
fs.access(path.join(libpath, 'lib.json'), fs.constants.F_OK, async (err) => {
|
|
181
|
+
if (err) {
|
|
182
|
+
console.error("lib.json not found in current directory. Please make sure you are in a WebIDE library directory.");
|
|
183
|
+
process.exit(114514);
|
|
184
|
+
}
|
|
185
|
+
const libJsonData = fs.readFileSync(path.join(libpath, 'lib.json'), 'utf8');
|
|
186
|
+
const libJson = JSON.parse(libJsonData);
|
|
187
|
+
const { name, author, description, version, imports } = libJson;
|
|
188
|
+
if (!name || !author || !description || !version) {
|
|
189
|
+
console.error("Invalid lib.json. Please make sure all required fields are present.");
|
|
190
|
+
process.exit(114514);
|
|
191
|
+
}
|
|
192
|
+
console.log("Library Info:");
|
|
193
|
+
console.log(` Name: ${name}`);
|
|
194
|
+
console.log(` Version: ${version}`);
|
|
195
|
+
console.log(` Author: ${author}`);
|
|
196
|
+
console.log(` Description: ${description}`);
|
|
197
|
+
if (imports && imports.length > 0) {
|
|
198
|
+
console.log(` Imports:`);
|
|
199
|
+
for (let i = 0; i < imports.length; i++) {
|
|
200
|
+
console.log(` ${path.join(libpath, imports[i])}`);
|
|
201
|
+
}
|
|
202
|
+
}
|
|
203
|
+
const load = loading(`Publishing library "${name}" ...`);
|
|
204
|
+
let totalSize = 0;
|
|
205
|
+
let totalFiles = 0;
|
|
206
|
+
await upload(libpath);
|
|
207
|
+
load();
|
|
208
|
+
console.log(`Total files: ${totalFiles}`);
|
|
209
|
+
console.log(`Total size: ${totalSize} bytes`);
|
|
210
|
+
console.log(`Library "${name}" published successfully.`);
|
|
211
|
+
|
|
212
|
+
async function upload(filepath) {
|
|
213
|
+
const files = fs.readdirSync(filepath);
|
|
214
|
+
for (const file of files) {
|
|
215
|
+
const filePath = path.join(libpath, file);
|
|
216
|
+
const stats = fs.statSync(filePath);
|
|
217
|
+
if (stats.isFile()) {
|
|
218
|
+
const fileData = fs.readFileSync(filePath);
|
|
219
|
+
const fileName = path.basename(filePath);
|
|
220
|
+
const fileType = path.extname(filePath).substring(1);
|
|
221
|
+
const fileSize = stats.size;
|
|
222
|
+
totalSize += fileSize;
|
|
223
|
+
totalFiles++;
|
|
224
|
+
const fp = filePath.replace(libpath, name).replace(/\\/g, '/');
|
|
225
|
+
const { data, error } = await bucket.update(fp, fileData, { contentType: fileType });
|
|
226
|
+
if (error) {
|
|
227
|
+
load();
|
|
228
|
+
console.error("\r\nAn error occurred:", error.stack);
|
|
229
|
+
process.exit(114514);
|
|
230
|
+
}
|
|
231
|
+
} else if (stats.isDirectory()) {
|
|
232
|
+
await upload(filePath);
|
|
233
|
+
} else {
|
|
234
|
+
load();
|
|
235
|
+
throw new Error(`Invalid file type: ${filePath}`);
|
|
236
|
+
}
|
|
237
|
+
}
|
|
238
|
+
}
|
|
239
|
+
})
|
|
240
|
+
});
|
|
241
|
+
|
|
155
242
|
const configCmd = program
|
|
156
243
|
.command('config')
|
|
157
244
|
.description('Configuration management');
|
|
@@ -251,7 +338,7 @@ program
|
|
|
251
338
|
|
|
252
339
|
program
|
|
253
340
|
.command('update')
|
|
254
|
-
.description('Update WebIDE')
|
|
341
|
+
.description('Update WebIDE CLI')
|
|
255
342
|
.action(async function () {
|
|
256
343
|
const load = loading("Checking for updates...");
|
|
257
344
|
const r = await fetch("https://registry.npmjs.org/webide-cli");
|