Forked from banyudu/extract-source-from-source-map.ts
Created
December 17, 2020 08:51
-
-
Save haipeng/e499cd18d815d642064c5e6dc8145242 to your computer and use it in GitHub Desktop.
Extract source code from source map
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
#!/usr/bin/env ts-node | |
import * as fs from 'fs' | |
import * as path from 'path' | |
import { promisify } from 'util' | |
import { SourceMapConsumer } from 'source-map' | |
const writeFile = promisify(fs.writeFile) | |
const mapFile = process.argv[2] | |
if (!mapFile) { | |
console.error('no input file given') | |
process.exit(1) | |
} | |
const mapFileContent = fs.readFileSync(mapFile, 'utf-8') | |
const outputDir = path.join(__dirname, 'output') | |
fs.mkdirSync(outputDir, { | |
recursive: true | |
}) | |
new SourceMapConsumer(mapFileContent).then(consumer => { | |
Promise.all(consumer.sources.map(async (source) => { | |
const content = consumer.sourceContentFor(source) | |
const outputPath = path.join(outputDir, source) | |
fs.mkdirSync(path.dirname(outputPath), { recursive: true }) | |
return writeFile(outputPath, content) | |
})) | |
}).catch(console.error) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment