This repository has been archived by the owner on Oct 6, 2020. It is now read-only.
forked from gatsbyjs/gatsby
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgatsby.js
executable file
·62 lines (54 loc) · 1.56 KB
/
gatsby.js
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
#!/usr/bin/env node
/*eslint-disable */
require('babel-core/register')
require('coffee-script/register')
global.appStartTime = Date.now()
var sysPath = require('path')
var fs = require('fs')
var version = process.version
var versionDigits = version.split('.')
.map(function (d) { return d.match(/\d+/)[0] })
.slice(0, 2).join('.')
var verDigit = Number(versionDigits)
if (verDigit < 0.12) {
console.error(
'Error: Gatsby 0.9+ requires node.js v0.12 or higher (you have ' + version + ') ' +
'Upgrade node to the latest stable release.'
)
process.exit()
}
var cwd = sysPath.resolve('.')
var cliFile = sysPath.join('dist', 'bin', 'cli.js')
var localPath = sysPath.join(cwd, 'node_modules', 'gatsby', cliFile)
var loadGatsby = function (path) {
require(path)
}
var loadGlobalGatsby = function () {
var commandsToIgnore = ['new', '--help']
if (commandsToIgnore.indexOf(process.argv[2]) === -1) {
console.log(
"A local install of Gatsby was not found.\n" +
"Generally you should save Gatsby as a site dependency e.g. npm install --save gatsby\n" +
"Continuing with global install.\n\n"
)
}
fs.realpath(__dirname, function (err, real) {
if (err) throw err
loadGatsby(sysPath.join(real, '..', cliFile))
})
}
fs.access(localPath, function (error) {
if (error) {
loadGlobalGatsby()
} else {
try {
loadGatsby(localPath)
} catch(error) {
console.log(
'Gatsby: Local install exists but failed to load it. ' +
'Continuing with global install:', error
)
loadGlobalGatsby()
}
}
})