create-nocdn-app 0.0.1 → 0.0.2

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 +110 -26
  2. package/package.json +1 -1
package/index.js CHANGED
@@ -7,29 +7,102 @@ import path from "path";
7
7
  import { promisify } from "util";
8
8
 
9
9
  const execAsync = promisify(exec);
10
+ const VERSION = "0.0.2";
11
+
12
+ const args = process.argv.slice(2);
13
+ const flags = {
14
+ help: args.includes("-h") || args.includes("--help"),
15
+ version: args.includes("-v") || args.includes("--version"),
16
+ skipInstall: args.includes("--skip-install"),
17
+ skipGit: args.includes("--skip-git"),
18
+ open: args.includes("--open"),
19
+ useNpm: args.includes("--use-npm"),
20
+ usePnpm: args.includes("--use-pnpm"),
21
+ };
22
+
23
+ const cliProjectName = args.find((arg) => !arg.startsWith("-"));
24
+
25
+ function showHelp() {
26
+ console.log(`
27
+ create-nocdn-app - Scaffold a new Next.js project with:
28
+ Tailwind
29
+ TypeScript
30
+ Biome
31
+ Shiki
32
+ Lucide
33
+
34
+ Usage:
35
+ bunx create-nocdn-app [project-name] [options]
36
+
37
+ Options:
38
+ -h, --help Show this help message
39
+ -v, --version Show version number
40
+ --skip-install Skip installing dependencies
41
+ --skip-git Skip initializing git repository
42
+ --open Open project in default editor after creation
43
+ --use-npm Use npm instead of bun for installing dependencies
44
+ --use-pnpm Use pnpm instead of bun for installing dependencies
45
+
46
+ Examples:
47
+ bunx create-nocdn-app Interactive mode
48
+ bunx create-nocdn-app my-app Create project named "my-app"
49
+ bunx create-nocdn-app my-app --skip-git Create without git init
50
+ `);
51
+ process.exit(0);
52
+ }
53
+
54
+ function showVersion() {
55
+ console.log(`create-nocdn-app v${VERSION}`);
56
+ process.exit(0);
57
+ }
58
+
59
+ if (flags.help) showHelp();
60
+ if (flags.version) showVersion();
61
+
62
+ function validateProjectName(value) {
63
+ if (value.length === 0) return "Project name is required";
64
+ if (!/^[a-z0-9-]+$/.test(value)) {
65
+ return "Project name must be lowercase, alphanumeric, and can contain hyphens";
66
+ }
67
+ }
68
+
69
+ function getPackageManager() {
70
+ if (flags.useNpm) return { name: "npm", install: "npm install" };
71
+ if (flags.usePnpm) return { name: "pnpm", install: "pnpm install" };
72
+ return { name: "bun", install: "bun install" };
73
+ }
10
74
 
11
75
  async function main() {
12
76
  console.clear();
13
77
 
14
78
  clack.intro("create-nocdn-app");
15
79
 
16
- const projectName = await clack.text({
17
- message: "What is your project name?",
18
- placeholder: "my-app",
19
- validate(value) {
20
- if (value.length === 0) return "Project name is required";
21
- if (!/^[a-z0-9-]+$/.test(value)) {
22
- return "Project name must be lowercase, alphanumeric, and can contain hyphens";
23
- }
24
- },
25
- });
26
-
27
- if (clack.isCancel(projectName)) {
28
- clack.cancel("Operation cancelled");
29
- process.exit(0);
80
+ let projectName;
81
+
82
+ if (cliProjectName) {
83
+ const validationError = validateProjectName(cliProjectName);
84
+ if (validationError) {
85
+ clack.log.error(validationError);
86
+ clack.cancel("Invalid project name");
87
+ process.exit(1);
88
+ }
89
+ projectName = cliProjectName;
90
+ clack.log.info(`Creating project: ${projectName}`);
91
+ } else {
92
+ projectName = await clack.text({
93
+ message: "What is your project name?",
94
+ placeholder: "my-app",
95
+ validate: validateProjectName,
96
+ });
97
+
98
+ if (clack.isCancel(projectName)) {
99
+ clack.cancel("Operation cancelled");
100
+ process.exit(0);
101
+ }
30
102
  }
31
103
 
32
104
  const s = clack.spinner();
105
+ const pm = getPackageManager();
33
106
 
34
107
  try {
35
108
  const projectPath = path.join(process.cwd(), projectName);
@@ -58,23 +131,34 @@ async function main() {
58
131
  await fs.writeFile(packageJsonPath, JSON.stringify(packageJson, null, 2));
59
132
  s.stop("Project configured");
60
133
 
61
- s.start("Installing dependencies...");
62
- await execAsync("bun install", { cwd: projectPath });
63
- s.stop("Dependencies installed");
64
-
65
- s.start("Initializing git...");
66
- await execAsync("git init", { cwd: projectPath });
67
- await execAsync("git add .", { cwd: projectPath });
68
- await execAsync('git commit -m "init: initial file upload"', {
69
- cwd: projectPath,
70
- });
71
- s.stop("Git initialized");
134
+ if (!flags.skipInstall) {
135
+ s.start(`Installing dependencies with ${pm.name}...`);
136
+ await execAsync(pm.install, { cwd: projectPath });
137
+ s.stop("Dependencies installed");
138
+ }
139
+
140
+ if (!flags.skipGit) {
141
+ s.start("Initializing git...");
142
+ await execAsync("git init", { cwd: projectPath });
143
+ await execAsync("git add .", { cwd: projectPath });
144
+ await execAsync('git commit -m "init: initial file upload"', {
145
+ cwd: projectPath,
146
+ });
147
+ s.stop("Git initialized");
148
+ }
149
+
150
+ if (flags.open) {
151
+ s.start("Opening in editor...");
152
+ await execAsync(`code "${projectPath}"`);
153
+ s.stop("Opened in VS Code");
154
+ }
72
155
 
73
156
  clack.outro(`Project ${projectName} is ready`);
74
157
 
158
+ const runCmd = pm.name === "bun" ? "bun run dev" : `${pm.name} run dev`;
75
159
  console.log(`\nNext steps:
76
160
  cd ${projectName}
77
- bun run dev
161
+ ${runCmd}
78
162
  `);
79
163
  } catch (error) {
80
164
  s.stop("Error occurred");
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "create-nocdn-app",
3
- "version": "0.0.1",
3
+ "version": "0.0.2",
4
4
  "description": "Scaffold Next.js projects the nocdn way",
5
5
  "license": "MIT",
6
6
  "type": "module",