chore: remove used script

This commit is contained in:
wzhudev
2023-11-09 16:09:00 +08:00
parent 67e5c700b4
commit e7fb4b6cba
3 changed files with 0 additions and 102 deletions
-2
View File
@@ -11,7 +11,6 @@
"build": "turbo esbuild",
"build:demo": "turbo esbuild:demo",
"clean": "npm cache clean --force && node scripts/clean.mjs && pnpm install",
"formatfilename": "node scripts/format-filename.mjs",
"prepare": "husky install",
"pre-commit": "lint-staged",
"lint": "eslint --cache packages/**/src/**/*.{tsx,ts}",
@@ -56,7 +55,6 @@
"eslint-plugin-prettier": "^5.0.1",
"eslint-plugin-simple-import-sort": "^10.0.0",
"eslint-plugin-unused-imports": "^3.0.0",
"fs-extra": "^11.1.1",
"husky": "^8.0.3",
"lint-staged": "^15.0.2",
"prettier": "^3.0.3",
-3
View File
@@ -98,9 +98,6 @@ importers:
eslint-plugin-unused-imports:
specifier: ^3.0.0
version: 3.0.0(@typescript-eslint/eslint-plugin@6.10.0)(eslint@8.53.0)
fs-extra:
specifier: ^11.1.1
version: 11.1.1
husky:
specifier: ^8.0.3
version: 8.0.3
-97
View File
@@ -1,97 +0,0 @@
import fs from 'fs-extra';
import path from 'node:path';
import { fileURLToPath } from 'url';
const __filename = fileURLToPath(import.meta.url);
const __dirname = path.dirname(__filename);
const kebabize = (str) => str.replace(/[A-Z]+(?![a-z])|[A-Z]/g, ($, ofs) => (ofs ? '-' : '') + $.toLowerCase());
const getAllFiles = function (dirPath, arrayOfFiles) {
const files = fs.readdirSync(dirPath);
arrayOfFiles = arrayOfFiles || [];
files.forEach(function (file) {
if (
file.includes('node_modules') ||
file.includes('dist') ||
file.includes('lib') ||
file.includes('.turbo') ||
file.includes('coverage') ||
file.includes('local') ||
file.includes('design') ||
file.includes('base-ui') ||
file.includes('git')
) {
return;
}
if (fs.statSync(dirPath + '/' + file).isDirectory()) {
arrayOfFiles = getAllFiles(dirPath + '/' + file, arrayOfFiles);
} else {
arrayOfFiles.push(path.join(dirPath, '/', file));
}
});
return arrayOfFiles.filter((f) => f.endsWith('.ts') || f.endsWith('.tsx') || f.endsWith('index.module.less'));
};
function normalizePath(s) {
// TODO@wzhudev: if the last part is React.TSX, keep it
const parts = s.split('/');
return parts
.map((s, index) => {
if (index === parts.length - 1 && s.endsWith('.tsx')) {
return s;
}
return kebabize(s)
.replace(/^controller$/i, 'controllers')
.replace(/^component$/i, 'components')
.replace(/^service$/i, 'services')
.replace(/^view$/i, 'views');
})
.join('/');
}
function makeFilePathToKebabCase(file) {
const prePath = file.split('/packages/')[0];
const relativePath = file.split('/packages/')[1];
const kebabCaseFileName = normalizePath(relativePath);
return `${prePath}/packages/${kebabCaseFileName}`;
}
function move(from, to) {
fs.moveSync(from, to);
}
function updateImports(to) {
const file = fs.readFileSync(to, 'utf8');
const newFile = file
.replace(/from '(.*?)';/g, (s) => {
if (!s.includes('./')) {
return s;
}
const newRelativePath = normalizePath(s);
console.log(s, newRelativePath);
return `${newRelativePath}`;
})
fs.writeFileSync(to, newFile);
}
const folderPath = path.join(__dirname, '../packages');
const allFiles = getAllFiles(folderPath).slice(1);
const allFilePairs = allFiles.map((f) => [f, makeFilePathToKebabCase(f)]);
allFilePairs
.filter(([from, to]) => from !== to)
.forEach(([from, to]) => {
move(from, to);
});
allFilePairs.forEach(([_, to]) => {
updateImports(to);
});