diff --git a/build/build.js b/build/build.js index 49103e63d..5d90029a9 100644 --- a/build/build.js +++ b/build/build.js @@ -3,9 +3,11 @@ 'use strict' const transpileBabelPaths = require('./lib/transpile-babel-paths') +const transpileCoffeeScriptPaths = require('./lib/transpile-coffee-script-paths') function transpile () { - transpileBabelPaths() + // transpileBabelPaths() + transpileCoffeeScriptPaths() } transpile() diff --git a/build/lib/compute-destination-path.js b/build/lib/compute-destination-path.js new file mode 100644 index 000000000..d79b01198 --- /dev/null +++ b/build/lib/compute-destination-path.js @@ -0,0 +1,13 @@ +// Takes an absolute path, relativizes it based on the repository root, then +// makes it absolute again in the output app path. + +'use strict' + +const path = require('path') +const CONFIG = require('../config') + +module.exports = +function computeDestinationPath (srcPath) { + let relativePath = path.relative(CONFIG.repositoryRootPath, srcPath) + return path.join(CONFIG.electronAppPath, relativePath) +} diff --git a/build/lib/transpile-babel-paths.js b/build/lib/transpile-babel-paths.js index 06e4c5c45..c38baf41d 100644 --- a/build/lib/transpile-babel-paths.js +++ b/build/lib/transpile-babel-paths.js @@ -10,7 +10,9 @@ const fs = require('fs') const glob = require('glob') const mkdirp = require('mkdirp') const path = require('path') +const computeDestinationPath = require('./compute-destination-path') +const CONFIG = require('../config') const BABEL_OPTIONS = require('../../static/babelrc.json') const BABEL_PREFIXES = [ "'use babel'", @@ -21,14 +23,10 @@ const BABEL_PREFIXES = [ const PREFIX_LENGTH = Math.max.apply(null, BABEL_PREFIXES.map(prefix => prefix.length)) const BUFFER = Buffer(PREFIX_LENGTH) -const CONFIG = require('../config') - function transpileBabelPaths () { - for (let srcPath of glob.sync(`${__dirname}/../../src/**/*.js`)) { + for (let srcPath of glob.sync(`${CONFIG.repositoryRootPath}/src/**/*.js`)) { if (usesBabel(srcPath)) { - const relPath = path.relative(CONFIG.repositoryRootPath, srcPath) - const destPath = path.join(CONFIG.electronAppPath, relPath) - transpileBabelPath(srcPath, destPath) + transpileBabelPath(srcPath, computeDestinationPath(srcPath)) } } } diff --git a/build/lib/transpile-coffee-script-paths.js b/build/lib/transpile-coffee-script-paths.js new file mode 100644 index 000000000..886234ef6 --- /dev/null +++ b/build/lib/transpile-coffee-script-paths.js @@ -0,0 +1,36 @@ +// This module exports a function that transpiles all .coffee files into the +// appropriate location in the build output directory. + +'use strict' + +const glob = require('glob') +const path = require('path') + +const CONFIG = require('../config') +const computeDestinationPath = require('./compute-destination-path') + +const GLOBS = [ + 'src/**/*.coffee,spec/*.coffee', + '!spec/*-spec.coffee', + 'exports/**/*.coffee', + 'static/**/*.coffee' +] + +module.exports = +function transpileCoffeeScriptPaths () { + for (let srcPath of getPathsToTranspile()) { + transpileCoffeeScriptPath(srcPath, computeDestinationPath(srcPath)) + } +} + +function getPathsToTranspile () { + let paths = [] + paths = paths.concat(glob.sync(`${CONFIG.repositoryRootPath}/src/**/*.coffee`)) + paths = paths.concat(glob.sync(`${CONFIG.repositoryRootPath}/spec/*.coffee`, {ignore: '**/*-spec.coffee'})) + paths = paths.concat(glob.sync(`${CONFIG.repositoryRootPath}/exports/**/*.coffee`)) + return paths +} + +function transpileCoffeeScriptPath (srcPath, destPath) { + console.log(srcPath); +}