Ruined
This commit is contained in:
+24
-2
@@ -7,6 +7,9 @@ import { generateAssets } from './assets.mjs';
|
||||
import { absolute, atomicDirectory, copyTree, disjoint, exists, json, relativeName, safePath, verifyManifest, writeManifest } from './files.mjs';
|
||||
|
||||
export const SOURCE = path.resolve(path.dirname(fileURLToPath(import.meta.url)), '..');
|
||||
const WORLDGEN_REPO = path.resolve(SOURCE, '..', 'luanti-mapgenerator-epic');
|
||||
const WORLDGEN_SOURCE = path.join(WORLDGEN_REPO, 'mods', 'epic_terrain');
|
||||
const BUNDLED_WORLDGEN = path.basename(SOURCE) === 'last_hearth' && path.dirname(WORLDGEN_REPO) === path.dirname(SOURCE);
|
||||
export async function readRelease(source = SOURCE) {
|
||||
await safePath(path.join(absolute(source), 'release.json'));
|
||||
const release = JSON.parse(await fs.readFile(path.join(source, 'release.json'), 'utf8'));
|
||||
@@ -21,6 +24,11 @@ export async function packageGame(destination, { source = SOURCE } = {}) {
|
||||
// dist/ within the repository is supported; no payload source may overlap it.
|
||||
for (const entry of ['mods', 'fixtures', 'tests', 'scripts']) disjoint(path.join(source, entry), destination);
|
||||
const release = await readRelease(source);
|
||||
if (source === SOURCE && BUNDLED_WORLDGEN) {
|
||||
disjoint(WORLDGEN_SOURCE, destination);
|
||||
const config = await safePath(path.join(WORLDGEN_SOURCE, 'mod.conf'));
|
||||
if (!(await fs.lstat(config)).isFile()) throw new Error('Epic-scale mapgen mod is missing from the workspace.');
|
||||
}
|
||||
return atomicDirectory(destination, async stage => {
|
||||
for (const name of ['game.conf', 'minetest.conf', 'settingtypes.txt', 'LICENSE.txt']) {
|
||||
const filename = await safePath(path.join(source, name));
|
||||
@@ -30,6 +38,9 @@ export async function packageGame(destination, { source = SOURCE } = {}) {
|
||||
await copyTree(path.join(source, 'mods'), path.join(stage, 'mods'), {
|
||||
exclude: new Set(['hearth/textures', 'hearth/models']),
|
||||
});
|
||||
if (source === SOURCE && BUNDLED_WORLDGEN) {
|
||||
await copyTree(WORLDGEN_SOURCE, path.join(stage, 'mods/epic_terrain'));
|
||||
}
|
||||
for (const name of ['init', 'model', 'runtime', 'content', 'encounters']) {
|
||||
if (!await exists(path.join(stage, 'mods/hearth', name + '.lua'))) throw new Error('Game payload is incomplete.');
|
||||
}
|
||||
@@ -51,12 +62,23 @@ export async function packageGame(destination, { source = SOURCE } = {}) {
|
||||
}
|
||||
await fs.writeFile(path.join(stage, 'release.json'), json(release), { flag: 'wx' });
|
||||
await writeManifest(stage, 'game');
|
||||
await verifyPackage(stage);
|
||||
await verifyPackage(stage, {requireBundled: source === SOURCE && BUNDLED_WORLDGEN});
|
||||
});
|
||||
}
|
||||
|
||||
export async function verifyPackage(directory) {
|
||||
export async function verifyPackage(directory, {requireBundled} = {}) {
|
||||
const manifest = await verifyManifest(directory, 'game');
|
||||
await readRelease(directory);
|
||||
if (requireBundled === undefined) {
|
||||
const configPath = await safePath(path.join(absolute(directory), 'mods/hearth/mod.conf'));
|
||||
const config = await fs.readFile(configPath, 'utf8');
|
||||
requireBundled = /^\s*depends\s*=.*(?:^|[,\s])creatura(?:$|[,\s])/m.test(config);
|
||||
}
|
||||
if (requireBundled && BUNDLED_WORLDGEN && !manifest.entries.some(entry => entry.path === 'mods/epic_terrain/init.lua')) {
|
||||
throw new Error('Packaged Last Hearth is missing its bundled epic_terrain generator.');
|
||||
}
|
||||
if (requireBundled && !manifest.entries.some(entry => entry.path === 'mods/creatura/LICENSE')) {
|
||||
throw new Error('Packaged Last Hearth is missing Creatura license attribution.');
|
||||
}
|
||||
return manifest;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user