Created
August 23, 2018 00:35
-
-
Save MonirAbuHilal/99d254851760c7bf6b6c886f3b3a9b5c to your computer and use it in GitHub Desktop.
A nodejs script for extracting source files from a sourcemap (.js.map) file
This file contains hidden or 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
| // yarn init . | |
| // yarn add mkdirp | |
| // node ./extract-sourcemap.js ./app-bundle.js.map | |
| const fs = require("fs"); | |
| const path = require("path"); | |
| const mkdirp = require("mkdirp"); | |
| const OUTPUT_DIRECTORY = "./extracted/"; | |
| const args = process.argv.slice(2); | |
| const sourceMapFilePath = args[0]; | |
| const parsedSourceMap = JSON.parse(fs.readFileSync(sourceMapFilePath, "utf8")); | |
| const sources = parsedSourceMap.sources; | |
| const contents = parsedSourceMap.sourcesContent; | |
| for (let index = 0; index < sources.length; index++) { | |
| const fileName = sources[index]; | |
| const fileContents = contents[index]; | |
| console.log(fileName); | |
| const filePath = `${OUTPUT_DIRECTORY}${fileName}`; | |
| const fileDirectory = path.dirname(filePath); | |
| mkdirp.sync(fileDirectory); | |
| fs.writeFileSync(filePath, fileContents); | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment