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 { 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";
|
import { splitBufferBundle } from "./utils";
|
||||||
|
|
||||||
export type Pass = InstanceType<typeof Pass>
|
export type Pass = InstanceType<typeof Pass>
|
||||||
|
|
||||||
@@ -18,7 +18,7 @@ export async function createPass(options: FactoryOptions, additionalBuffers?: Bu
|
|||||||
]);
|
]);
|
||||||
|
|
||||||
if (additionalBuffers) {
|
if (additionalBuffers) {
|
||||||
const [ additionalL10n, additionalBundle ] = splitBundle(additionalBuffers);
|
const [ additionalL10n, additionalBundle ] = splitBufferBundle(additionalBuffers);
|
||||||
Object.assign(bundle["l10nBundle"], additionalL10n);
|
Object.assign(bundle["l10nBundle"], additionalL10n);
|
||||||
Object.assign(bundle["bundle"], additionalBundle);
|
Object.assign(bundle["bundle"], additionalBundle);
|
||||||
}
|
}
|
||||||
|
|||||||
23
src/utils.ts
23
src/utils.ts
@@ -1,6 +1,7 @@
|
|||||||
import moment from "moment";
|
import moment from "moment";
|
||||||
import { EOL } from "os";
|
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
|
* 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
|
* @param origin
|
||||||
*/
|
*/
|
||||||
|
|
||||||
export function splitBundle(origin: Object): [BundleUnit, BundleUnit] {
|
export function splitBufferBundle(origin: Object): [PartitionedBundle["l10nBundle"], PartitionedBundle["bundle"]] {
|
||||||
const keys = Object.keys(origin);
|
const keys = Object.keys(origin);
|
||||||
return keys.reduce(([ l10n, bundle ], current) =>
|
return keys.reduce(([ l10n, bundle ], current) => {
|
||||||
current.includes(".lproj") &&
|
if (current.includes(".lproj")) {
|
||||||
[ { ...l10n, [current]: origin[current] }, bundle] ||
|
const pathComponents = current.split(sep);
|
||||||
[ l10n, {...bundle, [current]: origin[current] }]
|
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