Files
atom/script/lib/transpile-coffee-script-paths.js
Elliot Berman 3bd5c2d37d 🐛 Don't attempt to transpile directories
Enable option in glob to disable directories from being returned when
finding paths to transpile during compilation
2017-04-15 09:27:57 -04:00

35 lines
1.2 KiB
JavaScript

'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'), {nodir: true}))
paths = paths.concat(glob.sync(path.join(CONFIG.intermediateAppPath, 'spec', '*.coffee'), {nodir: true}))
for (let packageName of Object.keys(CONFIG.appMetadata.packageDependencies)) {
paths = paths.concat(glob.sync(
path.join(CONFIG.intermediateAppPath, 'node_modules', packageName, '**', '*.coffee'),
{ignore: path.join(CONFIG.intermediateAppPath, 'node_modules', packageName, 'spec', '**', '*.coffee'), nodir: true}
))
}
return paths
}
function transpileCoffeeScriptPath (coffeePath) {
const jsPath = coffeePath.replace(/coffee$/g, 'js')
fs.writeFileSync(jsPath, CompileCache.addPathToCache(coffeePath, CONFIG.atomHomeDirPath))
fs.unlinkSync(coffeePath)
}