diff --git a/src/factory.ts b/src/factory.ts index af6b4d4..8dd8378 100644 --- a/src/factory.ts +++ b/src/factory.ts @@ -2,10 +2,11 @@ import { Pass } from "./pass"; import { FactoryOptions, BundleUnit } from "./schema"; import formatMessage from "./messages"; import { getModelContents, readCertificatesFromOptions } from "./parser"; +import { splitBundle } from "./utils"; export type Pass = InstanceType -export async function createPass(options: FactoryOptions, additionalBuffers: BundleUnit): Promise { +export async function createPass(options: FactoryOptions, additionalBuffers?: BundleUnit): Promise { if (!(options && Object.keys(options).length)) { throw new Error(formatMessage("CP_NO_OPTS")); } @@ -28,21 +29,6 @@ export async function createPass(options: FactoryOptions, additionalBuffers: Bun overrides: options.overrides }); } catch (err) { - throw new Error(formatMessage("CP_INIT_ERROR")); + throw new Error(formatMessage("CP_INIT_ERROR", err)); } } - -/** - * Applies a partition to split one bundle - * to two - * @param origin - */ - -function splitBundle(origin: Object): [BundleUnit, BundleUnit] { - const keys = Object.keys(origin); - return keys.reduce(([ l10n, bundle ], current) => - current.includes(".lproj") && - [ { ...l10n, [current]: origin[current] }, bundle] || - [ l10n, {...bundle, [current]: origin[current] }] - , [{},{}]); -} diff --git a/src/utils.ts b/src/utils.ts index 2872955..2968bbf 100644 --- a/src/utils.ts +++ b/src/utils.ts @@ -1,5 +1,6 @@ import moment from "moment"; import { EOL } from "os"; +import { BundleUnit } from "./schema"; /** * Checks if an rgb value is compliant with CSS-like syntax @@ -80,3 +81,18 @@ export function generateStringFile(lang: { [index: string]: string }): Buffer { return Buffer.from(strings.join(EOL), "utf8"); } + +/** + * Applies a partition to split one bundle + * to two + * @param origin + */ + +export function splitBundle(origin: Object): [BundleUnit, BundleUnit] { + const keys = Object.keys(origin); + return keys.reduce(([ l10n, bundle ], current) => + current.includes(".lproj") && + [ { ...l10n, [current]: origin[current] }, bundle] || + [ l10n, {...bundle, [current]: origin[current] }] + , [{},{}]); +}