初始化提交
This commit is contained in:
47
scripts/build-boards.js
Normal file
47
scripts/build-boards.js
Normal file
@@ -0,0 +1,47 @@
|
||||
const shell = require('shelljs');
|
||||
const fs = require('fs');
|
||||
const fs_plus = require('fs-plus');
|
||||
const path = require('path');
|
||||
const { Command, Option } = require('commander');
|
||||
|
||||
const program = new Command();
|
||||
|
||||
program
|
||||
.addOption(new Option('-t, --type <string>', 'boards type', 'micropython').choices([
|
||||
'all', 'arduino', 'micropython', 'python'
|
||||
]));
|
||||
|
||||
program.parse();
|
||||
|
||||
const options = program.opts();
|
||||
|
||||
let ignore = ['arduino', 'micropython', 'python'];
|
||||
|
||||
if (ignore.includes(options.type)) {
|
||||
ignore.splice(ignore.indexOf(options.type), 1);
|
||||
} else if (options.type === 'all') {
|
||||
ignore = [];
|
||||
}
|
||||
|
||||
const ORIGIN_DIR = process.cwd();
|
||||
const DEFAULT_SRC_DIR = path.resolve(ORIGIN_DIR, 'boards/default_src');
|
||||
|
||||
if (fs_plus.isDirectorySync(DEFAULT_SRC_DIR)) {
|
||||
const names = fs.readdirSync(DEFAULT_SRC_DIR);
|
||||
for (let name of names) {
|
||||
let splitName = name.split('_');
|
||||
if (ignore.includes(splitName[0])) {
|
||||
continue;
|
||||
}
|
||||
const now = path.resolve(DEFAULT_SRC_DIR, name);
|
||||
if (!fs_plus.isDirectorySync(now)) {
|
||||
continue;
|
||||
}
|
||||
const packagejsonPath = path.resolve(now, 'package.json');
|
||||
if (!fs_plus.isFileSync(packagejsonPath)) {
|
||||
continue;
|
||||
}
|
||||
shell.cd(now);
|
||||
shell.exec(`npm run build:prod`);
|
||||
}
|
||||
}
|
||||
81
scripts/build-deps.js
Normal file
81
scripts/build-deps.js
Normal file
@@ -0,0 +1,81 @@
|
||||
const fs = require('fs');
|
||||
const fs_extra = require('fs-extra');
|
||||
const fs_plus = require('fs-plus');
|
||||
const path = require('path');
|
||||
|
||||
const scanDir = (dirPath, ignore, rootPath) => {
|
||||
let googList = [];
|
||||
const dirName = path.basename(dirPath);
|
||||
const dirIgnore = ignore?.dir ?? [];
|
||||
const fileIgnore = ignore?.file ?? [];
|
||||
if (!fs_plus.isDirectorySync(dirPath) || dirIgnore.includes(dirPath)) {
|
||||
return googList;
|
||||
}
|
||||
|
||||
let nameList = fs.readdirSync(dirPath);
|
||||
for (let i = 0; i < nameList.length; i++) {
|
||||
let childPath = path.join(dirPath, nameList[i]);
|
||||
if (fs_plus.isFileSync(childPath)) {
|
||||
let googObj = scanFile(childPath, ignore, rootPath);
|
||||
if (!googObj) {
|
||||
continue;
|
||||
}
|
||||
googList.push(googObj);
|
||||
} else {
|
||||
googList = [...googList, ...scanDir(childPath, ignore, rootPath)];
|
||||
}
|
||||
}
|
||||
|
||||
return googList;
|
||||
}
|
||||
|
||||
const scanFile = (filePath, ignore, rootPath) => {
|
||||
const fileIgnore = ignore?.file ?? [];
|
||||
if (fileIgnore.includes(filePath)) {
|
||||
return null;
|
||||
}
|
||||
let jsStr = fs.readFileSync(filePath, 'utf8');
|
||||
let googObj = {};
|
||||
googObj.path = '/' + path.relative(rootPath, filePath).replaceAll('\\', '/');
|
||||
googObj.require = match('goog.require', jsStr);
|
||||
googObj.provide = match("goog.provide", jsStr);
|
||||
if (googObj.require || googObj.provide) {
|
||||
if (!googObj.require) {
|
||||
googObj.require = [];
|
||||
}
|
||||
if (!googObj.provide) {
|
||||
googObj.provide = [];
|
||||
}
|
||||
} else {
|
||||
googObj = null;
|
||||
}
|
||||
return googObj;
|
||||
}
|
||||
|
||||
const match = (type, jsStr) => {
|
||||
let list = [];
|
||||
if (type === 'goog.require') {
|
||||
list = jsStr.match(/(?<=goog.require[\s]*\(["|'])[^"|']+(?=["|'][\s]*\))/g);
|
||||
} else {
|
||||
list = jsStr.match(/(?<=goog.provide[\s]*\(["|'])[^"|']+(?=["|'][\s]*\))/g);
|
||||
}
|
||||
if (list) {
|
||||
list = unique(list);
|
||||
}
|
||||
return list;
|
||||
}
|
||||
|
||||
// 数组去重
|
||||
const unique = (list) => {
|
||||
return Array.from(new Set(list));
|
||||
}
|
||||
|
||||
const generate = (needBuildDir, ignore) => {
|
||||
let outputConfig = [];
|
||||
outputConfig = scanDir(needBuildDir, ignore, needBuildDir);
|
||||
return outputConfig;
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
generate: generate
|
||||
};
|
||||
58
scripts/build-examples.js
Normal file
58
scripts/build-examples.js
Normal file
@@ -0,0 +1,58 @@
|
||||
const fs_extra = require('fs-extra');
|
||||
const fs_plus = require('fs-plus');
|
||||
const fs = require('fs');
|
||||
const path = require('path');
|
||||
|
||||
const getExamples = (dirPath) => {
|
||||
let examples = {};
|
||||
if (!fs_plus.isDirectorySync(dirPath)) {
|
||||
return examples;
|
||||
}
|
||||
const dataList = fs.readdirSync(dirPath);
|
||||
for (let data of dataList) {
|
||||
let dataPath = path.resolve(dirPath, data);
|
||||
if (fs_plus.isDirectorySync(dataPath)) {
|
||||
const children = getExamples(dataPath);
|
||||
if (!Object.keys(children).length) {
|
||||
continue;
|
||||
}
|
||||
examples[data] = {
|
||||
...children,
|
||||
'__file__': false,
|
||||
'__name__': data
|
||||
};
|
||||
} else {
|
||||
const extname = path.extname(data);
|
||||
if (extname === '.mix') {
|
||||
examples[data] = {
|
||||
'__file__': true,
|
||||
'__name__': data
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
return examples;
|
||||
}
|
||||
|
||||
|
||||
const ORIGIN_DIR = process.cwd();
|
||||
const DEFAULT_SRC_DIR = path.resolve(ORIGIN_DIR, 'boards/default_src');
|
||||
|
||||
if (fs_plus.isDirectorySync(DEFAULT_SRC_DIR)) {
|
||||
const names = fs.readdirSync(DEFAULT_SRC_DIR);
|
||||
for (let name of names) {
|
||||
const now = path.resolve(DEFAULT_SRC_DIR, name);
|
||||
if (!fs_plus.isDirectorySync(now)) {
|
||||
continue;
|
||||
}
|
||||
const examplesPath = path.resolve(now, 'origin/examples');
|
||||
if (!fs_plus.isDirectorySync(examplesPath)) {
|
||||
continue;
|
||||
}
|
||||
let outputPath = path.resolve(examplesPath, 'map.json');
|
||||
let output = getExamples(examplesPath);
|
||||
fs_extra.outputJsonSync(outputPath, output, {
|
||||
spaces: ' '
|
||||
});
|
||||
}
|
||||
}
|
||||
48
scripts/deps-gen.js
Normal file
48
scripts/deps-gen.js
Normal file
@@ -0,0 +1,48 @@
|
||||
const fs = require('fs');
|
||||
const fs_extra = require('fs-extra');
|
||||
const fs_plus = require('fs-plus');
|
||||
const build_deps = require('./build-deps.js');
|
||||
const path = require('path');
|
||||
|
||||
const config = {
|
||||
"workPath": __dirname,
|
||||
"fileIgnore": [
|
||||
path.resolve(__dirname, '../common/modules/mixly-modules/mixly.min.js')
|
||||
],
|
||||
"dirIgnore": []
|
||||
};
|
||||
|
||||
const needBuildDirList = [
|
||||
path.resolve(__dirname, '../mixly-sw/mixly-modules/'),
|
||||
path.resolve(__dirname, '../common/modules/mixly-modules/')
|
||||
];
|
||||
|
||||
const generateDeps = () => {
|
||||
for (let needBuildDir of needBuildDirList) {
|
||||
let fileIgnore = [];
|
||||
let dirIgnore = [];
|
||||
if (typeof config.fileIgnore === 'object') {
|
||||
for (let data of config.fileIgnore) {
|
||||
fileIgnore.push(path.resolve(needBuildDir, data));
|
||||
}
|
||||
}
|
||||
if (typeof config.dirIgnore === 'object') {
|
||||
for (let data of config.dirIgnore) {
|
||||
dirIgnore.push(path.resolve(needBuildDir, data));
|
||||
}
|
||||
}
|
||||
let outputConfig = [];
|
||||
console.log('deps.json生成中...');
|
||||
const ignore = {
|
||||
dir: dirIgnore,
|
||||
file: fileIgnore
|
||||
};
|
||||
outputConfig = build_deps.generate(needBuildDir, ignore);
|
||||
fs_extra.outputJsonSync(path.join(needBuildDir, 'deps.json'), outputConfig, {
|
||||
spaces: ' '
|
||||
});
|
||||
console.log(path.join(needBuildDir, 'deps.json') + '生成成功');
|
||||
}
|
||||
}
|
||||
|
||||
generateDeps();
|
||||
Reference in New Issue
Block a user