@qelos/plugins-cli 0.0.4 → 0.0.6

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.
@@ -5,14 +5,71 @@ 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
- export default async function createController({name}) {
12
- console.log(blue('Choose a boilerplate:'))
13
- const result = await cliSelect({
14
- values: {vanilla: 'Vanilla', react: 'React', vue: 'Vue', solid: 'Solid', custom: 'Custom from Github'},
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
+ react: 'React',
50
+ vue: 'Vue',
51
+ solid: 'Solid',
52
+ more: 'Show more',
53
+ custom: 'Custom from Github'
54
+ },
55
+ });
56
+ repository = project.id;
57
+
58
+ if (repository === 'more') {
59
+ const selected = await cliSelect({
60
+ values: await getOrgReposNames(organization)
61
+ });
62
+ repository = selected.id;
63
+ } else if (repository === 'custom') {
64
+ const [githubOrg, githubRepo] = (await askQuestion('Enter custom github project (org/repo)\n')).split('/');
65
+ organization = githubOrg || organization;
66
+ repository = githubRepo;
67
+ }
68
+ } catch {
69
+ console.log('See you soon :)');
70
+ process.exit(0);
71
+ }
72
+
16
73
  const tempFolder = 'ql-plugin-' + Date.now();
17
74
  const file = fs.createWriteStream(tempFolder + '.zip')
18
75
 
@@ -34,7 +91,7 @@ export default async function createController({name}) {
34
91
  })
35
92
  }
36
93
 
37
- const request = https.get(`https://github.com/qelos-boilerplates/${result.id}/archive/refs/heads/main.zip`, (response) => {
94
+ const request = https.get(`https://github.com/${organization}/${repository}/archive/refs/heads/main.zip`, (response) => {
38
95
  response.pipe(file);
39
96
  response.on('end', async () => {
40
97
  try {
@@ -44,6 +101,8 @@ export default async function createController({name}) {
44
101
 
45
102
  fs.renameSync(join(tempFolder, rootFolder), name);
46
103
 
104
+ execSync(`npm pkg set name=${name}`, {cwd: name});
105
+
47
106
  console.log(`Created ${name} successfully.`)
48
107
  } catch (err) {
49
108
  console.log('Failed');
package/package.json CHANGED
@@ -1,11 +1,11 @@
1
1
  {
2
2
  "name": "@qelos/plugins-cli",
3
- "version": "0.0.4",
3
+ "version": "0.0.6",
4
4
  "description": "CLI to manage QELOS plugins",
5
5
  "main": "cli.mjs",
6
6
  "bin": {
7
- "qplay": "cli.mjs",
8
- "plugins-cli": "cli.mjs"
7
+ "qelos": "cli.mjs",
8
+ "qplay": "cli.mjs"
9
9
  },
10
10
  "keywords": [
11
11
  "qelos",