Skip to content

Commit

Permalink
feat: add a copy-all script to gatsby-dev-cli (#8066)
Browse files Browse the repository at this point in the history
* feat: add a copy-all script to gatsby-dev-cli

* style: run lint

* refactor: move localPkg and packages declarations near usage

* fix: copy over gatsby dependencies even as part of not copy all

* refactor: re-use filter for gatsby packages

* chore: remove check that didn't need to happen
  • Loading branch information
DSchau authored and pieh committed Sep 12, 2018
1 parent 938d168 commit 1baa523
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 11 deletions.
4 changes: 4 additions & 0 deletions packages/gatsby-dev-cli/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,3 +57,7 @@ https://github.com/gatsbyjs/gatsby/blob/master/scripts/publish-site.sh.

Don't output anything except for a quit message when used together with
`--scan-once`.

#### `--copy-all`

Copy all modules/files in the gatsby source repo in packages/
30 changes: 19 additions & 11 deletions packages/gatsby-dev-cli/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@ const argv = require(`yargs`)
`Set path to Gatsby repository.
You typically only need to configure this once.`
)
.alias(`C`, `copy-all`)
.nargs(`C`, 0)
.describe(`C`, `Copy all contents in packages/ instead of just gatsby packages`)
.array(`packages`)
.describe(`packages`, `Explicitly specify packages to copy`)
.help(`h`)
Expand All @@ -37,14 +40,7 @@ if (!havePackageJsonFile) {
process.exit()
}

const localPkg = JSON.parse(fs.readFileSync(`package.json`))
const packages = Object.keys(
_.merge({}, localPkg.dependencies, localPkg.devDependencies)
)

const gatsbyPackages = packages.filter(p => p.startsWith(`gatsby`))

const pathToRepo = argv[`set-path-to-repo`]
const pathToRepo = argv.setPathToRepo
if (pathToRepo) {
console.log(`Saving path to your Gatsby repo`)
conf.set(`gatsby-location`, path.resolve(pathToRepo))
Expand All @@ -65,7 +61,19 @@ gatsby-dev --set-path-to-repo /path/to/my/cloned/version/gatsby
process.exit()
}

if (!argv.packages && _.isEmpty(gatsbyPackages)) {
const localPkg = JSON.parse(fs.readFileSync(`package.json`))
let packages = Object.keys(
_.merge({}, localPkg.dependencies, localPkg.devDependencies)
)

if (argv.copyAll) {
packages = fs.readdirSync(path.join(gatsbyLocation, `packages`))
} else {
const { dependencies } = JSON.parse(fs.readFileSync(path.join(gatsbyLocation, `packages/gatsby/package.json`)))
packages = packages.concat(Object.keys(dependencies)).filter(p => p.startsWith(`gatsby`))
}

if (!argv.packages && _.isEmpty(packages)) {
console.error(
`
You haven't got any gatsby dependencies into your current package.json
Expand All @@ -82,7 +90,7 @@ gatsby-dev will pick them up.
process.exit()
}

watch(gatsbyLocation, argv.packages || gatsbyPackages, {
watch(gatsbyLocation, argv.packages || packages, {
quiet: argv.quiet,
scanOnce: argv[`scan-once`],
scanOnce: argv.scanOnce,
})
1 change: 1 addition & 0 deletions packages/gatsby-dev-cli/src/watch.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ function watch(root, packages, { scanOnce, quiet }) {
const ignoreRegs = [
/[/\\]node_modules[/\\]/i,
/\.git/i,
/\.DS_Store/,
new RegExp(`${p}[\\/\\\\]src[\\/\\\\]`, `i`),
]

Expand Down

0 comments on commit 1baa523

Please sign in to comment.