@dev-angsu/cli 1.0.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.
Files changed (2) hide show
  1. package/bin/index.js +77 -0
  2. package/package.json +27 -0
package/bin/index.js ADDED
@@ -0,0 +1,77 @@
1
+ #!/usr/bin/env node
2
+ import { createRequire } from "module";
3
+ const require = createRequire(import.meta.url);
4
+
5
+ const packageJson = require("../package.json");
6
+
7
+ import { Command } from "commander";
8
+ import inquirer from "inquirer";
9
+ import chalk from "chalk";
10
+ import ora from "ora";
11
+ import fs from "fs";
12
+
13
+ const program = new Command();
14
+
15
+ // 1. Metadata
16
+ program
17
+ .name("cli")
18
+ .description("A CLI to demonstrate industry standards")
19
+ .version("1.0.0");
20
+
21
+ // 2. Define a Command
22
+ program
23
+ .command("create")
24
+ .alias("c")
25
+ .description("Create a new project file")
26
+ .argument("[name]", "Name of the project") // Optional argument
27
+ .option("-t, --type <type>", "Type of project (node/python)")
28
+ .action(async (name, options) => {
29
+ // 3. Interactivity (If args are missing, ask for them)
30
+ let answers = {};
31
+ if (!name || !options.type) {
32
+ answers = await inquirer.prompt([
33
+ {
34
+ type: "input",
35
+ name: "projectName",
36
+ message: "What is the project name?",
37
+ default: name || "my-project",
38
+ when: !name, // Only ask if name wasn't passed as arg
39
+ },
40
+ {
41
+ type: "list",
42
+ name: "projectType",
43
+ message: "Pick a template:",
44
+ choices: ["Node.js", "Python", "Go"],
45
+ when: !options.type,
46
+ },
47
+ ]);
48
+ }
49
+
50
+ const finalName = name || answers.projectName;
51
+ const finalType = options.type || answers.projectType;
52
+
53
+ // 4. Feedback (Spinners)
54
+ const spinner = ora(
55
+ `Scaffolding ${finalType} project: ${finalName}...`
56
+ ).start();
57
+
58
+ try {
59
+ // Simulate work (e.g., copying files, git clone)
60
+ await new Promise((resolve) => setTimeout(resolve, 2000));
61
+
62
+ // Write a dummy file
63
+ fs.writeFileSync(`${finalName}.txt`, `Project Type: ${finalType}`);
64
+
65
+ // 5. Success Message (Colored)
66
+ spinner.succeed(
67
+ chalk.green(`Successfully created project: ${chalk.bold(finalName)}`)
68
+ );
69
+ } catch (error) {
70
+ spinner.fail(chalk.red("Failed to create project."));
71
+ console.error(error);
72
+ process.exit(1); // Standard error exit code
73
+ }
74
+ });
75
+
76
+ // 6. Parse Arguments
77
+ program.parse(process.argv);
package/package.json ADDED
@@ -0,0 +1,27 @@
1
+ {
2
+ "name": "@dev-angsu/cli",
3
+ "version": "1.0.0",
4
+ "description": "",
5
+ "main": "index.js",
6
+ "scripts": {
7
+ "test": "echo \"Error: no test specified\" && exit 1"
8
+ },
9
+ "bin": {
10
+ "cli": "./bin/index.js"
11
+ },
12
+ "keywords": [],
13
+ "author": "",
14
+ "license": "ISC",
15
+ "type": "module",
16
+ "dependencies": {
17
+ "chalk": "^5.6.2",
18
+ "commander": "^14.0.2",
19
+ "inquirer": "^13.1.0",
20
+ "ora": "^9.0.0"
21
+ },
22
+ "files": [
23
+ "bin",
24
+ "src",
25
+ "README.md"
26
+ ]
27
+ }