feat(directory): add directory.json for index page
This commit is contained in:
18
lib/directory.js
Normal file
18
lib/directory.js
Normal file
@@ -0,0 +1,18 @@
|
||||
import path from 'path'
|
||||
import { writeSync, copy } from './file.js'
|
||||
|
||||
export default function (config, rootDir) {
|
||||
const targetFolder = path.join(rootDir, config.folder.release, "_assets");
|
||||
const sourceFolder = path.join(rootDir, config.folder.operator);
|
||||
const filesToCopy = [];
|
||||
const directoryJson = []
|
||||
for (const [key, value] of Object.entries(config.operators)) {
|
||||
filesToCopy.push(key);
|
||||
directoryJson.push(value);
|
||||
}
|
||||
writeSync(JSON.stringify(directoryJson, null), path.join(targetFolder, "directory.json"))
|
||||
filesToCopy.forEach((key) => {
|
||||
const filename = `${config.operators[key].filename}.json`;
|
||||
copy(path.join(sourceFolder, key, filename), path.join(targetFolder, filename))
|
||||
})
|
||||
}
|
||||
@@ -6,6 +6,11 @@ export async function write(content, filePath) {
|
||||
return await fsP.writeFile(filePath, content, { flag: 'w' })
|
||||
}
|
||||
|
||||
export function writeSync(content, filePath) {
|
||||
mkdir(path.dirname(filePath))
|
||||
return fs.writeFileSync(filePath, content, { flag: 'w' })
|
||||
}
|
||||
|
||||
export async function read(filePath, encoding = 'utf8') {
|
||||
return await fsP.readFile(filePath, encoding, { flag: 'r' })
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user