You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
88 lines
1.9 KiB
JavaScript
88 lines
1.9 KiB
JavaScript
#! /usr/bin/env node
|
|
|
|
const {VM} = require('vm2');
|
|
const {readFileSync} = require('fs');
|
|
|
|
const gens = JSON.parse(readFileSync('generators/generators.js').toString());
|
|
|
|
const run = (info) =>
|
|
{
|
|
// console.log(info);
|
|
const js = readFileSync(`generators/${info.file}`).toString();
|
|
const code = `
|
|
class FakeNode
|
|
{
|
|
appendChild() {}
|
|
removeChild() {}
|
|
setAttribute() {}
|
|
};
|
|
|
|
let radio_value;
|
|
const $ = () => ({ css: () => {}, each: () => {}, val: () => radio_value,
|
|
ready: () => {}, is: () => false /* todo */ });
|
|
|
|
// let's implement jquery, e-a-e-a-o
|
|
$.inArray = (val, array, from) =>
|
|
{
|
|
for (let i = from; i < array.length; ++i)
|
|
if (array[i] === val) return i;
|
|
return -1;
|
|
};
|
|
|
|
$.merge = (a, b) =>
|
|
{
|
|
for (const x in b) a.push(x);
|
|
return a;
|
|
};
|
|
|
|
const document =
|
|
{
|
|
createElement: () => new FakeNode(),
|
|
getElementById: () => new FakeNode(),
|
|
createTextNode: log,
|
|
};
|
|
const testSwear = () => {};
|
|
|
|
// sometimes used without initializing
|
|
// not let, because they are sometimes declared...
|
|
rnd = 0; rnd0 = 0; rnd1 = 0; rnd2 = 0; rnd3 = 0; rnd4 = 0; rnd5 = 0; rnd6 = 0;
|
|
rnd7 = 0; rnd8 = 0; rnd9 = 0; rnd10 = 0; rnd11 = 0; first = 1;
|
|
// also typo
|
|
rmd3 = 0;
|
|
|
|
${js}
|
|
triggered = 1; // prevent some easter egg shit
|
|
${info.call}
|
|
`;
|
|
new VM({
|
|
sandbox: { log: console.log }, timeout: 1000,
|
|
eval: false, wasm: false, require: false, nesting: false,
|
|
}).run(code);
|
|
};
|
|
|
|
let args = process.argv.slice(2);
|
|
if (args.length === 0)
|
|
{
|
|
const print_rec = (path, rem) =>
|
|
{
|
|
if (rem.file)
|
|
console.log(path.join(' > '));
|
|
else
|
|
for (const k in rem)
|
|
print_rec(path.concat([k]), rem[k]);
|
|
};
|
|
print_rec([], gens.paths);
|
|
return;
|
|
}
|
|
|
|
if (args.length === 1 && args[0].indexOf('>') !== -1)
|
|
args = args[0].split(/[ \t]*>[ \t]*/);
|
|
|
|
let x = gens.paths;
|
|
for (const p of args)
|
|
{
|
|
x = x[p];
|
|
if (!x) throw `Unknown item ${p}`;
|
|
}
|
|
run(x);
|