2.1.0 • Published 20 days ago

bm-thing-transformer v2.1.0

Weekly downloads
3
License
MIT
Repository
github
Last release
20 days ago

Intro

A tool that allows the development of Thingworx models in a real IDE. This repo contains the following:

  • The bm-thing-transformer module, which is a typescript transformer that converts TypeScript source files into Thingworx entity XML files.
  • The declarations of the decorators and thingworx specific types that are interpreted by the transformer
  • The declarations of the standard thingworx entities such as GenericThing and InfoTableFunctions

Index

Usage

You should primarily use this via the Thingworx VSCode Project Template. For more information, refer to that repository.

Nevertheless, you can use this standalone as well, by including it in your project with npm install bm-thing-transformer.

This must be used together with the typescript compiler api. Create a TWConfig object then use the transformer factory as a transformer in your TypeScript project in both the before and after phases of the transformation e.g.

import { TWThingTransformerFactory, TWConfig, TWThingTransformer } from 'bm-thing-transformer';

// Initialize the typescript program
const program = ...

// Create a twconfig object
const twConfig: TWConfig = {
    projectName: 'MyProject',
    store: {} // This should be empty
}

// Use the transformer factory in both the before & after phases
const emitResult = program.emit(undefined, () => {}, undefined, undefined, {
    before: [
        TWThingTransformerFactory(program, path, false, false, twConfig)
    ],
    after: [
        TWThingTransformerFactory(program, path, true, false, twConfig)
    ]
});

// Fire post transform actions, which enable features like data shape inheritance
for (const key in twConfig.store) {
    // Exclude non-transformer entries
    if (key.startsWith('@')) continue;

    twConfig.store[key].firePostTransformActions();
}

After the emit finishes, the transformers will properties to the store object of your twconfig object. This is an object whose keys are the names of the generated entities and their values are each an instance of the transformer. Beyond those related to the actual transformation, the transformer has the following public methods that can be invoked after the program's emit method returns:

  • toXML(): string - Returns a string that represents the XML definition of the entity
  • toDeclaration(): string - Returns a string that represents the declaration of the entity in its relevant collection. For example, with a Thing, the declaration will be something like:
declare interface Things { MyThing: MyThing }
  • write(path?: string): void - Writes the result of toXML() to a file at the specified path, in path/build/Entities/<CollectionName>/<EntityName>.xml. The path defaults to the project path.

Development

Pre-Requisites

The following software is required:

  • NodeJS: needs to be installed and added to the PATH. You should use the LTS version.

The following software is recommended:

  • Visual Studio Code: An integrated developer environment with great javascript and typescript support. You can also use any IDE of your liking, it just that most of the testing was done using VSCode.

Development Environment

In order to develop this extension you need to do the following: 1. Clone this repository 2. Run npm install. This will install the development dependencies for the project. 3. Start working on the project.

File Structure

ThingTransformer
│   README.md         // this file
│   package.json      // node package details
│   LICENSE           // license file
└───scripts           // build scripts
│   │   clean.js            // clean script
└───src               // main folder where your development will take place
│   │   file1.ts            // typescript file
|   |   ...
└───static            // folder containing declarations to be used in a thingworx project
└───dist              // files used in the distribution

Build

To build the project, run npm run build in the root of the project. This will generate the appropriate files in the dist folder.

Contributors

  • BogdanMihaiciuc: main developer.
  • dwil618: support for min/max aspects and date initializers.
  • stefan-lacatus: support for inferred types in property declarations, method helpers, bug fixes, support for the @exported decorator and API generation, data shape inheritance, declare modifier on members, upgrade from typescript 4 to typescript 5.
  • elena-bi: bug fixes
  • s-amory: SQLThing type definition.
  • CozminM: compatiblity with thingworx 8.5
  • kklorenzotesta: thingworx API typing updates

License

MIT License

2.1.0

20 days ago

2.0.2

27 days ago

2.0.1

1 month ago

2.0.0

1 month ago

1.7.4

5 months ago

1.7.3

5 months ago

1.7.2

1 year ago

1.7.1

1 year ago

1.6.2

1 year ago

1.7.0

1 year ago

1.6.1

1 year ago

1.6.0

1 year ago

1.5.1

1 year ago

1.5.0

1 year ago

1.4.8

2 years ago

1.4.7

2 years ago

1.4.6

2 years ago

1.4.5

2 years ago

1.4.0

2 years ago

0.21.1-beta.1

2 years ago

1.3.1

2 years ago

1.3.0

2 years ago

0.22.1-beta.1

2 years ago

0.22.0-beta.1

2 years ago

0.21.0-beta.1

2 years ago

0.19.0-beta.1

2 years ago

0.20.1-beta.1

2 years ago

0.20.0-beta.1

2 years ago

0.18.0-beta.1

2 years ago

0.17.0-beta.1

2 years ago

0.16.0-beta.1

3 years ago

0.15.0-beta.1

3 years ago

0.14.0-beta.1

3 years ago

0.13.0-beta.1

3 years ago

0.11.3-beta.1

3 years ago

0.11.2-beta.1

3 years ago

0.11.1-beta.1

3 years ago

0.11.0-beta.1

3 years ago

0.10.0-beta.1

4 years ago

0.9.0-beta.1

4 years ago

0.3.2-beta.1

4 years ago

0.3.1-beta.1

4 years ago

0.3.0-beta.1

4 years ago

0.2.0-beta.1

4 years ago

0.1.0-beta.1

4 years ago

0.0.1-alpha.6

4 years ago

0.0.1-alpha.5

4 years ago

0.0.1-alpha.4

4 years ago

0.0.1-alpha.3

4 years ago

0.0.1-alpha.2

4 years ago

0.0.1-alpha.1

4 years ago