@qelos/plugins-cli 0.0.5 → 0.0.7
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/controllers/create.mjs +63 -5
- package/package.json +1 -1
package/controllers/create.mjs
CHANGED
|
@@ -5,14 +5,70 @@ import DecompressZip from "decompress-zip";
|
|
|
5
5
|
import {join} from "path";
|
|
6
6
|
import rimraf from 'rimraf'
|
|
7
7
|
import ProgressBar from "../utils/progress-bar.mjs";
|
|
8
|
+
import * as readline from "readline";
|
|
9
|
+
import {execSync} from "child_process";
|
|
8
10
|
|
|
9
11
|
const https = follow.https;
|
|
10
12
|
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
13
|
+
function askQuestion(question) {
|
|
14
|
+
const rl = readline.createInterface({
|
|
15
|
+
input: process.stdin,
|
|
16
|
+
output: process.stdout
|
|
17
|
+
});
|
|
18
|
+
|
|
19
|
+
return new Promise((resolve) => {
|
|
20
|
+
rl.question(question, function (answer) {
|
|
21
|
+
rl.close();
|
|
22
|
+
resolve(answer);
|
|
23
|
+
});
|
|
15
24
|
})
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
async function getOrgReposNames(organization) {
|
|
28
|
+
const res = await fetch(`https://api.github.com/users/${organization}/repos`)
|
|
29
|
+
const repos = await res.json();
|
|
30
|
+
|
|
31
|
+
if (repos && repos instanceof Array) {
|
|
32
|
+
return repos.reduce((result, repo) => {
|
|
33
|
+
result[repo.name] = repo.description || repo.name;
|
|
34
|
+
return result;
|
|
35
|
+
}, {});
|
|
36
|
+
}
|
|
37
|
+
return [];
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
export default async function createController({name}) {
|
|
41
|
+
console.log(blue('Choose a boilerplate:'));
|
|
42
|
+
let organization = 'qelos-boilerplates';
|
|
43
|
+
let repository = 'vanilla';
|
|
44
|
+
|
|
45
|
+
try {
|
|
46
|
+
const project = await cliSelect({
|
|
47
|
+
values: {
|
|
48
|
+
vanilla: 'Vanilla',
|
|
49
|
+
vue: 'Vue',
|
|
50
|
+
crud: 'CRUD',
|
|
51
|
+
more: 'Show more',
|
|
52
|
+
custom: 'Custom from Github'
|
|
53
|
+
},
|
|
54
|
+
});
|
|
55
|
+
repository = project.id;
|
|
56
|
+
|
|
57
|
+
if (repository === 'more') {
|
|
58
|
+
const selected = await cliSelect({
|
|
59
|
+
values: await getOrgReposNames(organization)
|
|
60
|
+
});
|
|
61
|
+
repository = selected.id;
|
|
62
|
+
} else if (repository === 'custom') {
|
|
63
|
+
const [githubOrg, githubRepo] = (await askQuestion('Enter custom github project (org/repo)\n')).split('/');
|
|
64
|
+
organization = githubOrg || organization;
|
|
65
|
+
repository = githubRepo;
|
|
66
|
+
}
|
|
67
|
+
} catch {
|
|
68
|
+
console.log('See you soon :)');
|
|
69
|
+
process.exit(0);
|
|
70
|
+
}
|
|
71
|
+
|
|
16
72
|
const tempFolder = 'ql-plugin-' + Date.now();
|
|
17
73
|
const file = fs.createWriteStream(tempFolder + '.zip')
|
|
18
74
|
|
|
@@ -34,7 +90,7 @@ export default async function createController({name}) {
|
|
|
34
90
|
})
|
|
35
91
|
}
|
|
36
92
|
|
|
37
|
-
const request = https.get(`https://github.com
|
|
93
|
+
const request = https.get(`https://github.com/${organization}/${repository}/archive/refs/heads/main.zip`, (response) => {
|
|
38
94
|
response.pipe(file);
|
|
39
95
|
response.on('end', async () => {
|
|
40
96
|
try {
|
|
@@ -44,6 +100,8 @@ export default async function createController({name}) {
|
|
|
44
100
|
|
|
45
101
|
fs.renameSync(join(tempFolder, rootFolder), name);
|
|
46
102
|
|
|
103
|
+
execSync(`npm pkg set name=${name}`, {cwd: name});
|
|
104
|
+
|
|
47
105
|
console.log(`Created ${name} successfully.`)
|
|
48
106
|
} catch (err) {
|
|
49
107
|
console.log('Failed');
|