Skip to content

Commit d11b0e3

Browse files
committed
fix: improve error handling in create-zip script
- Add checks for dist/ folder existence - Add check for manifest.json existence - Add check for zip command availability - Improve error messages with actionable guidance - Better error handling for JSON parsing
1 parent a14f396 commit d11b0e3

File tree

1 file changed

+32
-4
lines changed

1 file changed

+32
-4
lines changed

scripts/create-zip.js

Lines changed: 32 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,35 @@
11
#!/usr/bin/env node
22

33
import { execSync } from 'node:child_process';
4-
import { readFileSync } from 'node:fs';
4+
import { existsSync, readFileSync } from 'node:fs';
55
import { dirname, resolve } from 'node:path';
66
import { fileURLToPath } from 'node:url';
77

88
const __filename = fileURLToPath(import.meta.url);
99
const __dirname = dirname(__filename);
1010
const rootDir = resolve(__dirname, '..');
1111

12+
// Check if dist folder exists
13+
const distDir = resolve(rootDir, 'dist');
14+
if (!existsSync(distDir)) {
15+
console.error('❌ Error: dist/ folder does not exist. Run "pnpm build" first.');
16+
process.exit(1);
17+
}
18+
1219
// Read manifest
13-
const manifestPath = resolve(rootDir, 'dist', 'manifest.json');
14-
const manifest = JSON.parse(readFileSync(manifestPath, 'utf-8'));
20+
const manifestPath = resolve(distDir, 'manifest.json');
21+
if (!existsSync(manifestPath)) {
22+
console.error(`❌ Error: ${manifestPath} does not exist. Run "pnpm build" first.`);
23+
process.exit(1);
24+
}
25+
26+
let manifest;
27+
try {
28+
manifest = JSON.parse(readFileSync(manifestPath, 'utf-8'));
29+
} catch (error) {
30+
console.error(`❌ Error: Failed to parse manifest.json: ${error.message}`);
31+
process.exit(1);
32+
}
1533

1634
// Convert manifest name to filename-friendly format
1735
// "Auth HI!" -> "auth-hi"
@@ -27,14 +45,24 @@ console.log(`Creating ${zipName} from manifest:`);
2745
console.log(` Name: ${manifest.name}`);
2846
console.log(` Version: ${version}`);
2947

48+
// Check if zip command is available
49+
try {
50+
execSync('which zip', { stdio: 'ignore' });
51+
} catch (_error) {
52+
console.error('❌ Error: "zip" command not found. Please install zip utility.');
53+
process.exit(1);
54+
}
55+
3056
// Create zip from dist folder
31-
const distDir = resolve(rootDir, 'dist');
3257
const zipPath = resolve(rootDir, zipName);
3358

3459
try {
3560
execSync(`cd "${distDir}" && zip -r "${zipPath}" .`, { stdio: 'inherit' });
3661
console.log(`\n✅ Created: ${zipName}`);
3762
} catch (error) {
3863
console.error(`\n❌ Failed to create zip: ${error.message}`);
64+
if (error instanceof Error && error.message.includes('zip')) {
65+
console.error(' Make sure "zip" utility is installed and available in PATH.');
66+
}
3967
process.exit(1);
4068
}

0 commit comments

Comments
 (0)