Moved splitBundle to utils and set optional to additionalBuffers

This commit is contained in:
Alexander Cerutti
2019-07-10 00:24:53 +02:00
parent 6d39139dc7
commit f4dabb42b0
2 changed files with 19 additions and 17 deletions

View File

@@ -2,10 +2,11 @@ import { Pass } from "./pass";
import { FactoryOptions, BundleUnit } from "./schema"; import { FactoryOptions, BundleUnit } from "./schema";
import formatMessage from "./messages"; import formatMessage from "./messages";
import { getModelContents, readCertificatesFromOptions } from "./parser"; import { getModelContents, readCertificatesFromOptions } from "./parser";
import { splitBundle } from "./utils";
export type Pass = InstanceType<typeof Pass> export type Pass = InstanceType<typeof Pass>
export async function createPass(options: FactoryOptions, additionalBuffers: BundleUnit): Promise<Pass> { export async function createPass(options: FactoryOptions, additionalBuffers?: BundleUnit): Promise<Pass> {
if (!(options && Object.keys(options).length)) { if (!(options && Object.keys(options).length)) {
throw new Error(formatMessage("CP_NO_OPTS")); throw new Error(formatMessage("CP_NO_OPTS"));
} }
@@ -28,21 +29,6 @@ export async function createPass(options: FactoryOptions, additionalBuffers: Bun
overrides: options.overrides overrides: options.overrides
}); });
} catch (err) { } 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] }]
, [{},{}]);
}

View File

@@ -1,5 +1,6 @@
import moment from "moment"; import moment from "moment";
import { EOL } from "os"; import { EOL } from "os";
import { BundleUnit } from "./schema";
/** /**
* Checks if an rgb value is compliant with CSS-like syntax * 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"); 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] }]
, [{},{}]);
}