Spaces:
Paused
Paused
File size: 1,487 Bytes
1fe7075 c7a38a3 1fe7075 c7a38a3 1fe7075 c7a38a3 1fe7075 c7a38a3 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 | import 'dotenv/config';
import { resolve } from 'node:path';
import { parseArgs } from 'node:util';
import { NestFactory } from '@nestjs/core';
import { adminCatalogProblems } from '../catalog/admin-catalog.js';
import { CatalogModule } from '../catalog/catalog.module.js';
import { CatalogService } from '../catalog/catalog.service.js';
// `seed-catalog` seeds prisma/catalog.json (run on every start).
// `seed-catalog --file <path> --require-visibility admin` imports an admin-only supplier catalog explicitly.
const { values } = parseArgs({ options: { file: { type: 'string' }, 'require-visibility': { type: 'string' } } });
if (values['require-visibility'] && values['require-visibility'] !== 'admin') {
console.error('Usage: seed-catalog [--file <path> --require-visibility admin]');
process.exit(1);
}
const app = await NestFactory.createApplicationContext(CatalogModule, { logger: ['error'] });
try {
const catalog = app.get(CatalogService);
const entries = await catalog.load(values.file ? resolve(values.file) : undefined);
if (values['require-visibility']) {
const problems = adminCatalogProblems(entries, await catalog.load());
if (problems.length) throw new Error(`catalog: refusing to import\n ${problems.join('\n ')}`);
}
console.log(`catalog: ${await catalog.seed(entries)} tiles inserted or updated`);
} catch (error) {
console.error(error instanceof Error ? error.message : error);
process.exitCode = 1;
} finally {
await app.close();
}
|