初始化提交

This commit is contained in:
王立帮
2024-07-19 10:16:00 +08:00
parent 4c7b571f20
commit 4a2d56dcc4
7084 changed files with 741212 additions and 63 deletions

58
scripts/build-examples.js Normal file
View 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: ' '
});
}
}