mirror of
https://github.com/marcogll/passkit-generator.git
synced 2026-03-15 21:25:26 +00:00
Generic Improvements
This commit is contained in:
@@ -18,25 +18,14 @@ const readFile = promisify(_readFile);
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
export async function getModelContents(model: FactoryOptions["model"]) {
|
export async function getModelContents(model: FactoryOptions["model"]) {
|
||||||
const isModelValid = (
|
|
||||||
model && (
|
|
||||||
typeof model === "string" || (
|
|
||||||
typeof model === "object" &&
|
|
||||||
Object.keys(model).length
|
|
||||||
)
|
|
||||||
)
|
|
||||||
);
|
|
||||||
|
|
||||||
if (!isModelValid) {
|
|
||||||
throw new Error(formatMessage("MODEL_NOT_VALID"));
|
|
||||||
}
|
|
||||||
|
|
||||||
let modelContents: PartitionedBundle;
|
let modelContents: PartitionedBundle;
|
||||||
|
|
||||||
if (typeof model === "string") {
|
if (typeof model === "string") {
|
||||||
modelContents = await getModelFolderContents(model);
|
modelContents = await getModelFolderContents(model);
|
||||||
} else {
|
} else if (typeof model === "object" && Object.keys(model).length) {
|
||||||
modelContents = getModelBufferContents(model);
|
modelContents = getModelBufferContents(model);
|
||||||
|
} else {
|
||||||
|
throw new Error(formatMessage("MODEL_NOT_VALID"));
|
||||||
}
|
}
|
||||||
|
|
||||||
const modelFiles = Object.keys(modelContents.bundle);
|
const modelFiles = Object.keys(modelContents.bundle);
|
||||||
@@ -112,14 +101,15 @@ export async function getModelFolderContents(model: string): Promise<Partitioned
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Splitting files from localization folders
|
// Splitting files from localization folders
|
||||||
const rawBundle = filteredFiles.filter(entry => !entry.includes(".lproj"));
|
const rawBundleFiles = filteredFiles.filter(entry => !entry.includes(".lproj"));
|
||||||
const l10nFolders = filteredFiles.filter(entry => entry.includes(".lproj"));
|
const l10nFolders = filteredFiles.filter(entry => entry.includes(".lproj"));
|
||||||
|
|
||||||
const bundleBuffers = rawBundle.map(file => readFile(path.resolve(modelPath, file)));
|
const rawBundleBuffers = await Promise.all(
|
||||||
const buffers = await Promise.all(bundleBuffers);
|
rawBundleFiles.map(file => readFile(path.resolve(modelPath, file)))
|
||||||
|
);
|
||||||
|
|
||||||
const bundle: BundleUnit = Object.assign({},
|
const bundle: BundleUnit = Object.assign({},
|
||||||
...rawBundle.map((fileName, index) => ({ [fileName]: buffers[index] }))
|
...rawBundleFiles.map((fileName, index) => ({ [fileName]: rawBundleBuffers[index] }))
|
||||||
);
|
);
|
||||||
|
|
||||||
// Reading concurrently localizations folder
|
// Reading concurrently localizations folder
|
||||||
|
|||||||
Reference in New Issue
Block a user