init git
This commit is contained in:
@@ -0,0 +1,37 @@
|
||||
import glob from 'glob'
|
||||
import fs from 'fs'
|
||||
|
||||
const pxToRemRegex = /-\[(\d*\.?\d*)px\]/g;
|
||||
const pxToEmRegex = /text-\[(\d*\.?\d*)px\]/g;
|
||||
|
||||
const excludedFolders = ['.nuxt', 'node_modules'];
|
||||
|
||||
const convertFile = (filePath) => {
|
||||
const fileContent = fs.readFileSync(filePath, 'utf8');
|
||||
if (filePath.includes('node_modules'))
|
||||
return;
|
||||
|
||||
const updatedContent = fileContent.replace(pxToRemRegex, (match, pxValue) => {
|
||||
let remValue = (parseInt(pxValue) / 16).toFixed(1);
|
||||
if (parseInt(remValue) == remValue)
|
||||
remValue = parseInt(remValue)
|
||||
return `-[${remValue}rem]`;
|
||||
});
|
||||
|
||||
|
||||
|
||||
// ذخیره محتوای بهروزشده در فایل
|
||||
fs.writeFileSync(filePath, updatedContent, 'utf8');
|
||||
};
|
||||
|
||||
// پیمایش فایلهای Nuxt با صرفنظر از پوشههای استثنا
|
||||
glob('**/*.{vue,css}', { cwd: './', ignore: excludedFolders }, (err, files) => {
|
||||
if (err) {
|
||||
console.error(err);
|
||||
return;
|
||||
}
|
||||
|
||||
files.forEach(filePath => {
|
||||
convertFile(filePath);
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user