Spaces:
Paused
Paused
Download apps/prevision-api/src/scripts/seed-catalog.ts from modventures/prevision: direct link, hf CLI and curl.
- Browser
- Download file 1.49 kB
-
https://huggingface.co/spaces/modventures/prevision/resolve/main/apps/prevision-api/src/scripts/seed-catalog.ts
- Command line
-
hf download hf://spaces/modventures/prevision/apps/prevision-api/src/scripts/seed-catalog.ts
-
curl -L -o seed-catalog.ts https://huggingface.co/spaces/modventures/prevision/resolve/main/apps/prevision-api/src/scripts/seed-catalog.ts
1.49 kB
| 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(); | |
| } | |