@robsun/create-keystone-app 0.1.2 → 0.1.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/README.md CHANGED
@@ -1,33 +1,12 @@
1
1
  # @robsun/create-keystone-app
2
2
 
3
- Minimal Keystone platform scaffold (web + server) with a demo module.
4
-
5
- ## Requirements
6
- - Node 18+
7
- - pnpm
8
- - Go 1.23+
9
-
10
- ## Usage
3
+ ## 用法
11
4
  ```bash
12
- npx @robsun/create-keystone-app my-app
13
- # or
14
- pnpm dlx @robsun/create-keystone-app my-app
5
+ npx @robsun/create-keystone-app <dir> [--demo]
6
+ pnpm dlx @robsun/create-keystone-app <dir> [--demo]
15
7
  ```
16
8
 
17
- ## Next steps
18
- ```bash
19
- cd my-app
20
- pnpm install
21
- pnpm server:dev
22
- pnpm dev
23
- ```
24
-
25
- ## Demo module
26
- - Menu: Demo Tasks
27
- - API: /api/v1/demo/tasks
28
-
29
- Default login:
30
-
31
- - Tenant code: default
32
- - Identifier: admin
33
- - Password: Admin123!
9
+ ## 参数
10
+ - `<dir>`:目标目录(必填)。新目录名或 `.`(当前目录)。
11
+ - `--demo`:生成 Demo 模块(默认不生成)。
12
+ - 目标目录必须为空;不为空会退出。
@@ -2,8 +2,38 @@
2
2
  const fs = require('fs');
3
3
  const path = require('path');
4
4
 
5
- const usage = 'Usage: create-keystone-app <dir>';
6
- const rawTarget = process.argv[2];
5
+ const usage = [
6
+ 'Usage: create-keystone-app <dir> [--demo]',
7
+ '',
8
+ 'Options:',
9
+ ' --demo Include demo module',
10
+ ].join('\n');
11
+ const args = process.argv.slice(2);
12
+ let rawTarget = null;
13
+ let includeDemo = false;
14
+
15
+ for (const arg of args) {
16
+ if (arg === '--demo') {
17
+ includeDemo = true;
18
+ continue;
19
+ }
20
+ if (arg === '--help' || arg === '-h') {
21
+ console.log(usage);
22
+ process.exit(0);
23
+ }
24
+ if (arg.startsWith('-')) {
25
+ console.error(`Unknown option: ${arg}`);
26
+ console.error(usage);
27
+ process.exit(1);
28
+ }
29
+ if (!rawTarget) {
30
+ rawTarget = arg;
31
+ continue;
32
+ }
33
+ console.error('Too many arguments.');
34
+ console.error(usage);
35
+ process.exit(1);
36
+ }
7
37
 
8
38
  if (!rawTarget) {
9
39
  console.error(usage);
@@ -31,6 +61,10 @@ copyDir(templateDir, targetDir, {
31
61
  '__RAW_NAME__': targetName,
32
62
  });
33
63
 
64
+ if (!includeDemo) {
65
+ stripDemo(targetDir);
66
+ }
67
+
34
68
  console.log(`Created ${targetName}`);
35
69
  console.log('Next steps:');
36
70
  console.log(` cd ${rawTarget}`);
@@ -68,4 +102,62 @@ function copyFile(src, dest, replacements) {
68
102
  content = content.split(key).join(value);
69
103
  }
70
104
  fs.writeFileSync(dest, content, 'utf8');
71
- }
105
+ }
106
+
107
+ function stripDemo(targetDir) {
108
+ removePath(path.join(targetDir, 'apps', 'web', 'src', 'modules', 'demo'));
109
+ removePath(path.join(targetDir, 'apps', 'server', 'internal', 'demo'));
110
+
111
+ updateFile(path.join(targetDir, 'apps', 'web', 'src', 'main.tsx'), (content) =>
112
+ content.replace(/^\s*import ['"]\.\/modules\/demo['"];?\r?\n/m, '')
113
+ );
114
+ updateFile(path.join(targetDir, 'apps', 'web', 'src', 'app.config.ts'), (content) =>
115
+ content.replace(/,\s*['"]demo['"]/, '')
116
+ );
117
+ updateFile(path.join(targetDir, 'README.md'), (content) => {
118
+ let next = content.replace(
119
+ 'Minimal Keystone platform shell (web + server) with a demo module.',
120
+ 'Minimal Keystone platform shell (web + server).'
121
+ );
122
+ next = next.replace(/\n+Demo module:[\s\S]*$/m, '\n');
123
+ return `${next.trimEnd()}\n`;
124
+ });
125
+
126
+ const serverMainPath = path.join(targetDir, 'apps', 'server', 'main.go');
127
+ const serverMain = `package main
128
+
129
+ import (
130
+ \t"log"
131
+
132
+ \t"github.com/robsuncn/keystone/server"
133
+ )
134
+
135
+ func main() {
136
+ \tapp, err := server.New()
137
+ \tif err != nil {
138
+ \t\tlog.Fatalf("failed to initialize server: %v", err)
139
+ \t}
140
+ \tif err := app.Run(); err != nil {
141
+ \t\tlog.Fatalf("server stopped: %v", err)
142
+ \t}
143
+ }
144
+ `;
145
+ fs.writeFileSync(serverMainPath, serverMain, 'utf8');
146
+ }
147
+
148
+ function removePath(target) {
149
+ if (fs.existsSync(target)) {
150
+ fs.rmSync(target, { recursive: true, force: true });
151
+ }
152
+ }
153
+
154
+ function updateFile(filePath, updater) {
155
+ if (!fs.existsSync(filePath)) {
156
+ return;
157
+ }
158
+ const content = fs.readFileSync(filePath, 'utf8');
159
+ const next = updater(content);
160
+ if (next !== content) {
161
+ fs.writeFileSync(filePath, next, 'utf8');
162
+ }
163
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@robsun/create-keystone-app",
3
- "version": "0.1.2",
3
+ "version": "0.1.3",
4
4
  "publishConfig": {
5
5
  "access": "public"
6
6
  },