Import and export server scripts
scada-manager script import and script export move server scripts between a project and a folder of files, for
example to keep them in version control or to load the same set into several projects. The import goes through the
same checks as a save in the editor: every changed script becomes a new version, and the import is written to the audit
log.
Before you begin
- You work on the YTCC server, in a command prompt in the YTCC folder. The commands are administrator tools: they can set the permission and limit fields of a script.
- The internal signals the scripts write to exist in the project.
Steps
1. Check the files
- Only
.jsfiles are imported. The script name is the file name without extension: letters, digits and_, 1–64 characters, and not a Windows device name such asCONorCOM1. - TypeScript without type declarations is JavaScript: rename it to
.js. For typed code use Compile and save in the editor.
2. Try the import
scada-manager script import pump_station scripts --dry-run
<project> is the slug, the project identifier or its display name; the project may be running. --dry-run checks
everything and lists all problems without writing anything.
3. Import
scada-manager script import pump_station scripts --activate
| Option | Meaning |
|---|---|
--activate | Makes the imported scripts active. Without it, activation is left as it is; new scripts start inactive. |
--can-command --targets "Pump1.*,Valve?.Open" | Allows commands to field points matching the patterns. The two options need each other; an empty target list is refused. |
--can-publish --publish-targets "Line1.*.Energized" | Allows publishing computed values to points matching the patterns. |
--publish-targets-file patterns.txt | Reads more publish patterns from a file, one per line, # for comments. Needs --can-publish. |
--handler-ms 2000 | Sets the handler time limit. |
Without --can-command or --can-publish the existing permission is kept; without --handler-ms the existing limit is
kept. A file whose content did not change is counted as unchanged and gets no new version.
Scripts are applied in groups of 200. If a group fails, the command stops there with an error; the groups before it stay
applied. Fix the problem and run the command again: unchanged scripts are skipped. A running project reloads the changed
scripts within a few seconds. The audit log shows the user as cli:<Windows user> and the source as import.
4. Export
scada-manager script export pump_station backup\scripts
Writes every script of the project to the folder: scripts without compiled code as <name>.js, which can be imported
again, scripts compiled from TypeScript in the editor as <name>.ts. The target folder must not contain .js or .ts
files. With --force, the files are first written to a temporary folder; only when all succeed are the .js and .ts
files of scripts no longer in the project removed and the new files moved in. Other files in the folder are not touched.
The export also prepares the folder for VS Code; see Work on scripts in VS Code. ytcc-script.d.ts and
.ytcc-sync.json are written on every export; tsconfig.json and .vscode/tasks.json only if they do not exist yet,
so your own changes to them are kept. .d.ts files are not counted as scripts.
Names that differ only in upper and lower case (Pump and pump, which Windows would put in one file) are refused
before anything is written.
Work on scripts in VS Code
An exported folder can be opened in VS Code on the server computer. Next to the scripts the export writes:
| File | Purpose |
|---|---|
ytcc-script.d.ts | Completion and error checking for defineScript, ctx and alarm(), with the same type information as the built-in editor |
tsconfig.json | Checks the .js files too; produces no output |
.vscode/tasks.json | Three tasks under Terminal › Run Task: a dry run (script import --dry-run), an import with activation (script import --activate) and a watch that uploads on save (script sync --watch) |
.ytcc-sync.json | The version of each script at the export. Do not delete it: the sync works with it |
To upload changed files without the task, run:
scada-manager script sync pump_station backup\scripts --watch
script sync uploads only the .js files whose content changed since the export or the last sync. With --watch it
checks the folder every second until you press Ctrl+C; without it, it runs once. --activate
also activates the uploaded scripts. A running project reloads the uploaded scripts.
The sync does not overwrite changes made in the project. A file is not uploaded, and a conflict line is printed, when:
- the script was changed in the built-in editor after the export, or
- the script exists in the project but was not exported to this folder.
To continue, export again with --force and apply your change to the new file. A folder exported from another project
is refused. Save TypeScript scripts (.ts) in the editor with Compile and save.
Result
The scripts of the folder are in the project, each with a new version where it changed; or the scripts of the project are in the folder. Check them in Automation › Server scripts; see Server scripts.