-
-
Notifications
You must be signed in to change notification settings - Fork 1
Tutorial 01 Quick Start
Sam Cao edited this page Jun 30, 2023
·
4 revisions
In this tutorial, you are going to learn:
- How to create a Jaspiler runtime environment.
- How to write your first Jaspiler script.
- What is the typical Jaspiler script development workflow.
- Download the all-in-one jar file Jaspiler-${version}.jar from the latest Actions.
- Create a JavaScript file
test.js
as follows:
const result = jaspiler.transformSync(
`package com.test;
public class A {
}
`,
{
plugins: [{
visitor: {
Class(node) {
node.simpleName = jaspiler.createName('B');
},
},
}],
sourceType: 'string',
});
console.info(result.code);
- Execute the command as follows:
java -jar Jaspiler-${version}.jar test.js
- The output is as follows:
package com.test;
public class B {
}
The complete code is at 01_quick_start.js
A typical Jaspiler script development workflow consists of the following steps.
- Create
test.js
- Write a plugin (optional)
- Write a visitor (optional)
- Write some event listeners (optional)
- Write transformation logic in the listeners (optional)
- Call
jaspiler.transformSync
in the end
- Call
java -jar Jaspiler-${version}.jar test.js