webide-cli 0.0.1-alpha.4 → 0.0.1-alpha.5
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 -1
- package/index.js +107 -1
- package/init.js +0 -1
- package/libs/example/example.js +1 -0
- package/libs/example/lib.json +5 -0
- package/package.json +2 -1
- package/webapp.json +0 -0
package/README.md
CHANGED
package/index.js
CHANGED
|
@@ -1,6 +1,18 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
const { program } = require('commander');
|
|
3
3
|
const { version } = require('./package.json');
|
|
4
|
+
const { createClient } = require('@supabase/supabase-js');
|
|
5
|
+
const fs = require('fs');
|
|
6
|
+
const path = require('path');
|
|
7
|
+
|
|
8
|
+
const SUPABASE_URL = "https://dbmp-xbgmorqeur6oh81z.database.nocode.cn";
|
|
9
|
+
const SUPABASE_ANON_KEY = "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJyb2xlIjoiYW5vbiIsImlzcyI6InN1cGFiYXNlIiwiaWF0IjoxNzQ2OTc5MjAwLCJleHAiOjE5MDQ3NDU2MDB9.11QbQ5OW_m10vblDXAlw1Qq7Dve5Swzn12ILo7-9IXY";
|
|
10
|
+
const FILE_BUCKET = "jslib";
|
|
11
|
+
|
|
12
|
+
const supabase = createClient(SUPABASE_URL, SUPABASE_ANON_KEY);
|
|
13
|
+
const bucket = supabase.storage.from(FILE_BUCKET);
|
|
14
|
+
|
|
15
|
+
const workdir = process.cwd();
|
|
4
16
|
|
|
5
17
|
program
|
|
6
18
|
.name('webide')
|
|
@@ -15,4 +27,98 @@ program
|
|
|
15
27
|
});
|
|
16
28
|
|
|
17
29
|
program
|
|
18
|
-
.
|
|
30
|
+
.command('workdir')
|
|
31
|
+
.description('Show current working directory.')
|
|
32
|
+
.action(() => {
|
|
33
|
+
console.log("Current working directory:", process.cwd());
|
|
34
|
+
});
|
|
35
|
+
|
|
36
|
+
program
|
|
37
|
+
.command('add <name>')
|
|
38
|
+
.description('Add a new library.')
|
|
39
|
+
.action(async (libname) => {
|
|
40
|
+
fs.access(workdir + "/webapp.json", fs.constants.F_OK, (err) => {
|
|
41
|
+
if (err) {
|
|
42
|
+
console.error("webapp.json not found in current directory. Please make sure you are in a WebIDE project directory.");
|
|
43
|
+
process.exit(114514);
|
|
44
|
+
}
|
|
45
|
+
});
|
|
46
|
+
fs.mkdirSync(path.join(workdir, 'libs', libname), { recursive: true });
|
|
47
|
+
try {
|
|
48
|
+
const load = loading(`Checking if library "${libname}" exists...`);
|
|
49
|
+
if (await checkFileExists(libname + "/lib.json")) {
|
|
50
|
+
load();
|
|
51
|
+
console.log(`Library "${libname}" already exists.`);
|
|
52
|
+
console.log(`Start downloading...`);
|
|
53
|
+
const downloadingTip = `Downloading library "${libname}" ...`;
|
|
54
|
+
let load2 = loading(downloadingTip);
|
|
55
|
+
const libJsonData = await getFile(libname + "/lib.json");
|
|
56
|
+
const libJson = JSON.parse(await libJsonData.text());
|
|
57
|
+
const { name, author, description, version } = libJson;
|
|
58
|
+
load2();
|
|
59
|
+
console.log(`Library info: `);
|
|
60
|
+
console.log(` Name: ${name}`);
|
|
61
|
+
console.log(` Version: ${version}`);
|
|
62
|
+
console.log(` Author: ${author || 'Unknown'}`);
|
|
63
|
+
console.log(` Description: ${description || 'No description'}`);
|
|
64
|
+
load2 = loading(downloadingTip);
|
|
65
|
+
await download(libname, path.join(workdir, 'libs', libname));
|
|
66
|
+
load2();
|
|
67
|
+
console.log(`Library "${libname}" downloaded successfully.`);
|
|
68
|
+
} else {
|
|
69
|
+
load();
|
|
70
|
+
console.error(`Library "${libname}" does not exist in the database.`);
|
|
71
|
+
process.exit(114514);
|
|
72
|
+
}
|
|
73
|
+
} catch (error) {
|
|
74
|
+
fs.rmSync(path.join(workdir, 'libs', libname), { recursive: true, force: true });
|
|
75
|
+
console.error("\r\nAn error occurred:", error.stack);
|
|
76
|
+
process.exit(114514);
|
|
77
|
+
}
|
|
78
|
+
});
|
|
79
|
+
|
|
80
|
+
program
|
|
81
|
+
.parse(process.argv);
|
|
82
|
+
|
|
83
|
+
async function checkFileExists(path) {
|
|
84
|
+
const { data } = await bucket.exists(path);
|
|
85
|
+
return data;
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
async function getFile(path) {
|
|
89
|
+
const { data, error } = await bucket.download(path);
|
|
90
|
+
return data;
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
function loading(msg) {
|
|
94
|
+
const spinnerChars = ['⠙', '⠹', '⠸', '⠼', '⠴', '⠦', '⠧', '⠇', '⠏'];
|
|
95
|
+
let i = 0;
|
|
96
|
+
const interval = setInterval(() => {
|
|
97
|
+
process.stdout.write(`\r${spinnerChars[i++]} ${msg}`);
|
|
98
|
+
i = i % spinnerChars.length;
|
|
99
|
+
}, 50);
|
|
100
|
+
return () => {
|
|
101
|
+
clearInterval(interval);
|
|
102
|
+
process.stdout.write('\r\x1b[K');
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
async function download(path, savepath) {
|
|
107
|
+
const { data, error } = await bucket.list(path);
|
|
108
|
+
if (error) throw error;
|
|
109
|
+
for (const file of data) {
|
|
110
|
+
const remotePath = path ? `${path}/${file.name}` : file.name;
|
|
111
|
+
if (!file.metadata) {
|
|
112
|
+
const localDirPath = require("path").join(savepath, file.name);
|
|
113
|
+
fs.mkdirSync(localDirPath, { recursive: true });
|
|
114
|
+
await download(remotePath, localDirPath);
|
|
115
|
+
continue;
|
|
116
|
+
}
|
|
117
|
+
const { data: fileData, error: downloadError } = await bucket.download(remotePath);
|
|
118
|
+
if (downloadError) throw downloadError;
|
|
119
|
+
const filepath = require("path").join(savepath, file.name);
|
|
120
|
+
fs.mkdirSync(require("path").dirname(filepath), { recursive: true });
|
|
121
|
+
const bufferData = Buffer.from(await fileData.arrayBuffer());
|
|
122
|
+
fs.writeFileSync(filepath, bufferData);
|
|
123
|
+
}
|
|
124
|
+
}
|
package/init.js
CHANGED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
console.log("Hello World!");
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "webide-cli",
|
|
3
|
-
"version": "0.0.1-alpha.
|
|
3
|
+
"version": "0.0.1-alpha.5",
|
|
4
4
|
"description": "A CLI for NEW WebIDE",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"WebIDE",
|
|
@@ -21,6 +21,7 @@
|
|
|
21
21
|
"postinstall": "node init"
|
|
22
22
|
},
|
|
23
23
|
"dependencies": {
|
|
24
|
+
"@supabase/supabase-js": "^2.90.1",
|
|
24
25
|
"commander": "^14.0.2"
|
|
25
26
|
}
|
|
26
27
|
}
|
package/webapp.json
ADDED
|
File without changes
|