Skip to content
This repository has been archived by the owner on Apr 30, 2019. It is now read-only.

Commit

Permalink
Use const whenever possible
Browse files Browse the repository at this point in the history
  • Loading branch information
akyoto committed Nov 15, 2016
1 parent fa87bbe commit 4e22010
Show file tree
Hide file tree
Showing 41 changed files with 110 additions and 87 deletions.
3 changes: 1 addition & 2 deletions default/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ module.exports = {
},
ports: {
http: 4000,
https: 4001,
liveReload: 9000
https: 4001
}
}
2 changes: 1 addition & 1 deletion lib/App/checkRoute.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
let requester = Promise.promisifyAll(require('request'))
const requester = Promise.promisifyAll(require('request'))

module.exports = function*(method, route) {
// The purpose of this function is only to write stuff to the console.
Expand Down
8 changes: 4 additions & 4 deletions lib/App/createDirectories.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
let path = require('path')
let chalk = require('chalk')
let fs = Promise.promisifyAll(require('fs'))
let mkdir = Promise.promisify(require('mkdirp'))
const path = require('path')
const chalk = require('chalk')
const fs = Promise.promisifyAll(require('fs'))
const mkdir = Promise.promisify(require('mkdirp'))

let touchFile = function(filePath, contents, encoding) {
return fs.statAsync(filePath).catch(error => {
Expand Down
14 changes: 7 additions & 7 deletions lib/App/index.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
let path = require('path')
let chalk = require('chalk')
let Server = require('../Server')
let Linter = require('../Linter')
let MarkdownIt = require('markdown-it')
let loadClass = require('../loadClass')
let aeroPackage = require('../../package.json')
const path = require('path')
const chalk = require('chalk')
const Server = require('../Server')
const Linter = require('../Linter')
const MarkdownIt = require('markdown-it')
const loadClass = require('../loadClass')
const aeroPackage = require('../../package.json')

class App {
constructor(root) {
Expand Down
2 changes: 1 addition & 1 deletion lib/App/initEvents.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
let EventEmitter = require('events').EventEmitter
const EventEmitter = require('events').EventEmitter

module.exports = function() {
this.events = new EventEmitter()
Expand Down
2 changes: 1 addition & 1 deletion lib/App/loadCache.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
let fs = Promise.promisifyAll(require('fs'))
const fs = Promise.promisifyAll(require('fs'))
const outdatedCacheMessage = 'Ignoring cache from an old Aero version'

module.exports = function*() {
Expand Down
8 changes: 4 additions & 4 deletions lib/App/loadCertificate.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
let fs = Promise.promisifyAll(require('fs'))
let pem = Promise.promisifyAll(require('pem'))
let path = require('path')
const fs = Promise.promisifyAll(require('fs'))
const pem = Promise.promisifyAll(require('pem'))
const path = require('path')

let isCertificate = file => file.content.startsWith('-----BEGIN CERTIFICATE-----')
let isPrivateKey = file => file.content.indexOf('PRIVATE KEY-----') !== -1
Expand All @@ -23,7 +23,7 @@ module.exports = function*(filePath, fallback, options) {
.catch(error => {
if(error.code === 'ENOENT')
return

throw error
})

Expand Down
11 changes: 10 additions & 1 deletion lib/App/loadConfig.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
const defaultConfig = require('../../default/config')
const chalk = require('chalk')

module.exports = function*() {
let configForEmptyApp = Object.assign({}, defaultConfig)
Expand All @@ -8,8 +9,16 @@ module.exports = function*() {

let configPath = this.path('config.json')
let configText = yield this.loadFile(configPath, configForEmptyApp)
let userConfig = JSON.parse(configText)

this.config = Object.assign({}, defaultConfig, userConfig)

// Auto-correct deprecated fields
if(this.config.ports && this.config.ports.liveReload) {
delete this.config.ports.liveReload
require('fs').writeFileSync(configPath, JSON.stringify(userConfig, null, '\t'))
}

this.config = Object.assign({}, defaultConfig, JSON.parse(configText))
Object.freeze(this.config)

this.events.emit('config loaded')
Expand Down
2 changes: 1 addition & 1 deletion lib/App/loadController.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
let path = require('path')
const path = require('path')

module.exports = function(controllerPath) {
// Delete existing controller from cache
Expand Down
4 changes: 2 additions & 2 deletions lib/App/loadDirectory.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
let fs = Promise.promisifyAll(require('fs'))
let path = require('path')
const fs = Promise.promisifyAll(require('fs'))
const path = require('path')

// We load all files in the directory but
// we want to prioritize the loading order specified
Expand Down
2 changes: 1 addition & 1 deletion lib/App/loadFile.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
let fs = Promise.promisifyAll(require('fs'))
const fs = Promise.promisifyAll(require('fs'))

module.exports = function*(filePath, fallback, options) {
options = options || {}
Expand Down
2 changes: 1 addition & 1 deletion lib/App/loadFonts.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
let request = Promise.promisifyAll(require('request'))
const request = Promise.promisifyAll(require('request'))

const maxRetries = 5

Expand Down
6 changes: 3 additions & 3 deletions lib/App/loadIcons.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
let fs = Promise.promisifyAll(require('fs'))
let getMIMEType = require('mime-types').lookup
let sizeOf = require('image-size')
const fs = Promise.promisifyAll(require('fs'))
const getMIMEType = require('mime-types').lookup
const sizeOf = require('image-size')

module.exports = function*() {
try {
Expand Down
2 changes: 1 addition & 1 deletion lib/App/loadJSON.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
let fs = Promise.promisifyAll(require('fs'))
const fs = Promise.promisifyAll(require('fs'))

module.exports = function*(file) {
try {
Expand Down
2 changes: 1 addition & 1 deletion lib/App/loadLayout.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
let Layout = require('../Layout')
const Layout = require('../Layout')

module.exports = function*() {
this.time('Layout')
Expand Down
6 changes: 3 additions & 3 deletions lib/App/loadPage.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
let fs = Promise.promisifyAll(require('fs'))
let path = require('path')
let Page = require('../Page')
const fs = Promise.promisifyAll(require('fs'))
const path = require('path')
const Page = require('../Page')
const windowsSlash = /\\/g

module.exports = function*(pageId, root) {
Expand Down
6 changes: 3 additions & 3 deletions lib/App/loadPages.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
let fs = Promise.promisifyAll(require('fs'))
let mkdir = Promise.promisify(require('mkdirp'))
let path = require('path')
const fs = Promise.promisifyAll(require('fs'))
const mkdir = Promise.promisify(require('mkdirp'))
const path = require('path')

let findPages = Promise.coroutine(function*(rootPath) {
let dirs =
Expand Down
4 changes: 2 additions & 2 deletions lib/App/loadScript.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
let fs = Promise.promisifyAll(require('fs'))
let path = require('path')
const fs = Promise.promisifyAll(require('fs'))
const path = require('path')

module.exports = function*(file) {
file = path.resolve(file)
Expand Down
2 changes: 1 addition & 1 deletion lib/App/loadStartup.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
let fs = require('fs')
const fs = require('fs')

module.exports = function() {
// TODO: Delete require.cache
Expand Down
8 changes: 4 additions & 4 deletions lib/App/loadStyle.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
let fs = Promise.promisifyAll(require('fs'))
let path = require('path')
let stylus = require('stylus')
let autoprefixer = require('autoprefixer-stylus')
const fs = Promise.promisifyAll(require('fs'))
const path = require('path')
const stylus = require('stylus')
const autoprefixer = require('autoprefixer-stylus')

module.exports = function*(file) {
file = path.resolve(file)
Expand Down
4 changes: 2 additions & 2 deletions lib/App/loadStyles.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
let fs = Promise.promisifyAll(require('fs'))
let path = require('path')
const fs = Promise.promisifyAll(require('fs'))
const path = require('path')

module.exports = function*() {
let globalStylePath = path.resolve(path.join(this.root, this.config.path.styles, 'config' + this.fileExtension.styles))
Expand Down
4 changes: 2 additions & 2 deletions lib/App/loadTemplate.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
let fs = Promise.promisifyAll(require('fs'))
let pug = require('pug')
const fs = Promise.promisifyAll(require('fs'))
const pug = require('pug')

module.exports = function*(file) {
try {
Expand Down
2 changes: 1 addition & 1 deletion lib/App/loadText.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
let fs = Promise.promisifyAll(require('fs'))
const fs = Promise.promisifyAll(require('fs'))

module.exports = function*(file) {
try {
Expand Down
2 changes: 1 addition & 1 deletion lib/App/minifyScripts.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
let uglifyJS = require('uglify-js-harmony')
const uglifyJS = require('uglify-js-harmony')

const uglifyJSOptions = {
fromString: true,
Expand Down
2 changes: 1 addition & 1 deletion lib/App/registerEventListeners.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
let path = require('path')
const path = require('path')

module.exports = function() {
// Layout modifications
Expand Down
4 changes: 2 additions & 2 deletions lib/App/routePage.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
let xxhash = require('xxhash')
let zlib = require('zlib')
const xxhash = require('xxhash')
const zlib = require('zlib')

// This should be close to the MTU size of a TCP packet.
// Regarding performance it makes no sense to compress smaller files.
Expand Down
2 changes: 1 addition & 1 deletion lib/App/saveCache.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
let fs = Promise.promisifyAll(require('fs'))
const fs = Promise.promisifyAll(require('fs'))

module.exports = function() {
if(!this.cache)
Expand Down
2 changes: 1 addition & 1 deletion lib/App/startLiveReload.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
let LiveReload = require('../LiveReload')
const LiveReload = require('../LiveReload')

module.exports = function() {
if(this.production)
Expand Down
6 changes: 3 additions & 3 deletions lib/App/watchFiles.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
let path = require('path')
let fs = require('fs')
let nodeWatch = require('node-watch')
const path = require('path')
const fs = require('fs')
const nodeWatch = require('node-watch')

let watch = function(fileName, callback, recursive) {
nodeWatch(fileName, {
Expand Down
4 changes: 2 additions & 2 deletions lib/Layout/index.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
let loadClass = require('../loadClass')
let path = require('path')
const loadClass = require('../loadClass')
const path = require('path')

class Layout {
constructor(app, layoutPath) {
Expand Down
4 changes: 2 additions & 2 deletions lib/Layout/load.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
let fs = Promise.promisifyAll(require('fs'))
let path = require('path')
const fs = Promise.promisifyAll(require('fs'))
const path = require('path')

module.exports = function*() {
let components = yield {
Expand Down
29 changes: 22 additions & 7 deletions lib/LiveReload/index.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
let WebSocket = require('uws')
let UglifyJS = require('uglify-js-harmony')
let chalk = require('chalk')
let scriptPath = require.resolve('./reload.client.js')
const WebSocket = require('uws')
const UglifyJS = require('uglify-js-harmony')
const chalk = require('chalk')
const scriptPath = require.resolve('./reload.client.js')

class LiveReload {
constructor(app) {
Expand All @@ -13,19 +13,32 @@ class LiveReload {
this.protocol = 'ws'
}

this.port = app.config.ports.liveReload
this.script = UglifyJS.minify(scriptPath, {
this.port = 45032

this.scriptCode = UglifyJS.minify(scriptPath, {
compress: {
screw_ie8: true
},
mangle: {
screw_ie8: true
}
}).code.replace('${protocol}', this.protocol).replace('${port}', this.port)
}).code.replace('${protocol}', this.protocol)

// Keep track of sockets to destroy them later
this.trackConnections(this.http, this)

// Automatically find an open port when listening fails
this.http.on('error', error => {
this.findPort()
})

// Listen
this.findPort()
}

findPort() {
this.port += 1

// Listen
this.http.listen(this.port, error => {
if(error)
Expand All @@ -34,6 +47,8 @@ class LiveReload {
this.server = new WebSocket.Server({
server: this.http
})

this.script = this.scriptCode.replace('${port}', this.port)
})
}

Expand Down
4 changes: 2 additions & 2 deletions lib/Page/index.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
let loadClass = require('../loadClass')
let path = require('path')
const loadClass = require('../loadClass')
const path = require('path')

class Page {
constructor(app, id, realPath) {
Expand Down
6 changes: 3 additions & 3 deletions lib/Page/load.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
let fs = Promise.promisifyAll(require('fs'))
let path = require('path')
let chalk = require('chalk')
const fs = Promise.promisifyAll(require('fs'))
const path = require('path')
const chalk = require('chalk')

let freezeCurrentProperties = function(obj) {
for(let i in obj) {
Expand Down
2 changes: 1 addition & 1 deletion lib/Server/index.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
let loadClass = require('../loadClass')
const loadClass = require('../loadClass')

require('./response')

Expand Down
2 changes: 1 addition & 1 deletion lib/Server/onRequest.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
let querystring = require('querystring')
const querystring = require('querystring')

const emptyArray = []

Expand Down
2 changes: 1 addition & 1 deletion lib/Server/response/json.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
let http = require('http')
const http = require('http')

http.ServerResponse.prototype.json = function(data) {
if(!this.headersSent) {
Expand Down
2 changes: 1 addition & 1 deletion lib/Server/response/redirect.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
let http = require('http')
const http = require('http')

http.ServerResponse.prototype.redirect = function(url, status) {
this.writeHead(status || 302, {
Expand Down
8 changes: 4 additions & 4 deletions lib/Server/response/sendFile.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
let http = require('http')
let fs = require('fs')
let path = require('path')
let getMIMEType = require('mime-types').lookup
const http = require('http')
const fs = require('fs')
const path = require('path')
const getMIMEType = require('mime-types').lookup

http.ServerResponse.prototype.sendFile = function(file) {
fs.stat(file, (statError, stats) => {
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "aero",
"version": "2.0.2",
"version": "2.0.3",
"description": "The fastest node.js framework.",
"repository": "aerojs/aero",
"homepage": "https://github.com/aerojs/aero",
Expand Down
Loading

0 comments on commit 4e22010

Please sign in to comment.