feat: working through the dynamic testing portion of ligmata
This commit is contained in:
parent
8859e43ac9
commit
90fdc7aa06
9 changed files with 113 additions and 58 deletions
59
scripts/generate
Executable file
59
scripts/generate
Executable file
|
|
@ -0,0 +1,59 @@
|
|||
#!/usr/bin/env node
|
||||
const fs = require("fs");
|
||||
const path = require("path");
|
||||
const config = require("../ligma.config");
|
||||
const dsa = require("./dsa");
|
||||
|
||||
const src_path = path.join(__dirname, "..", "src");
|
||||
let day = 1;
|
||||
|
||||
try {
|
||||
day = +fs.readdirSync(src_path).
|
||||
filter(i => i.includes("day")).
|
||||
sort((a, b) => {
|
||||
return +b.substring(3) - a.substring(3);
|
||||
})[0].substring(3) + 1;
|
||||
|
||||
if (isNaN(day)) {
|
||||
console.log("day is nan");
|
||||
day = 1;
|
||||
}
|
||||
} catch (e) {
|
||||
console.log("error", e.message);
|
||||
console.log("day is 1");
|
||||
day = 1;
|
||||
}
|
||||
|
||||
const day_name = `day${day}`;
|
||||
const day_path = path.join(src_path, day_name);
|
||||
try { fs.unlinkSync(day_path); } catch (e) { }
|
||||
try { fs.mkdirSync(day_path); } catch (e) { }
|
||||
|
||||
function create_class(item) {
|
||||
fs.writeFileSync(path.join(day_path, item.name), `export default class ${item.className} {
|
||||
constructor() {
|
||||
|
||||
}
|
||||
}`);
|
||||
}
|
||||
|
||||
function create_function(item) {
|
||||
fs.writeFileSync(path.join(day_path, item.name), `export default function ${item.fn}(${item.args}): ${item.return} {
|
||||
|
||||
}`);
|
||||
}
|
||||
|
||||
config.dsa.forEach(ds => {
|
||||
const item = dsa[ds];
|
||||
if (item.type === "class") {
|
||||
create_class(item);
|
||||
} else {
|
||||
create_function(item);
|
||||
}
|
||||
});
|
||||
|
||||
const align = require("./align-configs");
|
||||
align.jest(day_name);
|
||||
align.ts_config(day_name);
|
||||
align.package_json(config, day_name);
|
||||
|
||||
Loading…
Add table
Add a link
Reference in a new issue