@webjsdev/cli 0.8.1 → 0.8.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 +12 -5
- package/bin/webjs.js +5 -2
- package/lib/create.js +65 -10
- package/package.json +4 -4
- package/templates/AGENTS.md +2 -2
package/README.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# @webjsdev/cli
|
|
2
2
|
|
|
3
|
-
CLI for [webjs](https://github.com/
|
|
3
|
+
CLI for [webjs](https://github.com/webjsdev/webjs): scaffold, develop,
|
|
4
4
|
build, and run webjs apps.
|
|
5
5
|
|
|
6
6
|
Installing this package gives you the `webjs` command.
|
|
@@ -17,17 +17,24 @@ Then scaffold a new app anywhere:
|
|
|
17
17
|
|
|
18
18
|
```sh
|
|
19
19
|
webjs create my-app
|
|
20
|
-
cd my-app && npm
|
|
20
|
+
cd my-app && npm run dev
|
|
21
21
|
# → http://localhost:3000
|
|
22
22
|
```
|
|
23
23
|
|
|
24
|
-
One-shot without global install:
|
|
24
|
+
One-shot without a global install, two ways:
|
|
25
25
|
|
|
26
26
|
```sh
|
|
27
|
+
# Preferred: the npx-discoverable scaffolder
|
|
28
|
+
npx create-webjs-app@latest my-app
|
|
29
|
+
cd my-app && npm run dev
|
|
30
|
+
|
|
31
|
+
# Or via the CLI's npx entry directly
|
|
27
32
|
npx @webjsdev/cli create my-app
|
|
28
|
-
cd my-app && npm
|
|
33
|
+
cd my-app && npm run dev
|
|
29
34
|
```
|
|
30
35
|
|
|
36
|
+
Both `webjs create` and `create-webjs-app` auto-install dependencies in the new directory using your detected package manager (npm / pnpm / yarn / bun). Pass `--no-install` to opt out.
|
|
37
|
+
|
|
31
38
|
## Commands
|
|
32
39
|
|
|
33
40
|
```sh
|
|
@@ -64,7 +71,7 @@ The scaffold seeds opinionated defaults so AI agents produce consistent code:
|
|
|
64
71
|
- Tailwind CSS via CLI (no browser runtime at build time)
|
|
65
72
|
- TypeScript, `.editorconfig`, `.gitignore`
|
|
66
73
|
|
|
67
|
-
See the full framework docs at https://github.com/
|
|
74
|
+
See the full framework docs at https://github.com/webjsdev/webjs.
|
|
68
75
|
|
|
69
76
|
## License
|
|
70
77
|
|
package/bin/webjs.js
CHANGED
|
@@ -16,8 +16,10 @@ const USAGE = `webjs commands:
|
|
|
16
16
|
webjs start [--port 3000] Start production server (serves source directly, no build step)
|
|
17
17
|
webjs test [--server|--browser] Run server + browser tests
|
|
18
18
|
webjs check Validate app against conventions
|
|
19
|
-
webjs create <name> [--template full-stack|api|saas] Scaffold a new webjs app
|
|
19
|
+
webjs create <name> [--template full-stack|api|saas] [--no-install] Scaffold a new webjs app
|
|
20
20
|
(only 3 templates exist. default: full-stack with Prisma+SQLite)
|
|
21
|
+
Auto-runs the detected package manager's install in the new dir
|
|
22
|
+
unless --no-install is passed.
|
|
21
23
|
webjs db generate Run \`prisma generate\`
|
|
22
24
|
webjs db migrate [name] Run \`prisma migrate dev\`
|
|
23
25
|
webjs db studio Run \`prisma studio\`
|
|
@@ -259,8 +261,9 @@ files.
|
|
|
259
261
|
Full docs: https://docs.webjs.com`);
|
|
260
262
|
process.exit(1);
|
|
261
263
|
}
|
|
264
|
+
const noInstall = rest.includes('--no-install');
|
|
262
265
|
const { scaffoldApp } = await import('../lib/create.js');
|
|
263
|
-
await scaffoldApp(name, process.cwd(), { template });
|
|
266
|
+
await scaffoldApp(name, process.cwd(), { template, install: !noInstall });
|
|
264
267
|
break;
|
|
265
268
|
}
|
|
266
269
|
case 'help':
|
package/lib/create.js
CHANGED
|
@@ -15,6 +15,37 @@ import { mkdir, writeFile, readFile, cp } from 'node:fs/promises';
|
|
|
15
15
|
import { join, resolve, dirname } from 'node:path';
|
|
16
16
|
import { fileURLToPath } from 'node:url';
|
|
17
17
|
import { existsSync } from 'node:fs';
|
|
18
|
+
import { spawnSync } from 'node:child_process';
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* Detect which package manager invoked us. Reads `npm_config_user_agent`,
|
|
22
|
+
* which npm / pnpm / yarn / bun all set when running scripts or `npx`.
|
|
23
|
+
* Falls back to `npm` when nothing is detected (matches what most users
|
|
24
|
+
* actually have installed).
|
|
25
|
+
*
|
|
26
|
+
* @returns {'npm'|'pnpm'|'yarn'|'bun'}
|
|
27
|
+
*/
|
|
28
|
+
function detectPackageManager() {
|
|
29
|
+
const ua = process.env.npm_config_user_agent || '';
|
|
30
|
+
if (ua.startsWith('pnpm/')) return 'pnpm';
|
|
31
|
+
if (ua.startsWith('yarn/')) return 'yarn';
|
|
32
|
+
if (ua.startsWith('bun/')) return 'bun';
|
|
33
|
+
return 'npm';
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
/**
|
|
37
|
+
* Run `<pm> install` inside the scaffolded app. Returns true on success.
|
|
38
|
+
* Inherits stdio so the user sees the install progress live. Caller decides
|
|
39
|
+
* whether to call this (skipped when --no-install).
|
|
40
|
+
*
|
|
41
|
+
* @param {string} appDir absolute path to the new app
|
|
42
|
+
* @param {'npm'|'pnpm'|'yarn'|'bun'} pm
|
|
43
|
+
* @returns {boolean}
|
|
44
|
+
*/
|
|
45
|
+
function runInstall(appDir, pm) {
|
|
46
|
+
const r = spawnSync(pm, ['install'], { cwd: appDir, stdio: 'inherit' });
|
|
47
|
+
return r.status === 0;
|
|
48
|
+
}
|
|
18
49
|
|
|
19
50
|
const __dirname = dirname(fileURLToPath(import.meta.url));
|
|
20
51
|
const TEMPLATES = resolve(__dirname, '..', 'templates');
|
|
@@ -142,6 +173,11 @@ async function readThemeCss() {
|
|
|
142
173
|
*/
|
|
143
174
|
export async function scaffoldApp(name, cwd, opts = {}) {
|
|
144
175
|
const template = opts.template || 'full-stack';
|
|
176
|
+
// `install` is opt-in at the library level (so tests + programmatic
|
|
177
|
+
// callers get a side-effect-free scaffold by default). The CLI entry
|
|
178
|
+
// points (`webjs create` and `npx create-webjs-app`) explicitly set
|
|
179
|
+
// `install: true` unless the user passes `--no-install`.
|
|
180
|
+
const shouldInstall = opts.install === true;
|
|
145
181
|
// Defence in depth. The CLI already validates this, but library
|
|
146
182
|
// callers (tests, programmatic use) might pass anything.
|
|
147
183
|
const VALID_TEMPLATES = ['full-stack', 'api', 'saas'];
|
|
@@ -855,20 +891,39 @@ ThemeToggle.register('theme-toggle');
|
|
|
855
891
|
CONVENTIONS.md, AGENTS.md, CLAUDE.md
|
|
856
892
|
`);
|
|
857
893
|
}
|
|
858
|
-
//
|
|
859
|
-
//
|
|
860
|
-
//
|
|
861
|
-
//
|
|
862
|
-
|
|
894
|
+
// Auto-install (default). Detect the package manager from the env so
|
|
895
|
+
// pnpm / yarn / bun users get their own. Pass `--no-install` (or
|
|
896
|
+
// `{ install: false }` to scaffoldApp) to opt out, e.g. for CI tests
|
|
897
|
+
// that exercise the scaffold without paying the install cost.
|
|
898
|
+
const pm = detectPackageManager();
|
|
899
|
+
let installed = false;
|
|
900
|
+
if (shouldInstall) {
|
|
901
|
+
console.log(`\nRunning '${pm} install' in ${name}/ ...\n`);
|
|
902
|
+
installed = runInstall(appDir, pm);
|
|
903
|
+
if (!installed) {
|
|
904
|
+
console.log(`\n[warn] ${pm} install failed. Run '${pm} install' manually in ${name}/ to finish setup.\n`);
|
|
905
|
+
}
|
|
906
|
+
}
|
|
907
|
+
|
|
908
|
+
// Post-scaffold guidance. Lead with a single copy-paste line so the
|
|
909
|
+
// user can move from "scaffold done" to "dev server up" in one
|
|
910
|
+
// command. The full-stack and saas templates ship with @webjsdev/ui
|
|
911
|
+
// already initialised; the api template has no UI but may add one
|
|
912
|
+
// later. Saas needs a one-time prisma migrate before the first run
|
|
913
|
+
// (the example User model wants its table to exist).
|
|
914
|
+
const installSegment = installed ? '' : `${pm} install && `;
|
|
915
|
+
const prismaSegment = isSaas ? `npx prisma migrate dev --name init && ` : '';
|
|
916
|
+
const runCommand = `cd ${name} && ${installSegment}${prismaSegment}${pm} run dev`;
|
|
863
917
|
const uiNote = isApi
|
|
864
918
|
? `# If you later add a UI to this API project:
|
|
865
|
-
# webjs ui init && webjs ui add button card dialog`
|
|
866
|
-
: `webjs ui add <name> #
|
|
919
|
+
# npx webjs ui init && npx webjs ui add button card dialog`
|
|
920
|
+
: `npx webjs ui add <name> # add more ui-* components later`;
|
|
867
921
|
console.log(`Next steps:
|
|
868
|
-
|
|
869
|
-
|
|
922
|
+
${runCommand}
|
|
923
|
+
# → http://localhost:3000
|
|
924
|
+
|
|
925
|
+
Optional:
|
|
870
926
|
${uiNote}
|
|
871
|
-
webjs dev
|
|
872
927
|
|
|
873
928
|
AI-driven development (enforced for all AI agents):
|
|
874
929
|
✓ Tests auto-generated with every feature
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@webjsdev/cli",
|
|
3
|
-
"version": "0.8.
|
|
3
|
+
"version": "0.8.3",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "webjs CLI - dev, start, create, db",
|
|
6
6
|
"bin": {
|
|
@@ -21,11 +21,11 @@
|
|
|
21
21
|
},
|
|
22
22
|
"repository": {
|
|
23
23
|
"type": "git",
|
|
24
|
-
"url": "git+https://github.com/
|
|
24
|
+
"url": "git+https://github.com/webjsdev/webjs.git",
|
|
25
25
|
"directory": "packages/cli"
|
|
26
26
|
},
|
|
27
|
-
"homepage": "https://github.com/
|
|
28
|
-
"bugs": "https://github.com/
|
|
27
|
+
"homepage": "https://github.com/webjsdev/webjs#readme",
|
|
28
|
+
"bugs": "https://github.com/webjsdev/webjs/issues",
|
|
29
29
|
"license": "MIT",
|
|
30
30
|
"keywords": [
|
|
31
31
|
"webjs",
|
package/templates/AGENTS.md
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
Read this before editing any file. This is a webjs app: AI-first, web-
|
|
4
4
|
components-first, no build step. The framework's own full API reference
|
|
5
|
-
lives at https://github.com/
|
|
5
|
+
lives at https://github.com/webjsdev/webjs/blob/main/AGENTS.md and the
|
|
6
6
|
full hosted documentation (every API, recipe, and example) lives at
|
|
7
7
|
**https://docs.webjs.com**. Treat this file as the app-scoped
|
|
8
8
|
companion and reach for docs.webjs.com whenever you need more detail.
|
|
@@ -483,7 +483,7 @@ Practical consequences for agents writing webjs code.
|
|
|
483
483
|
|
|
484
484
|
The full annotated catalog with code examples lives in the framework
|
|
485
485
|
repo at
|
|
486
|
-
[`agent-docs/lit-muscle-memory-gotchas.md`](https://github.com/
|
|
486
|
+
[`agent-docs/lit-muscle-memory-gotchas.md`](https://github.com/webjsdev/webjs/blob/main/agent-docs/lit-muscle-memory-gotchas.md).
|
|
487
487
|
|
|
488
488
|
## Server action pattern
|
|
489
489
|
|