Skip to content

Commit f0e4587

Browse files
AxiosLeocursoragent
andcommitted
feat(cli): add simple app templates to init
init now asks for simple-ts, simple-js, or monorepo. The simple templates are a single HTTP service with sample routes and no database. Pass -t to skip the prompt. Co-authored-by: Cursor <cursoragent@cursor.com>
1 parent edadf37 commit f0e4587

38 files changed

Lines changed: 1136 additions & 42 deletions

‎.agents/rules/cli-commands.mdc‎

Lines changed: 22 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -28,30 +28,36 @@ package-manager detection). Keep command files thin and put logic there.
2828

2929
## Project Initialization
3030

31-
The init command creates new projects using templates from `assets/monorepo/`:
31+
The init command asks which template to generate (or takes `-t`):
3232

3333
```bash
34-
npx @axiosleo/koapp init <app-name> -d <optional-dir>
34+
npx @axiosleo/koapp init <app-name> [-d <optional-dir>] [-t simple-ts|simple-js|monorepo]
3535
```
3636

37-
This generates a pnpm monorepo:
38-
39-
- `apps/services` - TypeScript koapp API service (admin Session auth,
40-
`/openapi` Bearer Api-Key surface, SQLite metadata store)
41-
- `packages/commands` + `bin/<app-name>.js` - project CLI
42-
- `.agents/` - rules plus the koapp skills synced from `assets/skills/`
37+
| Template | Source | Result |
38+
| --- | --- | --- |
39+
| `simple-ts` (default) | `assets/simple/ts/` | One TypeScript HTTP service and sample routes. No database. |
40+
| `simple-js` | `assets/simple/js/` | The same service in CommonJS. No compile step. |
41+
| `monorepo` | `assets/monorepo/` | pnpm workspace: `apps/services` (admin Session auth, `/openapi` Bearer Api-Key, SQLite), `packages/commands`, `bin/<app-name>.js` |
4342

43+
Every template also receives `.agents/skills/` copied from `assets/skills/`.
4444
After writing files, init probes for pnpm (offering to install the pinned
4545
version) and then offers to run `pnpm install` and `pnpm dev`.
4646

47+
Template selection and file rendering live in [src/cli/scaffold.js](mdc:src/cli/scaffold.js)
48+
so they can be tested without a prompt.
49+
4750
## Template System
4851

4952
Templates use the `.tmpl` extension and are processed during project generation:
5053

51-
- `assets/monorepo/**/*.tmpl` - rendered with `_render_with_file`, which replaces
52-
`${name}` with the app name; the `.tmpl` suffix is stripped on output
54+
- `assets/simple/{ts,js}/**/*.tmpl` and `assets/monorepo/**/*.tmpl` - rendered
55+
with `_render_with_file`, which replaces `${name}` with the app name; the
56+
`.tmpl` suffix is stripped on output
5357
- `assets/monorepo/bin/monoapp.js.tmpl` - renamed to `bin/<app-name>.js`
58+
(monorepo template only)
5459
- `assets/skills/` - copied verbatim into `<app>/.agents/skills/`
60+
(`_sync` reback must stay off, or the copy writes back into this package)
5561

5662
## Command Development
5763

@@ -66,10 +72,14 @@ When creating new CLI commands:
6672
## Usage Examples
6773

6874
```bash
69-
# Initialize new project
75+
# Initialize new project (prompts for a template; default is simple-ts)
7076
npx @axiosleo/koapp init my-app
7177

72-
# Initialize in specific directory
78+
# Skip the prompt
79+
npx @axiosleo/koapp init my-app -t simple-js
80+
npx @axiosleo/koapp init my-app -t monorepo
81+
82+
# Initialize in a specific directory
7383
npx @axiosleo/koapp init my-app -d ./projects
7484

7585
# Show help

‎README.md‎

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,16 @@ npm install @axiosleo/koapp
1717

1818
## Initialization
1919

20+
`koapp init` asks which project to generate. Pressing enter selects the simple TypeScript service. Pass `-t` to skip the prompt.
21+
22+
| Template | Flag | What you get |
23+
| --- | --- | --- |
24+
| Simple TypeScript app (default) | `-t simple-ts` | One koapp HTTP service and sample routes. No database. |
25+
| Simple JavaScript app | `-t simple-js` | The same service in CommonJS, with no compile step. |
26+
| Full monorepo | `-t monorepo` | pnpm workspace: admin Session API, Api-Keys, and SQLite. |
27+
2028
```bash
21-
npx @axiosleo/koapp init <app-name> -d <optional-dir>
29+
npx @axiosleo/koapp init <app-name> [-d <dir>] [-t simple-ts|simple-js|monorepo]
2230

2331
# Show help information
2432
# npx @axiosleo/koapp init -h

‎assets/simple/js/.env.example.tmpl‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# HTTP listen port
2+
# API_PORT=8801
3+
4+
# prod enables production mode (debug off). Anything else is local/dev.
5+
# DEPLOY_ENV=local

‎assets/simple/js/.gitignore.tmpl‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
node_modules/
2+
dist/
3+
.env
4+
*.log
5+
.DS_Store
6+
coverage/

