Issue #3262160 by nod_, lauriii: Simplify code in assets.js, remove mix of await and promise code
parent
bb3ee2e9af
commit
068b3ff44b
|
@ -40,10 +40,11 @@ const assetsFolder = `${coreFolder}/assets/vendor`;
|
||||||
// that an empty /translations directory exists in the
|
// that an empty /translations directory exists in the
|
||||||
// /core/assets/vendor/ckeditor5 directory.
|
// /core/assets/vendor/ckeditor5 directory.
|
||||||
const ckeditor5Path = `${assetsFolder}/ckeditor5`;
|
const ckeditor5Path = `${assetsFolder}/ckeditor5`;
|
||||||
await rmdir(`${ckeditor5Path}/translations`, { recursive: true })
|
try {
|
||||||
.catch(() => {
|
await rmdir(`${ckeditor5Path}/translations`, { recursive: true })
|
||||||
// Nothing to do if the directory doesn't exist.
|
} catch (e) {
|
||||||
});
|
// Nothing to do if the directory doesn't exist.
|
||||||
|
}
|
||||||
await mkdir(`${ckeditor5Path}/translations`);
|
await mkdir(`${ckeditor5Path}/translations`);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -341,89 +342,84 @@ const assetsFolder = `${coreFolder}/assets/vendor`;
|
||||||
}
|
}
|
||||||
];
|
];
|
||||||
|
|
||||||
// Use Array.reduce for sequential processing to avoid corrupting the
|
// Use sequential processing to avoid corrupting the contents of the
|
||||||
// contents of the concatenated CKEditor 5 translation files.
|
// concatenated CKEditor 5 translation files.
|
||||||
await process.reduce(async (previous, { pack, files = [], folder = false, library = false }) => {
|
for (const { pack, files = [], folder = false, library = false } of process) {
|
||||||
return previous.then(async () => {
|
const sourceFolder = pack;
|
||||||
const sourceFolder = pack;
|
const libraryName = library || folder || pack;
|
||||||
const libraryName = library || folder || pack;
|
const destFolder = folder || pack;
|
||||||
const destFolder = folder || pack;
|
|
||||||
|
|
||||||
let packageInfo;
|
let packageInfo;
|
||||||
// Take the version info from the package.json file.
|
// Take the version info from the package.json file.
|
||||||
if (!['joyride', 'farbtastic'].includes(pack)) {
|
if (!['joyride', 'farbtastic'].includes(pack)) {
|
||||||
packageInfo = JSON.parse(
|
packageInfo = JSON.parse(
|
||||||
await readFile(`${packageFolder}/${sourceFolder}/package.json`),
|
await readFile(`${packageFolder}/${sourceFolder}/package.json`),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
if (packageInfo) {
|
if (packageInfo) {
|
||||||
updateLibraryVersion(libraryName, packageInfo);
|
updateLibraryVersion(libraryName, packageInfo);
|
||||||
}
|
}
|
||||||
|
|
||||||
// CKEditor 5 packages ship with translation files.
|
// CKEditor 5 packages ship with translation files.
|
||||||
if (pack.startsWith('@ckeditor') || pack === 'ckeditor5') {
|
if (pack.startsWith('@ckeditor') || pack === 'ckeditor5') {
|
||||||
const packageTranslationPath = `${packageFolder}/${sourceFolder}/build/translations`;
|
const packageTranslationPath = `${packageFolder}/${sourceFolder}/build/translations`;
|
||||||
await readdir(packageTranslationPath, { withFileTypes: true }).then(async (translationFiles) => {
|
try {
|
||||||
return translationFiles.map(async (translationFile) => {
|
const translationFiles = await readdir(packageTranslationPath, { withFileTypes: true });
|
||||||
if (!translationFile.isDirectory()) {
|
for (const translationFile of translationFiles) {
|
||||||
// Translation files are concatenated to a single translation
|
if (!translationFile.isDirectory()) {
|
||||||
// file to avoid having to make multiple network requests to
|
// Translation files are concatenated to a single translation
|
||||||
// various translation files. As a trade off, this leads into
|
// file to avoid having to make multiple network requests to
|
||||||
// some redundant translations depending on configuration.
|
// various translation files. As a trade off, this leads into
|
||||||
await readFile(`${packageTranslationPath}/${translationFile.name}`).then(async (contents) => {
|
// some redundant translations depending on configuration.
|
||||||
return appendFile(`${assetsFolder}/${destFolder}/translations/${translationFile.name}`, contents);
|
const contents = await readFile(`${packageTranslationPath}/${translationFile.name}`)
|
||||||
});
|
await appendFile(`${assetsFolder}/${destFolder}/translations/${translationFile.name}`, contents);
|
||||||
}
|
|
||||||
}, Promise.resolve());
|
|
||||||
}).catch(() => {
|
|
||||||
// Do nothing as it's expected that not all packages ship translations.
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
return files.forEach(async (file) => {
|
|
||||||
let source = file;
|
|
||||||
let dest = file;
|
|
||||||
if (typeof file === 'object') {
|
|
||||||
source = file.from;
|
|
||||||
dest = file.to;
|
|
||||||
}
|
|
||||||
// For map files, make sure the sources files don't leak outside the
|
|
||||||
// library folder. In the `sources` member, remove all "../" values at
|
|
||||||
// the start of the files names to avoid having the virtual files outside
|
|
||||||
// of the library vendor folder in dev tools.
|
|
||||||
if (path.extname(source) === '.map') {
|
|
||||||
console.log('Process map file', source);
|
|
||||||
const map = await readFile(
|
|
||||||
`${packageFolder}/${sourceFolder}/${source}`,
|
|
||||||
);
|
|
||||||
const json = JSON.parse(map);
|
|
||||||
json.sources = json.sources.map((source) =>
|
|
||||||
source.replace(/^(\.\.\/)+/, ''),
|
|
||||||
);
|
|
||||||
await writeFile(
|
|
||||||
`${assetsFolder}/${destFolder}/${dest}`,
|
|
||||||
JSON.stringify(json),
|
|
||||||
);
|
|
||||||
} else {
|
|
||||||
console.log(
|
|
||||||
'Copy',
|
|
||||||
`${sourceFolder}/${source}`,
|
|
||||||
'to',
|
|
||||||
`${destFolder}/${dest}`,
|
|
||||||
);
|
|
||||||
await copyFile(
|
|
||||||
`${packageFolder}/${sourceFolder}/${source}`,
|
|
||||||
`${assetsFolder}/${destFolder}/${dest}`,
|
|
||||||
);
|
|
||||||
// These 2 files come from a zip file that hasn't been updated in years
|
|
||||||
// hardcode the permission fix to pass the commit checks.
|
|
||||||
if (['jquery.joyride-2.1.js', 'marker.png'].includes(dest)) {
|
|
||||||
await chmod(`${assetsFolder}/${destFolder}/${dest}`, 0o644);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
} catch (e) {
|
||||||
});
|
// No translations folder, do nothing.
|
||||||
}, Promise.resolve());
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
for (const file of files) {
|
||||||
|
let source = file;
|
||||||
|
let dest = file;
|
||||||
|
if (typeof file === 'object') {
|
||||||
|
source = file.from;
|
||||||
|
dest = file.to;
|
||||||
|
}
|
||||||
|
// For map files, make sure the sources files don't leak outside the
|
||||||
|
// library folder. In the `sources` member, remove all "../" values at
|
||||||
|
// the start of the files names to avoid having the virtual files outside
|
||||||
|
// of the library vendor folder in dev tools.
|
||||||
|
if (path.extname(source) === '.map') {
|
||||||
|
console.log('Process map file', source);
|
||||||
|
const map = await readFile(
|
||||||
|
`${packageFolder}/${sourceFolder}/${source}`,
|
||||||
|
);
|
||||||
|
const json = JSON.parse(map);
|
||||||
|
json.sources = json.sources.map((source) =>
|
||||||
|
source.replace(/^(\.\.\/)+/, ''),
|
||||||
|
);
|
||||||
|
await writeFile(
|
||||||
|
`${assetsFolder}/${destFolder}/${dest}`,
|
||||||
|
JSON.stringify(json),
|
||||||
|
);
|
||||||
|
} else {
|
||||||
|
console.log(
|
||||||
|
`Copy ${sourceFolder}/${source} to ${destFolder}/${dest}`,
|
||||||
|
);
|
||||||
|
await copyFile(
|
||||||
|
`${packageFolder}/${sourceFolder}/${source}`,
|
||||||
|
`${assetsFolder}/${destFolder}/${dest}`,
|
||||||
|
);
|
||||||
|
// These 2 files come from a zip file that hasn't been updated in years
|
||||||
|
// hardcode the permission fix to pass the commit checks.
|
||||||
|
if (['jquery.joyride-2.1.js', 'marker.png'].includes(dest)) {
|
||||||
|
await chmod(`${assetsFolder}/${destFolder}/${dest}`, 0o644);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
await writeFile(librariesPath, libraries.join('\n\n'));
|
await writeFile(librariesPath, libraries.join('\n\n'));
|
||||||
})();
|
})();
|
||||||
|
|
Loading…
Reference in New Issue