Last active
August 23, 2019 10:42
-
-
Save zhangtaii/e5d87a0fbb2fa9263a722a6c16be18a8 to your computer and use it in GitHub Desktop.
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
var fs = require("fs"); | |
var path = require("path"); | |
var inputFile = process.argv[2], | |
input = fs.readFileSync(inputFile, "utf8"), | |
start = input.indexOf("__d("), | |
end = input.indexOf("__r("), | |
code = input.substring(start, end); | |
function __d(factory, name, deps) { | |
var output = []; | |
var filename = './output/' + name + '.js'; | |
var dirname = path.dirname(filename); | |
output.push("var dependencyMap = " ); | |
output.push(JSON.stringify(deps)); | |
output.push("\n"); | |
output.push("var moduleId"); | |
output.push(JSON.stringify(name)); | |
output.push("="); | |
output.push(factory.toString()); | |
if (!fs.existsSync(dirname)) { | |
fs.mkdirSync(dirname); | |
} | |
fs.writeFileSync(filename, output.join("")); | |
} | |
(new Function("__d", code))(__d); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment