anhedral 0.12.0 → 0.15.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 +35 -172
- package/assets/patches/audit-deps.mjs +12 -2
- package/assets/ui/LICENSE.shadcn +21 -0
- package/assets/ui/UPSTREAM.json +33 -0
- package/assets/ui/native/button.tsx +85 -0
- package/assets/ui/native/card.tsx +33 -0
- package/assets/ui/native/dialog.tsx +75 -0
- package/assets/ui/native/input.tsx +27 -0
- package/assets/ui/native/label.tsx +4 -0
- package/assets/ui/native/layout.tsx +26 -0
- package/assets/ui/native/text.tsx +20 -0
- package/assets/ui/native/theme-switcher.tsx +22 -0
- package/assets/ui/theme-storage.ts +25 -0
- package/assets/ui/theme.tsx +66 -0
- package/assets/ui/web/button.tsx +59 -0
- package/assets/ui/web/input.tsx +21 -0
- package/assets/ui/web/label.tsx +19 -0
- package/dist/capabilities.d.ts +5 -5
- package/dist/capabilities.js +3 -21
- package/dist/capability-contract.d.ts +3 -3
- package/dist/capability-contract.js +11 -39
- package/dist/cli-delivery.d.ts +1 -1
- package/dist/cli-delivery.js +5 -65
- package/dist/cli-output.js +3 -3
- package/dist/command-schema.js +35 -80
- package/dist/command.js +9 -11
- package/dist/delivery-evidence.d.ts +1 -1
- package/dist/delivery-evidence.js +7 -36
- package/dist/delivery.d.ts +2 -8
- package/dist/delivery.js +23 -102
- package/dist/dependencies.d.ts +12 -58
- package/dist/dependencies.js +67 -189
- package/dist/index.d.ts +1 -3
- package/dist/index.js +1 -3
- package/dist/inspector-model.d.ts +2 -2
- package/dist/integration-service-readers.d.ts +1 -2
- package/dist/integration-service-readers.js +3 -84
- package/dist/lifecycle-model.d.ts +1 -1
- package/dist/lifecycle-model.js +1 -1
- package/dist/mobile-delivery.d.ts +1 -1
- package/dist/mobile-delivery.js +4 -0
- package/dist/platforms/mobile.d.ts +1 -1
- package/dist/platforms/mobile.js +64 -114
- package/dist/platforms/web.d.ts +3 -0
- package/dist/platforms/web.js +299 -0
- package/dist/project-config.d.ts +1 -1
- package/dist/project-config.js +0 -1
- package/dist/project-inspector.js +5 -36
- package/dist/project-state.d.ts +1 -3
- package/dist/project-state.js +6 -86
- package/dist/provider-auth.js +3 -32
- package/dist/provider-readiness.d.ts +1 -1
- package/dist/provider-readiness.js +5 -24
- package/dist/providers/adapters.js +9 -178
- package/dist/providers/api.d.ts +1 -1
- package/dist/providers/api.js +3 -3
- package/dist/providers/config.js +2 -48
- package/dist/providers/definitions.d.ts +1 -204
- package/dist/providers/definitions.js +0 -85
- package/dist/providers/provision.d.ts +1 -1
- package/dist/providers/receipts.js +1 -11
- package/dist/providers/recovery-verification.js +1 -61
- package/dist/providers/runtime.js +15 -35
- package/dist/providers/state.js +1 -7
- package/dist/provision.d.ts +5 -13
- package/dist/provision.js +4 -80
- package/dist/readiness.d.ts +1 -1
- package/dist/readiness.js +3 -6
- package/dist/registry/add.js +11 -38
- package/dist/registry/bootstrap.d.ts +3 -2
- package/dist/registry/bootstrap.js +4 -13
- package/dist/registry/commands.js +8 -10
- package/dist/registry/context.js +0 -1
- package/dist/registry/options.js +8 -26
- package/dist/registry/resolve.d.ts +3 -2
- package/dist/registry/resolve.js +26 -82
- package/dist/registry/types.d.ts +2 -7
- package/dist/registry/usage.js +2 -2
- package/dist/runtime-policy.d.ts +0 -2
- package/dist/runtime-policy.js +0 -13
- package/dist/scaffold/api.js +10 -2
- package/dist/scaffold/auth.d.ts +1 -2
- package/dist/scaffold/auth.js +57 -116
- package/dist/scaffold/backend.d.ts +2 -0
- package/dist/scaffold/backend.js +39 -0
- package/dist/scaffold/billing-config.d.ts +1 -0
- package/dist/scaffold/billing-config.js +73 -0
- package/dist/scaffold/billing-contracts.d.ts +2 -0
- package/dist/scaffold/billing-contracts.js +48 -0
- package/dist/scaffold/billing-providers.d.ts +1 -0
- package/dist/scaffold/billing-providers.js +249 -0
- package/dist/scaffold/billing-schema.d.ts +1 -0
- package/dist/scaffold/billing-schema.js +34 -0
- package/dist/scaffold/billing-security.d.ts +1 -0
- package/dist/scaffold/billing-security.js +46 -0
- package/dist/scaffold/billing-server.d.ts +1 -0
- package/dist/scaffold/billing-server.js +139 -0
- package/dist/scaffold/billing-store.d.ts +1 -0
- package/dist/scaffold/billing-store.js +72 -0
- package/dist/scaffold/billing.d.ts +2 -0
- package/dist/scaffold/billing.js +208 -0
- package/dist/scaffold/bootstrap.d.ts +2 -3
- package/dist/scaffold/bootstrap.js +37 -43
- package/dist/scaffold/compose.js +2 -12
- package/dist/scaffold/database.d.ts +1 -1
- package/dist/scaffold/database.js +20 -111
- package/dist/scaffold/documentation.d.ts +0 -1
- package/dist/scaffold/documentation.js +22 -82
- package/dist/scaffold/expo-auth.d.ts +3 -0
- package/dist/scaffold/expo-auth.js +203 -0
- package/dist/scaffold/expo-billing.d.ts +3 -0
- package/dist/scaffold/expo-billing.js +257 -0
- package/dist/scaffold/expo-runtime.d.ts +3 -0
- package/dist/scaffold/expo-runtime.js +43 -0
- package/dist/scaffold/integrations.d.ts +1 -2
- package/dist/scaffold/integrations.js +9 -5
- package/dist/scaffold/managed-email.d.ts +3 -0
- package/dist/scaffold/managed-email.js +47 -0
- package/dist/scaffold/native-ui.d.ts +2 -0
- package/dist/scaffold/native-ui.js +69 -0
- package/dist/scaffold/password-reset.d.ts +1 -0
- package/dist/scaffold/password-reset.js +99 -0
- package/dist/scaffold/private-files.d.ts +2 -0
- package/dist/scaffold/private-files.js +78 -0
- package/dist/scaffold/stack-documentation.d.ts +0 -1
- package/dist/scaffold/stack-documentation.js +3 -49
- package/dist/scaffold/styling.d.ts +1 -1
- package/dist/scaffold/styling.js +20 -28
- package/dist/scaffold/web-billing.d.ts +2 -0
- package/dist/scaffold/web-billing.js +48 -0
- package/dist/scaffold/workspace.js +53 -189
- package/dist/service-deletion.js +1 -1
- package/dist/service-descriptor.js +5 -12
- package/dist/service-model.d.ts +1 -1
- package/dist/service-operations.js +2 -32
- package/dist/service-readers.js +1 -32
- package/dist/services-command.d.ts +1 -1
- package/dist/services-command.js +3 -9
- package/dist/ship.d.ts +3 -316
- package/dist/ship.js +13 -143
- package/dist/stack-registry.d.ts +2 -43
- package/dist/stack-registry.js +80 -308
- package/dist/standard.js +7 -14
- package/dist/version.d.ts +1 -1
- package/dist/version.js +1 -1
- package/docs/anhedral-stack.md +23 -0
- package/docs/assets/anhedral-stack-light.png +0 -0
- package/docs/assets/anhedral-stack.png +0 -0
- package/docs/software-factory.md +25 -499
- package/docs/stack-standard.md +48 -226
- package/docs/verification.md +433 -0
- package/package.json +22 -21
- package/dist/neon-service-data.d.ts +0 -8
- package/dist/neon-service-data.js +0 -117
- package/dist/platforms/desktop.d.ts +0 -2
- package/dist/platforms/desktop.js +0 -415
- package/dist/platforms/extension.d.ts +0 -2
- package/dist/platforms/extension.js +0 -328
- package/dist/scaffold/lint.d.ts +0 -4
- package/dist/scaffold/lint.js +0 -56
- package/dist/scaffold/neon-realtime.d.ts +0 -2
- package/dist/scaffold/neon-realtime.js +0 -97
- package/dist/scaffold/services.d.ts +0 -5
- package/dist/scaffold/services.js +0 -108
- package/dist/scaffold/stream.d.ts +0 -2
- package/dist/scaffold/stream.js +0 -114
- package/dist/scaffold/void.d.ts +0 -4
- package/dist/scaffold/void.js +0 -256
- package/dist/scaffold/web.d.ts +0 -2
- package/dist/scaffold/web.js +0 -128
- package/dist/vercel-project.d.ts +0 -101
- package/dist/vercel-project.js +0 -305
- package/dist/vercel.d.ts +0 -67
- package/dist/vercel.js +0 -581
- package/dist/vinext.d.ts +0 -2
- package/dist/vinext.js +0 -86
- package/dist/void-execution.d.ts +0 -10
- package/dist/void-execution.js +0 -94
- package/dist/void-migrations.d.ts +0 -6
- package/dist/void-migrations.js +0 -110
- package/dist/void-state.d.ts +0 -16
- package/dist/void-state.js +0 -65
- package/dist/void.d.ts +0 -3
- package/dist/void.js +0 -5
|
@@ -1,117 +0,0 @@
|
|
|
1
|
-
import { neon } from '@neondatabase/serverless';
|
|
2
|
-
import { setting } from './providers/config.js';
|
|
3
|
-
import { record } from './service-readers.js';
|
|
4
|
-
import { inspectIntegrationResource, } from './integration-service-readers.js';
|
|
5
|
-
const identifier = (value) => {
|
|
6
|
-
if (!/^[a-zA-Z_][a-zA-Z0-9_]{0,127}$/.test(value))
|
|
7
|
-
throw new Error('Unsupported database identifier.');
|
|
8
|
-
return `"${value}"`;
|
|
9
|
-
};
|
|
10
|
-
const sensitive = /password|secret|token|email|phone|address|authorization|cookie|session|private|credential/i;
|
|
11
|
-
export async function neonReadConnection(service, api, env = process.env, createClient = neon) {
|
|
12
|
-
if (service.provider !== 'neon')
|
|
13
|
-
throw new Error('Choose the selected Neon project.');
|
|
14
|
-
const project = await inspectIntegrationResource(service, api);
|
|
15
|
-
const connection = env[`ANHEDRAL_NEON_READONLY_URL_${String(project.id)
|
|
16
|
-
.replace(/[^a-zA-Z0-9]/g, '_')
|
|
17
|
-
.toUpperCase()}`] ?? env.ANHEDRAL_NEON_READONLY_URL;
|
|
18
|
-
if (!connection)
|
|
19
|
-
throw new Error('Provide ANHEDRAL_NEON_READONLY_URL for a restricted read-only role.');
|
|
20
|
-
let url;
|
|
21
|
-
try {
|
|
22
|
-
url = new URL(connection);
|
|
23
|
-
}
|
|
24
|
-
catch {
|
|
25
|
-
throw new Error('Invalid read-only database connection.');
|
|
26
|
-
}
|
|
27
|
-
if (!['postgres:', 'postgresql:'].includes(url.protocol) ||
|
|
28
|
-
!url.hostname.endsWith('.neon.tech') ||
|
|
29
|
-
!url.username ||
|
|
30
|
-
!url.password ||
|
|
31
|
-
(url.port && url.port !== '5432') ||
|
|
32
|
-
decodeURIComponent(url.pathname.slice(1)) !== setting(service.settings, 'database'))
|
|
33
|
-
throw new Error('Read-only database connection does not match selected configuration.');
|
|
34
|
-
const endpoints = record(await api(`/api/v2/projects/${project.id}/endpoints`)).endpoints;
|
|
35
|
-
if (!Array.isArray(endpoints) ||
|
|
36
|
-
endpoints.length > 100 ||
|
|
37
|
-
!endpoints.some((endpoint) => record(endpoint).host === url.hostname.replace(/-pooler\./, '.')))
|
|
38
|
-
throw new Error('Database endpoint does not belong to the selected Neon project.');
|
|
39
|
-
const sql = createClient(connection);
|
|
40
|
-
return async (query, params = []) => {
|
|
41
|
-
try {
|
|
42
|
-
const result = await sql.transaction([
|
|
43
|
-
sql.query("SELECT set_config('statement_timeout','5000',true)"),
|
|
44
|
-
sql.query("SELECT current_setting('transaction_read_only') = 'on' AS read_only, (SELECT rolsuper OR rolcreatedb OR rolcreaterole FROM pg_roles WHERE rolname = current_user) AS privileged, EXISTS(SELECT 1 FROM pg_class c JOIN pg_namespace n ON n.oid=c.relnamespace WHERE n.nspname='public' AND c.relkind IN ('r','p') AND has_table_privilege(current_user,c.oid,'INSERT,UPDATE,DELETE,TRUNCATE')) AS writable"),
|
|
45
|
-
sql.query(query, params),
|
|
46
|
-
], {
|
|
47
|
-
readOnly: true,
|
|
48
|
-
isolationLevel: 'RepeatableRead',
|
|
49
|
-
fetchOptions: { signal: AbortSignal.timeout(10000), redirect: 'error' },
|
|
50
|
-
});
|
|
51
|
-
const role = result[1]?.[0];
|
|
52
|
-
if (role?.read_only !== true || role.privileged !== false || role.writable !== false)
|
|
53
|
-
throw new Error('Restricted read-only role required.');
|
|
54
|
-
if (!Array.isArray(result[2]) || result[2].length > 1001)
|
|
55
|
-
throw new Error('Database response exceeded limits.');
|
|
56
|
-
return result[2].map(record);
|
|
57
|
-
}
|
|
58
|
-
catch {
|
|
59
|
-
throw new Error('Neon read failed. Check the selected endpoint, restricted role, read permissions and query limits.');
|
|
60
|
-
}
|
|
61
|
-
};
|
|
62
|
-
}
|
|
63
|
-
export async function listNeonTables(read) {
|
|
64
|
-
const rows = await read("SELECT table_name AS name FROM information_schema.tables WHERE table_schema='public' AND table_type='BASE TABLE' ORDER BY table_name LIMIT 1001");
|
|
65
|
-
if (rows.length > 1000)
|
|
66
|
-
throw new Error('Database schema exceeds its table limit.');
|
|
67
|
-
return rows.map((row) => {
|
|
68
|
-
if (typeof row.name !== 'string')
|
|
69
|
-
throw new Error('Invalid database table.');
|
|
70
|
-
identifier(row.name);
|
|
71
|
-
return row.name;
|
|
72
|
-
});
|
|
73
|
-
}
|
|
74
|
-
export async function browseNeonData(read, table, offset = 0) {
|
|
75
|
-
identifier(table);
|
|
76
|
-
if (!Number.isSafeInteger(offset) ||
|
|
77
|
-
offset < 0 ||
|
|
78
|
-
offset > 10000 ||
|
|
79
|
-
!(await listNeonTables(read)).includes(table))
|
|
80
|
-
throw new Error('Choose a bounded existing table page.');
|
|
81
|
-
const fields = await read("SELECT column_name AS name FROM information_schema.columns WHERE table_schema='public' AND table_name=$1 ORDER BY ordinal_position LIMIT 51", [table]);
|
|
82
|
-
if (fields.length > 50 || !fields.length)
|
|
83
|
-
throw new Error('Table exceeds its supported column limit.');
|
|
84
|
-
const columns = fields.map((row) => {
|
|
85
|
-
if (typeof row.name !== 'string')
|
|
86
|
-
throw new Error('Invalid database column.');
|
|
87
|
-
identifier(row.name);
|
|
88
|
-
return row.name;
|
|
89
|
-
});
|
|
90
|
-
const projection = columns
|
|
91
|
-
.map((column) => sensitive.test(column)
|
|
92
|
-
? `'[masked]'::text AS ${identifier(column)}`
|
|
93
|
-
: `left(${identifier(column)}::text,1000) AS ${identifier(column)}`)
|
|
94
|
-
.join(', ');
|
|
95
|
-
const rows = await read(`SELECT ${projection} FROM public.${identifier(table)} ORDER BY ${columns.map((_, index) => index + 1).join(', ')} LIMIT $1 OFFSET $2`, [26, offset]);
|
|
96
|
-
let masked = columns.some((column) => sensitive.test(column));
|
|
97
|
-
const outputRows = rows.slice(0, 25).map((row) => columns.map((column) => {
|
|
98
|
-
const value = row[column];
|
|
99
|
-
if (value === null)
|
|
100
|
-
return null;
|
|
101
|
-
if (typeof value !== 'string')
|
|
102
|
-
throw new Error('Unsupported database value.');
|
|
103
|
-
if (/^(?:sk[-_]|rk[-_]|whsec[-_]|Bearer )/i.test(value)) {
|
|
104
|
-
masked = true;
|
|
105
|
-
return '[masked]';
|
|
106
|
-
}
|
|
107
|
-
return value.slice(0, 1000);
|
|
108
|
-
}));
|
|
109
|
-
return {
|
|
110
|
-
fetchedAt: new Date().toISOString(),
|
|
111
|
-
columns,
|
|
112
|
-
rows: outputRows,
|
|
113
|
-
offset,
|
|
114
|
-
hasMore: rows.length > 25,
|
|
115
|
-
masked,
|
|
116
|
-
};
|
|
117
|
-
}
|
|
@@ -1,415 +0,0 @@
|
|
|
1
|
-
import path from 'node:path';
|
|
2
|
-
import { writeReactLintConfig } from './lint.js';
|
|
3
|
-
import { writeFile } from '../util.js';
|
|
4
|
-
import { DESKTOP_DEPENDENCIES } from '../dependencies.js';
|
|
5
|
-
import { childPackageName, htmlText, identifierSegment, jsString } from '../render.js';
|
|
6
|
-
export async function scaffoldElectron({ root, options }) {
|
|
7
|
-
const projectName = options.name;
|
|
8
|
-
const displayName = options.name;
|
|
9
|
-
const dir = path.join(root, 'apps/desktop');
|
|
10
|
-
writePackageJson(dir, projectName);
|
|
11
|
-
writeReactLintConfig(dir);
|
|
12
|
-
writeTsConfig(dir);
|
|
13
|
-
writeViteConfig(dir);
|
|
14
|
-
writePostcssConfig(dir);
|
|
15
|
-
writeDevScript(dir);
|
|
16
|
-
writeShadcnConfig(dir);
|
|
17
|
-
writeEnvExample(dir);
|
|
18
|
-
writeSourceFiles(dir, displayName);
|
|
19
|
-
}
|
|
20
|
-
function writePackageJson(dir, projectName) {
|
|
21
|
-
writeFile(path.join(dir, 'package.json'), JSON.stringify({
|
|
22
|
-
name: childPackageName(projectName, 'desktop'),
|
|
23
|
-
version: '0.1.0',
|
|
24
|
-
private: true,
|
|
25
|
-
type: 'module',
|
|
26
|
-
main: 'dist/main/main.js',
|
|
27
|
-
scripts: {
|
|
28
|
-
dev: 'tsc -p tsconfig.main.json && node scripts/dev.mjs',
|
|
29
|
-
build: 'tsc --noEmit && tsc -p tsconfig.main.json && vite build',
|
|
30
|
-
typecheck: 'tsc --noEmit && tsc -p tsconfig.main.json --noEmit',
|
|
31
|
-
lint: 'eslint src --max-warnings 0',
|
|
32
|
-
'build:mac': 'pnpm build && electron-builder --mac',
|
|
33
|
-
'build:win': 'pnpm build && electron-builder --win',
|
|
34
|
-
'build:linux': 'pnpm build && electron-builder --linux',
|
|
35
|
-
package: 'pnpm build && electron-builder',
|
|
36
|
-
},
|
|
37
|
-
build: {
|
|
38
|
-
appId: `dev.anhedral.${identifierSegment(projectName)}`,
|
|
39
|
-
productName: projectName,
|
|
40
|
-
directories: {
|
|
41
|
-
output: 'release',
|
|
42
|
-
},
|
|
43
|
-
files: ['dist/**/*', 'package.json'],
|
|
44
|
-
mac: {
|
|
45
|
-
target: ['dmg', 'zip'],
|
|
46
|
-
},
|
|
47
|
-
win: {
|
|
48
|
-
target: ['nsis', 'zip'],
|
|
49
|
-
},
|
|
50
|
-
linux: {
|
|
51
|
-
executableName: identifierSegment(projectName),
|
|
52
|
-
target: ['AppImage', 'deb'],
|
|
53
|
-
},
|
|
54
|
-
},
|
|
55
|
-
dependencies: DESKTOP_DEPENDENCIES.dependencies,
|
|
56
|
-
devDependencies: {
|
|
57
|
-
...DESKTOP_DEPENDENCIES.devDependencies,
|
|
58
|
-
'@workspace/eslint-config': 'workspace:*',
|
|
59
|
-
},
|
|
60
|
-
}, null, 2) + '\n');
|
|
61
|
-
}
|
|
62
|
-
function writeTsConfig(dir) {
|
|
63
|
-
writeFile(path.join(dir, 'tsconfig.json'), JSON.stringify({
|
|
64
|
-
compilerOptions: {
|
|
65
|
-
target: 'ES2022',
|
|
66
|
-
lib: ['ES2022', 'DOM'],
|
|
67
|
-
module: 'ESNext',
|
|
68
|
-
moduleResolution: 'Bundler',
|
|
69
|
-
jsx: 'react-jsx',
|
|
70
|
-
strict: true,
|
|
71
|
-
skipLibCheck: true,
|
|
72
|
-
esModuleInterop: true,
|
|
73
|
-
noEmit: true,
|
|
74
|
-
types: ['node', 'vite/client'],
|
|
75
|
-
paths: { '@/*': ['./src/renderer/*'] },
|
|
76
|
-
},
|
|
77
|
-
include: ['src/renderer/**/*', 'vite.config.ts'],
|
|
78
|
-
}, null, 2) + '\n');
|
|
79
|
-
writeFile(path.join(dir, 'tsconfig.main.json'), JSON.stringify({
|
|
80
|
-
compilerOptions: {
|
|
81
|
-
target: 'ES2022',
|
|
82
|
-
module: 'NodeNext',
|
|
83
|
-
moduleResolution: 'NodeNext',
|
|
84
|
-
strict: true,
|
|
85
|
-
skipLibCheck: true,
|
|
86
|
-
esModuleInterop: true,
|
|
87
|
-
outDir: 'dist/main',
|
|
88
|
-
rootDir: 'src/main',
|
|
89
|
-
types: ['node'],
|
|
90
|
-
},
|
|
91
|
-
include: ['src/main/**/*'],
|
|
92
|
-
}, null, 2) + '\n');
|
|
93
|
-
}
|
|
94
|
-
function writeViteConfig(dir) {
|
|
95
|
-
writeFile(path.join(dir, 'vite.config.ts'), `import { defineConfig } from 'vite';
|
|
96
|
-
import react from '@vitejs/plugin-react';
|
|
97
|
-
import path from 'node:path';
|
|
98
|
-
|
|
99
|
-
export default defineConfig({
|
|
100
|
-
base: './',
|
|
101
|
-
plugins: [react()],
|
|
102
|
-
resolve: {
|
|
103
|
-
alias: {
|
|
104
|
-
'@': path.resolve(__dirname, 'src/renderer'),
|
|
105
|
-
},
|
|
106
|
-
},
|
|
107
|
-
build: {
|
|
108
|
-
outDir: 'dist/renderer',
|
|
109
|
-
emptyOutDir: true,
|
|
110
|
-
},
|
|
111
|
-
});
|
|
112
|
-
`);
|
|
113
|
-
}
|
|
114
|
-
function writePostcssConfig(dir) {
|
|
115
|
-
writeFile(path.join(dir, 'postcss.config.mjs'), `const config = {
|
|
116
|
-
plugins: {
|
|
117
|
-
'@tailwindcss/postcss': {},
|
|
118
|
-
},
|
|
119
|
-
};
|
|
120
|
-
|
|
121
|
-
export default config;
|
|
122
|
-
`);
|
|
123
|
-
}
|
|
124
|
-
function writeDevScript(dir) {
|
|
125
|
-
writeFile(path.join(dir, 'scripts/dev.mjs'), `import { spawn } from 'node:child_process';
|
|
126
|
-
import { once } from 'node:events';
|
|
127
|
-
|
|
128
|
-
const host = '127.0.0.1';
|
|
129
|
-
const port = '5173';
|
|
130
|
-
const devServerUrl = 'http://' + host + ':' + port;
|
|
131
|
-
const viteCommand = process.platform === 'win32' ? 'vite.cmd' : 'vite';
|
|
132
|
-
const electronCommand = process.platform === 'win32' ? 'electron.cmd' : 'electron';
|
|
133
|
-
|
|
134
|
-
function start(command, args, options = {}) {
|
|
135
|
-
const invocation = process.platform === 'win32'
|
|
136
|
-
? {
|
|
137
|
-
command: process.env.ComSpec || 'cmd.exe',
|
|
138
|
-
args: ['/d', '/s', '/c', 'call', command, ...args],
|
|
139
|
-
}
|
|
140
|
-
: { command, args };
|
|
141
|
-
return spawn(invocation.command, invocation.args, {
|
|
142
|
-
cwd: process.cwd(),
|
|
143
|
-
stdio: 'inherit',
|
|
144
|
-
...options,
|
|
145
|
-
});
|
|
146
|
-
}
|
|
147
|
-
|
|
148
|
-
function stop(child) {
|
|
149
|
-
if (child && child.exitCode === null && !child.killed) child.kill('SIGTERM');
|
|
150
|
-
}
|
|
151
|
-
|
|
152
|
-
async function isServerReady(url) {
|
|
153
|
-
try { return (await fetch(url)).ok; }
|
|
154
|
-
catch { return false; }
|
|
155
|
-
}
|
|
156
|
-
|
|
157
|
-
async function waitForServer(server, url, timeoutMs = 30_000) {
|
|
158
|
-
const deadline = Date.now() + timeoutMs;
|
|
159
|
-
while (Date.now() < deadline) {
|
|
160
|
-
if (server.exitCode !== null) throw new Error('Vite exited before the dev server was ready.');
|
|
161
|
-
if (await isServerReady(url)) return;
|
|
162
|
-
await new Promise((resolve) => setTimeout(resolve, 150));
|
|
163
|
-
}
|
|
164
|
-
throw new Error('Timed out waiting for Vite at ' + url + '.');
|
|
165
|
-
}
|
|
166
|
-
|
|
167
|
-
const vite = start(viteCommand, ['--host', host, '--port', port, '--strictPort']);
|
|
168
|
-
let electron;
|
|
169
|
-
let shuttingDown = false;
|
|
170
|
-
|
|
171
|
-
for (const signal of ['SIGINT', 'SIGTERM']) {
|
|
172
|
-
process.once(signal, () => {
|
|
173
|
-
shuttingDown = true;
|
|
174
|
-
stop(electron);
|
|
175
|
-
stop(vite);
|
|
176
|
-
});
|
|
177
|
-
}
|
|
178
|
-
|
|
179
|
-
try {
|
|
180
|
-
await waitForServer(vite, devServerUrl);
|
|
181
|
-
electron = start(electronCommand, ['.'], {
|
|
182
|
-
env: { ...process.env, VITE_DEV_SERVER_URL: devServerUrl },
|
|
183
|
-
});
|
|
184
|
-
vite.once('exit', (code) => {
|
|
185
|
-
if (!shuttingDown) {
|
|
186
|
-
console.error('Vite exited while Electron was running.');
|
|
187
|
-
process.exitCode = code ?? 1;
|
|
188
|
-
stop(electron);
|
|
189
|
-
}
|
|
190
|
-
});
|
|
191
|
-
const [code] = await once(electron, 'exit');
|
|
192
|
-
if (process.exitCode === undefined) process.exitCode = typeof code === 'number' ? code : 1;
|
|
193
|
-
} catch (error) {
|
|
194
|
-
console.error(error instanceof Error ? error.message : error);
|
|
195
|
-
process.exitCode = 1;
|
|
196
|
-
} finally {
|
|
197
|
-
shuttingDown = true;
|
|
198
|
-
stop(electron);
|
|
199
|
-
stop(vite);
|
|
200
|
-
}
|
|
201
|
-
`);
|
|
202
|
-
}
|
|
203
|
-
function writeShadcnConfig(dir) {
|
|
204
|
-
writeFile(path.join(dir, 'components.json'), JSON.stringify({
|
|
205
|
-
$schema: 'https://ui.shadcn.com/schema.json',
|
|
206
|
-
style: 'new-york',
|
|
207
|
-
rsc: false,
|
|
208
|
-
tsx: true,
|
|
209
|
-
tailwind: {
|
|
210
|
-
config: '',
|
|
211
|
-
css: 'src/renderer/styles.css',
|
|
212
|
-
baseColor: 'neutral',
|
|
213
|
-
cssVariables: true,
|
|
214
|
-
prefix: '',
|
|
215
|
-
},
|
|
216
|
-
aliases: {
|
|
217
|
-
components: '@/components',
|
|
218
|
-
utils: '@/lib/utils',
|
|
219
|
-
ui: '@/components/ui',
|
|
220
|
-
lib: '@/lib',
|
|
221
|
-
hooks: '@/hooks',
|
|
222
|
-
},
|
|
223
|
-
iconLibrary: 'lucide',
|
|
224
|
-
}, null, 2) + '\n');
|
|
225
|
-
}
|
|
226
|
-
function writeEnvExample(dir) {
|
|
227
|
-
writeFile(path.join(dir, '.env.example'), '');
|
|
228
|
-
}
|
|
229
|
-
function writeSourceFiles(dir, displayName) {
|
|
230
|
-
const displayNameLiteral = jsString(displayName);
|
|
231
|
-
const displayNameHtml = htmlText(displayName);
|
|
232
|
-
writeFile(path.join(dir, 'src/main/app-window.ts'), `import { BrowserWindow, shell } from 'electron';
|
|
233
|
-
import path from 'node:path';
|
|
234
|
-
import { fileURLToPath, pathToFileURL } from 'node:url';
|
|
235
|
-
|
|
236
|
-
const __dirname = path.dirname(fileURLToPath(import.meta.url));
|
|
237
|
-
const rendererIndex = path.join(__dirname, '../renderer/index.html');
|
|
238
|
-
|
|
239
|
-
function isSafeExternalUrl(value: string): boolean {
|
|
240
|
-
try {
|
|
241
|
-
const url = new URL(value);
|
|
242
|
-
return url.protocol === 'https:' && !url.username && !url.password;
|
|
243
|
-
} catch {
|
|
244
|
-
return false;
|
|
245
|
-
}
|
|
246
|
-
}
|
|
247
|
-
|
|
248
|
-
function isAllowedAppNavigation(value: string): boolean {
|
|
249
|
-
try {
|
|
250
|
-
const target = new URL(value);
|
|
251
|
-
if (process.env.VITE_DEV_SERVER_URL) {
|
|
252
|
-
return target.origin === new URL(process.env.VITE_DEV_SERVER_URL).origin;
|
|
253
|
-
}
|
|
254
|
-
return target.href === pathToFileURL(rendererIndex).href;
|
|
255
|
-
} catch {
|
|
256
|
-
return false;
|
|
257
|
-
}
|
|
258
|
-
}
|
|
259
|
-
|
|
260
|
-
// Product-owned window options and navigation policy belong in this file.
|
|
261
|
-
// main.ts imports this seam and manages application lifecycle.
|
|
262
|
-
export function createAppWindow(): BrowserWindow {
|
|
263
|
-
const window = new BrowserWindow({
|
|
264
|
-
width: 1180,
|
|
265
|
-
height: 760,
|
|
266
|
-
minWidth: 860,
|
|
267
|
-
minHeight: 560,
|
|
268
|
-
title: ${displayNameLiteral},
|
|
269
|
-
webPreferences: {
|
|
270
|
-
preload: path.join(__dirname, 'preload.cjs'),
|
|
271
|
-
contextIsolation: true,
|
|
272
|
-
nodeIntegration: false,
|
|
273
|
-
sandbox: true,
|
|
274
|
-
webSecurity: true,
|
|
275
|
-
},
|
|
276
|
-
});
|
|
277
|
-
|
|
278
|
-
window.webContents.on('will-navigate', (event, url) => {
|
|
279
|
-
if (!isAllowedAppNavigation(url)) event.preventDefault();
|
|
280
|
-
});
|
|
281
|
-
window.webContents.setWindowOpenHandler(({ url }) => {
|
|
282
|
-
if (isSafeExternalUrl(url)) {
|
|
283
|
-
void shell.openExternal(url).catch((error) => {
|
|
284
|
-
console.error('Unable to open external URL:', error);
|
|
285
|
-
});
|
|
286
|
-
}
|
|
287
|
-
return { action: 'deny' };
|
|
288
|
-
});
|
|
289
|
-
|
|
290
|
-
if (process.env.VITE_DEV_SERVER_URL) {
|
|
291
|
-
void window.loadURL(process.env.VITE_DEV_SERVER_URL).catch((error) => {
|
|
292
|
-
console.error('Unable to load the development renderer:', error);
|
|
293
|
-
});
|
|
294
|
-
} else {
|
|
295
|
-
void window.loadFile(rendererIndex).catch((error) => {
|
|
296
|
-
console.error('Unable to load the packaged renderer:', error);
|
|
297
|
-
});
|
|
298
|
-
}
|
|
299
|
-
|
|
300
|
-
return window;
|
|
301
|
-
}
|
|
302
|
-
`);
|
|
303
|
-
writeFile(path.join(dir, 'src/main/main.ts'), `import { app, BrowserWindow, session } from 'electron';
|
|
304
|
-
import { createAppWindow } from './app-window.js';
|
|
305
|
-
|
|
306
|
-
app.whenReady().then(() => {
|
|
307
|
-
session.defaultSession.setPermissionCheckHandler(() => false);
|
|
308
|
-
session.defaultSession.setPermissionRequestHandler((_webContents, _permission, callback) => callback(false));
|
|
309
|
-
createAppWindow();
|
|
310
|
-
}).catch((error) => {
|
|
311
|
-
console.error('Unable to start the desktop app:', error);
|
|
312
|
-
app.quit();
|
|
313
|
-
});
|
|
314
|
-
app.on('window-all-closed', () => {
|
|
315
|
-
if (process.platform !== 'darwin') app.quit();
|
|
316
|
-
});
|
|
317
|
-
app.on('activate', () => {
|
|
318
|
-
if (BrowserWindow.getAllWindows().length === 0) createAppWindow();
|
|
319
|
-
});
|
|
320
|
-
`);
|
|
321
|
-
writeFile(path.join(dir, 'src/main/preload.cts'), `import { contextBridge } from 'electron';
|
|
322
|
-
|
|
323
|
-
contextBridge.exposeInMainWorld('anhedral', {
|
|
324
|
-
platform: process.platform,
|
|
325
|
-
});
|
|
326
|
-
`);
|
|
327
|
-
writeFile(path.join(dir, 'index.html'), `<!doctype html>
|
|
328
|
-
<html lang="en">
|
|
329
|
-
<head>
|
|
330
|
-
<meta charset="UTF-8" />
|
|
331
|
-
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
|
332
|
-
<meta http-equiv="Content-Security-Policy" content="default-src 'self'; base-uri 'none'; object-src 'none'; script-src 'self'; style-src 'self' 'unsafe-inline'; connect-src 'self' https: ws://127.0.0.1:* wss:; img-src 'self' data: https:; font-src 'self' data: https:; frame-src https:; form-action 'self' https:" />
|
|
333
|
-
<title>${displayNameHtml}</title>
|
|
334
|
-
</head>
|
|
335
|
-
<body>
|
|
336
|
-
<div id="root"></div>
|
|
337
|
-
<script type="module" src="/src/renderer/main.tsx"></script>
|
|
338
|
-
</body>
|
|
339
|
-
</html>
|
|
340
|
-
`);
|
|
341
|
-
writeFile(path.join(dir, 'src/renderer/lib/utils.ts'), `import { clsx, type ClassValue } from 'clsx';
|
|
342
|
-
import { twMerge } from 'tailwind-merge';
|
|
343
|
-
|
|
344
|
-
export function cn(...inputs: ClassValue[]) {
|
|
345
|
-
return twMerge(clsx(inputs));
|
|
346
|
-
}
|
|
347
|
-
`);
|
|
348
|
-
writeFile(path.join(dir, 'src/renderer/components/ui/button.tsx'), `import * as React from 'react';
|
|
349
|
-
import { cn } from '@/lib/utils';
|
|
350
|
-
|
|
351
|
-
export function Button({ className, type = 'button', ...props }: React.ButtonHTMLAttributes<HTMLButtonElement>) {
|
|
352
|
-
return (
|
|
353
|
-
<button
|
|
354
|
-
type={type}
|
|
355
|
-
className={cn('inline-flex h-9 items-center justify-center rounded-md bg-primary px-4 text-sm font-medium text-primary-foreground transition-colors hover:bg-primary/90 disabled:opacity-50', className)}
|
|
356
|
-
{...props}
|
|
357
|
-
/>
|
|
358
|
-
);
|
|
359
|
-
}
|
|
360
|
-
`);
|
|
361
|
-
writeFile(path.join(dir, 'src/renderer/main.tsx'), `import React from 'react';
|
|
362
|
-
import ReactDOM from 'react-dom/client';
|
|
363
|
-
import { Button } from '@/components/ui/button';
|
|
364
|
-
import './styles.css';
|
|
365
|
-
|
|
366
|
-
function App() {
|
|
367
|
-
return (
|
|
368
|
-
<main className="flex min-h-screen flex-col gap-6 bg-background p-8 text-foreground">
|
|
369
|
-
<section className="flex flex-col gap-3">
|
|
370
|
-
<h1 className="text-3xl font-semibold">{${displayNameLiteral}}</h1>
|
|
371
|
-
<p className="max-w-2xl text-muted-foreground">
|
|
372
|
-
${'Electron + shadcn/ui desktop client ready for your application.'}
|
|
373
|
-
</p>
|
|
374
|
-
</section>
|
|
375
|
-
<Button className="self-start" onClick={() => window.location.reload()}>Reload</Button>
|
|
376
|
-
</main>
|
|
377
|
-
);
|
|
378
|
-
}
|
|
379
|
-
|
|
380
|
-
ReactDOM.createRoot(document.getElementById('root')!).render(
|
|
381
|
-
<React.StrictMode>
|
|
382
|
-
<App />
|
|
383
|
-
</React.StrictMode>,
|
|
384
|
-
);
|
|
385
|
-
`);
|
|
386
|
-
writeFile(path.join(dir, 'src/renderer/styles.css'), `@import "tailwindcss";
|
|
387
|
-
|
|
388
|
-
:root {
|
|
389
|
-
--background: oklch(1 0 0);
|
|
390
|
-
--foreground: oklch(0.145 0 0);
|
|
391
|
-
--primary: oklch(0.205 0 0);
|
|
392
|
-
--primary-foreground: oklch(0.985 0 0);
|
|
393
|
-
--muted-foreground: oklch(0.556 0 0);
|
|
394
|
-
}
|
|
395
|
-
|
|
396
|
-
@theme inline {
|
|
397
|
-
--color-background: var(--background);
|
|
398
|
-
--color-foreground: var(--foreground);
|
|
399
|
-
--color-primary: var(--primary);
|
|
400
|
-
--color-primary-foreground: var(--primary-foreground);
|
|
401
|
-
--color-muted-foreground: var(--muted-foreground);
|
|
402
|
-
}
|
|
403
|
-
|
|
404
|
-
body {
|
|
405
|
-
margin: 0;
|
|
406
|
-
background: var(--background);
|
|
407
|
-
color: var(--foreground);
|
|
408
|
-
font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
|
|
409
|
-
}
|
|
410
|
-
|
|
411
|
-
button {
|
|
412
|
-
border: 0;
|
|
413
|
-
}
|
|
414
|
-
`);
|
|
415
|
-
}
|