Style: Use let/const instead of var

This commit is contained in:
Feross Aboukhadijeh
2016-09-28 15:52:24 -07:00
parent 5623c1024e
commit 76e071e965
5 changed files with 75 additions and 75 deletions

View File

@@ -5,13 +5,13 @@
* Useful for developers. * Useful for developers.
*/ */
var fs = require('fs') const fs = require('fs')
var os = require('os') const os = require('os')
var path = require('path') const path = require('path')
var rimraf = require('rimraf') const rimraf = require('rimraf')
var config = require('../src/config') const config = require('../src/config')
var handlers = require('../src/main/handlers') const handlers = require('../src/main/handlers')
// First, remove generated files // First, remove generated files
rimraf.sync('build/') rimraf.sync('build/')
@@ -21,7 +21,7 @@ rimraf.sync('dist/')
rimraf.sync(config.CONFIG_PATH) rimraf.sync(config.CONFIG_PATH)
// Remove any temporary files // Remove any temporary files
var tmpPath let tmpPath
try { try {
tmpPath = path.join(fs.statSync('/tmp') && '/tmp', 'webtorrent') tmpPath = path.join(fs.statSync('/tmp') && '/tmp', 'webtorrent')
} catch (err) { } catch (err) {

View File

@@ -7,16 +7,16 @@ const path = require('path')
let hasErrors = false let hasErrors = false
// Find all Javascript source files // Find all Javascript source files
var files = walkSync('src', {globs: ['**/*.js']}) const files = walkSync('src', {globs: ['**/*.js']})
console.log('Running extra-lint on ' + files.length + ' files...') console.log('Running extra-lint on ' + files.length + ' files...')
// Read each file, line by line // Read each file, line by line
files.forEach(function (file) { files.forEach(function (file) {
var filepath = path.join('src', file) const filepath = path.join('src', file)
var lines = fs.readFileSync(filepath, 'utf8').split('\n') const lines = fs.readFileSync(filepath, 'utf8').split('\n')
lines.forEach(function (line, i) { lines.forEach(function (line, i) {
var error let error
// Consistent JSX tag closing // Consistent JSX tag closing
if (line.match(/' {2}\/> *$/) || if (line.match(/' {2}\/> *$/) ||

View File

@@ -1,6 +1,6 @@
#!/usr/bin/env node #!/usr/bin/env node
var config = require('../src/config') const config = require('../src/config')
var open = require('open') const open = require('open')
open(config.CONFIG_PATH) open(config.CONFIG_PATH)

View File

@@ -4,25 +4,25 @@
* Builds app binaries for Mac, Windows, and Linux. * Builds app binaries for Mac, Windows, and Linux.
*/ */
var cp = require('child_process') const cp = require('child_process')
var electronPackager = require('electron-packager') const electronPackager = require('electron-packager')
var fs = require('fs') const fs = require('fs')
var minimist = require('minimist') const minimist = require('minimist')
var mkdirp = require('mkdirp') const mkdirp = require('mkdirp')
var os = require('os') const os = require('os')
var path = require('path') const path = require('path')
var rimraf = require('rimraf') const rimraf = require('rimraf')
var series = require('run-series') const series = require('run-series')
var zip = require('cross-zip') const zip = require('cross-zip')
var config = require('../src/config') const config = require('../src/config')
var pkg = require('../package.json') const pkg = require('../package.json')
var BUILD_NAME = config.APP_NAME + '-v' + config.APP_VERSION const BUILD_NAME = config.APP_NAME + '-v' + config.APP_VERSION
var BUILD_PATH = path.join(config.ROOT_PATH, 'build') const BUILD_PATH = path.join(config.ROOT_PATH, 'build')
var DIST_PATH = path.join(config.ROOT_PATH, 'dist') const DIST_PATH = path.join(config.ROOT_PATH, 'dist')
var argv = minimist(process.argv.slice(2), { const argv = minimist(process.argv.slice(2), {
boolean: [ boolean: [
'sign' 'sign'
], ],
@@ -43,7 +43,7 @@ function build () {
cp.execSync('npm run build', { NODE_ENV: 'production', stdio: 'inherit' }) cp.execSync('npm run build', { NODE_ENV: 'production', stdio: 'inherit' })
console.log('Build: Transpiled to ES5.') console.log('Build: Transpiled to ES5.')
var platform = argv._[0] const platform = argv._[0]
if (platform === 'darwin') { if (platform === 'darwin') {
buildDarwin(printDone) buildDarwin(printDone)
} else if (platform === 'win32') { } else if (platform === 'win32') {
@@ -61,7 +61,7 @@ function build () {
} }
} }
var all = { const all = {
// The human-readable copyright line for the app. Maps to the `LegalCopyright` metadata // The human-readable copyright line for the app. Maps to the `LegalCopyright` metadata
// property on Windows, and `NSHumanReadableCopyright` on Mac. // property on Windows, and `NSHumanReadableCopyright` on Mac.
'app-copyright': config.APP_COPYRIGHT, 'app-copyright': config.APP_COPYRIGHT,
@@ -108,7 +108,7 @@ var all = {
version: require('electron/package.json').version version: require('electron/package.json').version
} }
var darwin = { const darwin = {
// Build for Mac // Build for Mac
platform: 'darwin', platform: 'darwin',
@@ -129,7 +129,7 @@ var darwin = {
icon: config.APP_ICON + '.icns' icon: config.APP_ICON + '.icns'
} }
var win32 = { const win32 = {
// Build for Windows. // Build for Windows.
platform: 'win32', platform: 'win32',
@@ -163,7 +163,7 @@ var win32 = {
icon: config.APP_ICON + '.ico' icon: config.APP_ICON + '.ico'
} }
var linux = { const linux = {
// Build for Linux. // Build for Linux.
platform: 'linux', platform: 'linux',
@@ -176,18 +176,18 @@ var linux = {
build() build()
function buildDarwin (cb) { function buildDarwin (cb) {
var plist = require('plist') const plist = require('plist')
console.log('Mac: Packaging electron...') console.log('Mac: Packaging electron...')
electronPackager(Object.assign({}, all, darwin), function (err, buildPath) { electronPackager(Object.assign({}, all, darwin), function (err, buildPath) {
if (err) return cb(err) if (err) return cb(err)
console.log('Mac: Packaged electron. ' + buildPath) console.log('Mac: Packaged electron. ' + buildPath)
var appPath = path.join(buildPath[0], config.APP_NAME + '.app') const appPath = path.join(buildPath[0], config.APP_NAME + '.app')
var contentsPath = path.join(appPath, 'Contents') const contentsPath = path.join(appPath, 'Contents')
var resourcesPath = path.join(contentsPath, 'Resources') const resourcesPath = path.join(contentsPath, 'Resources')
var infoPlistPath = path.join(contentsPath, 'Info.plist') const infoPlistPath = path.join(contentsPath, 'Info.plist')
var infoPlist = plist.parse(fs.readFileSync(infoPlistPath, 'utf8')) const infoPlist = plist.parse(fs.readFileSync(infoPlistPath, 'utf8'))
infoPlist.CFBundleDocumentTypes = [ infoPlist.CFBundleDocumentTypes = [
{ {
@@ -261,7 +261,7 @@ function buildDarwin (cb) {
} }
function signApp (cb) { function signApp (cb) {
var sign = require('electron-osx-sign') const sign = require('electron-osx-sign')
/* /*
* Sign the app with Apple Developer ID certificates. We sign the app for 2 reasons: * Sign the app with Apple Developer ID certificates. We sign the app for 2 reasons:
@@ -276,7 +276,7 @@ function buildDarwin (cb) {
* - Xcode Command Line Tools (xcode-select --install) * - Xcode Command Line Tools (xcode-select --install)
* - Membership in the Apple Developer Program * - Membership in the Apple Developer Program
*/ */
var signOpts = { const signOpts = {
app: appPath, app: appPath,
platform: 'darwin', platform: 'darwin',
verbose: true verbose: true
@@ -302,8 +302,8 @@ function buildDarwin (cb) {
// Create .zip file (used by the auto-updater) // Create .zip file (used by the auto-updater)
console.log('Mac: Creating zip...') console.log('Mac: Creating zip...')
var inPath = path.join(buildPath[0], config.APP_NAME + '.app') const inPath = path.join(buildPath[0], config.APP_NAME + '.app')
var outPath = path.join(DIST_PATH, BUILD_NAME + '-darwin.zip') const outPath = path.join(DIST_PATH, BUILD_NAME + '-darwin.zip')
zip.zipSync(inPath, outPath) zip.zipSync(inPath, outPath)
console.log('Mac: Created zip.') console.log('Mac: Created zip.')
@@ -312,13 +312,13 @@ function buildDarwin (cb) {
function packageDmg (cb) { function packageDmg (cb) {
console.log('Mac: Creating dmg...') console.log('Mac: Creating dmg...')
var appDmg = require('appdmg') const appDmg = require('appdmg')
var targetPath = path.join(DIST_PATH, BUILD_NAME + '.dmg') const targetPath = path.join(DIST_PATH, BUILD_NAME + '.dmg')
rimraf.sync(targetPath) rimraf.sync(targetPath)
// Create a .dmg (Mac disk image) file, for easy user installation. // Create a .dmg (Mac disk image) file, for easy user installation.
var dmgOpts = { const dmgOpts = {
basepath: config.ROOT_PATH, basepath: config.ROOT_PATH,
target: targetPath, target: targetPath,
specification: { specification: {
@@ -339,7 +339,7 @@ function buildDarwin (cb) {
} }
} }
var dmg = appDmg(dmgOpts) const dmg = appDmg(dmgOpts)
dmg.once('error', cb) dmg.once('error', cb)
dmg.on('progress', function (info) { dmg.on('progress', function (info) {
if (info.type === 'step-begin') console.log(info.title + '...') if (info.type === 'step-begin') console.log(info.title + '...')
@@ -353,7 +353,7 @@ function buildDarwin (cb) {
} }
function buildWin32 (cb) { function buildWin32 (cb) {
var installer = require('electron-winstaller') const installer = require('electron-winstaller')
console.log('Windows: Packaging electron...') console.log('Windows: Packaging electron...')
/* /*
@@ -361,7 +361,7 @@ function buildWin32 (cb) {
* - Windows Authenticode private key and cert (authenticode.p12) * - Windows Authenticode private key and cert (authenticode.p12)
* - Windows Authenticode password file (authenticode.txt) * - Windows Authenticode password file (authenticode.txt)
*/ */
var CERT_PATH let CERT_PATH
try { try {
fs.accessSync('D:') fs.accessSync('D:')
CERT_PATH = 'D:' CERT_PATH = 'D:'
@@ -373,12 +373,12 @@ function buildWin32 (cb) {
if (err) return cb(err) if (err) return cb(err)
console.log('Windows: Packaged electron. ' + buildPath) console.log('Windows: Packaged electron. ' + buildPath)
var signWithParams let signWithParams
if (process.platform === 'win32') { if (process.platform === 'win32') {
if (argv.sign) { if (argv.sign) {
var certificateFile = path.join(CERT_PATH, 'authenticode.p12') const certificateFile = path.join(CERT_PATH, 'authenticode.p12')
var certificatePassword = fs.readFileSync(path.join(CERT_PATH, 'authenticode.txt'), 'utf8') const certificatePassword = fs.readFileSync(path.join(CERT_PATH, 'authenticode.txt'), 'utf8')
var timestampServer = 'http://timestamp.comodoca.com' const timestampServer = 'http://timestamp.comodoca.com'
signWithParams = `/a /f "${certificateFile}" /p "${certificatePassword}" /tr "${timestampServer}" /td sha256` signWithParams = `/a /f "${certificateFile}" /p "${certificatePassword}" /tr "${timestampServer}" /td sha256`
} else { } else {
printWarning() printWarning()
@@ -387,9 +387,9 @@ function buildWin32 (cb) {
printWarning() printWarning()
} }
var tasks = [] const tasks = []
buildPath.forEach(function (filesPath) { buildPath.forEach(function (filesPath) {
var destArch = filesPath.split('-').pop() const destArch = filesPath.split('-').pop()
if (argv.package === 'exe' || argv.package === 'all') { if (argv.package === 'exe' || argv.package === 'all') {
tasks.push((cb) => packageInstaller(filesPath, destArch, cb)) tasks.push((cb) => packageInstaller(filesPath, destArch, cb))
@@ -403,7 +403,7 @@ function buildWin32 (cb) {
function packageInstaller (filesPath, destArch, cb) { function packageInstaller (filesPath, destArch, cb) {
console.log(`Windows: Creating ${destArch} installer...`) console.log(`Windows: Creating ${destArch} installer...`)
var archStr = destArch === 'ia32' ? '-ia32' : '' const archStr = destArch === 'ia32' ? '-ia32' : ''
installer.createWindowsInstaller({ installer.createWindowsInstaller({
appDirectory: filesPath, appDirectory: filesPath,
@@ -459,7 +459,7 @@ function buildWin32 (cb) {
console.log('Windows: Renaming ia32 installer files...') console.log('Windows: Renaming ia32 installer files...')
// RELEASES -> RELEASES-ia32 // RELEASES -> RELEASES-ia32
var relPath = path.join(DIST_PATH, 'RELEASES-ia32') const relPath = path.join(DIST_PATH, 'RELEASES-ia32')
fs.renameSync( fs.renameSync(
path.join(DIST_PATH, 'RELEASES'), path.join(DIST_PATH, 'RELEASES'),
relPath relPath
@@ -472,8 +472,8 @@ function buildWin32 (cb) {
) )
// Change file name inside RELEASES-ia32 to match renamed file // Change file name inside RELEASES-ia32 to match renamed file
var relContent = fs.readFileSync(relPath, 'utf8') const relContent = fs.readFileSync(relPath, 'utf8')
var relContent32 = relContent.replace('full.nupkg', 'ia32-full.nupkg') const relContent32 = relContent.replace('full.nupkg', 'ia32-full.nupkg')
fs.writeFileSync(relPath, relContent32) fs.writeFileSync(relPath, relContent32)
if (relContent === relContent32) { if (relContent === relContent32) {
@@ -492,19 +492,19 @@ function buildWin32 (cb) {
function packagePortable (filesPath, destArch, cb) { function packagePortable (filesPath, destArch, cb) {
console.log(`Windows: Creating ${destArch} portable app...`) console.log(`Windows: Creating ${destArch} portable app...`)
var portablePath = path.join(filesPath, 'Portable Settings') const portablePath = path.join(filesPath, 'Portable Settings')
mkdirp.sync(portablePath) mkdirp.sync(portablePath)
var downloadsPath = path.join(portablePath, 'Downloads') const downloadsPath = path.join(portablePath, 'Downloads')
mkdirp.sync(downloadsPath) mkdirp.sync(downloadsPath)
var tempPath = path.join(portablePath, 'Temp') const tempPath = path.join(portablePath, 'Temp')
mkdirp.sync(tempPath) mkdirp.sync(tempPath)
var archStr = destArch === 'ia32' ? '-ia32' : '' const archStr = destArch === 'ia32' ? '-ia32' : ''
var inPath = path.join(DIST_PATH, path.basename(filesPath)) const inPath = path.join(DIST_PATH, path.basename(filesPath))
var outPath = path.join(DIST_PATH, BUILD_NAME + '-win' + archStr + '.zip') const outPath = path.join(DIST_PATH, BUILD_NAME + '-win' + archStr + '.zip')
zip.zipSync(inPath, outPath) zip.zipSync(inPath, outPath)
console.log(`Windows: Created ${destArch} portable app.`) console.log(`Windows: Created ${destArch} portable app.`)
@@ -519,9 +519,9 @@ function buildLinux (cb) {
if (err) return cb(err) if (err) return cb(err)
console.log('Linux: Packaged electron. ' + buildPath) console.log('Linux: Packaged electron. ' + buildPath)
var tasks = [] const tasks = []
buildPath.forEach(function (filesPath) { buildPath.forEach(function (filesPath) {
var destArch = filesPath.split('-').pop() const destArch = filesPath.split('-').pop()
if (argv.package === 'deb' || argv.package === 'all') { if (argv.package === 'deb' || argv.package === 'all') {
tasks.push((cb) => packageDeb(filesPath, destArch, cb)) tasks.push((cb) => packageDeb(filesPath, destArch, cb))
@@ -537,8 +537,8 @@ function buildLinux (cb) {
// Create .deb file for Debian-based platforms // Create .deb file for Debian-based platforms
console.log(`Linux: Creating ${destArch} deb...`) console.log(`Linux: Creating ${destArch} deb...`)
var deb = require('nobin-debian-installer')() const deb = require('nobin-debian-installer')()
var destPath = path.join('/opt', pkg.name) const destPath = path.join('/opt', pkg.name)
deb.pack({ deb.pack({
package: pkg, package: pkg,
@@ -572,10 +572,10 @@ function buildLinux (cb) {
// Create .zip file for Linux // Create .zip file for Linux
console.log(`Linux: Creating ${destArch} zip...`) console.log(`Linux: Creating ${destArch} zip...`)
var archStr = destArch === 'ia32' ? '-ia32' : '' const archStr = destArch === 'ia32' ? '-ia32' : ''
var inPath = path.join(DIST_PATH, path.basename(filesPath)) const inPath = path.join(DIST_PATH, path.basename(filesPath))
var outPath = path.join(DIST_PATH, BUILD_NAME + '-linux' + archStr + '.zip') const outPath = path.join(DIST_PATH, BUILD_NAME + '-linux' + archStr + '.zip')
zip.zipSync(inPath, outPath) zip.zipSync(inPath, outPath)
console.log(`Linux: Created ${destArch} zip.`) console.log(`Linux: Created ${destArch} zip.`)

View File

@@ -72,7 +72,7 @@ function updateCache (state) {
function findPreviousIndex (state) { function findPreviousIndex (state) {
const files = TorrentSummary.getByKey(state, state.playing.infoHash).files const files = TorrentSummary.getByKey(state, state.playing.infoHash).files
for (var i = state.playing.fileIndex - 1; i >= 0; i--) { for (let i = state.playing.fileIndex - 1; i >= 0; i--) {
if (TorrentPlayer.isPlayable(files[i])) return i if (TorrentPlayer.isPlayable(files[i])) return i
} }
return null return null
@@ -80,7 +80,7 @@ function findPreviousIndex (state) {
function findNextIndex (state) { function findNextIndex (state) {
const files = TorrentSummary.getByKey(state, state.playing.infoHash).files const files = TorrentSummary.getByKey(state, state.playing.infoHash).files
for (var i = state.playing.fileIndex + 1; i < files.length; i++) { for (let i = state.playing.fileIndex + 1; i < files.length; i++) {
if (TorrentPlayer.isPlayable(files[i])) return i if (TorrentPlayer.isPlayable(files[i])) return i
} }
return null return null