@ijuantm/simpl-addon 2.1.0 → 2.2.0
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/install.js +65 -44
- package/package.json +3 -3
package/install.js
CHANGED
|
@@ -3,6 +3,7 @@
|
|
|
3
3
|
const fs = require('fs');
|
|
4
4
|
const path = require('path');
|
|
5
5
|
const https = require('https');
|
|
6
|
+
const readline = require('readline');
|
|
6
7
|
const {promisify} = require('util');
|
|
7
8
|
const {exec} = require('child_process');
|
|
8
9
|
|
|
@@ -57,6 +58,16 @@ const downloadFile = (url, dest) => new Promise((resolve, reject) => {
|
|
|
57
58
|
});
|
|
58
59
|
});
|
|
59
60
|
|
|
61
|
+
const promptUser = (question, defaultValue = '') => new Promise(resolve => {
|
|
62
|
+
const rl = readline.createInterface({input: process.stdin, output: process.stdout});
|
|
63
|
+
const prompt = defaultValue ? `${question} ${COLORS.dim}(${defaultValue})${COLORS.reset}: ` : `${question}: `;
|
|
64
|
+
|
|
65
|
+
rl.question(prompt, answer => {
|
|
66
|
+
rl.close();
|
|
67
|
+
resolve(answer.trim() || defaultValue);
|
|
68
|
+
});
|
|
69
|
+
});
|
|
70
|
+
|
|
60
71
|
const getSimplVersion = () => {
|
|
61
72
|
const simplFile = path.join(process.cwd(), '.simpl');
|
|
62
73
|
|
|
@@ -76,20 +87,14 @@ const showHelp = () => {
|
|
|
76
87
|
log(` ╰${'─'.repeat(62)}╯`);
|
|
77
88
|
console.log();
|
|
78
89
|
log(` ${COLORS.bold}Usage:${COLORS.reset}`, 'blue');
|
|
79
|
-
log(` ${COLORS.dim}npx @ijuantm/simpl-addon
|
|
80
|
-
log(` ${COLORS.dim}npx @ijuantm/simpl-addon --list${COLORS.reset}`);
|
|
90
|
+
log(` ${COLORS.dim}npx @ijuantm/simpl-addon${COLORS.reset}`);
|
|
81
91
|
log(` ${COLORS.dim}npx @ijuantm/simpl-addon --help${COLORS.reset}`);
|
|
82
92
|
console.log();
|
|
83
|
-
log(` ${COLORS.bold}Arguments:${COLORS.reset}`, 'blue');
|
|
84
|
-
log(` ${COLORS.dim}addon-name${COLORS.reset} Name of the add-on to install`);
|
|
85
|
-
console.log();
|
|
86
93
|
log(` ${COLORS.bold}Commands:${COLORS.reset}`, 'blue');
|
|
87
|
-
log(` ${COLORS.dim}--list, -l${COLORS.reset} List all available add-ons`);
|
|
88
94
|
log(` ${COLORS.dim}--help, -h${COLORS.reset} Show this help message`);
|
|
89
95
|
console.log();
|
|
90
96
|
log(` ${COLORS.bold}Examples:${COLORS.reset}`, 'blue');
|
|
91
|
-
log(` ${COLORS.dim}npx @ijuantm/simpl-addon
|
|
92
|
-
log(` ${COLORS.dim}npx @ijuantm/simpl-addon --list${COLORS.reset}`);
|
|
97
|
+
log(` ${COLORS.dim}npx @ijuantm/simpl-addon${COLORS.reset}`);
|
|
93
98
|
console.log();
|
|
94
99
|
log(` ${COLORS.bold}Note:${COLORS.reset}`, 'blue');
|
|
95
100
|
log(` Run this command from the root of your Simpl project.`);
|
|
@@ -109,39 +114,14 @@ const checkServerAvailability = () => new Promise(resolve => {
|
|
|
109
114
|
});
|
|
110
115
|
});
|
|
111
116
|
|
|
112
|
-
const
|
|
113
|
-
|
|
114
|
-
log(` ╭${'─'.repeat(62)}╮`);
|
|
115
|
-
log(` │ ${COLORS.bold}Available Add-ons${COLORS.reset} ${COLORS.dim}(${version})${COLORS.reset}${' '.repeat(40 - version.length)}│`);
|
|
116
|
-
log(` ╰${'─'.repeat(62)}╯`);
|
|
117
|
-
console.log();
|
|
118
|
-
log(' 📦 Fetching available add-ons...', 'bold');
|
|
119
|
-
|
|
120
|
-
try {
|
|
121
|
-
const localListPath = path.join(LOCAL_RELEASES_DIR, version, 'add-ons', 'list.json');
|
|
122
|
-
let addons;
|
|
123
|
-
|
|
124
|
-
if (fs.existsSync(localListPath)) {
|
|
125
|
-
console.log();
|
|
126
|
-
log(` 💻 Using local add-ons list`, 'bold');
|
|
127
|
-
addons = JSON.parse(fs.readFileSync(localListPath, 'utf8'))['add-ons'];
|
|
128
|
-
} else {
|
|
129
|
-
if (!await checkServerAvailability()) throw new Error('CDN server is currently unreachable');
|
|
130
|
-
addons = JSON.parse(await fetchUrl(`${CDN_BASE}/${version}/add-ons/list.json`))['add-ons'];
|
|
131
|
-
}
|
|
117
|
+
const getAvailableAddons = async (version) => {
|
|
118
|
+
const localListPath = path.join(LOCAL_RELEASES_DIR, version, 'add-ons', 'list.json');
|
|
132
119
|
|
|
133
|
-
|
|
120
|
+
if (fs.existsSync(localListPath)) return JSON.parse(fs.readFileSync(localListPath, 'utf8'))['add-ons'];
|
|
134
121
|
|
|
135
|
-
|
|
136
|
-
else addons.forEach(name => log(` ${COLORS.cyan}•${COLORS.reset} ${name}`));
|
|
137
|
-
} catch (error) {
|
|
138
|
-
console.log();
|
|
139
|
-
log(` ${COLORS.red}✗${COLORS.reset} Failed to fetch add-ons`, 'red');
|
|
140
|
-
console.log();
|
|
141
|
-
process.exit(1);
|
|
142
|
-
}
|
|
122
|
+
if (!await checkServerAvailability()) throw new Error('CDN server is currently unreachable');
|
|
143
123
|
|
|
144
|
-
|
|
124
|
+
return JSON.parse(await fetchUrl(`${CDN_BASE}/${version}/add-ons/list.json`))['add-ons'];
|
|
145
125
|
};
|
|
146
126
|
|
|
147
127
|
const extractMarkers = (content) => {
|
|
@@ -375,7 +355,7 @@ const main = async () => {
|
|
|
375
355
|
const args = process.argv.slice(2);
|
|
376
356
|
const firstArg = args[0];
|
|
377
357
|
|
|
378
|
-
if (
|
|
358
|
+
if (firstArg === '--help' || firstArg === '-h') {
|
|
379
359
|
showHelp();
|
|
380
360
|
process.exit(0);
|
|
381
361
|
}
|
|
@@ -391,16 +371,57 @@ const main = async () => {
|
|
|
391
371
|
process.exit(1);
|
|
392
372
|
}
|
|
393
373
|
|
|
394
|
-
|
|
395
|
-
|
|
374
|
+
console.log();
|
|
375
|
+
log(` ╭${'─'.repeat(62)}╮`);
|
|
376
|
+
log(` │ ${COLORS.bold}Simpl Add-on Installer${COLORS.reset} ${COLORS.dim}(${version})${COLORS.reset}${' '.repeat(37 - version.length)}│`);
|
|
377
|
+
log(` ╰${'─'.repeat(62)}╯`);
|
|
378
|
+
console.log();
|
|
379
|
+
log(' 📦 Fetching available add-ons...', 'bold');
|
|
380
|
+
|
|
381
|
+
let addons;
|
|
382
|
+
|
|
383
|
+
try {
|
|
384
|
+
addons = await getAvailableAddons(version);
|
|
385
|
+
} catch (error) {
|
|
386
|
+
console.log();
|
|
387
|
+
log(` ${COLORS.red}✗${COLORS.reset} Failed to fetch add-ons`, 'red');
|
|
388
|
+
if (error.message === 'CDN server is currently unreachable') log(` ${COLORS.dim}The CDN server is currently unavailable. Please try again later.${COLORS.reset}`);
|
|
389
|
+
console.log();
|
|
390
|
+
process.exit(1);
|
|
391
|
+
}
|
|
392
|
+
|
|
393
|
+
console.log();
|
|
394
|
+
|
|
395
|
+
if (addons.length === 0) {
|
|
396
|
+
log(` ${COLORS.yellow}⚠${COLORS.reset} No add-ons available for this version`);
|
|
397
|
+
console.log();
|
|
396
398
|
process.exit(0);
|
|
397
399
|
}
|
|
398
400
|
|
|
399
|
-
|
|
401
|
+
log(` ${COLORS.bold}Available add-ons:${COLORS.reset}`, 'blue');
|
|
402
|
+
addons.forEach(name => log(` ${COLORS.cyan}•${COLORS.reset} ${name}`));
|
|
403
|
+
console.log();
|
|
404
|
+
|
|
405
|
+
let addonName;
|
|
406
|
+
|
|
407
|
+
while (true) {
|
|
408
|
+
addonName = await promptUser(' Add-on to install');
|
|
409
|
+
if (!addonName) {
|
|
410
|
+
log(` ${COLORS.red}✗${COLORS.reset} Add-on name cannot be empty`, 'red');
|
|
411
|
+
console.log();
|
|
412
|
+
continue;
|
|
413
|
+
}
|
|
414
|
+
if (!addons.includes(addonName)) {
|
|
415
|
+
log(` ${COLORS.red}✗${COLORS.reset} Add-on "${addonName}" not found`, 'red');
|
|
416
|
+
console.log();
|
|
417
|
+
continue;
|
|
418
|
+
}
|
|
419
|
+
break;
|
|
420
|
+
}
|
|
400
421
|
|
|
401
422
|
console.log();
|
|
402
423
|
log(` ╭${'─'.repeat(62)}╮`);
|
|
403
|
-
log(` │ ${COLORS.bold}Installing
|
|
424
|
+
log(` │ ${COLORS.bold}Installing: ${COLORS.cyan}${addonName}${COLORS.reset} ${COLORS.dim}(${version})${COLORS.reset}${' '.repeat(46 - addonName.length - version.length)}│`);
|
|
404
425
|
log(` ╰${'─'.repeat(62)}╯`);
|
|
405
426
|
console.log();
|
|
406
427
|
log(' 📦 Downloading add-on...', 'bold');
|
|
@@ -413,7 +434,7 @@ const main = async () => {
|
|
|
413
434
|
console.log();
|
|
414
435
|
log(` ${COLORS.red}✗${COLORS.reset} Installation failed`, 'red');
|
|
415
436
|
if (error.message === 'CDN server is currently unreachable') log(` ${COLORS.dim}The CDN server is currently unavailable. Please try again later.${COLORS.reset}`);
|
|
416
|
-
else log(` ${COLORS.dim}
|
|
437
|
+
else log(` ${COLORS.dim}Please verify the add-on exists and try again${COLORS.reset}`);
|
|
417
438
|
console.log();
|
|
418
439
|
process.exit(1);
|
|
419
440
|
}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ijuantm/simpl-addon",
|
|
3
3
|
"description": "CLI tool to install Simpl framework add-ons.",
|
|
4
|
-
"version": "2.
|
|
4
|
+
"version": "2.2.0",
|
|
5
5
|
"scripts": {
|
|
6
6
|
"link": "npm link",
|
|
7
7
|
"unlink": "npm unlink -g @ijuantm/simpl-addon"
|
|
@@ -15,7 +15,7 @@
|
|
|
15
15
|
},
|
|
16
16
|
"repository": {
|
|
17
17
|
"type": "git",
|
|
18
|
-
"url": "https://github.com/IJuanTM/simpl"
|
|
18
|
+
"url": "https://github.com/IJuanTM/simpl/"
|
|
19
19
|
},
|
|
20
20
|
"keywords": [
|
|
21
21
|
"simpl",
|
|
@@ -26,5 +26,5 @@
|
|
|
26
26
|
],
|
|
27
27
|
"author": "Iwan van der Wal",
|
|
28
28
|
"license": "GPL-3.0-only",
|
|
29
|
-
"homepage": "https://simpl.iwanvanderwal.nl"
|
|
29
|
+
"homepage": "https://simpl.iwanvanderwal.nl/"
|
|
30
30
|
}
|