import { glob , changed , exec _i } from "../lib/builderator.js" ;
import gen _players from "./gen_players.js" ;
export const description = "Deploys new changes to the app." ;
export const options = [
[ '--dry-run' , "Don't actually update, just pretend." ] ,
[ '--no-content' , "DO NOT deploy the render content, not the app." ] ,
[ '--no-app' , "DO NOT deploy the app, not the content." ] ,
] ;
export const required = [
[ '--target <dir>' , "rsync the results to this directory" ] ,
] ;
export const main = ( opts ) => {
exec _i ( "git pull" ) ;
const dry _run = opts . dryRun ? "--dry-run" : "" ;
if ( opts . app ) {
exec _i ( "npm run knex migrate:latest" ) ;
exec _i ( "npm run build" ) ;
// reset the icons because we need them all for the demo
exec _i ( "node bando.js icons" ) ;
exec _i ( ` rsync -av --delete admin/bando public/ ` ) ;
}
if ( opts . content ) {
gen _players . main ( ) ;
exec _i ( "node ./bando.js rendered" ) ;
}
const ext _list = [ "html" , "css" , "js" , "svg" , "xml" , "md" ] ;
for ( let ext of ext _list ) {
const files = glob ( ` ./public/**/*. ${ ext } ` ) ;
for ( let fname of files ) {
if ( changed ( fname , ` ${ fname } .br ` ) ) {
// compress the files with brotli
exec _i ( ` brotli -Zfk " ${ fname } " ` ) ;
}
// compress the files with gzip
if ( changed ( fname , ` ${ fname } .gz ` ) ) {
exec _i ( ` gzip -9fk " ${ fname } " ` ) ;
}
}
}
// sync the files
exec _i ( ` rsync ${ dry _run } -av --exclude media --delete public/* ${ opts . target } ` ) ;
process . exit ( 0 ) ;
}