Browse Source

Pull request #3437: KERNEL-14241 feat:es6脚本适配demo多处shortcut场景

Merge in VISUAL/fineui from ~VIVY.PAN/fineui:es6 to es6

* commit 'fd610389d494e36d5247ed53f7668e29cf9c32f4':
  KERNEL-14241 feat:es6脚本适配demo多处shortcut场景
es6
Vivy.Pan-潘柯芋 2 years ago
parent
commit
40ac231db4
  1. 35
      es6.js

35
es6.js

@ -64,6 +64,35 @@ async function saveAndFixCode(path, code) {
});
}
function divideFile(srcName) {
const targetPath = srcName.match(/.*\//g);
const sourceCode = fs.readFileSync(srcName).toString();
const splitSourceCode = sourceCode.match(/[\.\s]{1}[^\s\.]+?\s=\sBI\.inherit\([^]*?BI\.shortcut.*\;/g);
const newFileNames = [];
for (let i = 0; i < splitSourceCode.length; i++) {
// 去除开头的 空格 或者 .
const newCode = splitSourceCode[i].slice(1);
// 匹配第一个等号之前的组件名
const componentName = /BI\.shortcut\("(.*)"/.exec(newCode)[1];
// 文件名转化 ButtonIcon => demo.button.icon.js
const demoFileName = componentName + '.js';
newFileNames.push(demoFileName);
// 代码 componentName 前面加上 BI.
const fileCode = 'BI.' + newCode;
// 规范最后一行的组件为 BI.Button
const targetComponet = /(BI\..*)\s=/.exec(fileCode)[1];
// 最后一行的内容
const replaceContext = /BI\.shortcut.*;/.exec(fileCode)[0];
// 替换
const finalCode = fileCode.replace(replaceContext,`BI.shortcut("${componentName}", ${targetComponet});`)
// 创建新文件
fs.writeFileSync(targetPath + demoFileName, finalCode);
}
return newFileNames;
}
// const target = [];
// 加载模块
@ -107,6 +136,12 @@ async function handleFile(srcName) {
let G = (loader.G = {});
const sourceCode = fs.readFileSync(srcName).toString();
if (sourceCode.match(/shortcut/g).length > 1) {
console.log('该文件存在多处BI.shorcut, 需要拆分...');
const newTargets = divideFile(srcName);
newTargets.forEach(name => console.log(name));
return;
}
const result = /BI\.(.*?)\s=\sBI\.inherit\(/.exec(sourceCode);

Loading…
Cancel
Save