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