Spreadsheet-UX op een echte relationele engine
Deze repository wordt als momentopname gepubliceerd: een clone bevat de volledige inhoud, maar geen commitgeschiedenis.
import { randomBytes } from 'node:crypto';
import { config } from '../config.js';
import { openInstallation, provisionOwner } from './install.js';
/**
* Create an account and its first workspace from the command line.
*
* The scripted equivalent of the signup form, for deploys and for installs
* that run with `WELLFORMED_SIGNUPS=closed`.
*
* npm run provision -- --email you@example.com --workspace "Acme" --slug acme
*/
function flag(name: string): string | undefined {
const index = process.argv.indexOf(`--${name}`);
if (index === -1) return undefined;
return process.argv[index + 1];
}
const email = flag('email') ?? process.env.WELLFORMED_ADMIN_EMAIL ?? 'admin@wellformed.local';
const workspaceName = flag('workspace') ?? process.env.WELLFORMED_WORKSPACE_NAME ?? 'Workspace';
const slug = flag('slug') ?? process.env.WELLFORMED_WORKSPACE_SLUG;
const name = flag('name') ?? 'Admin';
// --empty for a bare workspace, --structure for the demo tables without their
// rows; saying nothing builds the full demo, so there is something to look at.
const demo = process.argv.includes('--empty')
? ('none' as const)
: process.argv.includes('--structure')
? ('structure' as const)
: ('full' as const);
let generated: string | undefined;
const password =
flag('password') ?? process.env.WELLFORMED_ADMIN_PASSWORD?.trim() ?? (generated = randomBytes(9).toString('base64url'));
const install = openInstallation();
try {
const result = await provisionOwner(install.control, install.registry, {
email,
password,
name,
workspaceName,
slug,
demo,
});
console.log(`[wellformed] control ${config.controlDbPath}`);
console.log(`[wellformed] workspaces ${config.tenantsDir}`);
if (!result.created) {
console.log(`[wellformed] ${email} already owns "${result.workspace.name}" — left alone.`);
} else {
console.log(`[wellformed] created workspace "${result.workspace.name}" at /w/${result.workspace.slug}`);
console.log('');
console.log(` email: ${email}`);
if (generated) {
console.log(` password: ${generated}`);
console.log('');
console.log(' Shown once. Store it now, or re-run with --password.');
} else {
console.log(' password: (the one you supplied)');
}
console.log('');
}
} finally {
install.close();
}