11#!/usr/bin/env node
22
33import { execSync } from 'node:child_process' ;
4- import { readFileSync } from 'node:fs' ;
4+ import { existsSync , readFileSync } from 'node:fs' ;
55import { dirname , resolve } from 'node:path' ;
66import { fileURLToPath } from 'node:url' ;
77
88const __filename = fileURLToPath ( import . meta. url ) ;
99const __dirname = dirname ( __filename ) ;
1010const 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:`);
2745console . log ( ` Name: ${ manifest . name } ` ) ;
2846console . 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' ) ;
3257const zipPath = resolve ( rootDir , zipName ) ;
3358
3459try {
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