|
|
|
@ -70,19 +70,32 @@ async function *get_files(root) {
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export const aug = async run => {
|
|
|
|
|
for (const query of process.argv.slice(2)) {
|
|
|
|
|
for await (const path of get_files(query)) {
|
|
|
|
|
const out = await run(query, path.slice(query.length + 1), type => new Promise(res => {
|
|
|
|
|
const hash = crypto.createHash(type);
|
|
|
|
|
fs.createReadStream(path).once('end', () => res(hash.digest())).pipe(hash);
|
|
|
|
|
}));
|
|
|
|
|
if (out) {
|
|
|
|
|
console.log(`${path} -> ${query}/${out.dest}`);
|
|
|
|
|
const aug_process = async (dir, query, run) => {
|
|
|
|
|
for await (const path of get_files(dir)) {
|
|
|
|
|
const out = await run(query, path.slice(dir.length + 1), type => new Promise(res => {
|
|
|
|
|
const hash = crypto.createHash(type);
|
|
|
|
|
fs.createReadStream(path).once('end', () => res(hash.digest())).pipe(hash);
|
|
|
|
|
}));
|
|
|
|
|
if (out) {
|
|
|
|
|
if (await fs.promises.access(`${dir}/${out.dest}`).then(() => true, () => false)) {
|
|
|
|
|
console.log(`${path} -> [deleted]`);
|
|
|
|
|
await fs.promises.unlink(path);
|
|
|
|
|
} else {
|
|
|
|
|
console.log(`${path} -> ${dir}/${out.dest}`);
|
|
|
|
|
const date_obj = new Date(out.date);
|
|
|
|
|
await fs.promises.utimes(path, date_obj, date_obj);
|
|
|
|
|
await fs.promises.rename(path, `${query}/${out.dest}`);
|
|
|
|
|
await fs.promises.rename(path, `${dir}/${out.dest}`);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
export const aug = async run => {
|
|
|
|
|
if (process.argv.length === 2) {
|
|
|
|
|
await aug_process('.', null, run);
|
|
|
|
|
} else {
|
|
|
|
|
for (const arg of process.argv.slice(2)) {
|
|
|
|
|
await aug_process(arg, get_query(arg), run);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|