create-davepi-app 0.1.0 → 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/bin/index.js +30 -2
- package/package.json +1 -1
- package/templates/_shared/agent.md +26 -0
package/bin/index.js
CHANGED
|
@@ -184,6 +184,25 @@ async function scaffold({ name, template, install, davepiVersion, port }) {
|
|
|
184
184
|
}
|
|
185
185
|
|
|
186
186
|
// 2. package.json — pin dAvePi as a runtime dep.
|
|
187
|
+
//
|
|
188
|
+
// The `imports` block declares Node's built-in subpath-import
|
|
189
|
+
// aliases (https://nodejs.org/api/packages.html#subpath-imports).
|
|
190
|
+
// Use them from any file in this project to require local code
|
|
191
|
+
// without `../../../` ladders:
|
|
192
|
+
//
|
|
193
|
+
// const postmark = require('#plugins/postmark'); // → ./plugins/postmark.js
|
|
194
|
+
// const { genCode } = require('#lib/codes'); // → ./lib/codes.js
|
|
195
|
+
// const helper = require('#plugins/postmark/helpers'); // → ./plugins/postmark/helpers.js
|
|
196
|
+
//
|
|
197
|
+
// The `.js` suffix on the right-hand side is intentional: Node's
|
|
198
|
+
// subpath-import resolver does NOT fall back to CJS resolution
|
|
199
|
+
// (`.js` / `/index.js`) for bare-glob targets — without the
|
|
200
|
+
// explicit extension, `require('#plugins/postmark')` would crash
|
|
201
|
+
// with MODULE_NOT_FOUND. The `*` matches the path segment(s)
|
|
202
|
+
// between the alias and the trailing `.js`, so nested files work
|
|
203
|
+
// too. `#` is the standard prefix (not `@`, which Node reserves
|
|
204
|
+
// for npm-scoped packages). This is the convention every dAvePi
|
|
205
|
+
// project uses; the docs site and the agent.md guide expect it.
|
|
187
206
|
writeJson(path.join(target, 'package.json'), {
|
|
188
207
|
name,
|
|
189
208
|
version: '0.1.0',
|
|
@@ -205,6 +224,11 @@ async function scaffold({ name, template, install, davepiVersion, port }) {
|
|
|
205
224
|
'gen-client': 'davepi gen-client --out client/davepi.ts',
|
|
206
225
|
'mcp:stdio': 'davepi mcp',
|
|
207
226
|
},
|
|
227
|
+
imports: {
|
|
228
|
+
'#plugins/*': './plugins/*.js',
|
|
229
|
+
'#lib/*': './lib/*.js',
|
|
230
|
+
'#schema/*': './schema/*.js',
|
|
231
|
+
},
|
|
208
232
|
dependencies: {
|
|
209
233
|
davepi: davepiVersion || 'latest',
|
|
210
234
|
},
|
|
@@ -230,7 +254,11 @@ async function scaffold({ name, template, install, davepiVersion, port }) {
|
|
|
230
254
|
`TOKEN_KEY=${randomSecret()}`,
|
|
231
255
|
`API_PORT=${apiPort}`,
|
|
232
256
|
`PAGE_SIZE=20`,
|
|
233
|
-
|
|
257
|
+
// localhost:3000 + localhost:5173 cover common frontend dev servers
|
|
258
|
+
// (CRA, Vite). localhost:${apiPort} covers same-origin asset loads
|
|
259
|
+
// from the bundled admin SPA in case the framework's same-origin
|
|
260
|
+
// bypass is ever bypassed.
|
|
261
|
+
`CORS_ORIGINS=http://localhost:3000,http://localhost:5173,http://localhost:${apiPort}`,
|
|
234
262
|
`# Set HOT_RELOAD_SCHEMAS=true in dev to pick up schema/versions/* changes live.`,
|
|
235
263
|
`HOT_RELOAD_SCHEMAS=true`,
|
|
236
264
|
`NODE_ENV=development`,
|
|
@@ -352,7 +380,7 @@ async function scaffold({ name, template, install, davepiVersion, port }) {
|
|
|
352
380
|
`- REST: http://localhost:${apiPort}/api/v1/...`,
|
|
353
381
|
`- GraphQL: http://localhost:${apiPort}/graphql/`,
|
|
354
382
|
`- Swagger: http://localhost:${apiPort}/api-docs`,
|
|
355
|
-
`- Admin SPA: http://localhost:${apiPort}/admin
|
|
383
|
+
`- Admin SPA: http://localhost:${apiPort}/admin`,
|
|
356
384
|
`- Capability manifest: http://localhost:${apiPort}/_describe`,
|
|
357
385
|
'',
|
|
358
386
|
'## What\'s in this template',
|
package/package.json
CHANGED
|
@@ -206,6 +206,32 @@ module.exports = {
|
|
|
206
206
|
- **State machines need `initial`.** Without it, the framework can't pick
|
|
207
207
|
a default starting state on POST and creates fail with a validation
|
|
208
208
|
error.
|
|
209
|
+
- **Use `#` subpath imports for local requires — never `../` ladders.**
|
|
210
|
+
Every scaffolded project ships with this in `package.json`:
|
|
211
|
+
|
|
212
|
+
```json
|
|
213
|
+
"imports": {
|
|
214
|
+
"#plugins/*": "./plugins/*.js",
|
|
215
|
+
"#lib/*": "./lib/*.js",
|
|
216
|
+
"#schema/*": "./schema/*.js"
|
|
217
|
+
}
|
|
218
|
+
```
|
|
219
|
+
|
|
220
|
+
So from a schema file or plugin, write:
|
|
221
|
+
|
|
222
|
+
```js
|
|
223
|
+
const postmark = require('#plugins/postmark'); // ✅ → ./plugins/postmark.js
|
|
224
|
+
const { genCode } = require('#lib/codes'); // ✅ → ./lib/codes.js
|
|
225
|
+
const postmark = require('../../../plugins/postmark'); // ❌ fragile
|
|
226
|
+
```
|
|
227
|
+
|
|
228
|
+
This is [Node's built-in subpath imports](https://nodejs.org/api/packages.html#subpath-imports) —
|
|
229
|
+
no bundler, no extra dep, no `@` prefix (Node reserves `@` for npm-scoped
|
|
230
|
+
packages like `@scope/pkg`; `#` is the standard for local aliases). The
|
|
231
|
+
trailing `.js` on the mapping target is required — Node's resolver does
|
|
232
|
+
not fall back to `.js`/`/index.js` for bare-glob subpath targets. Add
|
|
233
|
+
more entries to `imports` as you grow the project. Framework code from
|
|
234
|
+
the `davepi` package itself stays as `require('davepi/utils/...')`.
|
|
209
235
|
|
|
210
236
|
## The MCP tool surface
|
|
211
237
|
|