Skip to content

Commit

Permalink
Build and copy over built src to websites when building them so they'…
Browse files Browse the repository at this point in the history
…re truely running from HEAD
  • Loading branch information
KyleAMathews committed Apr 19, 2017
1 parent 1f1d870 commit a18ee33
Show file tree
Hide file tree
Showing 4 changed files with 57 additions and 42 deletions.
53 changes: 24 additions & 29 deletions packages/gatsby-dev-cli/bin/gatsby-dev
Original file line number Diff line number Diff line change
@@ -1,38 +1,33 @@
#!/usr/bin/env node

const Configstore = require("configstore");
const pkg = require("../package.json");
const argv = require("yargs").array("packages").argv;
const isAbsolute = require("is-absolute");
const _ = require("lodash");
const Configstore = require("configstore")
const pkg = require("../package.json")
const argv = require("yargs").array("packages").argv
const isAbsolute = require("is-absolute")
const _ = require("lodash")
const path = require("path")

const conf = new Configstore(pkg.name);
const conf = new Configstore(pkg.name)

const fs = require("fs-extra");
const havePackageJsonFile = fs.existsSync("package.json");
const fs = require("fs-extra")
const havePackageJsonFile = fs.existsSync("package.json")

if (!havePackageJsonFile) {
console.log("Current folder must have a package.json file!");
process.exit();
console.log("Current folder must have a package.json file!")
process.exit()
}

const localPkg = JSON.parse(fs.readFileSync("package.json"));
const packages = Object.keys(localPkg.dependencies);
const gatsbyPackages = packages.filter(p => p.startsWith("gatsby"));

// Test that the path is absolute
if (argv.setPathToRepo && !isAbsolute(argv.setPathToRepo)) {
console.log("The path to the repo has to be absolute!");
process.exit();
}
const localPkg = JSON.parse(fs.readFileSync("package.json"))
const packages = Object.keys(localPkg.dependencies)
const gatsbyPackages = packages.filter(p => p.startsWith("gatsby"))

if (argv.setPathToRepo) {
console.log("Saving path to your Gatsby repo");
conf.set("gatsby-location", argv.setPathToRepo);
process.exit();
console.log("Saving path to your Gatsby repo")
conf.set("gatsby-location", path.resolve(argv.setPathToRepo))
process.exit()
}

const gatsbyLocation = conf.get("gatsby-location");
const gatsbyLocation = conf.get("gatsby-location")

if (!gatsbyLocation) {
console.log(
Expand All @@ -42,8 +37,8 @@ version of Gatsby. Do so now by running:
gatsby-dev --set-path-to-repo /path/to/my/cloned/version/gatsby
`
);
process.exit();
)
process.exit()
}

if (!argv.packages && _.isEmpty(gatsbyPackages)) {
Expand All @@ -56,9 +51,9 @@ developing on! For example:
gatsby-dev --packages gatsby gatsby-typegen-remark
`
);
process.exit();
)
process.exit()
}

const watch = require("../");
watch(gatsbyLocation, argv.packages || gatsbyPackages);
const watch = require("../")
watch(gatsbyLocation, argv.packages || gatsbyPackages, argv.scanOnce)
10 changes: 9 additions & 1 deletion packages/gatsby-dev-cli/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,11 @@ const syspath = require("path")

const ignoreRegs = [/[\/\\]node_modules[\/\\]/i, /\.git/i, /[\/\\]src[\/\\]/i]

module.exports = (root, packages) => {
const debouncedQuit = _.debounce(() => {
process.exit()
}, 500)

module.exports = (root, packages, scanOnce) => {
packages.forEach(p => {
const prefix = `${root}/packages/${p}`
chokidar
Expand All @@ -27,6 +31,10 @@ module.exports = (root, packages) => {
if (err) console.error(err)
console.log(`copied ${path} to ${newPath}`)
})

if (scanOnce) {
debouncedQuit()
}
}
})
})
Expand Down
18 changes: 12 additions & 6 deletions scripts/publish-gatsbygram.sh
Original file line number Diff line number Diff line change
@@ -1,10 +1,16 @@
#echo "=== Building ES5 version of Gatsby"
#./node_modules/.bin/lerna bootstrap --npm-client=yarn
#./node_modules/.bin/lerna run build
cd examples/gatsbygram
echo "=== Building ES5 version of Gatsby"
./node_modules/.bin/lerna bootstrap --npm-client=yarn
./node_modules/.bin/lerna run build

echo "=== Installing the website dependencies"
cd examples/gatsbygram
yarn
#echo "=== Copying built Gatsby to website."
#cp -r ../../packages/gatsby/dist ./node_modules/gatsby/dist

echo "=== Copying built Gatsby to website."
yarn global add gatsby-dev-cli@canary
gatsby-dev --set-path-to-repo ../
gatsby-dev --scan-once

echo "=== Building website"
rm -rf .cache
./node_modules/.bin/gatsby build
18 changes: 12 additions & 6 deletions scripts/publish-site.sh
Original file line number Diff line number Diff line change
@@ -1,10 +1,16 @@
#echo "=== Building ES5 version of Gatsby"
#./node_modules/.bin/lerna bootstrap --npm-client=yarn
#./node_modules/.bin/lerna run build
cd www
echo "=== Building ES5 version of Gatsby"
./node_modules/.bin/lerna bootstrap --npm-client=yarn
./node_modules/.bin/lerna run build

echo "=== Installing the website dependencies"
cd www
yarn
#echo "=== Copying built Gatsby to website."
#cp -r ../packages/gatsby/dist ./node_modules/gatsby/dist

echo "=== Copying built Gatsby to website."
yarn global add gatsby-dev-cli@canary
gatsby-dev --set-path-to-repo ../
gatsby-dev --scan-once

echo "=== Building website"
rm -rf .cache
./node_modules/.bin/gatsby build

0 comments on commit a18ee33

Please sign in to comment.