2024-02-24 21:30:30 +00:00
|
|
|
//import * as babelparser from "../babel/packages/babel-parser";
|
|
|
|
import * as babelparser from "@babel/parser";
|
|
|
|
//import core from "../babel/packages/babel-core";
|
|
|
|
import { parse_with_plugins } from "./parser/parse";
|
2024-05-11 14:09:03 +00:00
|
|
|
import {
|
|
|
|
SelfHostedRecipe,
|
|
|
|
TransformRecipe,
|
|
|
|
transform,
|
|
|
|
} from "./transform/transform";
|
2024-05-23 11:46:40 +00:00
|
|
|
import { readdir } from "node:fs/promises";
|
2024-05-11 14:09:03 +00:00
|
|
|
import { parseJSTQL } from "./langium/langiumRunner";
|
2024-05-19 17:53:14 +00:00
|
|
|
|
|
|
|
const dir = "../prettier/src";
|
|
|
|
|
2024-05-27 22:22:40 +00:00
|
|
|
const path = "test_files/do_test.js";
|
2024-02-24 21:30:30 +00:00
|
|
|
const file = Bun.file(path);
|
|
|
|
const codeFromFile = await file.text();
|
|
|
|
const main = async () => {
|
2024-05-11 14:09:03 +00:00
|
|
|
//transform(selfHostedTransformExampleMultiStmt, codeFromFile);
|
2024-05-27 22:22:40 +00:00
|
|
|
|
2024-05-23 11:46:40 +00:00
|
|
|
/*
|
2024-05-19 17:53:14 +00:00
|
|
|
console.log(codeFromFile);
|
2024-05-11 14:09:03 +00:00
|
|
|
const jstql_file =
|
2024-05-27 22:22:40 +00:00
|
|
|
"/home/rolfmg/Coding/Master/didactic-chainsaw/dsl_files/do.jstql";
|
2024-05-11 14:09:03 +00:00
|
|
|
const test_file = Bun.file(jstql_file);
|
|
|
|
const test_JSTQL = await test_file.text();
|
2024-05-12 18:06:37 +00:00
|
|
|
let proposals = await parseJSTQL(test_JSTQL);
|
|
|
|
|
2024-05-23 11:46:40 +00:00
|
|
|
let [code, count] = transform(proposals[0].cases, codeFromFile);
|
2024-05-27 22:22:40 +00:00
|
|
|
await Bun.write("output_files/output_do.js", code);
|
2024-05-23 11:46:40 +00:00
|
|
|
return;
|
|
|
|
*/
|
2024-05-27 22:22:40 +00:00
|
|
|
let basepathExamplesJSFiles = "../react";
|
2024-05-23 11:46:40 +00:00
|
|
|
let examples = (await readdir(basepathExamplesJSFiles, { recursive: true }))
|
|
|
|
.filter((x) => x.endsWith(".js"))
|
|
|
|
.map((x) => basepathExamplesJSFiles + "/" + x);
|
|
|
|
console.log(examples);
|
2024-05-27 22:22:40 +00:00
|
|
|
let result = [];
|
|
|
|
for (let proposalFile of [
|
|
|
|
"pipeline.jstql",
|
|
|
|
"do.jstql",
|
|
|
|
"awaitToPromise.jstql",
|
|
|
|
]) {
|
|
|
|
const jstql_file = "dsl_files/" + proposalFile;
|
|
|
|
const test_file = Bun.file(jstql_file);
|
|
|
|
const test_JSTQL = await test_file.text();
|
|
|
|
let proposals = await parseJSTQL(test_JSTQL);
|
2024-05-23 11:46:40 +00:00
|
|
|
|
2024-05-27 22:22:40 +00:00
|
|
|
let sum = 0;
|
|
|
|
let failures = 0;
|
|
|
|
let filesSucceeded = 0;
|
|
|
|
console.log("Scripts found ", sum, "matches!");
|
|
|
|
let count = 0;
|
|
|
|
for (let examplesFile of examples) {
|
|
|
|
try {
|
|
|
|
if (examplesFile.split("/").includes("compiled")) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
console.log(examplesFile);
|
|
|
|
let script = await Bun.file(examplesFile).text();
|
|
|
|
let [resultString, matches] = transform(
|
|
|
|
proposals[0].cases,
|
|
|
|
script
|
2024-05-23 11:46:40 +00:00
|
|
|
);
|
2024-05-27 22:22:40 +00:00
|
|
|
sum += matches;
|
|
|
|
if (matches > 0) {
|
|
|
|
//await Bun.write(
|
|
|
|
// "output_testing/" + count + examplesFile.split("/").at(-1),
|
|
|
|
//resultString
|
|
|
|
//);
|
|
|
|
count += 1;
|
|
|
|
}
|
|
|
|
filesSucceeded += 1;
|
|
|
|
} catch (e) {
|
|
|
|
failures += 1;
|
2024-05-23 11:46:40 +00:00
|
|
|
}
|
2024-05-27 22:22:40 +00:00
|
|
|
console.log("current sum", sum);
|
2024-05-23 11:46:40 +00:00
|
|
|
}
|
2024-05-27 22:22:40 +00:00
|
|
|
result.push(
|
|
|
|
"Total for " +
|
|
|
|
proposalFile +
|
|
|
|
" is " +
|
|
|
|
sum +
|
|
|
|
",failures " +
|
|
|
|
failures +
|
|
|
|
",succeeded " +
|
|
|
|
filesSucceeded +
|
|
|
|
", Files With Matches " +
|
|
|
|
count +
|
|
|
|
",totalJSFiles " +
|
|
|
|
examples.length
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
for (let res of result) {
|
|
|
|
console.log(res);
|
2024-05-23 11:46:40 +00:00
|
|
|
}
|
2023-12-11 18:38:30 +00:00
|
|
|
};
|
2023-12-06 12:44:49 +00:00
|
|
|
|
|
|
|
main();
|