‎assets/simple/js/.npmrc.tmpl‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
registry=https://registry.npmmirror.com
2+
shamefully-hoist=false
3+
strict-peer-dependencies=false

‎assets/simple/js/.nvmrc.tmpl‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
24.8.0

‎assets/simple/js/AGENTS.md.tmpl‎

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
# ${name}
2+
3+
简易 koapp HTTP 服务(JavaScript / CommonJS,pnpm,Node >= 20)。无数据库,无需编译。
4+
5+
- 入口:`src/bootstrap.js`,应用类 `src/app.js`,配置 `src/config.js`
6+
- 路由:`src/routes/index.js` 挂载 `src/routes/example.router.js`
7+
- 默认端口 `8801`(`API_PORT`)
8+
- `pnpm dev` 或 `pnpm start`
9+
- koapp API 见 `.agents/skills/koapp*`

‎assets/simple/js/README.md.tmpl‎

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
# ${name}
2+
3+
基于 [@axiosleo/koapp](https://github.com/AxiosLeo/node-koapp) 的简易 HTTP 接口服务(JavaScript / CommonJS)。只包含示例路由,不包含数据库,无需编译。
4+
5+
## 环境要求
6+
7+
- Node.js `>= 20`
8+
- pnpm `>= 10`
9+
10+
## 快速开始
11+
12+
```bash
13+
pnpm install
14+
cp .env.example .env # 可选
15+
pnpm dev # http://127.0.0.1:8801
16+
```
17+
18+
直接启动:
19+
20+
```bash
21+
pnpm start
22+
```
23+
24+
## 目录
25+
26+
```
27+
src/
28+
bootstrap.js # 进程入口
29+
app.js # KoaApplication
30+
config.js # 读取 .env
31+
routes/index.js # 根路由:请求日志、404 兜底
32+
routes/example.router.js
33+
```
34+
35+
## 示例路由
36+
37+
| 方法 | 路径 | 说明 |
38+
| --- | --- | --- |
39+
| `GET` | `/` | `success('hello, world!')` |
40+
| `GET` | `/health` | `{ status: 'ok' }` |
41+
| `GET`/`POST` | `/multi` | 多方法,回显 method |
42+
| `GET` | `/a/{:a}/b/{:b}` | 路径参数 |
43+
| `ANY` | `/any` | 任意方法,回显 params / query / body |
44+
| `ANY` | `/error` | 抛错,框架转为 500 |
45+
| `ANY` | `/failed` | `failed()`,HTTP 403 |
46+
| `ANY` | `/result` | `result()` 自定义 header |
47+
| `GET` | `/result/obj` | `result()` 返回对象 |
48+
| `ANY` | `/success` | `success()` |
49+
| `ANY` | `/html` | `text/html` |
50+
| `ANY` | `/model` | `Model` 序列化 |
51+
| `ANY` | `/model/error` | `Model` 校验失败 |
52+
| `ANY` | `/validate/{:param1}/{:param2}` | params / query / body 校验 |
53+
| `ANY` | `/sse` | Server-Sent Events |
54+
55+
未匹配的路径返回 404。
56+
57+
## 环境变量
58+
59+
| 变量 | 默认值 | 说明 |
60+
| --- | --- | --- |
61+
| `API_PORT` | `8801` | 监听端口 |
62+
| `DEPLOY_ENV` | `local` | `prod` 时关闭 debug |
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
import js from '@eslint/js';
2+
import globals from 'globals';
3+
4+
export default [
5+
js.configs.recommended,
6+
{
7+
languageOptions: {
8+
globals: {
9+
...globals.node
10+
},
11+
ecmaVersion: 2020,
12+
sourceType: 'commonjs'
13+
},
14+
rules: {
15+
indent: [2, 2, { SwitchCase: 1 }],
16+
quotes: [2, 'single'],
17+
'linebreak-style': [2, 'unix'],
18+
semi: [2, 'always'],
19+
curly: 2,
20+
eqeqeq: 2,
21+
'no-eval': 2,
22+
'guard-for-in': 2,
23+
'no-caller': 2,
24+
'no-else-return': 2,
25+
'no-eq-null': 2,
26+
'no-extend-native': 2,
27+
'no-extra-bind': 2,
28+
'no-floating-decimal': 2,
29+
'no-implied-eval': 2,
30+
'no-labels': 2,
31+
'no-with': 2,
32+
'no-loop-func': 2,
33+
'no-redeclare': [2, { builtinGlobals: true }],
34+
'no-delete-var': 2,
35+
'no-shadow-restricted-names': 2,
36+
'no-undef-init': 2,
37+
'no-use-before-define': 2,
38+
'no-unused-vars': [2, { args: 'none' }],
39+
'no-undefined': 2,
40+
'no-undef': 2,
41+
'global-require': 0,
42+
'no-console': 2,
43+
'key-spacing': [2, { beforeColon: false, afterColon: true }],
44+
'eol-last': [2, 'always']
45+
}
46+
}
47+
];

‎assets/simple/js/nodemon.json.tmpl‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"watch": ["src"],
3+
"exec": "node src/bootstrap.js",
4+
"ext": "js"
5+
}

0 commit comments

Comments
 (0)