roomle-content-tool-api
v3.15.0
Published
Roomle Component Tool API
Downloads
364
Maintainers
Readme
content-tool-api
Roomle Component Tool API
Example usage - API for Tools
npm install roomle-content-tool-api
instantiate API
import { RoomleToolApi } from 'roomle-content-tool-api/lib/roomletoolapi';
// initialize the API instance
const api: RoomleToolApi = new RoomleToolApi((message: string, type: CallbackMessageType, showInUi: boolean) => {
console.log(message);
if (showInUi) {
// send it to your user interface message box
}
});
- get the data payload, either from file or from string
const payloadText = api.payloadFromText('{"id":"catalog:component","onUpdate":""}', false);
const payloadFile = api.payloadFromFile(path.resolve('../catalog/components/my.json'), false);
- prepare processing of the payload (this will unsecape and generate a valid JSON)
api.preparePayloadForProcessing(payload, false);
- get the component definition as a valid JSON in
payload.componentJson
or apply modifier functions
api.formatPayload(payload, false);
api.normalizePayload(payload, false);
api.squash(payload, false);
api.deformat(payload, false);
api.rescript(payload, false);
- run finishProcessing
api.finishProcessing(payload.false)
This will make ready document available for further use or export in payload.processedDocument: string
and payload.processedDocumentAsLines: string[]
.
Note: payload.documentHasActuallyChanged
is true if input and processed document are equal
- if you need, you can run analyses
api.feedPayloadOutlineEntries(payload, showMessagesInUi); // will analyse and feed code outline entries (= level 1 JSON keys, #tag, #region, custom code markers, TODOs/FIXMEs) in payload.outlineEntries and also returns them
await api.runScriptAnalyzer(payload, showMessagesInUi); // runs script analyzer from roomle-core-hsc
api.feedPayloadAutocompleteEntries(payload, false); // will analyse component definition and scripts to fetch autocomplete entries
Example usage: component import/export
npm install roomle-content-tool-api
import { RoomleToolApi } from 'roomle-content-tool-api/lib/roomletoolapi';
// initialize the API instance
const api = new RoomleToolApi();
const payload = api.importComponentDefinition('./component.json', false);
// do stuff with component
payload.componentJson.parameters.push({key:'test'});
api.exportComponentDefintion(payload, false); // overwrites original file
api.exportComponentDefintionAs('./modified/component.json', payload, false); // saves as new file