mirror of
https://github.com/nuxt/nuxt.git
synced 2024-11-27 08:02:01 +00:00
refactor: change function calls when arity is one (#3563)
This commit is contained in:
parent
b5f6ed1332
commit
095404a251
6
bin/nuxt
6
bin/nuxt
@ -4,9 +4,7 @@ const { join } = require('path')
|
|||||||
const consola = require('consola')
|
const consola = require('consola')
|
||||||
|
|
||||||
// Global error handler
|
// Global error handler
|
||||||
process.on('unhandledRejection', _error => {
|
process.on('unhandledRejection', consola.error)
|
||||||
consola.error(_error)
|
|
||||||
})
|
|
||||||
|
|
||||||
// Exit process on fatal errors
|
// Exit process on fatal errors
|
||||||
consola.add({
|
consola.add({
|
||||||
@ -21,7 +19,7 @@ consola.add({
|
|||||||
const defaultCommand = 'dev'
|
const defaultCommand = 'dev'
|
||||||
const commands = new Set([defaultCommand, 'init', 'build', 'start', 'generate'])
|
const commands = new Set([defaultCommand, 'init', 'build', 'start', 'generate'])
|
||||||
|
|
||||||
var cmd = process.argv[2]
|
let cmd = process.argv[2]
|
||||||
|
|
||||||
if (commands.has(cmd)) {
|
if (commands.has(cmd)) {
|
||||||
process.argv.splice(2, 1)
|
process.argv.splice(2, 1)
|
||||||
|
@ -51,7 +51,7 @@ const nuxt = new Nuxt(options)
|
|||||||
const builder = new Builder(nuxt)
|
const builder = new Builder(nuxt)
|
||||||
|
|
||||||
// Setup hooks
|
// Setup hooks
|
||||||
nuxt.hook('error', (_err) => consola.fatal(_err))
|
nuxt.hook('error', consola.fatal)
|
||||||
|
|
||||||
// Close function
|
// Close function
|
||||||
const close = () => {
|
const close = () => {
|
||||||
@ -68,12 +68,12 @@ if (options.mode !== 'spa' || argv.generate === false) {
|
|||||||
// Build only
|
// Build only
|
||||||
builder
|
builder
|
||||||
.build()
|
.build()
|
||||||
.then(() => close())
|
.then(close)
|
||||||
.catch(error => consola.fatal(error))
|
.catch(consola.fatal)
|
||||||
} else {
|
} else {
|
||||||
// Build + Generate for static deployment
|
// Build + Generate for static deployment
|
||||||
new Generator(nuxt, builder)
|
new Generator(nuxt, builder)
|
||||||
.generate({ build: true })
|
.generate({ build: true })
|
||||||
.then(() => close())
|
.then(close)
|
||||||
.catch(error => consola.fatal(error))
|
.catch(consola.fatal)
|
||||||
}
|
}
|
||||||
|
@ -115,7 +115,7 @@ function startDev(oldInstance) {
|
|||||||
}
|
}
|
||||||
})
|
})
|
||||||
// Start build
|
// Start build
|
||||||
.then(() => builder.build())
|
.then(builder.build)
|
||||||
// Close old nuxt after successful build
|
// Close old nuxt after successful build
|
||||||
.then(
|
.then(
|
||||||
() =>
|
() =>
|
||||||
|
@ -53,4 +53,4 @@ generator
|
|||||||
.then(() => {
|
.then(() => {
|
||||||
process.exit(0)
|
process.exit(0)
|
||||||
})
|
})
|
||||||
.catch(error => consola.fatal(error))
|
.catch(consola.fatal)
|
||||||
|
@ -52,7 +52,7 @@ options.dev = false
|
|||||||
const nuxt = new Nuxt(options)
|
const nuxt = new Nuxt(options)
|
||||||
|
|
||||||
// Setup hooks
|
// Setup hooks
|
||||||
nuxt.hook('error', (_err) => consola.fatal(_err))
|
nuxt.hook('error', consola.fatal)
|
||||||
|
|
||||||
// Check if project is built for production
|
// Check if project is built for production
|
||||||
const distDir = resolve(
|
const distDir = resolve(
|
||||||
|
@ -15,7 +15,7 @@ Vue.component('my-button', MyButton)
|
|||||||
const req = require.context('../stories', true, /.story.js$/)
|
const req = require.context('../stories', true, /.story.js$/)
|
||||||
|
|
||||||
function loadStories() {
|
function loadStories() {
|
||||||
req.keys().forEach((filename) => req(filename))
|
req.keys().forEach(req)
|
||||||
}
|
}
|
||||||
|
|
||||||
configure(loadStories, module)
|
configure(loadStories, module)
|
||||||
|
@ -9,9 +9,9 @@ import DoughnutChart from '~/components/doughnut-chart'
|
|||||||
import axios from 'axios'
|
import axios from 'axios'
|
||||||
|
|
||||||
function getRandomColor() {
|
function getRandomColor() {
|
||||||
var letters = '0123456789ABCDEF'
|
const letters = '0123456789ABCDEF'
|
||||||
var color = '#'
|
let color = '#'
|
||||||
for (var i = 0; i < 6; i++) {
|
for (let i = 0; i < 6; i++) {
|
||||||
color += letters[Math.floor(Math.random() * 16)]
|
color += letters[Math.floor(Math.random() * 16)]
|
||||||
}
|
}
|
||||||
return color
|
return color
|
||||||
@ -26,8 +26,8 @@ export default {
|
|||||||
datasets: [
|
datasets: [
|
||||||
{
|
{
|
||||||
label: 'Nuxt.js Contributors',
|
label: 'Nuxt.js Contributors',
|
||||||
backgroundColor: res.data.map(() => getRandomColor()),
|
backgroundColor: res.data.map(getRandomColor),
|
||||||
data: res.data.map((stat) => 1)
|
data: res.data.map(() => 1)
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
@ -5,7 +5,7 @@ import app from '../src/app'
|
|||||||
describe('Feathers application tests', function () {
|
describe('Feathers application tests', function () {
|
||||||
before(function (done) {
|
before(function (done) {
|
||||||
this.server = app.listen(3030)
|
this.server = app.listen(3030)
|
||||||
this.server.once('listening', () => done())
|
this.server.once('listening', done)
|
||||||
})
|
})
|
||||||
|
|
||||||
after(function (done) {
|
after(function (done) {
|
||||||
|
@ -8,7 +8,7 @@ export default function () {
|
|||||||
// overwrite nuxt.listen()
|
// overwrite nuxt.listen()
|
||||||
this.nuxt.listen = (port, host) => new Promise((resolve) => server.listen(port || 3000, host || 'localhost', resolve))
|
this.nuxt.listen = (port, host) => new Promise((resolve) => server.listen(port || 3000, host || 'localhost', resolve))
|
||||||
// close this server on 'close' event
|
// close this server on 'close' event
|
||||||
this.nuxt.hook('close', () => new Promise((resolve) => server.close(resolve)))
|
this.nuxt.hook('close', () => new Promise(server.close))
|
||||||
|
|
||||||
// Add socket.io events
|
// Add socket.io events
|
||||||
let messages = []
|
let messages = []
|
||||||
|
@ -155,7 +155,7 @@ export async function setContext(app, context) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (process.server) app.context.beforeNuxtRender = (fn) => context.beforeRenderFns.push(fn)
|
if (process.server) app.context.beforeNuxtRender = fn => context.beforeRenderFns.push(fn)
|
||||||
if (process.client) app.context.nuxtState = window.__NUXT__
|
if (process.client) app.context.nuxtState = window.__NUXT__
|
||||||
}
|
}
|
||||||
// Dynamic keys
|
// Dynamic keys
|
||||||
|
@ -47,7 +47,7 @@ export default class Builder {
|
|||||||
|
|
||||||
// Stop watching on nuxt.close()
|
// Stop watching on nuxt.close()
|
||||||
if (this.options.dev) {
|
if (this.options.dev) {
|
||||||
this.nuxt.hook('close', () => this.unwatch())
|
this.nuxt.hook('close', this.unwatch)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Initialize shared FS and Cache
|
// Initialize shared FS and Cache
|
||||||
@ -57,7 +57,7 @@ export default class Builder {
|
|||||||
|
|
||||||
// if(!this.options.dev) {
|
// if(!this.options.dev) {
|
||||||
// TODO: enable again when unsafe concern resolved.(common/options.js:42)
|
// TODO: enable again when unsafe concern resolved.(common/options.js:42)
|
||||||
// this.nuxt.hook('build:done', () => this.generateConfig())
|
// this.nuxt.hook('build:done', this.generateConfig)
|
||||||
// }
|
// }
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -599,7 +599,7 @@ export default class Builder {
|
|||||||
r(src, `${this.options.dir.pages}/**/*.{vue,js}`)
|
r(src, `${this.options.dir.pages}/**/*.{vue,js}`)
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
patterns = _.map(patterns, p => upath.normalizeSafe(p))
|
patterns = _.map(patterns, upath.normalizeSafe)
|
||||||
|
|
||||||
const options = Object.assign({}, this.options.watchers.chokidar, {
|
const options = Object.assign({}, this.options.watchers.chokidar, {
|
||||||
ignoreInitial: true
|
ignoreInitial: true
|
||||||
@ -618,9 +618,7 @@ export default class Builder {
|
|||||||
this.options.build.watch,
|
this.options.build.watch,
|
||||||
..._.values(_.omit(this.options.build.styleResources, ['options']))
|
..._.values(_.omit(this.options.build.styleResources, ['options']))
|
||||||
)
|
)
|
||||||
customPatterns = _.map(_.uniq(customPatterns), p =>
|
customPatterns = _.map(_.uniq(customPatterns), upath.normalizeSafe)
|
||||||
upath.normalizeSafe(p)
|
|
||||||
)
|
|
||||||
this.customFilesWatcher = chokidar
|
this.customFilesWatcher = chokidar
|
||||||
.watch(customPatterns, options)
|
.watch(customPatterns, options)
|
||||||
.on('change', refreshFiles)
|
.on('change', refreshFiles)
|
||||||
|
@ -31,6 +31,6 @@ export const onEmit = (compiler, name, hook) => {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export const isJS = (file) => /\.js(\?[^.]+)?$/.test(file)
|
export const isJS = file => /\.js(\?[^.]+)?$/.test(file)
|
||||||
|
|
||||||
export const isCSS = (file) => /\.css(\?[^.]+)?$/.test(file)
|
export const isCSS = file => /\.css(\?[^.]+)?$/.test(file)
|
||||||
|
@ -65,7 +65,7 @@ Options.from = function (_options) {
|
|||||||
options.modulesDir = []
|
options.modulesDir = []
|
||||||
.concat(options.modulesDir)
|
.concat(options.modulesDir)
|
||||||
.concat(path.join(options.nuxtDir, 'node_modules'))
|
.concat(path.join(options.nuxtDir, 'node_modules'))
|
||||||
.filter(dir => hasValue(dir))
|
.filter(hasValue)
|
||||||
.map(dir => path.resolve(options.rootDir, dir))
|
.map(dir => path.resolve(options.rootDir, dir))
|
||||||
|
|
||||||
// Sanitize extensions
|
// Sanitize extensions
|
||||||
|
@ -82,7 +82,7 @@ export const sequence = function sequence(tasks, fn) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export const parallel = function parallel(tasks, fn) {
|
export const parallel = function parallel(tasks, fn) {
|
||||||
return Promise.all(tasks.map(task => fn(task)))
|
return Promise.all(tasks.map(fn))
|
||||||
}
|
}
|
||||||
|
|
||||||
export const chainFn = function chainFn(base, fn) {
|
export const chainFn = function chainFn(base, fn) {
|
||||||
|
Loading…
Reference in New Issue
Block a user