farseer-cli 1.0.9 → 1.0.10
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/dist/commands/app.js +344 -316
- package/dist/commands/apps.js +83 -103
- package/dist/commands/checkout.js +156 -134
- package/dist/commands/config.js +126 -124
- package/dist/commands/diff.js +194 -169
- package/dist/commands/dimensions.js +122 -137
- package/dist/commands/files.js +77 -88
- package/dist/commands/install.js +77 -74
- package/dist/commands/list.js +74 -89
- package/dist/commands/login.js +101 -126
- package/dist/commands/logout.js +42 -57
- package/dist/commands/mcp-server.js +24 -39
- package/dist/commands/model.js +176 -184
- package/dist/commands/pull.js +276 -248
- package/dist/commands/push.js +222 -200
- package/dist/commands/run.js +322 -274
- package/dist/commands/status.js +170 -147
- package/dist/commands/variables.js +192 -168
- package/dist/commands/whoami.js +45 -61
- package/dist/index.js +115 -117
- package/dist/mcp/index.js +17 -33
- package/dist/mcp/prompts/workflows.js +146 -191
- package/dist/mcp/resources/documentation.js +149 -158
- package/dist/mcp/server.js +34 -50
- package/dist/mcp/tools/appTools.js +278 -307
- package/dist/mcp/tools/authTools.js +123 -130
- package/dist/mcp/tools/dataTools.js +271 -275
- package/dist/mcp/tools/modelTools.js +233 -265
- package/dist/mcp/tools/runTools.js +205 -199
- package/dist/mcp/tools/syncTools.js +315 -341
- package/dist/mcp/utils/helpers.js +124 -117
- package/dist/services/appSyncService.js +438 -379
- package/dist/services/configService.js +144 -154
- package/dist/services/farseerApi.js +401 -401
- package/dist/services/farseerFactory.js +274 -208
- package/dist/services/farseerService.js +488 -455
- package/dist/services/syncService.js +732 -657
- package/dist/utils/constants.js +20 -45
- package/dist/utils/helpers.js +366 -333
- package/dist/utils/logger.js +43 -74
- package/package.json +8 -1
- package/dist/commands/app.js.map +0 -7
- package/dist/commands/apps.js.map +0 -7
- package/dist/commands/checkout.js.map +0 -7
- package/dist/commands/config.js.map +0 -7
- package/dist/commands/diff.js.map +0 -7
- package/dist/commands/dimensions.js.map +0 -7
- package/dist/commands/files.js.map +0 -7
- package/dist/commands/install.js.map +0 -7
- package/dist/commands/list.js.map +0 -7
- package/dist/commands/login.js.map +0 -7
- package/dist/commands/logout.js.map +0 -7
- package/dist/commands/mcp-server.js.map +0 -7
- package/dist/commands/model.js.map +0 -7
- package/dist/commands/pull.js.map +0 -7
- package/dist/commands/push.js.map +0 -7
- package/dist/commands/run.js.map +0 -7
- package/dist/commands/status.js.map +0 -7
- package/dist/commands/variables.js.map +0 -7
- package/dist/commands/whoami.js.map +0 -7
- package/dist/index.js.map +0 -7
- package/dist/mcp/index.js.map +0 -7
- package/dist/mcp/prompts/workflows.js.map +0 -7
- package/dist/mcp/resources/documentation.js.map +0 -7
- package/dist/mcp/server.js.map +0 -7
- package/dist/mcp/tools/appTools.js.map +0 -7
- package/dist/mcp/tools/authTools.js.map +0 -7
- package/dist/mcp/tools/dataTools.js.map +0 -7
- package/dist/mcp/tools/modelTools.js.map +0 -7
- package/dist/mcp/tools/runTools.js.map +0 -7
- package/dist/mcp/tools/syncTools.js.map +0 -7
- package/dist/mcp/utils/helpers.js.map +0 -7
- package/dist/services/appSyncService.js.map +0 -7
- package/dist/services/configService.js.map +0 -7
- package/dist/services/farseerApi.js.map +0 -7
- package/dist/services/farseerFactory.js.map +0 -7
- package/dist/services/farseerService.js.map +0 -7
- package/dist/services/syncService.js.map +0 -7
- package/dist/utils/constants.js.map +0 -7
- package/dist/utils/helpers.js.map +0 -7
- package/dist/utils/logger.js.map +0 -7
package/dist/commands/run.js
CHANGED
|
@@ -1,288 +1,336 @@
|
|
|
1
|
-
|
|
2
|
-
var
|
|
3
|
-
|
|
4
|
-
var
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
return to;
|
|
18
|
-
};
|
|
19
|
-
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
20
|
-
// If the importer is in node compatibility mode or this is not an ESM
|
|
21
|
-
// file that has been converted to a CommonJS file using a Babel-
|
|
22
|
-
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
23
|
-
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
24
|
-
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
25
|
-
mod
|
|
26
|
-
));
|
|
27
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
28
|
-
var run_exports = {};
|
|
29
|
-
__export(run_exports, {
|
|
30
|
-
registerRunCommand: () => registerRunCommand
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
31
17
|
});
|
|
32
|
-
|
|
33
|
-
var
|
|
34
|
-
|
|
35
|
-
var
|
|
36
|
-
var
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
18
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
+
var ownKeys = function(o) {
|
|
20
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
+
var ar = [];
|
|
22
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
+
return ar;
|
|
24
|
+
};
|
|
25
|
+
return ownKeys(o);
|
|
26
|
+
};
|
|
27
|
+
return function (mod) {
|
|
28
|
+
if (mod && mod.__esModule) return mod;
|
|
29
|
+
var result = {};
|
|
30
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
+
__setModuleDefault(result, mod);
|
|
32
|
+
return result;
|
|
33
|
+
};
|
|
34
|
+
})();
|
|
35
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
|
+
exports.registerRunCommand = registerRunCommand;
|
|
37
|
+
const logger_1 = require("../utils/logger");
|
|
38
|
+
const configService_1 = require("../services/configService");
|
|
39
|
+
const farseerService_1 = require("../services/farseerService");
|
|
40
|
+
const farseerFactory_1 = require("../services/farseerFactory");
|
|
41
|
+
const helpers_1 = require("../utils/helpers");
|
|
42
|
+
const fs = __importStar(require("fs"));
|
|
43
|
+
const path = __importStar(require("path"));
|
|
44
|
+
const child_process_1 = require("child_process");
|
|
45
|
+
/**
|
|
46
|
+
* Find a script file recursively in a directory.
|
|
47
|
+
* Returns the relative path from baseDir if found, null otherwise.
|
|
48
|
+
*/
|
|
41
49
|
function findScriptRecursively(baseDir, scriptName) {
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
}
|
|
45
|
-
const search = (dir, relativePath = "") => {
|
|
46
|
-
const items = fs.readdirSync(dir, { withFileTypes: true });
|
|
47
|
-
for (const item of items) {
|
|
48
|
-
const itemRelPath = relativePath ? `${relativePath}/${item.name}` : item.name;
|
|
49
|
-
if (item.isFile() && item.name === scriptName) {
|
|
50
|
-
return itemRelPath;
|
|
51
|
-
}
|
|
52
|
-
if (item.isDirectory()) {
|
|
53
|
-
const found = search(path.join(dir, item.name), itemRelPath);
|
|
54
|
-
if (found) return found;
|
|
55
|
-
}
|
|
50
|
+
if (!fs.existsSync(baseDir)) {
|
|
51
|
+
return null;
|
|
56
52
|
}
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
53
|
+
const search = (dir, relativePath = '') => {
|
|
54
|
+
const items = fs.readdirSync(dir, { withFileTypes: true });
|
|
55
|
+
for (const item of items) {
|
|
56
|
+
const itemRelPath = relativePath ? `${relativePath}/${item.name}` : item.name;
|
|
57
|
+
if (item.isFile() && item.name === scriptName) {
|
|
58
|
+
return itemRelPath;
|
|
59
|
+
}
|
|
60
|
+
if (item.isDirectory()) {
|
|
61
|
+
const found = search(path.join(dir, item.name), itemRelPath);
|
|
62
|
+
if (found)
|
|
63
|
+
return found;
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
return null;
|
|
67
|
+
};
|
|
68
|
+
return search(baseDir);
|
|
60
69
|
}
|
|
61
70
|
async function getRunCredentials(tenant, tenantId) {
|
|
62
|
-
|
|
63
|
-
|
|
71
|
+
// First try API key config
|
|
72
|
+
const credential = (0, configService_1.getCredential)(tenant);
|
|
73
|
+
if (credential) {
|
|
74
|
+
return {
|
|
75
|
+
tenantId: credential.tenantId,
|
|
76
|
+
apiKey: credential.apiKey,
|
|
77
|
+
basePath: credential.basePath,
|
|
78
|
+
};
|
|
79
|
+
}
|
|
80
|
+
// Try user auth (browser login)
|
|
81
|
+
const auth = (0, configService_1.getUserAuth)();
|
|
82
|
+
if (!auth) {
|
|
83
|
+
return null;
|
|
84
|
+
}
|
|
85
|
+
// Check if token needs refresh
|
|
86
|
+
if (!(0, configService_1.isUserAuthValid)()) {
|
|
87
|
+
logger_1.logger.dim('Token expired, refreshing...');
|
|
88
|
+
const refreshed = await (0, farseerService_1.refreshAccessToken)(auth.refreshToken, auth.realm || 'master');
|
|
89
|
+
if (!refreshed) {
|
|
90
|
+
logger_1.logger.warning('Could not refresh token. Please login again with: farseer login');
|
|
91
|
+
return null;
|
|
92
|
+
}
|
|
93
|
+
// Save refreshed token
|
|
94
|
+
(0, configService_1.setUserAuth)({
|
|
95
|
+
accessToken: refreshed.accessToken,
|
|
96
|
+
refreshToken: refreshed.refreshToken,
|
|
97
|
+
expiresAt: new Date(Date.now() + refreshed.expiresIn * 1000).toISOString(),
|
|
98
|
+
realm: auth.realm,
|
|
99
|
+
});
|
|
100
|
+
logger_1.logger.success('Token refreshed');
|
|
101
|
+
}
|
|
102
|
+
const updatedAuth = (0, configService_1.getUserAuth)();
|
|
103
|
+
if (!updatedAuth)
|
|
104
|
+
return null;
|
|
105
|
+
// Use tenant name as organisation for basePath, tenantId for TENANT_ID env var
|
|
64
106
|
return {
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
107
|
+
tenantId: tenantId || tenant,
|
|
108
|
+
accessToken: updatedAuth.accessToken,
|
|
109
|
+
basePath: (0, configService_1.generateBasePath)(tenant),
|
|
68
110
|
};
|
|
69
|
-
}
|
|
70
|
-
const auth = (0, import_configService.getUserAuth)();
|
|
71
|
-
if (!auth) {
|
|
72
|
-
return null;
|
|
73
|
-
}
|
|
74
|
-
if (!(0, import_configService.isUserAuthValid)()) {
|
|
75
|
-
import_logger.logger.dim("Token expired, refreshing...");
|
|
76
|
-
const refreshed = await (0, import_farseerService.refreshAccessToken)(auth.refreshToken, auth.realm || "master");
|
|
77
|
-
if (!refreshed) {
|
|
78
|
-
import_logger.logger.warning("Could not refresh token. Please login again with: farseer login");
|
|
79
|
-
return null;
|
|
80
|
-
}
|
|
81
|
-
(0, import_configService.setUserAuth)({
|
|
82
|
-
accessToken: refreshed.accessToken,
|
|
83
|
-
refreshToken: refreshed.refreshToken,
|
|
84
|
-
expiresAt: new Date(Date.now() + refreshed.expiresIn * 1e3).toISOString(),
|
|
85
|
-
realm: auth.realm
|
|
86
|
-
});
|
|
87
|
-
import_logger.logger.success("Token refreshed");
|
|
88
|
-
}
|
|
89
|
-
const updatedAuth = (0, import_configService.getUserAuth)();
|
|
90
|
-
if (!updatedAuth) return null;
|
|
91
|
-
return {
|
|
92
|
-
tenantId: tenantId || tenant,
|
|
93
|
-
accessToken: updatedAuth.accessToken,
|
|
94
|
-
basePath: (0, import_configService.generateBasePath)(tenant)
|
|
95
|
-
};
|
|
96
111
|
}
|
|
112
|
+
// Helper to collect multiple --arg options
|
|
97
113
|
function collectArgs(value, previous) {
|
|
98
|
-
|
|
114
|
+
return previous.concat([value]);
|
|
99
115
|
}
|
|
100
116
|
function registerRunCommand(program) {
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
117
|
+
program
|
|
118
|
+
.command('run <args...>')
|
|
119
|
+
.description('Run an app locally with injected credentials')
|
|
120
|
+
.option('--tenant-id <id>', 'Tenant ID for env variables (defaults to tenant name)')
|
|
121
|
+
.option('--arg <value>', 'Pass argument in format "Name=Value" (can be used multiple times)', collectArgs, [])
|
|
122
|
+
.action(async (args, options) => {
|
|
123
|
+
const { tenant, appName } = (0, helpers_1.parseAppArgs)(args);
|
|
124
|
+
// First, get the app details to find the entrypoint script
|
|
125
|
+
const clientResult = await (0, farseerFactory_1.getFarseerClientWithFallback)(tenant, options.tenantId);
|
|
126
|
+
if (!clientResult) {
|
|
127
|
+
(0, farseerFactory_1.showLoginPrompt)(tenant);
|
|
128
|
+
process.exit(1);
|
|
129
|
+
}
|
|
130
|
+
const api = clientResult.client;
|
|
131
|
+
// Find the app
|
|
132
|
+
logger_1.logger.info(`Loading app: ${appName}...`);
|
|
133
|
+
const app = await api.getAppByName(appName);
|
|
134
|
+
if (!app) {
|
|
135
|
+
logger_1.logger.error(`App not found: ${appName}`);
|
|
136
|
+
logger_1.logger.dim('List available apps with: farseer apps ' + tenant);
|
|
137
|
+
process.exit(1);
|
|
138
|
+
}
|
|
139
|
+
const runScripts = app.scriptFiles ?? [];
|
|
140
|
+
if (!app.mainScriptFileId || runScripts.length === 0) {
|
|
141
|
+
logger_1.logger.error(`App "${appName}" has no scripts configured.`);
|
|
142
|
+
logger_1.logger.dim('Configure the app with: farseer app configure "' + appName + '" --entrypoint <script>');
|
|
143
|
+
process.exit(1);
|
|
144
|
+
}
|
|
145
|
+
// Find the entrypoint script name
|
|
146
|
+
const mainScript = runScripts.find((s) => s.id === app.mainScriptFileId);
|
|
147
|
+
if (!mainScript) {
|
|
148
|
+
logger_1.logger.error(`Entrypoint script not found for app "${appName}".`);
|
|
149
|
+
process.exit(1);
|
|
150
|
+
}
|
|
151
|
+
// Normalize script name - handle both "test.ts" and "Scripts/test.ts" formats
|
|
152
|
+
let scriptName = mainScript.name;
|
|
153
|
+
if (scriptName.toLowerCase().startsWith('scripts/')) {
|
|
154
|
+
scriptName = scriptName.substring('scripts/'.length);
|
|
155
|
+
}
|
|
156
|
+
// Get credentials for running
|
|
157
|
+
const credentials = await getRunCredentials(tenant, options.tenantId);
|
|
158
|
+
if (!credentials) {
|
|
159
|
+
(0, farseerFactory_1.showLoginPrompt)(tenant);
|
|
160
|
+
process.exit(1);
|
|
161
|
+
}
|
|
162
|
+
const tenantDir = (0, helpers_1.getTenantDir)(tenant);
|
|
163
|
+
const srcDir = (0, helpers_1.getTenantSrcDir)(tenant);
|
|
164
|
+
const filesDir = (0, helpers_1.getTenantFilesDir)(tenant);
|
|
165
|
+
// Script path is relative to files/Scripts/ folder
|
|
166
|
+
// First try direct path, then search recursively if not found
|
|
167
|
+
let scriptPath = path.resolve(srcDir, scriptName);
|
|
168
|
+
let relativeScriptPath = `files/Scripts/${scriptName}`;
|
|
169
|
+
if (!fs.existsSync(scriptPath)) {
|
|
170
|
+
// Try to find the script recursively in the files directory
|
|
171
|
+
const foundPath = findScriptRecursively(filesDir, path.basename(scriptName));
|
|
172
|
+
if (foundPath) {
|
|
173
|
+
scriptPath = path.resolve(filesDir, foundPath);
|
|
174
|
+
relativeScriptPath = `files/${foundPath}`;
|
|
175
|
+
logger_1.logger.dim(`Found script at: ${foundPath}`);
|
|
176
|
+
}
|
|
177
|
+
}
|
|
178
|
+
if (!fs.existsSync(scriptPath)) {
|
|
179
|
+
logger_1.logger.error(`Script not found locally: ${scriptPath}`);
|
|
180
|
+
logger_1.logger.dim('Run "farseer pull ' + tenant + '" to download scripts first.');
|
|
181
|
+
process.exit(1);
|
|
182
|
+
}
|
|
183
|
+
// Check if node_modules exists
|
|
184
|
+
const nodeModulesPath = path.join(tenantDir, 'node_modules');
|
|
185
|
+
if (!fs.existsSync(nodeModulesPath)) {
|
|
186
|
+
logger_1.logger.error(`Dependencies not installed for ${tenant}`);
|
|
187
|
+
logger_1.logger.dim(`Run: farseer install ${tenant}`);
|
|
188
|
+
process.exit(1);
|
|
189
|
+
}
|
|
190
|
+
// Parse arguments
|
|
191
|
+
const appArgs = {};
|
|
192
|
+
// Start with default values from app config
|
|
193
|
+
for (const arg of app.expectedArguments) {
|
|
194
|
+
appArgs[arg.name] = arg.defaultValue;
|
|
195
|
+
}
|
|
196
|
+
// Override with provided arguments
|
|
197
|
+
for (const argStr of options.arg) {
|
|
198
|
+
const eqIndex = argStr.indexOf('=');
|
|
199
|
+
if (eqIndex === -1) {
|
|
200
|
+
logger_1.logger.error(`Invalid argument format: ${argStr}`);
|
|
201
|
+
logger_1.logger.dim('Use format: --arg "Name=Value"');
|
|
202
|
+
process.exit(1);
|
|
203
|
+
}
|
|
204
|
+
const name = argStr.substring(0, eqIndex);
|
|
205
|
+
const value = argStr.substring(eqIndex + 1);
|
|
206
|
+
appArgs[name] = value;
|
|
207
|
+
}
|
|
208
|
+
const authType = credentials.apiKey ? 'API key' : 'access token';
|
|
209
|
+
logger_1.logger.info(`Running app "${app.name}" (${scriptName}) for tenant ${tenant} (using ${authType})...`);
|
|
210
|
+
// Show arguments being used
|
|
211
|
+
if (Object.keys(appArgs).length > 0) {
|
|
212
|
+
logger_1.logger.dim('Arguments:');
|
|
213
|
+
for (const [key, value] of Object.entries(appArgs)) {
|
|
214
|
+
logger_1.logger.dim(` ${key}: ${value}`);
|
|
215
|
+
}
|
|
216
|
+
}
|
|
217
|
+
console.log();
|
|
218
|
+
// Build environment variables based on auth type
|
|
219
|
+
const envVars = {
|
|
220
|
+
...process.env,
|
|
221
|
+
TENANT_ID: credentials.tenantId,
|
|
222
|
+
FARSEER_URL: credentials.basePath,
|
|
223
|
+
};
|
|
224
|
+
if (credentials.apiKey) {
|
|
225
|
+
envVars.FARSEER_API_KEY = credentials.apiKey;
|
|
226
|
+
}
|
|
227
|
+
if (credentials.accessToken) {
|
|
228
|
+
envVars.FARSEER_ACCESS_TOKEN = credentials.accessToken;
|
|
229
|
+
}
|
|
230
|
+
// Build command line arguments from app arguments (in order)
|
|
231
|
+
const cmdArgs = [];
|
|
232
|
+
for (const arg of app.expectedArguments) {
|
|
233
|
+
cmdArgs.push(appArgs[arg.name] ?? arg.defaultValue);
|
|
234
|
+
}
|
|
235
|
+
// Run with credentials injected via environment variables, arguments via command line
|
|
236
|
+
// Quote the script path to handle spaces in folder names
|
|
237
|
+
const quotedScriptPath = `"${relativeScriptPath}"`;
|
|
238
|
+
const child = (0, child_process_1.spawn)('npx', ['tsx', quotedScriptPath, ...cmdArgs], {
|
|
239
|
+
stdio: 'inherit',
|
|
240
|
+
cwd: tenantDir,
|
|
241
|
+
shell: true,
|
|
242
|
+
env: envVars,
|
|
243
|
+
});
|
|
244
|
+
child.on('close', (code) => {
|
|
245
|
+
if (code !== 0) {
|
|
246
|
+
logger_1.logger.error(`Script exited with code ${code}`);
|
|
247
|
+
process.exit(code || 1);
|
|
248
|
+
}
|
|
249
|
+
});
|
|
250
|
+
child.on('error', (err) => {
|
|
251
|
+
logger_1.logger.error(`Failed to run script: ${err.message}`);
|
|
252
|
+
logger_1.logger.dim('Make sure tsx is installed: npm install -g tsx');
|
|
253
|
+
process.exit(1);
|
|
254
|
+
});
|
|
210
255
|
});
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
256
|
+
// Keep the old script-based run as a separate command
|
|
257
|
+
program
|
|
258
|
+
.command('run-script <args...>')
|
|
259
|
+
.description('Run a script directly (without app wrapper)')
|
|
260
|
+
.option('--tenant-id <id>', 'Tenant ID for env variables (defaults to tenant name)')
|
|
261
|
+
.action(async (args, options) => {
|
|
262
|
+
const { tenant, appName } = (0, helpers_1.parseAppArgs)(args);
|
|
263
|
+
let script = appName;
|
|
264
|
+
const credentials = await getRunCredentials(tenant, options.tenantId);
|
|
265
|
+
if (!credentials) {
|
|
266
|
+
(0, farseerFactory_1.showLoginPrompt)(tenant);
|
|
267
|
+
process.exit(1);
|
|
268
|
+
}
|
|
269
|
+
// Normalize script path - strip Scripts/ prefix if present
|
|
270
|
+
if (script.toLowerCase().startsWith('scripts/')) {
|
|
271
|
+
script = script.substring('scripts/'.length);
|
|
272
|
+
}
|
|
273
|
+
const tenantDir = (0, helpers_1.getTenantDir)(tenant);
|
|
274
|
+
const srcDir = (0, helpers_1.getTenantSrcDir)(tenant);
|
|
275
|
+
const filesDir = (0, helpers_1.getTenantFilesDir)(tenant);
|
|
276
|
+
// Script path is relative to files/Scripts/ folder
|
|
277
|
+
// First try direct path, then search recursively if not found
|
|
278
|
+
let scriptPath = path.resolve(srcDir, script);
|
|
279
|
+
let relativeScriptPath = `files/Scripts/${script}`;
|
|
280
|
+
if (!fs.existsSync(scriptPath)) {
|
|
281
|
+
// Try to find the script recursively in the files directory
|
|
282
|
+
const foundPath = findScriptRecursively(filesDir, path.basename(script));
|
|
283
|
+
if (foundPath) {
|
|
284
|
+
scriptPath = path.resolve(filesDir, foundPath);
|
|
285
|
+
relativeScriptPath = `files/${foundPath}`;
|
|
286
|
+
logger_1.logger.dim(`Found script at: ${foundPath}`);
|
|
287
|
+
}
|
|
288
|
+
}
|
|
289
|
+
if (!fs.existsSync(scriptPath)) {
|
|
290
|
+
logger_1.logger.error(`Script not found: ${scriptPath}`);
|
|
291
|
+
process.exit(1);
|
|
292
|
+
}
|
|
293
|
+
// Check if node_modules exists
|
|
294
|
+
const nodeModulesPath = path.join(tenantDir, 'node_modules');
|
|
295
|
+
if (!fs.existsSync(nodeModulesPath)) {
|
|
296
|
+
logger_1.logger.error(`Dependencies not installed for ${tenant}`);
|
|
297
|
+
logger_1.logger.dim(`Run: farseer install ${tenant}`);
|
|
298
|
+
process.exit(1);
|
|
299
|
+
}
|
|
300
|
+
const authType = credentials.apiKey ? 'API key' : 'access token';
|
|
301
|
+
logger_1.logger.info(`Running ${script} for tenant ${tenant} (using ${authType})...`);
|
|
302
|
+
console.log();
|
|
303
|
+
// Build environment variables based on auth type
|
|
304
|
+
const envVars = {
|
|
305
|
+
...process.env,
|
|
306
|
+
TENANT_ID: credentials.tenantId,
|
|
307
|
+
FARSEER_URL: credentials.basePath,
|
|
308
|
+
};
|
|
309
|
+
if (credentials.apiKey) {
|
|
310
|
+
envVars.FARSEER_API_KEY = credentials.apiKey;
|
|
311
|
+
}
|
|
312
|
+
if (credentials.accessToken) {
|
|
313
|
+
envVars.FARSEER_ACCESS_TOKEN = credentials.accessToken;
|
|
314
|
+
}
|
|
315
|
+
// Run with credentials injected via environment variables
|
|
316
|
+
// Quote the script path to handle spaces in folder names
|
|
317
|
+
const quotedScriptPath = `"${relativeScriptPath}"`;
|
|
318
|
+
const child = (0, child_process_1.spawn)('npx', ['tsx', quotedScriptPath], {
|
|
319
|
+
stdio: 'inherit',
|
|
320
|
+
cwd: tenantDir,
|
|
321
|
+
shell: true,
|
|
322
|
+
env: envVars,
|
|
323
|
+
});
|
|
324
|
+
child.on('close', (code) => {
|
|
325
|
+
if (code !== 0) {
|
|
326
|
+
logger_1.logger.error(`Script exited with code ${code}`);
|
|
327
|
+
process.exit(code || 1);
|
|
328
|
+
}
|
|
329
|
+
});
|
|
330
|
+
child.on('error', (err) => {
|
|
331
|
+
logger_1.logger.error(`Failed to run script: ${err.message}`);
|
|
332
|
+
logger_1.logger.dim('Make sure tsx is installed: npm install -g tsx');
|
|
333
|
+
process.exit(1);
|
|
334
|
+
});
|
|
215
335
|
});
|
|
216
|
-
});
|
|
217
|
-
program.command("run-script <args...>").description("Run a script directly (without app wrapper)").option("--tenant-id <id>", "Tenant ID for env variables (defaults to tenant name)").action(async (args, options) => {
|
|
218
|
-
let { tenant, appName: script } = (0, import_helpers.parseAppArgs)(args);
|
|
219
|
-
const credentials = await getRunCredentials(tenant, options.tenantId);
|
|
220
|
-
if (!credentials) {
|
|
221
|
-
(0, import_farseerFactory.showLoginPrompt)(tenant);
|
|
222
|
-
process.exit(1);
|
|
223
|
-
}
|
|
224
|
-
if (script.toLowerCase().startsWith("scripts/")) {
|
|
225
|
-
script = script.substring("scripts/".length);
|
|
226
|
-
}
|
|
227
|
-
const tenantDir = (0, import_helpers.getTenantDir)(tenant);
|
|
228
|
-
const srcDir = (0, import_helpers.getTenantSrcDir)(tenant);
|
|
229
|
-
const filesDir = (0, import_helpers.getTenantFilesDir)(tenant);
|
|
230
|
-
let scriptPath = path.resolve(srcDir, script);
|
|
231
|
-
let relativeScriptPath = `files/Scripts/${script}`;
|
|
232
|
-
if (!fs.existsSync(scriptPath)) {
|
|
233
|
-
const foundPath = findScriptRecursively(filesDir, path.basename(script));
|
|
234
|
-
if (foundPath) {
|
|
235
|
-
scriptPath = path.resolve(filesDir, foundPath);
|
|
236
|
-
relativeScriptPath = `files/${foundPath}`;
|
|
237
|
-
import_logger.logger.dim(`Found script at: ${foundPath}`);
|
|
238
|
-
}
|
|
239
|
-
}
|
|
240
|
-
if (!fs.existsSync(scriptPath)) {
|
|
241
|
-
import_logger.logger.error(`Script not found: ${scriptPath}`);
|
|
242
|
-
process.exit(1);
|
|
243
|
-
}
|
|
244
|
-
const nodeModulesPath = path.join(tenantDir, "node_modules");
|
|
245
|
-
if (!fs.existsSync(nodeModulesPath)) {
|
|
246
|
-
import_logger.logger.error(`Dependencies not installed for ${tenant}`);
|
|
247
|
-
import_logger.logger.dim(`Run: farseer install ${tenant}`);
|
|
248
|
-
process.exit(1);
|
|
249
|
-
}
|
|
250
|
-
const authType = credentials.apiKey ? "API key" : "access token";
|
|
251
|
-
import_logger.logger.info(`Running ${script} for tenant ${tenant} (using ${authType})...`);
|
|
252
|
-
console.log();
|
|
253
|
-
const envVars = {
|
|
254
|
-
...process.env,
|
|
255
|
-
TENANT_ID: credentials.tenantId,
|
|
256
|
-
FARSEER_URL: credentials.basePath
|
|
257
|
-
};
|
|
258
|
-
if (credentials.apiKey) {
|
|
259
|
-
envVars.FARSEER_API_KEY = credentials.apiKey;
|
|
260
|
-
}
|
|
261
|
-
if (credentials.accessToken) {
|
|
262
|
-
envVars.FARSEER_ACCESS_TOKEN = credentials.accessToken;
|
|
263
|
-
}
|
|
264
|
-
const quotedScriptPath = `"${relativeScriptPath}"`;
|
|
265
|
-
const child = (0, import_child_process.spawn)("npx", ["tsx", quotedScriptPath], {
|
|
266
|
-
stdio: "inherit",
|
|
267
|
-
cwd: tenantDir,
|
|
268
|
-
shell: true,
|
|
269
|
-
env: envVars
|
|
270
|
-
});
|
|
271
|
-
child.on("close", (code) => {
|
|
272
|
-
if (code !== 0) {
|
|
273
|
-
import_logger.logger.error(`Script exited with code ${code}`);
|
|
274
|
-
process.exit(code || 1);
|
|
275
|
-
}
|
|
276
|
-
});
|
|
277
|
-
child.on("error", (err) => {
|
|
278
|
-
import_logger.logger.error(`Failed to run script: ${err.message}`);
|
|
279
|
-
import_logger.logger.dim("Make sure tsx is installed: npm install -g tsx");
|
|
280
|
-
process.exit(1);
|
|
281
|
-
});
|
|
282
|
-
});
|
|
283
336
|
}
|
|
284
|
-
// Annotate the CommonJS export names for ESM import in node:
|
|
285
|
-
0 && (module.exports = {
|
|
286
|
-
registerRunCommand
|
|
287
|
-
});
|
|
288
|
-
//# sourceMappingURL=run.js.map
|