import fs from "fs" ; import path from "path" ; import { zip } from 'zip-a-folder' ; class Main { public static async main ( ) { const src = path . join ( __dirname , "src" ) ; const dist = path . join ( __dirname , "dist" ) ; const chrome = path . join ( __dirname , "chrome.zip" ) ; const firefox = path . join ( __dirname , "firefox.zip" ) ; { if ( fs . existsSync ( dist ) ) for ( const file of fs . readdirSync ( dist ) ) fs . unlinkSync ( path . join ( dist , file ) ) ; else fs . mkdirSync ( dist ) ; ! fs . existsSync ( chrome ) || fs . unlinkSync ( chrome ) ; ! fs . existsSync ( firefox ) || fs . unlinkSync ( firefox ) ; } { for ( const file of fs . readdirSync ( src ) ) fs . copyFileSync ( path . join ( src , file ) , path . join ( dist , file ) ) ; } { await zip ( dist , chrome ) ; } { const manifest = path . join ( dist , "manifest.json" ) ; fs . writeFileSync ( manifest , fs . readFileSync ( manifest , "utf-8" ) . replace ( `"manifest_version": 3` , `"manifest_version": 2` ) ) ; await zip ( dist , firefox ) ; } { for ( const file of fs . readdirSync ( dist ) ) fs . unlinkSync ( path . join ( dist , file ) ) ; fs . rmdirSync ( dist ) ; } } } process . on ( "unhandledRejection" , ( error , promise ) => { console . error ( `Unhandled rejection at:\n  Promise ${ promise }\n  ${ error . stack }` ) ; process . exit ( - 1 ) ; } ) ; Main . main ( ) . catch ( ( error ) => { console . error ( error . stack ! ) ; process . exit ( - 1 ) ; } ) ;