thingworx-field-work / ThingworxVSCodeProject

Develop thingworx models using a real IDE
MIT License
33 stars 17 forks source link

πŸ– NOTE: This is still a work in progress.

Intro

A project template that allows the development of Thingworx models in a TypeScript IDE like Visual Studio Code.

Who is it for

This template is primarily aimed at Thingworx developer who are already very familiar with the composer but are also used to working in a regular IDE. To be able to succesfully use this, you should at least have an understanding of how the modelling environment works in Thingworx and some basic knowledge of TypeScript.

Why use it

There are many advantages to this, and here are some of them:

Development

Pre-Requisites

The following software is required:

The following software is recommended:

Development Environment

In order to develop with this project you need to do the following:

  1. Clone this repository
  2. Copy .env.sample to .env and configure the THINGWORX_SERVER and either THINGWORX_USER and THINGWORX_PASSWORD or THINGWORX_APP_KEY and other fields as needed.
  3. Open package.json and twconfig.json and change the fields as needed.
  4. Run npm install. This will install the development dependencies for the project.
  5. Run npm run watch:declarations. This will start a background process that is needed for generating certain files.
  6. Start working on the project.

Entity Dependencies

By default, the project contains the declarations for all the out of the box entities available in a fresh installation of Thingworx, however there may be the case that you need to use some entities that had been previously created on the Thingworx instance using the composer. To handle this, it is possible to define entity dependencies in twconfig.json. There are two types of dependencies that can be specified there:

Whenever you change twconfig.json, run npx twc install to pull the declarations from the Thingworx server specified in package.json.

Whenever entities are downloaded in this way, all other dependencies are downloaded as well, so if your MyThing thing depends on the MyDataShape data shape, you don't need to specify both in twconfig.json.

File Structure

ThingworxVSCodeProject
β”‚   README.md              // This file
β”‚   package.json           // Standard npm package details; the package name is also used as the extension name
β”‚   tsconfig.json          // Standard typescript configuration file
β”‚   twconfig.json          // Thingworx-specific configuration
β”‚   metadata.xml           // Thingworx metadata file for this extension; This is automatically updated based on your package.json and build settings
β”‚   LICENSE                // License file
β”‚   .env                   // Contains environment variables and thingworx connection details
└───src                    // Main folder where your development will take place
β”‚   └───file1.ts           // Thingworx entity file
β”‚   β”‚   ...
β”‚   └───[Project1]         // In multi-project mode, each subfolder represents a thingworx project
β”‚   β”‚   └───src            // Project's source folder
β”‚   β”‚   β”‚   └───file2.ts   // Thingworx entity file
β”‚   β”‚   β”‚   ...
β”‚   β”‚   └───tsconfig.json  // Project's typescript configuration file; Project dependencies are extracted from this
└───static                 // Supporting files required for compilation; Don't change these
└───tw_imports             // Entity dependencies downloaded from a Thingworx server
└───build                  // Temporary folder used during compilation
└───zip                    // Location of the built extension

Source Files

Any TypeScript file you add to the src folder will be compiled into a Thingworx entity. There are some restrictions on what is allowed to be included in these files, namely:

Current Limitations

Build

To build the extension, run npm run build in the root of the project. This will generate an extension .zip file in the zip folder in the root of the project.

To build the extension and upload it to Thingworx, run npm run upload in the root of the project. The details of the Thingworx server to which the script will upload the extension are declared in the project's environment or package.json file. These are:

To create a debug build that can be used for debugging, add the --debug argument to any task. For example, to create and upload a debug build, run npx twc upload --debug. For more information about debugging and debug builds, see BMDebugServer and ThingworxVSCodeDebugger.

Deployment

Deployment to Thingworx is part of the build process as explained above. Alternatively, you can manually install the extension that is generated in the zip folder in the root of the project.

Recent Changes

For a complete changelog see CHANGELOG.md.

31 Mar 2024

28 Mar 2023

11 Dec 2022

2 May 2022

Credit/Acknowledgment

Petrisor Lacatus - had the original idea for this, inferred property types and bug fixes, support for method helpers, API generation, data shape inheritance, declare on class members.

Bogdan Mihaiciuc - main developer.

thomas-thomas-tfs - deployment using app keys.

carlo-quinonez - bug fixes and documentation improvements.

dwil618 - support for min/max aspects and date initializers.

CozminM, elena-bi - bug fixes

kklorenzotesta - thingworx API typing updates

Disclaimer

The Thingworx VSCode Project is not an official Thingworx product. It is something developed to improve the life of a Thingworx developer and they need to understand that it is not supported and any issues encountered are their own responsibility.

License

MIT License