Files
atom/script/lib/fast-transpile-babel-paths.js
2017-03-07 17:56:36 +01:00

37 lines
1.1 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')
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))
}