Skip to content
This repository was archived by the owner on Sep 12, 2019. It is now read-only.

Add vue detector #54

Merged
merged 3 commits into from
Apr 2, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions src/detect-server.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ const craDetector = require('./detectors/cra')
const hugoDetector = require('./detectors/hugo')
const eleventyDetector = require('./detectors/eleventy')
const jekyllDetector = require('./detectors/jekyll')
const vueDetector = require('./detectors/vue')

const detectors = [
gatsbyDetector,
Expand All @@ -12,6 +13,7 @@ const detectors = [
jekyllDetector,
eleventyDetector,
craDetector,
vueDetector
]

module.exports.serverSettings = devConfig => {
Expand All @@ -31,9 +33,7 @@ module.exports.serverSettings = devConfig => {
}
if (devConfig.port) {
settings.proxyPort = devConfig.port
settings.urlRegexp =
devConfig.urlRegexp ||
new RegExp(`(http://)([^:]+:)${devConfig.port}(/)?`, 'g')
settings.urlRegexp = devConfig.urlRegexp || new RegExp(`(http://)([^:]+:)${devConfig.port}(/)?`, 'g')
}
settings.dist = devConfig.publish || settings.dist
}
Expand Down
31 changes: 31 additions & 0 deletions src/detectors/vue.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
const { existsSync, readFileSync } = require('fs')

module.exports = function() {
if (!existsSync('package.json')) {
return false
}

const packageSettings = JSON.parse(readFileSync('package.json', { encoding: 'utf8' }))
const { dependencies, scripts } = packageSettings
if (!(dependencies && dependencies.vue)) {
return false
}

const npmCommand = scripts && ((scripts.serve && 'serve') || (scripts.start && 'start') || (scripts.run && 'run'))

if (!npmCommand) {
console.error("Couldn't determine the script to run. Use the -c flag.")
process.exit(1)
}

const yarnExists = existsSync('yarn.lock')
return {
cmd: yarnExists ? 'yarn' : 'npm',
port: 8888,
proxyPort: 8080,
env: { ...process.env },
args: yarnExists || npmCommand != 'start' ? ['run', npmCommand] : [npmCommand],
urlRegexp: new RegExp(`(http://)([^:]+:)${8080}(/)?`, 'g'),
dist: 'dist'
}
}