@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 CHANGED
@@ -1,33 +1,22 @@
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
9
+ ## 参数
10
+ - `<dir>`:目标目录(必填)。新目录名或 `.`(当前目录)。
11
+ - `--demo`:生成 Demo 模块(默认不生成)。
12
+ - 目标目录必须为空;不为空会退出。
13
+
14
+ ## 初始化后操作
18
15
  ```bash
19
- cd my-app
16
+ cd <dir>
20
17
  pnpm install
21
18
  pnpm server:dev
22
19
  pnpm dev
23
20
  ```
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!
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 = '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.4",
4
4
  "publishConfig": {
5
5
  "access": "public"
6
6
  },
@@ -1,4 +1,4 @@
1
- <!doctype html>
1
+ <!doctype html>
2
2
  <html lang="en">
3
3
  <head>
4
4
  <meta charset="UTF-8" />
@@ -1,4 +1,4 @@
1
- {
1
+ {
2
2
  "name": "web",
3
3
  "private": true,
4
4
  "version": "0.0.0",
@@ -1,4 +1,4 @@
1
- import type { KeystoneWebConfig } from '@robsun/keystone-web-core'
1
+ import type { KeystoneWebConfig } from '@robsun/keystone-web-core'
2
2
 
3
3
  export const appConfig: Partial<KeystoneWebConfig> = {
4
4
  brand: {
@@ -1,4 +1,4 @@
1
- import { StrictMode } from 'react'
1
+ import { StrictMode } from 'react'
2
2
  import { createRoot } from 'react-dom/client'
3
3
  import dayjs from 'dayjs'
4
4
  import { KeystoneApp, getKeystoneConfig, setKeystoneConfig } from '@robsun/keystone-web-core'
@@ -1 +1 @@
1
- /// <reference types="vite/client" />
1
+ /// <reference types="vite/client" />
@@ -1,4 +1,4 @@
1
- {
1
+ {
2
2
  "compilerOptions": {
3
3
  "tsBuildInfoFile": "./node_modules/.tmp/tsconfig.app.tsbuildinfo",
4
4
  "target": "ES2022",
@@ -1,4 +1,4 @@
1
- {
1
+ {
2
2
  "files": [],
3
3
  "references": [{ "path": "./tsconfig.app.json" }, { "path": "./tsconfig.node.json" }]
4
4
  }
@@ -1,4 +1,4 @@
1
- {
1
+ {
2
2
  "compilerOptions": {
3
3
  "tsBuildInfoFile": "./node_modules/.tmp/tsconfig.node.tsbuildinfo",
4
4
  "target": "ES2023",
@@ -1,4 +1,4 @@
1
- import { createKeystoneViteConfig } from '@robsun/keystone-web-core/vite'
1
+ import { createKeystoneViteConfig } from '@robsun/keystone-web-core/vite'
2
2
 
3
3
  export default createKeystoneViteConfig({
4
4
  server: {
@@ -1,4 +1,4 @@
1
- server:
1
+ server:
2
2
  port: "8080"
3
3
  mode: "debug"
4
4
  database:
@@ -1,4 +1,4 @@
1
- {
1
+ {
2
2
  "name": "__APP_NAME__",
3
3
  "private": true,
4
4
  "version": "0.1.0",
@@ -1,2 +1,2 @@
1
- packages:
1
+ packages:
2
2
  - "apps/*"