forked from gatsbyjs/gatsby
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Default to using the local install of gatsby and warn if there's not one
- Loading branch information
1 parent
24a4869
commit 8196916
Showing
16 changed files
with
166 additions
and
128 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,6 @@ | ||
{ | ||
"presets": ['react', 'es2015', 'stage-0'] | ||
"presets": ['react', 'es2015', 'stage-0'], | ||
"plugins": [ | ||
'transform-object-rest-spread' | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
{ | ||
"parser": "babel-eslint", | ||
"extends": "eslint-config-airbnb", | ||
"rules": { | ||
"indent": [2, 2, {"SwitchCase": 1}], | ||
|
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,50 @@ | ||
#!/usr/bin/env node | ||
|
||
/*eslint-disable */ | ||
require('babel-core/register') | ||
require('./index') | ||
|
||
global.appStartTime = Date.now() | ||
|
||
var sysPath = require('path') | ||
var fs = require('fs') | ||
var version = process.version | ||
var verDigit = parseInt(version.match(/^v(\d+)\./)[1], 10) | ||
|
||
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 () { | ||
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.error( | ||
'Gatsby: Local install exists but failed to load it. ' + | ||
'Continuing with global install:', error | ||
) | ||
loadGlobalGatsby() | ||
} | ||
} | ||
}) |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
const program = require('commander') | ||
const packageJson = require('../../package.json') | ||
const _ = require('lodash') | ||
const fs = require('fs-extra') | ||
const path = require('path') | ||
|
||
// Copy our load-context function to root of site in a dot file. | ||
const gatsbyFile = `${__dirname}/../utils/load-context.js` | ||
const siteDirectory = path.resolve('.') | ||
const fileName = `${siteDirectory}/.gatsby-context.js` | ||
fs.copy(gatsbyFile, fileName) | ||
|
||
const defaultHost = process.platform === 'win32' | ||
? 'localhost' | ||
: '0.0.0.0' | ||
|
||
const directory = path.resolve('.') | ||
|
||
program | ||
.version(packageJson.version) | ||
.usage('[command] [options]') | ||
|
||
program.command('develop') | ||
.description('Start development server. Watches files and rebuilds and hot reloads if something changes') // eslint-disable-line max-len | ||
.option('-h, --host <url>', | ||
`Set host. Defaults to ${defaultHost}`, | ||
defaultHost | ||
) | ||
.option('-p, --port <port>', 'Set port. Defaults to 8000', '8000') | ||
.action((command) => { | ||
const develop = require('../utils/develop') | ||
const p = { | ||
...command, | ||
directory, | ||
} | ||
develop(p) | ||
}) | ||
|
||
program.command('build') | ||
.description('Build a Gatsby project.') | ||
.option('--prefix-links', 'Build site with links prefixed (set prefix in your config).') | ||
.action((command) => { | ||
const build = require('../utils/build') | ||
const p = { | ||
...command, | ||
directory, | ||
} | ||
console.log('running build') | ||
build(p, (err) => { | ||
if (err) { | ||
throw err | ||
} else { | ||
console.log('Done') | ||
} | ||
}) | ||
}) | ||
|
||
program | ||
.command('new [rootPath] [starter]') | ||
.description('Create new Gatsby project in path [.].') | ||
.action((rootPath, starter) => { | ||
console.log(rootPath, starter) | ||
const newCommand = require('../utils/new') | ||
console.log('running new') | ||
newCommand(rootPath, starter) | ||
}) | ||
|
||
|
||
// If the user types an unknown sub-command, just display the help. | ||
const subCmd = process.argv.slice(2, 3)[0] | ||
const cmds = _.map(program.commands, '_name') | ||
console.log(subCmd, cmds) | ||
|
||
if (!_.includes(cmds, subCmd)) { | ||
console.log('help me') | ||
program.help() | ||
} else { | ||
program.parse(process.argv) | ||
} |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
const loggy = require('loggy') | ||
|
||
const initStarter = require('./init-starter') | ||
|
||
module.exports = (rootPath, starter='gh:gatsbyjs/gatsby-starter-default') => { | ||
initStarter( | ||
starter, | ||
{ | ||
rootPath, | ||
logger: loggy, | ||
}, (error) => { | ||
if (error) { | ||
loggy.error(error) | ||
} | ||
} | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters