farseer-cli 1.0.5 → 1.0.6
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/checkout.js +1 -26
- package/dist/commands/checkout.js.map +2 -2
- package/dist/commands/pull.js +2 -77
- package/dist/commands/pull.js.map +2 -2
- package/dist/commands/push.js +14 -64
- package/dist/commands/push.js.map +2 -2
- package/dist/index.js +24 -13
- package/dist/index.js.map +2 -2
- package/dist/mcp/tools/modelTools.js +19 -21
- package/dist/mcp/tools/modelTools.js.map +2 -2
- package/dist/mcp/tools/syncTools.js +58 -59
- package/dist/mcp/tools/syncTools.js.map +2 -2
- package/dist/mcp/utils/helpers.js +22 -0
- package/dist/mcp/utils/helpers.js.map +2 -2
- package/dist/utils/constants.js +1 -4
- package/dist/utils/constants.js.map +2 -2
- package/dist/utils/helpers.js +0 -20
- package/dist/utils/helpers.js.map +2 -2
- package/package.json +2 -3
- package/dist/services/gitService.js +0 -134
- package/dist/services/gitService.js.map +0 -7
|
@@ -36,13 +36,11 @@ var import_configService = require("../services/configService");
|
|
|
36
36
|
var import_farseerFactory = require("../services/farseerFactory");
|
|
37
37
|
var import_syncService = require("../services/syncService");
|
|
38
38
|
var import_appSyncService = require("../services/appSyncService");
|
|
39
|
-
var import_gitService = require("../services/gitService");
|
|
40
39
|
var import_helpers = require("../utils/helpers");
|
|
41
|
-
var import_constants = require("../utils/constants");
|
|
42
40
|
var fs = __toESM(require("fs"));
|
|
43
41
|
var path = __toESM(require("path"));
|
|
44
42
|
function registerCheckoutCommand(program) {
|
|
45
|
-
program.command("checkout [first] [second]").description("Set default tenant for commands (runs auth check and pull)").option("--no-pull", "Skip automatic pull").option("--
|
|
43
|
+
program.command("checkout [first] [second]").description("Set default tenant for commands (runs auth check and pull)").option("--no-pull", "Skip automatic pull").option("--clear", "Clear current checkout").action(async (first, second, options) => {
|
|
46
44
|
if (options.clear) {
|
|
47
45
|
(0, import_configService.clearCurrentTenant)();
|
|
48
46
|
import_logger.logger.success("Checkout cleared. You now need to specify tenant for each command.");
|
|
@@ -81,18 +79,10 @@ function registerCheckoutCommand(program) {
|
|
|
81
79
|
if (options.pull) {
|
|
82
80
|
console.log();
|
|
83
81
|
import_logger.logger.info("Pulling latest files and apps...");
|
|
84
|
-
const gitService = new import_gitService.GitService();
|
|
85
82
|
const syncService = new import_syncService.SyncService(tenant, clientResult.client);
|
|
86
83
|
const tenantDir = (0, import_helpers.getTenantDir)(tenant);
|
|
87
84
|
(0, import_helpers.ensureDirectoryExists)(tenantDir);
|
|
88
|
-
const gitEnabled = options.git && !process.env.FARSEER_NO_GIT;
|
|
89
85
|
try {
|
|
90
|
-
if (gitEnabled) {
|
|
91
|
-
const gitPullResult = await gitService.pull();
|
|
92
|
-
if (!gitPullResult.success) {
|
|
93
|
-
import_logger.logger.warning("Git pull failed: " + gitPullResult.message);
|
|
94
|
-
}
|
|
95
|
-
}
|
|
96
86
|
const packageJsonPath = path.join(tenantDir, "package.json");
|
|
97
87
|
if (!fs.existsSync(packageJsonPath)) {
|
|
98
88
|
createDefaultPackageJson(tenant, packageJsonPath);
|
|
@@ -102,21 +92,6 @@ function registerCheckoutCommand(program) {
|
|
|
102
92
|
const appSyncService = new import_appSyncService.AppSyncService(tenant, clientResult.client);
|
|
103
93
|
const appResult = await appSyncService.pull();
|
|
104
94
|
import_logger.logger.dim(`Apps: +${appResult.created.length} ~${appResult.updated.length} -${appResult.deleted.length} (${appResult.unchanged.length} unchanged)`);
|
|
105
|
-
if (gitEnabled) {
|
|
106
|
-
const hasChanges = result.downloaded.length > 0 || result.deleted.length > 0 || appResult.created.length > 0 || appResult.updated.length > 0 || appResult.deleted.length > 0;
|
|
107
|
-
if (hasChanges) {
|
|
108
|
-
const appsPath = `apps/${tenant}`;
|
|
109
|
-
await gitService.add([appsPath]);
|
|
110
|
-
const commitMessage = `[${tenant}] Checkout sync
|
|
111
|
-
|
|
112
|
-
Files: +${result.downloaded.length} -${result.deleted.length}
|
|
113
|
-
Apps: +${appResult.created.length} ~${appResult.updated.length} -${appResult.deleted.length}
|
|
114
|
-
|
|
115
|
-
\u{1F916} Generated with Farseer CLI`;
|
|
116
|
-
await gitService.commit(commitMessage, import_constants.CLI_GIT_AUTHOR);
|
|
117
|
-
await gitService.push();
|
|
118
|
-
}
|
|
119
|
-
}
|
|
120
95
|
import_logger.logger.success("Pull complete!");
|
|
121
96
|
} catch (error) {
|
|
122
97
|
import_logger.logger.warning("Pull failed, but checkout is complete.");
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../src/commands/checkout.ts"],
|
|
4
|
-
"sourcesContent": ["import { Command } from 'commander';\nimport chalk from 'chalk';\nimport { logger } from '../utils/logger';\nimport { getCurrentCheckout, setCurrentCheckout, clearCurrentTenant
|
|
5
|
-
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AACA,mBAAkB;AAClB,oBAAuB;AACvB,
|
|
4
|
+
"sourcesContent": ["import { Command } from 'commander';\nimport chalk from 'chalk';\nimport { logger } from '../utils/logger';\nimport { getCurrentCheckout, setCurrentCheckout, clearCurrentTenant } from '../services/configService';\nimport { getFarseerClientWithFallback, showLoginPrompt } from '../services/farseerFactory';\nimport { SyncService } from '../services/syncService';\nimport { AppSyncService } from '../services/appSyncService';\nimport { getTenantDir, ensureDirectoryExists } from '../utils/helpers';\nimport * as fs from 'fs';\nimport * as path from 'path';\n\nexport function registerCheckoutCommand(program: Command): void {\n program\n .command('checkout [first] [second]')\n .description('Set default tenant for commands (runs auth check and pull)')\n .option('--no-pull', 'Skip automatic pull')\n .option('--clear', 'Clear current checkout')\n .action(async (first, second, options) => {\n // Handle --clear flag\n if (options.clear) {\n clearCurrentTenant();\n logger.success('Checkout cleared. You now need to specify tenant for each command.');\n return;\n }\n\n // If no arguments specified, show current checkout status\n if (!first) {\n const current = getCurrentCheckout();\n if (current) {\n if (current.organisation === current.tenant) {\n logger.info(`Currently checked out: ${chalk.bold(current.tenant)}`);\n } else {\n logger.info(`Currently checked out: ${chalk.bold(current.tenant)} (org: ${chalk.bold(current.organisation)})`);\n }\n logger.dim('Run \"farseer checkout <tenant>\" to switch tenants.');\n logger.dim('Run \"farseer checkout --clear\" to clear checkout.');\n } else {\n logger.info('No tenant currently checked out.');\n logger.dim('Run \"farseer checkout <tenant>\" to set a default tenant.');\n logger.dim('Run \"farseer checkout <org> <tenant>\" if organisation and tenant differ.');\n }\n return;\n }\n\n // Determine organisation and tenant\n // If two arguments: first=organisation, second=tenant\n // If one argument: organisation=tenant=first\n const organisation = second ? first : first;\n const tenant = second || first;\n\n logger.info(`Checking out tenant: ${chalk.bold(tenant)} (org: ${chalk.bold(organisation)})...`);\n console.log();\n\n // Step 1: Verify authentication\n logger.info('Verifying authentication...');\n const clientResult = await getFarseerClientWithFallback(organisation, tenant);\n\n if (!clientResult) {\n showLoginPrompt(tenant);\n process.exit(1);\n }\n\n const authLabel = clientResult.authType === 'apiKey' ? 'API key' : 'browser login';\n logger.success(`Authenticated (using ${authLabel})`);\n\n // Step 2: Set as current checkout\n setCurrentCheckout(organisation, tenant);\n\n // Step 3: Auto-pull (unless --no-pull)\n if (options.pull) {\n console.log();\n logger.info('Pulling latest files and apps...');\n\n const syncService = new SyncService(tenant, clientResult.client);\n const tenantDir = getTenantDir(tenant);\n ensureDirectoryExists(tenantDir);\n\n try {\n // Ensure package.json exists\n const packageJsonPath = path.join(tenantDir, 'package.json');\n if (!fs.existsSync(packageJsonPath)) {\n createDefaultPackageJson(tenant, packageJsonPath);\n }\n\n // Pull files (scripts only by default)\n const result = await syncService.pull({ all: false });\n logger.dim(`Files: +${result.downloaded.length} -${result.deleted.length} (${result.unchanged.length} unchanged)`);\n\n // Pull apps\n const appSyncService = new AppSyncService(tenant, clientResult.client);\n const appResult = await appSyncService.pull();\n logger.dim(`Apps: +${appResult.created.length} ~${appResult.updated.length} -${appResult.deleted.length} (${appResult.unchanged.length} unchanged)`);\n\n logger.success('Pull complete!');\n } catch (error) {\n logger.warning('Pull failed, but checkout is complete.');\n if (error instanceof Error) {\n logger.dim(error.message);\n }\n }\n }\n\n // Final message\n console.log();\n logger.success(`Tenant ${chalk.bold(tenant)} is now checked out.`);\n logger.dim('You can now run commands without specifying the tenant:');\n logger.dim(' farseer status');\n logger.dim(' farseer model --variables');\n logger.dim(' farseer apps');\n logger.dim(' farseer push');\n });\n}\n\nfunction createDefaultPackageJson(tenant: string, packageJsonPath: string): void {\n const packageJson = {\n name: `farseer-${tenant}`,\n version: '1.0.0',\n description: `Farseer scripts for ${tenant}`,\n type: 'module',\n scripts: {\n build: 'tsc',\n },\n dependencies: {\n 'farseer-client': 'https://storage.googleapis.com/farseer-remote-jobs-results/farseer-client/release-1.4.5.tar',\n arquero: '^7.0.1',\n xlsx: '^0.18.5',\n xmldom: '^0.6.0',\n },\n devDependencies: {\n '@types/node': '^22.5.0',\n '@types/xmldom': '^0.1.34',\n 'ts-node': '^10.9.2',\n typescript: '^5.5.4',\n },\n };\n\n fs.writeFileSync(packageJsonPath, JSON.stringify(packageJson, null, 2), 'utf-8');\n logger.dim(`Created package.json for ${tenant}`);\n}\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AACA,mBAAkB;AAClB,oBAAuB;AACvB,2BAA2E;AAC3E,4BAA8D;AAC9D,yBAA4B;AAC5B,4BAA+B;AAC/B,qBAAoD;AACpD,SAAoB;AACpB,WAAsB;AAEf,SAAS,wBAAwB,SAAwB;AAC5D,UACK,QAAQ,2BAA2B,EACnC,YAAY,4DAA4D,EACxE,OAAO,aAAa,qBAAqB,EACzC,OAAO,WAAW,wBAAwB,EAC1C,OAAO,OAAO,OAAO,QAAQ,YAAY;AAEtC,QAAI,QAAQ,OAAO;AACf,mDAAmB;AACnB,2BAAO,QAAQ,oEAAoE;AACnF;AAAA,IACJ;AAGA,QA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AA,IAChB;AAAA,EACJ;AAEA,KAAG,cAAc,iBAAiB,KAAK,UAAU,aAAa,MAAM,CAAC,GAAG,OAAO;AAC/E,uBAAO,IAAI,4BAA4B,MAAM,EAAE;AACnD;",
|
|
6
6
|
"names": ["chalk"]
|
|
7
7
|
}
|
package/dist/commands/pull.js
CHANGED
|
@@ -35,35 +35,16 @@ var import_logger = require("../utils/logger");
|
|
|
35
35
|
var import_farseerFactory = require("../services/farseerFactory");
|
|
36
36
|
var import_syncService = require("../services/syncService");
|
|
37
37
|
var import_appSyncService = require("../services/appSyncService");
|
|
38
|
-
var import_gitService = require("../services/gitService");
|
|
39
38
|
var import_helpers = require("../utils/helpers");
|
|
40
|
-
var import_constants = require("../utils/constants");
|
|
41
39
|
function registerPullCommand(program) {
|
|
42
|
-
program.command("pull [arg1] [arg2]").description("Pull files from Farseer instance to local\n\nUsage: pull <org> <tenant> OR pull <tenant> (if org is known)").option("--
|
|
40
|
+
program.command("pull [arg1] [arg2]").description("Pull files from Farseer instance to local\n\nUsage: pull <org> <tenant> OR pull <tenant> (if org is known)").option("--all", "Pull all files (default: only scripts .ts, .js)").action(async (arg1, arg2, options) => {
|
|
43
41
|
const { organisation, tenant } = (0, import_helpers.resolveTenantWithOrgMapping)(arg1, arg2);
|
|
44
42
|
const clientResult = await (0, import_farseerFactory.getFarseerClientWithFallback)(organisation, tenant);
|
|
45
43
|
if (!clientResult) {
|
|
46
44
|
(0, import_farseerFactory.showLoginPrompt)(tenant);
|
|
47
45
|
process.exit(1);
|
|
48
46
|
}
|
|
49
|
-
const gitService = new import_gitService.GitService();
|
|
50
47
|
const syncService = new import_syncService.SyncService(tenant, clientResult.client);
|
|
51
|
-
const inRemotejobsRepo = (0, import_helpers.isInRemotejobsRepo)();
|
|
52
|
-
const gitEnabled = options.git === true && inRemotejobsRepo && !process.env.FARSEER_NO_GIT;
|
|
53
|
-
if (options.git === true && !inRemotejobsRepo) {
|
|
54
|
-
import_logger.logger.error("Git operations are only available in remotejobs repository.");
|
|
55
|
-
process.exit(1);
|
|
56
|
-
}
|
|
57
|
-
if (gitEnabled) {
|
|
58
|
-
import_logger.logger.info("Pulling latest changes from git...");
|
|
59
|
-
const gitPullResult = await gitService.pull();
|
|
60
|
-
if (!gitPullResult.success) {
|
|
61
|
-
import_logger.logger.error("Git pull failed.");
|
|
62
|
-
import_logger.logger.dim(gitPullResult.message);
|
|
63
|
-
process.exit(1);
|
|
64
|
-
}
|
|
65
|
-
import_logger.logger.dim(gitPullResult.message);
|
|
66
|
-
}
|
|
67
48
|
const tenantDir = (0, import_helpers.getTenantDir)(tenant);
|
|
68
49
|
(0, import_helpers.ensureDirectoryExists)(tenantDir);
|
|
69
50
|
await createDefaultPackageJson(tenantDir, tenant);
|
|
@@ -123,63 +104,7 @@ function registerPullCommand(program) {
|
|
|
123
104
|
}
|
|
124
105
|
import_logger.logger.dim(`Apps: +${appResult.created.length} ~${appResult.updated.length} -${appResult.deleted.length} (${appResult.unchanged.length} unchanged)`);
|
|
125
106
|
hasChanges = hasChanges || appResult.created.length > 0 || appResult.updated.length > 0 || appResult.deleted.length > 0;
|
|
126
|
-
if (
|
|
127
|
-
const appsPath = `apps/${tenant}`;
|
|
128
|
-
const gitStatus = await gitService.status();
|
|
129
|
-
const hasUncommittedChanges = gitStatus.modified.some((f) => f.startsWith(appsPath)) || gitStatus.added.some((f) => f.startsWith(appsPath)) || gitStatus.deleted.some((f) => f.startsWith(appsPath)) || gitStatus.untracked.some((f) => f.startsWith(appsPath));
|
|
130
|
-
if (hasChanges || hasUncommittedChanges) {
|
|
131
|
-
import_logger.logger.info("Committing changes to git...");
|
|
132
|
-
await gitService.add([appsPath]);
|
|
133
|
-
const syncState = syncService.loadSyncState();
|
|
134
|
-
let commitMessage = `Sync with remote ${tenant}
|
|
135
|
-
|
|
136
|
-
`;
|
|
137
|
-
if (result.downloaded.length > 0) {
|
|
138
|
-
commitMessage += "Modified files:\n";
|
|
139
|
-
for (const file of result.downloaded) {
|
|
140
|
-
const metadata = syncState.files[file]?.metadata;
|
|
141
|
-
const author = metadata?.uploaderName || metadata?.uploaderEmail || "Unknown";
|
|
142
|
-
commitMessage += `- ${file} (${author})
|
|
143
|
-
`;
|
|
144
|
-
}
|
|
145
|
-
}
|
|
146
|
-
if (result.deleted.length > 0) {
|
|
147
|
-
commitMessage += "\nDeleted files:\n";
|
|
148
|
-
result.deleted.forEach((f) => commitMessage += `- ${f}
|
|
149
|
-
`);
|
|
150
|
-
}
|
|
151
|
-
if (appResult.created.length > 0 || appResult.updated.length > 0) {
|
|
152
|
-
commitMessage += "\nModified apps:\n";
|
|
153
|
-
appResult.created.forEach((a) => commitMessage += `- ${a} (new)
|
|
154
|
-
`);
|
|
155
|
-
appResult.updated.forEach((a) => commitMessage += `- ${a} (updated)
|
|
156
|
-
`);
|
|
157
|
-
}
|
|
158
|
-
if (appResult.deleted.length > 0) {
|
|
159
|
-
commitMessage += "\nDeleted apps:\n";
|
|
160
|
-
appResult.deleted.forEach((a) => commitMessage += `- ${a}
|
|
161
|
-
`);
|
|
162
|
-
}
|
|
163
|
-
const commitResult = await gitService.commit(commitMessage, import_constants.CLI_GIT_AUTHOR);
|
|
164
|
-
if (commitResult.success) {
|
|
165
|
-
import_logger.logger.dim(`Committed: ${commitResult.commitHash}`);
|
|
166
|
-
import_logger.logger.info("Pushing to remote...");
|
|
167
|
-
const pushResult = await gitService.push();
|
|
168
|
-
if (pushResult.success) {
|
|
169
|
-
import_logger.logger.dim(pushResult.message);
|
|
170
|
-
} else {
|
|
171
|
-
import_logger.logger.warning("Failed to push to remote.");
|
|
172
|
-
import_logger.logger.dim(pushResult.message);
|
|
173
|
-
import_logger.logger.dim("You may need to push manually.");
|
|
174
|
-
}
|
|
175
|
-
} else {
|
|
176
|
-
import_logger.logger.warning("Nothing to commit.");
|
|
177
|
-
}
|
|
178
|
-
} else {
|
|
179
|
-
import_logger.logger.success("Already up to date (no changes to commit).");
|
|
180
|
-
return;
|
|
181
|
-
}
|
|
182
|
-
} else if (!hasChanges) {
|
|
107
|
+
if (!hasChanges) {
|
|
183
108
|
import_logger.logger.success("Already up to date.");
|
|
184
109
|
return;
|
|
185
110
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../src/commands/pull.ts"],
|
|
4
|
-
"sourcesContent": ["import { Command } from 'commander';\nimport chalk from 'chalk';\nimport { logger } from '../utils/logger';\nimport { getFarseerClientWithFallback, showLoginPrompt } from '../services/farseerFactory';\nimport { SyncService } from '../services/syncService';\nimport { AppSyncService } from '../services/appSyncService';\nimport { GitService } from '../services/gitService';\nimport { getTenantDir, ensureDirectoryExists, resolveTenantWithOrgMapping, isInRemotejobsRepo, appendToAuditLog, AuditLogEntry } from '../utils/helpers';\nimport { CLI_GIT_AUTHOR } from '../utils/constants';\n\nexport function registerPullCommand(program: Command): void {\n program\n .command('pull [arg1] [arg2]')\n .description('Pull files from Farseer instance to local\\n\\nUsage: pull <org> <tenant> OR pull <tenant> (if org is known)')\n .option('--git', 'Enable git operations (commit & push) - internal use only')\n .option('--all', 'Pull all files (default: only scripts .ts, .js)')\n .action(async (arg1, arg2, options) => {\n const { organisation, tenant } = resolveTenantWithOrgMapping(arg1, arg2);\n const clientResult = await getFarseerClientWithFallback(organisation, tenant);\n\n if (!clientResult) {\n showLoginPrompt(tenant);\n process.exit(1);\n }\n\n const gitService = new GitService();\n const syncService = new SyncService(tenant, clientResult.client);\n\n // Git operations are opt-in with --git flag (internal developer feature)\n const inRemotejobsRepo = isInRemotejobsRepo();\n\n // Git enabled ONLY if:\n // 1. User explicitly requested it (--git flag)\n // 2. We're in remotejobs repo (safety check)\n // 3. FARSEER_NO_GIT env var is not set\n const gitEnabled = options.git === true && inRemotejobsRepo && !process.env.FARSEER_NO_GIT;\n\n // Show error if --git requested but not in remotejobs repo\n if (options.git === true && !inRemotejobsRepo) {\n logger.error('Git operations are only available in remotejobs repository.');\n process.exit(1);\n }\n\n // Step 1: Git pull\n if (gitEnabled) {\n logger.info('Pulling latest changes from git...');\n const gitPullResult = await gitService.pull();\n\n if (!gitPullResult.success) {\n logger.error('Git pull failed.');\n logger.dim(gitPullResult.message);\n process.exit(1);\n }\n\n logger.dim(gitPullResult.message);\n }\n\n // Step 2: Ensure tenant folder exists\n const tenantDir = getTenantDir(tenant);\n ensureDirectoryExists(tenantDir);\n\n // Create default package.json if it doesn't exist\n await createDefaultPackageJson(tenantDir, tenant);\n\n // Step 3: Pull files from Farseer\n console.log();\n console.log(chalk.bold('\u2550\u2550\u2550 Files \u2550\u2550\u2550'));\n logger.info(`Pulling files from ${tenant}...`);\n\n try {\n const result = await syncService.pull({ all: options.all });\n\n if (result.downloaded.length > 0) {\n console.log(chalk.green('Downloaded:'));\n for (const file of result.downloaded) {\n console.log(chalk.green(` + ${file}`));\n }\n }\n\n if (result.deleted.length > 0) {\n console.log(chalk.red('Deleted (removed from remote):'));\n for (const file of result.deleted) {\n console.log(chalk.red(` - ${file}`));\n }\n }\n\n logger.dim(`Files: +${result.downloaded.length} -${result.deleted.length} (${result.unchanged.length} unchanged)`);\n\n // Create audit log entries for downloaded files\n if (result.downloaded.length > 0) {\n const syncState = syncService.loadSyncState();\n const auditEntries: AuditLogEntry[] = result.downloaded.map(filePath => ({\n operation: 'pulled' as const,\n filePath,\n uploadTime: syncState.files[filePath]?.metadata?.uploadTime,\n uploaderEmail: syncState.files[filePath]?.metadata?.uploaderEmail,\n uploaderName: syncState.files[filePath]?.metadata?.uploaderName,\n }));\n\n appendToAuditLog(tenant, auditEntries);\n }\n\n let hasChanges = result.downloaded.length > 0 || result.deleted.length > 0;\n\n // Step 4: Pull apps (works with both JWT and API key)\n let appResult = { created: [] as string[], updated: [] as string[], deleted: [] as string[], unchanged: [] as string[] };\n\n console.log();\n console.log(chalk.bold('\u2550\u2550\u2550 Apps \u2550\u2550\u2550'));\n logger.info(`Pulling apps from ${tenant}...`);\n\n const appSyncService = new AppSyncService(tenant, clientResult.client);\n appResult = await appSyncService.pull();\n\n if (appResult.created.length > 0) {\n console.log(chalk.green('New apps:'));\n for (const app of appResult.created) {\n console.log(chalk.green(` + ${app}`));\n }\n }\n\n if (appResult.updated.length > 0) {\n console.log(chalk.yellow('Updated apps:'));\n for (const app of appResult.updated) {\n console.log(chalk.yellow(` ~ ${app}`));\n }\n }\n\n if (appResult.deleted.length > 0) {\n console.log(chalk.red('Deleted apps (removed from remote):'));\n for (const app of appResult.deleted) {\n console.log(chalk.red(` - ${app}`));\n }\n }\n\n logger.dim(`Apps: +${appResult.created.length} ~${appResult.updated.length} -${appResult.deleted.length} (${appResult.unchanged.length} unchanged)`);\n\n hasChanges = hasChanges || appResult.created.length > 0 || appResult.updated.length > 0 || appResult.deleted.length > 0;\n\n // Step 5: Git commit & push\n if (gitEnabled) {\n const appsPath = `apps/${tenant}`;\n\n // Check for any uncommitted changes (including from previous pulls without --git)\n const gitStatus = await gitService.status();\n const hasUncommittedChanges =\n gitStatus.modified.some(f => f.startsWith(appsPath)) ||\n gitStatus.added.some(f => f.startsWith(appsPath)) ||\n gitStatus.deleted.some(f => f.startsWith(appsPath)) ||\n gitStatus.untracked.some(f => f.startsWith(appsPath));\n\n if (hasChanges || hasUncommittedChanges) {\n logger.info('Committing changes to git...');\n\n await gitService.add([appsPath]);\n\n // Build detailed commit message with metadata\n const syncState = syncService.loadSyncState();\n let commitMessage = `Sync with remote ${tenant}\\n\\n`;\n\n if (result.downloaded.length > 0) {\n commitMessage += 'Modified files:\\n';\n for (const file of result.downloaded) {\n const metadata = syncState.files[file]?.metadata;\n const author = metadata?.uploaderName || metadata?.uploaderEmail || 'Unknown';\n commitMessage += `- ${file} (${author})\\n`;\n }\n }\n\n if (result.deleted.length > 0) {\n commitMessage += '\\nDeleted files:\\n';\n result.deleted.forEach(f => commitMessage += `- ${f}\\n`);\n }\n\n if (appResult.created.length > 0 || appResult.updated.length > 0) {\n commitMessage += '\\nModified apps:\\n';\n appResult.created.forEach(a => commitMessage += `- ${a} (new)\\n`);\n appResult.updated.forEach(a => commitMessage += `- ${a} (updated)\\n`);\n }\n\n if (appResult.deleted.length > 0) {\n commitMessage += '\\nDeleted apps:\\n';\n appResult.deleted.forEach(a => commitMessage += `- ${a}\\n`);\n }\n\n const commitResult = await gitService.commit(commitMessage, CLI_GIT_AUTHOR);\n\n if (commitResult.success) {\n logger.dim(`Committed: ${commitResult.commitHash}`);\n\n logger.info('Pushing to remote...');\n const pushResult = await gitService.push();\n\n if (pushResult.success) {\n logger.dim(pushResult.message);\n } else {\n logger.warning('Failed to push to remote.');\n logger.dim(pushResult.message);\n logger.dim('You may need to push manually.');\n }\n } else {\n logger.warning('Nothing to commit.');\n }\n } else {\n logger.success('Already up to date (no changes to commit).');\n return;\n }\n } else if (!hasChanges) {\n logger.success('Already up to date.');\n return;\n }\n\n console.log();\n console.log(chalk.bold('\u2550\u2550\u2550 Summary \u2550\u2550\u2550'));\n logger.success('Pull complete!');\n logger.dim(`Files: +${result.downloaded.length} -${result.deleted.length} (${result.unchanged.length} unchanged)`);\n logger.dim(`Apps: +${appResult.created.length} ~${appResult.updated.length} -${appResult.deleted.length} (${appResult.unchanged.length} unchanged)`);\n } catch (error) {\n logger.error('Pull failed.');\n if (error instanceof Error) {\n logger.dim(error.message);\n }\n process.exit(1);\n }\n });\n}\n\nasync function createDefaultPackageJson(tenantDir: string, tenant: string): Promise<void> {\n const fs = await import('fs');\n const path = await import('path');\n\n const packageJsonPath = path.join(tenantDir, 'package.json');\n\n if (fs.existsSync(packageJsonPath)) {\n return;\n }\n\n const packageJson = {\n name: `farseer-scripts-${tenant}`,\n version: '1.0.0',\n description: `Farseer App scripts for ${tenant}`,\n main: 'src/index.ts',\n scripts: {},\n keywords: ['farseer', 'scripts', tenant],\n author: 'Farseer',\n license: 'ISC',\n dependencies: {\n '@google-cloud/bigquery': '^7.9.0',\n '@google-cloud/storage': '^7.12.1',\n '@googleapis/sheets': '^5.0.5',\n '@sendgrid/mail': '^7.7.0',\n '@types/node-forge': '^1.3.11',\n '@xmldom/xmldom': '^0.9.8',\n 'arquero': '^5.4.1',\n 'axios': '^1.10.0',\n 'axios-retry': '^3.9.1',\n 'basic-ftp': '^5.0.5',\n 'client-oauth2': '^4.3.3',\n 'csv-parser': '^3.0.0',\n 'dotenv': '^16.4.5',\n 'draft-js': '^0.11.7',\n 'exceljs': '^4.4.0',\n 'farseer-client': 'https://storage.googleapis.com/farseer-remote-jobs-results/farseer-client/release-1.4.5.tar',\n 'farseer-client-axios': 'https://storage.googleapis.com/farseer-remote-jobs-results/farseer-client-axios/6898c0cb-5dca-4b2f-b325-119efc7f099e/v1.0.1.tar',\n 'fast-xml-parser': '^4.5.0',\n 'form-data': '^4.0.0',\n 'googleapis': '^144.0.0',\n 'heapdump': '^0.3.15',\n 'image-size': '^1.1.1',\n 'jszip': '^3.10.1',\n 'lossless-json': '^4.0.1',\n 'mssql': '^10.0.4',\n 'node-fetch': '^2.7.0',\n 'node-forge': '^1.3.1',\n 'node-sp-auth': '^3.0.8',\n 'numeral': '^2.0.6',\n 'oracledb': '^6.6.0',\n 'papaparse': '^5.5.1',\n 'pdfkit': '^0.14.0',\n 'pdfmake': '^0.2.20',\n 'soap': '^1.1.11',\n 'ssh2-sftp-client': '^11.0.0',\n 'strong-soap': '^4.1.13',\n 'ts-node': '^10.9.2',\n 'typescript': '^5.5.4',\n 'undici': '^6.19.8',\n 'uuid': '^11.1.0',\n 'winston': '^3.17.0',\n 'xlsx': 'https://cdn.sheetjs.com/xlsx-0.20.3/xlsx-0.20.3.tgz',\n 'xml-crypto': '^6.1.2',\n },\n devDependencies: {\n '@types/draft-js': '^0.11.18',\n '@types/heapdump': '^0.3.4',\n '@types/mssql': '^9.1.5',\n '@types/node': '^18.19.50',\n '@types/node-fetch': '^2.6.11',\n '@types/numeral': '^2.0.5',\n '@types/oracledb': '^6.5.3',\n '@types/papaparse': '^5.3.15',\n '@types/pdfmake': '^0.2.11',\n '@types/soap': '^0.18.0',\n '@types/ssh2-sftp-client': '^9.0.4',\n '@types/tough-cookie': '^4.0.5',\n '@types/uuid': '^10.0.0',\n '@types/xmldom': '^0.1.34',\n 'ts-node': '^10.9.2',\n 'typescript': '^5.5.4',\n },\n };\n\n fs.writeFileSync(packageJsonPath, JSON.stringify(packageJson, null, 2), 'utf-8');\n logger.dim(`Created package.json for ${tenant}`);\n}\n"],
|
|
5
|
-
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AACA,mBAAkB;AAClB,oBAAuB;AACvB,4BAA8D;AAC9D,yBAA4B;AAC5B,4BAA+B;AAC/B,
|
|
4
|
+
"sourcesContent": ["import { Command } from 'commander';\nimport chalk from 'chalk';\nimport { logger } from '../utils/logger';\nimport { getFarseerClientWithFallback, showLoginPrompt } from '../services/farseerFactory';\nimport { SyncService } from '../services/syncService';\nimport { AppSyncService } from '../services/appSyncService';\nimport { getTenantDir, ensureDirectoryExists, resolveTenantWithOrgMapping, appendToAuditLog, AuditLogEntry } from '../utils/helpers';\n\nexport function registerPullCommand(program: Command): void {\n program\n .command('pull [arg1] [arg2]')\n .description('Pull files from Farseer instance to local\\n\\nUsage: pull <org> <tenant> OR pull <tenant> (if org is known)')\n .option('--all', 'Pull all files (default: only scripts .ts, .js)')\n .action(async (arg1, arg2, options) => {\n const { organisation, tenant } = resolveTenantWithOrgMapping(arg1, arg2);\n const clientResult = await getFarseerClientWithFallback(organisation, tenant);\n\n if (!clientResult) {\n showLoginPrompt(tenant);\n process.exit(1);\n }\n\n const syncService = new SyncService(tenant, clientResult.client);\n\n // Step 1: Ensure tenant folder exists\n const tenantDir = getTenantDir(tenant);\n ensureDirectoryExists(tenantDir);\n\n // Create default package.json if it doesn't exist\n await createDefaultPackageJson(tenantDir, tenant);\n\n // Step 2: Pull files from Farseer\n console.log();\n console.log(chalk.bold('\u2550\u2550\u2550 Files \u2550\u2550\u2550'));\n logger.info(`Pulling files from ${tenant}...`);\n\n try {\n const result = await syncService.pull({ all: options.all });\n\n if (result.downloaded.length > 0) {\n console.log(chalk.green('Downloaded:'));\n for (const file of result.downloaded) {\n console.log(chalk.green(` + ${file}`));\n }\n }\n\n if (result.deleted.length > 0) {\n console.log(chalk.red('Deleted (removed from remote):'));\n for (const file of result.deleted) {\n console.log(chalk.red(` - ${file}`));\n }\n }\n\n logger.dim(`Files: +${result.downloaded.length} -${result.deleted.length} (${result.unchanged.length} unchanged)`);\n\n // Create audit log entries for downloaded files\n if (result.downloaded.length > 0) {\n const syncState = syncService.loadSyncState();\n const auditEntries: AuditLogEntry[] = result.downloaded.map(filePath => ({\n operation: 'pulled' as const,\n filePath,\n uploadTime: syncState.files[filePath]?.metadata?.uploadTime,\n uploaderEmail: syncState.files[filePath]?.metadata?.uploaderEmail,\n uploaderName: syncState.files[filePath]?.metadata?.uploaderName,\n }));\n\n appendToAuditLog(tenant, auditEntries);\n }\n\n let hasChanges = result.downloaded.length > 0 || result.deleted.length > 0;\n\n // Step 3: Pull apps\n let appResult = { created: [] as string[], updated: [] as string[], deleted: [] as string[], unchanged: [] as string[] };\n\n console.log();\n console.log(chalk.bold('\u2550\u2550\u2550 Apps \u2550\u2550\u2550'));\n logger.info(`Pulling apps from ${tenant}...`);\n\n const appSyncService = new AppSyncService(tenant, clientResult.client);\n appResult = await appSyncService.pull();\n\n if (appResult.created.length > 0) {\n console.log(chalk.green('New apps:'));\n for (const app of appResult.created) {\n console.log(chalk.green(` + ${app}`));\n }\n }\n\n if (appResult.updated.length > 0) {\n console.log(chalk.yellow('Updated apps:'));\n for (const app of appResult.updated) {\n console.log(chalk.yellow(` ~ ${app}`));\n }\n }\n\n if (appResult.deleted.length > 0) {\n console.log(chalk.red('Deleted apps (removed from remote):'));\n for (const app of appResult.deleted) {\n console.log(chalk.red(` - ${app}`));\n }\n }\n\n logger.dim(`Apps: +${appResult.created.length} ~${appResult.updated.length} -${appResult.deleted.length} (${appResult.unchanged.length} unchanged)`);\n\n hasChanges = hasChanges || appResult.created.length > 0 || appResult.updated.length > 0 || appResult.deleted.length > 0;\n\n if (!hasChanges) {\n logger.success('Already up to date.');\n return;\n }\n\n console.log();\n console.log(chalk.bold('\u2550\u2550\u2550 Summary \u2550\u2550\u2550'));\n logger.success('Pull complete!');\n logger.dim(`Files: +${result.downloaded.length} -${result.deleted.length} (${result.unchanged.length} unchanged)`);\n logger.dim(`Apps: +${appResult.created.length} ~${appResult.updated.length} -${appResult.deleted.length} (${appResult.unchanged.length} unchanged)`);\n } catch (error) {\n logger.error('Pull failed.');\n if (error instanceof Error) {\n logger.dim(error.message);\n }\n process.exit(1);\n }\n });\n}\n\nasync function createDefaultPackageJson(tenantDir: string, tenant: string): Promise<void> {\n const fs = await import('fs');\n const path = await import('path');\n\n const packageJsonPath = path.join(tenantDir, 'package.json');\n\n if (fs.existsSync(packageJsonPath)) {\n return;\n }\n\n const packageJson = {\n name: `farseer-scripts-${tenant}`,\n version: '1.0.0',\n description: `Farseer App scripts for ${tenant}`,\n main: 'src/index.ts',\n scripts: {},\n keywords: ['farseer', 'scripts', tenant],\n author: 'Farseer',\n license: 'ISC',\n dependencies: {\n '@google-cloud/bigquery': '^7.9.0',\n '@google-cloud/storage': '^7.12.1',\n '@googleapis/sheets': '^5.0.5',\n '@sendgrid/mail': '^7.7.0',\n '@types/node-forge': '^1.3.11',\n '@xmldom/xmldom': '^0.9.8',\n 'arquero': '^5.4.1',\n 'axios': '^1.10.0',\n 'axios-retry': '^3.9.1',\n 'basic-ftp': '^5.0.5',\n 'client-oauth2': '^4.3.3',\n 'csv-parser': '^3.0.0',\n 'dotenv': '^16.4.5',\n 'draft-js': '^0.11.7',\n 'exceljs': '^4.4.0',\n 'farseer-client': 'https://storage.googleapis.com/farseer-remote-jobs-results/farseer-client/release-1.4.5.tar',\n 'farseer-client-axios': 'https://storage.googleapis.com/farseer-remote-jobs-results/farseer-client-axios/6898c0cb-5dca-4b2f-b325-119efc7f099e/v1.0.1.tar',\n 'fast-xml-parser': '^4.5.0',\n 'form-data': '^4.0.0',\n 'googleapis': '^144.0.0',\n 'heapdump': '^0.3.15',\n 'image-size': '^1.1.1',\n 'jszip': '^3.10.1',\n 'lossless-json': '^4.0.1',\n 'mssql': '^10.0.4',\n 'node-fetch': '^2.7.0',\n 'node-forge': '^1.3.1',\n 'node-sp-auth': '^3.0.8',\n 'numeral': '^2.0.6',\n 'oracledb': '^6.6.0',\n 'papaparse': '^5.5.1',\n 'pdfkit': '^0.14.0',\n 'pdfmake': '^0.2.20',\n 'soap': '^1.1.11',\n 'ssh2-sftp-client': '^11.0.0',\n 'strong-soap': '^4.1.13',\n 'ts-node': '^10.9.2',\n 'typescript': '^5.5.4',\n 'undici': '^6.19.8',\n 'uuid': '^11.1.0',\n 'winston': '^3.17.0',\n 'xlsx': 'https://cdn.sheetjs.com/xlsx-0.20.3/xlsx-0.20.3.tgz',\n 'xml-crypto': '^6.1.2',\n },\n devDependencies: {\n '@types/draft-js': '^0.11.18',\n '@types/heapdump': '^0.3.4',\n '@types/mssql': '^9.1.5',\n '@types/node': '^18.19.50',\n '@types/node-fetch': '^2.6.11',\n '@types/numeral': '^2.0.5',\n '@types/oracledb': '^6.5.3',\n '@types/papaparse': '^5.3.15',\n '@types/pdfmake': '^0.2.11',\n '@types/soap': '^0.18.0',\n '@types/ssh2-sftp-client': '^9.0.4',\n '@types/tough-cookie': '^4.0.5',\n '@types/uuid': '^10.0.0',\n '@types/xmldom': '^0.1.34',\n 'ts-node': '^10.9.2',\n 'typescript': '^5.5.4',\n },\n };\n\n fs.writeFileSync(packageJsonPath, JSON.stringify(packageJson, null, 2), 'utf-8');\n logger.dim(`Created package.json for ${tenant}`);\n}\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AACA,mBAAkB;AAClB,oBAAuB;AACvB,4BAA8D;AAC9D,yBAA4B;AAC5B,4BAA+B;AAC/B,qBAAkH;AAE3G,SAAS,oBAAoB,SAAwB;AACxD,UACK,QAAQ,oBA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AAO,IAAI,4BAA4B,MAAM,EAAE;AACnD;",
|
|
6
6
|
"names": ["chalk"]
|
|
7
7
|
}
|
package/dist/commands/push.js
CHANGED
|
@@ -36,12 +36,10 @@ var import_logger = require("../utils/logger");
|
|
|
36
36
|
var import_farseerFactory = require("../services/farseerFactory");
|
|
37
37
|
var import_syncService = require("../services/syncService");
|
|
38
38
|
var import_appSyncService = require("../services/appSyncService");
|
|
39
|
-
var import_gitService = require("../services/gitService");
|
|
40
39
|
var import_helpers = require("../utils/helpers");
|
|
41
|
-
var import_constants = require("../utils/constants");
|
|
42
40
|
var fs = __toESM(require("fs"));
|
|
43
41
|
function registerPushCommand(program) {
|
|
44
|
-
program.command("push [arg1] [arg2]").description("Push local files to Farseer instance\n\nUsage: push <org> <tenant> OR push <tenant> (if org is known)").option("--
|
|
42
|
+
program.command("push [arg1] [arg2]").description("Push local files to Farseer instance\n\nUsage: push <org> <tenant> OR push <tenant> (if org is known)").option("--force", "Force push even if remote has changes").option("-y, --yes", "Skip confirmation prompt (auto-confirm)").action(async (arg1, arg2, options) => {
|
|
45
43
|
const { organisation, tenant } = (0, import_helpers.resolveTenantWithOrgMapping)(arg1, arg2);
|
|
46
44
|
const clientResult = await (0, import_farseerFactory.getFarseerClientWithFallback)(organisation, tenant);
|
|
47
45
|
if (!clientResult) {
|
|
@@ -50,34 +48,11 @@ function registerPushCommand(program) {
|
|
|
50
48
|
}
|
|
51
49
|
const filesDir = (0, import_helpers.getTenantFilesDir)(tenant);
|
|
52
50
|
if (!fs.existsSync(filesDir)) {
|
|
53
|
-
import_logger.logger.error(`Local folder not found: apps/${tenant}/files/`);
|
|
51
|
+
import_logger.logger.error(`Local folder not found: farseer-apps/${tenant}/files/`);
|
|
54
52
|
import_logger.logger.dim('Run "farseer pull <tenant>" first to initialize the folder.');
|
|
55
53
|
process.exit(1);
|
|
56
54
|
}
|
|
57
|
-
const inRemotejobsRepo = (0, import_helpers.isInRemotejobsRepo)();
|
|
58
|
-
const gitDisabledByEnv = !!process.env.FARSEER_NO_GIT;
|
|
59
|
-
const gitEnabled = options.git === true && inRemotejobsRepo && !gitDisabledByEnv;
|
|
60
|
-
if (options.git === true && !inRemotejobsRepo) {
|
|
61
|
-
import_logger.logger.error("Git operations are only available in remotejobs repository.");
|
|
62
|
-
process.exit(1);
|
|
63
|
-
}
|
|
64
|
-
if (gitEnabled && !options.message) {
|
|
65
|
-
import_logger.logger.error("Commit message is required when using git.");
|
|
66
|
-
import_logger.logger.dim('Use: farseer push <tenant> --git -m "Your message"');
|
|
67
|
-
process.exit(1);
|
|
68
|
-
}
|
|
69
|
-
const gitService = new import_gitService.GitService();
|
|
70
55
|
const syncService = new import_syncService.SyncService(tenant, clientResult.client);
|
|
71
|
-
if (gitEnabled) {
|
|
72
|
-
import_logger.logger.info("Pulling latest changes from git...");
|
|
73
|
-
const gitPullResult = await gitService.pull();
|
|
74
|
-
if (!gitPullResult.success) {
|
|
75
|
-
import_logger.logger.error("Git pull failed.");
|
|
76
|
-
import_logger.logger.dim(gitPullResult.message);
|
|
77
|
-
process.exit(1);
|
|
78
|
-
}
|
|
79
|
-
import_logger.logger.dim(gitPullResult.message);
|
|
80
|
-
}
|
|
81
56
|
if (!options.force) {
|
|
82
57
|
import_logger.logger.info("Checking for remote changes...");
|
|
83
58
|
const hasRemoteChanges = await syncService.checkRemoteChanges();
|
|
@@ -137,17 +112,19 @@ function registerPushCommand(program) {
|
|
|
137
112
|
}
|
|
138
113
|
console.log();
|
|
139
114
|
const totalChanges = filesToPush.length + filesToDelete.length + appStatus.newLocal.length + appStatus.modified.length;
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
115
|
+
if (!options.yes) {
|
|
116
|
+
const confirm = await import_inquirer.default.prompt([
|
|
117
|
+
{
|
|
118
|
+
type: "confirm",
|
|
119
|
+
name: "proceed",
|
|
120
|
+
message: `Push ${totalChanges} change(s) to ${tenant}?`,
|
|
121
|
+
default: true
|
|
122
|
+
}
|
|
123
|
+
]);
|
|
124
|
+
if (!confirm.proceed) {
|
|
125
|
+
import_logger.logger.info("Push cancelled.");
|
|
126
|
+
return;
|
|
146
127
|
}
|
|
147
|
-
]);
|
|
148
|
-
if (!confirm.proceed) {
|
|
149
|
-
import_logger.logger.info("Push cancelled.");
|
|
150
|
-
return;
|
|
151
128
|
}
|
|
152
129
|
await (0, import_farseerFactory.ensureFreshToken)(clientResult.client);
|
|
153
130
|
try {
|
|
@@ -204,33 +181,6 @@ function registerPushCommand(program) {
|
|
|
204
181
|
console.log();
|
|
205
182
|
}
|
|
206
183
|
}
|
|
207
|
-
if (gitEnabled) {
|
|
208
|
-
import_logger.logger.info("Committing changes to git...");
|
|
209
|
-
const appsPath = `apps/${tenant}`;
|
|
210
|
-
await gitService.add([appsPath]);
|
|
211
|
-
const commitMessage = `[${tenant}] ${options.message}
|
|
212
|
-
|
|
213
|
-
Files: +${result.uploaded.length} ~${result.updated.length} -${result.deleted.length}
|
|
214
|
-
Apps: +${appResult.created.length} ~${appResult.updated.length} -${appResult.deleted.length}
|
|
215
|
-
|
|
216
|
-
\u{1F916} Generated with Farseer CLI`;
|
|
217
|
-
const commitResult = await gitService.commit(commitMessage, import_constants.CLI_GIT_AUTHOR);
|
|
218
|
-
if (commitResult.success) {
|
|
219
|
-
import_logger.logger.dim(`Committed: ${commitResult.commitHash}`);
|
|
220
|
-
import_logger.logger.info("Pushing to git remote...");
|
|
221
|
-
const pushResult = await gitService.push();
|
|
222
|
-
if (pushResult.success) {
|
|
223
|
-
import_logger.logger.dim(pushResult.message);
|
|
224
|
-
} else {
|
|
225
|
-
import_logger.logger.warning("Failed to push to git remote.");
|
|
226
|
-
import_logger.logger.dim(pushResult.message);
|
|
227
|
-
import_logger.logger.dim("You may need to push manually.");
|
|
228
|
-
}
|
|
229
|
-
} else {
|
|
230
|
-
import_logger.logger.warning("Failed to commit changes.");
|
|
231
|
-
import_logger.logger.dim(commitResult.message);
|
|
232
|
-
}
|
|
233
|
-
}
|
|
234
184
|
console.log();
|
|
235
185
|
import_logger.logger.success("Push complete!");
|
|
236
186
|
import_logger.logger.dim(`Files: +${result.uploaded.length} ~${result.updated.length} -${result.deleted.length}`);
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../src/commands/push.ts"],
|
|
4
|
-
"sourcesContent": ["import { Command } from 'commander';\nimport chalk from 'chalk';\nimport inquirer from 'inquirer';\nimport { logger } from '../utils/logger';\nimport { getFarseerClientWithFallback, showLoginPrompt, ensureFreshToken } from '../services/farseerFactory';\nimport { SyncService } from '../services/syncService';\nimport { AppSyncService } from '../services/appSyncService';\nimport { GitService } from '../services/gitService';\nimport { getTenantFilesDir, resolveTenantWithOrgMapping, isInRemotejobsRepo } from '../utils/helpers';\nimport { CLI_GIT_AUTHOR } from '../utils/constants';\nimport * as fs from 'fs';\n\nexport function registerPushCommand(program: Command): void {\n program\n .command('push [arg1] [arg2]')\n .description('Push local files to Farseer instance\\n\\nUsage: push <org> <tenant> OR push <tenant> (if org is known)')\n .option('--git', 'Enable git operations (commit & push) - internal use only')\n .option('-m, --message <message>', 'Commit message (required when using --git)')\n .option('--force', 'Force push even if remote has changes')\n .action(async (arg1, arg2, options) => {\n const { organisation, tenant } = resolveTenantWithOrgMapping(arg1, arg2);\n const clientResult = await getFarseerClientWithFallback(organisation, tenant);\n\n if (!clientResult) {\n showLoginPrompt(tenant);\n process.exit(1);\n }\n\n const filesDir = getTenantFilesDir(tenant);\n\n if (!fs.existsSync(filesDir)) {\n logger.error(`Local folder not found: apps/${tenant}/files/`);\n logger.dim('Run \"farseer pull <tenant>\" first to initialize the folder.');\n process.exit(1);\n }\n\n // Git operations are opt-in with --git flag (internal developer feature)\n const inRemotejobsRepo = isInRemotejobsRepo();\n const gitDisabledByEnv = !!process.env.FARSEER_NO_GIT;\n\n // Git enabled ONLY if:\n // 1. User explicitly requested it (--git flag)\n // 2. We're in remotejobs repo (safety check)\n // 3. FARSEER_NO_GIT env var is not set\n const gitEnabled = options.git === true && inRemotejobsRepo && !gitDisabledByEnv;\n\n // Show error if --git requested but not in remotejobs repo\n if (options.git === true && !inRemotejobsRepo) {\n logger.error('Git operations are only available in remotejobs repository.');\n process.exit(1);\n }\n\n // Validate message is provided when using git\n if (gitEnabled && !options.message) {\n logger.error('Commit message is required when using git.');\n logger.dim('Use: farseer push <tenant> --git -m \"Your message\"');\n process.exit(1);\n }\n\n const gitService = new GitService();\n const syncService = new SyncService(tenant, clientResult.client);\n\n // Step 1: Git pull to ensure we're up to date\n if (gitEnabled) {\n logger.info('Pulling latest changes from git...');\n const gitPullResult = await gitService.pull();\n\n if (!gitPullResult.success) {\n logger.error('Git pull failed.');\n logger.dim(gitPullResult.message);\n process.exit(1);\n }\n\n logger.dim(gitPullResult.message);\n }\n\n // Step 2: Check if remote has unpulled changes\n if (!options.force) {\n logger.info('Checking for remote changes...');\n\n const hasRemoteChanges = await syncService.checkRemoteChanges();\n\n if (hasRemoteChanges) {\n logger.error('Remote has changes that are not synced locally.');\n logger.dim(`Run 'farseer pull ${tenant}' first, then try pushing again.`);\n logger.dim('Or use --force to push anyway (will overwrite remote changes).');\n process.exit(1);\n }\n\n logger.dim('Remote is in sync.');\n }\n\n // Step 3: Show what will be pushed (using fast status check that doesn't download remote content)\n const status = await syncService.getStatusFast();\n\n const filesToPush = [\n ...status.modifiedLocally,\n ...status.onlyLocal,\n ];\n\n const filesToDelete = status.modifiedRemotely.filter((f) =>\n !fs.existsSync(`${filesDir}/${f}`)\n );\n\n // Check app changes too (works with both JWT and API key)\n let appStatus = { newLocal: [] as string[], modified: [] as string[], newRemote: [] as string[], synced: [] as string[] };\n const appSyncService = new AppSyncService(tenant, clientResult.client);\n appStatus = await appSyncService.getStatus();\n\n const hasFileChanges = filesToPush.length > 0 || filesToDelete.length > 0;\n const hasAppChanges = appStatus.newLocal.length > 0 || appStatus.modified.length > 0;\n\n if (!hasFileChanges && !hasAppChanges) {\n logger.success('Nothing to push. Everything is in sync.');\n return;\n }\n\n console.log();\n logger.header('Changes to push:');\n\n if (filesToPush.length > 0) {\n for (const file of filesToPush) {\n const isNew = status.onlyLocal.includes(file);\n if (isNew) {\n console.log(chalk.green(` + ${file}`));\n } else {\n console.log(chalk.yellow(` M ${file}`));\n }\n }\n }\n\n if (filesToDelete.length > 0) {\n for (const file of filesToDelete) {\n console.log(chalk.red(` - ${file}`));\n }\n }\n\n // Show app changes\n if (appStatus.newLocal.length > 0) {\n console.log(chalk.green('New apps:'));\n for (const app of appStatus.newLocal) {\n console.log(chalk.green(` + ${app}`));\n }\n }\n\n if (appStatus.modified.length > 0) {\n console.log(chalk.yellow('Modified apps:'));\n for (const app of appStatus.modified) {\n console.log(chalk.yellow(` ~ ${app}`));\n }\n }\n\n console.log();\n\n const totalChanges = filesToPush.length + filesToDelete.length + appStatus.newLocal.length + appStatus.modified.length;\n\n // Step 4: Confirm push\n const confirm = await inquirer.prompt([\n {\n type: 'confirm',\n name: 'proceed',\n message: `Push ${totalChanges} change(s) to ${tenant}?`,\n default: true,\n },\n ]);\n\n if (!confirm.proceed) {\n logger.info('Push cancelled.');\n return;\n }\n\n // Ensure token is fresh before push operations (may have expired during user input)\n await ensureFreshToken(clientResult.client);\n\n try {\n // Step 5: Push files only if there are file changes\n let result = { uploaded: [] as string[], updated: [] as string[], deleted: [] as string[], unchanged: [] as string[] };\n\n if (hasFileChanges) {\n logger.info(`Pushing files to ${tenant}...`);\n result = await syncService.push();\n\n console.log();\n\n if (result.uploaded.length > 0) {\n console.log(chalk.green('Uploaded files (new):'));\n for (const file of result.uploaded) {\n console.log(chalk.green(` + ${file}`));\n }\n console.log();\n }\n\n if (result.updated.length > 0) {\n console.log(chalk.yellow('Updated files:'));\n for (const file of result.updated) {\n console.log(chalk.yellow(` M ${file}`));\n }\n console.log();\n }\n\n if (result.deleted.length > 0) {\n console.log(chalk.red('Deleted files:'));\n for (const file of result.deleted) {\n console.log(chalk.red(` - ${file}`));\n }\n console.log();\n }\n }\n\n // Step 6: Push apps only if there are app changes\n let appResult = { created: [] as string[], updated: [] as string[], deleted: [] as string[], unchanged: [] as string[] };\n\n if (hasAppChanges) {\n logger.info(`Pushing apps to ${tenant}...`);\n appResult = await appSyncService.push();\n\n if (appResult.created.length > 0) {\n console.log(chalk.green('Created apps:'));\n for (const app of appResult.created) {\n console.log(chalk.green(` + ${app}`));\n }\n console.log();\n }\n\n if (appResult.updated.length > 0) {\n console.log(chalk.yellow('Updated apps:'));\n for (const app of appResult.updated) {\n console.log(chalk.yellow(` ~ ${app}`));\n }\n console.log();\n }\n\n if (appResult.deleted.length > 0) {\n console.log(chalk.red('Deleted apps:'));\n for (const app of appResult.deleted) {\n console.log(chalk.red(` - ${app}`));\n }\n console.log();\n }\n }\n\n // Step 7: Git commit & push\n if (gitEnabled) {\n logger.info('Committing changes to git...');\n\n const appsPath = `apps/${tenant}`;\n await gitService.add([appsPath]);\n\n const commitMessage = `[${tenant}] ${options.message}\n\nFiles: +${result.uploaded.length} ~${result.updated.length} -${result.deleted.length}\nApps: +${appResult.created.length} ~${appResult.updated.length} -${appResult.deleted.length}\n\n\uD83E\uDD16 Generated with Farseer CLI`;\n\n const commitResult = await gitService.commit(commitMessage, CLI_GIT_AUTHOR);\n\n if (commitResult.success) {\n logger.dim(`Committed: ${commitResult.commitHash}`);\n\n logger.info('Pushing to git remote...');\n const pushResult = await gitService.push();\n\n if (pushResult.success) {\n logger.dim(pushResult.message);\n } else {\n logger.warning('Failed to push to git remote.');\n logger.dim(pushResult.message);\n logger.dim('You may need to push manually.');\n }\n } else {\n logger.warning('Failed to commit changes.');\n logger.dim(commitResult.message);\n }\n }\n\n console.log();\n logger.success('Push complete!');\n logger.dim(`Files: +${result.uploaded.length} ~${result.updated.length} -${result.deleted.length}`);\n logger.dim(`Apps: +${appResult.created.length} ~${appResult.updated.length} -${appResult.deleted.length}`);\n } catch (error) {\n logger.error('Push failed.');\n if (error instanceof Error) {\n logger.dim(error.message);\n }\n process.exit(1);\n }\n });\n}\n"],
|
|
5
|
-
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AACA,mBAAkB;AAClB,sBAAqB;AACrB,oBAAuB;AACvB,4BAAgF;AAChF,yBAA4B;AAC5B,4BAA+B;AAC/B,
|
|
4
|
+
"sourcesContent": ["import { Command } from 'commander';\nimport chalk from 'chalk';\nimport inquirer from 'inquirer';\nimport { logger } from '../utils/logger';\nimport { getFarseerClientWithFallback, showLoginPrompt, ensureFreshToken } from '../services/farseerFactory';\nimport { SyncService } from '../services/syncService';\nimport { AppSyncService } from '../services/appSyncService';\nimport { getTenantFilesDir, resolveTenantWithOrgMapping } from '../utils/helpers';\nimport * as fs from 'fs';\n\nexport function registerPushCommand(program: Command): void {\n program\n .command('push [arg1] [arg2]')\n .description('Push local files to Farseer instance\\n\\nUsage: push <org> <tenant> OR push <tenant> (if org is known)')\n .option('--force', 'Force push even if remote has changes')\n .option('-y, --yes', 'Skip confirmation prompt (auto-confirm)')\n .action(async (arg1, arg2, options) => {\n const { organisation, tenant } = resolveTenantWithOrgMapping(arg1, arg2);\n const clientResult = await getFarseerClientWithFallback(organisation, tenant);\n\n if (!clientResult) {\n showLoginPrompt(tenant);\n process.exit(1);\n }\n\n const filesDir = getTenantFilesDir(tenant);\n\n if (!fs.existsSync(filesDir)) {\n logger.error(`Local folder not found: farseer-apps/${tenant}/files/`);\n logger.dim('Run \"farseer pull <tenant>\" first to initialize the folder.');\n process.exit(1);\n }\n\n const syncService = new SyncService(tenant, clientResult.client);\n\n // Step 1: Check if remote has unpulled changes\n if (!options.force) {\n logger.info('Checking for remote changes...');\n\n const hasRemoteChanges = await syncService.checkRemoteChanges();\n\n if (hasRemoteChanges) {\n logger.error('Remote has changes that are not synced locally.');\n logger.dim(`Run 'farseer pull ${tenant}' first, then try pushing again.`);\n logger.dim('Or use --force to push anyway (will overwrite remote changes).');\n process.exit(1);\n }\n\n logger.dim('Remote is in sync.');\n }\n\n // Step 2: Show what will be pushed (using fast status check that doesn't download remote content)\n const status = await syncService.getStatusFast();\n\n const filesToPush = [\n ...status.modifiedLocally,\n ...status.onlyLocal,\n ];\n\n const filesToDelete = status.modifiedRemotely.filter((f) =>\n !fs.existsSync(`${filesDir}/${f}`)\n );\n\n // Check app changes too\n let appStatus = { newLocal: [] as string[], modified: [] as string[], newRemote: [] as string[], synced: [] as string[] };\n const appSyncService = new AppSyncService(tenant, clientResult.client);\n appStatus = await appSyncService.getStatus();\n\n const hasFileChanges = filesToPush.length > 0 || filesToDelete.length > 0;\n const hasAppChanges = appStatus.newLocal.length > 0 || appStatus.modified.length > 0;\n\n if (!hasFileChanges && !hasAppChanges) {\n logger.success('Nothing to push. Everything is in sync.');\n return;\n }\n\n console.log();\n logger.header('Changes to push:');\n\n if (filesToPush.length > 0) {\n for (const file of filesToPush) {\n const isNew = status.onlyLocal.includes(file);\n if (isNew) {\n console.log(chalk.green(` + ${file}`));\n } else {\n console.log(chalk.yellow(` M ${file}`));\n }\n }\n }\n\n if (filesToDelete.length > 0) {\n for (const file of filesToDelete) {\n console.log(chalk.red(` - ${file}`));\n }\n }\n\n // Show app changes\n if (appStatus.newLocal.length > 0) {\n console.log(chalk.green('New apps:'));\n for (const app of appStatus.newLocal) {\n console.log(chalk.green(` + ${app}`));\n }\n }\n\n if (appStatus.modified.length > 0) {\n console.log(chalk.yellow('Modified apps:'));\n for (const app of appStatus.modified) {\n console.log(chalk.yellow(` ~ ${app}`));\n }\n }\n\n console.log();\n\n const totalChanges = filesToPush.length + filesToDelete.length + appStatus.newLocal.length + appStatus.modified.length;\n\n // Step 3: Confirm push (skip if --yes flag is set)\n if (!options.yes) {\n const confirm = await inquirer.prompt([\n {\n type: 'confirm',\n name: 'proceed',\n message: `Push ${totalChanges} change(s) to ${tenant}?`,\n default: true,\n },\n ]);\n\n if (!confirm.proceed) {\n logger.info('Push cancelled.');\n return;\n }\n }\n\n // Ensure token is fresh before push operations (may have expired during user input)\n await ensureFreshToken(clientResult.client);\n\n try {\n // Step 4: Push files only if there are file changes\n let result = { uploaded: [] as string[], updated: [] as string[], deleted: [] as string[], unchanged: [] as string[] };\n\n if (hasFileChanges) {\n logger.info(`Pushing files to ${tenant}...`);\n result = await syncService.push();\n\n console.log();\n\n if (result.uploaded.length > 0) {\n console.log(chalk.green('Uploaded files (new):'));\n for (const file of result.uploaded) {\n console.log(chalk.green(` + ${file}`));\n }\n console.log();\n }\n\n if (result.updated.length > 0) {\n console.log(chalk.yellow('Updated files:'));\n for (const file of result.updated) {\n console.log(chalk.yellow(` M ${file}`));\n }\n console.log();\n }\n\n if (result.deleted.length > 0) {\n console.log(chalk.red('Deleted files:'));\n for (const file of result.deleted) {\n console.log(chalk.red(` - ${file}`));\n }\n console.log();\n }\n }\n\n // Step 5: Push apps only if there are app changes\n let appResult = { created: [] as string[], updated: [] as string[], deleted: [] as string[], unchanged: [] as string[] };\n\n if (hasAppChanges) {\n logger.info(`Pushing apps to ${tenant}...`);\n appResult = await appSyncService.push();\n\n if (appResult.created.length > 0) {\n console.log(chalk.green('Created apps:'));\n for (const app of appResult.created) {\n console.log(chalk.green(` + ${app}`));\n }\n console.log();\n }\n\n if (appResult.updated.length > 0) {\n console.log(chalk.yellow('Updated apps:'));\n for (const app of appResult.updated) {\n console.log(chalk.yellow(` ~ ${app}`));\n }\n console.log();\n }\n\n if (appResult.deleted.length > 0) {\n console.log(chalk.red('Deleted apps:'));\n for (const app of appResult.deleted) {\n console.log(chalk.red(` - ${app}`));\n }\n console.log();\n }\n }\n\n console.log();\n logger.success('Push complete!');\n logger.dim(`Files: +${result.uploaded.length} ~${result.updated.length} -${result.deleted.length}`);\n logger.dim(`Apps: +${appResult.created.length} ~${appResult.updated.length} -${appResult.deleted.length}`);\n } catch (error) {\n logger.error('Push failed.');\n if (error instanceof Error) {\n logger.dim(error.message);\n }\n process.exit(1);\n }\n });\n}\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;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,OAAO,QAAQ,MAAM,KAAK,OAAO,QAAQ,MAAM,EAAE;AAClG,2BAAO,IAAI,UAAU,UAAU,QAAQ,MAAM,KAAK,UAAU,QAAQ,MAAM,KAAK,UAAU,QAAQ,MAAM,EAAE;AAAA,IAC7G,SAAS,OAAO;AACZ,2BAAO,MAAM,cAAc;AAC3B,UAAI,iBAAiB,OAAO;AACxB,6BAAO,IAAI,MAAM,OAAO;AAAA,MAC5B;AACA,cAAQ,KAAK,CAAC;AAAA,IAClB;AAAA,EACJ,CAAC;AACT;",
|
|
6
6
|
"names": ["chalk", "inquirer"]
|
|
7
7
|
}
|
package/dist/index.js
CHANGED
|
@@ -54,12 +54,18 @@ program.configureHelp({
|
|
|
54
54
|
visibleCommands: () => []
|
|
55
55
|
// Hide all commands from default list
|
|
56
56
|
});
|
|
57
|
-
program.name("farseer").description("CLI tool for syncing Farseer App scripts between local
|
|
57
|
+
program.name("farseer").description("CLI tool for syncing Farseer App scripts between local folder and Farseer instances").version(import_constants.CLI_VERSION).addHelpText("after", `
|
|
58
|
+
${import_chalk.default.bold.underline("Tenant Resolution")}
|
|
59
|
+
Most commands accept ${import_chalk.default.cyan("[org] [tenant]")} arguments:
|
|
60
|
+
${import_chalk.default.green("$")} farseer checkout ${import_chalk.default.cyan("salvus-2 salvus-prodaja")} ${import_chalk.default.dim("First time: specify <org> <tenant>")}
|
|
61
|
+
${import_chalk.default.green("$")} farseer pull ${import_chalk.default.cyan("salvus-prodaja")} ${import_chalk.default.dim("After that: just <tenant> (org is remembered)")}
|
|
62
|
+
${import_chalk.default.green("$")} farseer push ${import_chalk.default.dim("Or omit entirely if checked out")}
|
|
63
|
+
|
|
58
64
|
${import_chalk.default.bold.underline("Authentication")}
|
|
59
|
-
login Login via browser (OAuth)
|
|
65
|
+
login Login via browser (OAuth)
|
|
60
66
|
logout [tenant] Logout and remove credentials
|
|
61
67
|
whoami Show login status and configured tenants
|
|
62
|
-
checkout [tenant]
|
|
68
|
+
checkout [org] [tenant] Set default tenant (verifies auth & pulls)
|
|
63
69
|
${import_chalk.default.dim("--no-pull")} Skip automatic pull
|
|
64
70
|
|
|
65
71
|
${import_chalk.default.bold.underline("Configuration")} ${import_chalk.default.dim("(farseer config <command>)")}
|
|
@@ -72,12 +78,11 @@ ${import_chalk.default.bold.underline("Configuration")} ${import_chalk.default.
|
|
|
72
78
|
config test <tenant> Test connection to tenant
|
|
73
79
|
|
|
74
80
|
${import_chalk.default.bold.underline("Sync Operations")} ${import_chalk.default.dim("(tenant optional if checked out)")}
|
|
75
|
-
pull [tenant]
|
|
76
|
-
${import_chalk.default.dim("--no-git")} Skip git operations
|
|
81
|
+
pull [org] [tenant] Pull files and apps from remote
|
|
77
82
|
${import_chalk.default.dim("--all")} Download all files (not just .ts/.js)
|
|
78
|
-
push [tenant]
|
|
79
|
-
${import_chalk.default.dim("-
|
|
80
|
-
${import_chalk.default.dim("--
|
|
83
|
+
push [org] [tenant] Push local changes to remote
|
|
84
|
+
${import_chalk.default.dim("-y, --yes")} Skip confirmation prompt
|
|
85
|
+
${import_chalk.default.dim("--force")} Push even if remote has changes
|
|
81
86
|
status [tenant] Show sync status (local vs remote)
|
|
82
87
|
${import_chalk.default.dim("--all")} Show all files (not just .ts/.js)
|
|
83
88
|
diff [tenant] [file] Show file differences
|
|
@@ -123,13 +128,19 @@ ${import_chalk.default.bold.underline("File Management")} ${import_chalk.defaul
|
|
|
123
128
|
files list [tenant] List files on remote
|
|
124
129
|
${import_chalk.default.dim("--all")} Show all files (not just scripts)
|
|
125
130
|
|
|
131
|
+
${import_chalk.default.bold.underline("MCP Server")} ${import_chalk.default.dim("(AI assistant integration)")}
|
|
132
|
+
mcp-server Start MCP server for Claude, Cursor, etc.
|
|
133
|
+
|
|
126
134
|
${import_chalk.default.bold.underline("Examples")}
|
|
127
135
|
${import_chalk.default.green("$")} farseer login ${import_chalk.default.dim("Login via browser")}
|
|
128
|
-
${import_chalk.default.green("$")} farseer
|
|
129
|
-
${import_chalk.default.green("$")} farseer pull
|
|
130
|
-
${import_chalk.default.green("$")} farseer push
|
|
131
|
-
${import_chalk.default.green("$")} farseer
|
|
132
|
-
${import_chalk.default.green("$")} farseer
|
|
136
|
+
${import_chalk.default.green("$")} farseer checkout salvus-2 salvus-prod ${import_chalk.default.dim("First time: org + tenant")}
|
|
137
|
+
${import_chalk.default.green("$")} farseer pull salvus-prod ${import_chalk.default.dim("Next time: just tenant")}
|
|
138
|
+
${import_chalk.default.green("$")} farseer push ${import_chalk.default.dim("If checked out: no args needed")}
|
|
139
|
+
${import_chalk.default.green("$")} farseer push -y ${import_chalk.default.dim("Push without confirmation")}
|
|
140
|
+
${import_chalk.default.green("$")} farseer run "My App" ${import_chalk.default.dim("Run app locally")}
|
|
141
|
+
${import_chalk.default.green("$")} farseer variables list ${import_chalk.default.dim("List all variables")}
|
|
142
|
+
${import_chalk.default.green("$")} farseer variable details "Revenue" ${import_chalk.default.dim("Show variable details")}
|
|
143
|
+
${import_chalk.default.green("$")} farseer dimensions list ${import_chalk.default.dim("List dimension tables")}
|
|
133
144
|
`);
|
|
134
145
|
(0, import_login.registerLoginCommand)(program);
|
|
135
146
|
(0, import_logout.registerLogoutCommand)(program);
|