Finished cleanup
This commit is contained in:
parent
3dd32df2c1
commit
953a1fefa2
4 changed files with 72 additions and 14 deletions
49
README.md
49
README.md
|
@ -7,3 +7,52 @@ This tool is created to transform JavaScript based on definitions written in a c
|
||||||
This is a DSL created to define proposal transformations using templates. A transformation is defined by two templates, a template of what code snippets to search for **applicable to** and a template of how to transform those snippets **transform to**.
|
This is a DSL created to define proposal transformations using templates. A transformation is defined by two templates, a template of what code snippets to search for **applicable to** and a template of how to transform those snippets **transform to**.
|
||||||
|
|
||||||
Examples of definitions for proposals can be found in [dsl_files](./dsl_files/)
|
Examples of definitions for proposals can be found in [dsl_files](./dsl_files/)
|
||||||
|
|
||||||
|
## Running this project
|
||||||
|
|
||||||
|
This project exposes an api in the file [transform/transfrom.ts](./src/transform/transform.ts), which is meant to be used as this library's entry point.
|
||||||
|
|
||||||
|
To run this code as a standalone project, a file [index.ts](./index.ts) exists to facilitate running this project.
|
||||||
|
|
||||||
|
This project is created using TypeScript, and it is recommended to use [Bun](https://bun.sh/) to compile and run it.
|
||||||
|
|
||||||
|
### Building Langium required files
|
||||||
|
|
||||||
|
Firstly, building langium is required, this is done by the following:
|
||||||
|
|
||||||
|
```sh
|
||||||
|
# cd into JSTQL
|
||||||
|
cd JSTQL
|
||||||
|
|
||||||
|
# Install dependencies
|
||||||
|
npm i
|
||||||
|
|
||||||
|
# Build langium generated files
|
||||||
|
npm run langium:generate
|
||||||
|
|
||||||
|
# Build final JS source
|
||||||
|
npm run build
|
||||||
|
```
|
||||||
|
|
||||||
|
### Running a transformation
|
||||||
|
|
||||||
|
Now we are ready to run this project with the pipeline on a test JS file:
|
||||||
|
|
||||||
|
```sh
|
||||||
|
# cd into top level
|
||||||
|
cd ..
|
||||||
|
|
||||||
|
# Install dependencies
|
||||||
|
bun i
|
||||||
|
|
||||||
|
# Run an example transformation
|
||||||
|
bun run index.ts dsl_files/pipeline.jstql test_files/test.js
|
||||||
|
```
|
||||||
|
|
||||||
|
### Arguments of index.ts
|
||||||
|
|
||||||
|
Arguments
|
||||||
|
|
||||||
|
- First positional is path to JSTQL
|
||||||
|
- Second positional is path to JS file to transform
|
||||||
|
- -o is optional output path, if not given path is **./out.js**
|
||||||
|
|
BIN
bun.lockb
BIN
bun.lockb
Binary file not shown.
|
@ -1,32 +1,40 @@
|
||||||
//import * as babelparser from "../babel/packages/babel-parser";
|
//import * as babelparser from "../babel/packages/babel-parser";
|
||||||
import * as babelparser from "@babel/parser";
|
import * as babelparser from "@babel/parser";
|
||||||
//import core from "../babel/packages/babel-core";
|
//import core from "../babel/packages/babel-core";
|
||||||
import { parse_with_plugins } from "./parser/parse";
|
import { parse_with_plugins } from "./src/parser/parse";
|
||||||
import {
|
import {
|
||||||
SelfHostedRecipe,
|
SelfHostedRecipe,
|
||||||
TransformRecipe,
|
TransformRecipe,
|
||||||
transform,
|
transform,
|
||||||
} from "./transform/transform";
|
} from "./src/transform/transform";
|
||||||
import { readdir } from "node:fs/promises";
|
import { readdir } from "node:fs/promises";
|
||||||
import { parseJSTQL } from "./langium/langiumRunner";
|
import { parseJSTQL } from "./src/langium/langiumRunner";
|
||||||
|
|
||||||
import { parseArgs } from "util";
|
import { parseArgs } from "util";
|
||||||
|
|
||||||
const options = {
|
const options = {};
|
||||||
o: {
|
|
||||||
type: "string",
|
|
||||||
},
|
|
||||||
};
|
|
||||||
|
|
||||||
const { values: argVals, tokens: positional } = parseArgs({
|
const { values: argVals, tokens: positional } = parseArgs({
|
||||||
options,
|
options: {
|
||||||
|
o: {
|
||||||
|
type: "string",
|
||||||
|
},
|
||||||
|
},
|
||||||
tokens: true,
|
tokens: true,
|
||||||
allowPositionals: true,
|
allowPositionals: true,
|
||||||
});
|
});
|
||||||
const main = async () => {
|
const main = async () => {
|
||||||
//transform(selfHostedTransformExampleMultiStmt, codeFromFile);
|
//transform(selfHostedTransformExampleMultiStmt, codeFromFile);
|
||||||
console.log(positional);
|
console.log(positional);
|
||||||
if (!positional[0] || !positional[0].value.endsWith(".jstql")) {
|
console.log(argVals);
|
||||||
|
if (!positional) {
|
||||||
|
throw new Error("Something is wrong with args");
|
||||||
|
}
|
||||||
|
if (
|
||||||
|
!positional[0] &&
|
||||||
|
positional[0].kind === "positional" &&
|
||||||
|
!positional[0].value.endsWith(".jstql")
|
||||||
|
) {
|
||||||
throw new Error("First positional argument is current JSTQL file");
|
throw new Error("First positional argument is current JSTQL file");
|
||||||
}
|
}
|
||||||
if (!positional[1] || !positional[1].value.endsWith(".js")) {
|
if (!positional[1] || !positional[1].value.endsWith(".js")) {
|
||||||
|
@ -44,12 +52,13 @@ const main = async () => {
|
||||||
|
|
||||||
for (let proposal of parsedJSTQL) {
|
for (let proposal of parsedJSTQL) {
|
||||||
let [resultString, matches] = transform(proposal.cases, codeString);
|
let [resultString, matches] = transform(proposal.cases, codeString);
|
||||||
|
console.log(resultString);
|
||||||
let path = "./";
|
let path = "./out.js";
|
||||||
if (argVals["o"]) {
|
if (argVals["o"]) {
|
||||||
path = argVals["o"];
|
path = argVals["o"];
|
||||||
}
|
}
|
||||||
Bun.write(path, resultString);
|
console.log(path);
|
||||||
|
await Bun.write(path, resultString);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
|
@ -10,6 +10,6 @@
|
||||||
"moduleResolution": "node",
|
"moduleResolution": "node",
|
||||||
"types": ["bun-types"]
|
"types": ["bun-types"]
|
||||||
},
|
},
|
||||||
"include": ["src"],
|
"include": ["src", "index.ts"],
|
||||||
"exclude": ["babel"]
|
"exclude": ["babel"]
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue