anhedral 0.17.0 → 0.19.0
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 +33 -68
- package/assets/contracts/LICENSE +201 -0
- package/assets/contracts/LICENSE.environment +201 -0
- package/assets/contracts/LICENSE.operations +201 -0
- package/assets/contracts/deployment-provenance.json +15 -0
- package/assets/contracts/environment-provenance.json +11 -0
- package/assets/contracts/operations-provenance.json +12 -0
- package/assets/launch/application.server.ts.txt +13 -0
- package/assets/launch/auth-client.ts.txt +4 -0
- package/assets/launch/home.tsx.txt +20 -0
- package/assets/launch/minimal-application.server.ts.txt +5 -0
- package/assets/launch/minimal-server.ts.txt +7 -0
- package/assets/launch/oj/OJ.LICENSE +21 -0
- package/assets/launch/oj/run.mjs +82 -0
- package/assets/launch/oj/runtime.json +21 -0
- package/assets/launch/request-context.ts.txt +3 -0
- package/assets/launch/root.tsx.txt +26 -0
- package/assets/launch/router.tsx.txt +21 -0
- package/assets/launch/server.ts.txt +15 -0
- package/assets/launch/sign-in.tsx.txt +53 -0
- package/assets/launch/styles.css.txt +19 -0
- package/assets/security/credential-patterns.d.mts +3 -0
- package/assets/security/credential-patterns.mjs +59 -0
- package/assets/stack/api-index.ts.txt +6 -1
- package/assets/stack/stripe.ts.txt +30 -13
- package/assets/ui/catalog.json +36 -324
- package/dist/{platforms/web.d.ts → api-proxy.d.ts} +1 -3
- package/dist/api-proxy.js +48 -0
- package/dist/bin.js +55 -36
- package/dist/capability-catalog.d.ts +36 -57
- package/dist/capability-catalog.js +65 -67
- package/dist/capability-command.d.ts +3 -3
- package/dist/capability-command.js +146 -59
- package/dist/capability-editor.js +6 -5
- package/dist/capability-recipes.js +9 -296
- package/dist/cli-arguments.d.ts +2 -0
- package/dist/cli-arguments.js +101 -50
- package/dist/cli-commands.d.ts +1 -1
- package/dist/cli-commands.js +31 -5
- package/dist/cli-errors.d.ts +18 -0
- package/dist/cli-errors.js +63 -0
- package/dist/cli-output.d.ts +22 -0
- package/dist/cli-output.js +42 -7
- package/dist/command-runner.js +88 -0
- package/dist/command-schema.d.ts +16 -0
- package/dist/command-schema.js +496 -21
- package/dist/command-types.d.ts +1 -0
- package/dist/command-types.js +1 -0
- package/dist/completion.d.ts +2 -0
- package/dist/completion.js +201 -0
- package/dist/composition.d.ts +25 -0
- package/dist/composition.js +28 -0
- package/dist/contracts/cli-transport.d.ts +316 -0
- package/dist/contracts/cli-transport.js +236 -0
- package/dist/contracts/deployment.d.ts +233 -0
- package/dist/contracts/deployment.js +198 -0
- package/dist/contracts/environment-file.d.ts +7 -0
- package/dist/contracts/environment-file.js +112 -0
- package/dist/contracts/environment-transport.d.ts +79 -0
- package/dist/contracts/environment-transport.js +110 -0
- package/dist/contracts/production-transport.d.ts +71 -0
- package/dist/contracts/production-transport.js +56 -0
- package/dist/contracts/runtime-logs-transport.d.ts +127 -0
- package/dist/contracts/runtime-logs-transport.js +50 -0
- package/dist/contracts/source-bundle.d.ts +11 -0
- package/dist/contracts/source-bundle.js +197 -0
- package/dist/contracts/source-profile.d.ts +4 -0
- package/dist/contracts/source-profile.js +5 -0
- package/dist/contracts/staging-transport.d.ts +79 -0
- package/dist/contracts/staging-transport.js +43 -0
- package/dist/dependencies.d.ts +9 -27
- package/dist/dependencies.js +19 -66
- package/dist/index.d.ts +4 -2
- package/dist/index.js +3 -1
- package/dist/launch.d.ts +27 -0
- package/dist/launch.js +262 -0
- package/dist/platform-command.d.ts +9 -0
- package/dist/platform-command.js +787 -0
- package/dist/platform-environment.d.ts +18 -0
- package/dist/platform-environment.js +257 -0
- package/dist/platform-operations.d.ts +26 -0
- package/dist/platform-operations.js +155 -0
- package/dist/platform-production.d.ts +16 -0
- package/dist/platform-production.js +135 -0
- package/dist/platform-source.d.ts +8 -0
- package/dist/platform-source.js +111 -0
- package/dist/platform-state.d.ts +15 -0
- package/dist/platform-state.js +229 -0
- package/dist/platforms/tanstack.d.ts +10 -0
- package/dist/platforms/tanstack.js +248 -0
- package/dist/registry/usage.d.ts +4 -1
- package/dist/registry/usage.js +59 -4
- package/dist/scaffold/bootstrap.d.ts +3 -3
- package/dist/scaffold/styling.d.ts +3 -2
- package/dist/transaction.js +28 -3
- package/dist/ui-catalog.d.ts +3 -5
- package/dist/ui-catalog.js +8 -24
- package/dist/ui-command.d.ts +3 -1
- package/dist/ui-command.js +74 -72
- package/dist/ui-project.d.ts +4 -2
- package/dist/ui-project.js +40 -38
- package/dist/util.js +40 -61
- package/dist/version.d.ts +1 -1
- package/dist/version.js +1 -1
- package/docs/capabilities.md +23 -89
- package/docs/software-factory.md +208 -9
- package/docs/stack-standard.md +7 -17
- package/docs/ui.md +9 -22
- package/package.json +26 -22
- package/assets/stack/ai-schema.ts.txt +0 -5
- package/assets/stack/ai.ts.txt +0 -30
- package/assets/stack/desktop.rs.txt +0 -21
- package/assets/stack/events-schema.ts.txt +0 -12
- package/assets/stack/events.ts.txt +0 -59
- package/assets/stack/mobile-auth.ts.txt +0 -25
- package/assets/stack/mobile-billing.tsx.txt +0 -63
- package/assets/stack/mobile-session.tsx.txt +0 -83
- package/assets/stack/native-button.tsx.txt +0 -108
- package/assets/stack/native-global.css.txt +0 -4
- package/assets/stack/native-lib-utils.ts.txt +0 -5
- package/assets/stack/native-metro.config.js.txt +0 -6
- package/assets/stack/native-nativewind-env.d.ts.txt +0 -1
- package/assets/stack/native-tailwind.config.js.txt +0 -73
- package/assets/stack/native-text.tsx.txt +0 -89
- package/assets/stack/purchases.ts.txt +0 -65
- package/assets/stack/revenuecat.ts.txt +0 -88
- package/assets/stack/rtc-schema.ts.txt +0 -10
- package/assets/stack/rtc.ts.txt +0 -122
- package/assets/stack/web-sign-in.tsx.txt +0 -51
- package/dist/capabilities.d.ts +0 -11
- package/dist/capabilities.js +0 -14
- package/dist/dependency-order.d.ts +0 -2
- package/dist/dependency-order.js +0 -24
- package/dist/platforms/lint.d.ts +0 -1
- package/dist/platforms/lint.js +0 -5
- package/dist/platforms/web.js +0 -251
- package/dist/project-config.d.ts +0 -3
- package/dist/project-config.js +0 -16
- package/dist/registry/context.d.ts +0 -3
- package/dist/registry/context.js +0 -20
- package/dist/registry/options.d.ts +0 -2
- package/dist/registry/options.js +0 -44
- package/dist/registry/resolve.d.ts +0 -11
- package/dist/registry/resolve.js +0 -46
- package/dist/registry/types.d.ts +0 -60
- package/dist/scaffold/api.d.ts +0 -2
- package/dist/scaffold/api.js +0 -38
- package/dist/scaffold/backend.d.ts +0 -2
- package/dist/scaffold/backend.js +0 -36
- package/dist/scaffold/compose.d.ts +0 -4
- package/dist/scaffold/compose.js +0 -30
- package/dist/scaffold/database.d.ts +0 -2
- package/dist/scaffold/database.js +0 -41
- package/dist/scaffold/documentation.d.ts +0 -2
- package/dist/scaffold/documentation.js +0 -71
- package/dist/scaffold/environment.d.ts +0 -4
- package/dist/scaffold/environment.js +0 -22
- package/dist/scaffold/stack-documentation.d.ts +0 -2
- package/dist/scaffold/stack-documentation.js +0 -6
- package/dist/scaffold/storage.d.ts +0 -2
- package/dist/scaffold/storage.js +0 -21
- package/dist/scaffold/workspace.d.ts +0 -3
- package/dist/scaffold/workspace.js +0 -131
- package/dist/stack-registry.d.ts +0 -35
- package/dist/stack-registry.js +0 -189
- package/dist/standard.d.ts +0 -8
- package/dist/standard.js +0 -94
- package/dist/workspace-graph.d.ts +0 -7
- package/dist/workspace-graph.js +0 -74
- package/docs/anhedral-stack.md +0 -12
- package/docs/assets/anhedral-stack-light.png +0 -0
- package/docs/assets/anhedral-stack.png +0 -0
- package/docs/native-ui.md +0 -47
- /package/dist/{registry/types.js → command-runner.d.ts} +0 -0
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import { readFileSync } from 'node:fs';
|
|
2
|
-
import {
|
|
3
|
-
import { CapabilityEditor, fingerprint } from './capability-editor.js';
|
|
2
|
+
import { CapabilityEditor } from './capability-editor.js';
|
|
4
3
|
import { CAPABILITY_DEPENDENCIES as P } from './dependencies.js';
|
|
5
4
|
import { STACK_DEPENDENCIES as D } from './dependencies.js';
|
|
6
5
|
import { resourceName } from './render.js';
|
|
7
|
-
import {
|
|
6
|
+
import { composeTanstack, addTanstackAuth } from './platforms/tanstack.js';
|
|
7
|
+
import { WEB_API_PROXY } from './api-proxy.js';
|
|
8
8
|
const template = (name) => readFileSync(new URL(`../assets/stack/${name}`, import.meta.url), 'utf8');
|
|
9
9
|
const json = (value) => JSON.stringify(value, null, 2) + '\n';
|
|
10
10
|
function dependency(e, app, dependencies) {
|
|
@@ -96,23 +96,8 @@ export function addCapabilityRecipe(e, id, name) {
|
|
|
96
96
|
});
|
|
97
97
|
else
|
|
98
98
|
e.set(web, ['services'], [{ binding: 'ANHEDRAL_API', service: resourceName(name, 'api') }]);
|
|
99
|
-
e.
|
|
100
|
-
e.create('apps/web/lib/
|
|
101
|
-
import { getCloudflareContext } from '@opennextjs/cloudflare';
|
|
102
|
-
import { proxyApi,type ApiBinding } from './api-proxy';
|
|
103
|
-
function apiBinding(candidate:unknown):ApiBinding|undefined {
|
|
104
|
-
if(typeof candidate !== 'object' || candidate===null)return undefined;
|
|
105
|
-
if(typeof Reflect.get(candidate,'fetch') !== 'function')return undefined;
|
|
106
|
-
return candidate as ApiBinding;
|
|
107
|
-
}
|
|
108
|
-
export async function apiRequest(request:Request):Promise<Response>{
|
|
109
|
-
if(process.env.NODE_ENV==='development')return proxyApi(request,{development:true,devOrigin:process.env.API_INTERNAL_URL});
|
|
110
|
-
const {env}=await getCloudflareContext({async:true});
|
|
111
|
-
return proxyApi(request,{development:false,binding:apiBinding(Reflect.get(env,'ANHEDRAL_API'))});
|
|
112
|
-
}
|
|
113
|
-
`);
|
|
114
|
-
e.create('apps/web/app/api/[[...path]]/route.ts', "import { apiRequest } from '@/lib/server-api';\nexport const dynamic = 'force-dynamic';\nexport const GET = apiRequest;\nexport const POST = apiRequest;\nexport const PUT = apiRequest;\nexport const PATCH = apiRequest;\nexport const DELETE = apiRequest;\nexport const HEAD = apiRequest;\nexport const OPTIONS = apiRequest;\n");
|
|
115
|
-
e.create('apps/web/README.hono.md', '# Hono development\n\nSet this in apps/web/.env.local for local development:\n\n```dotenv\nAPI_INTERNAL_URL=http://127.0.0.1:8787\n```\n\nProduction uses the ANHEDRAL_API service binding.\n');
|
|
99
|
+
e.set('apps/api/package.json', ['devDependencies', 'wrangler'], e.json('apps/web/package.json').devDependencies.wrangler);
|
|
100
|
+
e.create('apps/web/src/lib/api-proxy.ts', WEB_API_PROXY.replace("'idempotency-key'", "'idempotency-key', 'stripe-signature', 'last-event-id'").replace('AbortSignal.timeout(15000)', "AbortSignal.timeout(request.headers.get('accept')?.includes('text/event-stream') ? 35000 : 15000)"));
|
|
116
101
|
break;
|
|
117
102
|
}
|
|
118
103
|
case 'database-auth': {
|
|
@@ -170,8 +155,7 @@ export async function apiRequest(request:Request):Promise<Response>{
|
|
|
170
155
|
e.create('apps/api/src/auth-features.ts', template('auth-features.ts.txt'));
|
|
171
156
|
e.create('apps/api/src/security.ts', template('security.ts.txt'));
|
|
172
157
|
e.create('apps/api/src/features/auth.ts', template('auth-routes.ts.txt'));
|
|
173
|
-
e
|
|
174
|
-
e.create('apps/web/lib/auth-client.ts', "'use client';\nimport { createAuthClient } from 'better-auth/react';\nexport const authClient = createAuthClient();\n");
|
|
158
|
+
addTanstackAuth(e);
|
|
175
159
|
e.merge('package.json', 'scripts', {
|
|
176
160
|
'db:generate': 'pnpm --dir packages/db db:generate',
|
|
177
161
|
'db:migrate': 'pnpm --dir packages/db db:migrate',
|
|
@@ -195,231 +179,17 @@ export async function apiRequest(request:Request):Promise<Response>{
|
|
|
195
179
|
e.create('packages/db/src/billing-schema.ts', template('billing-schema.ts.txt'));
|
|
196
180
|
schemaExport(e, 'billing-schema');
|
|
197
181
|
break;
|
|
198
|
-
case 'revenuecat':
|
|
199
|
-
dependency(e, 'apps/mobile', { 'react-native-purchases': P['react-native-purchases'] });
|
|
200
|
-
e.create('apps/api/src/features/revenuecat.ts', template('revenuecat.ts.txt'));
|
|
201
|
-
e.create('apps/mobile/lib/purchases.ts', template('purchases.ts.txt'));
|
|
202
|
-
appendExample(e, 'apps/mobile/.env.example', [
|
|
203
|
-
'EXPO_PUBLIC_REVENUECAT_IOS_KEY',
|
|
204
|
-
'EXPO_PUBLIC_REVENUECAT_ANDROID_KEY',
|
|
205
|
-
]);
|
|
206
|
-
e.create('apps/mobile/components/billing-controls.tsx', template('mobile-billing.tsx.txt'));
|
|
207
|
-
break;
|
|
208
|
-
case 'realtime':
|
|
209
|
-
e.create('packages/db/src/events-schema.ts', template('events-schema.ts.txt'));
|
|
210
|
-
schemaExport(e, 'events-schema');
|
|
211
|
-
e.create('apps/api/src/features/events.ts', template('events.ts.txt'));
|
|
212
|
-
break;
|
|
213
|
-
case 'rtc':
|
|
214
|
-
e.create('apps/api/src/features/rtc.ts', template('rtc.ts.txt'));
|
|
215
|
-
e.create('packages/db/src/rtc-schema.ts', template('rtc-schema.ts.txt'));
|
|
216
|
-
schemaExport(e, 'rtc-schema');
|
|
217
|
-
break;
|
|
218
|
-
case 'ai':
|
|
219
|
-
apiConfig(e, 'ai', { binding: 'AI', remote: true });
|
|
220
|
-
e.create('apps/api/src/features/ai.ts', template('ai.ts.txt'));
|
|
221
|
-
e.create('packages/db/src/ai-schema.ts', template('ai-schema.ts.txt'));
|
|
222
|
-
schemaExport(e, 'ai-schema');
|
|
223
|
-
break;
|
|
224
|
-
case 'expo':
|
|
225
|
-
addExpo(e, name);
|
|
226
|
-
break;
|
|
227
|
-
case 'native-ui':
|
|
228
|
-
addNativeUi(e);
|
|
229
|
-
break;
|
|
230
|
-
case 'wxt':
|
|
231
|
-
addExtension(e);
|
|
232
|
-
break;
|
|
233
|
-
case 'side-panel':
|
|
234
|
-
e.create('apps/extension/entrypoints/sidepanel/index.html', '<!doctype html><html><head><meta charset="UTF-8"><title>Side panel</title></head><body><div id="root"></div><script type="module" src="./main.tsx"></script></body></html>\n');
|
|
235
|
-
e.create('apps/extension/entrypoints/sidepanel/main.tsx', "import { createRoot } from 'react-dom/client';\nimport { App } from '../../components/App';\ncreateRoot(document.getElementById('root')!).render(<App />);\n");
|
|
236
|
-
break;
|
|
237
|
-
case 'gpui':
|
|
238
|
-
addDesktop(e);
|
|
239
|
-
break;
|
|
240
182
|
}
|
|
241
183
|
}
|
|
242
|
-
function addExpo(e, name) {
|
|
243
|
-
project(e, 'apps/mobile', '@workspace/mobile', {
|
|
244
|
-
dev: 'expo start',
|
|
245
|
-
start: 'expo start',
|
|
246
|
-
android: 'expo run:android',
|
|
247
|
-
ios: 'expo run:ios',
|
|
248
|
-
typecheck: 'tsc --noEmit',
|
|
249
|
-
lint: 'tsc --noEmit',
|
|
250
|
-
build: 'expo export --platform ios --platform android',
|
|
251
|
-
}, {
|
|
252
|
-
expo: P.expo,
|
|
253
|
-
react: P.react,
|
|
254
|
-
'react-native': P['react-native'],
|
|
255
|
-
'expo-secure-store': P['expo-secure-store'],
|
|
256
|
-
'expo-linking': P['expo-linking'],
|
|
257
|
-
'better-auth': P['better-auth'],
|
|
258
|
-
'@better-auth/expo': P['@better-auth/expo'],
|
|
259
|
-
}, { '@types/react': P['@types/react'], 'babel-preset-expo': P['babel-preset-expo'] });
|
|
260
|
-
e.set('apps/mobile/package.json', ['type'], 'commonjs');
|
|
261
|
-
e.set('apps/mobile/package.json', ['main'], 'index.ts');
|
|
262
|
-
const workspaceSource = e.read('pnpm-workspace.yaml');
|
|
263
|
-
if (workspaceSource === null)
|
|
264
|
-
throw Error('Missing pnpm workspace');
|
|
265
|
-
const workspace = parseDocument(workspaceSource);
|
|
266
|
-
if (workspace.errors.length)
|
|
267
|
-
throw Error('Invalid pnpm workspace configuration');
|
|
268
|
-
const existing = workspace.getIn(['overrides', '@expo/cli>zod']);
|
|
269
|
-
if (existing !== undefined && existing !== D.zod)
|
|
270
|
-
throw Error('Preserve the custom Expo Zod override; reconcile it first.');
|
|
271
|
-
workspace.setIn(['overrides', '@expo/cli>zod'], D.zod);
|
|
272
|
-
e.writes.set('pnpm-workspace.yaml', workspace.toString());
|
|
273
|
-
e.create('apps/mobile/app.json', json({
|
|
274
|
-
expo: {
|
|
275
|
-
name,
|
|
276
|
-
slug: resourceName(name, 'mobile'),
|
|
277
|
-
scheme: resourceName(name, 'mobile'),
|
|
278
|
-
version: '1.0.0',
|
|
279
|
-
userInterfaceStyle: 'automatic',
|
|
280
|
-
plugins: ['expo-secure-store'],
|
|
281
|
-
},
|
|
282
|
-
}));
|
|
283
|
-
e.create('apps/mobile/tsconfig.json', json({
|
|
284
|
-
extends: 'expo/tsconfig.base',
|
|
285
|
-
compilerOptions: { strict: true, baseUrl: '.', paths: { '@/*': ['./*'] } },
|
|
286
|
-
}));
|
|
287
|
-
e.create('apps/mobile/babel.config.js', "module.exports = function(api) {api.cache(true);return {presets:['babel-preset-expo']};};\n");
|
|
288
|
-
e.create('apps/mobile/index.ts', "import './anhedral-entry';\n");
|
|
289
|
-
e.create('apps/mobile/App.tsx', "import { View, Text } from 'react-native';\nexport default function App() { return <View style={{flex:1,alignItems:'center',justifyContent:'center'}}><Text>Your Expo application</Text></View>; }\n");
|
|
290
|
-
e.create('apps/mobile/components/session-controls.tsx', template('mobile-session.tsx.txt'));
|
|
291
|
-
e.create('apps/mobile/lib/auth-client.ts', template('mobile-auth.ts.txt').replaceAll('__SCHEME__', JSON.stringify(resourceName(name, 'mobile'))));
|
|
292
|
-
e.create('apps/mobile/.env.example', '# Public application URL only, never a server secret. Use a device-reachable development origin.\nEXPO_PUBLIC_API_URL=https://your-app.example\n');
|
|
293
|
-
dependency(e, 'apps/api', { '@better-auth/expo': P['@better-auth/expo'] });
|
|
294
|
-
}
|
|
295
|
-
function addNativeUi(e) {
|
|
296
|
-
dependency(e, 'apps/mobile', {
|
|
297
|
-
nativewind: P.nativewind,
|
|
298
|
-
'react-native-css-interop': P['react-native-css-interop'],
|
|
299
|
-
'react-native-reanimated': P['react-native-reanimated'],
|
|
300
|
-
'react-native-worklets': P['react-native-worklets'],
|
|
301
|
-
'react-native-safe-area-context': P['react-native-safe-area-context'],
|
|
302
|
-
'class-variance-authority': P['class-variance-authority'],
|
|
303
|
-
clsx: P.clsx,
|
|
304
|
-
'tailwind-merge': P['tailwind-merge'],
|
|
305
|
-
'tailwindcss-animate': P['tailwindcss-animate'],
|
|
306
|
-
'@rn-primitives/portal': P['@rn-primitives/portal'],
|
|
307
|
-
'@rn-primitives/slot': P['@rn-primitives/slot'],
|
|
308
|
-
});
|
|
309
|
-
e.merge('apps/mobile/package.json', 'devDependencies', { tailwindcss: P.tailwindcss });
|
|
310
|
-
e.create('apps/mobile/components.json', json({
|
|
311
|
-
$schema: 'https://ui.shadcn.com/schema.json',
|
|
312
|
-
style: 'new-york',
|
|
313
|
-
rsc: false,
|
|
314
|
-
tsx: true,
|
|
315
|
-
tailwind: {
|
|
316
|
-
config: 'tailwind.config.js',
|
|
317
|
-
css: 'global.css',
|
|
318
|
-
baseColor: 'neutral',
|
|
319
|
-
cssVariables: true,
|
|
320
|
-
},
|
|
321
|
-
aliases: {
|
|
322
|
-
components: '@/components',
|
|
323
|
-
ui: '@/components/ui',
|
|
324
|
-
utils: '@/lib/utils',
|
|
325
|
-
lib: '@/lib',
|
|
326
|
-
hooks: '@/hooks',
|
|
327
|
-
},
|
|
328
|
-
}));
|
|
329
|
-
for (const file of [
|
|
330
|
-
'global.css',
|
|
331
|
-
'tailwind.config.js',
|
|
332
|
-
'metro.config.js',
|
|
333
|
-
'nativewind-env.d.ts',
|
|
334
|
-
'lib/utils.ts',
|
|
335
|
-
])
|
|
336
|
-
e.create(`apps/mobile/${file}`, template('native-' + file.replaceAll('/', '-') + '.txt'));
|
|
337
|
-
// Dedicated entry: NativeWind/PortalHost integration never replaces the user's App.
|
|
338
|
-
if (e.json('apps/mobile/package.json').main !== 'index.ts')
|
|
339
|
-
throw Error('Preserve the custom Expo entry; reconcile NativeWind/PortalHost setup first.');
|
|
340
|
-
e.set('apps/mobile/package.json', ['main'], 'anhedral-entry.tsx');
|
|
341
|
-
for (const name of ['button', 'text'])
|
|
342
|
-
e.create(`apps/mobile/components/ui/${name}.tsx`, template(`native-${name}.tsx.txt`));
|
|
343
|
-
if (e.read('apps/mobile/App.tsx') === null)
|
|
344
|
-
throw Error('Preserve the custom Expo layout; reconcile the NativeWind root entry first.');
|
|
345
|
-
const babel = 'apps/mobile/babel.config.js';
|
|
346
|
-
const expected = "module.exports = function(api) {api.cache(true);return {presets:['babel-preset-expo']};};\n";
|
|
347
|
-
if (e.read(babel) !== expected)
|
|
348
|
-
throw Error('Preserve edited Expo Babel configuration; reconcile NativeWind first.');
|
|
349
|
-
e.writes.set(babel, "module.exports = function(api) {api.cache(true);return {presets:[['babel-preset-expo',{jsxImportSource:'nativewind'}],'nativewind/babel']};};\n");
|
|
350
|
-
e.create('apps/mobile/.anhedral-ui.json', json({
|
|
351
|
-
schemaVersion: 1,
|
|
352
|
-
platform: 'native',
|
|
353
|
-
catalogRevision: '2026-10-26.1',
|
|
354
|
-
nativeStyling: 'nativewind4',
|
|
355
|
-
sourceOwned: true,
|
|
356
|
-
automaticUpdates: false,
|
|
357
|
-
}));
|
|
358
|
-
e.create('apps/mobile/UPSTREAM.json', json({
|
|
359
|
-
catalogRevision: '2026-10-26.1',
|
|
360
|
-
source: 'https://github.com/founded-labs/react-native-reusables/tree/385834c2196f8a303cbc9057d1ac768f3bde0a3b',
|
|
361
|
-
automaticUpdates: false,
|
|
362
|
-
files: Object.fromEntries(['button', 'text'].map((name) => [
|
|
363
|
-
`components/ui/${name}.tsx`,
|
|
364
|
-
{ sha256: fingerprint(template(`native-${name}.tsx.txt`)) },
|
|
365
|
-
])),
|
|
366
|
-
}));
|
|
367
|
-
for (const name of ['LICENSE.react-native-reusables', 'LICENSE.shadcn'])
|
|
368
|
-
e.create(`apps/mobile/ANHEDRAL_UI_LICENSES/${name}`, readFileSync(new URL(`../assets/ui/${name}`, import.meta.url), 'utf8'));
|
|
369
|
-
}
|
|
370
|
-
function addExtension(e) {
|
|
371
|
-
project(e, 'apps/extension', '@workspace/extension', {
|
|
372
|
-
dev: 'wxt',
|
|
373
|
-
build: 'wxt build',
|
|
374
|
-
zip: 'wxt zip',
|
|
375
|
-
typecheck: 'wxt prepare && tsc --noEmit',
|
|
376
|
-
lint: 'wxt prepare && tsc --noEmit',
|
|
377
|
-
postinstall: 'wxt prepare',
|
|
378
|
-
}, { react: P.react, 'react-dom': P.react }, {
|
|
379
|
-
wxt: P.wxt,
|
|
380
|
-
'@wxt-dev/module-react': P['@wxt-dev/module-react'],
|
|
381
|
-
'@types/react': P['@types/react'],
|
|
382
|
-
'@types/react-dom': P['@types/react-dom'],
|
|
383
|
-
});
|
|
384
|
-
e.create('apps/extension/entrypoints/background.ts', "import {configureCapabilities} from '../anhedral-background';\nexport default defineBackground(()=>{configureCapabilities();});\n");
|
|
385
|
-
e.create('apps/extension/wxt.config.ts', "import {defineConfig} from 'wxt';\nconst origin=process.env.WXT_API_ORIGIN || 'https://your-app.example';\nconst url=new URL(origin);\nif(url.protocol !== 'https:' && !(url.protocol === 'http:' && ['localhost','127.0.0.1'].includes(url.hostname)))throw Error('Choose a secure API origin');\nexport default defineConfig({modules:['@wxt-dev/module-react'], manifest:{name:'Anhedral application extension',permissions:['storage'],host_permissions:[url.origin+'/*']}});\n");
|
|
386
|
-
e.create('apps/extension/tsconfig.json', json({ extends: './.wxt/tsconfig.json', compilerOptions: { strict: true, jsx: 'react-jsx' } }));
|
|
387
|
-
e.create('apps/extension/entrypoints/popup/index.html', '<!doctype html><html><head><meta charset="UTF-8"><title>Application</title></head><body><div id="root"></div><script type="module" src="./main.tsx"></script></body></html>\n');
|
|
388
|
-
e.create('apps/extension/entrypoints/popup/main.tsx', "import {createRoot} from 'react-dom/client';\nimport {App} from '../../components/App';\ncreateRoot(document.getElementById('root')!).render(<App />);\n");
|
|
389
|
-
e.create('apps/extension/components/App.tsx', 'export function App(){return <main><h1>Your application</h1><p>Configure the API origin and an explicit sign-in flow before accessing private data.</p></main>;}\n');
|
|
390
|
-
e.create('apps/extension/.env.example', 'WXT_API_ORIGIN=https://your-app.example\n');
|
|
391
|
-
}
|
|
392
|
-
function addDesktop(e) {
|
|
393
|
-
project(e, 'apps/desktop', '@workspace/desktop', {
|
|
394
|
-
dev: 'cargo run',
|
|
395
|
-
build: 'cargo build',
|
|
396
|
-
typecheck: 'cargo check',
|
|
397
|
-
lint: 'cargo fmt --check',
|
|
398
|
-
test: 'cargo test',
|
|
399
|
-
}, {});
|
|
400
|
-
e.create('apps/desktop/Cargo.toml', '[package]\nname = "anhedral-desktop"\nversion = "0.1.0"\nedition = "2024"\n\n[dependencies]\ngpui = { version = "=0.2.2", features = ["runtime_shaders"] }\n');
|
|
401
|
-
e.create('apps/desktop/src/main.rs', template('desktop.rs.txt'));
|
|
402
|
-
e.create('apps/desktop/.gitignore', '/target/\n');
|
|
403
|
-
e.create('apps/desktop/.env.example', '# Desktop binaries run natively, not on Workers.\nANHEDRAL_API_ORIGIN=https://your-app.example\n');
|
|
404
|
-
}
|
|
405
184
|
export function composeCapabilities(e, installed) {
|
|
185
|
+
composeTanstack(e, installed);
|
|
406
186
|
if (!installed.includes('hono'))
|
|
407
187
|
return;
|
|
408
|
-
if (installed.includes('expo'))
|
|
409
|
-
composeMobile(e, installed);
|
|
410
|
-
if (installed.includes('wxt'))
|
|
411
|
-
e.owned('apps/extension/anhedral-background.ts', installed.includes('side-panel')
|
|
412
|
-
? "import {browser} from 'wxt/browser';\nexport function configureCapabilities(){if(browser.sidePanel)void browser.sidePanel.setPanelBehavior({openPanelOnActionClick:true}).catch(()=>console.error('Side Panel setup failed'));}\n"
|
|
413
|
-
: 'export function configureCapabilities(){}\n');
|
|
414
188
|
const features = [
|
|
415
189
|
['database-auth', 'authRoutes', 'auth'],
|
|
416
190
|
['r2', 'storageRoutes', 'storage'],
|
|
417
191
|
['stripe', 'stripeRoutes', 'stripe'],
|
|
418
192
|
['stripe', 'entitlementRoutes', 'entitlements'],
|
|
419
|
-
['revenuecat', 'revenuecatRoutes', 'revenuecat'],
|
|
420
|
-
['realtime', 'eventRoutes', 'events'],
|
|
421
|
-
['rtc', 'rtcRoutes', 'rtc'],
|
|
422
|
-
['ai', 'aiRoutes', 'ai'],
|
|
423
193
|
];
|
|
424
194
|
const chosen = features.filter(([id]) => installed.includes(id));
|
|
425
195
|
e.owned('apps/api/src/capabilities.ts', "// CLI-owned composition. Add custom routes in index.ts; edited composition is never overwritten.\nimport { Hono } from 'hono';\nimport type { AppEnv } from './environment';\n" +
|
|
@@ -429,17 +199,9 @@ export function composeCapabilities(e, installed) {
|
|
|
429
199
|
'export const capabilities = new Hono<AppEnv>();\n' +
|
|
430
200
|
chosen.map(([, symbol]) => `capabilities.route('/', ${symbol});\n`).join(''));
|
|
431
201
|
if (installed.includes('database-auth'))
|
|
432
|
-
e.owned('apps/api/src/auth-platform.ts',
|
|
433
|
-
? "import { expo } from '@better-auth/expo';\nexport const platformAuthPlugins = () => [expo()];\n"
|
|
434
|
-
: 'export const platformAuthPlugins = () => [];\n');
|
|
202
|
+
e.owned('apps/api/src/auth-platform.ts', 'export const platformAuthPlugins = () => [];\n');
|
|
435
203
|
if (installed.includes('stripe'))
|
|
436
|
-
e.owned('apps/api/src/billing-providers.ts', "import type {AppEnv} from './environment';\nimport {stripeEntitled} from './features/stripe';\n"
|
|
437
|
-
(installed.includes('revenuecat')
|
|
438
|
-
? "import {revenuecatEntitled} from './features/revenuecat';\n"
|
|
439
|
-
: '') +
|
|
440
|
-
"export const billingProviders:Record<string,(env:AppEnv['Bindings'],userId:string)=>Promise<boolean>>={stripe:stripeEntitled" +
|
|
441
|
-
(installed.includes('revenuecat') ? ',revenuecat:revenuecatEntitled' : '') +
|
|
442
|
-
'};\n');
|
|
204
|
+
e.owned('apps/api/src/billing-providers.ts', "import type {AppEnv} from './environment';\nimport {stripeEntitled} from './features/stripe';\nexport const billingProviders:Record<string,(env:AppEnv['Bindings'],userId:string)=>Promise<boolean>>={stripe:stripeEntitled};\n");
|
|
443
205
|
const bindings = [
|
|
444
206
|
'PUBLIC_APP_URL?: string',
|
|
445
207
|
'BETTER_AUTH_SECRET?: string',
|
|
@@ -451,60 +213,11 @@ export function composeCapabilities(e, installed) {
|
|
|
451
213
|
bindings.push('FILES: R2Bucket');
|
|
452
214
|
if (installed.includes('stripe'))
|
|
453
215
|
bindings.push('STRIPE_SECRET_KEY?: string', 'STRIPE_WEBHOOK_SECRET?: string', 'STRIPE_PRICE_ID?: string', 'BILLING_ENVIRONMENT?: string', 'BILLING_PROVIDER?: string');
|
|
454
|
-
if (installed.includes('revenuecat'))
|
|
455
|
-
bindings.push('REVENUECAT_SECRET_KEY?: string', 'REVENUECAT_WEBHOOK_AUTH?: string', 'REVENUECAT_APP_ID?: string', 'REVENUECAT_ENTITLEMENT?: string');
|
|
456
|
-
if (installed.includes('rtc'))
|
|
457
|
-
bindings.push('RTC_APP_ID?: string', 'RTC_APP_SECRET?: string');
|
|
458
|
-
if (installed.includes('ai'))
|
|
459
|
-
bindings.push('AI: Ai', 'AI_MODEL?: string', 'AI_DAILY_LIMIT?: string');
|
|
460
216
|
e.owned('apps/api/src/environment.ts', `import type { CustomBindings, CustomVariables } from './custom-environment';\nexport type AppEnv = { Bindings: CustomBindings & {${bindings.join(';\n')}}; Variables: CustomVariables & {userId:string;fileKey:string} };\n`);
|
|
461
217
|
appendExample(e, 'apps/api/.dev.vars.example', bindings
|
|
462
218
|
.filter((binding) => binding.includes('string'))
|
|
463
219
|
.map((binding) => binding.split('?')[0]));
|
|
464
220
|
}
|
|
465
|
-
function composeMobile(e, installed) {
|
|
466
|
-
const ui = installed.includes('native-ui');
|
|
467
|
-
const billing = installed.includes('revenuecat');
|
|
468
|
-
e.owned('apps/mobile/anhedral-entry.tsx', (ui
|
|
469
|
-
? "import './global.css';\nimport {PortalHost} from '@rn-primitives/portal';\nimport {SafeAreaProvider} from 'react-native-safe-area-context';\n"
|
|
470
|
-
: '') +
|
|
471
|
-
"import {registerRootComponent} from 'expo';\nimport {View} from 'react-native';\nimport App from './App';\nimport {SessionControls} from './components/session-controls';\n" +
|
|
472
|
-
(billing
|
|
473
|
-
? "import {BillingControls} from './components/billing-controls';\nimport {disconnectPurchases} from './lib/purchases';\n"
|
|
474
|
-
: '') +
|
|
475
|
-
'function Root(){return ' +
|
|
476
|
-
(ui ? '<SafeAreaProvider>' : '') +
|
|
477
|
-
'<View style={{flex:1}}><App /><SessionControls' +
|
|
478
|
-
(billing ? ' onSignOut={disconnectPurchases}' : '') +
|
|
479
|
-
'>' +
|
|
480
|
-
(billing ? '<BillingControls/>' : '') +
|
|
481
|
-
'</SessionControls></View>' +
|
|
482
|
-
(ui ? '<PortalHost/></SafeAreaProvider>' : '') +
|
|
483
|
-
';}\nregisterRootComponent(Root);\n');
|
|
484
|
-
e.owned('apps/mobile/components/action-button.tsx', ui
|
|
485
|
-
? "import {Button} from './ui/button';\nimport {Text} from './ui/text';\nexport function ActionButton({label,...props}:{label:string;onPress:()=>void;disabled?:boolean}) {return <Button {...props}><Text>{label}</Text></Button>;}\n"
|
|
486
|
-
: "import {Button} from 'react-native';\nexport function ActionButton({label,...props}:{label:string;onPress:()=>void;disabled?:boolean}) {return <Button title={label} {...props}/>;}\n");
|
|
487
|
-
const file = '.fallowrc.json';
|
|
488
|
-
const current = e.json(file).ignoreDependencies ?? [];
|
|
489
|
-
const peers = ui
|
|
490
|
-
? [
|
|
491
|
-
'babel-preset-expo',
|
|
492
|
-
'react-native-css-interop',
|
|
493
|
-
'react-native-reanimated',
|
|
494
|
-
'react-native-worklets',
|
|
495
|
-
]
|
|
496
|
-
: ['babel-preset-expo'];
|
|
497
|
-
e.set(file, ['ignoreDependencies'], [...new Set([...current, ...peers])]);
|
|
498
|
-
if (ui) {
|
|
499
|
-
const rules = e.json(file).ignoreExports ?? [];
|
|
500
|
-
const rule = {
|
|
501
|
-
file: 'apps/mobile/components/ui/button.tsx',
|
|
502
|
-
exports: ['buttonVariants', 'buttonTextVariants'],
|
|
503
|
-
};
|
|
504
|
-
if (!rules.some((value) => JSON.stringify(value) === JSON.stringify(rule)))
|
|
505
|
-
e.set(file, ['ignoreExports'], [...rules, rule]);
|
|
506
|
-
}
|
|
507
|
-
}
|
|
508
221
|
function appendExample(e, file, keys) {
|
|
509
222
|
const current = e.read(file);
|
|
510
223
|
const source = current ?? '# Copy selected values to the local environment. Never commit secrets.\n';
|
package/dist/cli-arguments.d.ts
CHANGED
|
@@ -11,6 +11,8 @@ export declare function globalArguments(input: readonly string[]): {
|
|
|
11
11
|
quiet: boolean;
|
|
12
12
|
verbose: boolean;
|
|
13
13
|
json: boolean;
|
|
14
|
+
human: boolean;
|
|
15
|
+
nonInteractive: boolean;
|
|
14
16
|
};
|
|
15
17
|
export declare function validateCommand(command: string | undefined, args: readonly string[]): void;
|
|
16
18
|
export declare function inlineArguments(command: string | undefined, args: readonly string[]): string[];
|
package/dist/cli-arguments.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { COMMANDS,
|
|
1
|
+
import { COMMANDS, commandDefinition, commandOptions, commandTopic } from './command-schema.js';
|
|
2
2
|
export class CliArgumentError extends Error {
|
|
3
3
|
nextAction;
|
|
4
4
|
code;
|
|
@@ -35,11 +35,14 @@ export function suggest(input, choices) {
|
|
|
35
35
|
export function globalArguments(input) {
|
|
36
36
|
const args = [];
|
|
37
37
|
let cwd;
|
|
38
|
-
let quiet = false;
|
|
39
|
-
let
|
|
40
|
-
let json = false;
|
|
38
|
+
let quiet = false, verbose = false, json = false, human = false, nonInteractive = false;
|
|
39
|
+
let command;
|
|
41
40
|
for (let index = 0; index < input.length; index++) {
|
|
42
41
|
const arg = input[index];
|
|
42
|
+
if (arg === '--') {
|
|
43
|
+
args.push(...input.slice(index));
|
|
44
|
+
break;
|
|
45
|
+
}
|
|
43
46
|
if (arg === '-c' || arg === '--cwd' || arg.startsWith('--cwd=')) {
|
|
44
47
|
const value = arg.startsWith('--cwd=') ? arg.slice(6) : input[++index];
|
|
45
48
|
if (!value || value.startsWith('-') || cwd !== undefined)
|
|
@@ -48,93 +51,141 @@ export function globalArguments(input) {
|
|
|
48
51
|
}
|
|
49
52
|
else if (arg === '--json')
|
|
50
53
|
json = true;
|
|
54
|
+
else if (arg === '--human')
|
|
55
|
+
human = true;
|
|
51
56
|
else if (arg === '--quiet' || arg === '-q')
|
|
52
57
|
quiet = true;
|
|
53
58
|
else if (arg === '--verbose')
|
|
54
59
|
verbose = true;
|
|
55
|
-
else
|
|
60
|
+
else if (arg === '--non-interactive')
|
|
61
|
+
nonInteractive = true;
|
|
62
|
+
else {
|
|
56
63
|
args.push(arg);
|
|
64
|
+
if (!command && !arg.startsWith('-'))
|
|
65
|
+
command = arg;
|
|
66
|
+
const option = commandOptions(command).find((entry) => entry.flag === arg || entry.aliases?.includes(arg));
|
|
67
|
+
if (option?.arity && input[index + 1] !== undefined && !input[index + 1].startsWith('-'))
|
|
68
|
+
args.push(input[++index]);
|
|
69
|
+
}
|
|
57
70
|
}
|
|
58
|
-
|
|
71
|
+
if (json && human)
|
|
72
|
+
throw new CliArgumentError('Choose --json or --human.', 'Run anhedral --help.');
|
|
73
|
+
return { args, cwd, quiet, verbose, json, human, nonInteractive };
|
|
59
74
|
}
|
|
60
|
-
|
|
61
|
-
if (!command || ['--help', '-h', '--version', '-v', 'help'].includes(command))
|
|
62
|
-
return;
|
|
75
|
+
function definitionFor(command) {
|
|
63
76
|
const definition = commandDefinition(command);
|
|
64
77
|
if (!definition) {
|
|
65
78
|
const recommendation = suggest(command, [...Object.keys(COMMANDS), 'help']);
|
|
66
79
|
const name = /^[a-z-]{1,32}$/.test(command) ? `: ${command}` : '';
|
|
67
80
|
throw new CliArgumentError(`Unknown command${name}.${recommendation ? ` Did you mean ${recommendation}?` : ''}`, 'Run anhedral --help.', 'UNKNOWN_COMMAND');
|
|
68
81
|
}
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
82
|
+
return definition;
|
|
83
|
+
}
|
|
84
|
+
function collectArguments(command, input) {
|
|
85
|
+
const definitions = commandOptions(command);
|
|
86
|
+
const flags = definitions.flatMap((option) => [option.flag, ...(option.aliases ?? [])]);
|
|
87
|
+
const positional = [];
|
|
88
|
+
const options = new Map();
|
|
89
|
+
let literal = false;
|
|
90
|
+
for (let index = 0; index < input.length; index++) {
|
|
91
|
+
const argument = input[index];
|
|
92
|
+
if (!literal && argument === '--') {
|
|
93
|
+
literal = true;
|
|
75
94
|
continue;
|
|
95
|
+
}
|
|
96
|
+
if (literal || !argument.startsWith('-')) {
|
|
97
|
+
positional.push(argument);
|
|
98
|
+
continue;
|
|
99
|
+
}
|
|
76
100
|
const separator = argument.indexOf('=');
|
|
77
101
|
const flag = separator < 0 ? argument : argument.slice(0, separator);
|
|
78
|
-
const option =
|
|
102
|
+
const option = definitions.find((entry) => entry.flag === flag || entry.aliases?.includes(flag));
|
|
79
103
|
if (!option) {
|
|
80
104
|
const recommendation = suggest(flag, flags);
|
|
81
105
|
const display = /^--?[a-z-]{1,64}$/.test(flag) ? `: ${flag}` : '';
|
|
82
106
|
throw new CliArgumentError(`Unknown ${command} option${display}.${recommendation ? ` Did you mean ${recommendation}?` : ''}`, `Run anhedral ${command} --help.`);
|
|
83
107
|
}
|
|
84
|
-
if (
|
|
108
|
+
if (options.has(option.flag) && !option.repeatable)
|
|
85
109
|
throw new CliArgumentError(`Specify ${option.flag} once.`, `Run anhedral ${command} --help.`);
|
|
86
|
-
seen.add(option.flag);
|
|
87
110
|
if (separator >= 0 && !option.arity)
|
|
88
111
|
throw new CliArgumentError('This option does not accept an inline value.', `Run anhedral ${command} --help.`);
|
|
112
|
+
const values = options.get(option.flag) ?? [];
|
|
89
113
|
if (option.arity) {
|
|
90
|
-
const value = separator >= 0 ? argument.slice(separator + 1) :
|
|
114
|
+
const value = separator >= 0 ? argument.slice(separator + 1) : input[index + 1];
|
|
91
115
|
if (!value || value.startsWith('-')) {
|
|
92
116
|
if (option.arity === 'required' || separator >= 0)
|
|
93
117
|
throw new CliArgumentError(`Supply a value for ${option.flag}.`, `Run anhedral ${command} --help.`);
|
|
94
118
|
}
|
|
95
|
-
else
|
|
96
|
-
|
|
119
|
+
else {
|
|
120
|
+
if (option.choices && !option.choices.includes(value))
|
|
121
|
+
throw new CliArgumentError(`Choose ${option.choices.join(', ')} for ${option.flag}.`, `Run anhedral ${command} --help.`);
|
|
122
|
+
values.push(value);
|
|
123
|
+
if (separator < 0)
|
|
124
|
+
index++;
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
options.set(option.flag, values);
|
|
128
|
+
}
|
|
129
|
+
return { positional, options };
|
|
130
|
+
}
|
|
131
|
+
export function validateCommand(command, args) {
|
|
132
|
+
if (!command || ['--help', '-h', '--version', '-v', 'help'].includes(command))
|
|
133
|
+
return;
|
|
134
|
+
const definition = definitionFor(command);
|
|
135
|
+
const parsed = collectArguments(command, args);
|
|
136
|
+
let topic = [command], selected = definition, positional = parsed.positional;
|
|
137
|
+
while (selected.children) {
|
|
138
|
+
const child = positional[0];
|
|
139
|
+
if (!child || !Object.hasOwn(selected.children, child)) {
|
|
140
|
+
const choices = Object.keys(selected.children), recommendation = child ? suggest(child, choices) : undefined;
|
|
141
|
+
throw new CliArgumentError(`Choose ${topic.join(' ')} ${choices.join(', ')}.${recommendation ? ` Did you mean ${recommendation}?` : ''}`, `Run anhedral ${topic.join(' ')} --help.`);
|
|
97
142
|
}
|
|
143
|
+
topic = [...topic, child];
|
|
144
|
+
selected = commandTopic(topic);
|
|
145
|
+
positional = positional.slice(1);
|
|
146
|
+
}
|
|
147
|
+
const shape = selected.positional;
|
|
148
|
+
if (positional.length < (shape?.min ?? 0) || positional.length > (shape?.max ?? 0))
|
|
149
|
+
throw new CliArgumentError(`Expected ${shape?.name ?? 'no extra arguments'} for ${topic.join(' ')}.`, `Run anhedral ${topic.join(' ')} --help.`);
|
|
150
|
+
if (shape?.choices && positional.some((value) => !shape.choices.includes(value)))
|
|
151
|
+
throw new CliArgumentError(`Choose ${shape.choices.join(', ')} for ${shape.name}.`, `Run anhedral ${topic.join(' ')} --help.`);
|
|
152
|
+
for (const group of [
|
|
153
|
+
...(definition.conflicts ?? []),
|
|
154
|
+
...(selected === definition ? [] : (selected.conflicts ?? [])),
|
|
155
|
+
['--json', '--human'],
|
|
156
|
+
]) {
|
|
157
|
+
const used = group.filter((flag) => parsed.options.has(flag));
|
|
158
|
+
if (used.length > 1)
|
|
159
|
+
throw new CliArgumentError(`Choose one of ${group.join(', ')}.`, `Run anhedral ${topic.join(' ')} --help.`);
|
|
98
160
|
}
|
|
99
161
|
}
|
|
100
162
|
export function inlineArguments(command, args) {
|
|
101
|
-
const
|
|
102
|
-
const flags = new Set(definition?.options
|
|
163
|
+
const flags = new Set(commandOptions(command)
|
|
103
164
|
.filter((option) => option.arity)
|
|
104
|
-
.flatMap((option) => [option.flag, ...(option.aliases ?? [])])
|
|
105
|
-
|
|
165
|
+
.flatMap((option) => [option.flag, ...(option.aliases ?? [])]));
|
|
166
|
+
const result = [];
|
|
167
|
+
for (let index = 0; index < args.length; index++) {
|
|
168
|
+
const argument = args[index];
|
|
169
|
+
if (argument === '--') {
|
|
170
|
+
result.push(...args.slice(index));
|
|
171
|
+
return result;
|
|
172
|
+
}
|
|
106
173
|
const separator = argument.indexOf('=');
|
|
107
|
-
if (separator < 0 || !flags.has(argument.slice(0, separator)))
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
174
|
+
if (separator < 0 || !flags.has(argument.slice(0, separator))) {
|
|
175
|
+
result.push(argument);
|
|
176
|
+
continue;
|
|
177
|
+
}
|
|
178
|
+
const flag = argument.slice(0, separator), value = argument.slice(separator + 1);
|
|
111
179
|
if (!value || value.startsWith('-'))
|
|
112
180
|
throw new CliArgumentError(`Supply a value for ${flag}.`, `Run anhedral ${command} --help.`);
|
|
113
|
-
|
|
114
|
-
}
|
|
181
|
+
result.push(flag, value);
|
|
182
|
+
}
|
|
183
|
+
return result;
|
|
115
184
|
}
|
|
116
185
|
/** Collect validated options using the same arity and alias metadata as help. */
|
|
117
186
|
export function commandArguments(command, input) {
|
|
118
187
|
validateCommand(command, input);
|
|
119
|
-
const
|
|
120
|
-
const definitions = [...(commandDefinition(command)?.options ?? []), ...GLOBAL_OPTIONS];
|
|
121
|
-
const positional = [];
|
|
122
|
-
const options = new Map();
|
|
123
|
-
for (let index = 0; index < args.length; index++) {
|
|
124
|
-
const argument = args[index];
|
|
125
|
-
const option = definitions.find((entry) => entry.flag === argument || entry.aliases?.includes(argument));
|
|
126
|
-
if (!option) {
|
|
127
|
-
positional.push(argument);
|
|
128
|
-
continue;
|
|
129
|
-
}
|
|
130
|
-
const values = options.get(option.flag) ?? [];
|
|
131
|
-
const next = args[index + 1];
|
|
132
|
-
if (option.arity && next && !next.startsWith('-')) {
|
|
133
|
-
values.push(next);
|
|
134
|
-
index++;
|
|
135
|
-
}
|
|
136
|
-
options.set(option.flag, values);
|
|
137
|
-
}
|
|
188
|
+
const { positional, options } = collectArguments(command, input);
|
|
138
189
|
return {
|
|
139
190
|
positional,
|
|
140
191
|
has: (flag) => options.has(flag),
|
package/dist/cli-commands.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import type
|
|
1
|
+
import { type OutputOptions } from './cli-output.js';
|
|
2
2
|
export declare function runCommand(command: string, args: string[], output: OutputOptions): Promise<void>;
|
package/dist/cli-commands.js
CHANGED
|
@@ -1,20 +1,46 @@
|
|
|
1
|
+
import { runPlatformCommand } from './platform-command.js';
|
|
1
2
|
import { runCapabilityCommand } from './capability-command.js';
|
|
2
|
-
import {
|
|
3
|
+
import { runAnhedralUiCommand } from './ui-command.js';
|
|
3
4
|
import { commandArgumentError } from './cli-arguments.js';
|
|
4
|
-
import {
|
|
5
|
+
import { createReporter } from './cli-output.js';
|
|
6
|
+
import { scaffoldLaunchProject, parseAnhedralStackOptions } from './launch.js';
|
|
7
|
+
import { completionScript } from './completion.js';
|
|
8
|
+
import { commandArguments } from './cli-arguments.js';
|
|
5
9
|
export async function runCommand(command, args, output) {
|
|
10
|
+
if (command === 'completion') {
|
|
11
|
+
const parsed = commandArguments(command, args);
|
|
12
|
+
const shell = parsed.positional[0];
|
|
13
|
+
const script = completionScript(shell);
|
|
14
|
+
createReporter(output, () => script.trimEnd()).result({ shell, script });
|
|
15
|
+
return;
|
|
16
|
+
}
|
|
17
|
+
if ([
|
|
18
|
+
'login',
|
|
19
|
+
'logout',
|
|
20
|
+
'whoami',
|
|
21
|
+
'projects',
|
|
22
|
+
'link',
|
|
23
|
+
'unlink',
|
|
24
|
+
'source',
|
|
25
|
+
'deploy',
|
|
26
|
+
'env',
|
|
27
|
+
'staging',
|
|
28
|
+
'production',
|
|
29
|
+
'logs',
|
|
30
|
+
].includes(command))
|
|
31
|
+
return runPlatformCommand(command, args, output);
|
|
6
32
|
if (command === 'add' || command === 'stack')
|
|
7
33
|
return runCapabilityCommand(command, args, output);
|
|
8
34
|
if (command === 'ui')
|
|
9
|
-
return
|
|
35
|
+
return runAnhedralUiCommand(args, output);
|
|
10
36
|
if (command !== 'init')
|
|
11
37
|
throw commandArgumentError(command, 'Use init, add, stack or ui. Run anhedral --help.');
|
|
12
38
|
let options;
|
|
13
39
|
try {
|
|
14
|
-
options =
|
|
40
|
+
options = parseAnhedralStackOptions(args);
|
|
15
41
|
}
|
|
16
42
|
catch (error) {
|
|
17
43
|
throw commandArgumentError('init', error instanceof Error ? error.message : String(error));
|
|
18
44
|
}
|
|
19
|
-
await
|
|
45
|
+
await scaffoldLaunchProject(options, undefined, output);
|
|
20
46
|
}
|