This repository was archived by the owner on Sep 12, 2019. It is now read-only.
File tree Expand file tree Collapse file tree 2 files changed +50
-6
lines changed Expand file tree Collapse file tree 2 files changed +50
-6
lines changed Original file line number Diff line number Diff line change 1- const { existsSync } = require ( 'fs' )
1+ const { existsSync, readFileSync } = require ( 'fs' )
22
33module . exports = function ( ) {
4- if ( ! existsSync ( 'gatsby-config.js' ) ) {
4+ if ( ! existsSync ( 'gatsby-config.js' ) || ! existsSync ( 'package.json' ) ) {
55 return false
66 }
77
8+ const packageSettings = JSON . parse ( readFileSync ( 'package.json' , { encoding : 'utf8' } ) )
9+ const { dependencies, scripts } = packageSettings
10+ if ( ! ( dependencies && dependencies [ 'gatsby' ] ) ) {
11+ return false
12+ }
13+
14+ const npmCommand = scripts && ( ( scripts . develop && 'develop' ) || ( scripts . dev && 'dev' ) )
15+ if ( ! npmCommand ) {
16+ // search all the scripts for something that starts with 'gatsby develop'
17+ Object . entries ( scripts ) . forEach ( ( [ k , v ] ) => {
18+ if ( v . startsWith ( 'gatsby develop' ) ) {
19+ npmCommand = k
20+ }
21+ } )
22+ if ( ! npmCommand ) {
23+ console . error ( "Couldn't determine the package.json script to run for this Gatsby project. Use the -c flag." )
24+ process . exit ( 1 )
25+ } else {
26+ console . log ( 'using npm script starting with gatsby develop: ' , k )
27+ }
28+ }
29+
830 const yarnExists = existsSync ( 'yarn.lock' )
931 return {
1032 command : yarnExists ? 'yarn' : 'npm' ,
1133 port : 8888 ,
1234 proxyPort : 8000 ,
1335 env : { ...process . env } ,
14- args : yarnExists ? [ 'run' , 'develop' ] : [ 'develop' ] ,
36+ args : yarnExists || npmCommand != 'start' ? [ 'run' , npmCommand ] : [ npmCommand ] ,
1537 urlRegexp : new RegExp ( `(http://)([^:]+:)${ 8000 } (/)?` , 'g' ) ,
1638 dist : 'public'
1739 }
Original file line number Diff line number Diff line change 1- const { existsSync } = require ( 'fs' )
1+ const { existsSync, readFileSync } = require ( 'fs' )
22
33module . exports = function ( ) {
4- if ( ! existsSync ( 'static.config.js' ) ) {
4+ if ( ! existsSync ( 'static.config.js' ) || ! existsSync ( 'package.json' ) ) {
55 return false
66 }
77
8+ const packageSettings = JSON . parse ( readFileSync ( 'package.json' , { encoding : 'utf8' } ) )
9+ const { dependencies, scripts } = packageSettings
10+ if ( ! ( dependencies && dependencies [ 'react-static' ] ) ) {
11+ return false
12+ }
13+
14+ const npmCommand = scripts && ( ( scripts . start && 'start' ) || ( scripts . develop && 'develop' ) || ( scripts . dev && 'dev' ) )
15+ if ( ! npmCommand ) {
16+ // search all the scripts for something that starts with 'react-static start'
17+ Object . entries ( scripts ) . forEach ( ( [ k , v ] ) => {
18+ if ( v . startsWith ( 'react-static start' ) ) {
19+ npmCommand = k
20+ }
21+ } )
22+ if ( ! npmCommand ) {
23+ console . error ( "Couldn't determine the package.json script to run for this React-Static project. Use the -c flag." )
24+ process . exit ( 1 )
25+ } else {
26+ console . log ( 'using npm script starting with react-static start: ' , k )
27+ }
28+ }
29+
830 const yarnExists = existsSync ( 'yarn.lock' )
931 return {
1032 command : yarnExists ? 'yarn' : 'npm' ,
1133 port : 8888 ,
1234 proxyPort : 3000 ,
1335 env : { ...process . env } ,
14- args : yarnExists ? [ 'run' , 'start' ] : [ 'start' ] ,
36+ args : yarnExists || npmCommand != 'start' ? [ 'run' , npmCommand ] : [ npmCommand ] ,
1537 urlRegexp : new RegExp ( `(http://)([^:]+:)${ 3000 } (/)?` , 'g' ) ,
1638 dist : 'dist'
1739 }
You can’t perform that action at this time.
0 commit comments