This repository has been archived by the owner on Dec 14, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
run
executable file
·92 lines (64 loc) · 1.88 KB
/
run
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
#!/usr/bin/env node
const path = require('path')
const fs = require('fs')
const chalk = require('chalk')
const spawn = require('react-dev-utils/crossSpawn')
const appRoot = process.cwd()
const appPackagePath = path.join(appRoot, 'package.json')
let [command, ...args] = process.argv.slice(2)
const knownCommands = [
'build',
'dev',
'export',
'help',
'new',
'version',
]
if (knownCommands.indexOf(command) < 0) {
if (command) console.log(chalk.yellow(`Unknown command "${command}"`))
command = 'help'
}
// Check that project has package.json and node_modules
if (command==='new' || command==='help') {
// Pass through
} else if (command==='version') {
const {
name, version
} = require('./package.json')
console.log(`${name} ${version}`)
process.exit()
} else if (!fs.existsSync(appPackagePath)) {
console.log(chalk.yellow('No package.json found'))
command = 'help'
} else {
const { name } = require(appPackagePath)
if (name) console.log(`Project "${name}"\n`)
if (!fs.existsSync(path.join(appRoot, 'node_modules'))) {
console.log(chalk.yellow('Please run "npm install" or "yarn"'))
command = 'help'
}
}
const run = (...cmd) => spawn.sync('node', cmd, { stdio: 'inherit' })
let result = {}
switch (command) {
case 'export':
// Build for production
result = require('./scripts/build') // run(require.resolve('./scripts/build'))
// Export
if (!result.signal) {
// Resolve from built application
const serverPath = path.join(appRoot, 'build', 'server.js')
if (fs.existsSync(serverPath)) {
process.env.APP_EXPORT = 1
result = run(serverPath)
} else {
console.log(chalk.red('Server not found at build/server.js'))
}
}
process.exit(
!result ? 0 : (result.signal ? 1 : result.status)
)
break
default:
result = require('./scripts/' + command) // run(require.resolve('./scripts/' + command))
}