Files
2026-09-23 12:29:08 -03:00

98 lines
2.8 KiB
Markdown

# Create Vitruvio Script
> All messages shown to the user must be written in Portuguese.
You are creating a new script inside a Vitruvio repository. Follow these steps in order.
## Step 1 — Confirm you are inside a Vitruvio repo
```bash
ls vitruvio.json 2>/dev/null && echo "OK" || echo "NOT_A_VITRUVIO_REPO"
```
If `NOT_A_VITRUVIO_REPO`, stop and tell the user to `cd` into the correct repo.
## Step 2 — Collect script details
Ask the user (in a single message, only ask what is missing from their original request):
- **Key (sigla)** — unique identifier used in `libService.loadScript('key')`. Snake_case. Must be unique across all scripts in the repo. If the user already provided a name, suggest a key derived from it.
- **Name** — human-readable label shown in the Vitruvio UI.
- **Pattern** — which of the two patterns applies:
- **Library** — reusable module, loaded by other scripts/endpoints/panels via `libService.loadScript`. Wrap in `({...})`.
- **Process/task script** — runs directly from a process task or scheduler. Top-level execution, no export.
- **Description** — one sentence about what this script does (optional, but ask if not provided).
- **Domain** — `USUARIO` (user-level, default) or `SISTEMA` (system-level).
## Step 3 — Create the file
Target path: `scripts/<key>.js`
### Library template
```javascript
/**
* Nome: <name>
* Sigla: <key>
* Descrição: <description>
*/
({
// example function — replace with actual implementation
run: function(params) {
var db = libService.loadScript('db');
var banco = new db(db.VITRUVIO_DATASOURCE);
// implementation here
return {};
}
})
```
### Process / task script template
```javascript
/**
* Nome: <name>
* Sigla: <key>
* Descrição: <description>
*/
(function(execution) {
var db = libService.loadScript('db');
var banco = new db(db.VITRUVIO_DATASOURCE);
// implementation here
})(execution)
```
Rules (Rhino ES5 — no exceptions):
- No `let`, `const`, arrow functions, template literals, destructuring, spread, `class`, or `import/export`
- Use `var` everywhere
- No `require`, `process`, `window`, or Node/browser globals
- String concatenation with `+`, not template literals
- `JSON.parse` / `JSON.stringify` for serialization
## Step 4 — Register in vitruvio.json
Read `vitruvio.json`, find or create the `"scripts"` array, and add:
```json
{
"key": "<key>",
"name": "<name>",
"description": "<description>",
"language": "javascript",
"domain": "<USUARIO|SISTEMA>",
"source": "scripts/<key>.js"
}
```
Preserve the existing file structure and all other entries. Write the updated `vitruvio.json` back.
## Step 5 — Report
Tell the user:
- File created: `scripts/<key>.js`
- Registered in `vitruvio.json` with key `<key>`
- How to load it from another script or endpoint: `var lib = libService.loadScript('<key>');`