webide-cli 0.0.1-alpha.6 → 0.0.1-alpha.8

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.
Files changed (3) hide show
  1. package/README.md +1 -0
  2. package/index.js +44 -3
  3. package/package.json +1 -1
package/README.md CHANGED
@@ -4,6 +4,7 @@ QQ群:1050254184
4
4
  # 安装
5
5
  1. 安装NodeJS和NPM:(如已安装,则跳过此步骤)
6
6
  ```bash
7
+ # WebIDE内置的Alpine Linux系统,该CLI仅限WebIDE使用
7
8
  apk add nodejs
8
9
  apk add npm
9
10
  # 验证是否已安装
package/index.js CHANGED
@@ -80,7 +80,7 @@ program
80
80
  program
81
81
  .command('remove <name>')
82
82
  .description('Remove a library')
83
- .action(function (libname) {
83
+ .action(function (libname) {
84
84
  const libPath = path.join(workdir, 'libs', libname);
85
85
  if (fs.existsSync(libPath)) {
86
86
  fs.rmSync(libPath, { recursive: true, force: true });
@@ -90,6 +90,24 @@ program
90
90
  }
91
91
  });
92
92
 
93
+ function truncateMessage(msg, maxLength = 50) {
94
+ if (msg.length <= maxLength) return msg;
95
+ return msg.substring(0, maxLength - 3) + '...';
96
+ }
97
+
98
+ program
99
+ .command('search <keyword>')
100
+ .description('Search for libraries')
101
+ .action(async function (keyword) {
102
+ const load = loading(`Searching for libraries with keyword "${truncateMessage(keyword)}" ...`);
103
+ const results = await search(keyword);
104
+ load();
105
+ console.log("\r\nSearch results(" + results.length + " items):");
106
+ for (const lib of results) {
107
+ console.log(` ${lib.name.replaceAll(keyword, `\x1b[43;30m${keyword}\x1b[0m`)}`);
108
+ }
109
+ });
110
+
93
111
  program
94
112
  .parse(process.argv);
95
113
 
@@ -105,14 +123,31 @@ async function getFile(path) {
105
123
 
106
124
  function loading(msg) {
107
125
  const spinnerChars = ['⠙', '⠹', '⠸', '⠼', '⠴', '⠦', '⠧', '⠇', '⠏'];
126
+ const terminalWidth = process.stdout.columns || 80; // 获取终端宽度
108
127
  let i = 0;
128
+ let linesUsed = Math.ceil((spinnerChars[0].length + msg.length + 1) / terminalWidth);
129
+
109
130
  const interval = setInterval(() => {
110
- process.stdout.write(`\r${spinnerChars[i++]} ${msg}`);
131
+ const displayText = `${spinnerChars[i++]} ${msg}`;
132
+ linesUsed = Math.ceil(displayText.length / terminalWidth);
133
+
134
+ // 清除之前占用的行
135
+ let clearLines = '';
136
+ for (let j = 0; j < linesUsed - 1; j++) {
137
+ clearLines += '\x1b[1F\x1b[K'; // 移动到上一行并清除
138
+ }
139
+ clearLines += '\r\x1b[K';
140
+ process.stdout.write(clearLines + displayText);
111
141
  i = i % spinnerChars.length;
112
142
  }, 50);
113
143
  return () => {
114
144
  clearInterval(interval);
115
- process.stdout.write('\r\x1b[K');
145
+ let clearLines = '';
146
+ for (let j = 0; j < linesUsed - 1; j++) {
147
+ clearLines += '\x1b[1F\x1b[K';
148
+ }
149
+ clearLines += '\r\x1b[K';
150
+ process.stdout.write(clearLines);
116
151
  }
117
152
  }
118
153
 
@@ -134,4 +169,10 @@ async function download(path, savepath) {
134
169
  const bufferData = Buffer.from(await fileData.arrayBuffer());
135
170
  fs.writeFileSync(filepath, bufferData);
136
171
  }
172
+ }
173
+
174
+ async function search(keyword) {
175
+ const { data, error } = await bucket.list('');
176
+ if (error) throw error;
177
+ return data.filter(file => file.name.includes(keyword));
137
178
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "webide-cli",
3
- "version": "0.0.1-alpha.6",
3
+ "version": "0.0.1-alpha.8",
4
4
  "description": "A CLI for NEW WebIDE",
5
5
  "keywords": [
6
6
  "WebIDE",