This is a Node library which wraps around MTMR. It is highly recommended to use this library with typescript. The main features are:
- TS/JS support for button handlers
- Typescript typings for the items
For further documentation have a look at the original repo.
Here you find the NPM Page.
npm i node-mtmr
Or
yarn add node-mtmr
A working example can be found here.
Create an index file inside your "src" directory. In this file call the "createParse" function:
import { createParse } from "node-mtmr";
const parse = createParse({
outDir: "./my-mtmr-config",
loggingEnabled: true,
});
- "outDir" is the output path for the script and assets. It's either relative to the cwd or absolute
- "loggingEnabled" configures the logging output
Pass the items to the parse function. The result is a correct MTMR item array.
const result = await parse(items);
There is a utility function for saving the output into the MTMR directory. Pass an options object with the force set to true to overwrite an existing file.
import { saveItems } from "node-mtmr";
saveItems(result, { force: true });
If you want to create a ScriptTitledButton with a jsSource you can use either the createSourceScriptSync
or the createSourceScript
function. These will handle your script result and hand them to MTMR.
createSourceScriptSync(() => {
const buttonLabel = "Label";
const imageIdentifier = "inactive";
return {
label: buttonLabel,
imgKey: imageIdentifier,
};
});
or async
createSourceScript(async () => {
const label = await func();
return label;
});
or pass the result to the sourceOutput
util function
sourceOutput({
label: "Label",
imgKey: "key",
});
If you your button needs a state make use of the state functions. Internally the data is stored in your computers ''/tmp/'' folder (so it might be deleted at some point):
const stateId = "counter";
const count = stateValue<number>(stateId, 0);
const setCount = stateFunction<number>(stateId);
const [count, setCount] = state<number>(stateId);
This is the new item type which supports JavaScript.
{
type: "scriptTitledButton",
sourceType: "javaScript",
jsSource: {
inline: () => {
// Your function logic
},
},
actions: [
{
action: "javaScript",
trigger: "singleTap",
actionJavaScript: {
filePath: "./path/to/js/file.js",
},
},
],
}