@mussonindustrial/pyro-resource
TypeScript icon, indicating that this package has built-in type declarations

2.1.0 • Public • Published

pyro-resource Musson Industrial Logo

NPM Version

pyro-resource lets you build Ignition-compatible project resource files in JavaScript.

import fs from 'fs'
import { newProject, perspective } from '@mussonindustrial/pyro-resource'

const project = newProject({ perspective })

const styleClasses = project.perspective.resources.styleClasses
styleClasses.node('MyStyleClass', {
    'style.json': '{ base: { style: {} } }',
})

const zip = await project.zip()
fs.writeFileSync('./project-import.zip', zip)

Usage

  1. Add pyro-resource to your build tool:
npm install @mussonindustrial/pyro-resource
  1. Create a new project and include your desired modules.
import {
    alarmNotification,
    newProject,
    perspective,
    reporting,
    sfc,
    sqlBridge,
    vision,
    webdev,
} from '@mussonindustrial/pyro-resource'

const project = newProject({
    alarmNotification,
    perspective,
    reporting,
    sfc,
    sqlBridge,
    vision,
    webdev,
})
  1. Add your resource content.
const pageConfig = project.perspective.resources.pageConfig
// Setting node content.
pageConfig.set({
    'config.json': '{}',
})

const styleClasses = project.perspective.resources.styleClasses
// Creating a node.
styleClasses.node('MyStyleClass', {
    'style.json': '{ base: { style: {} } }',
})

// Creating a node in a folder.
styleClasses.node('Folder/StyleClass', {
    'style.json': '{ base: { style: {} } }',
})

// Creating a folder.
const folder = styleClasses.folder('Folder2')
folder.node('InAFolder', {
    'style.json': '{ base: { style: {} } }',
})
  1. Zip the project and write to disk.
const zip = await project.zip()
fs.writeFileSync('./projectImport.zip', zip)

resource.json Files

The required resource.json files are generated and signed using pyro-resource-signature.

Type Hints

Each module comes with resource definitions and type hints for the required files.

project.perspective.resources
// (property) resources: {
//     generalProperties: NodeResource<readonly ["data.bin"]>;
//     pageConfig: NodeResource<readonly ["config.json"]>;
//     sessionProperties: NodeResource<readonly ["props.json"]>;
//     sessionScripts: NodeResource<...>;
//     styleClasses: FolderResource<...>;
//     views: FolderResource<...>;
// }

Custom Modules and Resources

Custom module definitions can be created in order to support 3rd party modules (with complete type hinting).

import {
    newFolderResource,
    newModule,
    newNodeResource,
    newProject,
} from '@mussonindustrial/pyro-resource'

const myFolderResource = newFolderResource('my-resource', ['file.json'])

const mySingletonResource = newNodeResource('my-singleton-resource', [
    'file.json',
    'image.png',
    'another.xml',
])

const myModule = newModule('com.acme.module', {
    myFolderResource,
    mySingletonResource,
})

const project = newProject({ myModule })

project.myModule.resources
// (property) resources: {
//     myFolderResource: FolderResource<readonly ["file.json"]>;
//     mySingletonResource: NodeResource<readonly ["file.json", "image.png", "another.xml"]>;
// }

Copyright and Licensing

Copyright (C) 2023 Musson Industrial

Free use of this software is granted under the terms of the MIT License.

Readme

Keywords

none

Package Sidebar

Install

npm i @mussonindustrial/pyro-resource

Weekly Downloads

0

Version

2.1.0

License

MIT

Unpacked Size

27.4 kB

Total Files

6

Last publish

Collaborators

  • benmusson