@factorialco/fcode-cli 1.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 +1021 -0
- package/bin/dev +17 -0
- package/bin/dev.cmd +3 -0
- package/bin/run +7 -0
- package/bin/run.cmd +3 -0
- package/dist/commands/add.d.ts +6 -0
- package/dist/commands/add.js +22 -0
- package/dist/commands/clone.d.ts +26 -0
- package/dist/commands/clone.js +177 -0
- package/dist/commands/dependencies/add.d.ts +9 -0
- package/dist/commands/dependencies/add.js +13 -0
- package/dist/commands/dependencies/install.d.ts +14 -0
- package/dist/commands/dependencies/install.js +44 -0
- package/dist/commands/dependencies/pull.d.ts +12 -0
- package/dist/commands/dependencies/pull.js +14 -0
- package/dist/commands/dependencies/push.d.ts +12 -0
- package/dist/commands/dependencies/push.js +14 -0
- package/dist/commands/dependencies/reset.d.ts +9 -0
- package/dist/commands/dependencies/reset.js +13 -0
- package/dist/commands/dependencies/status.d.ts +9 -0
- package/dist/commands/dependencies/status.js +13 -0
- package/dist/commands/http.d.ts +22 -0
- package/dist/commands/http.js +272 -0
- package/dist/commands/login.d.ts +18 -0
- package/dist/commands/login.js +62 -0
- package/dist/commands/logout.d.ts +10 -0
- package/dist/commands/logout.js +34 -0
- package/dist/commands/modules/add.d.ts +9 -0
- package/dist/commands/modules/add.js +13 -0
- package/dist/commands/modules/pull.d.ts +13 -0
- package/dist/commands/modules/pull.js +43 -0
- package/dist/commands/modules/push.d.ts +13 -0
- package/dist/commands/modules/push.js +35 -0
- package/dist/commands/modules/remove.d.ts +9 -0
- package/dist/commands/modules/remove.js +19 -0
- package/dist/commands/modules/reset.d.ts +9 -0
- package/dist/commands/modules/reset.js +13 -0
- package/dist/commands/modules/status.d.ts +11 -0
- package/dist/commands/modules/status.js +40 -0
- package/dist/commands/pre-debug.d.ts +20 -0
- package/dist/commands/pre-debug.js +120 -0
- package/dist/commands/process-metadata.d.ts +18 -0
- package/dist/commands/process-metadata.js +63 -0
- package/dist/commands/processes/add.d.ts +9 -0
- package/dist/commands/processes/add.js +13 -0
- package/dist/commands/processes/install-dependencies.d.ts +14 -0
- package/dist/commands/processes/install-dependencies.js +30 -0
- package/dist/commands/processes/pull.d.ts +13 -0
- package/dist/commands/processes/pull.js +47 -0
- package/dist/commands/processes/push.d.ts +13 -0
- package/dist/commands/processes/push.js +39 -0
- package/dist/commands/processes/remove.d.ts +9 -0
- package/dist/commands/processes/remove.js +19 -0
- package/dist/commands/processes/reset.d.ts +9 -0
- package/dist/commands/processes/reset.js +13 -0
- package/dist/commands/processes/status.d.ts +11 -0
- package/dist/commands/processes/status.js +58 -0
- package/dist/commands/pull.d.ts +9 -0
- package/dist/commands/pull.js +32 -0
- package/dist/commands/push.d.ts +9 -0
- package/dist/commands/push.js +29 -0
- package/dist/commands/remote/add.d.ts +10 -0
- package/dist/commands/remote/add.js +32 -0
- package/dist/commands/remote/list.d.ts +7 -0
- package/dist/commands/remote/list.js +33 -0
- package/dist/commands/remote/set.d.ts +10 -0
- package/dist/commands/remote/set.js +28 -0
- package/dist/commands/reset.d.ts +6 -0
- package/dist/commands/reset.js +19 -0
- package/dist/commands/run.d.ts +16 -0
- package/dist/commands/run.js +56 -0
- package/dist/commands/runtime-env.d.ts +12 -0
- package/dist/commands/runtime-env.js +42 -0
- package/dist/commands/settings/get.d.ts +12 -0
- package/dist/commands/settings/get.js +67 -0
- package/dist/commands/settings/remove.d.ts +9 -0
- package/dist/commands/settings/remove.js +35 -0
- package/dist/commands/settings/set.d.ts +10 -0
- package/dist/commands/settings/set.js +39 -0
- package/dist/commands/setup-debug.d.ts +12 -0
- package/dist/commands/setup-debug.js +118 -0
- package/dist/commands/status.d.ts +6 -0
- package/dist/commands/status.js +22 -0
- package/dist/commands/team/pull.d.ts +8 -0
- package/dist/commands/team/pull.js +23 -0
- package/dist/commands/team/push.d.ts +11 -0
- package/dist/commands/team/push.js +41 -0
- package/dist/commands/team/status.d.ts +8 -0
- package/dist/commands/team/status.js +40 -0
- package/dist/commands/test/scaffold.d.ts +9 -0
- package/dist/commands/test/scaffold.js +61 -0
- package/dist/commands/test.d.ts +13 -0
- package/dist/commands/test.js +72 -0
- package/dist/commands/variables/add.d.ts +12 -0
- package/dist/commands/variables/add.js +21 -0
- package/dist/commands/variables/pull.d.ts +12 -0
- package/dist/commands/variables/pull.js +14 -0
- package/dist/commands/variables/push.d.ts +12 -0
- package/dist/commands/variables/push.js +14 -0
- package/dist/commands/variables/remove.d.ts +9 -0
- package/dist/commands/variables/remove.js +19 -0
- package/dist/commands/variables/reset.d.ts +9 -0
- package/dist/commands/variables/reset.js +13 -0
- package/dist/commands/variables/status.d.ts +12 -0
- package/dist/commands/variables/status.js +58 -0
- package/dist/config/global.d.ts +15 -0
- package/dist/config/global.js +77 -0
- package/dist/config/index.d.ts +14 -0
- package/dist/config/index.js +44 -0
- package/dist/config/remote.d.ts +15 -0
- package/dist/config/remote.js +60 -0
- package/dist/config/settings.d.ts +16 -0
- package/dist/config/settings.js +54 -0
- package/dist/config/workspace.d.ts +28 -0
- package/dist/config/workspace.js +158 -0
- package/dist/core/commands/api-client-command.d.ts +6 -0
- package/dist/core/commands/api-client-command.js +30 -0
- package/dist/core/commands/base-command.d.ts +11 -0
- package/dist/core/commands/base-command.js +61 -0
- package/dist/core/commands/dependency-command.d.ts +5 -0
- package/dist/core/commands/dependency-command.js +16 -0
- package/dist/core/commands/modules-command.d.ts +7 -0
- package/dist/core/commands/modules-command.js +18 -0
- package/dist/core/commands/processes-command.d.ts +8 -0
- package/dist/core/commands/processes-command.js +27 -0
- package/dist/core/commands/resource-command.d.ts +24 -0
- package/dist/core/commands/resource-command.js +92 -0
- package/dist/core/commands/variables-command.d.ts +5 -0
- package/dist/core/commands/variables-command.js +16 -0
- package/dist/core/dependencies/env-dependencies-command.d.ts +19 -0
- package/dist/core/dependencies/env-dependencies-command.js +70 -0
- package/dist/core/dependencies/env-process-dependencies-command.d.ts +15 -0
- package/dist/core/dependencies/env-process-dependencies-command.js +78 -0
- package/dist/core/dependencies/javascript-env-dependencies.d.ts +8 -0
- package/dist/core/dependencies/javascript-env-dependencies.js +77 -0
- package/dist/core/dependencies/python-env-dependencies.d.ts +9 -0
- package/dist/core/dependencies/python-env-dependencies.js +91 -0
- package/dist/core/errors.d.ts +55 -0
- package/dist/core/errors.js +144 -0
- package/dist/core/executors/execution-task.d.ts +29 -0
- package/dist/core/executors/execution-task.js +139 -0
- package/dist/core/executors/javascript-execution-task.d.ts +13 -0
- package/dist/core/executors/javascript-execution-task.js +618 -0
- package/dist/core/executors/python/context.d.ts +2 -0
- package/dist/core/executors/python/context.js +3 -0
- package/dist/core/executors/python/datastore.d.ts +2 -0
- package/dist/core/executors/python/datastore.js +4 -0
- package/dist/core/executors/python-execution-task.d.ts +11 -0
- package/dist/core/executors/python-execution-task.js +173 -0
- package/dist/core/executors/source-code-sanitizer.d.ts +4 -0
- package/dist/core/executors/source-code-sanitizer.js +45 -0
- package/dist/core/resource-merger.d.ts +14 -0
- package/dist/core/resource-merger.js +155 -0
- package/dist/core/resource-pusher.d.ts +12 -0
- package/dist/core/resource-pusher.js +133 -0
- package/dist/core/resource-repository.d.ts +8 -0
- package/dist/core/resource-repository.js +2 -0
- package/dist/core/types.d.ts +290 -0
- package/dist/core/types.js +238 -0
- package/dist/core/utils/dependencies.d.ts +5 -0
- package/dist/core/utils/dependencies.js +82 -0
- package/dist/core/utils/variables.d.ts +4 -0
- package/dist/core/utils/variables.js +10 -0
- package/dist/hooks/init/auth.d.ts +3 -0
- package/dist/hooks/init/auth.js +28 -0
- package/dist/hooks/init/update.d.ts +3 -0
- package/dist/hooks/init/update.js +42 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +4 -0
- package/dist/repositories/process.d.ts +36 -0
- package/dist/repositories/process.js +339 -0
- package/dist/repositories/programming-language-manifest.d.ts +17 -0
- package/dist/repositories/programming-language-manifest.js +95 -0
- package/dist/repositories/resource.d.ts +29 -0
- package/dist/repositories/resource.js +79 -0
- package/dist/repositories/script-library.d.ts +28 -0
- package/dist/repositories/script-library.js +164 -0
- package/dist/repositories/team.d.ts +23 -0
- package/dist/repositories/team.js +74 -0
- package/dist/repositories/variable.d.ts +26 -0
- package/dist/repositories/variable.js +174 -0
- package/dist/runtime/executor.js +87 -0
- package/dist/runtime/executor.py +81 -0
- package/dist/runtime/libs/node/fcode/index.js +1 -0
- package/dist/runtime/libs/python/fcode/__init__.py +75 -0
- package/dist/runtime/libs/python/fcode/context.py +98 -0
- package/dist/runtime/libs/python/fcode/datastore.py +35 -0
- package/dist/runtime/libs/python/fcode/schedule.py +45 -0
- package/dist/runtime/libs/python/fcode/storage.py +271 -0
- package/dist/runtime/libs/python/fcode/variables.py +102 -0
- package/dist/services/auth-service.d.ts +12 -0
- package/dist/services/auth-service.js +114 -0
- package/dist/services/credential-prompter.d.ts +6 -0
- package/dist/services/credential-prompter.js +60 -0
- package/dist/services/fcode-graphql-client.d.ts +45 -0
- package/dist/services/fcode-graphql-client.js +721 -0
- package/dist/services/http-server.d.ts +3 -0
- package/dist/services/http-server.js +17 -0
- package/dist/services/oauth-browser-service.d.ts +9 -0
- package/dist/services/oauth-browser-service.js +164 -0
- package/dist/services/process-parameters-sampler.d.ts +2 -0
- package/dist/services/process-parameters-sampler.js +41 -0
- package/dist/services/process-runner.d.ts +22 -0
- package/dist/services/process-runner.js +97 -0
- package/dist/services/resource-checker.d.ts +8 -0
- package/dist/services/resource-checker.js +82 -0
- package/dist/services/test-runner.d.ts +17 -0
- package/dist/services/test-runner.js +228 -0
- package/dist/utils/canonical-hash.d.ts +9 -0
- package/dist/utils/canonical-hash.js +30 -0
- package/dist/utils/cli/index.d.ts +14 -0
- package/dist/utils/cli/index.js +50 -0
- package/dist/utils/cli/screen.d.ts +2 -0
- package/dist/utils/cli/screen.js +25 -0
- package/dist/utils/cli/styled/table.d.ts +23 -0
- package/dist/utils/cli/styled/table.js +272 -0
- package/dist/utils/colorize-resource.d.ts +1 -0
- package/dist/utils/colorize-resource.js +7 -0
- package/dist/utils/env-utils.d.ts +2 -0
- package/dist/utils/env-utils.js +16 -0
- package/dist/utils/file-utils.d.ts +11 -0
- package/dist/utils/file-utils.js +33 -0
- package/dist/utils/filenamify.d.ts +4 -0
- package/dist/utils/filenamify.js +73 -0
- package/dist/utils/gitignore.d.ts +17 -0
- package/dist/utils/gitignore.js +60 -0
- package/dist/utils/promise.d.ts +4 -0
- package/dist/utils/promise.js +38 -0
- package/dist/utils/url-utils.d.ts +2 -0
- package/dist/utils/url-utils.js +10 -0
- package/dist/utils/variable-warnings.d.ts +8 -0
- package/dist/utils/variable-warnings.js +38 -0
- package/oclif.manifest.json +1783 -0
- package/package.json +129 -0
|
@@ -0,0 +1,139 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const node_child_process_1 = require("node:child_process");
|
|
4
|
+
const fs = require("node:fs");
|
|
5
|
+
const os = require("node:os");
|
|
6
|
+
const path = require("node:path");
|
|
7
|
+
const errors_1 = require("../errors");
|
|
8
|
+
const cli_1 = require("../../utils/cli");
|
|
9
|
+
const dependencies_1 = require("../utils/dependencies");
|
|
10
|
+
const python_env_dependencies_1 = require("../dependencies/python-env-dependencies");
|
|
11
|
+
const javascript_env_dependencies_1 = require("../dependencies/javascript-env-dependencies");
|
|
12
|
+
const variables_1 = require("../utils/variables");
|
|
13
|
+
const env_process_dependencies_command_1 = require("../dependencies/env-process-dependencies-command");
|
|
14
|
+
const createTempDirectory = () => {
|
|
15
|
+
const runtimeDir = path.join(`${os.tmpdir()}${path.sep}fcode${path.sep}`);
|
|
16
|
+
fs.mkdirSync(runtimeDir, { recursive: true });
|
|
17
|
+
return fs.mkdtempSync(runtimeDir);
|
|
18
|
+
};
|
|
19
|
+
class ExecutionTask {
|
|
20
|
+
constructor(_programmingLanguage, process, options, tempDir) {
|
|
21
|
+
this.getVariablesObject = () => (0, variables_1.getVariablesObject)(this._options.variables);
|
|
22
|
+
this._programmingLanguage = _programmingLanguage;
|
|
23
|
+
this._process = process;
|
|
24
|
+
this._options = options;
|
|
25
|
+
this._tempDir = tempDir ?? createTempDirectory();
|
|
26
|
+
}
|
|
27
|
+
async getCliPath() {
|
|
28
|
+
return new Promise((resolve, reject) => {
|
|
29
|
+
(0, node_child_process_1.exec)('npm root -g', (error, rootPath) => {
|
|
30
|
+
if (error) {
|
|
31
|
+
reject(error);
|
|
32
|
+
}
|
|
33
|
+
resolve(path.join(rootPath.trim(), '@factorialco', 'fcode-cli'));
|
|
34
|
+
});
|
|
35
|
+
});
|
|
36
|
+
}
|
|
37
|
+
getExecutionSourceCode() {
|
|
38
|
+
return this._process.script.sourceCode;
|
|
39
|
+
}
|
|
40
|
+
async getDependenciesPath() {
|
|
41
|
+
try {
|
|
42
|
+
const isScopedToProcess = this._process.settings.dependencies.scopedToProcess;
|
|
43
|
+
const fullPath = isScopedToProcess ? (0, dependencies_1.getProcessDependenciesPath)(this._process) : await (0, dependencies_1.getDependenciesPath)(this._process.script.programmingLanguage);
|
|
44
|
+
if (!fs.existsSync(fullPath)) {
|
|
45
|
+
throw isScopedToProcess ? new errors_1.ProcessDependenciesNotInstalled(this._process) : new errors_1.DependenciesNotInstalled(this._process.script.programmingLanguage);
|
|
46
|
+
}
|
|
47
|
+
return fullPath;
|
|
48
|
+
}
|
|
49
|
+
catch (error) {
|
|
50
|
+
if (error instanceof errors_1.DependenciesNotInstalled) {
|
|
51
|
+
if (!(await cli_1.default.confirm('⚠️ Dependencies are not installed. Do you want to install them? yes/no'))) {
|
|
52
|
+
throw error;
|
|
53
|
+
}
|
|
54
|
+
else {
|
|
55
|
+
if ('PYTHON' === this._programmingLanguage) {
|
|
56
|
+
await python_env_dependencies_1.default.run([]);
|
|
57
|
+
}
|
|
58
|
+
else {
|
|
59
|
+
await javascript_env_dependencies_1.default.run([]);
|
|
60
|
+
}
|
|
61
|
+
return this.getDependenciesPath();
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
else if (error instanceof errors_1.ProcessDependenciesNotInstalled) {
|
|
65
|
+
if (!(await cli_1.default.confirm('⚠️ Process dependencies are not installed. Do you want to install them? yes/no'))) {
|
|
66
|
+
throw error;
|
|
67
|
+
}
|
|
68
|
+
else {
|
|
69
|
+
await env_process_dependencies_command_1.default.run([this._process.slug]);
|
|
70
|
+
return this.getDependenciesPath();
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
else {
|
|
74
|
+
throw error;
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
get returnValueFilePath() {
|
|
79
|
+
return path.join(this._tempDir, 'return_value.json');
|
|
80
|
+
}
|
|
81
|
+
get errorValueFilePath() {
|
|
82
|
+
return path.join(this._tempDir, 'error_value.json');
|
|
83
|
+
}
|
|
84
|
+
readReturnValue() {
|
|
85
|
+
if (fs.existsSync(this.returnValueFilePath)) {
|
|
86
|
+
try {
|
|
87
|
+
return JSON.parse(fs.readFileSync(this.returnValueFilePath, 'utf8'));
|
|
88
|
+
}
|
|
89
|
+
catch {
|
|
90
|
+
return undefined;
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
return undefined;
|
|
94
|
+
}
|
|
95
|
+
readErrorValue() {
|
|
96
|
+
if (fs.existsSync(this.errorValueFilePath)) {
|
|
97
|
+
try {
|
|
98
|
+
return JSON.parse(fs.readFileSync(this.errorValueFilePath, 'utf8'));
|
|
99
|
+
}
|
|
100
|
+
catch {
|
|
101
|
+
return undefined;
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
return undefined;
|
|
105
|
+
}
|
|
106
|
+
getMetadata() {
|
|
107
|
+
return {
|
|
108
|
+
parameters: this._options.parameters,
|
|
109
|
+
execution: {
|
|
110
|
+
process: {
|
|
111
|
+
id: this._process?.id,
|
|
112
|
+
name: this._process?.name,
|
|
113
|
+
},
|
|
114
|
+
},
|
|
115
|
+
variables: this.getVariablesObject(),
|
|
116
|
+
request: this._options.request ?? 'No request, you are using the CLI',
|
|
117
|
+
};
|
|
118
|
+
}
|
|
119
|
+
async prepare() {
|
|
120
|
+
this._dependenciesPath = await this.getDependenciesPath();
|
|
121
|
+
const createFilesResult = await this._createExecutionFiles(this._tempDir);
|
|
122
|
+
this._execFilePath = createFilesResult.FCODE_EXECUTION_FILE;
|
|
123
|
+
const exportVars = {
|
|
124
|
+
...createFilesResult,
|
|
125
|
+
FCODE_DEPENDENCIES_PATH: this._dependenciesPath,
|
|
126
|
+
FCODE_EXECUTION_PATH: [createFilesResult.FCODE_LIBRARY_PATH, this._dependenciesPath].filter((p) => p).join(':'),
|
|
127
|
+
};
|
|
128
|
+
fs.writeFileSync(path.join(this._tempDir, 'METADATA'), Object.entries(exportVars)
|
|
129
|
+
.map(([key, value]) => `${key}=${value}`)
|
|
130
|
+
.join('\n'));
|
|
131
|
+
return this._execFilePath;
|
|
132
|
+
}
|
|
133
|
+
cleanup() {
|
|
134
|
+
if (this._tempDir) {
|
|
135
|
+
fs.rmSync(this._tempDir, { force: true, recursive: true });
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
exports.default = ExecutionTask;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import ExecutionTask from './execution-task';
|
|
2
|
+
/**
|
|
3
|
+
* Task which handles native executions using child_process.
|
|
4
|
+
*/
|
|
5
|
+
declare class JavaScriptExecutionTask extends ExecutionTask {
|
|
6
|
+
run(): Promise<unknown>;
|
|
7
|
+
_getLegacyBlock(): string;
|
|
8
|
+
_getNewBlock(): string;
|
|
9
|
+
_createExecutionFiles(tempDir: string): Promise<{
|
|
10
|
+
[name: string]: string;
|
|
11
|
+
}>;
|
|
12
|
+
}
|
|
13
|
+
export default JavaScriptExecutionTask;
|