webide-cli 0.0.1-alpha.3 → 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 ADDED
@@ -0,0 +1,25 @@
1
+ # WebIDE CLI命令行工具
2
+ QQ群:1050254184
3
+
4
+ # 安装
5
+ 1. 安装NodeJS和NPM:(如已安装,则跳过此步骤)
6
+ ```bash
7
+ apk add nodejs
8
+ apk add npm
9
+ # 验证是否已安装
10
+ node -v
11
+ npm -v
12
+ ```
13
+ 2. 安装CLI工具:
14
+ ```bash
15
+ npm install -g webide-cli
16
+ ```
17
+ 3. 验证是否安装成功:
18
+ ```bash
19
+ webide -v
20
+ ```
21
+ 4. 获取相关帮助:
22
+ ```bash
23
+ webide -h
24
+ ```
25
+ > 安装过程如有问题,请加Q群反馈
package/index.js CHANGED
@@ -1,8 +1,22 @@
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
18
+ .name('webide')
19
+ .description('A CLI for NEW WebIDE.\nJoin QQ group 1050254184 for help and feedback.')
6
20
  .version(version)
7
21
 
8
22
  program
@@ -13,4 +27,98 @@ program
13
27
  });
14
28
 
15
29
  program
16
- .parse(process.argv);
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
@@ -6,7 +6,6 @@ const arch = os.arch();
6
6
  const workdir = process.cwd();
7
7
  const bindir = "/usr/bin/";
8
8
 
9
- // console.log(workdir);
10
9
  if (platform === "linux" && arch === "arm64") {
11
10
  fs.writeFile(bindir + "webide", `#!/bin/bash
12
11
  node ${workdir}/index.js "$@"
@@ -0,0 +1 @@
1
+ console.log("Hello World!");
@@ -0,0 +1,5 @@
1
+ {
2
+ "name": "example",
3
+ "description": "An example lib",
4
+ "version": "1.0.0"
5
+ }
package/package.json CHANGED
@@ -1,9 +1,10 @@
1
1
  {
2
2
  "name": "webide-cli",
3
- "version": "0.0.1-alpha.3",
3
+ "version": "0.0.1-alpha.5",
4
4
  "description": "A CLI for NEW WebIDE",
5
5
  "keywords": [
6
6
  "WebIDE",
7
+ "CLI",
7
8
  "IFTC",
8
9
  "VV"
9
10
  ],
@@ -20,6 +21,7 @@
20
21
  "postinstall": "node init"
21
22
  },
22
23
  "dependencies": {
24
+ "@supabase/supabase-js": "^2.90.1",
23
25
  "commander": "^14.0.2"
24
26
  }
25
27
  }
package/webapp.json ADDED
File without changes