@robsun/create-keystone-app 0.1.2 → 0.1.4
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 +12 -23
- package/bin/create-keystone-app.js +95 -3
- package/package.json +1 -1
- package/template/apps/web/index.html +1 -1
- package/template/apps/web/package.json +1 -1
- package/template/apps/web/src/app.config.ts +1 -1
- package/template/apps/web/src/main.tsx +1 -1
- package/template/apps/web/src/vite-env.d.ts +1 -1
- package/template/apps/web/tsconfig.app.json +1 -1
- package/template/apps/web/tsconfig.json +1 -1
- package/template/apps/web/tsconfig.node.json +1 -1
- package/template/apps/web/vite.config.ts +1 -1
- package/template/config.yaml +1 -1
- package/template/package.json +1 -1
- package/template/pnpm-workspace.yaml +1 -1
package/README.md
CHANGED
|
@@ -1,33 +1,22 @@
|
|
|
1
1
|
# @robsun/create-keystone-app
|
|
2
2
|
|
|
3
|
-
|
|
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
|
|
13
|
-
|
|
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
|
-
##
|
|
9
|
+
## 参数
|
|
10
|
+
- `<dir>`:目标目录(必填)。新目录名或 `.`(当前目录)。
|
|
11
|
+
- `--demo`:生成 Demo 模块(默认不生成)。
|
|
12
|
+
- 目标目录必须为空;不为空会退出。
|
|
13
|
+
|
|
14
|
+
## 初始化后操作
|
|
18
15
|
```bash
|
|
19
|
-
cd
|
|
16
|
+
cd <dir>
|
|
20
17
|
pnpm install
|
|
21
18
|
pnpm server:dev
|
|
22
19
|
pnpm dev
|
|
23
20
|
```
|
|
24
|
-
|
|
25
|
-
|
|
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!
|
|
21
|
+
- Web 默认端口:`3000`,后端默认端口:`8080`。
|
|
22
|
+
- `--demo` 模式下:Demo API 为 `/api/v1/demo/tasks`。
|
|
@@ -2,8 +2,38 @@
|
|
|
2
2
|
const fs = require('fs');
|
|
3
3
|
const path = require('path');
|
|
4
4
|
|
|
5
|
-
const usage =
|
|
6
|
-
|
|
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 +1 @@
|
|
|
1
|
-
|
|
1
|
+
/// <reference types="vite/client" />
|
package/template/config.yaml
CHANGED
package/template/package.json
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
|
|
1
|
+
packages:
|
|
2
2
|
- "apps/*"
|