diff --git a/script/lib/fast-clean-output-directory.js b/script/lib/fast-clean-output-directory.js new file mode 100644 index 000000000..b1053eba2 --- /dev/null +++ b/script/lib/fast-clean-output-directory.js @@ -0,0 +1,19 @@ +const fs = require('fs-extra') +const path = require('path') +const CONFIG = require('../config') + +module.exports = function () { + let srcPaths = [ + path.join('benchmarks', 'benchmark-runner.js'), + path.join('dot-atom'), + path.join('exports'), + path.join('package.json'), + path.join('static'), + path.join('src'), + path.join('vendor') + ] + + for (const srcPath of srcPaths) { + fs.removeSync(path.join(CONFIG.intermediateAppPath, srcPath)) + } +} diff --git a/script/lib/fast-copy-assets.js b/script/lib/fast-copy-assets.js new file mode 100644 index 000000000..1602a7af8 --- /dev/null +++ b/script/lib/fast-copy-assets.js @@ -0,0 +1,31 @@ +// This module exports a function that copies all the static assets into the +// appropriate location in the build output directory. + +'use strict' + +const path = require('path') +const fs = require('fs-extra') +const CONFIG = require('../config') +const glob = require('glob') +const includePathInPackagedApp = require('./include-path-in-packaged-app') + +module.exports = function () { + console.log(`Copying assets to ${CONFIG.intermediateAppPath}`); + let srcPaths = [ + path.join(CONFIG.repositoryRootPath, 'benchmarks', 'benchmark-runner.js'), + path.join(CONFIG.repositoryRootPath, 'dot-atom'), + path.join(CONFIG.repositoryRootPath, 'exports'), + path.join(CONFIG.repositoryRootPath, 'package.json'), + path.join(CONFIG.repositoryRootPath, 'static'), + path.join(CONFIG.repositoryRootPath, 'src'), + path.join(CONFIG.repositoryRootPath, 'vendor') + ] + for (let srcPath of srcPaths) { + fs.copySync(srcPath, computeDestinationPath(srcPath), {filter: includePathInPackagedApp}) + } +} + +function computeDestinationPath (srcPath) { + const relativePath = path.relative(CONFIG.repositoryRootPath, srcPath) + return path.join(CONFIG.intermediateAppPath, relativePath) +} diff --git a/script/lib/fast-transpile-babel-paths.js b/script/lib/fast-transpile-babel-paths.js new file mode 100644 index 000000000..a1901e7a0 --- /dev/null +++ b/script/lib/fast-transpile-babel-paths.js @@ -0,0 +1,36 @@ +'use strict' + +const CompileCache = require('../../src/compile-cache') +const fs = require('fs') +const glob = require('glob') +const path = require('path') + +const CONFIG = require('../config') +const BABEL_OPTIONS = require('../../static/babelrc.json') +const BABEL_PREFIXES = [ + "'use babel'", + '"use babel"', + '/** @babel */', + '/* @flow */' +] +const PREFIX_LENGTH = Math.max.apply(null, BABEL_PREFIXES.map(prefix => prefix.length)) +const BUFFER = Buffer(PREFIX_LENGTH) + +module.exports = function () { + console.log(`Transpiling Babel paths in ${CONFIG.intermediateAppPath}`) + for (let path of getPathsToTranspile()) { + transpileBabelPath(path) + } +} + +function getPathsToTranspile () { + let paths = [] + paths = paths.concat(glob.sync(path.join(CONFIG.intermediateAppPath, 'benchmarks', '**', '*.js'))) + paths = paths.concat(glob.sync(path.join(CONFIG.intermediateAppPath, 'exports', '**', '*.js'))) + paths = paths.concat(glob.sync(path.join(CONFIG.intermediateAppPath, 'src', '**', '*.js'))) + return paths +} + +function transpileBabelPath (path) { + fs.writeFileSync(path, CompileCache.addPathToCache(path, CONFIG.atomHomeDirPath)) +} diff --git a/script/lib/fast-transpile-coffee-script-paths.js b/script/lib/fast-transpile-coffee-script-paths.js new file mode 100644 index 000000000..7e080691f --- /dev/null +++ b/script/lib/fast-transpile-coffee-script-paths.js @@ -0,0 +1,28 @@ +'use strict' + +const CompileCache = require('../../src/compile-cache') +const fs = require('fs') +const glob = require('glob') +const path = require('path') + +const CONFIG = require('../config') + +module.exports = function () { + console.log(`Transpiling CoffeeScript paths in ${CONFIG.intermediateAppPath}`) + for (let path of getPathsToTranspile()) { + transpileCoffeeScriptPath(path) + } +} + +function getPathsToTranspile () { + let paths = [] + paths = paths.concat(glob.sync(path.join(CONFIG.intermediateAppPath, 'src', '**', '*.coffee'))) + paths = paths.concat(glob.sync(path.join(CONFIG.intermediateAppPath, 'spec', '*.coffee'))) + return paths +} + +function transpileCoffeeScriptPath (coffeePath) { + const jsPath = coffeePath.replace(/coffee$/g, 'js') + fs.writeFileSync(jsPath, CompileCache.addPathToCache(coffeePath, CONFIG.atomHomeDirPath)) + fs.unlinkSync(coffeePath) +} diff --git a/script/tdd b/script/tdd new file mode 100755 index 000000000..db78ef3e4 --- /dev/null +++ b/script/tdd @@ -0,0 +1,42 @@ +#!/usr/bin/env node + +'use strict' + +// Needed so we can require src/module-cache.coffee during generateModuleCache +require('coffee-script/register') +require('colors') + +const yargs = require('yargs') +const argv = yargs + .usage('Usage: $0 [options]') + .help('help') + .describe('code-sign', 'Code-sign executables (macOS and Windows only)') + .describe('create-windows-installer', 'Create installer (Windows only)') + .describe('create-debian-package', 'Create .deb package (Linux only)') + .describe('create-rpm-package', 'Create .rpm package (Linux only)') + .describe('compress-artifacts', 'Compress Atom binaries (and symbols on macOS)') + .describe('install', 'Install Atom') + .wrap(yargs.terminalWidth()) + .argv + +const cleanOutputDirectory = require('./lib/fast-clean-output-directory') +const copyAssets = require('./lib/fast-copy-assets') +const generateMetadata = require('./lib/generate-metadata') +const generateModuleCache = require('./lib/generate-module-cache') +const generateStartupSnapshot = require('./lib/generate-startup-snapshot') +const packageApplication = require('./lib/package-application') +const transpileBabelPaths = require('./lib/fast-transpile-babel-paths') +const transpileCoffeeScriptPaths = require('./lib/fast-transpile-coffee-script-paths') + +process.on('unhandledRejection', function (e) { + console.error(e.stack || e) + process.exit(1) +}) + +cleanOutputDirectory() +copyAssets() +transpileBabelPaths() +transpileCoffeeScriptPaths() +generateModuleCache() +generateMetadata() +packageApplication().then(generateStartupSnapshot)