create-rspack 0.0.1-0 → 0.0.1-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.
Files changed (2) hide show
  1. package/index.js +20 -25
  2. package/package.json +3 -2
package/index.js CHANGED
@@ -3,34 +3,29 @@ const yargs = require("yargs/yargs");
3
3
  const { hideBin } = require("yargs/helpers");
4
4
  const fs = require("fs");
5
5
  const path = require("path");
6
+ const prompts = require("prompts");
6
7
  yargs(hideBin(process.argv))
7
- .command(
8
- "$0 [project]",
9
- "init rspack project",
10
- yargs => {
11
- yargs.positional("projectDir", {
12
- type: "string",
13
- describe: "project directory"
14
- });
15
- },
16
- async () => {
17
- const argv = minimist(process.argv.slice(2));
18
- const projectDir = argv.project || "rspack-project";
19
- if (!projectDir) {
20
- throw new Error("please specify a project directory");
8
+ .command("$0", "init rspack project", async argv => {
9
+ const defaultProjectName = "rspack-project";
10
+ let result = await prompts([
11
+ {
12
+ type: "text",
13
+ name: "projectDir",
14
+ initial: defaultProjectName,
15
+ message: "Project folder"
21
16
  }
22
- const root = path.resolve(process.cwd(), projectDir);
23
- if (fs.existsSync(root)) {
24
- throw new Error("project directory already exists");
25
- }
26
- fs.mkdirSync(root);
27
- // TODO support more template in the future
28
- const templateDir = "template-react";
29
- const srcFolder = path.resolve(__dirname, templateDir);
30
- const dstFolder = path.resolve(projectDir);
31
- copyFolder(srcFolder, dstFolder);
17
+ ]);
18
+ const { projectDir } = result;
19
+ const root = path.resolve(process.cwd(), projectDir);
20
+ if (fs.existsSync(root)) {
21
+ throw new Error("project directory already exists");
32
22
  }
33
- )
23
+ fs.mkdirSync(root);
24
+ // TODO support more template in the future
25
+ const templateDir = "template-react";
26
+ const srcFolder = path.resolve(__dirname, templateDir);
27
+ copyFolder(srcFolder, projectDir);
28
+ })
34
29
  .help()
35
30
  .parse();
36
31
  function copyFolder(src, dst) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "create-rspack",
3
- "version": "0.0.1-0",
3
+ "version": "0.0.1-1",
4
4
  "description": "",
5
5
  "main": "index.js",
6
6
  "bin": {
@@ -13,6 +13,7 @@
13
13
  "author": "",
14
14
  "license": "ISC",
15
15
  "dependencies": {
16
- "yargs": "17.6.2"
16
+ "yargs": "17.6.2",
17
+ "prompts": "2.4.2"
17
18
  }
18
19
  }