Created
March 1, 2021 16:09
-
-
Save gabrielperales/7cc684742dfecd79bfdbc43497888ed0 to your computer and use it in GitHub Desktop.
regenerate sourcemap
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
const { constants } = require('fs'); | |
const { readFile, writeFile, mkdir, access } = require('fs').promises; | |
const { dirname, basename, sep } = require('path'); | |
const args = process.argv.slice(2); | |
const [file] = args; | |
access(file, constants.R_OK).then(async (error) => { | |
if (error) { | |
return console.log(error); | |
} | |
const fileContent = await readFile(file); | |
const json = JSON.parse(fileContent); | |
const {sources} = json; | |
sources.forEach(async (source, index) => { | |
const dir = dirname(source); | |
try { | |
await access(dir, constants.F_OK); | |
} catch (error) { | |
console.log('creating directory: ', dir); | |
await mkdir(dir, { recursive: true, mode: 0755 }); | |
} | |
const data = source.split(sep); | |
const file = basename(source); | |
console.log(`processing file: ${file}`); | |
await writeFile(`${dir}${sep}${file}`, json.sourcesContent[index], {flag: 'w+'}); | |
console.log(`file processed: ${file}`); | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment