mirror of
https://github.com/DustinBrett/daedalOS.git
synced 2025-12-06 12:20:20 +01:00
38 lines
823 B
JavaScript
38 lines
823 B
JavaScript
/* eslint @typescript-eslint/no-var-requires: off */
|
|
const fs = require('fs');
|
|
|
|
const cwd = process.cwd();
|
|
|
|
const getFileData = (filePath) => {
|
|
const { size, mtime } = fs.statSync(filePath);
|
|
|
|
return {
|
|
size,
|
|
mtime: new Date(mtime)
|
|
};
|
|
};
|
|
|
|
const parseDirectory = (index, sourcePath = cwd) => {
|
|
return Object.keys(index).reduce((acc, entry) => {
|
|
const filePath = `${sourcePath}/${entry}`;
|
|
|
|
return {
|
|
...acc,
|
|
...(index[entry]
|
|
? parseDirectory(index[entry], filePath)
|
|
: { [filePath.replace(cwd, '')]: getFileData(filePath) })
|
|
};
|
|
}, {});
|
|
};
|
|
|
|
const { argv: [, , fileArg, saveFileArg] = [] } = process || {};
|
|
|
|
fs.writeFileSync(
|
|
saveFileArg || fileArg,
|
|
JSON.stringify(
|
|
parseDirectory(
|
|
JSON.parse(fs.readFileSync(fileArg || 'index.json').toString())
|
|
)
|
|
)
|
|
);
|