-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
88330e9
commit 05bb52a
Showing
6 changed files
with
6,044 additions
and
7,089 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
#!/usr/bin/env node | ||
import fs from 'node:fs' | ||
import path from 'node:path' | ||
|
||
function copyFile(file, location) { | ||
fs.mkdirSync(path.dirname(file), { | ||
mode: 0x1ed, | ||
recursive: true, | ||
}) | ||
fs.writeFileSync(file, fs.readFileSync(location)) | ||
} | ||
|
||
function mergeDirs(src, dest, overwrite = true) { | ||
const files = fs.readdirSync(src) | ||
|
||
files.forEach((file) => { | ||
const srcFile = path.join(src, file) | ||
const destFile = path.join(dest, file) | ||
const stats = fs.lstatSync(srcFile) | ||
|
||
if(stats.isDirectory()) { | ||
mergeDirs(srcFile, destFile) | ||
} else { | ||
if(overwrite || !fs.existsSync(destFile)) { | ||
copyFile(destFile, srcFile) | ||
} | ||
// skip when not overwrite and file exists | ||
} | ||
}) | ||
} | ||
|
||
const argv = process.argv.slice(2) | ||
|
||
const helpString = `Usage: merge-dirs source destination [--overwrite]` | ||
if(argv.length < 2 || argv.includes('--help')) { | ||
console.log(helpString) | ||
process.exit() | ||
} | ||
|
||
mergeDirs(argv[0], argv[1], argv[2] === '--overwrite') |
Oops, something went wrong.