game_maker_serve runs project-shells.mjs unconditionally, so running the CI smoke runner on a development machine overwrote the four project documents with empty shells: revision 1301 became 1, and the name became the key from PROJECTS, because the seeders keep whatever name the server already holds. "Jump and Run" came back as "jumpRun". The shells are only ever needed on a fresh checkout, where the directory is empty, so an existing file is kept.
40 lines
1.5 KiB
JavaScript
Executable File
40 lines
1.5 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 { 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,
|
||
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}`);
|
||
}
|
||
}
|