mirror of
https://github.com/marcogll/passkit-generator.git
synced 2026-03-16 06:26:09 +00:00
Moved to more async-await approach a L10N parser
This commit is contained in:
@@ -125,35 +125,36 @@ export async function getModelFolderContents(model: string): Promise<Partitioned
|
|||||||
// Reading concurrently localizations folder
|
// Reading concurrently localizations folder
|
||||||
// and their files and their buffers
|
// and their files and their buffers
|
||||||
const L10N_FilesListByFolder: Array<BundleUnit> = await Promise.all(
|
const L10N_FilesListByFolder: Array<BundleUnit> = await Promise.all(
|
||||||
l10nFolders.map(folderPath => {
|
l10nFolders.map(async folderPath => {
|
||||||
// Reading current folder
|
// Reading current folder
|
||||||
const currentLangPath = path.join(modelPath, folderPath);
|
const currentLangPath = path.join(modelPath, folderPath);
|
||||||
return readDir(currentLangPath)
|
|
||||||
.then(files => {
|
|
||||||
// Transforming files path to a model-relative path
|
|
||||||
const validFiles = removeHidden(files)
|
|
||||||
.map(file => path.join(currentLangPath, file));
|
|
||||||
|
|
||||||
// Getting all the buffers from file paths
|
const files = await readDir(currentLangPath);
|
||||||
return Promise.all([
|
// Transforming files path to a model-relative path
|
||||||
...validFiles.map(file =>
|
const validFiles = removeHidden(files)
|
||||||
readFile(file).catch(() => Buffer.alloc(0))
|
.map(file => path.join(currentLangPath, file));
|
||||||
)
|
|
||||||
]).then(buffers =>
|
|
||||||
// Assigning each file path to its buffer
|
|
||||||
// and discarding the empty ones
|
|
||||||
validFiles.reduce<BundleUnit>((acc, file, index) => {
|
|
||||||
if (!buffers[index].length) {
|
|
||||||
return acc;
|
|
||||||
}
|
|
||||||
|
|
||||||
const fileComponents = file.split(path.sep);
|
// Getting all the buffers from file paths
|
||||||
const fileName = fileComponents[fileComponents.length - 1];
|
const buffers = await Promise.all(
|
||||||
|
validFiles.map(file => readFile(file).catch(() => Buffer.alloc(0)))
|
||||||
|
);
|
||||||
|
|
||||||
return { ...acc, [fileName]: buffers[index] };
|
// Assigning each file path to its buffer
|
||||||
}, {})
|
// and discarding the empty ones
|
||||||
);
|
|
||||||
});
|
return validFiles.reduce<BundleUnit>((acc, file, index) => {
|
||||||
|
if (!buffers[index].length) {
|
||||||
|
return acc;
|
||||||
|
}
|
||||||
|
|
||||||
|
const fileComponents = file.split(path.sep);
|
||||||
|
const fileName = fileComponents[fileComponents.length - 1];
|
||||||
|
|
||||||
|
return {
|
||||||
|
...acc,
|
||||||
|
[fileName]: buffers[index]
|
||||||
|
};
|
||||||
|
}, {});
|
||||||
})
|
})
|
||||||
);
|
);
|
||||||
|
|
||||||
@@ -168,7 +169,7 @@ export async function getModelFolderContents(model: string): Promise<Partitioned
|
|||||||
l10nBundle
|
l10nBundle
|
||||||
};
|
};
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
if (err.code && err.code === "ENOENT") {
|
if (err?.code === "ENOENT") {
|
||||||
if (err.syscall === "open") {
|
if (err.syscall === "open") {
|
||||||
// file opening failed
|
// file opening failed
|
||||||
throw new Error(formatMessage("MODELF_NOT_FOUND", err.path))
|
throw new Error(formatMessage("MODELF_NOT_FOUND", err.path))
|
||||||
|
|||||||
Reference in New Issue
Block a user