UNPKG

@rr0/cms

Version:

RR0 Content Management System (CMS)

34 lines (33 loc) 1.39 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 { cmsTestUtil } from "../test/index.js"; const logger = new ConsoleLogger("rr0-books"); const args = new CLI().getArgs(); const fileName = args.import; if (fileName) { const dry = args.dry === "true"; const peopleFactory = cmsTestUtil.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(cmsTestUtil.time.timeOptions); let files = []; const peopleService = new PeopleService(dataService, peopleFactory, { files, rootDir: cmsTestUtil.filePath("people") }); const books = new BookService(logger, dry, peopleService, timeUrlBuilder, config); books.import(fileName).then((result) => { logger.log("Wrote", result.length, "books"); }); } else { console.warn("No file specified"); }