@enfocussw/switch-scripting-context 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +504 -0
- package/README.md +192 -0
- package/bin/cli.js +8 -0
- package/dist/init.d.ts +78 -0
- package/dist/init.js +894 -0
- package/docs/switch-api/api-versions.md +127 -0
- package/docs/switch-api/connection.md +82 -0
- package/docs/switch-api/document-classes.md +189 -0
- package/docs/switch-api/entry-points.md +185 -0
- package/docs/switch-api/enums.md +181 -0
- package/docs/switch-api/execution-environment.md +143 -0
- package/docs/switch-api/flow-element.md +143 -0
- package/docs/switch-api/http.md +96 -0
- package/docs/switch-api/job-patterns.md +238 -0
- package/docs/switch-api/job.md +187 -0
- package/docs/switch-api/logging.md +117 -0
- package/docs/switch-api/switch.md +210 -0
- package/docs/switch-appstore/app-guidelines.md +281 -0
- package/docs/switch-appstore/app-manual.md +84 -0
- package/docs/switch-appstore/app-store-listing.md +69 -0
- package/docs/switch-appstore/app-store-submission.md +83 -0
- package/docs/switch-project/debugging.md +61 -0
- package/docs/switch-project/logs-and-dataroot.md +80 -0
- package/docs/switch-project/node-versions.md +87 -0
- package/docs/switch-project/project-planning.md +149 -0
- package/docs/switch-project/property-documentation.md +75 -0
- package/docs/switch-project/property-editors.md +249 -0
- package/docs/switch-project/script-declaration.md +407 -0
- package/docs/switch-project/script-structure.md +157 -0
- package/docs/switch-project/tooling.md +165 -0
- package/docs/switch-project/vscode.md +90 -0
- package/docs/switch-scripting.md +70 -0
- package/package.json +65 -0
|
@@ -0,0 +1,165 @@
|
|
|
1
|
+
---
|
|
2
|
+
id: tooling
|
|
3
|
+
category: switch-project
|
|
4
|
+
order: 11
|
|
5
|
+
summary: "SwitchScriptTool commands and install paths, folder vs `.sscript` trade-offs, deployment"
|
|
6
|
+
triggers:
|
|
7
|
+
- "Running SwitchScriptTool: transpiling, packing, unpacking, or deploying"
|
|
8
|
+
---
|
|
9
|
+
|
|
10
|
+
# Script Folders, Packages & SwitchScriptTool
|
|
11
|
+
|
|
12
|
+
<!-- docs-index:contents begin -->
|
|
13
|
+
## Contents
|
|
14
|
+
|
|
15
|
+
- Script folder vs script package
|
|
16
|
+
- SwitchScriptTool
|
|
17
|
+
- Commands
|
|
18
|
+
- Verify entry points before packing
|
|
19
|
+
- Deployment
|
|
20
|
+
<!-- docs-index:contents end -->
|
|
21
|
+
|
|
22
|
+
## Script folder vs script package
|
|
23
|
+
|
|
24
|
+
| | Script folder | Script package (`.sscript`) |
|
|
25
|
+
|---|---|---|
|
|
26
|
+
| Use for | Development, version control | Production, deployment |
|
|
27
|
+
| Included in flow export | **No** | Yes |
|
|
28
|
+
| TypeScript transpile | Manual — `SwitchScriptTool --transpile` | Automatic in SwitchScripter |
|
|
29
|
+
| Password protection | Not supported | Optional |
|
|
30
|
+
| Can be used as App | No — must pack first | Yes |
|
|
31
|
+
|
|
32
|
+
Script folders are not included in flow exports or backups. Never use a script folder in production — pack it to a `.sscript` package first.
|
|
33
|
+
|
|
34
|
+
## SwitchScriptTool
|
|
35
|
+
|
|
36
|
+
Command-line tool included with Switch. May not be on `PATH` — fall back to the known install
|
|
37
|
+
location for the current OS if the bare command isn't found.
|
|
38
|
+
|
|
39
|
+
**Windows:** `C:\Program Files\Enfocus\Enfocus Switch\SwitchScriptTool\SwitchScriptTool.exe` (add to PATH to avoid typing the full path)
|
|
40
|
+
|
|
41
|
+
**macOS:** symlinked to `/usr/local/bin/SwitchScriptTool` by the installer. If the symlink is missing, the real binary is bundled inside the SwitchScripter app: `/Applications/Enfocus/Enfocus Switch/SwitchScripter.app/Contents/MacOS/SwitchScriptTool/SwitchScriptTool`.
|
|
42
|
+
|
|
43
|
+
## Commands
|
|
44
|
+
|
|
45
|
+
| Mode | Command | Purpose |
|
|
46
|
+
|---|---|---|
|
|
47
|
+
| Create | `SwitchScriptTool --create <ScriptID> <Path> [--JavaScript]` | Scaffold a new script folder with all required files |
|
|
48
|
+
| Transpile | `SwitchScriptTool --transpile <Path>` | Compile `main.ts` → `main.js`. **Must use this, not `tsc` directly** |
|
|
49
|
+
| Pack | `SwitchScriptTool --pack <Folder> <OutputFolder> [--password <pwd>] [--verbose]` | Create `<OutputFolder>/<ScriptID>.sscript` for deployment. `<OutputFolder>` is a directory, created if missing, not the package's file path |
|
|
50
|
+
| Unpack | `SwitchScriptTool --unpack <file.sscript> <Folder> [--password <pwd>]` | Extract package to folder |
|
|
51
|
+
| List | `SwitchScriptTool --list <file.sscript>` | List package contents (no password needed) |
|
|
52
|
+
| Generate translations | `SwitchScriptTool --generate-translations <ScriptFolder> <ResultFolder>` | Generate translation files for the script package |
|
|
53
|
+
|
|
54
|
+
**Create** scaffolds: `manifest.xml`, `<ScriptID>.xml`, `<ScriptID>.sscript`, `main.ts` (or `main.js` with `--JavaScript`), `.vscode/launch.json`, `Resources/`, plus `package.json`, `tsconfig.json`, `.vscode/switch.code-snippets`, and type declarations for TypeScript. Creates `<Path>/<ScriptID>/` — it does not write into `<Path>` directly. `ScriptID` may only contain letters, digits, hyphens, and underscores.
|
|
55
|
+
|
|
56
|
+
**Gotcha: `--create` deletes an existing target folder.** If `<Path>/<ScriptID>/` already exists, `--create` removes it and everything in it (including `.git/`, a README, or AI agent config files) without prompting, then scaffolds a fresh folder. The only sign is an `Info: Removed existing target folder` line in its output. Never run `--create` where `<Path>/<ScriptID>/` exists, and never use it to turn the folder you're already working in into a script folder: `--create <FolderName> <ParentOfFolder>` wipes that folder. Check that the target doesn't exist first.
|
|
57
|
+
|
|
58
|
+
**Transpile** is required after every edit to `main.ts` before testing a **script folder** directly in Switch. Switch executes `main.js` only — `main.ts` is never run directly. Using SwitchScriptTool (not `tsc`) ensures the same transpile options as SwitchScripter, which is required for consistent behavior. This step is **not** needed before packing — see Pack below.
|
|
59
|
+
|
|
60
|
+
**Pack** transpiles `main.ts` fresh into the package on every run; it never reads or modifies any `main.js` already sitting in the source folder (a stale hand-edited `main.js` there is ignored and left untouched).
|
|
61
|
+
|
|
62
|
+
Pack copies an allowlist of files, not the whole folder. Only these end up in the `.sscript`: `manifest.xml`, the declaration file named in `ScriptDeclarationFile`, the program file named in `ScriptProgramFiles` plus the `main.js` and `main.js.map` pack transpiles from it, the icon named in `ScriptIconFile`, `tsconfig.json`, the placeholder `<ScriptID>.sscript`, `Resources/`, and `node_modules/`. Everything else in the folder is left out and printed in an "Info: ... will not be packed" list, even without `--verbose`. That includes `package.json`, `package-lock.json`, `.vscode/`, a README, other `.ts`/`.js` files, subfolders other than `Resources/` and `node_modules/`, and AI agent config and docs folders. `--verbose` additionally prints the full list of what *will* be packed. Translation files were not part of this test. Verified with a pre-release SwitchScriptTool build.
|
|
63
|
+
|
|
64
|
+
`node_modules` is packed as-is, so run `npm prune --production` first (see Deployment) — otherwise `devDependencies` (including `@types/*` packages, which the scaffolded `package.json` puts there) get bundled into the package for no runtime benefit. One harmless quirk: the placeholder `<ScriptID>.sscript` file scaffolded by `--create` is on the allowlist and ends up packed inside the real `.sscript` too. Pack also replaces `SwitchVersion` in the packed `manifest.xml` with SwitchScriptTool's own version (`--create` writes it too), and that value picks the Node.js version the package runs on. See [node-versions.md § What writes `SwitchVersion`](node-versions.md#what-writes-switchversion).
|
|
65
|
+
|
|
66
|
+
**Gotcha: local modules break pack.** A `main.ts` that imports a local module (`import { x } from './helper'` or `'./lib/helper'`) fails to pack with TypeScript error TS2307 (`Cannot find module`), and no `.sscript` is written. Pack's own output shows why: `helper.ts` and `lib/helper.ts` appear in its "will not be packed" list, and the TS2307 error points at pack's temporary copy of the folder, which doesn't contain them. A `main.js` that `require`s a local file was not tested, but that file isn't packed either. The manifest also accepts only one `ScriptProgramFile` (pack errors with `The manifest must contain only one script program file`), so listing the helper there doesn't work. The verified option is to keep script code in the single program file. Shared code in an npm package under `node_modules/` might work, since `node_modules/` is packed, but that was not tested, and neither was a `file:` dependency, which npm installs as a symlink.
|
|
67
|
+
|
|
68
|
+
**Unpack** prints package metadata (`Type`, `Protection`, `Status`) before extracting. For a TypeScript-sourced package it extracts only `main.ts` — the compiled `main.js`/`main.js.map` are not written back out, so a pack → unpack round trip returns a clean, editable script folder rather than a compiled snapshot.
|
|
69
|
+
|
|
70
|
+
## Verify entry points before packing
|
|
71
|
+
|
|
72
|
+
Switch's entry-point scanner is regex-based, not a real parser, and can silently drop entry-point
|
|
73
|
+
functions from certain string/regex/division shapes — see
|
|
74
|
+
[entry-points.md § Entry-point scanner constraints](../switch-api/entry-points.md#entry-point-scanner-constraints).
|
|
75
|
+
`--pack` does not validate or warn about this: a script that packs cleanly can still fail to load,
|
|
76
|
+
or load with a property callback that silently never runs. Compiling and passing tests doesn't
|
|
77
|
+
catch it either, since the source is syntactically valid JS/TS — only extraction against the built
|
|
78
|
+
`main.js` does.
|
|
79
|
+
|
|
80
|
+
After any edit to `main.ts`/`main.js`, run the extracted entry points against the **built**
|
|
81
|
+
`main.js` and confirm the expected names come back. Python:
|
|
82
|
+
|
|
83
|
+
```python
|
|
84
|
+
#!/usr/bin/env python3
|
|
85
|
+
import re, sys
|
|
86
|
+
|
|
87
|
+
STRIP_PATTERN = re.compile(
|
|
88
|
+
r'(?:/\*.*?\*/)'
|
|
89
|
+
r'|(?:(["\'`])\1)'
|
|
90
|
+
r'|(?://.*?$)'
|
|
91
|
+
r'|(?:([/"\'`]).*?[^\\]\2)'
|
|
92
|
+
r'|(?:/(?:\\.|[^/\n])*/)'
|
|
93
|
+
r'|(?:\(\s*\w+\s*/\s*\w+\s*\))'
|
|
94
|
+
r'|(?:\w+\s*/\s*\w+)',
|
|
95
|
+
re.DOTALL | re.MULTILINE,
|
|
96
|
+
)
|
|
97
|
+
FUNC_PATTERN = re.compile(r'function[\s\n\r]+(\$?\w+)[\s\n\r]*\(', re.MULTILINE)
|
|
98
|
+
NODE_ENTRY_POINTS = {
|
|
99
|
+
'timerFired', 'jobArrived', 'getLibraryForProperty', 'getLibraryForConnectionProperty',
|
|
100
|
+
'findExternalEditorPath', 'validateProperties', 'validateConnectionProperties',
|
|
101
|
+
'httpRequestTriggeredSync', 'httpRequestTriggeredAsync', 'flowStopTriggered',
|
|
102
|
+
'flowStartTriggered', 'abort',
|
|
103
|
+
}
|
|
104
|
+
REQUIRED_ANY = {'jobArrived', 'timerFired', 'flowStopTriggered', 'httpRequestTriggeredAsync'}
|
|
105
|
+
|
|
106
|
+
code = open(sys.argv[1], encoding='utf-8').read()
|
|
107
|
+
stripped = STRIP_PATTERN.sub('', code)
|
|
108
|
+
found = [m.group(1) for m in FUNC_PATTERN.finditer(stripped) if m.group(1) in NODE_ENTRY_POINTS]
|
|
109
|
+
print('Entry points found:', found or '(none)')
|
|
110
|
+
if not (REQUIRED_ANY & set(found)):
|
|
111
|
+
sys.exit('FAIL: none of ' + str(sorted(REQUIRED_ANY)) + ' survived extraction.')
|
|
112
|
+
```
|
|
113
|
+
|
|
114
|
+
Or Node.js:
|
|
115
|
+
|
|
116
|
+
```js
|
|
117
|
+
#!/usr/bin/env node
|
|
118
|
+
const fs = require('fs');
|
|
119
|
+
|
|
120
|
+
const STRIP_PATTERN = /(?:\/\*[\s\S]*?\*\/)|(?:(["'`])\1)|(?:\/\/.*?$)|(?:([/"'`])[\s\S]*?[^\\]\2)|(?:\/(?:\\.|[^/\n])*\/)|(?:\(\s*\w+\s*\/\s*\w+\s*\))|(?:\w+\s*\/\s*\w+)/gm;
|
|
121
|
+
const FUNC_PATTERN = /function[\s\n\r]+(\$?\w+)[\s\n\r]*\(/gm;
|
|
122
|
+
const NODE_ENTRY_POINTS = new Set([
|
|
123
|
+
'timerFired', 'jobArrived', 'getLibraryForProperty', 'getLibraryForConnectionProperty',
|
|
124
|
+
'findExternalEditorPath', 'validateProperties', 'validateConnectionProperties',
|
|
125
|
+
'httpRequestTriggeredSync', 'httpRequestTriggeredAsync', 'flowStopTriggered',
|
|
126
|
+
'flowStartTriggered', 'abort',
|
|
127
|
+
]);
|
|
128
|
+
const REQUIRED_ANY = ['jobArrived', 'timerFired', 'flowStopTriggered', 'httpRequestTriggeredAsync'];
|
|
129
|
+
|
|
130
|
+
const stripped = fs.readFileSync(process.argv[2], 'utf8').replace(STRIP_PATTERN, '');
|
|
131
|
+
const found = [];
|
|
132
|
+
let m;
|
|
133
|
+
while ((m = FUNC_PATTERN.exec(stripped)) !== null) {
|
|
134
|
+
if (NODE_ENTRY_POINTS.has(m[1])) found.push(m[1]);
|
|
135
|
+
}
|
|
136
|
+
console.log('Entry points found:', found.length ? found : '(none)');
|
|
137
|
+
if (!found.some((f) => REQUIRED_ANY.includes(f))) {
|
|
138
|
+
console.error('FAIL: none of', REQUIRED_ANY, 'survived extraction.');
|
|
139
|
+
process.exit(1);
|
|
140
|
+
}
|
|
141
|
+
```
|
|
142
|
+
|
|
143
|
+
If the required entry point is missing, dump `stripped`/the stripped output and diff it against
|
|
144
|
+
`main.js` — the first swallowed region starts at the string, regex, or division literal identified
|
|
145
|
+
in the rules above.
|
|
146
|
+
|
|
147
|
+
## Deployment
|
|
148
|
+
|
|
149
|
+
Before packing, remove dev dependencies to reduce package size — this matters because `--pack` bundles `node_modules` as-is, and the scaffolded `package.json` puts type-only packages (`@types/node`, `@types/switch-scripting`, `undici-types`) under `devDependencies`:
|
|
150
|
+
|
|
151
|
+
```
|
|
152
|
+
npm prune --production
|
|
153
|
+
```
|
|
154
|
+
|
|
155
|
+
Then pack:
|
|
156
|
+
|
|
157
|
+
```
|
|
158
|
+
SwitchScriptTool --pack <ScriptFolder> <OutputFolder>
|
|
159
|
+
```
|
|
160
|
+
|
|
161
|
+
Reasons not to use a script folder in production:
|
|
162
|
+
- Not included in flow exports or backups
|
|
163
|
+
- Slower execution than a package
|
|
164
|
+
- Any syntax error saved to `main.js` immediately breaks the running script
|
|
165
|
+
- No password protection available
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
---
|
|
2
|
+
id: vscode
|
|
3
|
+
category: switch-project
|
|
4
|
+
order: 13
|
|
5
|
+
summary: "Type declarations, tsconfig for TypeScript 6, ESLint rules, entry point snippets"
|
|
6
|
+
triggers:
|
|
7
|
+
- "Setting up VS Code or fixing type errors"
|
|
8
|
+
---
|
|
9
|
+
|
|
10
|
+
# VS Code Setup
|
|
11
|
+
|
|
12
|
+
## Type declarations
|
|
13
|
+
|
|
14
|
+
Enables autocomplete and type checking for `Switch`, `Job`, `FlowElement` and all Switch API globals.
|
|
15
|
+
|
|
16
|
+
**Via npm (preferred):** Add to `devDependencies` in `package.json` and run `npm install`:
|
|
17
|
+
|
|
18
|
+
```json
|
|
19
|
+
"@types/switch-scripting": "https://github.com/enfocus-switch/types-switch-scripting/archive/refs/tags/v24.1.1-final.tar.gz"
|
|
20
|
+
```
|
|
21
|
+
|
|
22
|
+
**Manual fallback:** Download `index.d.ts` from the types repo and place it at `node_modules/@types/switch-scripting/index.d.ts` inside the script folder.
|
|
23
|
+
|
|
24
|
+
> `SwitchScriptTool --create` sets this up automatically for new TypeScript script folders.
|
|
25
|
+
|
|
26
|
+
v24.1.1-final is the last published version and matches the API of every Switch release from 24.1
|
|
27
|
+
to 26.11. It declares every method without marking which Switch release added it, so the compiler
|
|
28
|
+
won't flag a call that an older target Switch lacks. Check those against
|
|
29
|
+
[api-versions.md](../switch-api/api-versions.md).
|
|
30
|
+
|
|
31
|
+
SwitchScriptTool 26.11 also scaffolds `@types/node` 24.x whatever Node.js version the script will
|
|
32
|
+
run on. When the package will run on an older Node.js (see
|
|
33
|
+
[node-versions.md](node-versions.md)),
|
|
34
|
+
pin `@types/node` to that major version so the compiler flags newer Node.js APIs.
|
|
35
|
+
|
|
36
|
+
## TypeScript 6 / VS Code 1.114+
|
|
37
|
+
|
|
38
|
+
From VS Code 1.114, TypeScript 6 is used. Ambient/global types are no longer auto-included — without explicit configuration, `@types/node` and `@types/switch-scripting` globals (`Switch`, `Job`, etc.) will not be recognised.
|
|
39
|
+
|
|
40
|
+
Add a `types` array to `compilerOptions` in `tsconfig.json`:
|
|
41
|
+
|
|
42
|
+
```json
|
|
43
|
+
{
|
|
44
|
+
"compilerOptions": {
|
|
45
|
+
"types": ["node", "switch-scripting"]
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
```
|
|
49
|
+
|
|
50
|
+
## ESLint rules
|
|
51
|
+
|
|
52
|
+
Two rules that catch Switch-specific async bugs before runtime:
|
|
53
|
+
|
|
54
|
+
- **`require-await`** — flags `async` functions that never actually `await`, catching accidentally dropped API call promises
|
|
55
|
+
- **`@typescript-eslint/no-floating-promises`** — errors on any unawaited promise; in Switch scripts these cause silent race conditions that are very difficult to diagnose
|
|
56
|
+
|
|
57
|
+
Example `.eslintrc`:
|
|
58
|
+
|
|
59
|
+
```json
|
|
60
|
+
{
|
|
61
|
+
"root": true,
|
|
62
|
+
"parser": "@typescript-eslint/parser",
|
|
63
|
+
"parserOptions": { "project": "./tsconfig.json" },
|
|
64
|
+
"plugins": ["@typescript-eslint", "prettier"],
|
|
65
|
+
"extends": [
|
|
66
|
+
"eslint:recommended",
|
|
67
|
+
"plugin:@typescript-eslint/eslint-recommended",
|
|
68
|
+
"plugin:@typescript-eslint/recommended",
|
|
69
|
+
"prettier"
|
|
70
|
+
],
|
|
71
|
+
"rules": {
|
|
72
|
+
"require-await": 2,
|
|
73
|
+
"@typescript-eslint/no-floating-promises": 2,
|
|
74
|
+
"prettier/prettier": 2
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
```
|
|
78
|
+
|
|
79
|
+
## Snippets
|
|
80
|
+
|
|
81
|
+
`SwitchScriptTool --create` generates `.vscode/switch.code-snippets` for TypeScript scripts only; a
|
|
82
|
+
`--JavaScript` scaffold gets none. The file has one snippet per entry point, 13 in all (checked with
|
|
83
|
+
SwitchScriptTool 26.11). Each prefix is `switch` followed by the entry point name, for example
|
|
84
|
+
`switchJobArrived` or `switchHttpRequestTriggeredSync`. The one exception is
|
|
85
|
+
`switchfindExternalEditorPath`, with a lowercase `f`. Each snippet inserts an empty top-level
|
|
86
|
+
`async function` with the signature from [entry-points.md](../switch-api/entry-points.md), without
|
|
87
|
+
`export`.
|
|
88
|
+
|
|
89
|
+
Snippets expand only when a person types the prefix in VS Code. An agent writing `main.ts` copies the
|
|
90
|
+
signature from `entry-points.md` instead.
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
# Switch Scripting (Node.js)
|
|
2
|
+
Enfocus Switch workflow automation scripts written in TypeScript/Node.js.
|
|
3
|
+
|
|
4
|
+
Read the matching file from the API reference table below before answering any question about Switch scripting, not only before writing code. This applies to short and yes/no questions too. This page only summarises; the answer usually depends on a detail that is only in the linked file, and Switch often differs from what general Node.js or scripting knowledge suggests.
|
|
5
|
+
|
|
6
|
+
## Execution environment
|
|
7
|
+
- Entry points are top-level `async` functions with specific names — **not exported** — executed in a `node:vm.Script()` context.
|
|
8
|
+
- ESM is supported: if ES modules are present the script is bundled with ESBuild before running (when `SwitchVersion` in `manifest.xml` is `24.0` or higher).
|
|
9
|
+
- Type declarations are in `node_modules/@types/switch-scripting/index.d.ts` and must be followed precisely. They list every method up to Switch 24.1 without saying which release added it.
|
|
10
|
+
- The Node.js version comes from `SwitchVersion` in `manifest.xml`; the available API methods come from the Switch version the script runs on. See `switch-project/node-versions.md` and `switch-api/api-versions.md`.
|
|
11
|
+
|
|
12
|
+
## API reference
|
|
13
|
+
Detailed docs live in three folders, alongside this file: `switch-api/` (the scripting API itself),
|
|
14
|
+
`switch-project/` (script/app project structure and tooling), and `switch-appstore/` (Appstore
|
|
15
|
+
publishing guidance).
|
|
16
|
+
|
|
17
|
+
<!-- docs-index:table begin -->
|
|
18
|
+
| File | Contents | Load when |
|
|
19
|
+
|---|---|---|
|
|
20
|
+
| `switch-project/project-planning.md` | Planning checklist, run before scaffolding or on a project that is already scaffolded: Script vs App, job-processing approach, one script folder or several, target OS, Switch version baseline, concurrency, native/binary npm dependencies, Appstore competition risk | Starting a new script or app, before scaffolding any files, or working in a script folder that is already scaffolded where Script vs App has not been settled |
|
|
21
|
+
| `switch-api/entry-points.md` | All entry point signatures, constraints, and when each is called | Scaffolding a script, adding/editing an entry point, or making any edit to main.ts/main.js |
|
|
22
|
+
| `switch-api/switch.md` | `Switch` (`s`): global data, webhooks, abort, server utilities | Using global data, webhooks, abort, or server settings |
|
|
23
|
+
| `switch-api/flow-element.md` | `FlowElement`: properties, connections, job creation, logging | Reading properties, creating jobs, logging, connections |
|
|
24
|
+
| `switch-api/job.md` | `Job` **signatures**: routing, file access, child jobs, private data, datasets | Looking up what a `job.*` method takes, returns, or throws |
|
|
25
|
+
| `switch-api/connection.md` | `Connection`: type, properties, file count | Routing to specific connections or reading connection properties |
|
|
26
|
+
| `switch-api/http.md` | `HttpRequest` / `HttpResponse` + webhook pattern | Handling incoming HTTP webhooks |
|
|
27
|
+
| `switch-api/enums.md` | All enums with string values (`LogLevel`, `AccessLevel`, `DatasetModel`, `Scope`, `Priority`, `Connection.Level`, etc.) | Looking up enum values |
|
|
28
|
+
| `switch-api/document-classes.md` | `PdfDocument`, `PdfPage`, `ImageDocument`, `XmlDocument`, `XmpDocument`: read-only file introspection | Inspecting PDF, image, XML, or XMP file contents |
|
|
29
|
+
| `switch-project/script-structure.md` | What files a script folder contains, laying out several script folders side by side, `manifest.xml` format, Script vs App, packing an app with SwitchScripter | Setting up a new script project or converting a Script to an App |
|
|
30
|
+
| `switch-project/tooling.md` | SwitchScriptTool commands and install paths, folder vs `.sscript` trade-offs, deployment | Running SwitchScriptTool: transpiling, packing, unpacking, or deploying |
|
|
31
|
+
| `switch-project/debugging.md` | Enabling debug mode in Switch Designer, debuggable entry points, VS Code attach | Debugging a script |
|
|
32
|
+
| `switch-project/vscode.md` | Type declarations, tsconfig for TypeScript 6, ESLint rules, entry point snippets | Setting up VS Code or fixing type errors |
|
|
33
|
+
| `switch-project/script-declaration.md` | XML declaration reference: properties, connections, execution config; agents may edit this file directly | Understanding, adding, or editing script properties/connections/execution config |
|
|
34
|
+
| `switch-project/property-editors.md` | Property editor types, string return values, literal editors, dropdowns | Defining property editors in XML or reading property values in code |
|
|
35
|
+
| `switch-api/job-patterns.md` | `Job` **rules and gotchas**: file access semantics, temp cleanup, which `sendTo*()` suits which connection type, dataset/child ordering, locking shared global data, executor limits | Writing or reviewing job-handling code. Pair with `job.md` when you also need signatures |
|
|
36
|
+
| `switch-api/execution-environment.md` | Execution modes (`Concurrent`/`Serialized`, `ExecutionGroup`, `NumberOfSlots`), process/concurrency model, state persistence across job invocations, unhandled-rejection behavior, npm/native module constraints | Choosing or changing an execution mode, relying on module-level state across jobs, handling errors/rejections, or using third-party npm packages |
|
|
37
|
+
| `switch-api/logging.md` | Log level semantics, logging practice, `console.log` limitation, common gotchas | Adding or reviewing `job.log()`/`flowElement.log()`/`job.fail()`/`failProcess()` calls |
|
|
38
|
+
| `switch-project/logs-and-dataroot.md` | Locating the Application Data Root, querying `ServerLogs.db3` directly | Diagnosing or validating a script from its actual log output rather than by reading the code |
|
|
39
|
+
| `switch-appstore/app-guidelines.md` | Pre-publish checklist for Appstore apps: property naming/tooltips/editors, entry point and sendTo consistency, logging quality, packaging, and the app-only submission rules (localization, signed universal macOS binaries) | Preparing a script for publication as an app, or reviewing one against Appstore submission criteria |
|
|
40
|
+
| `switch-project/property-documentation.md` | Writing guidance for `Tooltip` and `DetailedInfo` content on properties/connections | Writing or reviewing the text in a property's or connection's `Tooltip`/`DetailedInfo` |
|
|
41
|
+
| `switch-appstore/app-store-listing.md` | Writing guidance for the declaration's Appstore listing fields: `Description`, `Compatibility`, `SupportInfo`, `AppDiscovery`, `Connections` | Writing or reviewing the app's Appstore listing text |
|
|
42
|
+
| `switch-appstore/app-manual.md` | Writing guidance for the separate app manual document uploaded during Appstore review (`documentation-app_name.docx` template) | Preparing the app manual document for Appstore submission |
|
|
43
|
+
| `switch-appstore/app-store-submission.md` | Writing guidance for the Create Appstore App / Create Appstore App Version web forms: Short Description, What's new, Eula, icon specs, and which fields reuse content already written elsewhere | Preparing content for the Appstore website submission forms |
|
|
44
|
+
| `switch-api/api-versions.md` | Which Switch release added each scripting API class, method, and enum value; API availability follows the running Switch, not `manifest.xml` | Writing or reviewing code for a script or app that must run on a Switch version older than the latest, or when the user names a minimum Switch version |
|
|
45
|
+
| `switch-project/node-versions.md` | How `SwitchVersion` in `manifest.xml` selects the Node.js version, the version table per Switch release, which tools overwrite `SwitchVersion`, values missing from the table, other effects of `SwitchVersion` | Working out which Node.js version a script or app will run on, or what `SwitchVersion` in manifest.xml does |
|
|
46
|
+
<!-- docs-index:table end -->
|
|
47
|
+
|
|
48
|
+
## Key rules
|
|
49
|
+
- Before scaffolding a new script or app, work through `switch-project/project-planning.md` with the user.
|
|
50
|
+
If the script folder is already scaffolded, still ask Script or App; the manifest cannot answer it.
|
|
51
|
+
- If the script or app must run on a Switch version older than the latest, check each API call
|
|
52
|
+
against `switch-api/api-versions.md`. The API files mark anything newer than the baseline with
|
|
53
|
+
"Switch X+" (a `// Switch X+` comment above a signature, or a note in the text), meaning that
|
|
54
|
+
version or later.
|
|
55
|
+
- To find documented behavioural pitfalls before writing code in an area, grep the `switch-api/`,
|
|
56
|
+
`switch-project/`, and `switch-appstore/` docs folders for `known issue`, `gotcha`,
|
|
57
|
+
`quirk`, `caveat` (case-insensitive) — every documented pitfall uses one of these four terms.
|
|
58
|
+
- Do not `export` entry point functions. Declare them with the literal `function` keyword at top
|
|
59
|
+
level — arrow functions, `exports.name = ...`, and class methods are invisible to Switch.
|
|
60
|
+
- Switch discovers entry points with a regex, not a parser. Never write a string literal whose
|
|
61
|
+
content ends with a backslash, a regex literal, or division outside the plain `word / word`
|
|
62
|
+
shape — each silently deletes a span of real code, and every entry point inside that span
|
|
63
|
+
disappears with no error anywhere. Read `switch-api/entry-points.md` §
|
|
64
|
+
Entry-point scanner constraints before editing `main.ts`/`main.js`.
|
|
65
|
+
- Every `jobArrived` invocation must end with exactly one `job.sendTo*()` or `job.fail()` call — either in the same invocation or deferred to `timerFired` via job information stored in global data.
|
|
66
|
+
- Use `AccessLevel.ReadOnly` for `job.get()` unless the file content will be modified.
|
|
67
|
+
- After editing `main.ts`, transpile with `SwitchScriptTool --transpile <folder>`. Do not use `tsc` directly.
|
|
68
|
+
- Never use a script folder in production. Pack it with `SwitchScriptTool --pack` first; flow exports and backups leave script folders out.
|
|
69
|
+
- After calling `createJob()`, `createChild()`, or `createDataset()` with a file path, the script must delete the source file/folder after routing — Switch does not auto-remove it.
|
|
70
|
+
- The XML declaration (`<ScriptID>.xml`) can be edited directly — read `switch-project/script-declaration.md` first and follow its rules exactly (no schema validates this format, so mistakes fail silently). Never change an existing script's `Name`. Bump `Version` only when the current value has already been released, not on every edit. Leave `manifest.xml` edits (package type, declaration filename, program files) to the user unless explicitly asked.
|
package/package.json
ADDED
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@enfocussw/switch-scripting-context",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "AI coding assistant context for Enfocus Switch scripting (Node.js/TypeScript)",
|
|
5
|
+
"keywords": [
|
|
6
|
+
"switch",
|
|
7
|
+
"enfocus",
|
|
8
|
+
"switch-scripting",
|
|
9
|
+
"ai-context",
|
|
10
|
+
"claude",
|
|
11
|
+
"copilot",
|
|
12
|
+
"cursor",
|
|
13
|
+
"codex",
|
|
14
|
+
"gemini",
|
|
15
|
+
"windsurf",
|
|
16
|
+
"zed",
|
|
17
|
+
"cline"
|
|
18
|
+
],
|
|
19
|
+
"main": "dist/init.js",
|
|
20
|
+
"bin": {
|
|
21
|
+
"switch-scripting-context": "bin/cli.js"
|
|
22
|
+
},
|
|
23
|
+
"files": [
|
|
24
|
+
"bin/",
|
|
25
|
+
"dist/",
|
|
26
|
+
"!dist/*.test.js",
|
|
27
|
+
"docs/",
|
|
28
|
+
"!docs/superpowers",
|
|
29
|
+
"!docs/temp",
|
|
30
|
+
"!docs/adr",
|
|
31
|
+
"CHANGELOG.md"
|
|
32
|
+
],
|
|
33
|
+
"scripts": {
|
|
34
|
+
"build": "tsc -p tsconfig.json",
|
|
35
|
+
"build:test": "tsc src/init.test.ts --outDir dist --target ES2020 --module commonjs --lib ES2020 --types node --strict --esModuleInterop --skipLibCheck",
|
|
36
|
+
"test": "npm run build && npm run build:test && node dist/init.test.js && node --test scripts/release.test.js && node scripts/check-prose.js && node scripts/check-gotcha-tags.js && node scripts/generate-docs-index.js --check",
|
|
37
|
+
"prepack": "npm run build && node scripts/readme-links.js --publish",
|
|
38
|
+
"postpack": "node scripts/readme-links.js --restore && node -e \"const fs=require('fs');const version=process.env.npm_package_version;const scoped=process.env.npm_package_name.replace(/^@/,'').replace('/','-')+'-'+version+'.tgz';const unscoped=process.env.npm_package_name.replace(/^@[^/]+\\//,'')+'-'+version+'.tgz';if(scoped!==unscoped&&fs.existsSync(scoped))fs.renameSync(scoped,unscoped);\"",
|
|
39
|
+
"lint:prose": "node scripts/check-prose.js",
|
|
40
|
+
"lint:gotchas": "node scripts/check-gotcha-tags.js",
|
|
41
|
+
"docs:generate": "node scripts/generate-docs-index.js",
|
|
42
|
+
"release:prepare": "node scripts/release.js prepare"
|
|
43
|
+
},
|
|
44
|
+
"author": "Sam Wallace",
|
|
45
|
+
"license": "ISC",
|
|
46
|
+
"repository": {
|
|
47
|
+
"type": "git",
|
|
48
|
+
"url": "git+https://github.com/esko-bv/enf-switch-scripting-context.git"
|
|
49
|
+
},
|
|
50
|
+
"publishConfig": {
|
|
51
|
+
"registry": "https://registry.npmjs.org/",
|
|
52
|
+
"access": "public"
|
|
53
|
+
},
|
|
54
|
+
"devDependencies": {
|
|
55
|
+
"@types/node": "^20.0.0",
|
|
56
|
+
"typescript": "^5.0.0"
|
|
57
|
+
},
|
|
58
|
+
"homepage": "https://github.com/esko-bv/enf-switch-scripting-context#readme",
|
|
59
|
+
"bugs": {
|
|
60
|
+
"url": "https://github.com/esko-bv/enf-switch-scripting-context/issues"
|
|
61
|
+
},
|
|
62
|
+
"engines": {
|
|
63
|
+
"node": ">=18"
|
|
64
|
+
}
|
|
65
|
+
}
|