SUPPORT-8956: front mfe
This commit is contained in:
parent
c52a094e96
commit
6a6d3af94e
40 changed files with 898 additions and 38 deletions
33
frontend/normalize-css-path.ts
Normal file
33
frontend/normalize-css-path.ts
Normal file
|
|
@ -0,0 +1,33 @@
|
|||
const fs = require('fs');
|
||||
|
||||
const srcUrlRegex = /url\((\\?["'])?(?!data:)\S+(\\?["'])?\)/g;
|
||||
|
||||
export function normalizeCssPaths(params: {paths: string[], outDir: string}) {
|
||||
params.paths = params.paths ? params.paths : [];
|
||||
params.paths.forEach(path => normalizeCssPath(path, params.outDir));
|
||||
}
|
||||
|
||||
function normalizeCssPath(path: string, outputDirectory: string) {
|
||||
console.log(`Start processing ${path}`);
|
||||
const css: string = fs.readFileSync(path, 'utf8');
|
||||
let counter = 0;
|
||||
|
||||
const processedCss = css.replace(srcUrlRegex, (srcUrl: string) => {
|
||||
if (srcUrl.search(outputDirectory) != -1) return srcUrl;
|
||||
|
||||
let fileName = getFileName(srcUrl);
|
||||
let processedUrl = `url('${outputDirectory}/${fileName}')`;
|
||||
counter++;
|
||||
console.log(`Replaced ${srcUrl} -> ${processedUrl}`);
|
||||
return processedUrl;
|
||||
});
|
||||
console.log(`Replaced ${counter} urls`);
|
||||
fs.writeFileSync(path, processedCss);
|
||||
}
|
||||
|
||||
function getFileName(srcUrl: string): string {
|
||||
let url = srcUrl.substring(4, srcUrl.length - 1); // unbox 'url(...)'
|
||||
url = url.replace(/(\\?["'])/g, '');
|
||||
let urlPaths = url.split('/');
|
||||
return urlPaths[urlPaths.length - 1].split('?')[0];
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue