mirror of
https://github.com/nuxt/nuxt.git
synced 2024-11-22 05:35:13 +00:00
style: lint
This commit is contained in:
parent
38e72f86c2
commit
c1188eebd5
@ -8,6 +8,7 @@ import hash from 'hash-sum'
|
|||||||
import pify from 'pify'
|
import pify from 'pify'
|
||||||
import upath from 'upath'
|
import upath from 'upath'
|
||||||
import semver from 'semver'
|
import semver from 'semver'
|
||||||
|
import type { RouteLocationRaw } from 'vue-router'
|
||||||
|
|
||||||
import debounce from 'lodash/debounce'
|
import debounce from 'lodash/debounce'
|
||||||
import omit from 'lodash/omit'
|
import omit from 'lodash/omit'
|
||||||
@ -36,7 +37,6 @@ import {
|
|||||||
import Ignore from './ignore'
|
import Ignore from './ignore'
|
||||||
import BuildContext from './context/build'
|
import BuildContext from './context/build'
|
||||||
import TemplateContext from './context/template'
|
import TemplateContext from './context/template'
|
||||||
import { RouteLocationRaw } from 'vue-router'
|
|
||||||
|
|
||||||
const glob = pify(Glob)
|
const glob = pify(Glob)
|
||||||
export default class Builder {
|
export default class Builder {
|
||||||
|
@ -17,7 +17,7 @@ export default class TemplateContext {
|
|||||||
nuxtOptions: options,
|
nuxtOptions: options,
|
||||||
features: options.features,
|
features: options.features,
|
||||||
extensions: options.extensions
|
extensions: options.extensions
|
||||||
.map(ext => ext.replace(/^\./, ''))
|
.map((ext: string) => ext.replace(/^\./, ''))
|
||||||
.join('|'),
|
.join('|'),
|
||||||
messages: options.messages,
|
messages: options.messages,
|
||||||
splitChunks: options.build.splitChunks,
|
splitChunks: options.build.splitChunks,
|
||||||
@ -57,7 +57,7 @@ export default class TemplateContext {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
get templateOptions() {
|
get templateOptions () {
|
||||||
return {
|
return {
|
||||||
imports: {
|
imports: {
|
||||||
serialize,
|
serialize,
|
||||||
|
@ -44,7 +44,7 @@ export default class NuxtCommand extends Hookable {
|
|||||||
|
|
||||||
cmd: Command & { options: Command['options'] }
|
cmd: Command & { options: Command['options'] }
|
||||||
|
|
||||||
constructor(cmd: Command = { name: '', usage: '', description: '' }, argv = process.argv.slice(2), hooks: Hooks = {}) {
|
constructor (cmd: Command = { name: '', usage: '', description: '' }, argv = process.argv.slice(2), hooks: Hooks = {}) {
|
||||||
super(consola)
|
super(consola)
|
||||||
this.addHooks(hooks)
|
this.addHooks(hooks)
|
||||||
|
|
||||||
@ -57,18 +57,18 @@ export default class NuxtCommand extends Hookable {
|
|||||||
this._parsedArgv = null // Lazy evaluate
|
this._parsedArgv = null // Lazy evaluate
|
||||||
}
|
}
|
||||||
|
|
||||||
static run(cmd: Command, argv: NodeJS.Process['argv'], hooks: Hooks) {
|
static run (cmd: Command, argv: NodeJS.Process['argv'], hooks: Hooks) {
|
||||||
return NuxtCommand.from(cmd, argv, hooks).run()
|
return NuxtCommand.from(cmd, argv, hooks).run()
|
||||||
}
|
}
|
||||||
|
|
||||||
static from(cmd: Command, argv: NodeJS.Process['argv'], hooks: Hooks) {
|
static from (cmd: Command, argv: NodeJS.Process['argv'], hooks: Hooks) {
|
||||||
if (cmd instanceof NuxtCommand) {
|
if (cmd instanceof NuxtCommand) {
|
||||||
return cmd
|
return cmd
|
||||||
}
|
}
|
||||||
return new NuxtCommand(cmd, argv, hooks)
|
return new NuxtCommand(cmd, argv, hooks)
|
||||||
}
|
}
|
||||||
|
|
||||||
async run() {
|
async run () {
|
||||||
await this.callHook('run:before', {
|
await this.callHook('run:before', {
|
||||||
argv: this._argv,
|
argv: this._argv,
|
||||||
cmd: this.cmd,
|
cmd: this.cmd,
|
||||||
@ -117,15 +117,15 @@ export default class NuxtCommand extends Hookable {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
showVersion() {
|
showVersion () {
|
||||||
process.stdout.write(`${name} v${version}\n`)
|
process.stdout.write(`${name} v${version}\n`)
|
||||||
}
|
}
|
||||||
|
|
||||||
showHelp() {
|
showHelp () {
|
||||||
process.stdout.write(this._getHelp())
|
process.stdout.write(this._getHelp())
|
||||||
}
|
}
|
||||||
|
|
||||||
get argv() {
|
get argv () {
|
||||||
if (!this._parsedArgv) {
|
if (!this._parsedArgv) {
|
||||||
const minimistOptions = this._getMinimistOptions()
|
const minimistOptions = this._getMinimistOptions()
|
||||||
this._parsedArgv = minimist(this._argv, minimistOptions)
|
this._parsedArgv = minimist(this._argv, minimistOptions)
|
||||||
@ -133,7 +133,7 @@ export default class NuxtCommand extends Hookable {
|
|||||||
return this._parsedArgv
|
return this._parsedArgv
|
||||||
}
|
}
|
||||||
|
|
||||||
async getNuxtConfig(extraOptions: ExtraOptions = {}) {
|
async getNuxtConfig (extraOptions: ExtraOptions = {}) {
|
||||||
// Flag to indicate nuxt is running with CLI (not programmatic)
|
// Flag to indicate nuxt is running with CLI (not programmatic)
|
||||||
extraOptions._cli = true
|
extraOptions._cli = true
|
||||||
|
|
||||||
@ -154,7 +154,7 @@ export default class NuxtCommand extends Hookable {
|
|||||||
return options
|
return options
|
||||||
}
|
}
|
||||||
|
|
||||||
async getNuxt(options) {
|
async getNuxt (options) {
|
||||||
|
|
||||||
const nuxt = new Nuxt(options)
|
const nuxt = new Nuxt(options)
|
||||||
await nuxt.ready()
|
await nuxt.ready()
|
||||||
@ -162,16 +162,16 @@ export default class NuxtCommand extends Hookable {
|
|||||||
return nuxt
|
return nuxt
|
||||||
}
|
}
|
||||||
|
|
||||||
async getBuilder(nuxt: Nuxt) {
|
async getBuilder (nuxt: Nuxt) {
|
||||||
return new Builder(nuxt)
|
return new Builder(nuxt)
|
||||||
}
|
}
|
||||||
|
|
||||||
async getGenerator(nuxt) {
|
async getGenerator (nuxt) {
|
||||||
const builder = await this.getBuilder(nuxt)
|
const builder = await this.getBuilder(nuxt)
|
||||||
return new Generator(nuxt, builder)
|
return new Generator(nuxt, builder)
|
||||||
}
|
}
|
||||||
|
|
||||||
async setLock(lockRelease) {
|
async setLock (lockRelease) {
|
||||||
if (lockRelease) {
|
if (lockRelease) {
|
||||||
if (this._lockRelease) {
|
if (this._lockRelease) {
|
||||||
consola.warn(`A previous unreleased lock was found, this shouldn't happen and is probably an error in 'nuxt ${this.cmd.name}' command. The lock will be removed but be aware of potential strange results`)
|
consola.warn(`A previous unreleased lock was found, this shouldn't happen and is probably an error in 'nuxt ${this.cmd.name}' command. The lock will be removed but be aware of potential strange results`)
|
||||||
@ -184,14 +184,14 @@ export default class NuxtCommand extends Hookable {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async releaseLock() {
|
async releaseLock () {
|
||||||
if (this._lockRelease) {
|
if (this._lockRelease) {
|
||||||
await this._lockRelease()
|
await this._lockRelease()
|
||||||
this._lockRelease = undefined
|
this._lockRelease = undefined
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
isUserSuppliedArg(option: string) {
|
isUserSuppliedArg (option: string) {
|
||||||
return this._argv.includes(`--${option}`) || this._argv.includes(`--no-${option}`)
|
return this._argv.includes(`--${option}`) || this._argv.includes(`--no-${option}`)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -199,7 +199,7 @@ export default class NuxtCommand extends Hookable {
|
|||||||
return option.default instanceof Function ? option.default(this.cmd) : option.default
|
return option.default instanceof Function ? option.default(this.cmd) : option.default
|
||||||
}
|
}
|
||||||
|
|
||||||
_getMinimistOptions() {
|
_getMinimistOptions () {
|
||||||
const minimistOptions = {
|
const minimistOptions = {
|
||||||
alias: {},
|
alias: {},
|
||||||
boolean: [],
|
boolean: [],
|
||||||
@ -224,7 +224,7 @@ export default class NuxtCommand extends Hookable {
|
|||||||
return minimistOptions
|
return minimistOptions
|
||||||
}
|
}
|
||||||
|
|
||||||
_getHelp() {
|
_getHelp () {
|
||||||
const options = []
|
const options = []
|
||||||
let maxOptionLength = 0
|
let maxOptionLength = 0
|
||||||
|
|
||||||
|
@ -17,7 +17,7 @@ export default {
|
|||||||
alias: 'a',
|
alias: 'a',
|
||||||
type: 'boolean',
|
type: 'boolean',
|
||||||
description: 'Launch webpack-bundle-analyzer to optimize your bundles',
|
description: 'Launch webpack-bundle-analyzer to optimize your bundles',
|
||||||
prepare (cmd: NuxtCommand, options, argv: ParsedArgs) {
|
prepare (_cmd: NuxtCommand, options, argv: ParsedArgs) {
|
||||||
// Analyze option
|
// Analyze option
|
||||||
options.build = options.build || {}
|
options.build = options.build || {}
|
||||||
if (argv.analyze && typeof options.build.analyze !== 'object') {
|
if (argv.analyze && typeof options.build.analyze !== 'object') {
|
||||||
@ -29,7 +29,7 @@ export default {
|
|||||||
type: 'boolean',
|
type: 'boolean',
|
||||||
default: false,
|
default: false,
|
||||||
description: 'Enable Vue devtools',
|
description: 'Enable Vue devtools',
|
||||||
prepare (cmd: NuxtCommand, options, argv: ParsedArgs) {
|
prepare (_cmd: NuxtCommand, options, argv: ParsedArgs) {
|
||||||
options.vue = options.vue || {}
|
options.vue = options.vue || {}
|
||||||
options.vue.config = options.vue.config || {}
|
options.vue.config = options.vue.config || {}
|
||||||
if (argv.devtools) {
|
if (argv.devtools) {
|
||||||
@ -46,7 +46,7 @@ export default {
|
|||||||
alias: 'q',
|
alias: 'q',
|
||||||
type: 'boolean',
|
type: 'boolean',
|
||||||
description: 'Disable output except for errors',
|
description: 'Disable output except for errors',
|
||||||
prepare (cmd: NuxtCommand, options, argv: ParsedArgs) {
|
prepare (_cmd: NuxtCommand, options, argv: ParsedArgs) {
|
||||||
// Silence output when using --quiet
|
// Silence output when using --quiet
|
||||||
options.build = options.build || {}
|
options.build = options.build || {}
|
||||||
if (argv.quiet) {
|
if (argv.quiet) {
|
||||||
@ -58,7 +58,7 @@ export default {
|
|||||||
type: 'boolean',
|
type: 'boolean',
|
||||||
default: false,
|
default: false,
|
||||||
description: 'Bundle all server dependencies (useful for nuxt-start)',
|
description: 'Bundle all server dependencies (useful for nuxt-start)',
|
||||||
prepare (cmd: NuxtCommand, options, argv: ParsedArgs) {
|
prepare (_cmd: NuxtCommand, options, argv: ParsedArgs) {
|
||||||
if (argv.standalone) {
|
if (argv.standalone) {
|
||||||
options.build.standalone = true
|
options.build.standalone = true
|
||||||
}
|
}
|
||||||
|
@ -50,7 +50,7 @@ export default {
|
|||||||
return nuxt
|
return nuxt
|
||||||
},
|
},
|
||||||
|
|
||||||
async _listenDev (cmd: NuxtCommand, argv) {
|
async _listenDev (cmd: NuxtCommand, argv: ParsedArgs) {
|
||||||
const config = await cmd.getNuxtConfig({ dev: true, _build: true })
|
const config = await cmd.getNuxtConfig({ dev: true, _build: true })
|
||||||
const nuxt = await cmd.getNuxt(config)
|
const nuxt = await cmd.getNuxt(config)
|
||||||
|
|
||||||
@ -78,7 +78,7 @@ export default {
|
|||||||
return nuxt
|
return nuxt
|
||||||
},
|
},
|
||||||
|
|
||||||
async _buildDev (cmd: NuxtCommand, argv: ParsedArgs, nuxt: Nuxt) {
|
async _buildDev (cmd: NuxtCommand, _argv: ParsedArgs, nuxt: Nuxt) {
|
||||||
// Create builder instance
|
// Create builder instance
|
||||||
const builder = await cmd.getBuilder(nuxt)
|
const builder = await cmd.getBuilder(nuxt)
|
||||||
|
|
||||||
@ -97,7 +97,7 @@ export default {
|
|||||||
return nuxt
|
return nuxt
|
||||||
},
|
},
|
||||||
|
|
||||||
logChanged ({ event, path }) {
|
logChanged ({ event, path }: { event: keyof typeof eventsMapping, path: string }) {
|
||||||
const { icon, color, action } = eventsMapping[event] || eventsMapping.change
|
const { icon, color, action } = eventsMapping[event] || eventsMapping.change
|
||||||
|
|
||||||
consola.log({
|
consola.log({
|
||||||
|
Loading…
Reference in New Issue
Block a user