44 lines
1.7 KiB
JavaScript
Executable File
44 lines
1.7 KiB
JavaScript
Executable File
#!/usr/bin/env node
|
||
/**
|
||
* Creates the empty project files the seeders write into. `PUT ?r=projects/{id}` does not create
|
||
* a project and `POST` hands out a random id, so a fresh CI checkout has to put the shells with
|
||
* the known ids in place itself. The playground is left out – no tool may touch it.
|
||
*
|
||
* A file that is already there is left alone. Overwriting it used to cost a development machine
|
||
* the project's whole revision history and its name: the shell carries the key from PROJECTS as
|
||
* its name, and the seeders keep whatever name they find, so "Jump and Run" came back as
|
||
* "jumpRun". Only CI ever needs the shells, and there the directory is empty.
|
||
*
|
||
* Usage: node tools/ci/project-shells.mjs [dataDir]
|
||
*/
|
||
import { mkdir, writeFile } from 'node:fs/promises';
|
||
import { dirname, resolve } from 'node:path';
|
||
import { fileURLToPath } from 'node:url';
|
||
import { E2E_USER } from '../lib/auth.mjs';
|
||
import { PROJECTS } from '../lib/projects.mjs';
|
||
|
||
const root = resolve(dirname(fileURLToPath(import.meta.url)), '../..');
|
||
const dir = process.argv[2] ?? resolve(root, 'data/projects');
|
||
|
||
await mkdir(dir, { recursive: true });
|
||
for (const [name, id] of Object.entries(PROJECTS)) {
|
||
if (name === 'playground') continue;
|
||
const doc = {
|
||
id,
|
||
name,
|
||
// The test projects belong to the `e2e` account (#177); a file without an owner is invisible
|
||
// to everybody, so the shells have to say whose they are.
|
||
owner: E2E_USER,
|
||
revision: 0,
|
||
updatedAt: '1970-01-01T00:00:00Z',
|
||
project: {},
|
||
};
|
||
try {
|
||
await writeFile(resolve(dir, `${id}.json`), `${JSON.stringify(doc)}\n`, { flag: 'wx' });
|
||
console.log(`shell ${name} ${id}`);
|
||
} catch (err) {
|
||
if (err.code !== 'EEXIST') throw err;
|
||
console.log(`kept ${name} ${id}`);
|
||
}
|
||
}
|