create-gloom 0.2.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 (3) hide show
  1. package/README.md +17 -0
  2. package/package.json +31 -0
  3. package/src/index.mjs +104 -0
package/README.md ADDED
@@ -0,0 +1,17 @@
1
+ # create-gloom
2
+
3
+ CLI for scaffolding Gloom projects.
4
+
5
+ ## Usage
6
+
7
+ ```bash
8
+ pnpm create gloom
9
+ pnpm create gloom next
10
+ pnpm create gloom next my-app
11
+ ```
12
+
13
+ ## Templates
14
+
15
+ - `next`
16
+
17
+ The `next` template is currently available. More templates are coming soon.
package/package.json ADDED
@@ -0,0 +1,31 @@
1
+ {
2
+ "name": "create-gloom",
3
+ "version": "0.2.0",
4
+ "description": "Scaffold Gloom templates",
5
+ "author": "Kevin Sutandi",
6
+ "homepage": "https://github.com/gloom-studio/create-gloom#readme",
7
+ "bugs": {
8
+ "url": "https://github.com/gloom-studio/create-gloom/issues"
9
+ },
10
+ "repository": {
11
+ "type": "git",
12
+ "url": "git+https://github.com/gloom-studio/create-gloom.git"
13
+ },
14
+ "keywords": [
15
+ "create",
16
+ "gloom",
17
+ "nextjs",
18
+ "template"
19
+ ],
20
+ "license": "MIT",
21
+ "bin": {
22
+ "create-gloom": "./src/index.mjs"
23
+ },
24
+ "files": [
25
+ "src"
26
+ ],
27
+ "type": "module",
28
+ "dependencies": {
29
+ "degit": "^2.8.4"
30
+ }
31
+ }
package/src/index.mjs ADDED
@@ -0,0 +1,104 @@
1
+ #!/usr/bin/env node
2
+
3
+ import { stdin as input, stdout as output } from 'node:process';
4
+ import readline from 'node:readline/promises';
5
+
6
+ import degit from 'degit';
7
+
8
+ const TEMPLATE_SOURCES = {
9
+ next: 'gloom-studio/nextjs-starter-gloom',
10
+ };
11
+
12
+ function printHelp() {
13
+ output.write(`
14
+ Usage:
15
+ pnpm create gloom [template] [project-name]
16
+
17
+ Examples:
18
+ pnpm create gloom
19
+ pnpm create gloom next
20
+ pnpm create gloom next my-app
21
+ `);
22
+ }
23
+
24
+ async function promptTemplate(rl) {
25
+ const answer = (await rl.question('Template (next): ')).trim().toLowerCase();
26
+ return answer || 'next';
27
+ }
28
+
29
+ async function promptProjectName(rl) {
30
+ const answer = (await rl.question('Project name: ')).trim();
31
+ return answer;
32
+ }
33
+
34
+ function resolveTemplate(rawTemplate) {
35
+ const template = rawTemplate?.toLowerCase();
36
+ if (!template) return null;
37
+ if (template in TEMPLATE_SOURCES) return template;
38
+ return null;
39
+ }
40
+
41
+ async function main() {
42
+ const [, , arg1, arg2] = process.argv;
43
+
44
+ if (arg1 === '-h' || arg1 === '--help') {
45
+ printHelp();
46
+ return;
47
+ }
48
+
49
+ const rl = readline.createInterface({ input, output });
50
+
51
+ try {
52
+ let template = resolveTemplate(arg1);
53
+ let projectName = arg2;
54
+
55
+ if (!template) {
56
+ template = await promptTemplate(rl);
57
+ if (!resolveTemplate(template)) {
58
+ throw new Error(
59
+ `Unknown template "${template}". Available: ${Object.keys(TEMPLATE_SOURCES).join(', ')}`,
60
+ );
61
+ }
62
+ if (!projectName && arg1 && !arg1.startsWith('-')) {
63
+ projectName = arg1;
64
+ }
65
+ }
66
+
67
+ if (!projectName) {
68
+ projectName = await promptProjectName(rl);
69
+ }
70
+
71
+ if (!projectName) {
72
+ throw new Error('Project name is required.');
73
+ }
74
+
75
+ const source = TEMPLATE_SOURCES[template];
76
+
77
+ output.write(`\nScaffolding "${template}" into "${projectName}"...\n`);
78
+ const emitter = degit(source, {
79
+ cache: false,
80
+ force: false,
81
+ verbose: true,
82
+ });
83
+
84
+ await emitter.clone(projectName);
85
+
86
+ output.write(`
87
+ Done.
88
+
89
+ Next steps:
90
+ cd ${projectName}
91
+ cp .env.example .env
92
+ pnpm install
93
+ pnpm exec prisma generate
94
+ pnpm dev
95
+ `);
96
+ } finally {
97
+ rl.close();
98
+ }
99
+ }
100
+
101
+ void main().catch((error) => {
102
+ console.error(`\ncreate-gloom failed: ${error.message}`);
103
+ process.exit(1);
104
+ });