|
|
@ -1,10 +1,26 @@ |
|
|
|
const fs = require("fs"); |
|
|
|
const fs = require("fs"); |
|
|
|
|
|
|
|
const path = require("path"); |
|
|
|
|
|
|
|
const prettier = require("prettier"); |
|
|
|
|
|
|
|
const { exec } = require("child_process"); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
async function fix(path) { |
|
|
|
|
|
|
|
new Promise(res => { |
|
|
|
|
|
|
|
exec(`yarn eslint --fix ${path}`, () => { |
|
|
|
|
|
|
|
res(); |
|
|
|
|
|
|
|
}); |
|
|
|
|
|
|
|
}); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
const srcName = process.argv[2]; |
|
|
|
async function handleFile(srcName) { |
|
|
|
|
|
|
|
|
|
|
|
const sourceCode = fs.readFileSync(srcName).toString(); |
|
|
|
const sourceCode = fs.readFileSync(srcName).toString(); |
|
|
|
|
|
|
|
|
|
|
|
const clzName = /BI\.(.*?)\s\=\sBI\.inherit\(/.exec(sourceCode)[1]; |
|
|
|
const result = /BI\.(.*?)\s\=\sBI\.inherit\(/.exec(sourceCode); |
|
|
|
|
|
|
|
if (!result) { |
|
|
|
|
|
|
|
console.log(`可能是已经es6过了 ${srcName}`); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
const clzName = result[1]; |
|
|
|
|
|
|
|
|
|
|
|
const superName = /inherit\(BI\.(.*?),/.exec(sourceCode)[1]; |
|
|
|
const superName = /inherit\(BI\.(.*?),/.exec(sourceCode)[1]; |
|
|
|
|
|
|
|
|
|
|
@ -139,5 +155,36 @@ ${M} |
|
|
|
} |
|
|
|
} |
|
|
|
`;
|
|
|
|
`;
|
|
|
|
|
|
|
|
|
|
|
|
// fs.writeFileSync(`${srcName}.js.raw`, sourceCode);
|
|
|
|
const prettierCode = prettier.format(outputCode); |
|
|
|
fs.writeFileSync(srcName, outputCode); |
|
|
|
fs.writeFileSync(srcName, prettierCode); |
|
|
|
|
|
|
|
await fix(srcName); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return clzName; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
async function traverse(srcName) { |
|
|
|
|
|
|
|
if (srcName.indexOf("__test__") >= 0) return; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (srcName.endsWith(".js")) { |
|
|
|
|
|
|
|
return await handleFile(srcName); |
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
const stat = fs.statSync(srcName); |
|
|
|
|
|
|
|
const flag = stat.isDirectory(); |
|
|
|
|
|
|
|
if (flag) { |
|
|
|
|
|
|
|
const files = fs.readdirSync(srcName); |
|
|
|
|
|
|
|
// let indexContent = "";
|
|
|
|
|
|
|
|
for (let i = 0; i < files.length; i++) { |
|
|
|
|
|
|
|
const file = files[i]; |
|
|
|
|
|
|
|
await traverse(path.resolve(srcName, file)); |
|
|
|
|
|
|
|
// const clzName = await traverse(path.resolve(srcName, file));
|
|
|
|
|
|
|
|
// const moduleName = path.basename(srcName).replace(/.js$/, "");
|
|
|
|
|
|
|
|
// if (clzName) {
|
|
|
|
|
|
|
|
// indexContent += `export { ${clzName} } from '${moduleName}'\n`;
|
|
|
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const srcName = process.argv[2]; |
|
|
|
|
|
|
|
traverse(srcName); |
|
|
|