Update: 更新板卡
This commit is contained in:
@@ -2,8 +2,9 @@ const fs_extra = require('fs-extra');
|
||||
const fs_plus = require('fs-plus');
|
||||
const fs = require('fs');
|
||||
const path = require('path');
|
||||
const shortid = require('shortid');
|
||||
|
||||
const getExamples = (dirPath) => {
|
||||
const getExamples = (dirPath, convertExample = false) => {
|
||||
let examples = {};
|
||||
if (!fs_plus.isDirectorySync(dirPath)) {
|
||||
return examples;
|
||||
@@ -12,29 +13,43 @@ const getExamples = (dirPath) => {
|
||||
for (let data of dataList) {
|
||||
let dataPath = path.resolve(dirPath, data);
|
||||
if (fs_plus.isDirectorySync(dataPath)) {
|
||||
const children = getExamples(dataPath);
|
||||
let id = data;
|
||||
if (convertExample) {
|
||||
id = shortid.generate();
|
||||
const newDataPath = path.resolve(dirPath, id);
|
||||
fs.renameSync(dataPath, newDataPath);
|
||||
dataPath = newDataPath;
|
||||
}
|
||||
const children = getExamples(dataPath, convertExample);
|
||||
if (!Object.keys(children).length) {
|
||||
continue;
|
||||
}
|
||||
examples[data] = {
|
||||
examples[id] = {
|
||||
...children,
|
||||
'__file__': false,
|
||||
'__name__': data
|
||||
};
|
||||
} else {
|
||||
const extname = path.extname(data);
|
||||
if (extname === '.mix') {
|
||||
examples[data] = {
|
||||
'__file__': true,
|
||||
'__name__': data
|
||||
};
|
||||
if (extname !== '.mix') {
|
||||
continue;
|
||||
}
|
||||
let id = data;
|
||||
if (convertExample) {
|
||||
id = shortid.generate() + extname;
|
||||
const newDataPath = path.resolve(dirPath, id);
|
||||
fs.renameSync(dataPath, newDataPath);
|
||||
dataPath = newDataPath;
|
||||
}
|
||||
examples[id] = {
|
||||
'__file__': true,
|
||||
'__name__': data
|
||||
};
|
||||
}
|
||||
}
|
||||
return examples;
|
||||
}
|
||||
|
||||
|
||||
const ORIGIN_DIR = process.cwd();
|
||||
const DEFAULT_SRC_DIR = path.resolve(ORIGIN_DIR, 'boards/default_src');
|
||||
|
||||
@@ -55,4 +70,25 @@ if (fs_plus.isDirectorySync(DEFAULT_SRC_DIR)) {
|
||||
spaces: ' '
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
const DEFAULT_DIR = path.resolve(ORIGIN_DIR, 'boards/default');
|
||||
|
||||
if (fs_plus.isDirectorySync(DEFAULT_DIR)) {
|
||||
const names = fs.readdirSync(DEFAULT_DIR);
|
||||
for (let name of names) {
|
||||
const now = path.resolve(DEFAULT_DIR, name);
|
||||
if (!fs_plus.isDirectorySync(now)) {
|
||||
continue;
|
||||
}
|
||||
const examplesPath = path.resolve(now, 'examples');
|
||||
if (!fs_plus.isDirectorySync(examplesPath)) {
|
||||
continue;
|
||||
}
|
||||
let outputPath = path.resolve(examplesPath, 'map.json');
|
||||
let output = getExamples(examplesPath, true);
|
||||
fs_extra.outputJsonSync(outputPath, output, {
|
||||
spaces: ' '
|
||||
});
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user