-
Notifications
You must be signed in to change notification settings - Fork 10.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[feat] Extract internal plugin for automatically creating pages so we can reuse for other directories #4490
Changes from 17 commits
3d1b166
e116257
601c8f1
87e5a16
d636e09
c0588de
9e11a16
aac2e89
8f803f4
e58a328
9f7e69c
87001d7
1f8c7d6
8939a4b
eb02d69
45c5827
3919910
778e427
32edb33
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
# Logs | ||
logs | ||
*.log | ||
|
||
# Runtime data | ||
pids | ||
*.pid | ||
*.seed | ||
|
||
# Directory for instrumented libs generated by jscoverage/JSCover | ||
lib-cov | ||
|
||
# Coverage directory used by tools like istanbul | ||
coverage | ||
|
||
# Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files) | ||
.grunt | ||
|
||
# node-waf configuration | ||
.lock-wscript | ||
|
||
# Compiled binary addons (http://nodejs.org/api/addons.html) | ||
build/Release | ||
|
||
# Dependency directory | ||
# https://www.npmjs.org/doc/misc/npm-faq.html#should-i-check-my-node_modules-folder-into-git | ||
node_modules | ||
|
||
decls | ||
dist | ||
|
||
/*.js |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
# Logs | ||
logs | ||
*.log | ||
|
||
# Runtime data | ||
pids | ||
*.pid | ||
*.seed | ||
|
||
# Directory for instrumented libs generated by jscoverage/JSCover | ||
lib-cov | ||
|
||
# Coverage directory used by tools like istanbul | ||
coverage | ||
|
||
# Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files) | ||
.grunt | ||
|
||
# node-waf configuration | ||
.lock-wscript | ||
|
||
# Compiled binary addons (http://nodejs.org/api/addons.html) | ||
build/Release | ||
|
||
# Dependency directory | ||
# https://www.npmjs.org/doc/misc/npm-faq.html#should-i-check-my-node_modules-folder-into-git | ||
node_modules | ||
*.un~ | ||
yarn.lock | ||
src | ||
flow-typed | ||
coverage | ||
decls | ||
examples |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
# gatsby-plugin-page-creator | ||
|
||
Gatsby plugin that automatically creates pages from React components in specified directories. Gatsby | ||
includes this plugin automatically in all sites for creating pages from components in `src/pages`. | ||
|
||
## Install | ||
|
||
`npm install --save gatsby-plugin-page-creator` | ||
|
||
## How to use | ||
|
||
```javascript | ||
// gatsby-config.js | ||
|
||
module.exports = { | ||
plugins: [ | ||
// You can have multiple instances of this plugin | ||
// to create pages from components in different directories. | ||
// | ||
// The following sets up the pattern of having multiple | ||
// "pages" directories in your project | ||
{ | ||
resolve: `gatsby-plugin-page-creator`, | ||
options: { | ||
path: `${__dirname}/src/account/pages`, | ||
}, | ||
}, | ||
{ | ||
resolve: `gatsby-plugin-page-creator`, | ||
options: { | ||
path: `${__dirname}/src/settings/pages`, | ||
}, | ||
}, | ||
], | ||
}; | ||
``` |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
{ | ||
"name": "gatsby-plugin-page-creator", | ||
"version": "1.0.0", | ||
"description": "Gatsby plugin that automatically creates pages from React components in specified directories", | ||
"main": "index.js", | ||
"scripts": { | ||
"build": "babel src --out-dir . --ignore __tests__", | ||
"watch": "babel -w src --out-dir . --ignore __tests__", | ||
"prepublish": "cross-env NODE_ENV=production npm run build" | ||
}, | ||
"keywords": [ | ||
"gatsby", | ||
"gatsby-plugin" | ||
], | ||
"author": "Kyle Mathews <mathews.kyle@gmail.com>", | ||
"contributors": [ | ||
"Steven Natera <tektekpush@gmail.com> (https://twitter.com/stevennatera)" | ||
], | ||
"license": "MIT", | ||
"dependencies": { | ||
"babel-runtime": "^6.26.0", | ||
"bluebird": "^3.5.0", | ||
"chokidar": "^1.7.0", | ||
"glob": "^7.1.1", | ||
"lodash": "^4.17.4", | ||
"parse-filepath": "^1.0.1", | ||
"slash": "^1.0.0" | ||
}, | ||
"devDependencies": { | ||
"babel-cli": "^6.26.0", | ||
"cross-env": "^5.0.5" | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,6 +3,7 @@ const Promise = require(`bluebird`) | |
const _ = require(`lodash`) | ||
const chokidar = require(`chokidar`) | ||
const systemPath = require(`path`) | ||
const fs = require(`fs`) | ||
|
||
const glob = Promise.promisify(globCB) | ||
|
||
|
@@ -15,14 +16,38 @@ const validatePath = require(`./validate-path`) | |
// underscored. Then create url w/ our path algorithm *unless* user | ||
// takes control of that page component in gatsby-node. | ||
exports.createPagesStatefully = async ( | ||
{ store, boundActionCreators }, | ||
options, | ||
{ store, boundActionCreators, reporter }, | ||
{ path: pagesPath, pathCheck = true }, | ||
doneCb | ||
) => { | ||
const { createPage, deletePage } = boundActionCreators | ||
const program = store.getState().program | ||
const exts = program.extensions.map(e => `${e.slice(1)}`).join(`,`) | ||
const pagesDirectory = systemPath.posix.join(program.directory, `/src/pages`) | ||
|
||
if (!pagesPath) { | ||
reporter.panic( | ||
` | ||
"path" is a required option for gatsby-plugin-page-creator | ||
|
||
See docs here - https://www.gatsbyjs.org/packages/gatsby-plugin-page-creator/ | ||
` | ||
) | ||
} | ||
|
||
// Validate that the path exists. | ||
if (pathCheck && !fs.existsSync(pagesPath)) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. adding
Is this fine? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this seems Ok to me? it could be given an awkward name to discourage people from using it - There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This option is not documented in README, so they would have to dive into code to discover it and even then I don't consider it harmless if they use that option There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 👍 |
||
reporter.panic( | ||
` | ||
The path passed to gatsby-plugin-page-creator does not exist on your file system: | ||
|
||
${pagesPath} | ||
|
||
Please pick a path to an existing directory. | ||
` | ||
) | ||
} | ||
|
||
const pagesDirectory = systemPath.posix.join(pagesPath) | ||
const pagesGlob = `${pagesDirectory}/**/*.{${exts}}` | ||
|
||
// Get initial list of files. | ||
|
This file was deleted.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
link should go to
/plugins/
instead of/packages/