parent
faead71ba7
commit
dd30640eef
@ -0,0 +1,29 @@ |
|||||||
|
const fs=require('fs'); |
||||||
|
|
||||||
|
const requireFn=` |
||||||
|
const require=function require(name) { |
||||||
|
if(require.cache[name]) return require.cache[name]; |
||||||
|
if(!require.source[name]) throw new Error("Cannot require "+name+": not found"); |
||||||
|
require.cache[name]=require.source[name]() || true; |
||||||
|
return require.cache[name]; |
||||||
|
}; |
||||||
|
require.cache=Object.create(null); |
||||||
|
require.source=Object.create(null); |
||||||
|
window.require=require; |
||||||
|
`;
|
||||||
|
|
||||||
|
let outputCode=[requireFn]; |
||||||
|
process.argv |
||||||
|
.slice(2) |
||||||
|
.map(a => [a, a.match(/([a-zA-Z_][a-zA-Z0-9_-]*).js$/)[1]]) |
||||||
|
.forEach(([modFile, modName]) => { |
||||||
|
const modSource=fs.readFileSync(modFile, 'utf8'); |
||||||
|
outputCode.push(` |
||||||
|
require.source['${modName}']=(a => a.bind(a)) (function ${modName}() { |
||||||
|
'use strict'; |
||||||
|
${modSource} |
||||||
|
}); |
||||||
|
`);
|
||||||
|
}); |
||||||
|
|
||||||
|
fs.writeSync(1, outputCode.join('\n')); |
Loading…
Reference in new issue