Skip to content

Commit

Permalink
fix: lint errors
Browse files Browse the repository at this point in the history
  • Loading branch information
Guillaume Chau committed Oct 20, 2019
1 parent 9817316 commit 0f2040d
Show file tree
Hide file tree
Showing 8 changed files with 32 additions and 31 deletions.
16 changes: 8 additions & 8 deletions generator/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ const chalk = require('chalk')

module.exports = (api, options, rootOptions) => {
if (!api.hasPlugin('router')) {
throw new Error(`Please install router plugin with 'vue add router'.`)
throw new Error('Please install router plugin with \'vue add router\'.')
}

api.extendPackage({
Expand Down Expand Up @@ -43,16 +43,16 @@ module.exports = (api, options, rootOptions) => {
const file = getFile(api, './src/main.js')
if (file) {
let contents = fs.readFileSync(file, { encoding: 'utf8' })
contents = contents.replace(/import router from ('|")\.\/router(\.\w+)?('|")/, `import { createRouter } from $1./router$3`)
contents = contents.replace(/import store from ('|")\.\/store(\.\w+)?('|")/, `import { createStore } from $1./store$3`)
contents = contents.replace(/import ('|")\.\/registerServiceWorker('|")\n/, ``)
contents = contents.replace(/const apolloProvider = createProvider\(({(.|\s)*?})?\)\n/, ``)
contents = contents.replace(/import router from ('|")\.\/router(\.\w+)?('|")/, 'import { createRouter } from $1./router$3')
contents = contents.replace(/import store from ('|")\.\/store(\.\w+)?('|")/, 'import { createStore } from $1./store$3')
contents = contents.replace(/import ('|")\.\/registerServiceWorker('|")\n/, '')
contents = contents.replace(/const apolloProvider = createProvider\(({(.|\s)*?})?\)\n/, '')
contents = contents.replace(/new Vue\({((.|\s)*)}\)\.\$mount\(.*?\)/, `export async function createApp ({
beforeApp = () => {},
afterApp = () => {}
} = {}) {
const router = createRouter()
${templateOptions.vuex ? `const store = createStore()` : ''}
${templateOptions.vuex ? 'const store = createStore()' : ''}
${templateOptions.apollo ? `const apolloProvider = createProvider({
ssr: process.server,
})` : ''}
Expand Down Expand Up @@ -88,7 +88,7 @@ module.exports = (api, options, rootOptions) => {
let contents = fs.readFileSync(file, { encoding: 'utf8' })
contents = contents.replace(/export default new Router\({((.|\s)+)}\)/, `export function createRouter () {
return new Router({
${contents.includes('mode:') ? '' : `mode: 'history',`}$1})
${contents.includes('mode:') ? '' : 'mode: \'history\','}$1})
}`)
contents = contents.replace(/mode:\s*("|')(hash|abstract)("|'),/, '')
fs.writeFileSync(file, contents, { encoding: 'utf8' })
Expand Down Expand Up @@ -127,7 +127,7 @@ module.exports = (api, options, rootOptions) => {
contents = contents.replace(/export default app => {((.|\s)*)}/, `export default app => {$1
ssrMiddleware(app, { prodOnly: true })
}`)
contents = `import ssrMiddleware from '@akryum/vue-cli-plugin-ssr/lib/app'\n` + contents
contents = 'import ssrMiddleware from \'@akryum/vue-cli-plugin-ssr/lib/app\'\n' + contents
fs.writeFileSync(file, contents, { encoding: 'utf8' })
}

Expand Down
2 changes: 1 addition & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ module.exports = (api, options) => {
config.port = port
config.host = host

return await createServer({
return createServer({
port,
host,
})
Expand Down
6 changes: 3 additions & 3 deletions lib/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ module.exports = (app, options) => {
if (options.prodOnly && !isProd) return

const templatePath = config.templatePath
const { publicPath } = config.service.projectOptions

try {
// Vue bundle renderer
Expand Down Expand Up @@ -81,7 +82,7 @@ module.exports = (app, options) => {
})
}

if(config.applyDefaultServer){
if (config.applyDefaultServer) {
// Serve static files
const serve = (filePath, cache) => express.static(filePath, {
maxAge: cache && isProd ? config.staticCacheTtl : 0,
Expand All @@ -95,7 +96,6 @@ module.exports = (app, options) => {
app.use('/service-worker.js', serve(config.serviceWorkerPath))
}
const serveStaticFiles = serve(config.distPath, true)
const { publicPath } = config.service.projectOptions
app.use(publicPath, (req, res, next) => {
if (/index\.html/g.test(req.path)) {
next()
Expand Down Expand Up @@ -153,7 +153,7 @@ module.exports = (app, options) => {
res.status(context.httpCode)
}

if(config.onRender){
if (config.onRender) {
config.onRender(res, context)
}

Expand Down
8 changes: 4 additions & 4 deletions lib/dev-server.js
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ module.exports.setupDevServer = ({ server, templatePath, onUpdate }) => new Prom
if (stats.hasErrors()) return

// Fix dev server render error when a custom path is used for the server-renderer bundles
const ssrPlugin = (clientConfig.plugins.find((p) => (p.__pluginName || p.constructor.name) === 'ssr') || {}).options || {}
const ssrPlugin = (clientConfig.plugins.find((p) => (p.__pluginName || p.constructor.name) === 'ssr') || {}).options || {}

clientManifest = JSON.parse(readFile(
devMiddleware.fileSystem,
Expand Down Expand Up @@ -116,7 +116,7 @@ module.exports.setupDevServer = ({ server, templatePath, onUpdate }) => new Prom

// Try to find ssr plugin config options
// to fix dev server render error when a custom path is used for the server-renderer bundles
const ssrPlugin = (serverConfig.plugins.find((p) => (p.__pluginName || p.constructor.name) === 'ssr') || {}).options || {}
const ssrPlugin = (serverConfig.plugins.find((p) => (p.__pluginName || p.constructor.name) === 'ssr') || {}).options || {}

// read bundle generated by vue-ssr-webpack-plugin
serverBundle = JSON.parse(readFile(
Expand All @@ -131,15 +131,15 @@ module.exports.setupDevServer = ({ server, templatePath, onUpdate }) => new Prom
function onCompilationCompleted () {
if (firstRun) {
firstRun = false
if(config.copyUrlOnStart) {
if (config.copyUrlOnStart) {
require('clipboardy').write(url)
copied = chalk.dim('(copied to clipboard)')
}
}

setTimeout(() => {
console.log()
console.log(` App running at:`)
console.log(' App running at:')
console.log(` - Local: ${chalk.cyan(url)} ${copied}`)
})
}
Expand Down
14 changes: 7 additions & 7 deletions lib/loaders/css-context.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,23 +27,23 @@ module.exports.pitch = function (remainingRequest) {

if (isServer && isProduction) {
const shared = [
`// load the styles`,
'// load the styles',
`var content = require(${request});`,
// content list format is [id, css, media, sourceMap]
`if(typeof content === 'string') content = [[module.id, content, '']];`,
`module.exports = content;`,
`if(content.locals) module.exports = content.locals;`,
'if(typeof content === \'string\') content = [[module.id, content, \'\']];',
'module.exports = content;',
'if(content.locals) module.exports = content.locals;',
]
// on the server: attach to Vue SSR context
if (isVue) {
// inside *.vue file: expose a function so it can be called in
// component's lifecycle hooks
return shared.concat([
`// add CSS to SSR context`,
'// add CSS to SSR context',
`var add = require(${addStylesServerPath}).default`,
`module.exports.__inject__ = function (context) {`,
'module.exports.__inject__ = function (context) {',
` add(${id}, content, ${isProduction}, context)`,
`};`,
'};',
]).join('\n')
} else {
// normal import
Expand Down
3 changes: 2 additions & 1 deletion lib/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,13 @@ exports.createServer = ({
port,
host,
}) => {
// eslint-disable-next-line no-async-promise-executor
return new Promise(async (resolve, reject) => {
const clustered = process.env.NODE_ENV === 'production' && config.clustered

// If the clustering mode is enabled and we are in the master process, create one worker per CPU core
if (cluster.isMaster && clustered) {
let cpus = require('os').cpus().length
const cpus = require('os').cpus().length
console.log(`[${new Date().toTimeString().split(' ')[0]}] Setting up clusters for ${cpus} cores`)
for (let i = 0; i < cpus; i += 1) {
cluster.fork()
Expand Down
8 changes: 4 additions & 4 deletions lib/webpack.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,15 +53,15 @@ exports.chainWebpack = (webpackConfig) => {
webpackConfig.entry('app').clear().add(config.entry(target))

webpackConfig.plugin('define').tap(args => {
return [Object.assign(args[0], {'process.client': target === 'client', 'process.server': target === 'server'})]
return [Object.assign(args[0], { 'process.client': target === 'client', 'process.server': target === 'server' })]
})

webpackConfig.stats(isProd ? 'normal' : 'none')
webpackConfig.devServer.stats('errors-only').quiet(true).noInfo(true)

if (isClient) {
webpackConfig.plugin('ssr').use(VueSSRClientPlugin)
webpackConfig.plugin('loader').use(WebpackBar, [{name: 'Client', color: 'green'}])
webpackConfig.plugin('loader').use(WebpackBar, [{ name: 'Client', color: 'green' }])

webpackConfig.devtool(!isProd ? '#cheap-module-source-map' : undefined)

Expand All @@ -71,10 +71,10 @@ exports.chainWebpack = (webpackConfig) => {
})
} else {
webpackConfig.plugin('ssr').use(VueSSRServerPlugin)
webpackConfig.plugin('loader').use(WebpackBar, [{name: 'Server', color: 'orange'}])
webpackConfig.plugin('loader').use(WebpackBar, [{ name: 'Server', color: 'orange' }])

webpackConfig.devtool('source-map')
webpackConfig.externals(nodeExternals({whitelist: config.nodeExternalsWhitelist}))
webpackConfig.externals(nodeExternals({ whitelist: config.nodeExternalsWhitelist }))
webpackConfig.output.libraryTarget('commonjs2'); webpackConfig.target('node')
webpackConfig.optimization.splitChunks(false).minimize(false)

Expand Down
6 changes: 3 additions & 3 deletions ui.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,21 +15,21 @@ module.exports = api => {

api.describeTask({
match: /vue-cli-service ssr:serve --mode production/,
description: `Starts the included HTTP server for SSR in production`,
description: 'Starts the included HTTP server for SSR in production',
link: 'https://github.com/Akryum/vue-cli-plugin-ssr#usage',
...taskCommon,
})

api.describeTask({
match: /vue-cli-service ssr:serve/,
description: `Compiles and hot-reloads for development with SSR`,
description: 'Compiles and hot-reloads for development with SSR',
link: 'https://github.com/Akryum/vue-cli-plugin-ssr#usage',
...taskCommon,
})

api.describeTask({
match: /vue-cli-service ssr:build/,
description: `Compiles and minifies for production with SSR`,
description: 'Compiles and minifies for production with SSR',
link: 'https://github.com/Akryum/vue-cli-plugin-ssr#usage',
})
}

0 comments on commit 0f2040d

Please sign in to comment.