WIP: Start on coffee transpilation

This commit is contained in:
Nathan Sobo 2016-03-22 23:06:28 -06:00
parent ff9b0af780
commit fb2f4fc5a4
4 changed files with 56 additions and 7 deletions

View File

@ -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()

View File

@ -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)
}

View File

@ -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))
}
}
}

View File

@ -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);
}