@askrjs/cli 0.0.2 → 0.0.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 +46 -7
- package/dist/add.d.ts +16 -0
- package/dist/add.js +558 -1
- package/dist/cli.d.ts +5 -0
- package/dist/cli.js +43 -16
- package/dist/create.d.ts +5 -0
- package/dist/create.js +104 -26
- package/dist/directory-swap-DWoHtx7C.js +35 -0
- package/dist/discovery-Difb7Y4G.js +323 -0
- package/dist/generate.d.ts +5 -0
- package/dist/generate.js +461 -0
- package/dist/is-direct-execution-Cdlr-ZUl.js +0 -2
- package/dist/openapi.d.ts +25 -0
- package/dist/openapi.js +49 -16
- package/dist/planner-VAj7qlxr.js +285 -0
- package/dist/range-YUs9eimn.js +125 -0
- package/dist/registry-CyrRHRG5.js +209 -0
- package/dist/skills/askr-dashboard-charts/SKILL.md +61 -44
- package/dist/skills/askr-dashboard-charts/agents/openai.yaml +2 -2
- package/dist/skills/askr-ssr-ssg/SKILL.md +3 -1
- package/dist/{skills-Bh0mEhIx.js → skills-B7CbWur9.js} +89 -26
- package/dist/skills.d.ts +18 -0
- package/dist/skills.js +1 -1
- package/dist/specification-DXnDOC-0.js +49 -0
- package/dist/ssg-config.d.ts +41 -0
- package/dist/ssg-config.js +1 -0
- package/dist/ssg.d.ts +61 -0
- package/dist/ssg.js +360 -24
- package/dist/templates/full-stack/AGENTS.md +0 -1
- package/dist/templates/full-stack/README.md +0 -1
- package/dist/templates/full-stack/index.html +0 -1
- package/dist/templates/full-stack/package.json +5 -3
- package/dist/templates/full-stack/server.ts +5 -9
- package/dist/templates/full-stack/src/action-authorizations.ts +2 -2
- package/dist/templates/full-stack/src/actions/create-message.ts +5 -5
- package/dist/templates/full-stack/src/i18n.ts +4 -4
- package/dist/templates/full-stack/src/main.tsx +4 -5
- package/dist/templates/full-stack/src/pages/home.tsx +5 -5
- package/dist/templates/full-stack/src/pages/layout.tsx +15 -5
- package/dist/templates/full-stack/src/pages/not-found.tsx +5 -2
- package/dist/templates/full-stack/src/routes.tsx +11 -12
- package/dist/templates/full-stack/src/schemas.ts +1 -2
- package/dist/templates/full-stack/src/server/action-registry.ts +5 -10
- package/dist/templates/full-stack/src/server/actions/create-message.ts +4 -4
- package/dist/templates/full-stack/src/server/app.ts +67 -57
- package/dist/templates/full-stack/src/server/dependencies.ts +10 -10
- package/dist/templates/full-stack/src/server/entry-server.ts +3 -3
- package/dist/templates/full-stack/src/telemetry.ts +1 -2
- package/dist/templates/full-stack/tests/actions/create-message.test.ts +7 -8
- package/dist/templates/full-stack/tsconfig.json +1 -2
- package/dist/templates/full-stack/vite.config.ts +5 -6
- package/dist/templates/spa/AGENTS.md +1 -1
- package/dist/templates/spa/package.json +3 -4
- package/dist/templates/spa/src/adapters/operations-client.ts +7 -2
- package/dist/templates/spa/src/pages/app/_routes.tsx +2 -0
- package/dist/templates/spa/src/pages/app/admin-home.tsx +21 -3
- package/dist/templates/spa/src/pages/public/_routes.tsx +2 -0
- package/dist/templates/spa/src/styles.css +1 -1
- package/dist/templates/spa/tsconfig.json +2 -1
- package/dist/templates/spa/vitest.config.ts +0 -4
- package/dist/templates/ssg/README.md +1 -1
- package/dist/templates/ssg/package.json +1 -1
- package/dist/templates/ssg/ssg.config.ts +7 -0
- package/dist/templates/ssg/tests/ssg-config.test.ts +5 -3
- package/dist/templates/ssg/tsconfig.json +2 -1
- package/dist/templates/ssg/vitest.config.ts +0 -4
- package/dist/templates/ssr/package.json +2 -2
- package/dist/templates/ssr/server.ts +4 -10
- package/dist/templates/ssr/src/entry-server.tsx +6 -4
- package/dist/templates/startkit/package.json +2 -2
- package/dist/templates/startkit/src/lib/mock-data.ts +17 -39
- package/dist/templates/startkit/tsconfig.json +2 -1
- package/dist/update.d.ts +41 -0
- package/dist/update.js +282 -2
- package/dist/writer-D8qe_7ud.js +226 -0
- package/package.json +23 -22
- package/dist/add-DqhqRzBQ.js +0 -555
- package/dist/add-DqhqRzBQ.js.map +0 -1
- package/dist/cli.js.map +0 -1
- package/dist/create.js.map +0 -1
- package/dist/is-direct-execution-Cdlr-ZUl.js.map +0 -1
- package/dist/openapi.js.map +0 -1
- package/dist/skills-Bh0mEhIx.js.map +0 -1
- package/dist/ssg.js.map +0 -1
- package/dist/templates/full-stack/src/vite-server.d.ts +0 -6
- package/dist/templates/spa/src/styles.d.ts +0 -1
- package/dist/templates/ssg/src/vite-env.d.ts +0 -5
- package/dist/templates/ssr/src/vite-server.d.ts +0 -7
- package/dist/templates/startkit/src/vite-env.d.ts +0 -5
- package/dist/update-DyW1na5V.js +0 -1140
- package/dist/update-DyW1na5V.js.map +0 -1
- package/skills/askr-accessibility/SKILL.md +0 -68
- package/skills/askr-accessibility/agents/openai.yaml +0 -4
- package/skills/askr-agent-execution/SKILL.md +0 -85
- package/skills/askr-agent-execution/agents/openai.yaml +0 -4
- package/skills/askr-agent-workflows/SKILL.md +0 -57
- package/skills/askr-agent-workflows/agents/openai.yaml +0 -4
- package/skills/askr-api-integration/SKILL.md +0 -79
- package/skills/askr-api-integration/agents/openai.yaml +0 -4
- package/skills/askr-app-builder/SKILL.md +0 -99
- package/skills/askr-app-builder/agents/openai.yaml +0 -4
- package/skills/askr-auth-access/SKILL.md +0 -74
- package/skills/askr-auth-access/agents/openai.yaml +0 -4
- package/skills/askr-cli-vite/SKILL.md +0 -76
- package/skills/askr-cli-vite/agents/openai.yaml +0 -4
- package/skills/askr-dashboard-charts/SKILL.md +0 -82
- package/skills/askr-dashboard-charts/agents/openai.yaml +0 -4
- package/skills/askr-design-system/SKILL.md +0 -86
- package/skills/askr-design-system/agents/openai.yaml +0 -4
- package/skills/askr-env-config/SKILL.md +0 -74
- package/skills/askr-env-config/agents/openai.yaml +0 -4
- package/skills/askr-error-loading-empty/SKILL.md +0 -89
- package/skills/askr-error-loading-empty/agents/openai.yaml +0 -4
- package/skills/askr-file-upload-artifacts/SKILL.md +0 -77
- package/skills/askr-file-upload-artifacts/agents/openai.yaml +0 -4
- package/skills/askr-forms-tables-crud/SKILL.md +0 -98
- package/skills/askr-forms-tables-crud/agents/openai.yaml +0 -4
- package/skills/askr-mental-model/SKILL.md +0 -109
- package/skills/askr-mental-model/agents/openai.yaml +0 -4
- package/skills/askr-migration-react/SKILL.md +0 -81
- package/skills/askr-migration-react/agents/openai.yaml +0 -4
- package/skills/askr-observability-debugging/SKILL.md +0 -83
- package/skills/askr-observability-debugging/agents/openai.yaml +0 -4
- package/skills/askr-project-structure/SKILL.md +0 -79
- package/skills/askr-project-structure/agents/openai.yaml +0 -4
- package/skills/askr-query-mutation/SKILL.md +0 -115
- package/skills/askr-query-mutation/agents/openai.yaml +0 -4
- package/skills/askr-realtime-streaming/SKILL.md +0 -76
- package/skills/askr-realtime-streaming/agents/openai.yaml +0 -4
- package/skills/askr-resources-data/SKILL.md +0 -100
- package/skills/askr-resources-data/agents/openai.yaml +0 -4
- package/skills/askr-routing-layouts/SKILL.md +0 -107
- package/skills/askr-routing-layouts/agents/openai.yaml +0 -4
- package/skills/askr-runtime-reactivity/SKILL.md +0 -92
- package/skills/askr-runtime-reactivity/agents/openai.yaml +0 -4
- package/skills/askr-ssr-ssg/SKILL.md +0 -76
- package/skills/askr-ssr-ssg/agents/openai.yaml +0 -4
- package/skills/askr-testing-determinism/SKILL.md +0 -75
- package/skills/askr-testing-determinism/agents/openai.yaml +0 -4
- package/skills/askr-theming/SKILL.md +0 -86
- package/skills/askr-theming/agents/openai.yaml +0 -4
- package/skills/askr-ui-composition/SKILL.md +0 -92
- package/skills/askr-ui-composition/agents/openai.yaml +0 -4
- package/templates/full-stack/AGENTS.md +0 -12
- package/templates/full-stack/README.md +0 -18
- package/templates/full-stack/gitignore.template +0 -4
- package/templates/full-stack/index.html +0 -14
- package/templates/full-stack/package.json +0 -37
- package/templates/full-stack/server.ts +0 -13
- package/templates/full-stack/src/action-authorizations.ts +0 -10
- package/templates/full-stack/src/actions/create-message.ts +0 -10
- package/templates/full-stack/src/i18n.ts +0 -8
- package/templates/full-stack/src/main.tsx +0 -12
- package/templates/full-stack/src/pages/home.tsx +0 -25
- package/templates/full-stack/src/pages/layout.tsx +0 -33
- package/templates/full-stack/src/pages/not-found.tsx +0 -4
- package/templates/full-stack/src/routes.tsx +0 -20
- package/templates/full-stack/src/schemas.ts +0 -11
- package/templates/full-stack/src/server/action-registry.ts +0 -12
- package/templates/full-stack/src/server/actions/create-message.ts +0 -14
- package/templates/full-stack/src/server/app.ts +0 -66
- package/templates/full-stack/src/server/dependencies.ts +0 -55
- package/templates/full-stack/src/server/entry-server.ts +0 -8
- package/templates/full-stack/src/telemetry.ts +0 -4
- package/templates/full-stack/src/vite-server.d.ts +0 -6
- package/templates/full-stack/tests/actions/create-message.test.ts +0 -13
- package/templates/full-stack/tsconfig.json +0 -16
- package/templates/full-stack/vite.config.ts +0 -11
- package/templates/spa/AGENTS.md +0 -60
- package/templates/spa/README.md +0 -96
- package/templates/spa/gitignore.template +0 -16
- package/templates/spa/index.html +0 -13
- package/templates/spa/package.json +0 -35
- package/templates/spa/src/adapters/operations-client.ts +0 -90
- package/templates/spa/src/components/shared/metric-card.tsx +0 -27
- package/templates/spa/src/components/shared/status-badge.tsx +0 -24
- package/templates/spa/src/features/operations/operations.query.ts +0 -9
- package/templates/spa/src/main.tsx +0 -10
- package/templates/spa/src/pages/_layout.tsx +0 -9
- package/templates/spa/src/pages/_routes.tsx +0 -27
- package/templates/spa/src/pages/app/_layout.tsx +0 -94
- package/templates/spa/src/pages/app/_routes.tsx +0 -10
- package/templates/spa/src/pages/app/admin-home.tsx +0 -152
- package/templates/spa/src/pages/app/agent-runs.tsx +0 -93
- package/templates/spa/src/pages/app/settings.tsx +0 -91
- package/templates/spa/src/pages/auth/_layout.tsx +0 -38
- package/templates/spa/src/pages/auth/_routes.tsx +0 -6
- package/templates/spa/src/pages/auth/login.tsx +0 -63
- package/templates/spa/src/pages/not-found.tsx +0 -22
- package/templates/spa/src/pages/public/_layout.tsx +0 -47
- package/templates/spa/src/pages/public/_routes.tsx +0 -6
- package/templates/spa/src/pages/public/home.tsx +0 -143
- package/templates/spa/src/shared/format.ts +0 -12
- package/templates/spa/src/shared/navigation.ts +0 -15
- package/templates/spa/src/styles/components.css +0 -49
- package/templates/spa/src/styles/layout.css +0 -192
- package/templates/spa/src/styles/reset.css +0 -44
- package/templates/spa/src/styles/theme.css +0 -57
- package/templates/spa/src/styles/tokens.css +0 -20
- package/templates/spa/src/styles.css +0 -7
- package/templates/spa/src/styles.d.ts +0 -1
- package/templates/spa/tests/app.test.tsx +0 -37
- package/templates/spa/tests/components/shared.test.tsx +0 -12
- package/templates/spa/tests/resources.test.ts +0 -22
- package/templates/spa/tsconfig.json +0 -20
- package/templates/spa/tsconfig.node.json +0 -10
- package/templates/spa/vite.config.ts +0 -24
- package/templates/spa/vitest.config.ts +0 -17
- package/templates/ssg/AGENTS.md +0 -55
- package/templates/ssg/README.md +0 -39
- package/templates/ssg/gitignore.template +0 -17
- package/templates/ssg/index.html +0 -13
- package/templates/ssg/package.json +0 -35
- package/templates/ssg/src/app.tsx +0 -14
- package/templates/ssg/src/components/badge.tsx +0 -3
- package/templates/ssg/src/components/counter.tsx +0 -30
- package/templates/ssg/src/components/site-shell.tsx +0 -111
- package/templates/ssg/src/jsx.d.ts +0 -23
- package/templates/ssg/src/main.tsx +0 -8
- package/templates/ssg/src/pages/about.tsx +0 -82
- package/templates/ssg/src/pages/content.tsx +0 -63
- package/templates/ssg/src/pages/example.tsx +0 -97
- package/templates/ssg/src/pages/home.tsx +0 -51
- package/templates/ssg/src/resources/user.ts +0 -15
- package/templates/ssg/src/routes.tsx +0 -15
- package/templates/ssg/src/styles.css +0 -89
- package/templates/ssg/src/vite-env.d.ts +0 -5
- package/templates/ssg/ssg.config.ts +0 -34
- package/templates/ssg/tests/app.test.tsx +0 -19
- package/templates/ssg/tests/components/counter.test.tsx +0 -18
- package/templates/ssg/tests/resources.test.ts +0 -11
- package/templates/ssg/tests/ssg-config.test.ts +0 -11
- package/templates/ssg/tsconfig.json +0 -20
- package/templates/ssg/tsconfig.node.json +0 -10
- package/templates/ssg/vite.config.ts +0 -24
- package/templates/ssg/vitest.config.ts +0 -17
- package/templates/ssr/AGENTS.md +0 -28
- package/templates/ssr/README.md +0 -38
- package/templates/ssr/gitignore.template +0 -16
- package/templates/ssr/index.html +0 -13
- package/templates/ssr/package.json +0 -34
- package/templates/ssr/server.ts +0 -16
- package/templates/ssr/src/app.tsx +0 -21
- package/templates/ssr/src/components/counter.tsx +0 -26
- package/templates/ssr/src/entry-server.tsx +0 -10
- package/templates/ssr/src/main.tsx +0 -11
- package/templates/ssr/src/pages/about.tsx +0 -75
- package/templates/ssr/src/pages/example.tsx +0 -113
- package/templates/ssr/src/pages/home.tsx +0 -56
- package/templates/ssr/src/resources/user.ts +0 -15
- package/templates/ssr/src/routes.tsx +0 -13
- package/templates/ssr/src/styles.css +0 -148
- package/templates/ssr/src/vite-server.d.ts +0 -7
- package/templates/ssr/tests/app.test.tsx +0 -24
- package/templates/ssr/tests/components/counter.test.tsx +0 -13
- package/templates/ssr/tests/resources.test.ts +0 -11
- package/templates/ssr/tsconfig.json +0 -22
- package/templates/ssr/tsconfig.node.json +0 -10
- package/templates/ssr/tsconfig.server.json +0 -15
- package/templates/ssr/vite.config.ts +0 -25
- package/templates/ssr/vitest.config.ts +0 -13
- package/templates/startkit/AGENTS.md +0 -77
- package/templates/startkit/README.md +0 -192
- package/templates/startkit/gitignore.template +0 -16
- package/templates/startkit/index.html +0 -13
- package/templates/startkit/package.json +0 -35
- package/templates/startkit/src/components/app-header.tsx +0 -93
- package/templates/startkit/src/components/app-sidebar.tsx +0 -95
- package/templates/startkit/src/components/data-table.tsx +0 -80
- package/templates/startkit/src/components/empty-state.tsx +0 -13
- package/templates/startkit/src/components/page-header.tsx +0 -23
- package/templates/startkit/src/components/stat-card.tsx +0 -24
- package/templates/startkit/src/features/accounts/account-filters.tsx +0 -61
- package/templates/startkit/src/features/accounts/account-table.tsx +0 -79
- package/templates/startkit/src/lib/format.ts +0 -31
- package/templates/startkit/src/lib/mock-data.ts +0 -441
- package/templates/startkit/src/lib/routes.ts +0 -116
- package/templates/startkit/src/main.tsx +0 -12
- package/templates/startkit/src/pages/_layout.tsx +0 -56
- package/templates/startkit/src/pages/auth/_layout.tsx +0 -7
- package/templates/startkit/src/pages/auth/login.tsx +0 -129
- package/templates/startkit/src/pages/home.tsx +0 -83
- package/templates/startkit/src/pages/not-found.tsx +0 -24
- package/templates/startkit/src/pages/workspace/_layout.tsx +0 -17
- package/templates/startkit/src/pages/workspace/accounts/index.tsx +0 -217
- package/templates/startkit/src/pages/workspace/dashboard.tsx +0 -118
- package/templates/startkit/src/pages/workspace/settings.tsx +0 -218
- package/templates/startkit/src/router.tsx +0 -7
- package/templates/startkit/src/routes/auth-config.ts +0 -38
- package/templates/startkit/src/routes/auth.ts +0 -8
- package/templates/startkit/src/routes/index.ts +0 -28
- package/templates/startkit/src/routes/public.ts +0 -8
- package/templates/startkit/src/routes/workspace/accounts.ts +0 -8
- package/templates/startkit/src/routes/workspace/index.ts +0 -14
- package/templates/startkit/src/styles/components.css +0 -396
- package/templates/startkit/src/styles/layout.css +0 -192
- package/templates/startkit/src/styles/reset.css +0 -38
- package/templates/startkit/src/styles/theme.css +0 -76
- package/templates/startkit/src/styles/tokens.css +0 -67
- package/templates/startkit/src/styles.css +0 -7
- package/templates/startkit/src/toast.ts +0 -55
- package/templates/startkit/src/utils/join-classes.ts +0 -4
- package/templates/startkit/src/vite-env.d.ts +0 -5
- package/templates/startkit/tests/app.test.tsx +0 -32
- package/templates/startkit/tests/preferences.test.ts +0 -43
- package/templates/startkit/tests/resources.test.ts +0 -82
- package/templates/startkit/tsconfig.json +0 -20
- package/templates/startkit/tsconfig.node.json +0 -10
- package/templates/startkit/vite.config.ts +0 -32
- package/templates/startkit/vitest.config.ts +0 -13
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@askrjs/cli",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.4",
|
|
4
4
|
"description": "Unified CLI for the Askr platform",
|
|
5
5
|
"homepage": "https://github.com/askrjs/askr-cli#readme",
|
|
6
6
|
"bugs": {
|
|
@@ -19,13 +19,15 @@
|
|
|
19
19
|
"askr": "./dist/cli.js"
|
|
20
20
|
},
|
|
21
21
|
"files": [
|
|
22
|
-
"dist"
|
|
23
|
-
"skills",
|
|
24
|
-
"templates"
|
|
22
|
+
"dist"
|
|
25
23
|
],
|
|
26
24
|
"type": "module",
|
|
27
25
|
"exports": {
|
|
28
|
-
"./package.json": "./package.json"
|
|
26
|
+
"./package.json": "./package.json",
|
|
27
|
+
"./ssg": {
|
|
28
|
+
"types": "./dist/ssg-config.d.ts",
|
|
29
|
+
"import": "./dist/ssg-config.js"
|
|
30
|
+
}
|
|
29
31
|
},
|
|
30
32
|
"publishConfig": {
|
|
31
33
|
"access": "public"
|
|
@@ -35,36 +37,35 @@
|
|
|
35
37
|
"build": "vp pack",
|
|
36
38
|
"dev": "vp pack --watch",
|
|
37
39
|
"test": "vp test run -c vitest.config.ts",
|
|
40
|
+
"test:coverage": "vp test run -c vitest.config.ts --coverage",
|
|
38
41
|
"fmt": "vp fmt .",
|
|
39
42
|
"lint": "vp lint src tests vite.config.ts vitest.config.ts",
|
|
40
43
|
"typecheck": "tsc -p tsconfig.json --noEmit",
|
|
41
44
|
"test:publint": "publint",
|
|
42
45
|
"pack:check": "npm pack --ignore-scripts --dry-run --json",
|
|
43
|
-
"
|
|
46
|
+
"test:templates": "node scripts/verify-packed-templates.mjs",
|
|
47
|
+
"check": "npm run lint && npm run typecheck && npm run test:coverage && npm run build && npm run test:publint && npm run pack:check",
|
|
44
48
|
"prepack": "npm run build",
|
|
45
|
-
"prepublishOnly": "npm run check"
|
|
49
|
+
"prepublishOnly": "npm run check && npm run test:templates"
|
|
46
50
|
},
|
|
47
51
|
"dependencies": {
|
|
48
|
-
"
|
|
49
|
-
"@npmcli/map-workspaces": "^4.0.2",
|
|
50
|
-
"jsonc-parser": "^3.3.1",
|
|
52
|
+
"js-yaml": "^4.3.0",
|
|
51
53
|
"minimatch": "^10.2.5",
|
|
52
|
-
"npm-package-arg": "^13.0.2",
|
|
53
|
-
"npm-registry-fetch": "^19.1.1",
|
|
54
54
|
"semver": "^7.8.5",
|
|
55
|
-
"tsx": "^4.23.1"
|
|
56
|
-
"yaml": "^2.9.0"
|
|
55
|
+
"tsx": "^4.23.1"
|
|
57
56
|
},
|
|
58
57
|
"devDependencies": {
|
|
59
|
-
"@askrjs/askr": "
|
|
60
|
-
"@askrjs/charts": "
|
|
61
|
-
"@askrjs/logos": "
|
|
62
|
-
"@askrjs/lucide": "
|
|
63
|
-
"@askrjs/themes": "
|
|
64
|
-
"@askrjs/ui": "
|
|
65
|
-
"@askrjs/vite": "
|
|
66
|
-
"@types/
|
|
58
|
+
"@askrjs/askr": ">=0.0.53 <0.1.0",
|
|
59
|
+
"@askrjs/charts": ">=0.1.0 <0.2.0",
|
|
60
|
+
"@askrjs/logos": ">=0.0.3 <0.1.0",
|
|
61
|
+
"@askrjs/lucide": ">=0.0.3 <0.1.0",
|
|
62
|
+
"@askrjs/themes": ">=0.0.12 <0.1.0",
|
|
63
|
+
"@askrjs/ui": ">=0.0.13 <0.1.0",
|
|
64
|
+
"@askrjs/vite": ">=0.0.6 <0.1.0",
|
|
65
|
+
"@types/js-yaml": "^4.0.9",
|
|
66
|
+
"@types/node": "^20.19.43",
|
|
67
67
|
"@types/semver": "^7.7.1",
|
|
68
|
+
"@vitest/coverage-v8": "^4.1.10",
|
|
68
69
|
"publint": "^0.3.21",
|
|
69
70
|
"typescript": "^6.0.3",
|
|
70
71
|
"vite-plus": "^0.2.4",
|
package/dist/add-DqhqRzBQ.js
DELETED
|
@@ -1,555 +0,0 @@
|
|
|
1
|
-
import { t as isDirectExecution } from "./is-direct-execution-Cdlr-ZUl.js";
|
|
2
|
-
import fs from "node:fs/promises";
|
|
3
|
-
import path from "node:path";
|
|
4
|
-
import { randomUUID } from "node:crypto";
|
|
5
|
-
//#region src/file-changes.ts
|
|
6
|
-
async function remove(paths) {
|
|
7
|
-
await Promise.all(paths.map((filePath) => fs.rm(filePath, { force: true }).catch(() => void 0)));
|
|
8
|
-
}
|
|
9
|
-
async function restore(changes) {
|
|
10
|
-
let complete = true;
|
|
11
|
-
for (const change of [...changes].reverse()) try {
|
|
12
|
-
if (change.original === null) {
|
|
13
|
-
await fs.rm(change.filePath, { force: true });
|
|
14
|
-
continue;
|
|
15
|
-
}
|
|
16
|
-
const rollbackPath = path.join(path.dirname(change.filePath), `.${path.basename(change.filePath)}.askr-rollback-${randomUUID()}`);
|
|
17
|
-
await fs.writeFile(rollbackPath, change.original, {
|
|
18
|
-
flag: "wx",
|
|
19
|
-
mode: change.mode
|
|
20
|
-
});
|
|
21
|
-
await fs.rename(rollbackPath, change.filePath);
|
|
22
|
-
} catch {
|
|
23
|
-
complete = false;
|
|
24
|
-
}
|
|
25
|
-
return complete;
|
|
26
|
-
}
|
|
27
|
-
async function writeFileChanges(changes, options = {}) {
|
|
28
|
-
const ordered = [...changes].sort((left, right) => left.filePath.localeCompare(right.filePath));
|
|
29
|
-
if (new Set(ordered.map((change) => change.filePath)).size !== ordered.length) throw new Error("File changes contain duplicate target paths.");
|
|
30
|
-
const replace = options.replace ?? fs.rename;
|
|
31
|
-
const staged = [];
|
|
32
|
-
try {
|
|
33
|
-
for (const change of ordered) {
|
|
34
|
-
await fs.mkdir(path.dirname(change.filePath), { recursive: true });
|
|
35
|
-
const stat = await fs.stat(change.filePath).catch(() => null);
|
|
36
|
-
const original = stat ? await fs.readFile(change.filePath) : null;
|
|
37
|
-
const temporaryPath = path.join(path.dirname(change.filePath), `.${path.basename(change.filePath)}.askr-change-${randomUUID()}`);
|
|
38
|
-
const mode = stat?.mode ?? 420;
|
|
39
|
-
await fs.writeFile(temporaryPath, change.content, {
|
|
40
|
-
flag: "wx",
|
|
41
|
-
mode
|
|
42
|
-
});
|
|
43
|
-
staged.push({
|
|
44
|
-
...change,
|
|
45
|
-
original,
|
|
46
|
-
mode,
|
|
47
|
-
temporaryPath
|
|
48
|
-
});
|
|
49
|
-
}
|
|
50
|
-
} catch (error) {
|
|
51
|
-
await remove(staged.map((change) => change.temporaryPath));
|
|
52
|
-
throw error;
|
|
53
|
-
}
|
|
54
|
-
const replaced = [];
|
|
55
|
-
try {
|
|
56
|
-
for (const change of staged) {
|
|
57
|
-
await replace(change.temporaryPath, change.filePath);
|
|
58
|
-
replaced.push(change);
|
|
59
|
-
}
|
|
60
|
-
} catch {
|
|
61
|
-
const complete = await restore(replaced);
|
|
62
|
-
await remove(staged.map((change) => change.temporaryPath));
|
|
63
|
-
throw new Error(complete ? "File replacement failed; completed changes were rolled back." : "File replacement failed and rollback was incomplete.");
|
|
64
|
-
}
|
|
65
|
-
}
|
|
66
|
-
//#endregion
|
|
67
|
-
//#region src/bin/add.ts
|
|
68
|
-
const BRANCH_CONFIG = {
|
|
69
|
-
app: {
|
|
70
|
-
badge: "app route",
|
|
71
|
-
pagesDir: [
|
|
72
|
-
"src",
|
|
73
|
-
"pages",
|
|
74
|
-
"app"
|
|
75
|
-
],
|
|
76
|
-
routesFile: [
|
|
77
|
-
"src",
|
|
78
|
-
"pages",
|
|
79
|
-
"app",
|
|
80
|
-
"_routes.tsx"
|
|
81
|
-
]
|
|
82
|
-
},
|
|
83
|
-
public: {
|
|
84
|
-
badge: "public route",
|
|
85
|
-
pagesDir: [
|
|
86
|
-
"src",
|
|
87
|
-
"pages",
|
|
88
|
-
"public"
|
|
89
|
-
],
|
|
90
|
-
routesFile: [
|
|
91
|
-
"src",
|
|
92
|
-
"pages",
|
|
93
|
-
"public",
|
|
94
|
-
"_routes.tsx"
|
|
95
|
-
]
|
|
96
|
-
}
|
|
97
|
-
};
|
|
98
|
-
function helpText() {
|
|
99
|
-
return [
|
|
100
|
-
"askr add - Generate code into an existing Askr project",
|
|
101
|
-
"",
|
|
102
|
-
"Usage:",
|
|
103
|
-
" askr add page <name> [--branch app|public] [--cwd <dir>] [--title <title>] [--route <path>] [--force]",
|
|
104
|
-
" askr add action <name> --route <path> [--cwd <dir>] [--force]",
|
|
105
|
-
"",
|
|
106
|
-
"Commands:",
|
|
107
|
-
" page Scaffold a route page and register it in a route-first SPA branch",
|
|
108
|
-
" action Scaffold a browser descriptor, server handler, registration, authorization, and test",
|
|
109
|
-
"",
|
|
110
|
-
"Options:",
|
|
111
|
-
" --branch <name> Route branch to target (default: app)",
|
|
112
|
-
" --cwd <dir> Project directory (default: current directory)",
|
|
113
|
-
" --title <text> Override the generated page title",
|
|
114
|
-
" --route <path> Override the generated route path",
|
|
115
|
-
" --force Overwrite an existing page file",
|
|
116
|
-
" --help Show this help message",
|
|
117
|
-
"",
|
|
118
|
-
"Examples:",
|
|
119
|
-
" askr add page audit-log",
|
|
120
|
-
" askr add page ops/audit-log --branch public",
|
|
121
|
-
" askr add page approvals --title \"Human approvals\" --route /app/approvals",
|
|
122
|
-
" askr add action approve-request --route /requests/{id}",
|
|
123
|
-
"",
|
|
124
|
-
"Notes:",
|
|
125
|
-
" Page generation supports route-first SPA projects created from `askr create spa`.",
|
|
126
|
-
" Action generation supports projects created from `askr create full-stack`."
|
|
127
|
-
].join("\n");
|
|
128
|
-
}
|
|
129
|
-
function parseArgs(args) {
|
|
130
|
-
const positional = [];
|
|
131
|
-
const parsed = {
|
|
132
|
-
branch: "app",
|
|
133
|
-
cwd: process.cwd(),
|
|
134
|
-
force: false,
|
|
135
|
-
help: false,
|
|
136
|
-
routePath: "",
|
|
137
|
-
title: "",
|
|
138
|
-
errors: []
|
|
139
|
-
};
|
|
140
|
-
for (let index = 0; index < args.length; index += 1) {
|
|
141
|
-
const arg = args[index];
|
|
142
|
-
if (arg === "--help" || arg === "-h") parsed.help = true;
|
|
143
|
-
else if (arg === "--force") parsed.force = true;
|
|
144
|
-
else if (arg === "--branch") if (index + 1 >= args.length) parsed.errors.push("Missing value for --branch");
|
|
145
|
-
else {
|
|
146
|
-
parsed.branch = args[index + 1];
|
|
147
|
-
index += 1;
|
|
148
|
-
}
|
|
149
|
-
else if (arg === "--cwd") if (index + 1 >= args.length) parsed.errors.push("Missing value for --cwd");
|
|
150
|
-
else {
|
|
151
|
-
parsed.cwd = args[index + 1];
|
|
152
|
-
index += 1;
|
|
153
|
-
}
|
|
154
|
-
else if (arg === "--title") if (index + 1 >= args.length) parsed.errors.push("Missing value for --title");
|
|
155
|
-
else {
|
|
156
|
-
parsed.title = args[index + 1].trim();
|
|
157
|
-
index += 1;
|
|
158
|
-
}
|
|
159
|
-
else if (arg === "--route") if (index + 1 >= args.length) parsed.errors.push("Missing value for --route");
|
|
160
|
-
else {
|
|
161
|
-
parsed.routePath = args[index + 1].trim();
|
|
162
|
-
index += 1;
|
|
163
|
-
}
|
|
164
|
-
else positional.push(arg);
|
|
165
|
-
}
|
|
166
|
-
return {
|
|
167
|
-
...parsed,
|
|
168
|
-
command: positional[0] || "",
|
|
169
|
-
name: positional[1] || ""
|
|
170
|
-
};
|
|
171
|
-
}
|
|
172
|
-
async function pathExists(filePath) {
|
|
173
|
-
return Boolean(await fs.stat(filePath).catch(() => null));
|
|
174
|
-
}
|
|
175
|
-
function slugifySegment(value) {
|
|
176
|
-
return value.replace(/([a-z0-9])([A-Z])/g, "$1-$2").toLowerCase().replace(/[^a-z0-9]+/g, "-").replace(/^-+|-+$/g, "");
|
|
177
|
-
}
|
|
178
|
-
function normalizePageSegments(input) {
|
|
179
|
-
const segments = input.replace(/^\/+|\/+$/g, "").split("/").map((segment) => slugifySegment(segment.trim())).filter(Boolean);
|
|
180
|
-
if (segments.length === 0 || segments.some((segment) => segment.startsWith("_"))) return [];
|
|
181
|
-
return segments;
|
|
182
|
-
}
|
|
183
|
-
function toWords(segments) {
|
|
184
|
-
return segments.flatMap((segment) => segment.split("-").filter(Boolean));
|
|
185
|
-
}
|
|
186
|
-
function toTitleCase(words) {
|
|
187
|
-
return words.map((word) => word.charAt(0).toUpperCase() + word.slice(1)).join(" ");
|
|
188
|
-
}
|
|
189
|
-
function buildComponentName(segments) {
|
|
190
|
-
return `${toWords(segments).map((word) => word.charAt(0).toUpperCase() + word.slice(1)).join("")}Page`;
|
|
191
|
-
}
|
|
192
|
-
function buildIdentifier(segments) {
|
|
193
|
-
const [first = "action", ...rest] = toWords(segments);
|
|
194
|
-
return [first.toLowerCase(), ...rest.map((word) => word.charAt(0).toUpperCase() + word.slice(1))].join("").replace(/^[^a-z_$]/i, "action");
|
|
195
|
-
}
|
|
196
|
-
function renderAuthorizationRegistry(actions) {
|
|
197
|
-
const imports = actions.map((action) => `import { ${action.descriptorName} } from './actions/${action.slug}.js';`);
|
|
198
|
-
const routes = /* @__PURE__ */ new Map();
|
|
199
|
-
for (const action of actions) {
|
|
200
|
-
const entries = routes.get(action.routePath) ?? [];
|
|
201
|
-
entries.push(action);
|
|
202
|
-
routes.set(action.routePath, entries);
|
|
203
|
-
}
|
|
204
|
-
const routeLines = [...routes].sort(([left], [right]) => left.localeCompare(right)).map(([routePath, entries]) => ` ${JSON.stringify(routePath)}: [${entries.map((entry) => entry.descriptorName).join(", ")}],`);
|
|
205
|
-
return [
|
|
206
|
-
"import type { ActionDescriptor } from '@askrjs/askr/actions';",
|
|
207
|
-
...imports,
|
|
208
|
-
"",
|
|
209
|
-
"const actionsByRoute: Readonly<Record<string, readonly ActionDescriptor[]>> = Object.freeze({",
|
|
210
|
-
...routeLines,
|
|
211
|
-
"});",
|
|
212
|
-
"",
|
|
213
|
-
"export function actionsFor(path: string): readonly ActionDescriptor[] {",
|
|
214
|
-
" return actionsByRoute[path] ?? [];",
|
|
215
|
-
"}",
|
|
216
|
-
""
|
|
217
|
-
].join("\n");
|
|
218
|
-
}
|
|
219
|
-
function renderServerActionRegistry(actions) {
|
|
220
|
-
return [
|
|
221
|
-
"import { createActionRegistry } from '@askrjs/server/askr';",
|
|
222
|
-
...actions.map((action) => `import { ${action.descriptorName} } from '../actions/${action.slug}.js';`),
|
|
223
|
-
...actions.map((action) => `import { ${action.handlerName} } from './actions/${action.slug}.js';`),
|
|
224
|
-
"import type { AppDependencies } from './dependencies.js';",
|
|
225
|
-
"",
|
|
226
|
-
"export function createActions(deps: AppDependencies) {",
|
|
227
|
-
" const registry = createActionRegistry(deps, {",
|
|
228
|
-
" csrf: { secret: process.env.CSRF_SECRET ?? 'development-only-secret' },",
|
|
229
|
-
" });",
|
|
230
|
-
...actions.map((action) => ` registry.register(${action.descriptorName}, ${action.handlerName});`),
|
|
231
|
-
" return registry;",
|
|
232
|
-
"}",
|
|
233
|
-
""
|
|
234
|
-
].join("\n");
|
|
235
|
-
}
|
|
236
|
-
async function discoverDeclaredActions(projectRoot, replacement) {
|
|
237
|
-
const actionsDir = path.join(projectRoot, "src", "actions");
|
|
238
|
-
const names = await fs.readdir(actionsDir).catch(() => []);
|
|
239
|
-
const files = new Set(names.filter((name) => name.endsWith(".ts")).map((name) => path.join(actionsDir, name)));
|
|
240
|
-
files.add(replacement.filePath);
|
|
241
|
-
const actions = [];
|
|
242
|
-
for (const filePath of [...files].sort()) {
|
|
243
|
-
const content = filePath === replacement.filePath ? replacement.content : await fs.readFile(filePath, "utf8");
|
|
244
|
-
const descriptor = /export const (\w+Action) = defineAction\(/.exec(content)?.[1];
|
|
245
|
-
if (!descriptor) continue;
|
|
246
|
-
const routeName = `${descriptor}Route`;
|
|
247
|
-
const routeMatch = new RegExp(`export const ${routeName} = (['"])(.*?)\\1;`).exec(content);
|
|
248
|
-
if (!routeMatch) throw new Error(`Action descriptor ${path.basename(filePath)} must declare ${routeName}.`);
|
|
249
|
-
const slug = path.basename(filePath, ".ts");
|
|
250
|
-
actions.push({
|
|
251
|
-
slug,
|
|
252
|
-
descriptorName: descriptor,
|
|
253
|
-
handlerName: buildIdentifier([slug]),
|
|
254
|
-
routePath: routeMatch[2]
|
|
255
|
-
});
|
|
256
|
-
}
|
|
257
|
-
return actions.sort((left, right) => left.slug.localeCompare(right.slug));
|
|
258
|
-
}
|
|
259
|
-
function renderActionDescriptor(options) {
|
|
260
|
-
return [
|
|
261
|
-
"import { defineAction } from '@askrjs/askr/actions';",
|
|
262
|
-
"import { schema } from '@askrjs/schema';",
|
|
263
|
-
"",
|
|
264
|
-
`export const ${options.descriptorName}Route = ${JSON.stringify(options.routePath)};`,
|
|
265
|
-
"",
|
|
266
|
-
`export const ${options.descriptorName} = defineAction({`,
|
|
267
|
-
` id: '${options.slug}',`,
|
|
268
|
-
" input: schema.object({ value: schema.string({ minLength: 1 }) }),",
|
|
269
|
-
" invalidates: [],",
|
|
270
|
-
"});",
|
|
271
|
-
""
|
|
272
|
-
].join("\n");
|
|
273
|
-
}
|
|
274
|
-
function renderActionHandler(options) {
|
|
275
|
-
return [
|
|
276
|
-
"import type { InferSchema } from '@askrjs/schema';",
|
|
277
|
-
`import { ${options.descriptorName} } from '../../actions/${options.slug}.js';`,
|
|
278
|
-
"import type { AppDependencies } from '../dependencies.js';",
|
|
279
|
-
"",
|
|
280
|
-
`type Input = InferSchema<typeof ${options.descriptorName}.input>;`,
|
|
281
|
-
"",
|
|
282
|
-
`export async function ${options.handlerName}(`,
|
|
283
|
-
" _context: unknown,",
|
|
284
|
-
" input: Input,",
|
|
285
|
-
" deps: Pick<AppDependencies, 'actions'>,",
|
|
286
|
-
") {",
|
|
287
|
-
" await deps.actions.record({ action: " + JSON.stringify(options.slug) + ", value: input.value });",
|
|
288
|
-
" return { result: { accepted: true } };",
|
|
289
|
-
"}",
|
|
290
|
-
""
|
|
291
|
-
].join("\n");
|
|
292
|
-
}
|
|
293
|
-
function renderActionTest(options) {
|
|
294
|
-
return [
|
|
295
|
-
"import { describe, expect, it } from 'vitest';",
|
|
296
|
-
`import { ${options.descriptorName} } from '../../src/actions/${options.slug}.js';`,
|
|
297
|
-
"",
|
|
298
|
-
`describe('${options.slug} action', () => {`,
|
|
299
|
-
" it('should expose a browser-safe executable input contract', () => {",
|
|
300
|
-
` expect(${options.descriptorName}.id).toBe('${options.slug}');`,
|
|
301
|
-
` expect(${options.descriptorName}.input.safeParse({ value: 'example' }).success).toBe(true);`,
|
|
302
|
-
` expect(${options.descriptorName}.input.safeParse({ value: '' }).success).toBe(false);`,
|
|
303
|
-
" });",
|
|
304
|
-
"});",
|
|
305
|
-
""
|
|
306
|
-
].join("\n");
|
|
307
|
-
}
|
|
308
|
-
function buildRoutePath(branch, segments, overridePath = "") {
|
|
309
|
-
if (!overridePath) {
|
|
310
|
-
const suffix = segments.join("/");
|
|
311
|
-
return branch === "app" ? `/app/${suffix}` : `/${suffix}`;
|
|
312
|
-
}
|
|
313
|
-
const normalized = overridePath.startsWith("/") ? overridePath : `/${overridePath}`;
|
|
314
|
-
if (branch === "app") return normalized === "/app" || normalized.startsWith("/app/") ? normalized : `/app${normalized}`;
|
|
315
|
-
if (normalized === "/app" || normalized.startsWith("/app/")) throw new Error("Public branch routes cannot live under /app.");
|
|
316
|
-
return normalized;
|
|
317
|
-
}
|
|
318
|
-
function toImportSpecifier(fromFile, toFile) {
|
|
319
|
-
const withoutExtension = path.relative(path.dirname(fromFile), toFile).replace(/\\/g, "/").replace(/\.tsx$/i, "");
|
|
320
|
-
return withoutExtension.startsWith(".") ? withoutExtension : `./${withoutExtension}`;
|
|
321
|
-
}
|
|
322
|
-
function createUpdatedRouteFile(routeFileContent, options) {
|
|
323
|
-
const normalized = routeFileContent.replace(/\r\n/g, "\n");
|
|
324
|
-
const lines = normalized.split("\n");
|
|
325
|
-
const lastImportIndex = lines.reduce((currentIndex, line, index) => line.startsWith("import ") ? index : currentIndex, -1);
|
|
326
|
-
if (lastImportIndex === -1) throw new Error("Unsupported route file: could not find import block.");
|
|
327
|
-
const importLine = `import ${options.componentName} from '${options.importSpecifier}';`;
|
|
328
|
-
if (normalized.includes(importLine) || normalized.includes(`route('${options.routePath}',`) || normalized.includes(`route("${options.routePath}",`)) throw new Error(`Route '${options.routePath}' is already registered.`);
|
|
329
|
-
lines.splice(lastImportIndex + 1, 0, importLine);
|
|
330
|
-
const closingIndex = lines.map((line) => line.trim()).lastIndexOf("}");
|
|
331
|
-
if (closingIndex === -1) throw new Error("Unsupported route file: could not find registration function body.");
|
|
332
|
-
lines.splice(closingIndex, 0, ` route('${options.routePath}', ${options.componentName});`);
|
|
333
|
-
return `${lines.join("\n")}\n`;
|
|
334
|
-
}
|
|
335
|
-
function renderPageFile(options) {
|
|
336
|
-
return [
|
|
337
|
-
"import {",
|
|
338
|
-
" Badge,",
|
|
339
|
-
" Card,",
|
|
340
|
-
" CardContent,",
|
|
341
|
-
" CardDescription,",
|
|
342
|
-
" CardHeader,",
|
|
343
|
-
" CardTitle,",
|
|
344
|
-
"} from '@askrjs/themes/components';",
|
|
345
|
-
"import { Stack } from '@askrjs/themes/components';",
|
|
346
|
-
"",
|
|
347
|
-
`export default function ${options.componentName}() {`,
|
|
348
|
-
" return (",
|
|
349
|
-
" <Stack gap=\"5\">",
|
|
350
|
-
" <section class=\"page-heading\">",
|
|
351
|
-
" <Stack gap=\"2\">",
|
|
352
|
-
` <Badge>${options.badge}</Badge>`,
|
|
353
|
-
` <h1>${options.title}</h1>`,
|
|
354
|
-
" <p class=\"lead\">",
|
|
355
|
-
` Route-first scaffold for ${options.routePath}. Keep adapters, queries, and mutations outside the page as this surface grows.`,
|
|
356
|
-
" </p>",
|
|
357
|
-
" </Stack>",
|
|
358
|
-
" </section>",
|
|
359
|
-
"",
|
|
360
|
-
" <Card>",
|
|
361
|
-
" <CardHeader>",
|
|
362
|
-
" <CardTitle>Next step</CardTitle>",
|
|
363
|
-
" <CardDescription>",
|
|
364
|
-
" Move view logic into feature folders and keep loading, empty, error, and success states explicit.",
|
|
365
|
-
" </CardDescription>",
|
|
366
|
-
" </CardHeader>",
|
|
367
|
-
" <CardContent>",
|
|
368
|
-
" <Stack gap=\"3\">",
|
|
369
|
-
" <p>Start with a focused feature boundary instead of inline data fetching.</p>",
|
|
370
|
-
" <p>Prefer resource(), derive(), and For once the page takes on real state.</p>",
|
|
371
|
-
" </Stack>",
|
|
372
|
-
" </CardContent>",
|
|
373
|
-
" </Card>",
|
|
374
|
-
" </Stack>",
|
|
375
|
-
" );",
|
|
376
|
-
"}",
|
|
377
|
-
""
|
|
378
|
-
].join("\n");
|
|
379
|
-
}
|
|
380
|
-
async function addPage(parsed, io) {
|
|
381
|
-
if (!parsed.name) {
|
|
382
|
-
io.error("Page name is required.");
|
|
383
|
-
return 1;
|
|
384
|
-
}
|
|
385
|
-
const branch = parsed.branch.toLowerCase();
|
|
386
|
-
const branchConfig = BRANCH_CONFIG[branch];
|
|
387
|
-
if (!branchConfig) {
|
|
388
|
-
io.error(`Unsupported branch '${parsed.branch}'. Use app or public.`);
|
|
389
|
-
return 1;
|
|
390
|
-
}
|
|
391
|
-
const segments = normalizePageSegments(parsed.name);
|
|
392
|
-
if (segments.length === 0) {
|
|
393
|
-
io.error("Page name must contain at least one non-empty path segment.");
|
|
394
|
-
return 1;
|
|
395
|
-
}
|
|
396
|
-
const projectRoot = path.resolve(parsed.cwd);
|
|
397
|
-
const routesFile = path.join(projectRoot, ...branchConfig.routesFile);
|
|
398
|
-
if (!await pathExists(routesFile)) {
|
|
399
|
-
io.error(`Unsupported project layout. Expected route file: ${routesFile}`);
|
|
400
|
-
io.error("askr add page currently supports route-first SPA projects created by `askr create spa`.");
|
|
401
|
-
return 1;
|
|
402
|
-
}
|
|
403
|
-
const pageFile = path.join(projectRoot, ...branchConfig.pagesDir, ...segments).concat(".tsx");
|
|
404
|
-
if (await pathExists(pageFile) && !parsed.force) {
|
|
405
|
-
io.error(`Page file already exists: ${pageFile}`);
|
|
406
|
-
io.error("Pass --force to overwrite the existing file.");
|
|
407
|
-
return 1;
|
|
408
|
-
}
|
|
409
|
-
const title = parsed.title || toTitleCase(toWords(segments));
|
|
410
|
-
const componentName = buildComponentName(segments);
|
|
411
|
-
let routePath = "";
|
|
412
|
-
try {
|
|
413
|
-
routePath = buildRoutePath(branch, segments, parsed.routePath);
|
|
414
|
-
} catch (error) {
|
|
415
|
-
io.error(error instanceof Error ? error.message : String(error));
|
|
416
|
-
return 1;
|
|
417
|
-
}
|
|
418
|
-
const importSpecifier = toImportSpecifier(routesFile, pageFile);
|
|
419
|
-
let updatedRoutes = "";
|
|
420
|
-
try {
|
|
421
|
-
updatedRoutes = createUpdatedRouteFile(await fs.readFile(routesFile, "utf8"), {
|
|
422
|
-
componentName,
|
|
423
|
-
importSpecifier,
|
|
424
|
-
routePath
|
|
425
|
-
});
|
|
426
|
-
} catch (error) {
|
|
427
|
-
io.error(error instanceof Error ? error.message : String(error));
|
|
428
|
-
return 1;
|
|
429
|
-
}
|
|
430
|
-
try {
|
|
431
|
-
await fs.mkdir(path.dirname(pageFile), { recursive: true });
|
|
432
|
-
await fs.writeFile(pageFile, renderPageFile({
|
|
433
|
-
badge: branchConfig.badge,
|
|
434
|
-
componentName,
|
|
435
|
-
routePath,
|
|
436
|
-
title
|
|
437
|
-
}), "utf8");
|
|
438
|
-
await fs.writeFile(routesFile, updatedRoutes, "utf8");
|
|
439
|
-
} catch (error) {
|
|
440
|
-
io.error("Failed to write generated page artifacts.");
|
|
441
|
-
io.error(error instanceof Error ? error.message : String(error));
|
|
442
|
-
return 1;
|
|
443
|
-
}
|
|
444
|
-
io.log(`Added ${branch} page '${title}'.`);
|
|
445
|
-
io.log(` File: ${path.relative(projectRoot, pageFile).replace(/\\/g, "/")}`);
|
|
446
|
-
io.log(` Route: ${routePath}`);
|
|
447
|
-
io.log(` Router: ${path.relative(projectRoot, routesFile).replace(/\\/g, "/")}`);
|
|
448
|
-
return 0;
|
|
449
|
-
}
|
|
450
|
-
async function addAction(parsed, io) {
|
|
451
|
-
if (!parsed.name) {
|
|
452
|
-
io.error("Action name is required.");
|
|
453
|
-
return 1;
|
|
454
|
-
}
|
|
455
|
-
if (!parsed.routePath || !parsed.routePath.startsWith("/")) {
|
|
456
|
-
io.error("Action generation requires an absolute --route path.");
|
|
457
|
-
return 1;
|
|
458
|
-
}
|
|
459
|
-
const segments = normalizePageSegments(parsed.name);
|
|
460
|
-
if (segments.length === 0) {
|
|
461
|
-
io.error("Action name must contain at least one non-empty path segment.");
|
|
462
|
-
return 1;
|
|
463
|
-
}
|
|
464
|
-
const projectRoot = path.resolve(parsed.cwd);
|
|
465
|
-
const slug = segments.join("-");
|
|
466
|
-
const handlerName = buildIdentifier(segments);
|
|
467
|
-
const descriptorName = `${handlerName}Action`;
|
|
468
|
-
const descriptorFile = path.join(projectRoot, "src", "actions", `${slug}.ts`);
|
|
469
|
-
const handlerFile = path.join(projectRoot, "src", "server", "actions", `${slug}.ts`);
|
|
470
|
-
const registryFile = path.join(projectRoot, "src", "server", "action-registry.ts");
|
|
471
|
-
const authorizationFile = path.join(projectRoot, "src", "action-authorizations.ts");
|
|
472
|
-
const testFile = path.join(projectRoot, "tests", "actions", `${slug}.test.ts`);
|
|
473
|
-
if (!await pathExists(registryFile) || !await pathExists(authorizationFile)) {
|
|
474
|
-
io.error("Unsupported project layout. Expected an `askr create full-stack` project.");
|
|
475
|
-
return 1;
|
|
476
|
-
}
|
|
477
|
-
if (!parsed.force && (await pathExists(descriptorFile) || await pathExists(handlerFile))) {
|
|
478
|
-
io.error(`Action '${slug}' already exists. Pass --force to replace its generated files.`);
|
|
479
|
-
return 1;
|
|
480
|
-
}
|
|
481
|
-
try {
|
|
482
|
-
const descriptor = renderActionDescriptor({
|
|
483
|
-
descriptorName,
|
|
484
|
-
routePath: parsed.routePath,
|
|
485
|
-
slug
|
|
486
|
-
});
|
|
487
|
-
const actions = await discoverDeclaredActions(projectRoot, {
|
|
488
|
-
filePath: descriptorFile,
|
|
489
|
-
content: descriptor
|
|
490
|
-
});
|
|
491
|
-
await writeFileChanges([
|
|
492
|
-
{
|
|
493
|
-
filePath: descriptorFile,
|
|
494
|
-
content: descriptor
|
|
495
|
-
},
|
|
496
|
-
{
|
|
497
|
-
filePath: handlerFile,
|
|
498
|
-
content: renderActionHandler({
|
|
499
|
-
descriptorName,
|
|
500
|
-
handlerName,
|
|
501
|
-
slug
|
|
502
|
-
})
|
|
503
|
-
},
|
|
504
|
-
{
|
|
505
|
-
filePath: testFile,
|
|
506
|
-
content: renderActionTest({
|
|
507
|
-
descriptorName,
|
|
508
|
-
slug
|
|
509
|
-
})
|
|
510
|
-
},
|
|
511
|
-
{
|
|
512
|
-
filePath: registryFile,
|
|
513
|
-
content: renderServerActionRegistry(actions)
|
|
514
|
-
},
|
|
515
|
-
{
|
|
516
|
-
filePath: authorizationFile,
|
|
517
|
-
content: renderAuthorizationRegistry(actions)
|
|
518
|
-
}
|
|
519
|
-
]);
|
|
520
|
-
} catch (error) {
|
|
521
|
-
io.error("Failed to write generated action artifacts.");
|
|
522
|
-
io.error(error instanceof Error ? error.message : String(error));
|
|
523
|
-
return 1;
|
|
524
|
-
}
|
|
525
|
-
io.log(`Added action '${slug}' for ${parsed.routePath}.`);
|
|
526
|
-
io.log(` Descriptor: ${path.relative(projectRoot, descriptorFile).replace(/\\/g, "/")}`);
|
|
527
|
-
io.log(` Handler: ${path.relative(projectRoot, handlerFile).replace(/\\/g, "/")}`);
|
|
528
|
-
io.log(` Test: ${path.relative(projectRoot, testFile).replace(/\\/g, "/")}`);
|
|
529
|
-
return 0;
|
|
530
|
-
}
|
|
531
|
-
async function runAddCli(args = process.argv.slice(2), io = console) {
|
|
532
|
-
const parsed = parseArgs(args);
|
|
533
|
-
if (parsed.errors.length > 0) {
|
|
534
|
-
for (const message of parsed.errors) io.error(message);
|
|
535
|
-
return 1;
|
|
536
|
-
}
|
|
537
|
-
if (!parsed.command || parsed.help) {
|
|
538
|
-
io.log(helpText());
|
|
539
|
-
return 0;
|
|
540
|
-
}
|
|
541
|
-
if (parsed.command === "page") return addPage(parsed, io);
|
|
542
|
-
if (parsed.command === "action") return addAction(parsed, io);
|
|
543
|
-
io.error(`Unknown add command: ${parsed.command}`);
|
|
544
|
-
io.error("Run `askr add --help` to see available commands.");
|
|
545
|
-
return 1;
|
|
546
|
-
}
|
|
547
|
-
async function main() {
|
|
548
|
-
const code = await runAddCli(process.argv.slice(2));
|
|
549
|
-
process.exit(code);
|
|
550
|
-
}
|
|
551
|
-
if (isDirectExecution(import.meta.url)) main();
|
|
552
|
-
//#endregion
|
|
553
|
-
export { runAddCli as t };
|
|
554
|
-
|
|
555
|
-
//# sourceMappingURL=add-DqhqRzBQ.js.map
|