👕 Use standard style for js code

This commit is contained in:
Max Brunsfeld
2015-08-21 16:56:32 -07:00
parent ca4922bb70
commit a4b9b9c6cd
7 changed files with 209 additions and 202 deletions

View File

@@ -17,14 +17,14 @@ var PREFIX_LENGTH = Math.max.apply(Math, PREFIXES.map(function (prefix) {
return prefix.length
}))
exports.shouldCompile = function(sourceCode) {
exports.shouldCompile = function (sourceCode) {
var start = sourceCode.substr(0, PREFIX_LENGTH)
return PREFIXES.some(function (prefix) {
return start.indexOf(prefix) === 0
})
}
exports.getCachePath = function(sourceCode) {
exports.getCachePath = function (sourceCode) {
if (babelVersionDirectory == null) {
var babelVersion = require('babel-core/package.json').version
babelVersionDirectory = path.join('js', 'babel', createVersionAndOptionsDigest(babelVersion, defaultOptions))
@@ -35,11 +35,11 @@ exports.getCachePath = function(sourceCode) {
crypto
.createHash('sha1')
.update(sourceCode, 'utf8')
.digest('hex') + ".js"
.digest('hex') + '.js'
)
}
exports.compile = function(sourceCode, filePath) {
exports.compile = function (sourceCode, filePath) {
if (!babel) {
babel = require('babel-core')
}

View File

@@ -4,21 +4,21 @@ var crypto = require('crypto')
var path = require('path')
var CoffeeScript = null
exports.shouldCompile = function() {
exports.shouldCompile = function () {
return true
}
exports.getCachePath = function(sourceCode) {
exports.getCachePath = function (sourceCode) {
return path.join(
"coffee",
'coffee',
crypto
.createHash('sha1')
.update(sourceCode, 'utf8')
.digest('hex') + ".js"
.digest('hex') + '.js'
)
}
exports.compile = function(sourceCode, filePath) {
exports.compile = function (sourceCode, filePath) {
if (!CoffeeScript) {
var previousPrepareStackTrace = Error.prepareStackTrace
CoffeeScript = require('coffee-script')

View File

@@ -93,8 +93,9 @@ function writeCachedJavascript (relativeCachePath, code) {
}
function addSourceURL (jsCode, filePath) {
if (process.platform === 'win32')
if (process.platform === 'win32') {
filePath = '/' + path.resolve(filePath).replace(/\\/g, '/')
}
return jsCode + '\n' + '//# sourceURL=' + encodeURI(filePath) + '\n'
}
@@ -114,7 +115,7 @@ require('source-map-support').install({
try {
var sourceCode = fs.readFileSync(filePath, 'utf8')
} catch (error) {
console.warn("Error reading source file", error.stack)
console.warn('Error reading source file', error.stack)
return null
}
@@ -123,7 +124,7 @@ require('source-map-support').install({
try {
var fileData = readCachedJavascript(compiler.getCachePath(sourceCode, filePath))
} catch (error) {
console.warn("Error reading compiled file", error.stack)
console.warn('Error reading compiled file', error.stack)
return null
}
@@ -146,7 +147,7 @@ require('source-map-support').install({
try {
var sourceMap = JSON.parse(new Buffer(rawData, 'base64'))
} catch (error) {
console.warn("Error parsing source map", error.stack)
console.warn('Error parsing source map', error.stack)
return null
}

View File

@@ -13,11 +13,11 @@ var defaultOptions = {
var TypeScriptSimple = null
var typescriptVersionDir = null
exports.shouldCompile = function() {
exports.shouldCompile = function () {
return true
}
exports.getCachePath = function(sourceCode) {
exports.getCachePath = function (sourceCode) {
if (typescriptVersionDir == null) {
var version = require('typescript-simple/package.json').version
typescriptVersionDir = path.join('ts', createVersionAndOptionsDigest(version, defaultOptions))
@@ -32,7 +32,7 @@ exports.getCachePath = function(sourceCode) {
)
}
exports.compile = function(sourceCode, filePath) {
exports.compile = function (sourceCode, filePath) {
if (!TypeScriptSimple) {
TypeScriptSimple = require('typescript-simple').TypeScriptSimple
}