mirror of
https://github.com/marcogll/passkit-generator.git
synced 2026-03-15 19:25:23 +00:00
Renamed splitBundle to splitBufferBundle and edited it to return splitted l10n/rootBundle object
This commit is contained in:
@@ -2,7 +2,7 @@ import { Pass } from "./pass";
|
||||
import { FactoryOptions, BundleUnit } from "./schema";
|
||||
import formatMessage from "./messages";
|
||||
import { getModelContents, readCertificatesFromOptions } from "./parser";
|
||||
import { splitBundle } from "./utils";
|
||||
import { splitBufferBundle } from "./utils";
|
||||
|
||||
export type Pass = InstanceType<typeof Pass>
|
||||
|
||||
@@ -18,7 +18,7 @@ export async function createPass(options: FactoryOptions, additionalBuffers?: Bu
|
||||
]);
|
||||
|
||||
if (additionalBuffers) {
|
||||
const [ additionalL10n, additionalBundle ] = splitBundle(additionalBuffers);
|
||||
const [ additionalL10n, additionalBundle ] = splitBufferBundle(additionalBuffers);
|
||||
Object.assign(bundle["l10nBundle"], additionalL10n);
|
||||
Object.assign(bundle["bundle"], additionalBundle);
|
||||
}
|
||||
|
||||
23
src/utils.ts
23
src/utils.ts
@@ -1,6 +1,7 @@
|
||||
import moment from "moment";
|
||||
import { EOL } from "os";
|
||||
import { BundleUnit } from "./schema";
|
||||
import { PartitionedBundle } from "./schema";
|
||||
import { sep } from "path";
|
||||
|
||||
/**
|
||||
* Checks if an rgb value is compliant with CSS-like syntax
|
||||
@@ -88,11 +89,19 @@ export function generateStringFile(lang: { [index: string]: string }): Buffer {
|
||||
* @param origin
|
||||
*/
|
||||
|
||||
export function splitBundle(origin: Object): [BundleUnit, BundleUnit] {
|
||||
export function splitBufferBundle(origin: Object): [PartitionedBundle["l10nBundle"], PartitionedBundle["bundle"]] {
|
||||
const keys = Object.keys(origin);
|
||||
return keys.reduce(([ l10n, bundle ], current) =>
|
||||
current.includes(".lproj") &&
|
||||
[ { ...l10n, [current]: origin[current] }, bundle] ||
|
||||
[ l10n, {...bundle, [current]: origin[current] }]
|
||||
, [{},{}]);
|
||||
return keys.reduce(([ l10n, bundle ], current) => {
|
||||
if (current.includes(".lproj")) {
|
||||
const pathComponents = current.split(sep);
|
||||
const lang = pathComponents[0];
|
||||
const file = pathComponents.slice(1).join("/");
|
||||
|
||||
(l10n[lang] || (l10n[lang] = {}))[file] = origin[current];
|
||||
|
||||
return [ l10n, bundle ];
|
||||
} else {
|
||||
return [ l10n, { ...bundle, [current]: origin[current] }];
|
||||
}
|
||||
}, [{},{}]);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user