mirror of
https://github.com/marcogll/passkit-generator.git
synced 2026-03-15 14:25:17 +00:00
Moved splitBundle to utils and set optional to additionalBuffers
This commit is contained in:
@@ -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<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)) {
|
||||
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] }]
|
||||
, [{},{}]);
|
||||
}
|
||||
|
||||
16
src/utils.ts
16
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] }]
|
||||
, [{},{}]);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user