UNPKG

1.16 kBJavaScriptView Raw
1const { hasRequiredDeps, hasRequiredFiles, getYarnOrNPMCommand, scanScripts } = require('./utils/jsdetect')
2
3/**
4 * detection logic - artificial intelligence!
5 * */
6module.exports = function() {
7 // REQUIRED FILES
8 if (!hasRequiredFiles(['package.json'])) return false
9 // REQUIRED DEPS
10 if (!hasRequiredDeps(['react-scripts'])) return false
11
12 /** everything below now assumes that we are within create-react-app */
13
14 const possibleArgsArrs = scanScripts({
15 preferredScriptsArr: ['start', 'serve', 'run'],
16 preferredCommand: 'react-scripts start'
17 })
18
19 if (possibleArgsArrs.length === 0) {
20 // ofer to run it when the user doesnt have any scripts setup! 🤯
21 possibleArgsArrs.push(['react-scripts', 'start'])
22 }
23
24 return {
25 type: 'create-react-app',
26 command: getYarnOrNPMCommand(),
27 port: 8888, // the port that the Netlify Dev User will use
28 proxyPort: 3000, // the port that create-react-app normally outputs
29 env: { ...process.env, BROWSER: 'none', PORT: 3000 },
30 stdio: ['inherit', 'pipe', 'pipe'],
31 possibleArgsArrs,
32 urlRegexp: new RegExp(`(http://)([^:]+:)${3000}(/)?`, 'g'),
33 dist: 'public'
34 }
35}