Skip to content
This repository was archived by the owner on Sep 12, 2019. It is now read-only.
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
28 changes: 25 additions & 3 deletions src/detectors/gatsby.js
Original file line number Diff line number Diff line change
@@ -1,17 +1,39 @@
const { existsSync } = require('fs')
const { existsSync, readFileSync } = require('fs')

module.exports = function() {
if (!existsSync('gatsby-config.js')) {
if (!existsSync('gatsby-config.js') || !existsSync('package.json')) {
return false
}

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

const npmCommand = scripts && ((scripts.develop && 'develop') || (scripts.dev && 'dev'))
if (!npmCommand) {
// search all the scripts for something that starts with 'gatsby develop'
Object.entries(scripts).forEach(([k, v]) => {
if (v.startsWith('gatsby develop')) {
npmCommand = k
}
})
if (!npmCommand) {
console.error("Couldn't determine the package.json script to run for this Gatsby project. Use the -c flag.")
process.exit(1)
} else {
console.log('using npm script starting with gatsby develop: ', k)
}
}

const yarnExists = existsSync('yarn.lock')
return {
command: yarnExists ? 'yarn' : 'npm',
port: 8888,
proxyPort: 8000,
env: { ...process.env },
args: yarnExists ? ['run', 'develop'] : ['develop'],
args: yarnExists || npmCommand != 'start' ? ['run', npmCommand] : [npmCommand],
urlRegexp: new RegExp(`(http://)([^:]+:)${8000}(/)?`, 'g'),
dist: 'public'
}
Expand Down
28 changes: 25 additions & 3 deletions src/detectors/react-static.js
Original file line number Diff line number Diff line change
@@ -1,17 +1,39 @@
const { existsSync } = require('fs')
const { existsSync, readFileSync } = require('fs')

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

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

const npmCommand = scripts && ((scripts.start && 'start') || (scripts.develop && 'develop') || (scripts.dev && 'dev'))
if (!npmCommand) {
// search all the scripts for something that starts with 'react-static start'
Object.entries(scripts).forEach(([k, v]) => {
if (v.startsWith('react-static start')) {
npmCommand = k
}
})
if (!npmCommand) {
console.error("Couldn't determine the package.json script to run for this React-Static project. Use the -c flag.")
process.exit(1)
} else {
console.log('using npm script starting with react-static start: ', k)
}
}

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