build
1 #!/usr/bin/env node 2 3 'use strict' 4 5 if (process.argv.includes('--no-bootstrap')) { 6 console.log('Skipping bootstrap') 7 } else { 8 // Bootstrap first to ensure all the dependencies used later in this script 9 // are installed. 10 require('./bootstrap') 11 } 12 13 // Needed so we can require src/module-cache.coffee during generateModuleCache 14 require('coffee-script/register') 15 require('colors') 16 17 const path = require('path') 18 const yargs = require('yargs') 19 const argv = yargs 20 .usage('Usage: $0 [options]') 21 .help('help') 22 .describe('existing-binaries', 'Use existing Atom binaries (skip clean/transpile/cache)') 23 .describe('code-sign', 'Code-sign executables (macOS and Windows only)') 24 .describe('test-sign', 'Test-sign executables (macOS only)') 25 .describe('create-windows-installer', 'Create installer (Windows only)') 26 .describe('create-debian-package', 'Create .deb package (Linux only)') 27 .describe('create-rpm-package', 'Create .rpm package (Linux only)') 28 .describe('compress-artifacts', 'Compress Atom binaries (and symbols on macOS)') 29 .describe('generate-api-docs', 'Only build the API documentation') 30 .describe('install', 'Install Atom') 31 .string('install') 32 .describe('ci', 'Install dependencies quickly (package-lock.json files must be up to date)') 33 .wrap(yargs.terminalWidth()) 34 .argv 35 36 const checkChromedriverVersion = require('./lib/check-chromedriver-version') 37 const cleanOutputDirectory = require('./lib/clean-output-directory') 38 const codeSignOnMac = require('./lib/code-sign-on-mac') 39 const codeSignOnWindows = require('./lib/code-sign-on-windows') 40 const compressArtifacts = require('./lib/compress-artifacts') 41 const copyAssets = require('./lib/copy-assets') 42 const createDebianPackage = require('./lib/create-debian-package') 43 const createRpmPackage = require('./lib/create-rpm-package') 44 const createWindowsInstaller = require('./lib/create-windows-installer') 45 const dumpSymbols = require('./lib/dump-symbols') 46 const generateAPIDocs = require('./lib/generate-api-docs') 47 const generateMetadata = require('./lib/generate-metadata') 48 const generateModuleCache = require('./lib/generate-module-cache') 49 const generateStartupSnapshot = require('./lib/generate-startup-snapshot') 50 const installApplication = require('./lib/install-application') 51 const packageApplication = require('./lib/package-application') 52 const prebuildLessCache = require('./lib/prebuild-less-cache') 53 const testSignOnMac = require('./lib/test-sign-on-mac') 54 const transpileBabelPaths = require('./lib/transpile-babel-paths') 55 const transpileCoffeeScriptPaths = require('./lib/transpile-coffee-script-paths') 56 const transpileCsonPaths = require('./lib/transpile-cson-paths') 57 const transpilePegJsPaths = require('./lib/transpile-peg-js-paths') 58 const transpilePackagesWithCustomTranspilerPaths = require('./lib/transpile-packages-with-custom-transpiler-paths.js') 59 60 process.on('unhandledRejection', function (e) { 61 console.error(e.stack || e) 62 process.exit(1) 63 }) 64 65 const CONFIG = require('./config') 66 process.env.ELECTRON_VERSION = CONFIG.appMetadata.electronVersion 67 68 let binariesPromise = Promise.resolve() 69 70 if (!argv.existingBinaries) { 71 checkChromedriverVersion() 72 cleanOutputDirectory() 73 copyAssets() 74 transpilePackagesWithCustomTranspilerPaths() 75 transpileBabelPaths() 76 transpileCoffeeScriptPaths() 77 transpileCsonPaths() 78 transpilePegJsPaths() 79 generateModuleCache() 80 prebuildLessCache() 81 generateMetadata() 82 generateAPIDocs() 83 if (!argv.generateApiDocs) { 84 binariesPromise = dumpSymbols() 85 } 86 } 87 88 if (!argv.generateApiDocs) { 89 binariesPromise 90 .then(packageApplication) 91 .then(packagedAppPath => generateStartupSnapshot(packagedAppPath).then(() => packagedAppPath)) 92 .then(packagedAppPath => { 93 switch (process.platform) { 94 case 'darwin': { 95 if (argv.codeSign) { 96 codeSignOnMac(packagedAppPath) 97 } else if (argv.testSign) { 98 testSignOnMac(packagedAppPath) 99 } else { 100 console.log('Skipping code-signing. Specify the --code-sign option to perform code-signing'.gray) 101 } 102 break 103 } 104 case 'win32': { 105 if (argv.testSign) { 106 console.log('Test signing is not supported on Windows, skipping.'.gray) 107 } 108 109 if (argv.codeSign) { 110 const executablesToSign = [ path.join(packagedAppPath, CONFIG.executableName) ] 111 if (argv.createWindowsInstaller) { 112 executablesToSign.push(path.join(__dirname, 'node_modules', '@atom', 'electron-winstaller', 'vendor', 'Squirrel.exe')) 113 } 114 codeSignOnWindows(executablesToSign) 115 } else { 116 console.log('Skipping code-signing. Specify the --code-sign option to perform code-signing'.gray) 117 } 118 if (argv.createWindowsInstaller) { 119 return createWindowsInstaller(packagedAppPath) 120 .then((installerPath) => { 121 argv.codeSign && codeSignOnWindows([installerPath]) 122 return packagedAppPath 123 }) 124 } else { 125 console.log('Skipping creating installer. Specify the --create-windows-installer option to create a Squirrel-based Windows installer.'.gray) 126 } 127 break 128 } 129 case 'linux': { 130 if (argv.createDebianPackage) { 131 createDebianPackage(packagedAppPath) 132 } else { 133 console.log('Skipping creating debian package. Specify the --create-debian-package option to create it.'.gray) 134 } 135 136 if (argv.createRpmPackage) { 137 createRpmPackage(packagedAppPath) 138 } else { 139 console.log('Skipping creating rpm package. Specify the --create-rpm-package option to create it.'.gray) 140 } 141 break 142 } 143 } 144 145 return Promise.resolve(packagedAppPath) 146 }).then(packagedAppPath => { 147 if (argv.compressArtifacts) { 148 compressArtifacts(packagedAppPath) 149 } else { 150 console.log('Skipping artifacts compression. Specify the --compress-artifacts option to compress Atom binaries (and symbols on macOS)'.gray) 151 } 152 153 if (argv.install != null) { 154 installApplication(packagedAppPath, argv.install) 155 } else { 156 console.log('Skipping installation. Specify the --install option to install Atom'.gray) 157 } 158 }) 159 }