A "simple" Snake, done as my final JS class project back in DUT https://snek.s.codinget.me
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
Snek/mergejs.js

31 lines
804 B

5 years ago
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;
5 years ago
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}(module) {
5 years ago
'use strict';
${modSource}
});
`);
});
fs.writeSync(1, outputCode.map(a => a.trim()).join('\n'));