1
Fork 0

initial version

This commit is contained in:
Conduitry 2022-07-20 08:38:57 -04:00
parent dcbf859ba3
commit d2dd00d193
2 changed files with 46 additions and 0 deletions

43
dir-timestamp.js Executable file
View File

@ -0,0 +1,43 @@
#!/usr/bin/env node
import { readdirSync, statSync, utimesSync } from 'node:fs';
if (process.argv.length < 3) {
console.log('Arguments: <directory>...');
process.exit(1);
}
function recurse(path) {
const stats = statSync(path);
if (stats.isFile()) {
return stats.mtimeMs;
}
if (stats.isDirectory()) {
let max = 0;
readdirSync(path).forEach(child => {
max = Math.max(max, recurse(path + '/' + child));
});
if (max === 0) {
throw new Error(`Empty directory: ${path}`);
}
utimesSync(path, max / 1000, max / 1000);
return max;
}
throw new Error(`Unexpected type: ${path}`);
}
let had_errors = false;
for (const dir of process.argv.slice(2)) {
try {
recurse(dir.replace(/\/$/, ''));
console.log(`Done: ${dir}`);
} catch (err) {
console.log(`${err.message}\nAborting: ${dir}`);
had_errors = true;
}
}
if (had_errors) {
process.exit(1);
}

3
package.json Normal file
View File

@ -0,0 +1,3 @@
{
"type": "module"
}