create-donghanh 0.2.0 → 0.2.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.
@@ -1,21 +1,18 @@
1
1
  #!/usr/bin/env node
2
+
3
+ // src/index.ts
2
4
  import fs from "node:fs";
3
5
  import path from "node:path";
4
6
  import readline from "node:readline";
5
-
6
- const TEMPLATES = ["minimal", "kanban-gpt"] as const;
7
- type Template = (typeof TEMPLATES)[number];
8
-
9
- const DESCRIPTIONS: Record<Template, string> = {
7
+ var TEMPLATES = ["minimal", "kanban-gpt"];
8
+ var DESCRIPTIONS = {
10
9
  minimal: "Hello world with D1 SQLite — 2 operations",
11
- "kanban-gpt":
12
- "Kanban board with Better Auth + Drizzle + GPT Store OAuth — 6 operations",
10
+ "kanban-gpt": "Kanban board with Better Auth + Drizzle + GPT Store OAuth — 6 operations"
13
11
  };
14
-
15
- async function prompt(question: string): Promise<string> {
12
+ async function prompt(question) {
16
13
  const rl = readline.createInterface({
17
14
  input: process.stdin,
18
- output: process.stdout,
15
+ output: process.stdout
19
16
  });
20
17
  return new Promise((resolve) => {
21
18
  rl.question(question, (answer) => {
@@ -24,8 +21,7 @@ async function prompt(question: string): Promise<string> {
24
21
  });
25
22
  });
26
23
  }
27
-
28
- function copyDir(src: string, dest: string, replacements: [string, string][]) {
24
+ function copyDir(src, dest, replacements) {
29
25
  fs.mkdirSync(dest, { recursive: true });
30
26
  for (const entry of fs.readdirSync(src, { withFileTypes: true })) {
31
27
  const srcPath = path.join(src, entry.name);
@@ -41,29 +37,22 @@ function copyDir(src: string, dest: string, replacements: [string, string][]) {
41
37
  }
42
38
  }
43
39
  }
44
-
45
40
  async function main() {
46
41
  const args = process.argv.slice(2);
47
42
  let target = args[0];
48
- let template: Template | undefined;
49
-
50
- // Parse --template / -t flag
43
+ let template;
51
44
  const tIdx = args.indexOf("--template");
52
45
  const tShortIdx = args.indexOf("-t");
53
46
  const flagIdx = tIdx !== -1 ? tIdx : tShortIdx;
54
47
  if (flagIdx !== -1 && args[flagIdx + 1]) {
55
- template = args[flagIdx + 1] as Template;
56
- // Remove flag and value from args
48
+ template = args[flagIdx + 1];
57
49
  if (!target || target.startsWith("-")) {
58
50
  target = undefined;
59
51
  }
60
52
  }
61
-
62
53
  console.log();
63
- console.log(" \x1b[1m@donghanh\x1b[0m — Conversational UI Framework");
54
+ console.log(" \x1B[1m@donghanh\x1B[0m — Conversational UI Framework");
64
55
  console.log();
65
-
66
- // Prompt for target if not given
67
56
  if (!target || target.startsWith("-")) {
68
57
  target = await prompt(" Project name: ");
69
58
  if (!target) {
@@ -71,56 +60,37 @@ async function main() {
71
60
  process.exit(0);
72
61
  }
73
62
  }
74
-
75
- // Prompt for template if not given
76
63
  if (!template || !TEMPLATES.includes(template)) {
77
64
  console.log();
78
65
  console.log(" Templates:");
79
- for (let i = 0; i < TEMPLATES.length; i++) {
80
- console.log(
81
- ` \x1b[1m${i + 1}\x1b[0m) ${TEMPLATES[i]} — ${DESCRIPTIONS[TEMPLATES[i]]}`,
82
- );
66
+ for (let i = 0;i < TEMPLATES.length; i++) {
67
+ console.log(` \x1B[1m${i + 1}\x1B[0m) ${TEMPLATES[i]} — ${DESCRIPTIONS[TEMPLATES[i]]}`);
83
68
  }
84
69
  console.log();
85
70
  const choice = await prompt(" Select template (1-2): ");
86
71
  const idx = Number.parseInt(choice, 10) - 1;
87
72
  template = TEMPLATES[idx] ?? "minimal";
88
73
  }
89
-
90
74
  const destDir = path.resolve(target);
91
75
  if (fs.existsSync(destDir)) {
92
- console.log(
93
- ` \x1b[31mError:\x1b[0m Directory "${target}" already exists.`,
94
- );
76
+ console.log(` \x1B[31mError:\x1B[0m Directory "${target}" already exists.`);
95
77
  process.exit(1);
96
78
  }
97
-
98
- // Find templates directory
99
- const templatesDir = path.join(
100
- path.dirname(new URL(import.meta.url).pathname),
101
- "..",
102
- "templates",
103
- );
79
+ const templatesDir = path.join(path.dirname(new URL(import.meta.url).pathname), "..", "templates");
104
80
  const srcDir = path.join(templatesDir, template);
105
-
106
81
  if (!fs.existsSync(srcDir)) {
107
- console.log(` \x1b[31mError:\x1b[0m Template "${template}" not found.`);
82
+ console.log(` \x1B[31mError:\x1B[0m Template "${template}" not found.`);
108
83
  process.exit(1);
109
84
  }
110
-
111
- // Copy template with name replacement
112
85
  const appName = path.basename(target);
113
86
  copyDir(srcDir, destDir, [
114
87
  ["my-donghanh-app", appName],
115
88
  ["my-kanban-app", appName],
116
89
  ["my-donghanh-app-db", `${appName}-db`],
117
- ["my-kanban-db", `${appName}-db`],
90
+ ["my-kanban-db", `${appName}-db`]
118
91
  ]);
119
-
120
92
  console.log();
121
- console.log(
122
- ` \x1b[32m✓\x1b[0m Created \x1b[1m${appName}\x1b[0m from \x1b[1m${template}\x1b[0m template`,
123
- );
93
+ console.log(` \x1B[32m✓\x1B[0m Created \x1B[1m${appName}\x1B[0m from \x1B[1m${template}\x1B[0m template`);
124
94
  console.log();
125
95
  console.log(" Next steps:");
126
96
  console.log(` cd ${target}`);
@@ -129,5 +99,4 @@ async function main() {
129
99
  console.log(" bun run dev # start dev server");
130
100
  console.log();
131
101
  }
132
-
133
102
  main().catch(console.error);
package/package.json CHANGED
@@ -1,14 +1,17 @@
1
1
  {
2
2
  "name": "create-donghanh",
3
- "version": "0.2.0",
3
+ "version": "0.2.1",
4
4
  "description": "Scaffold a donghanh project — conversational UI with JSX",
5
5
  "license": "MIT",
6
6
  "type": "module",
7
7
  "bin": {
8
- "create-donghanh": "src/index.ts"
8
+ "create-donghanh": "dist/index.js"
9
+ },
10
+ "scripts": {
11
+ "build": "bun build src/index.ts --outdir dist --target node"
9
12
  },
10
13
  "files": [
11
- "src",
14
+ "dist",
12
15
  "templates"
13
16
  ],
14
17
  "repository": {