Enable Your App to Deploy Template Packages
You can enable your web application to deploy Twinit Template Packages using the twinit-template-pkg node module.
This package allows you to validate template packages and deploy template packages to workspaces on Twinit.
Installation#
Be sure you have followed the steps to enable installing packages from npm.twinit.dev.
npm install @dtplatform/twinit-template-pkgtwinit-template-pkg requires that you also have installed compatible versions of:
- jszip: "^3.10.1"
- @dtplatform/platform-api: "^5.0.0"
- @dtplatform/iaf-script-engine: "^5.0.0"
Usage#
Validate a Template Package#
You can validate a template package using
import { validateTemplatePackage } from '@dtplatform/twinit-template-pkg'
async function deployTemplates(input, lbraries, ctx) {
const validationResult = await validateTemplatePackage(packageFile)
}| Parameters | |
|---|---|
| packageFile | a String/Array of bytes/ArrayBuffer/Uint8Array/Buffer/Blob or a Promise that resolves to a String/Array of bytes/ArrayBuffer/Uint8Array/Buffer/Blob |
| Returns | |
|---|---|
| validationResults | a validation result object, results are returned when the first error is encountered |
{ valid: <boolean> // true if the validation passed, false if it didn't message: <string> // an error or success message manifest: <object> // the parsed template package manifest, if validation fails this is null}Deploy a Template Package#
You can validate a template package using
import { deployTemplatePackage } from '@dtplatform/twinit-template-pkg'
async function deployTemplates(input, lbraries, ctx) {
const { IafProj } = libraries.PlatformApi
let project = IafProj.getCurrent(ctx)
const results = await deployTemplatePackage(packageFile, project, ctx)}| Parameters | |
|---|---|
| packageFile | a String/Array of bytes/ArrayBuffer/Uint8Array/Buffer/Blob or a Promise that resolves to a String/Array of bytes/ArrayBuffer/Uint8Array/Buffer/Blob |
| project | the Twinit workpace/project in to which the template package should be deployed |
| ctx | the current Twinit ctx |
| Returns | |
|---|---|
| deployResults | an Array\<string> of deployment log messages |