2022-02-14 10:19:20 +01:00
/ * *
* Script to build desktop release versions of the app .
* /
import options from "commander"
import * as env from "./buildSrc/env.js"
import os from "os"
import { buildWebapp } from "./buildSrc/buildWebapp.js"
2022-03-02 18:21:01 +01:00
import { getCanonicalPlatformName , getTutanotaAppVersion , measure } from "./buildSrc/buildUtils.js"
2022-02-14 10:19:20 +01:00
import { dirname } from "path"
import { fileURLToPath } from "url"
import { createHtml } from "./buildSrc/createHtml.js"
const _ _dirname = dirname ( fileURLToPath ( import . meta . url ) )
options
. usage ( '[options] [test|prod|local|release|host <url>], "release" is default' )
2022-03-02 18:21:01 +01:00
. description ( 'Main build tool for distributable tutanota desktop artifacts.' )
2022-02-14 10:19:20 +01:00
. arguments ( '[stage] [host]' )
. option ( '-e, --existing' , 'Use existing prebuilt Webapp files in /build/dist/' )
2022-03-02 18:21:01 +01:00
. option ( '-p, --platform <platform>' , "For which platform to build: linux|win|mac" , process . platform )
. option ( '-c,--custom-desktop-release' , "use if manually building desktop client from source. doesn't install auto updates, but may still notify about new releases." )
. option ( '-d,--disable-minify' , "disable minification" , false )
. option ( '-u,--unpacked' , "don't pack the app into an installer" )
. option ( '-o,--out-dir <outDir>' , "where to copy the client" , )
. action ( async ( stage , host , opts ) => {
2022-02-14 10:19:20 +01:00
if ( ! [ "test" , "prod" , "local" , "host" , "release" , undefined ] . includes ( stage )
|| ( stage !== "host" && host )
|| ( stage === "host" && ! host ) ) {
2022-03-02 18:21:01 +01:00
opts . outputHelp ( )
2022-02-14 10:19:20 +01:00
process . exit ( 1 )
}
2022-03-02 18:21:01 +01:00
opts . stage = stage ? ? "release"
opts . host = host
2022-02-14 10:19:20 +01:00
2022-03-02 18:21:01 +01:00
if ( opts . customDesktopRelease ) {
console . log ( ` Custom desktop release - setting platform to ${ process . platform } ` )
opts . platform = process . platform
2022-02-14 10:19:20 +01:00
}
2022-03-02 18:21:01 +01:00
opts . platform = getCanonicalPlatformName ( opts . platform )
2022-02-14 10:19:20 +01:00
2022-03-02 18:21:01 +01:00
await doBuild ( opts )
2022-02-14 10:19:20 +01:00
} )
2022-03-02 18:21:01 +01:00
. parseAsync ( process . argv )
2022-02-14 10:19:20 +01:00
2022-03-02 18:21:01 +01:00
async function doBuild ( opts ) {
2022-02-14 10:19:20 +01:00
try {
measure ( )
2022-03-02 18:21:01 +01:00
const version = getTutanotaAppVersion ( )
2022-02-14 10:19:20 +01:00
2022-03-02 18:21:01 +01:00
if ( opts . existing ) {
2022-02-14 10:19:20 +01:00
console . log ( "Found existing option (-e). Skipping Webapp build." )
} else {
2022-03-02 18:21:01 +01:00
if ( opts . disableMinify ) {
2022-02-14 10:19:20 +01:00
console . warn ( "Minification is disabled" )
}
await buildWebapp (
{
version ,
2022-03-02 18:21:01 +01:00
stage : opts . stage ,
host : opts . host ,
2022-02-14 10:19:20 +01:00
measure ,
2022-03-02 18:21:01 +01:00
minify : ! opts . disableMinify ,
2022-02-14 10:19:20 +01:00
projectDir : _ _dirname
} )
}
2022-03-02 18:21:01 +01:00
await buildDesktopClient ( version , opts )
2022-02-14 10:19:20 +01:00
const now = new Date ( Date . now ( ) ) . toTimeString ( ) . substr ( 0 , 5 )
console . log ( ` \n Build time: ${ measure ( ) } s ( ${ now } ) ` )
} catch ( e ) {
console . error ( "\nBuild error:" , e )
process . exit ( 1 )
}
}
2022-03-02 18:21:01 +01:00
async function buildDesktopClient (
version ,
{
stage ,
host ,
platform ,
customDesktopRelease ,
unpacked ,
outDir
}
) {
2022-02-14 10:19:20 +01:00
const { buildDesktop } = await import ( "./buildSrc/DesktopBuilder.js" )
const desktopBaseOpts = {
dirname : _ _dirname ,
version ,
2022-03-02 18:21:01 +01:00
platform : platform ,
updateUrl : customDesktopRelease
2022-02-14 10:19:20 +01:00
? ""
: "https://mail.tutanota.com/desktop" ,
nameSuffix : "" ,
2022-03-02 18:21:01 +01:00
notarize : ! customDesktopRelease ,
outDir : outDir ,
unpacked : unpacked
2022-02-14 10:19:20 +01:00
}
2022-03-02 18:21:01 +01:00
if ( stage === "release" ) {
2022-02-14 10:19:20 +01:00
await createHtml ( env . create ( { staticUrl : "https://mail.tutanota.com" , version , mode : "Desktop" , dist : true } ) )
await buildDesktop ( desktopBaseOpts )
2022-03-02 18:21:01 +01:00
if ( ! customDesktopRelease ) { // don't build the test version for manual/custom builds
2022-02-14 10:19:20 +01:00
const desktopTestOpts = Object . assign ( { } , desktopBaseOpts , {
updateUrl : "https://test.tutanota.com/desktop" ,
nameSuffix : "-test" ,
// Do not notarize test build
notarize : false
} )
await createHtml ( env . create ( { staticUrl : "https://test.tutanota.com" , version , mode : "Desktop" , dist : true } ) )
await buildDesktop ( desktopTestOpts )
}
2022-03-02 18:21:01 +01:00
} else if ( stage === "local" ) {
2022-02-14 10:19:20 +01:00
// this is the only way to contact the local server from localhost, a VM and
// from other machines in the LAN with the same url.
const addr = Object
. values ( os . networkInterfaces ( ) )
. map ( net => net . find ( a => a . family === "IPv4" ) )
. filter ( Boolean )
. filter ( net => ! net . internal && net . address . startsWith ( '192.168.' ) ) [ 0 ] . address
const desktopLocalOpts = Object . assign ( { } , desktopBaseOpts , {
version ,
updateUrl : ` http:// ${ addr } :9000/client/build/desktop-snapshot ` ,
nameSuffix : "-snapshot" ,
notarize : false
} )
await createHtml ( env . create ( { staticUrl : ` http:// ${ addr } :9000 ` , version , mode : "Desktop" , dist : true } ) )
await buildDesktop ( desktopLocalOpts )
2022-03-02 18:21:01 +01:00
} else if ( stage === "test" ) {
2022-02-14 10:19:20 +01:00
const desktopTestOpts = Object . assign ( { } , desktopBaseOpts , {
updateUrl : "https://test.tutanota.com/desktop" ,
nameSuffix : "-test" ,
notarize : false
} )
await createHtml ( env . create ( { staticUrl : "https://test.tutanota.com" , version , mode : "Desktop" , dist : true } ) )
await buildDesktop ( desktopTestOpts )
2022-03-02 18:21:01 +01:00
} else if ( stage === "prod" ) {
2022-02-14 10:19:20 +01:00
const desktopProdOpts = Object . assign ( { } , desktopBaseOpts , {
version ,
updateUrl : "http://localhost:9000/desktop" ,
notarize : false
} )
await createHtml ( env . create ( { staticUrl : "https://mail.tutanota.com" , version , mode : "Desktop" , dist : true } ) )
await buildDesktop ( desktopProdOpts )
} else { // stage = host
const desktopHostOpts = Object . assign ( { } , desktopBaseOpts , {
version ,
2022-03-02 18:21:01 +01:00
updateUrl : ` ${ host } /client/build/desktop-snapshot ` ,
2022-02-14 10:19:20 +01:00
nameSuffix : "-snapshot" ,
notarize : false
} )
2022-03-02 18:21:01 +01:00
await createHtml ( env . create ( { staticUrl : host , version , mode : "Desktop" , dist : true } ) )
2022-02-14 10:19:20 +01:00
await buildDesktop ( desktopHostOpts )
}
}