farseer-cli 1.0.8 → 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 +377 -0
- package/dist/commands/apps.js +91 -0
- package/dist/commands/checkout.js +164 -0
- package/dist/commands/config.js +141 -0
- package/dist/commands/diff.js +210 -0
- package/dist/commands/dimensions.js +130 -0
- package/dist/commands/files.js +88 -0
- package/dist/commands/install.js +82 -0
- package/dist/commands/list.js +77 -0
- package/dist/commands/login.js +109 -0
- package/dist/commands/logout.js +44 -0
- package/dist/commands/mcp-server.js +26 -0
- package/dist/commands/model.js +181 -0
- package/dist/commands/pull.js +286 -0
- package/dist/commands/push.js +235 -0
- package/dist/commands/run.js +336 -0
- package/dist/commands/status.js +178 -0
- package/dist/commands/variables.js +200 -0
- package/dist/commands/whoami.js +47 -0
- package/dist/index.js +163 -0
- package/dist/mcp/index.js +19 -0
- package/dist/mcp/prompts/workflows.js +403 -0
- package/dist/mcp/resources/documentation.js +158 -0
- package/dist/mcp/server.js +36 -0
- package/dist/mcp/tools/appTools.js +348 -0
- package/dist/mcp/tools/authTools.js +152 -0
- package/dist/mcp/tools/dataTools.js +358 -0
- package/dist/mcp/tools/modelTools.js +293 -0
- package/dist/mcp/tools/runTools.js +239 -0
- package/dist/mcp/tools/syncTools.js +383 -0
- package/dist/mcp/utils/helpers.js +142 -0
- package/dist/services/appSyncService.js +458 -0
- package/dist/services/configService.js +186 -0
- package/dist/services/farseerApi.js +426 -0
- package/dist/services/farseerFactory.js +297 -0
- package/dist/services/farseerService.js +647 -0
- package/dist/services/syncService.js +764 -0
- package/dist/utils/constants.js +21 -0
- package/dist/utils/helpers.js +446 -0
- package/dist/utils/logger.js +45 -0
- package/package.json +8 -1
|
@@ -0,0 +1,286 @@
|
|
|
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;
|
|
17
|
+
});
|
|
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
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
36
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
37
|
+
};
|
|
38
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
39
|
+
exports.registerPullCommand = registerPullCommand;
|
|
40
|
+
const chalk_1 = __importDefault(require("chalk"));
|
|
41
|
+
const inquirer_1 = __importDefault(require("inquirer"));
|
|
42
|
+
const logger_1 = require("../utils/logger");
|
|
43
|
+
const farseerFactory_1 = require("../services/farseerFactory");
|
|
44
|
+
const syncService_1 = require("../services/syncService");
|
|
45
|
+
const appSyncService_1 = require("../services/appSyncService");
|
|
46
|
+
const helpers_1 = require("../utils/helpers");
|
|
47
|
+
function registerPullCommand(program) {
|
|
48
|
+
program
|
|
49
|
+
.command('pull [org] [tenant]')
|
|
50
|
+
.description('Pull files from Farseer instance to local\n\nUsage: pull <org> <tenant> OR pull <tenant> (if org is known)')
|
|
51
|
+
.option('--all', 'Pull all files (default: only scripts .ts, .js)')
|
|
52
|
+
.option('--force', 'Force pull, overwriting local changes on conflicts')
|
|
53
|
+
.action(async (arg1, arg2, options) => {
|
|
54
|
+
const { organisation, tenant } = (0, helpers_1.resolveTenantWithOrgMapping)(arg1, arg2);
|
|
55
|
+
const clientResult = await (0, farseerFactory_1.getFarseerClientWithFallback)(organisation, tenant);
|
|
56
|
+
if (!clientResult) {
|
|
57
|
+
(0, farseerFactory_1.showLoginPrompt)(tenant);
|
|
58
|
+
process.exit(1);
|
|
59
|
+
}
|
|
60
|
+
const syncService = new syncService_1.SyncService(tenant, clientResult.client);
|
|
61
|
+
// Step 1: Ensure tenant folder exists
|
|
62
|
+
const tenantDir = (0, helpers_1.getTenantDir)(tenant);
|
|
63
|
+
(0, helpers_1.ensureDirectoryExists)(tenantDir);
|
|
64
|
+
// Create default package.json if it doesn't exist
|
|
65
|
+
await createDefaultPackageJson(tenantDir, tenant);
|
|
66
|
+
// Step 2: Pull files from Farseer
|
|
67
|
+
console.log();
|
|
68
|
+
console.log(chalk_1.default.bold('═══ Files ═══'));
|
|
69
|
+
logger_1.logger.info(`Pulling files from ${tenant}...`);
|
|
70
|
+
try {
|
|
71
|
+
let result = await syncService.pull({ all: options.all, force: options.force });
|
|
72
|
+
// Handle conflicts interactively
|
|
73
|
+
if (result.conflicts.length > 0 && !options.force) {
|
|
74
|
+
console.log();
|
|
75
|
+
console.log(chalk_1.default.red.bold(`${result.conflicts.length} conflict(s) detected:`));
|
|
76
|
+
console.log();
|
|
77
|
+
for (const conflict of result.conflicts) {
|
|
78
|
+
console.log(chalk_1.default.red(` ! ${conflict.filePath}`));
|
|
79
|
+
console.log(chalk_1.default.dim(` ${conflict.description}`));
|
|
80
|
+
}
|
|
81
|
+
console.log();
|
|
82
|
+
const resolutions = {};
|
|
83
|
+
for (const conflict of result.conflicts) {
|
|
84
|
+
let choices;
|
|
85
|
+
if (conflict.type === 'local_modified_remote_deleted') {
|
|
86
|
+
choices = [
|
|
87
|
+
{ name: 'Keep local (keep your modified file)', value: 'keep_local' },
|
|
88
|
+
{ name: 'Accept deletion (delete local file)', value: 'keep_remote' },
|
|
89
|
+
];
|
|
90
|
+
}
|
|
91
|
+
else if (conflict.type === 'local_deleted_remote_modified') {
|
|
92
|
+
choices = [
|
|
93
|
+
{ name: "Keep deleted (don't restore file)", value: 'keep_local' },
|
|
94
|
+
{ name: 'Restore remote version', value: 'keep_remote' },
|
|
95
|
+
];
|
|
96
|
+
}
|
|
97
|
+
else {
|
|
98
|
+
choices = [
|
|
99
|
+
{ name: 'Keep local version', value: 'keep_local' },
|
|
100
|
+
{ name: 'Use remote version (overwrite local)', value: 'keep_remote' },
|
|
101
|
+
{ name: 'Keep both (save remote as .remote file)', value: 'keep_both' },
|
|
102
|
+
];
|
|
103
|
+
}
|
|
104
|
+
const answer = await inquirer_1.default.prompt([
|
|
105
|
+
{
|
|
106
|
+
type: 'list',
|
|
107
|
+
name: 'resolution',
|
|
108
|
+
message: `${conflict.filePath} - ${conflict.description}`,
|
|
109
|
+
choices,
|
|
110
|
+
},
|
|
111
|
+
]);
|
|
112
|
+
resolutions[conflict.filePath] = answer.resolution;
|
|
113
|
+
}
|
|
114
|
+
// Re-pull with resolutions
|
|
115
|
+
result = await syncService.pull({ all: options.all, conflictResolutions: resolutions });
|
|
116
|
+
}
|
|
117
|
+
if (result.downloaded.length > 0) {
|
|
118
|
+
console.log(chalk_1.default.green('Downloaded:'));
|
|
119
|
+
for (const file of result.downloaded) {
|
|
120
|
+
console.log(chalk_1.default.green(` + ${file}`));
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
if (result.deleted.length > 0) {
|
|
124
|
+
console.log(chalk_1.default.red('Deleted (removed from remote):'));
|
|
125
|
+
for (const file of result.deleted) {
|
|
126
|
+
console.log(chalk_1.default.red(` - ${file}`));
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
if (result.conflictFilesWritten.length > 0) {
|
|
130
|
+
console.log(chalk_1.default.yellow('Conflict files created:'));
|
|
131
|
+
for (const file of result.conflictFilesWritten) {
|
|
132
|
+
console.log(chalk_1.default.yellow(` ~ ${file}`));
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
logger_1.logger.dim(`Files: +${result.downloaded.length} -${result.deleted.length} (${result.unchanged.length} unchanged)`);
|
|
136
|
+
// Create audit log entries for downloaded files
|
|
137
|
+
if (result.downloaded.length > 0) {
|
|
138
|
+
const syncState = syncService.loadSyncState();
|
|
139
|
+
const auditEntries = result.downloaded.map((filePath) => ({
|
|
140
|
+
operation: 'pulled',
|
|
141
|
+
filePath,
|
|
142
|
+
uploadTime: syncState.files[filePath]?.metadata?.uploadTime,
|
|
143
|
+
uploaderEmail: syncState.files[filePath]?.metadata?.uploaderEmail,
|
|
144
|
+
uploaderName: syncState.files[filePath]?.metadata?.uploaderName,
|
|
145
|
+
}));
|
|
146
|
+
(0, helpers_1.appendToAuditLog)(tenant, auditEntries);
|
|
147
|
+
}
|
|
148
|
+
let hasChanges = result.downloaded.length > 0 || result.deleted.length > 0;
|
|
149
|
+
// Step 3: Pull apps
|
|
150
|
+
let appResult = {
|
|
151
|
+
created: [],
|
|
152
|
+
updated: [],
|
|
153
|
+
deleted: [],
|
|
154
|
+
unchanged: [],
|
|
155
|
+
};
|
|
156
|
+
console.log();
|
|
157
|
+
console.log(chalk_1.default.bold('═══ Apps ═══'));
|
|
158
|
+
logger_1.logger.info(`Pulling apps from ${tenant}...`);
|
|
159
|
+
const appSyncService = new appSyncService_1.AppSyncService(tenant, clientResult.client);
|
|
160
|
+
appResult = await appSyncService.pull();
|
|
161
|
+
if (appResult.created.length > 0) {
|
|
162
|
+
console.log(chalk_1.default.green('New apps:'));
|
|
163
|
+
for (const app of appResult.created) {
|
|
164
|
+
console.log(chalk_1.default.green(` + ${app}`));
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
if (appResult.updated.length > 0) {
|
|
168
|
+
console.log(chalk_1.default.yellow('Updated apps:'));
|
|
169
|
+
for (const app of appResult.updated) {
|
|
170
|
+
console.log(chalk_1.default.yellow(` ~ ${app}`));
|
|
171
|
+
}
|
|
172
|
+
}
|
|
173
|
+
if (appResult.deleted.length > 0) {
|
|
174
|
+
console.log(chalk_1.default.red('Deleted apps (removed from remote):'));
|
|
175
|
+
for (const app of appResult.deleted) {
|
|
176
|
+
console.log(chalk_1.default.red(` - ${app}`));
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
logger_1.logger.dim(`Apps: +${appResult.created.length} ~${appResult.updated.length} -${appResult.deleted.length} (${appResult.unchanged.length} unchanged)`);
|
|
180
|
+
hasChanges =
|
|
181
|
+
hasChanges ||
|
|
182
|
+
appResult.created.length > 0 ||
|
|
183
|
+
appResult.updated.length > 0 ||
|
|
184
|
+
appResult.deleted.length > 0;
|
|
185
|
+
if (!hasChanges) {
|
|
186
|
+
logger_1.logger.success('Already up to date.');
|
|
187
|
+
return;
|
|
188
|
+
}
|
|
189
|
+
console.log();
|
|
190
|
+
console.log(chalk_1.default.bold('═══ Summary ═══'));
|
|
191
|
+
logger_1.logger.success('Pull complete!');
|
|
192
|
+
logger_1.logger.dim(`Files: +${result.downloaded.length} -${result.deleted.length} (${result.unchanged.length} unchanged)`);
|
|
193
|
+
logger_1.logger.dim(`Apps: +${appResult.created.length} ~${appResult.updated.length} -${appResult.deleted.length} (${appResult.unchanged.length} unchanged)`);
|
|
194
|
+
}
|
|
195
|
+
catch (error) {
|
|
196
|
+
logger_1.logger.error('Pull failed.');
|
|
197
|
+
if (error instanceof Error) {
|
|
198
|
+
logger_1.logger.dim(error.message);
|
|
199
|
+
}
|
|
200
|
+
process.exit(1);
|
|
201
|
+
}
|
|
202
|
+
});
|
|
203
|
+
}
|
|
204
|
+
async function createDefaultPackageJson(tenantDir, tenant) {
|
|
205
|
+
const fs = await Promise.resolve().then(() => __importStar(require('fs')));
|
|
206
|
+
const path = await Promise.resolve().then(() => __importStar(require('path')));
|
|
207
|
+
const packageJsonPath = path.join(tenantDir, 'package.json');
|
|
208
|
+
if (fs.existsSync(packageJsonPath)) {
|
|
209
|
+
return;
|
|
210
|
+
}
|
|
211
|
+
const packageJson = {
|
|
212
|
+
name: `farseer-scripts-${tenant}`,
|
|
213
|
+
version: '1.0.0',
|
|
214
|
+
description: `Farseer App scripts for ${tenant}`,
|
|
215
|
+
main: 'src/index.ts',
|
|
216
|
+
scripts: {},
|
|
217
|
+
keywords: ['farseer', 'scripts', tenant],
|
|
218
|
+
author: 'Farseer',
|
|
219
|
+
license: 'ISC',
|
|
220
|
+
dependencies: {
|
|
221
|
+
'@google-cloud/bigquery': '^7.9.0',
|
|
222
|
+
'@google-cloud/storage': '^7.12.1',
|
|
223
|
+
'@googleapis/sheets': '^5.0.5',
|
|
224
|
+
'@sendgrid/mail': '^7.7.0',
|
|
225
|
+
'@types/node-forge': '^1.3.11',
|
|
226
|
+
'@xmldom/xmldom': '^0.9.8',
|
|
227
|
+
arquero: '^5.4.1',
|
|
228
|
+
axios: '^1.10.0',
|
|
229
|
+
'axios-retry': '^3.9.1',
|
|
230
|
+
'basic-ftp': '^5.0.5',
|
|
231
|
+
'client-oauth2': '^4.3.3',
|
|
232
|
+
'csv-parser': '^3.0.0',
|
|
233
|
+
dotenv: '^16.4.5',
|
|
234
|
+
'draft-js': '^0.11.7',
|
|
235
|
+
exceljs: '^4.4.0',
|
|
236
|
+
'farseer-client': 'https://storage.googleapis.com/farseer-remote-jobs-results/farseer-client/release-1.4.5.tar',
|
|
237
|
+
'farseer-client-axios': 'https://storage.googleapis.com/farseer-remote-jobs-results/farseer-client-axios/6898c0cb-5dca-4b2f-b325-119efc7f099e/v1.0.1.tar',
|
|
238
|
+
'fast-xml-parser': '^4.5.0',
|
|
239
|
+
'form-data': '^4.0.0',
|
|
240
|
+
googleapis: '^144.0.0',
|
|
241
|
+
heapdump: '^0.3.15',
|
|
242
|
+
'image-size': '^1.1.1',
|
|
243
|
+
jszip: '^3.10.1',
|
|
244
|
+
'lossless-json': '^4.0.1',
|
|
245
|
+
mssql: '^10.0.4',
|
|
246
|
+
'node-fetch': '^2.7.0',
|
|
247
|
+
'node-forge': '^1.3.1',
|
|
248
|
+
'node-sp-auth': '^3.0.8',
|
|
249
|
+
numeral: '^2.0.6',
|
|
250
|
+
oracledb: '^6.6.0',
|
|
251
|
+
papaparse: '^5.5.1',
|
|
252
|
+
pdfkit: '^0.14.0',
|
|
253
|
+
pdfmake: '^0.2.20',
|
|
254
|
+
soap: '^1.1.11',
|
|
255
|
+
'ssh2-sftp-client': '^11.0.0',
|
|
256
|
+
'strong-soap': '^4.1.13',
|
|
257
|
+
'ts-node': '^10.9.2',
|
|
258
|
+
typescript: '^5.5.4',
|
|
259
|
+
undici: '^6.19.8',
|
|
260
|
+
uuid: '^11.1.0',
|
|
261
|
+
winston: '^3.17.0',
|
|
262
|
+
xlsx: 'https://cdn.sheetjs.com/xlsx-0.20.3/xlsx-0.20.3.tgz',
|
|
263
|
+
'xml-crypto': '^6.1.2',
|
|
264
|
+
},
|
|
265
|
+
devDependencies: {
|
|
266
|
+
'@types/draft-js': '^0.11.18',
|
|
267
|
+
'@types/heapdump': '^0.3.4',
|
|
268
|
+
'@types/mssql': '^9.1.5',
|
|
269
|
+
'@types/node': '^18.19.50',
|
|
270
|
+
'@types/node-fetch': '^2.6.11',
|
|
271
|
+
'@types/numeral': '^2.0.5',
|
|
272
|
+
'@types/oracledb': '^6.5.3',
|
|
273
|
+
'@types/papaparse': '^5.3.15',
|
|
274
|
+
'@types/pdfmake': '^0.2.11',
|
|
275
|
+
'@types/soap': '^0.18.0',
|
|
276
|
+
'@types/ssh2-sftp-client': '^9.0.4',
|
|
277
|
+
'@types/tough-cookie': '^4.0.5',
|
|
278
|
+
'@types/uuid': '^10.0.0',
|
|
279
|
+
'@types/xmldom': '^0.1.34',
|
|
280
|
+
'ts-node': '^10.9.2',
|
|
281
|
+
typescript: '^5.5.4',
|
|
282
|
+
},
|
|
283
|
+
};
|
|
284
|
+
fs.writeFileSync(packageJsonPath, JSON.stringify(packageJson, null, 2), 'utf-8');
|
|
285
|
+
logger_1.logger.dim(`Created package.json for ${tenant}`);
|
|
286
|
+
}
|
|
@@ -0,0 +1,235 @@
|
|
|
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;
|
|
17
|
+
});
|
|
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
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
36
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
37
|
+
};
|
|
38
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
39
|
+
exports.registerPushCommand = registerPushCommand;
|
|
40
|
+
const chalk_1 = __importDefault(require("chalk"));
|
|
41
|
+
const inquirer_1 = __importDefault(require("inquirer"));
|
|
42
|
+
const logger_1 = require("../utils/logger");
|
|
43
|
+
const farseerFactory_1 = require("../services/farseerFactory");
|
|
44
|
+
const syncService_1 = require("../services/syncService");
|
|
45
|
+
const appSyncService_1 = require("../services/appSyncService");
|
|
46
|
+
const helpers_1 = require("../utils/helpers");
|
|
47
|
+
const fs = __importStar(require("fs"));
|
|
48
|
+
function registerPushCommand(program) {
|
|
49
|
+
program
|
|
50
|
+
.command('push [org] [tenant]')
|
|
51
|
+
.description('Push local files to Farseer instance\n\nUsage: push <org> <tenant> OR push <tenant> (if org is known)')
|
|
52
|
+
.option('--force', 'Force push even if remote has changes')
|
|
53
|
+
.option('-y, --yes', 'Skip confirmation prompt (auto-confirm)')
|
|
54
|
+
.action(async (arg1, arg2, options) => {
|
|
55
|
+
const { organisation, tenant } = (0, helpers_1.resolveTenantWithOrgMapping)(arg1, arg2);
|
|
56
|
+
const clientResult = await (0, farseerFactory_1.getFarseerClientWithFallback)(organisation, tenant);
|
|
57
|
+
if (!clientResult) {
|
|
58
|
+
(0, farseerFactory_1.showLoginPrompt)(tenant);
|
|
59
|
+
process.exit(1);
|
|
60
|
+
}
|
|
61
|
+
const filesDir = (0, helpers_1.getTenantFilesDir)(tenant);
|
|
62
|
+
if (!fs.existsSync(filesDir)) {
|
|
63
|
+
logger_1.logger.error(`Local folder not found: farseer-apps/${tenant}/files/`);
|
|
64
|
+
logger_1.logger.dim('Run "farseer pull <tenant>" first to initialize the folder.');
|
|
65
|
+
process.exit(1);
|
|
66
|
+
}
|
|
67
|
+
const syncService = new syncService_1.SyncService(tenant, clientResult.client);
|
|
68
|
+
// Step 1: Check if remote has unpulled changes
|
|
69
|
+
if (!options.force) {
|
|
70
|
+
logger_1.logger.info('Checking for remote changes...');
|
|
71
|
+
const hasRemoteChanges = await syncService.checkRemoteChanges();
|
|
72
|
+
if (hasRemoteChanges) {
|
|
73
|
+
logger_1.logger.error('Remote has changes that are not synced locally.');
|
|
74
|
+
logger_1.logger.dim(`Run 'farseer pull ${tenant}' first, then try pushing again.`);
|
|
75
|
+
logger_1.logger.dim('Or use --force to push anyway (will overwrite remote changes).');
|
|
76
|
+
process.exit(1);
|
|
77
|
+
}
|
|
78
|
+
logger_1.logger.dim('Remote is in sync.');
|
|
79
|
+
}
|
|
80
|
+
// Step 2: Show what will be pushed (using fast status check that doesn't download remote content)
|
|
81
|
+
const status = await syncService.getStatusFast();
|
|
82
|
+
const filesToPush = [...status.modifiedLocally, ...status.onlyLocal];
|
|
83
|
+
const filesToDelete = status.modifiedRemotely.filter((f) => !fs.existsSync(`${filesDir}/${f}`));
|
|
84
|
+
// Check app changes too
|
|
85
|
+
let appStatus = {
|
|
86
|
+
newLocal: [],
|
|
87
|
+
modified: [],
|
|
88
|
+
newRemote: [],
|
|
89
|
+
synced: [],
|
|
90
|
+
};
|
|
91
|
+
const appSyncService = new appSyncService_1.AppSyncService(tenant, clientResult.client);
|
|
92
|
+
appStatus = await appSyncService.getStatus();
|
|
93
|
+
const hasFileChanges = filesToPush.length > 0 || filesToDelete.length > 0;
|
|
94
|
+
const hasAppChanges = appStatus.newLocal.length > 0 || appStatus.modified.length > 0;
|
|
95
|
+
if (!hasFileChanges && !hasAppChanges) {
|
|
96
|
+
logger_1.logger.success('Nothing to push. Everything is in sync.');
|
|
97
|
+
return;
|
|
98
|
+
}
|
|
99
|
+
console.log();
|
|
100
|
+
logger_1.logger.header('Changes to push:');
|
|
101
|
+
if (filesToPush.length > 0) {
|
|
102
|
+
for (const file of filesToPush) {
|
|
103
|
+
const isNew = status.onlyLocal.includes(file);
|
|
104
|
+
if (isNew) {
|
|
105
|
+
console.log(chalk_1.default.green(` + ${file}`));
|
|
106
|
+
}
|
|
107
|
+
else {
|
|
108
|
+
console.log(chalk_1.default.yellow(` M ${file}`));
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
if (filesToDelete.length > 0) {
|
|
113
|
+
for (const file of filesToDelete) {
|
|
114
|
+
console.log(chalk_1.default.red(` - ${file}`));
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
// Show app changes
|
|
118
|
+
if (appStatus.newLocal.length > 0) {
|
|
119
|
+
console.log(chalk_1.default.green('New apps:'));
|
|
120
|
+
for (const app of appStatus.newLocal) {
|
|
121
|
+
console.log(chalk_1.default.green(` + ${app}`));
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
if (appStatus.modified.length > 0) {
|
|
125
|
+
console.log(chalk_1.default.yellow('Modified apps:'));
|
|
126
|
+
for (const app of appStatus.modified) {
|
|
127
|
+
console.log(chalk_1.default.yellow(` ~ ${app}`));
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
console.log();
|
|
131
|
+
const totalChanges = filesToPush.length + filesToDelete.length + appStatus.newLocal.length + appStatus.modified.length;
|
|
132
|
+
// Step 3: Confirm push (skip if --yes flag is set)
|
|
133
|
+
if (!options.yes) {
|
|
134
|
+
const confirm = await inquirer_1.default.prompt([
|
|
135
|
+
{
|
|
136
|
+
type: 'confirm',
|
|
137
|
+
name: 'proceed',
|
|
138
|
+
message: `Push ${totalChanges} change(s) to ${tenant}?`,
|
|
139
|
+
default: true,
|
|
140
|
+
},
|
|
141
|
+
]);
|
|
142
|
+
if (!confirm.proceed) {
|
|
143
|
+
logger_1.logger.info('Push cancelled.');
|
|
144
|
+
return;
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
// Ensure token is fresh before push operations (may have expired during user input)
|
|
148
|
+
await (0, farseerFactory_1.ensureFreshToken)(clientResult.client);
|
|
149
|
+
try {
|
|
150
|
+
// Step 4: Push files only if there are file changes
|
|
151
|
+
let result = { uploaded: [], updated: [], deleted: [], unchanged: [] };
|
|
152
|
+
if (hasFileChanges) {
|
|
153
|
+
logger_1.logger.info(`Pushing files to ${tenant}...`);
|
|
154
|
+
result = await syncService.push({ force: options.force });
|
|
155
|
+
console.log();
|
|
156
|
+
if (result.conflicts && result.conflicts.length > 0) {
|
|
157
|
+
console.log(chalk_1.default.red.bold(`${result.conflicts.length} conflict(s) detected:`));
|
|
158
|
+
console.log();
|
|
159
|
+
for (const conflict of result.conflicts) {
|
|
160
|
+
console.log(chalk_1.default.red(` ! ${conflict.filePath}`));
|
|
161
|
+
console.log(chalk_1.default.dim(` ${conflict.description}`));
|
|
162
|
+
}
|
|
163
|
+
console.log();
|
|
164
|
+
logger_1.logger.dim(`Resolve conflicts by pulling first: farseer pull ${tenant}`);
|
|
165
|
+
logger_1.logger.dim('Or use --force to push anyway (may overwrite remote changes).');
|
|
166
|
+
console.log();
|
|
167
|
+
}
|
|
168
|
+
if (result.uploaded.length > 0) {
|
|
169
|
+
console.log(chalk_1.default.green('Uploaded files (new):'));
|
|
170
|
+
for (const file of result.uploaded) {
|
|
171
|
+
console.log(chalk_1.default.green(` + ${file}`));
|
|
172
|
+
}
|
|
173
|
+
console.log();
|
|
174
|
+
}
|
|
175
|
+
if (result.updated.length > 0) {
|
|
176
|
+
console.log(chalk_1.default.yellow('Updated files:'));
|
|
177
|
+
for (const file of result.updated) {
|
|
178
|
+
console.log(chalk_1.default.yellow(` M ${file}`));
|
|
179
|
+
}
|
|
180
|
+
console.log();
|
|
181
|
+
}
|
|
182
|
+
if (result.deleted.length > 0) {
|
|
183
|
+
console.log(chalk_1.default.red('Deleted files:'));
|
|
184
|
+
for (const file of result.deleted) {
|
|
185
|
+
console.log(chalk_1.default.red(` - ${file}`));
|
|
186
|
+
}
|
|
187
|
+
console.log();
|
|
188
|
+
}
|
|
189
|
+
}
|
|
190
|
+
// Step 5: Push apps only if there are app changes
|
|
191
|
+
let appResult = {
|
|
192
|
+
created: [],
|
|
193
|
+
updated: [],
|
|
194
|
+
deleted: [],
|
|
195
|
+
unchanged: [],
|
|
196
|
+
};
|
|
197
|
+
if (hasAppChanges) {
|
|
198
|
+
logger_1.logger.info(`Pushing apps to ${tenant}...`);
|
|
199
|
+
appResult = await appSyncService.push();
|
|
200
|
+
if (appResult.created.length > 0) {
|
|
201
|
+
console.log(chalk_1.default.green('Created apps:'));
|
|
202
|
+
for (const app of appResult.created) {
|
|
203
|
+
console.log(chalk_1.default.green(` + ${app}`));
|
|
204
|
+
}
|
|
205
|
+
console.log();
|
|
206
|
+
}
|
|
207
|
+
if (appResult.updated.length > 0) {
|
|
208
|
+
console.log(chalk_1.default.yellow('Updated apps:'));
|
|
209
|
+
for (const app of appResult.updated) {
|
|
210
|
+
console.log(chalk_1.default.yellow(` ~ ${app}`));
|
|
211
|
+
}
|
|
212
|
+
console.log();
|
|
213
|
+
}
|
|
214
|
+
if (appResult.deleted.length > 0) {
|
|
215
|
+
console.log(chalk_1.default.red('Deleted apps:'));
|
|
216
|
+
for (const app of appResult.deleted) {
|
|
217
|
+
console.log(chalk_1.default.red(` - ${app}`));
|
|
218
|
+
}
|
|
219
|
+
console.log();
|
|
220
|
+
}
|
|
221
|
+
}
|
|
222
|
+
console.log();
|
|
223
|
+
logger_1.logger.success('Push complete!');
|
|
224
|
+
logger_1.logger.dim(`Files: +${result.uploaded.length} ~${result.updated.length} -${result.deleted.length}`);
|
|
225
|
+
logger_1.logger.dim(`Apps: +${appResult.created.length} ~${appResult.updated.length} -${appResult.deleted.length}`);
|
|
226
|
+
}
|
|
227
|
+
catch (error) {
|
|
228
|
+
logger_1.logger.error('Push failed.');
|
|
229
|
+
if (error instanceof Error) {
|
|
230
|
+
logger_1.logger.dim(error.message);
|
|
231
|
+
}
|
|
232
|
+
process.exit(1);
|
|
233
|
+
}
|
|
234
|
+
});
|
|
235
|
+
}
|