@mussonindustrial/pyro-resource
v2.1.0
Published
Ignition project resource builder.
Downloads
9
Readme
pyro-resource
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
- Add pyro-resource to your build tool:
npm install @mussonindustrial/pyro-resource
- 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,
})
- 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: {} } }',
})
- 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.