mirror of
https://github.com/marcogll/passkit-generator.git
synced 2026-03-15 17:25:21 +00:00
Added support for additional buffers
This commit is contained in:
@@ -1,11 +1,11 @@
|
||||
import { Pass } from "./pass";
|
||||
import { FactoryOptions } from "./schema";
|
||||
import { FactoryOptions, BundleUnit } from "./schema";
|
||||
import formatMessage from "./messages";
|
||||
import { getModelContents, readCertificatesFromOptions } from "./parser";
|
||||
|
||||
export type Pass = InstanceType<typeof Pass>
|
||||
|
||||
export async function createPass(options: FactoryOptions): Promise<Pass> {
|
||||
export async function createPass(options: FactoryOptions, additionalBuffers: BundleUnit): Promise<Pass> {
|
||||
if (!(options && Object.keys(options).length)) {
|
||||
throw new Error(formatMessage("CP_NO_OPTS"));
|
||||
}
|
||||
@@ -16,6 +16,12 @@ export async function createPass(options: FactoryOptions): Promise<Pass> {
|
||||
readCertificatesFromOptions(options.certificates)
|
||||
]);
|
||||
|
||||
if (additionalBuffers) {
|
||||
const [ additionalL10n, additionalBundle ] = splitBundle(additionalBuffers);
|
||||
Object.assign(bundle["l10nBundle"], additionalL10n);
|
||||
Object.assign(bundle["bundle"], additionalBundle);
|
||||
}
|
||||
|
||||
return new Pass({
|
||||
model: bundle,
|
||||
certificates,
|
||||
@@ -26,3 +32,18 @@ export async function createPass(options: FactoryOptions): Promise<Pass> {
|
||||
throw new Error(formatMessage("CP_INIT_ERROR"));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 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] }]
|
||||
, [{},{}]);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user