nstantpage-agent 0.8.6 → 0.8.7
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/start.js +39 -12
- package/package.json +1 -1
package/dist/commands/start.js
CHANGED
|
@@ -268,13 +268,16 @@ export async function startCommand(directory, options) {
|
|
|
268
268
|
console.log(chalk.gray(` API server: port ${apiPort}`));
|
|
269
269
|
console.log(chalk.gray(` Gateway: ${options.gateway}`));
|
|
270
270
|
console.log(chalk.gray(` Backend: ${backendUrl}\n`));
|
|
271
|
-
//
|
|
271
|
+
// Determine if this is a user-managed local directory (--dir flag or explicit path)
|
|
272
|
+
// For local projects: disk is truth, NEVER overwrite disk from DB
|
|
273
|
+
const isLocalDir = !!(options.dir) || directory !== '.';
|
|
274
|
+
// 1. Fetch or sync project files
|
|
272
275
|
const installer = new PackageInstaller({ projectDir });
|
|
273
276
|
let fetchedVersionId;
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
//
|
|
277
|
+
if (isLocalDir) {
|
|
278
|
+
// Local project — SKIP DB→disk fetch. Disk is truth.
|
|
279
|
+
console.log(chalk.gray(` Local project — using files from disk (not fetching from DB)`));
|
|
280
|
+
// Install dependencies if needed
|
|
278
281
|
if (!installer.areDependenciesInstalled()) {
|
|
279
282
|
if (fs.existsSync(path.join(projectDir, 'package.json'))) {
|
|
280
283
|
console.log(chalk.gray(' Installing dependencies...'));
|
|
@@ -292,13 +295,37 @@ export async function startCommand(directory, options) {
|
|
|
292
295
|
console.log(chalk.gray(` Dependencies already installed`));
|
|
293
296
|
}
|
|
294
297
|
}
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
298
|
+
else {
|
|
299
|
+
// Cloud/managed project — fetch files from DB to disk
|
|
300
|
+
try {
|
|
301
|
+
const { fileCount, isNew, versionId } = await fetchProjectFiles(backendUrl, projectId, projectDir, token);
|
|
302
|
+
fetchedVersionId = versionId;
|
|
303
|
+
// 2. Install dependencies if needed (verifies actual packages, not just folder)
|
|
304
|
+
if (!installer.areDependenciesInstalled()) {
|
|
305
|
+
if (fs.existsSync(path.join(projectDir, 'package.json'))) {
|
|
306
|
+
console.log(chalk.gray(' Installing dependencies...'));
|
|
307
|
+
try {
|
|
308
|
+
await installer.ensureDependencies();
|
|
309
|
+
console.log(chalk.green(` ✓ Dependencies installed`));
|
|
310
|
+
}
|
|
311
|
+
catch (err) {
|
|
312
|
+
console.log(chalk.yellow(` ⚠ Install failed: ${err.message?.slice(0, 200)}`));
|
|
313
|
+
console.log(chalk.gray(` Will retry when dev server starts`));
|
|
314
|
+
}
|
|
315
|
+
}
|
|
316
|
+
}
|
|
317
|
+
else {
|
|
318
|
+
console.log(chalk.gray(` Dependencies already installed`));
|
|
319
|
+
}
|
|
320
|
+
}
|
|
321
|
+
catch (err) {
|
|
322
|
+
console.log(chalk.yellow(` ⚠ Could not fetch project files: ${err.message}`));
|
|
323
|
+
console.log(chalk.gray(' Continuing with existing local files (if any)...'));
|
|
324
|
+
if (!fs.existsSync(path.join(projectDir, 'package.json'))) {
|
|
325
|
+
console.log(chalk.red(`\n✗ No package.json found and cannot fetch files from backend.`));
|
|
326
|
+
console.log(chalk.gray(' Check your project ID and authentication.'));
|
|
327
|
+
process.exit(1);
|
|
328
|
+
}
|
|
302
329
|
}
|
|
303
330
|
}
|
|
304
331
|
// Save .nstantpage.json for future runs
|
package/package.json
CHANGED