@openfn/cli 0.0.40 → 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/README.md +183 -49
- package/dist/index.js +162 -116
- package/dist/process/runner.js +143 -70
- package/package.json +7 -6
package/README.md
CHANGED
|
@@ -1,17 +1,36 @@
|
|
|
1
1
|
# @openfn/cli
|
|
2
2
|
|
|
3
|
-
This package contains a new devtools CLI for running OpenFn jobs.
|
|
3
|
+
This package contains a new devtools CLI for running and deploying OpenFn jobs.
|
|
4
4
|
|
|
5
5
|
The CLI includes:
|
|
6
6
|
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
7
|
+
- A secure runtime for executing OpenFn jobs and workflows
|
|
8
|
+
- A compiler for making OpenFn jobs runnable
|
|
9
|
+
- Configurable logging output
|
|
10
|
+
- Auto-installation of language adaptors
|
|
11
|
+
- Support for the adaptors monorepo
|
|
12
|
+
- Deployment of workflows to OpenFn (and Lightning)
|
|
12
13
|
|
|
13
14
|
## Getting Started
|
|
14
15
|
|
|
16
|
+
- [Installation](#installation)
|
|
17
|
+
- [Updating](#updating)
|
|
18
|
+
- [Migrating from devtools](#migrating-from-devtools)
|
|
19
|
+
- [Basic Usage](#basic-usage)
|
|
20
|
+
- [Advanced Usage](#advanced-usage)
|
|
21
|
+
- [Deploying Workflows](#deploying-workflows)
|
|
22
|
+
- [Logging](#logging)
|
|
23
|
+
- [Structured/JSON logging](#structuredjson-logging)
|
|
24
|
+
- [Workflows](#workflows)
|
|
25
|
+
- [Compilation](#compilation)
|
|
26
|
+
- [Contributing](#contributing)
|
|
27
|
+
- [Usage from this repo](#usage-from-this-repo)
|
|
28
|
+
- [Installing globally](#installing-globally)
|
|
29
|
+
- [Repo Directory](#repo-directory)
|
|
30
|
+
- [Contribution changes](#contribution-changes)
|
|
31
|
+
|
|
32
|
+
## Installation
|
|
33
|
+
|
|
15
34
|
To install:
|
|
16
35
|
|
|
17
36
|
```
|
|
@@ -56,14 +75,13 @@ And then re-installing.
|
|
|
56
75
|
|
|
57
76
|
If you're coming to the CLI from the old openfn devtools, here are a couple of key points to be aware of:
|
|
58
77
|
|
|
59
|
-
|
|
60
|
-
|
|
78
|
+
- The CLI has a shorter, sleeker syntax, so your command should be much shorter
|
|
79
|
+
- The CLI will automatically install adaptors for you (with full version control)
|
|
61
80
|
|
|
62
81
|
## Basic Usage
|
|
63
82
|
|
|
64
83
|
You're probably here to run jobs (expressions) or workflows, which the CLI makes easy:
|
|
65
84
|
|
|
66
|
-
|
|
67
85
|
```
|
|
68
86
|
openfn path/to/workflow.json
|
|
69
87
|
openfn path/to/job.js -ia adaptor-name
|
|
@@ -87,24 +105,123 @@ You can pass `--log info` to get more feedback about what's happening, or `--log
|
|
|
87
105
|
|
|
88
106
|
The CLI has a number of commands (the first argument after openfn)
|
|
89
107
|
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
108
|
+
- execute - run a job
|
|
109
|
+
- compile - compile a job to a .js file
|
|
110
|
+
- docs - show documentation for an adaptor function
|
|
111
|
+
- repo - manage the repo of installed modules
|
|
112
|
+
- docgen - generate JSON documentation for an adaptor based on its typescript
|
|
95
113
|
|
|
96
114
|
If no command is specified, execute will run.
|
|
97
115
|
|
|
98
116
|
To get more information about a command, including usage examples, run `openfn <command> help`, ie, `openfn compile help`.
|
|
99
117
|
|
|
100
|
-
##
|
|
118
|
+
## Deploying Workflows
|
|
119
|
+
|
|
120
|
+
> ⚠️ This feature is still in active development. Expect breaking changes.
|
|
121
|
+
|
|
122
|
+
The CLI can deploy workflows to OpenFn.org and instances of Lightning.
|
|
123
|
+
|
|
124
|
+
In order to deploy a workflow, you need the follow:
|
|
125
|
+
|
|
126
|
+
- A project file written in YAML
|
|
127
|
+
- A config file (or env vars) with your OpenFn credentials
|
|
128
|
+
|
|
129
|
+
Example project file:
|
|
130
|
+
|
|
131
|
+
```yaml
|
|
132
|
+
---
|
|
133
|
+
name: my-new-project
|
|
134
|
+
workflows:
|
|
135
|
+
workflow-one:
|
|
136
|
+
name: My New Workflow
|
|
137
|
+
jobs:
|
|
138
|
+
job-a:
|
|
139
|
+
name: My First Job
|
|
140
|
+
enabled: true # default
|
|
141
|
+
adaptor: @openfn/language-http@latest
|
|
142
|
+
body: |
|
|
143
|
+
alterState(state => {
|
|
144
|
+
console.log("Hello world!");
|
|
145
|
+
return state;
|
|
146
|
+
});
|
|
147
|
+
job-b:
|
|
148
|
+
name: My Second Job
|
|
149
|
+
adaptor: @openfn/language-common@latest
|
|
150
|
+
body: |
|
|
151
|
+
alterState(state => {
|
|
152
|
+
console.log("Hello world!");
|
|
153
|
+
return state;
|
|
154
|
+
});
|
|
155
|
+
triggers:
|
|
156
|
+
trigger-one:
|
|
157
|
+
type: webhook # default
|
|
158
|
+
edges:
|
|
159
|
+
webhook->job-a:
|
|
160
|
+
source_trigger: trigger-one
|
|
161
|
+
target_job: job-a
|
|
162
|
+
job-a->job-b:
|
|
163
|
+
source_job: job-a
|
|
164
|
+
target_job: job-b
|
|
165
|
+
|
|
166
|
+
```
|
|
167
|
+
|
|
168
|
+
Example config file:
|
|
169
|
+
|
|
170
|
+
```jsonc
|
|
171
|
+
{
|
|
172
|
+
// Required, can be overridden or set with `OPENFN_API_KEY` env var
|
|
173
|
+
"apiKey": "***",
|
|
174
|
+
|
|
175
|
+
// Optional: can be set using the -p, defaults to project.yaml
|
|
176
|
+
"specPath": "project.yaml",
|
|
177
|
+
|
|
178
|
+
// Optional: can be set using -s, defaults to .state.json
|
|
179
|
+
"statePath": ".state.json",
|
|
180
|
+
|
|
181
|
+
// Optional: defaults to OpenFn.org's API, can be overridden or set with
|
|
182
|
+
// `OPENFN_ENDPOINT` env var
|
|
183
|
+
"endpoint": "https://app.openfn.org/api/provision"
|
|
184
|
+
}
|
|
185
|
+
```
|
|
186
|
+
|
|
187
|
+
**Environment Variables**
|
|
188
|
+
|
|
189
|
+
You can also set the following environment variables to avoid using a config file:
|
|
190
|
+
|
|
191
|
+
- `OPENFN_API_KEY` - your OpenFn/Lightning API key
|
|
192
|
+
- `OPENFN_ENDPOINT` - the endpoint to deploy to (defaults to OpenFn.org)
|
|
193
|
+
|
|
194
|
+
**Using the CLI**
|
|
195
|
+
|
|
196
|
+
```bash
|
|
197
|
+
OPENFN_API_KEY="***" \
|
|
198
|
+
openfn deploy
|
|
199
|
+
|
|
200
|
+
# [CLI] ♦ Changes:
|
|
201
|
+
# {
|
|
202
|
+
# + ... diff
|
|
203
|
+
# - ... diff
|
|
204
|
+
# }
|
|
205
|
+
#
|
|
206
|
+
# ? Deploy? yes
|
|
207
|
+
# [CLI] ♦ Deployed.
|
|
208
|
+
```
|
|
209
|
+
|
|
210
|
+
**Flags and Options**
|
|
211
|
+
|
|
212
|
+
- `-p, --project-path <path>` - path to the project file (defaults to `project.yaml`)
|
|
213
|
+
- `-s, --state-path <path>` - path to the state file (defaults to `.state.json`)
|
|
214
|
+
- `-c, --config, --config-path` - path to the config file (defaults to `.config.json`)
|
|
215
|
+
- `--no-confirm` - skip the confirmation prompt
|
|
216
|
+
|
|
217
|
+
## Logging
|
|
101
218
|
|
|
102
219
|
The CLI is actually a collection of packages, each of which will log with slightly different rules. To help understand where logs are coming from, each package prints a namespace or prefix at the start of its log.
|
|
103
220
|
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
221
|
+
- [CLI] - the CLI itself, responsible for parsing and validating user input, reading and writing to disk, and executing the correct functionality.
|
|
222
|
+
- [CMP] - the Compiler will parse openfn jobs into executable Javascript, changing your code
|
|
223
|
+
- [R/T] - the Runtime executes your job code in a secure sandboxed environment, one operation at a time
|
|
224
|
+
- [JOB] - the actual job code that your wrote. Any console.log statements in your job will appear under this namespace.
|
|
108
225
|
|
|
109
226
|
The CLI will log information at three different levels of verbosity: `default`, `info` and `debug` (`none` is also supported).
|
|
110
227
|
|
|
@@ -120,14 +237,18 @@ If something unexpected happens during a command, your first step should be to r
|
|
|
120
237
|
|
|
121
238
|
`debug` level logging is highly verbose and aims to tell you everything that's going on under-the hood. This is aimed mostly at CLI/runtime developers and can be very useful for debugging problems.
|
|
122
239
|
|
|
123
|
-
|
|
240
|
+
### Structred/JSON logging
|
|
124
241
|
|
|
125
242
|
By default all logs will be printed as human-readable strings.
|
|
126
243
|
|
|
127
244
|
For a more structured output, you can emit logs as JSON objects with `level`, `name` and `message` properties:
|
|
245
|
+
|
|
128
246
|
```
|
|
247
|
+
|
|
129
248
|
{ level: 'info', name: 'CLI', message: ['Loaded adaptor'] }
|
|
249
|
+
|
|
130
250
|
```
|
|
251
|
+
|
|
131
252
|
Pass `--log-json` to the CLI to do this. You can also set the OPENFN_LOG_JSON env var (and use `--no-log-json` to disable).
|
|
132
253
|
|
|
133
254
|
## Workflows
|
|
@@ -141,37 +262,39 @@ To see an example workflow, run the test command with `openfn test`.
|
|
|
141
262
|
A workflow has a structure like this (better documentation is coming soon):
|
|
142
263
|
|
|
143
264
|
```
|
|
265
|
+
|
|
144
266
|
{
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
267
|
+
"start": "a", // optionally specify the start node (defaults to jobs[0])
|
|
268
|
+
"jobs": [
|
|
269
|
+
{
|
|
270
|
+
"id": "a",
|
|
271
|
+
"expression": "fn((state) => state)", // code or a path
|
|
272
|
+
"adaptor": "@openfn/language-common@1.75", // specifiy the adaptor to use (version optional)
|
|
273
|
+
"data": {}, // optionally pre-populate the data object (this will be overriden by keys in in previous state)
|
|
274
|
+
"configuration": {}, // Use this to pass credentials
|
|
275
|
+
"next": {
|
|
276
|
+
// This object defines which jobs to call next
|
|
277
|
+
// All edges returning true will run
|
|
278
|
+
// If there are no next edges, the workflow will end
|
|
279
|
+
"b": true,
|
|
280
|
+
"c": {
|
|
281
|
+
"condition": "!state.error" // Not that this is an expression, not a function
|
|
282
|
+
}
|
|
283
|
+
}
|
|
284
|
+
},
|
|
285
|
+
]
|
|
164
286
|
}
|
|
287
|
+
|
|
165
288
|
```
|
|
166
289
|
|
|
167
290
|
## Compilation
|
|
168
291
|
|
|
169
292
|
The CLI will attempt to compile your job code into normalized Javascript. It will do a number of things to make your code robust and portable:
|
|
170
293
|
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
294
|
+
- The language adaptor will be imported into the file
|
|
295
|
+
- The adaptor's execute function will be exported form the file
|
|
296
|
+
- All top level operations will be added to an array
|
|
297
|
+
- That array will be made the default export of the file
|
|
175
298
|
|
|
176
299
|
The result of this is a lightweight, modern JS source file. It can be executed in any runtime environment: just execute each function in the exported array.
|
|
177
300
|
|
|
@@ -181,7 +304,7 @@ All jobs which work against `@openfn/core` will work in the new CLI and runtime
|
|
|
181
304
|
|
|
182
305
|
If you want to see how the compiler is changing your job, run `openfn compile path/to/job -a <adaptor>` to return the compiled code to stdout. Add `-o path/to/output.js` to save the result to disk.
|
|
183
306
|
|
|
184
|
-
|
|
307
|
+
## Contributing
|
|
185
308
|
|
|
186
309
|
First of all, thanks for helping! You're contributing to a digital public good that will always be free and open source and aimed at serving innovative NGOs, governments, and social impact organizations the world over! You rock. heart
|
|
187
310
|
|
|
@@ -189,44 +312,55 @@ To get this started, you'll want to clone this repo.
|
|
|
189
312
|
|
|
190
313
|
You also need to install `pnpm`.
|
|
191
314
|
|
|
192
|
-
|
|
315
|
+
### Usage from this repo
|
|
193
316
|
|
|
194
317
|
You can run the cli straight from source with `pnpm`
|
|
195
318
|
|
|
196
319
|
```
|
|
320
|
+
|
|
197
321
|
$ pnpm openfn path/to/job.js
|
|
198
322
|
$ pnpm openfn -h
|
|
323
|
+
|
|
199
324
|
```
|
|
200
325
|
|
|
201
326
|
See test/execute.test.ts for more usage examples
|
|
202
327
|
|
|
203
|
-
|
|
328
|
+
### Installing globally
|
|
204
329
|
|
|
205
330
|
To install the CLI globally from the build in repo:
|
|
206
331
|
|
|
207
332
|
```
|
|
333
|
+
|
|
208
334
|
$ npm install -g .
|
|
335
|
+
|
|
209
336
|
```
|
|
210
337
|
|
|
211
338
|
Note that this will install the built source from `dist`
|
|
212
339
|
|
|
213
|
-
|
|
340
|
+
### Repo Directory
|
|
214
341
|
|
|
215
342
|
The CLI will save and load adaptors from an arbitrary folder on your system.
|
|
216
343
|
|
|
217
344
|
You should set the OPENFN_REPO_DIR env var to something sensible.
|
|
218
345
|
|
|
219
346
|
In `~/.bashrc` (or whatever you use), add:
|
|
347
|
+
|
|
220
348
|
```
|
|
349
|
+
|
|
221
350
|
export OPENFN_REPO_DIR=~/repo/openfn/cli-repo
|
|
351
|
+
|
|
222
352
|
```
|
|
223
353
|
|
|
224
354
|
To run adaptors straight from the adaptors monorepo:
|
|
225
355
|
|
|
226
356
|
export OPENFN_ADAPTORS_REPO=~/repo/openfn/adaptors
|
|
227
357
|
|
|
228
|
-
|
|
358
|
+
### Contributing changes
|
|
229
359
|
|
|
230
360
|
Open a PR at https://github.com/openfn/kit. Include a changeset and a description of your change.
|
|
231
361
|
|
|
232
|
-
See the root readme for more details about changests,
|
|
362
|
+
See the root readme for more details about changests,
|
|
363
|
+
|
|
364
|
+
```
|
|
365
|
+
|
|
366
|
+
```
|
package/dist/index.js
CHANGED
|
@@ -82,6 +82,24 @@ var compile = {
|
|
|
82
82
|
setDefaultValue(opts2, "compile", true);
|
|
83
83
|
}
|
|
84
84
|
};
|
|
85
|
+
var confirm = {
|
|
86
|
+
name: "no-confirm",
|
|
87
|
+
yargs: {
|
|
88
|
+
boolean: true,
|
|
89
|
+
description: "Skip confirmation prompts (e.g. 'Are you sure?')"
|
|
90
|
+
},
|
|
91
|
+
ensure: (opts2) => {
|
|
92
|
+
setDefaultValue(opts2, "confirm", true);
|
|
93
|
+
}
|
|
94
|
+
};
|
|
95
|
+
var configPath = {
|
|
96
|
+
name: "config",
|
|
97
|
+
yargs: {
|
|
98
|
+
alias: ["c", "config-path"],
|
|
99
|
+
description: "The location of your config file",
|
|
100
|
+
default: "./.config.json"
|
|
101
|
+
}
|
|
102
|
+
};
|
|
85
103
|
var expandAdaptors = {
|
|
86
104
|
name: "no-expand-adaptors",
|
|
87
105
|
yargs: {
|
|
@@ -186,6 +204,14 @@ var outputPath = {
|
|
|
186
204
|
delete opts2.o;
|
|
187
205
|
}
|
|
188
206
|
};
|
|
207
|
+
var projectPath = {
|
|
208
|
+
name: "project-path",
|
|
209
|
+
yargs: {
|
|
210
|
+
string: true,
|
|
211
|
+
alias: ["p"],
|
|
212
|
+
description: "The location of your project.yaml file"
|
|
213
|
+
}
|
|
214
|
+
};
|
|
189
215
|
var repoDir = {
|
|
190
216
|
name: "repo-dir",
|
|
191
217
|
yargs: () => ({
|
|
@@ -240,6 +266,9 @@ var statePath = {
|
|
|
240
266
|
yargs: {
|
|
241
267
|
alias: ["s"],
|
|
242
268
|
description: "Path to the state file"
|
|
269
|
+
},
|
|
270
|
+
ensure: (opts2) => {
|
|
271
|
+
delete opts2.s;
|
|
243
272
|
}
|
|
244
273
|
};
|
|
245
274
|
var stateStdin = {
|
|
@@ -279,7 +308,12 @@ var expandYargs = (y2) => {
|
|
|
279
308
|
}
|
|
280
309
|
return y2;
|
|
281
310
|
};
|
|
282
|
-
|
|
311
|
+
function build(opts2, yargs2) {
|
|
312
|
+
return opts2.reduce(
|
|
313
|
+
(_y, o) => yargs2.option(o.name, expandYargs(o.yargs)),
|
|
314
|
+
yargs2
|
|
315
|
+
);
|
|
316
|
+
}
|
|
283
317
|
var ensure = (command, opts2) => (yargs2) => {
|
|
284
318
|
yargs2.command = command;
|
|
285
319
|
opts2.filter((opt) => opt.ensure).forEach((opt) => {
|
|
@@ -296,63 +330,74 @@ var override = (command, yargs2) => {
|
|
|
296
330
|
};
|
|
297
331
|
};
|
|
298
332
|
|
|
299
|
-
// src/
|
|
300
|
-
var
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
default: true,
|
|
309
|
-
hidden: true
|
|
333
|
+
// src/compile/command.ts
|
|
334
|
+
var options = [
|
|
335
|
+
expandAdaptors,
|
|
336
|
+
adaptors,
|
|
337
|
+
ignoreImports,
|
|
338
|
+
inputPath,
|
|
339
|
+
logJson,
|
|
340
|
+
override(outputStdout, {
|
|
341
|
+
default: true
|
|
310
342
|
}),
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
343
|
+
outputPath,
|
|
344
|
+
repoDir,
|
|
345
|
+
useAdaptorsMonorepo
|
|
314
346
|
];
|
|
315
|
-
var
|
|
316
|
-
command: "
|
|
317
|
-
desc: "
|
|
318
|
-
handler: ensure("
|
|
319
|
-
builder: (yargs2) => build(
|
|
320
|
-
"
|
|
321
|
-
|
|
347
|
+
var compileCommand = {
|
|
348
|
+
command: "compile [path]",
|
|
349
|
+
desc: "Compile an openfn job or workflow and print or save the resulting JavaScript.",
|
|
350
|
+
handler: ensure("compile", options),
|
|
351
|
+
builder: (yargs2) => build(options, yargs2).positional("path", {
|
|
352
|
+
describe: "The path to load the job or workflow from (a .js or .json file or a dir containing a job.js file)",
|
|
353
|
+
demandOption: true
|
|
354
|
+
}).example(
|
|
355
|
+
"compile foo/job.js",
|
|
356
|
+
"Compiles the job at foo/job.js and prints the result to stdout"
|
|
322
357
|
).example(
|
|
323
|
-
"
|
|
324
|
-
"
|
|
358
|
+
"compile foo/workflow.json -o foo/workflow-compiled.json",
|
|
359
|
+
"Compiles the workflow at foo/work.json and prints the result to -o foo/workflow-compiled.json"
|
|
325
360
|
)
|
|
326
361
|
};
|
|
327
|
-
var
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
description: "Skip the prompt and force deletion",
|
|
339
|
-
boolean: true
|
|
340
|
-
}
|
|
341
|
-
}
|
|
342
|
-
],
|
|
343
|
-
yargs2
|
|
344
|
-
)
|
|
362
|
+
var command_default = compileCommand;
|
|
363
|
+
|
|
364
|
+
// src/deploy/command.ts
|
|
365
|
+
var options2 = [statePath, projectPath, configPath, confirm];
|
|
366
|
+
var deployCommand = {
|
|
367
|
+
command: "deploy",
|
|
368
|
+
desc: "Deploy a project's config to a remote Lightning instance",
|
|
369
|
+
builder: (yargs2) => {
|
|
370
|
+
return build(options2, yargs2).example("deploy", "");
|
|
371
|
+
},
|
|
372
|
+
handler: ensure("deploy", options2)
|
|
345
373
|
};
|
|
346
|
-
var
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
374
|
+
var command_default2 = deployCommand;
|
|
375
|
+
|
|
376
|
+
// src/docgen/command.ts
|
|
377
|
+
var docgenCommand = {
|
|
378
|
+
command: "docgen <specifier>",
|
|
379
|
+
desc: false,
|
|
380
|
+
handler: (argv) => {
|
|
381
|
+
argv.command = "docgen";
|
|
382
|
+
},
|
|
383
|
+
builder: (yargs2) => {
|
|
384
|
+
return yargs2.example("docgen @openfn/language-common@1.7.5", "");
|
|
385
|
+
}
|
|
386
|
+
};
|
|
387
|
+
var command_default3 = docgenCommand;
|
|
388
|
+
|
|
389
|
+
// src/docs/command.ts
|
|
390
|
+
var command_default4 = {
|
|
391
|
+
command: "docs <adaptor> [operation]",
|
|
392
|
+
desc: "Print help for an adaptor function. You can use short-hand for adaptor names (ie, common instead of @openfn/language-common)",
|
|
393
|
+
handler: (argv) => {
|
|
394
|
+
argv.command = "docs";
|
|
395
|
+
},
|
|
396
|
+
builder: (yargs2) => yargs2.example("docs common fn", "Print help for the common fn operation")
|
|
352
397
|
};
|
|
353
398
|
|
|
354
399
|
// src/execute/command.ts
|
|
355
|
-
var
|
|
400
|
+
var options3 = [
|
|
356
401
|
expandAdaptors,
|
|
357
402
|
adaptors,
|
|
358
403
|
autoinstall,
|
|
@@ -383,8 +428,8 @@ By default only state.data will be returned fron a job. Include --no-strict to w
|
|
|
383
428
|
|
|
384
429
|
Remember to include the adaptor name with -a. Auto install adaptors with the -i flag.`,
|
|
385
430
|
aliases: ["$0"],
|
|
386
|
-
handler: ensure("execute",
|
|
387
|
-
builder: (yargs2) => build(
|
|
431
|
+
handler: ensure("execute", options3),
|
|
432
|
+
builder: (yargs2) => build(options3, yargs2).positional("path", {
|
|
388
433
|
describe: "The path to load the job or workflow from (a .js or .json file or a dir containing a job.js file)",
|
|
389
434
|
demandOption: true
|
|
390
435
|
}).example(
|
|
@@ -401,70 +446,7 @@ Remember to include the adaptor name with -a. Auto install adaptors with the -i
|
|
|
401
446
|
"Compile job.js with the http adaptor and print the code to stdout"
|
|
402
447
|
)
|
|
403
448
|
};
|
|
404
|
-
var
|
|
405
|
-
|
|
406
|
-
// src/compile/command.ts
|
|
407
|
-
var options2 = [
|
|
408
|
-
expandAdaptors,
|
|
409
|
-
adaptors,
|
|
410
|
-
ignoreImports,
|
|
411
|
-
inputPath,
|
|
412
|
-
logJson,
|
|
413
|
-
override(outputStdout, {
|
|
414
|
-
default: true
|
|
415
|
-
}),
|
|
416
|
-
outputPath,
|
|
417
|
-
repoDir,
|
|
418
|
-
useAdaptorsMonorepo
|
|
419
|
-
];
|
|
420
|
-
var compileCommand = {
|
|
421
|
-
command: "compile [path]",
|
|
422
|
-
desc: "Compile an openfn job or workflow and print or save the resulting JavaScript.",
|
|
423
|
-
handler: ensure("compile", options2),
|
|
424
|
-
builder: (yargs2) => build(options2, yargs2).positional("path", {
|
|
425
|
-
describe: "The path to load the job or workflow from (a .js or .json file or a dir containing a job.js file)",
|
|
426
|
-
demandOption: true
|
|
427
|
-
}).example(
|
|
428
|
-
"compile foo/job.js",
|
|
429
|
-
"Compiles the job at foo/job.js and prints the result to stdout"
|
|
430
|
-
).example(
|
|
431
|
-
"compile foo/workflow.json -o foo/workflow-compiled.json",
|
|
432
|
-
"Compiles the workflow at foo/work.json and prints the result to -o foo/workflow-compiled.json"
|
|
433
|
-
)
|
|
434
|
-
};
|
|
435
|
-
var command_default2 = compileCommand;
|
|
436
|
-
|
|
437
|
-
// src/test/command.ts
|
|
438
|
-
var options3 = [stateStdin];
|
|
439
|
-
var command_default3 = {
|
|
440
|
-
command: "test",
|
|
441
|
-
desc: "Compiles and runs a test job, printing the result to stdout",
|
|
442
|
-
handler: ensure("test", options3),
|
|
443
|
-
builder: (yargs2) => build(options3, yargs2).example("test", "Run the test script")
|
|
444
|
-
};
|
|
445
|
-
|
|
446
|
-
// src/docgen/command.ts
|
|
447
|
-
var docgenCommand = {
|
|
448
|
-
command: "docgen <specifier>",
|
|
449
|
-
desc: false,
|
|
450
|
-
handler: (argv) => {
|
|
451
|
-
argv.command = "docgen";
|
|
452
|
-
},
|
|
453
|
-
builder: (yargs2) => {
|
|
454
|
-
return yargs2.example("docgen @openfn/language-common@1.7.5", "");
|
|
455
|
-
}
|
|
456
|
-
};
|
|
457
|
-
var command_default4 = docgenCommand;
|
|
458
|
-
|
|
459
|
-
// src/docs/command.ts
|
|
460
|
-
var command_default5 = {
|
|
461
|
-
command: "docs <adaptor> [operation]",
|
|
462
|
-
desc: "Print help for an adaptor function. You can use short-hand for adaptor names (ie, common instead of @openfn/language-common)",
|
|
463
|
-
handler: (argv) => {
|
|
464
|
-
argv.command = "docs";
|
|
465
|
-
},
|
|
466
|
-
builder: (yargs2) => yargs2.example("docs common fn", "Print help for the common fn operation")
|
|
467
|
-
};
|
|
449
|
+
var command_default5 = executeCommand;
|
|
468
450
|
|
|
469
451
|
// src/metadata/command.ts
|
|
470
452
|
var options4 = [
|
|
@@ -487,9 +469,73 @@ var command_default6 = {
|
|
|
487
469
|
)
|
|
488
470
|
};
|
|
489
471
|
|
|
472
|
+
// src/repo/command.ts
|
|
473
|
+
var repo = {
|
|
474
|
+
command: "repo [subcommand]",
|
|
475
|
+
desc: "Run commands on the module repo (install|clean)",
|
|
476
|
+
builder: (yargs2) => yargs2.command(clean).command(install).command(list).example("repo install -a http", "Install @openfn/language-http").example("repo clean", "Remove everything from the repo working dir")
|
|
477
|
+
};
|
|
478
|
+
var installOptions = [
|
|
479
|
+
repoDir,
|
|
480
|
+
override(expandAdaptors, {
|
|
481
|
+
default: true,
|
|
482
|
+
hidden: true
|
|
483
|
+
}),
|
|
484
|
+
override(adaptors, {
|
|
485
|
+
description: "Specify which language-adaptor to install (allows short-form names to be used, eg, http)"
|
|
486
|
+
})
|
|
487
|
+
];
|
|
488
|
+
var install = {
|
|
489
|
+
command: "install [packages...]",
|
|
490
|
+
desc: "install one or more packages to the runtime repo. Use -a to pass shorthand adaptor names.",
|
|
491
|
+
handler: ensure("repo-install", installOptions),
|
|
492
|
+
builder: (yargs2) => build(installOptions, yargs2).example("install axios", "Install the axios npm package to the repo").example(
|
|
493
|
+
"install -a http",
|
|
494
|
+
"Install @openfn/language-http adaptor to the repo"
|
|
495
|
+
).example(
|
|
496
|
+
"install @openfn/language-http",
|
|
497
|
+
"Install the language-http adaptor to the repo"
|
|
498
|
+
)
|
|
499
|
+
};
|
|
500
|
+
var clean = {
|
|
501
|
+
command: "clean",
|
|
502
|
+
desc: "Removes all modules from the runtime module repo",
|
|
503
|
+
handler: ensure("repo-clean", [repoDir]),
|
|
504
|
+
builder: (yargs2) => build(
|
|
505
|
+
[
|
|
506
|
+
repoDir,
|
|
507
|
+
{
|
|
508
|
+
name: "force",
|
|
509
|
+
yargs: {
|
|
510
|
+
alias: ["f"],
|
|
511
|
+
description: "Skip the prompt and force deletion",
|
|
512
|
+
boolean: true
|
|
513
|
+
}
|
|
514
|
+
}
|
|
515
|
+
],
|
|
516
|
+
yargs2
|
|
517
|
+
)
|
|
518
|
+
};
|
|
519
|
+
var list = {
|
|
520
|
+
command: "list",
|
|
521
|
+
desc: "Show a report on what is installed in the repo",
|
|
522
|
+
aliases: ["$0"],
|
|
523
|
+
handler: ensure("repo-list", [repoDir]),
|
|
524
|
+
builder: (yargs2) => build([repoDir], yargs2)
|
|
525
|
+
};
|
|
526
|
+
|
|
527
|
+
// src/test/command.ts
|
|
528
|
+
var options5 = [stateStdin];
|
|
529
|
+
var command_default7 = {
|
|
530
|
+
command: "test",
|
|
531
|
+
desc: "Compiles and runs a test job, printing the result to stdout",
|
|
532
|
+
handler: ensure("test", options5),
|
|
533
|
+
builder: (yargs2) => build(options5, yargs2).example("test", "Run the test script")
|
|
534
|
+
};
|
|
535
|
+
|
|
490
536
|
// src/cli.ts
|
|
491
537
|
var y = yargs(hideBin(process.argv));
|
|
492
|
-
var cmd = y.command(command_default).command(command_default2).command(install).command(repo).command(
|
|
538
|
+
var cmd = y.command(command_default5).command(command_default).command(command_default2).command(install).command(repo).command(command_default7).command(command_default4).command(command_default6).command(command_default3).option("log", {
|
|
493
539
|
alias: ["l"],
|
|
494
540
|
description: "Set the default log level to none, default, info or debug",
|
|
495
541
|
array: true
|
package/dist/process/runner.js
CHANGED
|
@@ -511,6 +511,59 @@ Paths inside the workflow are relative to the workflow.json`
|
|
|
511
511
|
}
|
|
512
512
|
};
|
|
513
513
|
|
|
514
|
+
// src/util/map-adaptors-to-monorepo.ts
|
|
515
|
+
import { readFile } from "node:fs/promises";
|
|
516
|
+
import path2 from "node:path";
|
|
517
|
+
import assert from "node:assert";
|
|
518
|
+
import { getNameAndVersion as getNameAndVersion2 } from "@openfn/runtime";
|
|
519
|
+
var validateMonoRepo = async (repoPath, log) => {
|
|
520
|
+
try {
|
|
521
|
+
const raw = await readFile(`${repoPath}/package.json`, "utf8");
|
|
522
|
+
const pkg = JSON.parse(raw);
|
|
523
|
+
assert(pkg.name === "adaptors");
|
|
524
|
+
} catch (e) {
|
|
525
|
+
log.error(`ERROR: Adaptors Monorepo not found at ${repoPath}`);
|
|
526
|
+
process.exit(9);
|
|
527
|
+
}
|
|
528
|
+
};
|
|
529
|
+
var updatePath = (adaptor, repoPath, log) => {
|
|
530
|
+
if (adaptor.match("=")) {
|
|
531
|
+
return adaptor;
|
|
532
|
+
}
|
|
533
|
+
const { name, version } = getNameAndVersion2(adaptor);
|
|
534
|
+
if (version) {
|
|
535
|
+
log.warn(
|
|
536
|
+
`Warning: Ignoring version specifier on ${adaptor} as loading from the adaptors monorepo`
|
|
537
|
+
);
|
|
538
|
+
}
|
|
539
|
+
const shortName = name.replace("@openfn/language-", "");
|
|
540
|
+
const abspath = path2.resolve(repoPath, "packages", shortName);
|
|
541
|
+
return `${name}=${abspath}`;
|
|
542
|
+
};
|
|
543
|
+
var mapAdaptorsToMonorepo = async (options, log) => {
|
|
544
|
+
const { adaptors, monorepoPath, workflow } = options;
|
|
545
|
+
if (monorepoPath) {
|
|
546
|
+
await validateMonoRepo(monorepoPath, log);
|
|
547
|
+
log.success(`Loading adaptors from monorepo at ${monorepoPath}`);
|
|
548
|
+
if (adaptors) {
|
|
549
|
+
options.adaptors = adaptors.map((a) => {
|
|
550
|
+
const p = updatePath(a, monorepoPath, log);
|
|
551
|
+
log.info(`Mapped adaptor ${a} to monorepo: ${p.split("=")[1]}`);
|
|
552
|
+
return p;
|
|
553
|
+
});
|
|
554
|
+
}
|
|
555
|
+
if (workflow) {
|
|
556
|
+
Object.values(workflow.jobs).forEach((job) => {
|
|
557
|
+
if (job.adaptor) {
|
|
558
|
+
job.adaptor = updatePath(job.adaptor, monorepoPath, log);
|
|
559
|
+
}
|
|
560
|
+
});
|
|
561
|
+
}
|
|
562
|
+
}
|
|
563
|
+
return options;
|
|
564
|
+
};
|
|
565
|
+
var map_adaptors_to_monorepo_default = mapAdaptorsToMonorepo;
|
|
566
|
+
|
|
514
567
|
// src/execute/handler.ts
|
|
515
568
|
var executeHandler = async (options, logger) => {
|
|
516
569
|
const start = new Date().getTime();
|
|
@@ -518,6 +571,10 @@ var executeHandler = async (options, logger) => {
|
|
|
518
571
|
let input = await load_input_default(options, logger);
|
|
519
572
|
if (options.workflow) {
|
|
520
573
|
expand_adaptors_default(options);
|
|
574
|
+
await map_adaptors_to_monorepo_default(
|
|
575
|
+
options,
|
|
576
|
+
logger
|
|
577
|
+
);
|
|
521
578
|
}
|
|
522
579
|
const { repoDir, monorepoPath, autoinstall } = options;
|
|
523
580
|
if (autoinstall) {
|
|
@@ -564,6 +621,13 @@ var handler_default = executeHandler;
|
|
|
564
621
|
import { writeFile as writeFile2 } from "node:fs/promises";
|
|
565
622
|
var compileHandler = async (options, logger) => {
|
|
566
623
|
await load_input_default(options, logger);
|
|
624
|
+
if (options.workflow) {
|
|
625
|
+
expand_adaptors_default(options);
|
|
626
|
+
await map_adaptors_to_monorepo_default(
|
|
627
|
+
options,
|
|
628
|
+
logger
|
|
629
|
+
);
|
|
630
|
+
}
|
|
567
631
|
let result = await compile_default(options, logger);
|
|
568
632
|
if (options.workflow) {
|
|
569
633
|
result = JSON.stringify(result);
|
|
@@ -588,7 +652,7 @@ var testHandler = async (options, logger) => {
|
|
|
588
652
|
jobs: [
|
|
589
653
|
{
|
|
590
654
|
id: "start",
|
|
591
|
-
data: { defaultAnswer: 42 },
|
|
655
|
+
state: { data: { defaultAnswer: 42 } },
|
|
592
656
|
expression: "const fn = () => (state) => { console.log('Starting computer...'); return state; }; fn()",
|
|
593
657
|
next: {
|
|
594
658
|
calculate: "!state.error"
|
|
@@ -620,29 +684,82 @@ var testHandler = async (options, logger) => {
|
|
|
620
684
|
const silentLogger = createNullLogger();
|
|
621
685
|
const state = await load_state_default(options, silentLogger);
|
|
622
686
|
const code = await compile_default(options, logger);
|
|
623
|
-
const result = await execute_default(code, state, options);
|
|
687
|
+
const result = await execute_default(code, state, options, silentLogger);
|
|
624
688
|
logger.success(`Result: ${result.data.answer}`);
|
|
625
689
|
return result;
|
|
626
690
|
};
|
|
627
691
|
var handler_default3 = testHandler;
|
|
628
692
|
|
|
693
|
+
// src/deploy/handler.ts
|
|
694
|
+
import {
|
|
695
|
+
DeployError,
|
|
696
|
+
deploy,
|
|
697
|
+
getConfig,
|
|
698
|
+
validateConfig
|
|
699
|
+
} from "@openfn/deploy";
|
|
700
|
+
var actualDeploy = deploy;
|
|
701
|
+
async function deployHandler(options, logger, deployFn = actualDeploy) {
|
|
702
|
+
try {
|
|
703
|
+
const config = mergeOverrides(await getConfig(options.configPath), options);
|
|
704
|
+
logger.debug("Deploying with config", JSON.stringify(config, null, 2));
|
|
705
|
+
if (options.confirm === false) {
|
|
706
|
+
config.requireConfirmation = options.confirm;
|
|
707
|
+
}
|
|
708
|
+
if (process.env["OPENFN_API_KEY"]) {
|
|
709
|
+
logger.info("Using OPENFN_API_KEY environment variable");
|
|
710
|
+
config.apiKey = process.env["OPENFN_API_KEY"];
|
|
711
|
+
}
|
|
712
|
+
if (process.env["OPENFN_ENDPOINT"]) {
|
|
713
|
+
logger.info("Using OPENFN_ENDPOINT environment variable");
|
|
714
|
+
config.endpoint = process.env["OPENFN_ENDPOINT"];
|
|
715
|
+
}
|
|
716
|
+
logger.debug("Deploying with config", config);
|
|
717
|
+
logger.info(`Deploying`);
|
|
718
|
+
validateConfig(config);
|
|
719
|
+
const isOk = await deployFn(config, logger);
|
|
720
|
+
process.exitCode = isOk ? 0 : 1;
|
|
721
|
+
return isOk;
|
|
722
|
+
} catch (error) {
|
|
723
|
+
if (error instanceof DeployError) {
|
|
724
|
+
logger.error(error.message);
|
|
725
|
+
process.exitCode = 10;
|
|
726
|
+
return false;
|
|
727
|
+
}
|
|
728
|
+
throw error;
|
|
729
|
+
}
|
|
730
|
+
}
|
|
731
|
+
function mergeOverrides(config, options) {
|
|
732
|
+
return {
|
|
733
|
+
...config,
|
|
734
|
+
apiKey: pickFirst(process.env["OPENFN_API_KEY"], config.apiKey),
|
|
735
|
+
endpoint: pickFirst(process.env["OPENFN_ENDPOINT"], config.endpoint),
|
|
736
|
+
statePath: pickFirst(options.statePath, config.statePath),
|
|
737
|
+
configPath: options.configPath,
|
|
738
|
+
requireConfirmation: pickFirst(options.confirm, config.requireConfirmation)
|
|
739
|
+
};
|
|
740
|
+
}
|
|
741
|
+
function pickFirst(...args) {
|
|
742
|
+
return args.find((arg) => arg !== void 0 && arg !== null);
|
|
743
|
+
}
|
|
744
|
+
var handler_default4 = deployHandler;
|
|
745
|
+
|
|
629
746
|
// src/docgen/handler.ts
|
|
630
747
|
import { writeFile as writeFile3 } from "node:fs/promises";
|
|
631
748
|
import { readFileSync, writeFileSync, mkdirSync, rmSync } from "node:fs";
|
|
632
|
-
import
|
|
749
|
+
import path3 from "node:path";
|
|
633
750
|
import { describePackage } from "@openfn/describe-package";
|
|
634
|
-
import { getNameAndVersion as
|
|
751
|
+
import { getNameAndVersion as getNameAndVersion3 } from "@openfn/runtime";
|
|
635
752
|
var RETRY_DURATION = 500;
|
|
636
753
|
var RETRY_COUNT = 20;
|
|
637
754
|
var TIMEOUT_MS = 1e3 * 60;
|
|
638
755
|
var actualDocGen = (specifier) => describePackage(specifier, {});
|
|
639
|
-
var ensurePath = (filePath) => mkdirSync(
|
|
756
|
+
var ensurePath = (filePath) => mkdirSync(path3.dirname(filePath), { recursive: true });
|
|
640
757
|
var generatePlaceholder = (path7) => {
|
|
641
758
|
writeFileSync(path7, `{ "loading": true, "timestamp": ${Date.now()}}`);
|
|
642
759
|
};
|
|
643
760
|
var finish = (logger, resultPath) => {
|
|
644
761
|
logger.success("Done! Docs can be found at:\n");
|
|
645
|
-
logger.print(` ${
|
|
762
|
+
logger.print(` ${path3.resolve(resultPath)}`);
|
|
646
763
|
};
|
|
647
764
|
var generateDocs = async (specifier, path7, docgen, logger) => {
|
|
648
765
|
const result = await docgen(specifier);
|
|
@@ -683,7 +800,7 @@ var waitForDocs = async (docs, path7, logger, retryDuration = RETRY_DURATION) =>
|
|
|
683
800
|
};
|
|
684
801
|
var docgenHandler = (options, logger, docgen = actualDocGen, retryDuration = RETRY_DURATION) => {
|
|
685
802
|
const { specifier, repoDir } = options;
|
|
686
|
-
const { version } =
|
|
803
|
+
const { version } = getNameAndVersion3(specifier);
|
|
687
804
|
if (!version) {
|
|
688
805
|
logger.error("Error: No version number detected");
|
|
689
806
|
logger.error("eg, @openfn/language-common@1.7.5");
|
|
@@ -719,11 +836,11 @@ var docgenHandler = (options, logger, docgen = actualDocGen, retryDuration = RET
|
|
|
719
836
|
});
|
|
720
837
|
}
|
|
721
838
|
};
|
|
722
|
-
var
|
|
839
|
+
var handler_default5 = docgenHandler;
|
|
723
840
|
|
|
724
841
|
// src/docs/handler.ts
|
|
725
|
-
import { readFile } from "node:fs/promises";
|
|
726
|
-
import { getNameAndVersion as
|
|
842
|
+
import { readFile as readFile2 } from "node:fs/promises";
|
|
843
|
+
import { getNameAndVersion as getNameAndVersion4, getLatestVersion } from "@openfn/runtime";
|
|
727
844
|
var describeFn = (adaptorName, fn) => `## ${fn.name}(${fn.parameters.map(({ name }) => name).join(",")})
|
|
728
845
|
|
|
729
846
|
${fn.description}
|
|
@@ -753,7 +870,7 @@ var docsHandler = async (options, logger) => {
|
|
|
753
870
|
const { adaptor, operation, repoDir } = options;
|
|
754
871
|
const { adaptors } = expand_adaptors_default({ adaptors: [adaptor] });
|
|
755
872
|
const [adaptorName] = adaptors;
|
|
756
|
-
let { name, version } =
|
|
873
|
+
let { name, version } = getNameAndVersion4(adaptorName);
|
|
757
874
|
if (!version) {
|
|
758
875
|
logger.info("No version number provided, looking for latest...");
|
|
759
876
|
version = await getLatestVersion(name);
|
|
@@ -761,7 +878,7 @@ var docsHandler = async (options, logger) => {
|
|
|
761
878
|
logger.success(`Showing docs for ${adaptorName} v${version}`);
|
|
762
879
|
}
|
|
763
880
|
logger.info("Generating/loading documentation...");
|
|
764
|
-
const path7 = await
|
|
881
|
+
const path7 = await handler_default5(
|
|
765
882
|
{
|
|
766
883
|
specifier: `${name}@${version}`,
|
|
767
884
|
repoDir
|
|
@@ -770,7 +887,7 @@ var docsHandler = async (options, logger) => {
|
|
|
770
887
|
);
|
|
771
888
|
let didError = false;
|
|
772
889
|
if (path7) {
|
|
773
|
-
const source = await
|
|
890
|
+
const source = await readFile2(path7, "utf8");
|
|
774
891
|
const data = JSON.parse(source);
|
|
775
892
|
let desc;
|
|
776
893
|
if (operation) {
|
|
@@ -797,12 +914,12 @@ var docsHandler = async (options, logger) => {
|
|
|
797
914
|
logger.error("Not found");
|
|
798
915
|
}
|
|
799
916
|
};
|
|
800
|
-
var
|
|
917
|
+
var handler_default6 = docsHandler;
|
|
801
918
|
|
|
802
919
|
// src/metadata/cache.ts
|
|
803
920
|
import { createHash } from "node:crypto";
|
|
804
921
|
import { readFileSync as readFileSync2 } from "node:fs";
|
|
805
|
-
import
|
|
922
|
+
import path4 from "node:path";
|
|
806
923
|
import { writeFile as writeFile4, mkdir } from "node:fs/promises";
|
|
807
924
|
var getPath = (repoDir, key) => `${repoDir}/meta/${key}.json`;
|
|
808
925
|
var sortKeys = (obj) => {
|
|
@@ -833,7 +950,7 @@ var get = (repoPath, key) => {
|
|
|
833
950
|
};
|
|
834
951
|
var set = async (repoPath, key, data) => {
|
|
835
952
|
const fullPath = getPath(repoPath, key);
|
|
836
|
-
await mkdir(
|
|
953
|
+
await mkdir(path4.dirname(fullPath), { recursive: true });
|
|
837
954
|
await writeFile4(fullPath, JSON.stringify(data));
|
|
838
955
|
};
|
|
839
956
|
var cache_default = { get, set, generateKey, getPath, sortKeys };
|
|
@@ -914,10 +1031,10 @@ var metadataHandler = async (options, logger) => {
|
|
|
914
1031
|
process.exit(1);
|
|
915
1032
|
}
|
|
916
1033
|
};
|
|
917
|
-
var
|
|
1034
|
+
var handler_default7 = metadataHandler;
|
|
918
1035
|
|
|
919
1036
|
// src/util/ensure-opts.ts
|
|
920
|
-
import
|
|
1037
|
+
import path5 from "node:path";
|
|
921
1038
|
var defaultLoggerOptions = {
|
|
922
1039
|
default: "default",
|
|
923
1040
|
job: "debug"
|
|
@@ -995,7 +1112,7 @@ function ensureOpts(basePath = ".", opts) {
|
|
|
995
1112
|
}
|
|
996
1113
|
let baseDir = basePath;
|
|
997
1114
|
if (basePath.endsWith(".js")) {
|
|
998
|
-
baseDir =
|
|
1115
|
+
baseDir = path5.dirname(basePath);
|
|
999
1116
|
set2("jobPath", basePath);
|
|
1000
1117
|
} else {
|
|
1001
1118
|
set2("jobPath", `${baseDir}/job.js`);
|
|
@@ -1011,47 +1128,6 @@ function ensureOpts(basePath = ".", opts) {
|
|
|
1011
1128
|
return newOpts;
|
|
1012
1129
|
}
|
|
1013
1130
|
|
|
1014
|
-
// src/util/use-adaptors-repo.ts
|
|
1015
|
-
import { readFile as readFile2 } from "node:fs/promises";
|
|
1016
|
-
import path5 from "node:path";
|
|
1017
|
-
import assert from "node:assert";
|
|
1018
|
-
import { getNameAndVersion as getNameAndVersion5 } from "@openfn/runtime";
|
|
1019
|
-
var validateMonoRepo = async (repoPath, log) => {
|
|
1020
|
-
try {
|
|
1021
|
-
const raw = await readFile2(`${repoPath}/package.json`, "utf8");
|
|
1022
|
-
const pkg = JSON.parse(raw);
|
|
1023
|
-
assert(pkg.name === "adaptors");
|
|
1024
|
-
} catch (e) {
|
|
1025
|
-
log.error(`ERROR: Adaptors Monorepo not found at ${repoPath}`);
|
|
1026
|
-
process.exit(9);
|
|
1027
|
-
}
|
|
1028
|
-
};
|
|
1029
|
-
var updatePath = (adaptor, repoPath, log) => {
|
|
1030
|
-
if (adaptor.match("=")) {
|
|
1031
|
-
return adaptor;
|
|
1032
|
-
}
|
|
1033
|
-
const { name, version } = getNameAndVersion5(adaptor);
|
|
1034
|
-
if (version) {
|
|
1035
|
-
log.warn(
|
|
1036
|
-
`Warning: Ignoring version specifier on ${adaptor} as loading from the adaptors monorepo`
|
|
1037
|
-
);
|
|
1038
|
-
}
|
|
1039
|
-
const shortName = name.replace("@openfn/language-", "");
|
|
1040
|
-
const abspath = path5.resolve(repoPath, "packages", shortName);
|
|
1041
|
-
return `${name}=${abspath}`;
|
|
1042
|
-
};
|
|
1043
|
-
var useAdaptorsRepo = async (adaptors, repoPath, log) => {
|
|
1044
|
-
await validateMonoRepo(repoPath, log);
|
|
1045
|
-
log.success(`Loading adaptors from monorepo at ${repoPath}`);
|
|
1046
|
-
const updatedAdaptors = adaptors.map((a) => {
|
|
1047
|
-
const p = updatePath(a, repoPath, log);
|
|
1048
|
-
log.info(`Mapped adaptor ${a} to monorepo: ${p.split("=")[1]}`);
|
|
1049
|
-
return p;
|
|
1050
|
-
});
|
|
1051
|
-
return updatedAdaptors;
|
|
1052
|
-
};
|
|
1053
|
-
var use_adaptors_repo_default = useAdaptorsRepo;
|
|
1054
|
-
|
|
1055
1131
|
// src/util/print-versions.ts
|
|
1056
1132
|
import { readFileSync as readFileSync3 } from "node:fs";
|
|
1057
1133
|
import path6 from "node:path";
|
|
@@ -1132,16 +1208,17 @@ var handlers = {
|
|
|
1132
1208
|
execute: handler_default,
|
|
1133
1209
|
compile: handler_default2,
|
|
1134
1210
|
test: handler_default3,
|
|
1135
|
-
|
|
1136
|
-
|
|
1137
|
-
|
|
1211
|
+
deploy: handler_default4,
|
|
1212
|
+
docgen: handler_default5,
|
|
1213
|
+
docs: handler_default6,
|
|
1214
|
+
metadata: handler_default7,
|
|
1138
1215
|
["repo-clean"]: clean,
|
|
1139
1216
|
["repo-install"]: install,
|
|
1140
1217
|
["repo-pwd"]: pwd,
|
|
1141
1218
|
["repo-list"]: list,
|
|
1142
1219
|
version: async (opts, logger) => print_versions_default(logger, opts)
|
|
1143
1220
|
};
|
|
1144
|
-
var maybeEnsureOpts = (basePath, options) => /(^(execute|compile|test)$)|(repo-)/.test(options.command) ? ensureLogOpts(options) : ensureOpts(basePath, options);
|
|
1221
|
+
var maybeEnsureOpts = (basePath, options) => /(^(deploy|execute|compile|test)$)|(repo-)/.test(options.command) ? ensureLogOpts(options) : ensureOpts(basePath, options);
|
|
1145
1222
|
var parse = async (basePath, options, log) => {
|
|
1146
1223
|
const opts = maybeEnsureOpts(basePath, options);
|
|
1147
1224
|
const logger = log || logger_default(CLI, opts);
|
|
@@ -1156,15 +1233,11 @@ var parse = async (basePath, options, log) => {
|
|
|
1156
1233
|
logger.error("Set OPENFN_ADAPTORS_REPO to a path pointing to the repo");
|
|
1157
1234
|
process.exit(9);
|
|
1158
1235
|
}
|
|
1159
|
-
|
|
1160
|
-
opts.adaptors,
|
|
1161
|
-
opts.monorepoPath,
|
|
1162
|
-
logger
|
|
1163
|
-
);
|
|
1236
|
+
await map_adaptors_to_monorepo_default(opts, logger);
|
|
1164
1237
|
} else if (opts.adaptors && opts.expandAdaptors) {
|
|
1165
1238
|
expand_adaptors_default(opts);
|
|
1166
1239
|
}
|
|
1167
|
-
if (!/^(test|version)$/.test(opts.command) && !opts.repoDir) {
|
|
1240
|
+
if (!/^(deploy|test|version)$/.test(opts.command) && !opts.repoDir) {
|
|
1168
1241
|
logger.warn(
|
|
1169
1242
|
"WARNING: no repo module dir found! Using the default (/tmp/repo)"
|
|
1170
1243
|
);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@openfn/cli",
|
|
3
|
-
"version": "0.0
|
|
3
|
+
"version": "0.1.0",
|
|
4
4
|
"description": "CLI devtools for the openfn toolchain.",
|
|
5
5
|
"engines": {
|
|
6
6
|
"node": ">=18",
|
|
@@ -36,14 +36,15 @@
|
|
|
36
36
|
"typescript": "^4.7.4"
|
|
37
37
|
},
|
|
38
38
|
"dependencies": {
|
|
39
|
-
"@openfn/compiler": "0.0.32",
|
|
40
|
-
"@openfn/describe-package": "0.0.16",
|
|
41
|
-
"@openfn/logger": "0.0.13",
|
|
42
|
-
"@openfn/runtime": "0.0.25",
|
|
43
39
|
"figures": "^5.0.0",
|
|
44
40
|
"rimraf": "^3.0.2",
|
|
45
41
|
"treeify": "^1.1.0",
|
|
46
|
-
"yargs": "^17.5.1"
|
|
42
|
+
"yargs": "^17.5.1",
|
|
43
|
+
"@openfn/deploy": "0.1.0",
|
|
44
|
+
"@openfn/runtime": "0.0.26",
|
|
45
|
+
"@openfn/logger": "0.0.13",
|
|
46
|
+
"@openfn/describe-package": "0.0.16",
|
|
47
|
+
"@openfn/compiler": "0.0.32"
|
|
47
48
|
},
|
|
48
49
|
"files": [
|
|
49
50
|
"dist",
|