Skip to content

Instantly share code, notes, and snippets.

@gabrielperales
Created March 1, 2021 16:09
Show Gist options
  • Save gabrielperales/7cc684742dfecd79bfdbc43497888ed0 to your computer and use it in GitHub Desktop.
Save gabrielperales/7cc684742dfecd79bfdbc43497888ed0 to your computer and use it in GitHub Desktop.
regenerate sourcemap
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