Skip to content

Instantly share code, notes, and snippets.

@Yash-Singh1
Forked from Sturtuk/extract_mapjs.php
Created August 9, 2024 05:46
Show Gist options
  • Save Yash-Singh1/6198c27acb6966b290ba2024c0e45e38 to your computer and use it in GitHub Desktop.
Save Yash-Singh1/6198c27acb6966b290ba2024c0e45e38 to your computer and use it in GitHub Desktop.
Extract source code & directories from the javascript .map files (modified to support maps with sections)
<?php
/**
* Created by PhpStorm.
* User: edwinsturt
* Date: 2020-06-24
* Time: 00:45
*/
$file = 'main.js.map';
if(file_exists($file)) {
$json = json_decode(file_get_contents($file));
foreach ($json->sections as $index => $section) {
$directories = [];
foreach ($section->map->sources as $index => $source) {
$dir = dirname($source);
if (!is_dir($dir)) {
mkdir($dir, 0755, true);
}
$data = explode('/', $source);
$file = end($data);
file_put_contents($dir . "/" . $file, $section->map->sourcesContent[$index]);
$files[] = $dir . "/" . $file;
}
echo "<pre>All Source codes has been extracted from map file ";
print_r($files);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment