nstantpage-agent 0.8.1 → 0.8.3
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/cli.js +10 -4
- package/dist/commands/logs.d.ts +14 -0
- package/dist/commands/logs.js +42 -0
- package/dist/commands/run.d.ts +4 -8
- package/dist/commands/run.js +10 -25
- package/dist/commands/sync.d.ts +0 -3
- package/dist/commands/sync.js +26 -18
- package/package.json +1 -1
package/dist/cli.js
CHANGED
|
@@ -62,15 +62,12 @@ program
|
|
|
62
62
|
.action(runCommand);
|
|
63
63
|
program
|
|
64
64
|
.command('sync')
|
|
65
|
-
.description('Sync local directory to nstantpage
|
|
65
|
+
.description('Sync local directory files to nstantpage database')
|
|
66
66
|
.argument('[directory]', 'Project directory to sync (defaults to current directory)', '.')
|
|
67
|
-
.option('-p, --port <port>', 'Local dev server port', '3000')
|
|
68
|
-
.option('-a, --api-port <port>', 'Local API server port', '18924')
|
|
69
67
|
.option('--local [port]', 'Sync to local backend (default: localhost:5001)')
|
|
70
68
|
.option('--gateway <url>', 'Gateway URL (default: from login)')
|
|
71
69
|
.option('--backend <url>', 'Backend API URL (auto-detected from gateway)')
|
|
72
70
|
.option('--token <token>', 'Auth token (skip login flow)')
|
|
73
|
-
.option('--no-start', 'Only sync files, do not start the agent')
|
|
74
71
|
.action(syncCommand);
|
|
75
72
|
program
|
|
76
73
|
.command('stop')
|
|
@@ -129,5 +126,14 @@ program
|
|
|
129
126
|
.command('update')
|
|
130
127
|
.description('Update CLI to the latest version')
|
|
131
128
|
.action(updateCommand);
|
|
129
|
+
program
|
|
130
|
+
.command('logs')
|
|
131
|
+
.description('Show agent log output')
|
|
132
|
+
.option('-f, --follow', 'Follow log output (like tail -f)')
|
|
133
|
+
.option('-n, --lines <count>', 'Number of lines to show', '50')
|
|
134
|
+
.action(async (options) => {
|
|
135
|
+
const { logsCommand } = await import('./commands/logs.js');
|
|
136
|
+
await logsCommand(options);
|
|
137
|
+
});
|
|
132
138
|
program.parse();
|
|
133
139
|
//# sourceMappingURL=cli.js.map
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Logs command — show agent log output.
|
|
3
|
+
*
|
|
4
|
+
* Usage:
|
|
5
|
+
* nstantpage logs — Show last 50 lines
|
|
6
|
+
* nstantpage logs -f — Follow log output (tail -f)
|
|
7
|
+
* nstantpage logs -n 100 — Show last 100 lines
|
|
8
|
+
*/
|
|
9
|
+
interface LogsOptions {
|
|
10
|
+
follow?: boolean;
|
|
11
|
+
lines: string;
|
|
12
|
+
}
|
|
13
|
+
export declare function logsCommand(options: LogsOptions): Promise<void>;
|
|
14
|
+
export {};
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Logs command — show agent log output.
|
|
3
|
+
*
|
|
4
|
+
* Usage:
|
|
5
|
+
* nstantpage logs — Show last 50 lines
|
|
6
|
+
* nstantpage logs -f — Follow log output (tail -f)
|
|
7
|
+
* nstantpage logs -n 100 — Show last 100 lines
|
|
8
|
+
*/
|
|
9
|
+
import chalk from 'chalk';
|
|
10
|
+
import fs from 'fs';
|
|
11
|
+
import path from 'path';
|
|
12
|
+
import os from 'os';
|
|
13
|
+
import { execSync } from 'child_process';
|
|
14
|
+
export async function logsCommand(options) {
|
|
15
|
+
const logPath = path.join(os.homedir(), '.nstantpage', 'agent.log');
|
|
16
|
+
if (!fs.existsSync(logPath)) {
|
|
17
|
+
console.log(chalk.yellow(' No log file found.'));
|
|
18
|
+
console.log(chalk.gray(` Expected: ${logPath}`));
|
|
19
|
+
console.log(chalk.gray(' Run "nstantpage run" to start the agent service first.'));
|
|
20
|
+
return;
|
|
21
|
+
}
|
|
22
|
+
const lines = parseInt(options.lines, 10) || 50;
|
|
23
|
+
if (options.follow) {
|
|
24
|
+
console.log(chalk.gray(` Following ${logPath} (Ctrl+C to stop)\n`));
|
|
25
|
+
try {
|
|
26
|
+
execSync(`tail -n ${lines} -f "${logPath}"`, { stdio: 'inherit' });
|
|
27
|
+
}
|
|
28
|
+
catch {
|
|
29
|
+
// User pressed Ctrl+C
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
else {
|
|
33
|
+
try {
|
|
34
|
+
const output = execSync(`tail -n ${lines} "${logPath}"`, { encoding: 'utf-8' });
|
|
35
|
+
console.log(output);
|
|
36
|
+
}
|
|
37
|
+
catch {
|
|
38
|
+
console.log(chalk.red(' Failed to read log file.'));
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
//# sourceMappingURL=logs.js.map
|
package/dist/commands/run.d.ts
CHANGED
|
@@ -1,14 +1,10 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Run command — install the background service
|
|
2
|
+
* Run command — install the background service so the agent starts on boot.
|
|
3
3
|
*
|
|
4
4
|
* Usage:
|
|
5
|
-
* nstantpage run — Install service
|
|
6
|
-
* nstantpage run --local —
|
|
7
|
-
* nstantpage run --local 3000 —
|
|
8
|
-
*
|
|
9
|
-
* This is the main entry point for users. It:
|
|
10
|
-
* 1. Installs the agent as a background service (auto-start on boot)
|
|
11
|
-
* 2. Starts the agent immediately in standby mode
|
|
5
|
+
* nstantpage run — Install service (connects to nstantpage.com)
|
|
6
|
+
* nstantpage run --local — Install service targeting localhost:5001
|
|
7
|
+
* nstantpage run --local 3000 — Install service targeting localhost:3000
|
|
12
8
|
*/
|
|
13
9
|
interface RunOptions {
|
|
14
10
|
local?: string | boolean;
|
package/dist/commands/run.js
CHANGED
|
@@ -1,19 +1,14 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Run command — install the background service
|
|
2
|
+
* Run command — install the background service so the agent starts on boot.
|
|
3
3
|
*
|
|
4
4
|
* Usage:
|
|
5
|
-
* nstantpage run — Install service
|
|
6
|
-
* nstantpage run --local —
|
|
7
|
-
* nstantpage run --local 3000 —
|
|
8
|
-
*
|
|
9
|
-
* This is the main entry point for users. It:
|
|
10
|
-
* 1. Installs the agent as a background service (auto-start on boot)
|
|
11
|
-
* 2. Starts the agent immediately in standby mode
|
|
5
|
+
* nstantpage run — Install service (connects to nstantpage.com)
|
|
6
|
+
* nstantpage run --local — Install service targeting localhost:5001
|
|
7
|
+
* nstantpage run --local 3000 — Install service targeting localhost:3000
|
|
12
8
|
*/
|
|
13
9
|
import chalk from 'chalk';
|
|
14
10
|
import { getConfig } from '../config.js';
|
|
15
11
|
import { serviceInstallCommand } from './service.js';
|
|
16
|
-
import { startCommand } from './start.js';
|
|
17
12
|
export async function runCommand(options = {}) {
|
|
18
13
|
const conf = getConfig();
|
|
19
14
|
// Resolve gateway based on --local flag
|
|
@@ -21,7 +16,6 @@ export async function runCommand(options = {}) {
|
|
|
21
16
|
if (options.local !== undefined && options.local !== false) {
|
|
22
17
|
const port = (typeof options.local === 'string') ? options.local : '5001';
|
|
23
18
|
gateway = `ws://localhost:4000`;
|
|
24
|
-
// Store backend override for the start command
|
|
25
19
|
conf.set('localBackendUrl', `http://localhost:${port}`);
|
|
26
20
|
}
|
|
27
21
|
else {
|
|
@@ -35,25 +29,16 @@ export async function runCommand(options = {}) {
|
|
|
35
29
|
}
|
|
36
30
|
console.log(chalk.blue(`\n 🚀 nstantpage run\n`));
|
|
37
31
|
console.log(chalk.gray(` Server: ${isLocal ? 'localhost (dev)' : 'nstantpage.com'}`));
|
|
38
|
-
//
|
|
39
|
-
console.log(chalk.gray(' Installing background service...'));
|
|
32
|
+
// Install background service (auto-start on boot + starts immediately)
|
|
40
33
|
try {
|
|
41
34
|
await serviceInstallCommand({ gateway });
|
|
42
35
|
}
|
|
43
36
|
catch (err) {
|
|
44
|
-
console.log(chalk.
|
|
37
|
+
console.log(chalk.red(` ✗ Service install failed: ${err.message}`));
|
|
38
|
+
process.exit(1);
|
|
45
39
|
}
|
|
46
|
-
|
|
47
|
-
console.log(chalk.gray('
|
|
48
|
-
|
|
49
|
-
? (conf.get('localBackendUrl') || 'http://localhost:5001')
|
|
50
|
-
: undefined;
|
|
51
|
-
await startCommand('.', {
|
|
52
|
-
port: '3000',
|
|
53
|
-
apiPort: '18924',
|
|
54
|
-
gateway,
|
|
55
|
-
token: token || 'local-dev',
|
|
56
|
-
backend: backendUrl,
|
|
57
|
-
});
|
|
40
|
+
console.log(chalk.green('\n ✓ Agent is running as a background service.'));
|
|
41
|
+
console.log(chalk.gray(' Use "nstantpage logs" to view agent output.'));
|
|
42
|
+
console.log(chalk.gray(' Use "nstantpage service stop" to stop.\n'));
|
|
58
43
|
}
|
|
59
44
|
//# sourceMappingURL=run.js.map
|
package/dist/commands/sync.d.ts
CHANGED
|
@@ -12,13 +12,10 @@
|
|
|
12
12
|
* 4. Starts the agent (equivalent to `nstantpage start`)
|
|
13
13
|
*/
|
|
14
14
|
interface SyncOptions {
|
|
15
|
-
port: string;
|
|
16
|
-
apiPort: string;
|
|
17
15
|
local?: boolean | string;
|
|
18
16
|
gateway?: string;
|
|
19
17
|
backend?: string;
|
|
20
18
|
token?: string;
|
|
21
|
-
noStart?: boolean;
|
|
22
19
|
}
|
|
23
20
|
export declare function syncCommand(directory: string, options: SyncOptions): Promise<void>;
|
|
24
21
|
export {};
|
package/dist/commands/sync.js
CHANGED
|
@@ -15,11 +15,11 @@ import chalk from 'chalk';
|
|
|
15
15
|
import path from 'path';
|
|
16
16
|
import fs from 'fs';
|
|
17
17
|
import { getConfig, getDeviceId } from '../config.js';
|
|
18
|
-
import { startCommand } from './start.js';
|
|
19
18
|
const SKIP_DIRS = new Set([
|
|
20
19
|
'node_modules', 'dist', '.git', '.vite-cache', '.next',
|
|
21
20
|
'__pycache__', '.turbo', '.cache', 'build', 'out',
|
|
22
21
|
'.svelte-kit', '.nuxt', '.output', '.vercel',
|
|
22
|
+
'.angular', '.parcel-cache', '.rollup.cache',
|
|
23
23
|
]);
|
|
24
24
|
const SKIP_FILES = new Set([
|
|
25
25
|
'.DS_Store', 'Thumbs.db', '.env.local',
|
|
@@ -174,7 +174,28 @@ export async function syncCommand(directory, options) {
|
|
|
174
174
|
console.log(chalk.red(` ✗ ${err.message}`));
|
|
175
175
|
process.exit(1);
|
|
176
176
|
}
|
|
177
|
-
// 4.
|
|
177
|
+
// 4. Create new version and clear old files (clean sync)
|
|
178
|
+
console.log(chalk.gray(' Creating new version (clearing old files)...'));
|
|
179
|
+
try {
|
|
180
|
+
const syncRes = await fetch(`${backendUrl}/api/projects/${projectId}/sync`, {
|
|
181
|
+
method: 'POST',
|
|
182
|
+
headers: {
|
|
183
|
+
'Authorization': `Bearer ${token}`,
|
|
184
|
+
'Content-Type': 'application/json',
|
|
185
|
+
},
|
|
186
|
+
});
|
|
187
|
+
if (!syncRes.ok) {
|
|
188
|
+
const text = await syncRes.text().catch(() => '');
|
|
189
|
+
throw new Error(`Sync init failed (${syncRes.status}): ${text}`);
|
|
190
|
+
}
|
|
191
|
+
const syncData = await syncRes.json();
|
|
192
|
+
console.log(chalk.green(` ✓ Version ${syncData.versionNumber} created (old files cleared)`));
|
|
193
|
+
}
|
|
194
|
+
catch (err) {
|
|
195
|
+
console.log(chalk.red(` ✗ ${err.message}`));
|
|
196
|
+
process.exit(1);
|
|
197
|
+
}
|
|
198
|
+
// 5. Push all files to DB
|
|
178
199
|
console.log(chalk.gray(` Pushing ${files.length} files to database...`));
|
|
179
200
|
// Push in batches of 100 to avoid huge payloads
|
|
180
201
|
const BATCH_SIZE = 100;
|
|
@@ -214,21 +235,8 @@ export async function syncCommand(directory, options) {
|
|
|
214
235
|
if (files.length > BATCH_SIZE)
|
|
215
236
|
process.stdout.write('\n');
|
|
216
237
|
console.log(chalk.green(` ✓ ${totalPushed} files synced to database`));
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
console.log(chalk.gray(` To start the agent: nstantpage start --project-id ${projectId} --dir "${projectDir}"`));
|
|
221
|
-
return;
|
|
222
|
-
}
|
|
223
|
-
console.log(chalk.gray('\n Starting agent...\n'));
|
|
224
|
-
await startCommand(projectDir, {
|
|
225
|
-
port: options.port,
|
|
226
|
-
apiPort: options.apiPort,
|
|
227
|
-
projectId,
|
|
228
|
-
gateway,
|
|
229
|
-
backend: options.backend,
|
|
230
|
-
token,
|
|
231
|
-
dir: projectDir,
|
|
232
|
-
});
|
|
238
|
+
console.log(chalk.blue(`\n ✓ Sync complete! Project ID: ${projectId}`));
|
|
239
|
+
console.log(chalk.gray(`\n View on web: https://nstantpage.com/project/${projectId}`));
|
|
240
|
+
console.log(chalk.gray(` Start agent: nstantpage start --project-id ${projectId} --dir "${projectDir}"\n`));
|
|
233
241
|
}
|
|
234
242
|
//# sourceMappingURL=sync.js.map
|
package/package.json
CHANGED