Commit 6e409a33 authored by Ekaitz Zárraga's avatar Ekaitz Zárraga

Remove some unneded () and style touches

parent 709add66
......@@ -14,10 +14,10 @@ program = require 'commander'
exec = require('child_process').exec
slug = require('slug')
swig = require('swig')
slug = require 'slug'
swig = require 'swig'
moment = require('moment')
moment = require 'moment'
marked = require 'marked'
Express = require 'express'
path = require 'path'
......@@ -55,18 +55,18 @@ fsExistsAsync = (filePath)->
# Note: accord uses when.js and the promises are compatible with bluebird.
# ==== (see http://promisesaplus.com/implementations)
accord = require 'accord'
stylus = accord.load('stylus')
stylus = accord.load 'stylus'
# Promise.promisifyAll doesn’t work with imagemin.
# The only method we’re using is the .optimize() method so let’s just promisify that.
Imagemin = require('imagemin')
Imagemin = require 'imagemin'
Imagemin.prototype.optimizeAsync = Promise.promisify(Imagemin.prototype.run)
# Exec
execAsync = Promise.promisify(exec)
fs = Promise.promisifyAll(require('fs-extra'))
fs = Promise.promisifyAll(require 'fs-extra')
# Roll our own promise for kit — Promise.promisify isn’t working on
# the kit function (maybe because it is synchronous?)
......@@ -79,7 +79,7 @@ kitAsync = (str) ->
)
)
globAsync = Promise.promisify(require('glob'))
globAsync = Promise.promisify(require 'glob')
......@@ -185,7 +185,7 @@ shortFilePath = (filePath) ->
logCompileMessage = (event, filePath) ->
if event != 'build'
log ('— ' + moment().format('dddd, D MMM @ H:m: ') + 'Compiled ' + shortFilePath(filePath) + ' (' + event + ')\n')
log "— #{moment().format('dddd, D MMM @ H:m: ')} Compiled #{shortFilePath(filePath)} (#{event}) + \n"
......@@ -369,7 +369,7 @@ processSourceFile = (event, filePath) ->
#
if stats.isDirectory() and event is not 'build'
if event is 'changed' or event is 'added' or event is 'renamed'
if event in ['changed' , 'added' , 'renamed']
return copyFile event, filePath
else if event is 'trashed'
......@@ -381,14 +381,14 @@ processSourceFile = (event, filePath) ->
#
else if stats.isFile()
ext = path.extname(filePath)
ext = path.extname filePath
#
# File should be processed if it is changed, added, or renamed.
# If we don’t know what to do with a file with the given
# extension, we simply copy it over. (Better Safe Than Sorry™)
#
if event is 'build' or event is 'changed' or event is 'added' or event is 'renamed'
if event in ['build', 'changed', 'added', 'renamed']
#
# Calculate the files’s new MD5 checksum and add it to the cache
......@@ -428,7 +428,7 @@ processSourceFile = (event, filePath) ->
matches = filePath.match(basePathOfSourceFolderRegExp)
if matches == null
log 'WARNING: Source folder not found in changed Stylus path ('+filePath+'). This should never happen. Not compiling.'
log "WARNING: Source folder not found in changed Stylus path (#{filePath}). This should never happen. Not compiling."
else
#
# Compile the main stylus file and the current stylus file…
......@@ -450,9 +450,9 @@ processSourceFile = (event, filePath) ->
# (e.g., Pulse logo)
#
else if (ext is '.jpg') or (ext is '.jpeg') or (ext is '.png') or (ext is '.gif') #or (ext is '.svg')
else if ext in ['.jpg', '.jpeg', '.png', '.gif'] #or (ext is '.svg')
verbose 'Image changed: ' + filePath
compileImageFile(event, filePath)
compileImageFile event, filePath
#
# Catchall: simply copy the file over.
......@@ -540,9 +540,9 @@ buildSite = (options) ->
# log 'Checking cache for file: ' + cachePath
skipCache = false
pathExtension = path.extname(cachePath)
pathExtension = path.extname cachePath
if options == 'partials'
skipCache = pathExtension == '.html' || pathExtension == '.styl'
skipCache = pathExtension == '.html' or pathExtension == '.styl'
else if options != undefined
skipCache = pathExtension == options
......@@ -555,32 +555,31 @@ buildSite = (options) ->
if stats.isFile()
fs.readFileAsync(cachePath).then (cacheMD5) ->
fs.readFileAsync(filePath).then (currentFileContents) ->
currentFileMD5 = checksum(currentFileContents)
currentFileMD5 = checksum currentFileContents
# log ' Cache MD5: ' + cacheMD5
# log 'Current MD5: ' + currentFileMD5
if cacheMD5.toString() == currentFileMD5.toString()
# log 'Files are the same.'
progressBar.tick({title: 'Unchanged: ' + file})
progressBar.tick title: 'Unchanged: ' + file
return
else
# log 'File has changed, processing…'
processSourceFile('build', filePath).then ->
progressBar.tick({title: file})
progressBar.tick title: file
else
# log 'This is a folder, skipping…'
progressBar.tick({title: 'Folder: ' + file})
progressBar.tick title: 'Folder: ' + file
else
# log 'No cache file found, processing…'
processSourceFile('build', filePath).then ->
progressBar.tick({title: file})
progressBar.tick title: file
.then =>
message = '\n' + (chalk.green.inverse 'Build complete.') + '\n'
log message
.catch ((e)->
.catch (e)->
console.log 'Error: ' + e
)
######################################################################
......@@ -594,9 +593,9 @@ buildSite = (options) ->
######################################################################
compilers =
'copy': copyFile,
'kit': compileKitFile,
'image': compileImageFile,
'copy': copyFile,
'kit': compileKitFile,
'image': compileImageFile,
'stylus': compileStylusFile,
'delete': deleteFile
......@@ -610,7 +609,7 @@ deleteFile = (filePath) ->
ext = path.extname filePath
if ext is '.styl'
outputFilePath = outputFilePath.replace('stylus', 'css')
outputFilePath = outputFilePath.replace 'stylus', 'css'
fs.removeAsync outputFilePath
.then ->
......@@ -622,10 +621,10 @@ deleteFile = (filePath) ->
#
copyFile = (event, filePath) ->
outputFilePath = getOutputPath(filePath)
outputFilePath = getOutputPath filePath
if !program.dryRun
return fs.copyAsync(filePath, outputFilePath)
return fs.copyAsync filePath, outputFilePath
else
log 'Dry run: copy ' + filePath + ' to ' + outputFilePath
# Return a fulfilled promise
......@@ -638,7 +637,7 @@ copyFile = (event, filePath) ->
compileImageFile = (event, filePath) ->
outputFilePath = getOutputPath(filePath)
outputFilePath = getOutputPath filePath
if !program.dryRun
return fs.ensureFileAsync(outputFilePath).then( ->
......@@ -646,7 +645,7 @@ compileImageFile = (event, filePath) ->
imageMin = new Imagemin()
.use(Imagemin.jpegtran())
.src(filePath)
.dest(path.dirname(outputFilePath))
.dest(path.dirname outputFilePath )
ext = path.extname filePath
......@@ -685,9 +684,8 @@ compileKitFile = (event, filePath) ->
return kitAsync(filePath)
.then (html) ->
return writeFileAsync event, filePath, '', '', '', '', html
.catch ((e) ->
.catch (e) ->
log (chalk.yellow.inverse 'Kit error: ') + e
)
#
......@@ -716,7 +714,7 @@ compileStylusFile = (event, filePath) ->
#
getOutputPath = (filePath) ->
return filePath.replace('source', 'build')
return filePath.replace 'source', 'build'
#
......@@ -736,7 +734,7 @@ writeFileAsync = (event, filePath, oldFolder, newFolder, oldExtension, newExtens
if !program.dryRun
fs.ensureFileAsync(outputFilePath).then( ->
fs.writeFileAsync(outputFilePath, content).then( ->
logCompileMessage(event, filePath)
logCompileMessage event, filePath
)
)
else
......@@ -866,7 +864,7 @@ parseCommand = (commandString) ->
# Create an array as would argv so we can use Commander’s parser
# (so we don’t create redundancy in parsing commands)
# Regex courtesy of http://stackoverflow.com/questions/13796594/how-to-split-string-into-arguments-and-options-in-javascript#comment21935456_13796877
commandArray = commandString.match(/('(\\'|[^'])*'|"(\\"|[^"])*"|\/(\\\/|[^\/])*\/|(\\ |[^ ])+|[\w-]+)/g)
commandArray = commandString.match /('(\\'|[^'])*'|"(\\"|[^"])*"|\/(\\\/|[^\/])*\/|(\\ |[^ ])+|[\w-]+)/g
# Hack: Add a dummy process name and path to make it look exactly like an argv array
# for Commander (who will splice out the first two elements anyway)
......@@ -906,7 +904,7 @@ if process.argv.length == 2 || (process.argv.length == 3 && program.dryRun)
log welcomeMessage
else
# Goodbye!
process.exit(0)
process.exit 0
######################################################################
......@@ -915,14 +913,14 @@ else
#
######################################################################
livereload = require('express-livereload')
livereload = require 'express-livereload'
buildServer = null
buildServerDaemon = null
createBuildServer = ->
buildServer = new Express()
buildServer.use Express.static 'build/'
livereload(buildServer, config={watchDir: 'build/'})
livereload buildServer, config= watchDir: 'build/'
buildServer.use (require('connect-livereload')({
port: 35729
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment