代码拉取完成,页面将自动刷新
同步操作将从 mixly2/mixly2.0_src 强制同步,此操作会覆盖自 Fork 仓库以来所做的任何修改,且无法恢复!!!
确定后同步将在后台操作,完成时将刷新页面,请耐心等待。
const fs = require('fs');
const path = require('path');
const config = {
"electron": {
"dirName": "electron"
},
"web": {
"dirName": "web"
},
"web-socket": {
"dirName": "web-socket"
},
"web-compiler": {
"dirName": "web-compiler"
},
"common": {
"dirName": "common"
},
"workPath": __dirname,
"fileIgnore": [
/*"./common/serial-charts.js"*/
"./common/env.js",
"./common/deps.js",
"./common/modules/base64.min.js",
"./common/modules/lazyload.js",
"./common/modules/microbit-fs.umd.min.js",
"./common/modules/notify.js",
"./common/modules/popper.min.js",
"./common/modules/sortable.min.js",
"./common/modules/store.modern.min.js",
"./common/modules/tippy-bundle.umd.min.js",
"./common/modules/xscrollbar.js",
"./common/modules/select2.min.js",
"./common/modules/xterm.min.js"
]
};
const needBuildDirList = [
__dirname + '/mixly-sw/',
__dirname + '/board/common/mixly/'
];
const scan = (dir, fileIgnore, outputConfig) => {
let googList = [];
let dirName = path.basename(dir);
if (fs.existsSync(dir) && fs.statSync(dir).isDirectory()) {
let childNames = fs.readdirSync(dir);
for (let i = 0; i < childNames.length; i++) {
let childPath = path.join(dir, childNames[i]);
if (fs.existsSync(childPath) && fs.statSync(childPath).isFile()) {
if (typeof fileIgnore === 'object'
&& fileIgnore.includes(childPath))
continue;
let jsStr = fs.readFileSync(childPath, 'utf8');
let googObj = {};
googObj.path = '/' + dirName + '/' + childNames[i];
googObj.require = match('goog.require', jsStr);
googObj.provide = match("goog.provide", jsStr);
let Mixly = {};
Mixly.require = match("Mixly.require", jsStr);
if (googObj.require || googObj.provide || Mixly.require) {
if (!googObj.require)
googObj.require = [];
if (!googObj.provide)
googObj.provide = [];
if (Mixly.require.length > 0) {
let obj = {};
let defaultObj = {
"electron": [],
"web": [],
"web-socket": {
"electron": [],
"web": [],
"common": []
},
"web-compiler": {
"electron": [],
"web": [],
"common": []
},
"common": []
};
for (let j = 0; j < Mixly.require.length; j++) {
let nowGoogObj = {};
let nowGoogRequireObj = {
...defaultObj,
...Mixly.require[j]
};
nowGoogObj.path = googObj.path;
nowGoogObj.provide = googObj.provide;
nowGoogRequireObj.common = [...googObj.require, ...nowGoogRequireObj.common];
nowGoogObj.require = nowGoogRequireObj;
addDeps(nowGoogObj, outputConfig);
}
continue;
} else {
googList.push(googObj);
}
}
} else {
googList = [...googList, ...scan(childPath, fileIgnore)];
}
}
}
return googList;
}
const addDeps = (obj, outputConfig) => {
let electronObj = {
'path': obj['path'],
'provide': obj['provide'],
'require': [...obj['require']['common'], ...obj['require']['electron']]
};
electronObj.require = unique(electronObj.require);
let webObj = {
'path': obj['path'],
'provide': obj['provide'],
'require': [...obj['require']['common'], ...obj['require']['web']]
};
webObj.require = unique(webObj.require);
let websocketElectronObj = {
'path': obj['path'],
'provide': obj['provide'],
'require': [...obj['require']['common'], ...obj['require']['web-socket']['common'], ...obj['require']['web-socket']['electron']]
};
websocketElectronObj.require = unique(websocketElectronObj.require);
let websocketWebObj = {
'path': obj['path'],
'provide': obj['provide'],
'require': [...obj['require']['common'], ...obj['require']['web-socket']['common'], ...obj['require']['web-socket']['web']]
};
websocketWebObj.require = unique(websocketWebObj.require);
let webcompilerElectronObj = {
'path': obj['path'],
'provide': obj['provide'],
'require': [...obj['require']['common'], ...obj['require']['web-compiler']['common'], ...obj['require']['web-compiler']['electron']]
};
webcompilerElectronObj.require = unique(webcompilerElectronObj.require);
let webcompilerWebObj = {
'path': obj['path'],
'provide': obj['provide'],
'require': [...obj['require']['common'], ...obj['require']['web-compiler']['common'], ...obj['require']['web-compiler']['web']]
};
webcompilerWebObj.require = unique(webcompilerWebObj.require);
outputConfig['electron'].push(electronObj);
outputConfig['web'].push(webObj);
outputConfig['web-socket']['electron'].push(websocketElectronObj);
outputConfig['web-socket']['web'].push(websocketWebObj);
outputConfig['web-compiler']['electron'].push(webcompilerElectronObj);
outputConfig['web-compiler']['web'].push(webcompilerWebObj);
}
const match = (type, jsStr) => {
let list = [];
if (type === 'goog.require') {
list = jsStr.match(/(?<=goog.require[\s]*\(["|'])[\w-.]+(?=["|'][\s]*\))/g);
} else if (type === 'goog.provide') {
list = jsStr.match(/(?<=goog.provide[\s]*\(["|'])[\w-.]+(?=["|'][\s]*\))/g);
} else if (type === 'Mixly.require') {
let strList = jsStr.match(/(?<=Mixly.require[\s]*\()[^)]+(?=\))/g);
if (strList) {
for (let i = 0; i < strList.length; i++) {
if (!strList[i]) continue;
try {
list.push(JSON.parse(strList[i]));
} catch (e) {
console.log(e);
}
}
}
}
if (list)
list = unique(list);
return list;
}
// 数组去重
const unique = (list) => {
return Array.from(new Set(list));
}
const formatJson = (json, options) => {
var reg = null,
formatted = '',
pad = 0,
PADDING = ' ';
options = options || {};
options.newlineAfterColonIfBeforeBraceOrBracket = (options.newlineAfterColonIfBeforeBraceOrBracket === true) ? true : false;
options.spaceAfterColon = (options.spaceAfterColon === false) ? false : true;
if (typeof json !== 'string') {
json = JSON.stringify(json);
} else {
json = JSON.parse(json);
json = JSON.stringify(json);
}
reg = /([\{\}])/g;
json = json.replace(reg, '\r\n$1\r\n');
reg = /([\[\]])/g;
json = json.replace(reg, '\r\n$1\r\n');
reg = /(\,)/g;
json = json.replace(reg, '$1\r\n');
reg = /(\r\n\r\n)/g;
json = json.replace(reg, '\r\n');
reg = /\r\n\,/g;
json = json.replace(reg, ',');
if (!options.newlineAfterColonIfBeforeBraceOrBracket) {
reg = /\:\r\n\{/g;
json = json.replace(reg, ':{');
reg = /\:\r\n\[/g;
json = json.replace(reg, ':[');
}
if (options.spaceAfterColon) {
reg = /\:/g;
json = json.replace(reg, ':');
}
(json.split('\r\n')).forEach(function (node, index) {
var i = 0,
indent = 0,
padding = '';
if (node.match(/\{$/) || node.match(/\[$/)) {
indent = 1;
} else if (node.match(/\}/) || node.match(/\]/)) {
if (pad !== 0) {
pad -= 1;
}
} else {
indent = 0;
}
for (i = 0; i < pad; i++) {
padding += PADDING;
}
formatted += padding + node + '\r\n';
pad += indent;
}
);
return formatted;
};
const generateDeps = () => {
for (let needBuildDir of needBuildDirList) {
let fileIgnore = [];
if (typeof config.fileIgnore === 'object') {
for (let i = 0; i < config.fileIgnore.length; i++) {
fileIgnore.push(path.resolve(needBuildDir, config.fileIgnore[i]));
}
}
let outputConfig = {
"electron": [],
"web": [],
"web-socket": {
"electron": [],
"web": [],
"common": []
},
"web-compiler": {
"electron": [],
"web": [],
"common": []
},
"common": []
};
console.log('deps.json生成中...');
outputConfig['electron'] = [
...outputConfig['electron'],
...scan(path.join(needBuildDir, config['electron'].dirName), fileIgnore, outputConfig)
];
outputConfig['web'] = [
...outputConfig['web'],
...scan(path.join(needBuildDir, config['web'].dirName), fileIgnore, outputConfig)
];
outputConfig['web-socket'].common = [
...outputConfig['web-socket'].common,
...scan(path.join(needBuildDir, config['web-socket'].dirName), fileIgnore, outputConfig)
];
outputConfig['web-compiler'].common = [
...outputConfig['web-compiler'].common,
...scan(path.join(needBuildDir, config['web-compiler'].dirName), fileIgnore, outputConfig)
];
outputConfig['common'] = [
...outputConfig['common'],
...scan(path.join(needBuildDir, config['common'].dirName), fileIgnore, outputConfig)
];
fs.writeFileSync(path.join(needBuildDir, 'deps.json'), formatJson(JSON.stringify(outputConfig)));
console.log(path.join(needBuildDir, 'deps.json') + '生成成功');
}
}
generateDeps();
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。