Created
December 19, 2019 00:32
-
-
Save eldoy/92ceaa99de84951cd207466300bc993f to your computer and use it in GitHub Desktop.
Replace in file recursively
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
#!/usr/bin/env node | |
const fs = require('fs') | |
const path = require('path') | |
const mode = process.argv[2] | |
const exec = require('child_process').execSync | |
const root = process.cwd() | |
const matches = [ "require('presang')", "require('../../index.js')" ] | |
function replaceIn (from, to) { | |
from = matches[from] | |
to = matches[to] | |
function replace (dir) { | |
fs.readdirSync(dir).forEach(function (f) { | |
f = path.join(dir, f) | |
if (fs.lstatSync(f).isFile()) { | |
fs.writeFileSync( | |
f, fs.readFileSync(f, 'utf-8').replace(from, to) | |
) | |
} else { | |
replace(f) | |
} | |
}) | |
} | |
replace(path.join(root, 'app')) | |
} | |
if (mode === 'dev') { | |
replaceIn(0, 1) | |
} else if (mode === 'dist') { | |
replaceIn(1, 0) | |
} else { | |
console.log('Usage: ./scripts/setmode.js dev|dist') | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment