node abstraction layer for PROS CLI
run npm i --save @purduesigbots/pros-cli-middleware
to add to your project
import functions into files:
import { listTemplates } from '@purduesigbots/pros-cli-middleware'
all the functions listed below return a promise that resolves when the command exits successfully. this means that there are effectively two ways to call any of these functions:
let r
try {
r = await listTemplates(...)
} catch e {
console.error(e)
}
listTemplates(...).then(r => {...}).catch(e => console.error(e))
applyTemplate(callbacks, path, query, [options])
Upgrade or install a template to a PROS projectcallbacks
: standard set of UI hookspath
: path to PROS projectquery
: semver-compliant string (e.g.[email protected]
)options
: an object containing zero or one each of the following fieldsupgrade: boolean
: allow upgrading templatesinstall: boolean
: allow installing templatesdownload: boolean
: allow downloading templates (iffalse
, will only consider local templates)user: boolean
: forcibly replace all user files in templatessystem: boolean
: force insertion of system files into the project
fetchTemplate(callbacks, query)
Fetch/dowload a template from a depotcallbacks
: standard set of UI hooksquery
: semver-compliant string (e.g.template
ortemplate@^0.7.0
or[email protected]
)
listTemplates(callbacks, query, [options])
Return all available templates satisfyingquery
callbacks
: standard set of UI hooksquery
: semver-compliant string (e.g.template
or[email protected]
ortemplate^0.7.0
or1.0.0
)options
: an object containing zero or one each of the following fieldsoffline: boolean
: return offline templatesonline: boolean
: return online templatesrefresh: boolean
: force refresh of remote listingslimit: number
: limit number of templates returned
purgeTemplate(callbacks, query, [options])
Purge templates satisfyingquery
from the local cachecallbacks
: standard set of UI hooksquery
: semver-compliant string (e.g.template
or[email protected]
ortemplate^0.7.0
or1.0.0
)options
: an object containing zero or one each of the following fieldsforce
: do not prompt for removal of multiple templates
getProjectInfo(callbacks, path, [options])
Return information about a PROS projectcallbacks
: standard set of UI hookspath
: path to PROS projectoptions
: an object containing zero or one each of the following fieldsupgrades: boolean
: add list of upgradable versions for templates that are out of date
createNewProject(callbacks, path, version, [platform='v5', options])
Create a new PROS projectcallbacks
: standard set of UI hookspath
: path at which to create projectversion
: the version of the kernel to use when creating the project. can be'latest'
target
: optionally specify the platform to target. can be either'v5'
or'cortex'
options
: an object containing zero or one each of the following fieldsuser: boolean
: forcibly replace all user files in templatessystem: boolean
: forcibly replace all system files in templatesrefresh: boolean
: force refresh of remote listingscompile: boolean
: compile the project immediately after creation from version 1.0.0 (CLI version >=3.0.8)cache: boolean
: compile the project immediately after creation and build compile_commands.json file for cquery from version 1.0.0 (CLI version >=3.0.8)
upgradeProject(callbacks, path, version, [options])
Upgrade a PROS projectcallbacks
: standard set of UI hookspath
: path to PROS projectversion
: version to upgrade project tooptions
: an object containing zero or one each of the following fieldsinstall: boolean
: install libraries that are not already installeddownload: boolean
: download templates if not present locally (otherwise use latest available locally)user: boolean
: forcibly replace all user files in templatessystem: boolean
forcibly replace all system files in templates
listDevices(callbacks, [target])
List connected VEX devicescallbacks
: standard set of UI hookstarget: 'v5'|'cortex
: optionally limit results to those matching the specified target
uploadProject(callbacks, path, [options])
Upload a PROS projectcallbacks
: standard set of UI hookspath
: path to PROS projectoptions
: an object containing zero or one each of the following fieldsrun: boolean
: run the program immmediately after uploadingname: string
: name of the project on the uC (only applies for v5-targeted projects)slot: number
: the slot to which the program will be uploaded on the uC (only applies for v5-targeted projects)
listFiles(callbacks, [port])
List files on a connected V5 devicecallbacks
: standard set of UI hooksport
: string specifying the port of the device you wish to interact with. if unspecified, the CLI will try to choose a port. if multiple devices are connected, the CLI will prompt for a choice
removeAll(callbacks, [port])
Remove all program files on a connected V5 devicecallbacks
: standard set of UI hooksport
: string specifying the port of the device you wish to interact with. if unspecified, the CLI will try to choose a port. if multiple devices are connected, the CLI will prompt for a choice
removeFile(callbacks, file, [options, port])
Remove a program file from a connected V5 devicecallbacks
: standard set of UI hooksfile
: the file to removeoptions
: an object containing zero or one each of the following keysall: boolean
: erase all files matching base name
port
: string specifying the port of the device you wish to interact with. if unspecified, the CLI will try to choose a port. if multiple devices are connected, the CLI will prompt for a choice
runProgram(callbacks, [file, port])
Run a program on a connected V5 devicecallbacks
: standard set of UI hooksfile
: the file to run. if unspecified, the CLI will attempt to find the correct name based on the CWD's PROS project (note: this will not work at present-- please specify a file for now)port
: string specifying the port of the device you wish to interact with. if unspecified, the CLI will try to choose a port. if multiple devices are connected, the CLI will prompt for a choice
systemStatus(callbacks, [port])
Display information about a connected V5 devicecallbacks
: standard set of UI hooksport
: string specifying the port of the device you wish to interact with. if unspecified, the CLI will try to choose a port. if multiple devices are connected, the CLI will prompt for a choice
stopProgram(callbacks, [file, port])
Stop a program on a connected V5 devicecallbacks
: standard set of UI hooksfile
: the file to run. if unspecified, the CLI will attempt to find the correct name based on the CWD's PROS project (note: this will not work at present-- please specify a file for now)port
: string specifying the port of the device you wish to interact with. if unspecified, the CLI will try to choose a port. if multiple devices are connected, the CLI will prompt for a choice
each function listed above takes for its first parameter a set of callbacks whose purpose is to provide an interface for GUIs to interact with data returned from the CLI. the specification for this object is as follows:
{
notify: (data: any) => void,
log: (data: any) => void,
prompt: (data: any, callback: (val: any) => boolean) => void,
finalize: (data: any) => void
}
each callback corresponds to an event that will be propagated up from an invocation of a CLI command:
notify
: fired for general information updates that occur as the command runs. possible events includenotify/progress
(update a progress bar) andnotify/echo
(inform about significant operations, e.g. updating remote listings)log
: fired for debugging information about the invoked command, including warnings and errors that occurprompt
: fired when the command requests user input. this callback must in turn call the passed callback with the result of the user's inputfinalize
: fired just before the command exits, sending the resultant data from the command to the UI
- clone the repository
- run
npm i
in the project root - run
npm run build
to generate the transpiled output - ...
- profit