UNPKG

@rr0/cms

Version:

RR0 Content Management System (CMS)

29 lines (28 loc) 1.25 kB
import path from "path"; import { ConsoleLogger } from "ssg-api"; import { CLI } from "../util/cli/CLI.js"; import { AllDataService, PeopleService, RR0EventFactory, TypedDataFactory } from "@rr0/data"; import { BookService } from "./BookService.js"; import { TimeUrlBuilder } from "../time/TimeUrlBuilder.js"; import { rr0TestUtil } from "../test/index.js"; const logger = new ConsoleLogger("rr0-books"); const args = new CLI().getArgs(); const fileName = args.import; const dry = args.dry === "true"; const peopleFactory = rr0TestUtil.peopleFactory; const eventFactory = new RR0EventFactory(); const bookFactory = new TypedDataFactory(eventFactory, "book"); const dataService = new AllDataService([bookFactory, peopleFactory]); const outDir = "out"; const config = { getOutputPath(context) { return path.join(outDir, context.file.name); } }; const timeUrlBuilder = new TimeUrlBuilder(rr0TestUtil.time.timeOptions); let files = []; const peopleService = new PeopleService(dataService, peopleFactory, { files, rootDir: rr0TestUtil.filePath("people") }); const books = new BookService(logger, dry, peopleService, timeUrlBuilder, config); books.import(fileName).then((result) => { logger.log("Wrote", result.length, "books"); });