Skip to content

Commit d2c5aec

Browse files
author
Balša Lazarević
committed
Add inquirer.js; Run create.js script by default
1 parent 303ba86 commit d2c5aec

File tree

3 files changed

+283
-63
lines changed

3 files changed

+283
-63
lines changed

create.js

100644100755
+27-10
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,35 @@
1+
#!/usr/bin/env node
12
import fs from "fs";
23
import fse from "fs-extra";
34
import path from "path";
45
import * as url from "url";
5-
import _yargs from "yargs";
6-
import { hideBin } from "yargs/helpers";
7-
const yargs = _yargs(hideBin(process.argv));
6+
7+
import { input, select } from "@inquirer/prompts";
8+
9+
// Ask user for params
10+
const params = {
11+
projectName: await input({ message: "Enter project name" }),
12+
template: await select({
13+
message: "Select an app template",
14+
choices: [
15+
{
16+
name: "basic",
17+
value: "basic",
18+
description: "Javascript template - Vite + Zustand",
19+
},
20+
{
21+
name: "typescript",
22+
value: "typescript",
23+
description: "Typescript template - Vite + Zustand",
24+
disabled: true,
25+
},
26+
],
27+
}),
28+
};
829

930
// Alternative for ES module
1031
const __dirname = url.fileURLToPath(new URL(".", import.meta.url));
1132

12-
const argv = await yargs
13-
.option("projectName", { type: "string", require: true })
14-
.option("template", { type: "string", require: true }).argv;
15-
1633
const DESTINATION_FOLDER = process.cwd(); // Folder from which the script is called - first create destination folder
1734

1835
// Helpers
@@ -86,7 +103,7 @@ const main = async ({ projectName, template }) => {
86103

87104
console.log("Provided params");
88105
console.log("---------------");
89-
console.log("Project name - ", argv.projectName);
90-
console.log("Template - ", argv.template);
106+
console.log("Project name - ", params.projectName);
107+
console.log("Template - ", params.template);
91108

92-
main(argv).catch((e) => console.log(e));
109+
main(params).catch((e) => console.log(e));

package.json

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
{
22
"name": "project-seeder",
33
"version": "1.0.0",
4-
"description": "",
4+
"description": "Create frontend apps in one line",
55
"type": "module",
6-
"main": "index.js",
6+
"main": "create.js",
77
"scripts": {
88
"test": "echo \"Error: no test specified\" && exit 1"
99
},
@@ -15,7 +15,7 @@
1515
"license": "ISC",
1616
"homepage": "https://bitbucket.org/autautdoo/kubernetes-configs#readme",
1717
"dependencies": {
18-
"fs-extra": "^10.1.0",
19-
"yargs": "^17.7.2"
18+
"@inquirer/prompts": "^3.3.0",
19+
"fs-extra": "^10.1.0"
2020
}
2121
}

0 commit comments

Comments
 (0)