webide-cli 0.0.1-beta.4 → 0.0.1
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/index.js +66 -2
- package/package.json +1 -1
package/index.js
CHANGED
|
@@ -152,6 +152,70 @@ program
|
|
|
152
152
|
}
|
|
153
153
|
});
|
|
154
154
|
|
|
155
|
+
program
|
|
156
|
+
.command('publish <libpath>')
|
|
157
|
+
.description('Publish a library')
|
|
158
|
+
.action(async function (libpath) {
|
|
159
|
+
libpath = path.resolve(libpath);
|
|
160
|
+
fs.access(path.join(libpath, 'lib.json'), fs.constants.F_OK, async (err) => {
|
|
161
|
+
if (err) {
|
|
162
|
+
console.error("lib.json not found in current directory. Please make sure you are in a WebIDE library directory.");
|
|
163
|
+
process.exit(114514);
|
|
164
|
+
}
|
|
165
|
+
const libJsonData = fs.readFileSync(path.join(libpath, 'lib.json'), 'utf8');
|
|
166
|
+
const libJson = JSON.parse(libJsonData);
|
|
167
|
+
const { name, author, description, version, imports } = libJson;
|
|
168
|
+
if (!name || !author || !description || !version) {
|
|
169
|
+
console.error("Invalid lib.json. Please make sure all required fields are present.");
|
|
170
|
+
process.exit(114514);
|
|
171
|
+
}
|
|
172
|
+
console.log("Library Info:");
|
|
173
|
+
console.log(` Name: ${name}`);
|
|
174
|
+
console.log(` Version: ${version}`);
|
|
175
|
+
console.log(` Author: ${author}`);
|
|
176
|
+
console.log(` Description: ${description}`);
|
|
177
|
+
if (imports && imports.length > 0) {
|
|
178
|
+
console.log(` Imports:`);
|
|
179
|
+
for (let i = 0; i < imports.length; i++) {
|
|
180
|
+
console.log(` ${path.join(libpath, imports[i])}`);
|
|
181
|
+
}
|
|
182
|
+
}
|
|
183
|
+
const load = loading(`Publishing library "${name}" ...`);
|
|
184
|
+
let totalSize = 0;
|
|
185
|
+
await upload(libpath);
|
|
186
|
+
load();
|
|
187
|
+
console.log(`Total size: ${totalSize} bytes`);
|
|
188
|
+
console.log(`Library "${name}" published successfully.`);
|
|
189
|
+
|
|
190
|
+
async function upload(filepath) {
|
|
191
|
+
const files = fs.readdirSync(filepath);
|
|
192
|
+
for (const file of files) {
|
|
193
|
+
const filePath = path.join(libpath, file);
|
|
194
|
+
const stats = fs.statSync(filePath);
|
|
195
|
+
if (stats.isFile()) {
|
|
196
|
+
const fileData = fs.readFileSync(filePath);
|
|
197
|
+
const fileName = path.basename(filePath);
|
|
198
|
+
const fileType = path.extname(filePath).substring(1);
|
|
199
|
+
const fileSize = stats.size;
|
|
200
|
+
totalSize += fileSize;
|
|
201
|
+
const fp = filePath.replace(libpath, name).replace(/\\/g, '/');
|
|
202
|
+
const { data, error } = await bucket.update(fp, fileData, { contentType: fileType });
|
|
203
|
+
if (error) {
|
|
204
|
+
load();
|
|
205
|
+
console.error("\r\nAn error occurred:", error.stack);
|
|
206
|
+
process.exit(114514);
|
|
207
|
+
}
|
|
208
|
+
} else if (stats.isDirectory()) {
|
|
209
|
+
await upload(filePath);
|
|
210
|
+
} else {
|
|
211
|
+
load();
|
|
212
|
+
throw new Error(`Invalid file type: ${filePath}`);
|
|
213
|
+
}
|
|
214
|
+
}
|
|
215
|
+
}
|
|
216
|
+
})
|
|
217
|
+
});
|
|
218
|
+
|
|
155
219
|
const configCmd = program
|
|
156
220
|
.command('config')
|
|
157
221
|
.description('Configuration management');
|
|
@@ -251,7 +315,7 @@ program
|
|
|
251
315
|
|
|
252
316
|
program
|
|
253
317
|
.command('update')
|
|
254
|
-
.description('Update WebIDE')
|
|
318
|
+
.description('Update WebIDE CLI')
|
|
255
319
|
.action(async function () {
|
|
256
320
|
const load = loading("Checking for updates...");
|
|
257
321
|
const r = await fetch("https://registry.npmjs.org/webide-cli");
|
|
@@ -266,7 +330,7 @@ program
|
|
|
266
330
|
times.sort((a, b) => b - a);
|
|
267
331
|
const latestVersion = timeKeys.find(key => data.time[key] == new Date(times[0]).toISOString());
|
|
268
332
|
load();
|
|
269
|
-
if (
|
|
333
|
+
if (version == latestVersion) {
|
|
270
334
|
console.log("You are using the latest version.");
|
|
271
335
|
process.exit(0);
|
|
272
336
|
}
|