-
Notifications
You must be signed in to change notification settings - Fork 10.3k
Plugin Library build fixes #3906
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
Changes from 250 commits
40df85e
396ae6e
3492447
771f241
9c1935a
95e5af7
03c19fb
de876dd
c881201
f1eb95c
65e851f
74b1ebe
60c0533
5ad3b38
4c1bbeb
4ef16d0
ec1b7ac
80775eb
74be3d8
b007e5a
d4cc9f1
f9846a2
84c31f6
f95f249
3fbba4e
bbc764c
5d3a508
2f4cf0e
3c1fa01
2fba7b4
cee6352
b6ae588
94b2b7a
e5b24d4
08a0ae0
b812df8
9341256
d0f58e0
86b5d9d
7c2982d
6144049
71f939a
c079cf2
07dd840
8d39adf
d4946b1
1a4e765
a3194fc
3360f7d
d19cc12
20d856c
e5a71eb
e303054
88f77e2
c6f5fb1
fb06047
7d70a07
870e05c
3912e79
ccd179c
301833e
bc433fb
2b0996c
9528157
efb237e
a838d81
5c71c64
cb7c848
878f821
6e6933a
b74a2ea
6854d7d
9efb99f
e882c31
e2d50bb
d2d4f02
edee33b
0739bd5
10cc9d2
252b2ca
31cc5e8
3390a5f
a9d9c4f
ff7de90
037914e
c065540
b352e42
b78b2bf
edcfb2f
c54f190
69764bb
5f6a99b
ad71018
f8d4f40
6de400f
d023db2
b53d822
abaaf42
5ffdaf0
2eb64d8
9aa445a
8ef3ccf
43cb33d
9e84510
925e6d6
8ac5f18
2333593
cfe5d32
240a519
c9df375
9935773
6b87e0d
c1bfd74
827edbc
27d89ed
6759fb7
d82de7c
972016a
02cb881
83050a5
562c083
02ae0c9
2c50ce3
b9791f5
3b033cf
9d80bcf
526db89
d2c30ef
a354d8b
d76d4a9
dbc7a1b
0011656
af6afcb
3f0fd1f
414d0bd
ade0ff6
785e4f7
dba20b2
4e6aa9a
8dbdf2b
dd03f4c
46bed46
5d360d6
44d7ac9
46f356a
c5d205e
e4a64ee
02eb3da
bda4c72
97e8a7c
1217a00
2c99cbf
4f6a239
3f60eda
c9459f7
8486bf0
f2467b0
06f58ff
1891a85
b832e70
0273f12
4c3d038
9194b76
9e183bf
457335a
f1b88ec
16f0c59
a08b581
45c01a8
610d83d
5a4b511
86b8308
55136bb
ed42acb
a403325
47da85d
82f797e
2e47389
a32b9ca
08ecb97
00639a8
78bd170
11692b2
d9413e0
14e1bca
397308b
3dc2df6
39c0fa5
6a5dc7c
c007b3f
5f446a2
fdb3c3f
4ee73f7
dd6b9ec
05ec13b
22349bf
d5e4a67
9807e5b
de22f28
45a0d2f
9e147ca
c6d8e7b
2bb8d13
ce4878f
96c4839
a6ce75b
9224b8e
a0987d0
dd20c4c
9976291
8d32524
99da0b6
cb316ca
350b3ff
20a8054
9c153ff
9a1235f
771cf35
708dce8
4479e4c
dafdbb4
6128a86
c7062e9
8a8cbee
c7bea21
82c64e4
f5ef7e0
2198108
c0220da
0a21870
bcb75bd
23ac85b
94e9e6d
b1e9cda
d3f602b
dcc5b54
3cacd0d
e94abfc
16ac490
779f518
fe18055
c5e7bf6
3e6c48c
159126c
86ecd9a
473ca9b
4695344
41b8362
dc290f8
6a0af0f
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,4 @@ | ||
| /*.js | ||
| !index.js | ||
| yarn.lock | ||
| gatsby-node.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,40 @@ | ||
| # gatsby-source-npm-package-search | ||
|
|
||
| This plugin uses Yarn's Algolia search to import all gatsby-related package info (any package with the gatsby-component or gatsby-plugin keyword). Check back for updates to search for other npm packages based on keyword. | ||
|
|
||
| ## Install | ||
| `npm install --save gatsby-source-npm` | ||
|
|
||
| ## How to use | ||
|
|
||
| ```javascript | ||
| // In your gatsby-config.js | ||
| plugins: [ | ||
| resolve: `gatsby-source-npm`, | ||
| options: { | ||
| keywords: [`keyword1`, `keyword2`] | ||
| } | ||
| ] | ||
| ``` | ||
|
|
||
| ## How to query | ||
|
|
||
| You can query npm nodes like the following | ||
|
|
||
| ```graphql | ||
| { | ||
| allNpmPackages{ | ||
| edges{ | ||
| node{ | ||
| name | ||
| humanDownloadsLast30Days | ||
| readme{ | ||
| childMarkdownRemark{ | ||
| html | ||
| } | ||
| } | ||
| } | ||
| } | ||
| } | ||
| } | ||
| ``` |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| // noop |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,22 @@ | ||
| { | ||
| "name": "gatsby-source-npm-package-search", | ||
| "version": "1.0.1", | ||
| "description": "Search gatsby plugins and pull metadata with algolia search", | ||
| "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"], | ||
| "author": "[email protected]", | ||
| "license": "MIT", | ||
| "dependencies": { | ||
| "algoliasearch": "^3.24.9", | ||
| "babel-runtime": "^6.26.0" | ||
| }, | ||
| "devDependencies": { | ||
| "babel-cli": "^6.26.0", | ||
| "cross-env": "^5.0.5" | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,83 @@ | ||
| const algoliasearch = require(`algoliasearch`) | ||
| const crypto = require(`crypto`) | ||
|
|
||
| const client = algoliasearch(`OFCNCOG2CU`, `f54e21fa3a2a0160595bb058179bfb1e`) | ||
| var index = client.initIndex(`npm-search`) | ||
|
|
||
| const createContentDigest = obj => | ||
| crypto | ||
| .createHash(`md5`) | ||
| .update(JSON.stringify(obj)) | ||
| .digest(`hex`) | ||
|
|
||
| exports.sourceNodes = async ( | ||
| { boundActionCreators, createNodeId }, | ||
| { keywords } | ||
| ) => { | ||
| const { createNode } = boundActionCreators | ||
|
|
||
| console.log(`Grabbing local NPM packages...`) | ||
|
|
||
| let buildFilter = [] | ||
|
|
||
| keywords.forEach(keyword => { | ||
| buildFilter.push(`keywords:${keyword}`) | ||
| }) | ||
|
|
||
| const data = await index.search({ | ||
| query: ``, | ||
| filters: `(${buildFilter.join(` OR `)})`, | ||
| hitsPerPage: 1000, | ||
| }) | ||
|
|
||
| // TODO: Currently the gatsby-transformer-remark plugin | ||
| // has a hard time with markdown that includes | ||
| // images -> for now this filters out those packages | ||
|
|
||
| data.hits.forEach(hit => { | ||
| if (hit.readme.includes(`![`)) { | ||
| return | ||
| } | ||
|
|
||
| const parentId = createNodeId(`plugin ${hit.objectID}`) | ||
| console.log(parentId) | ||
| const readmeNode = { | ||
| id: createNodeId(`readme ${hit.objectID}`), | ||
| parent: parentId, | ||
| slug: `/packages/en/${hit.objectID}`, | ||
| children: [], | ||
| internal: { | ||
| type: `NPMPackageReadme`, | ||
| mediaType: `text/markdown`, | ||
| content: hit.readme, | ||
|
||
| }, | ||
| } | ||
| readmeNode.internal.contentDigest = createContentDigest(readmeNode) | ||
| // Remove unneeded data | ||
| delete hit.readme | ||
| delete hit._highlightResult | ||
| delete hit.versions | ||
|
|
||
| const node = { | ||
| ...hit, | ||
| deprecated: `${hit.deprecated}`, | ||
| created: new Date(hit.created), | ||
| modified: new Date(hit.modified), | ||
| id: parentId, | ||
| parent: null, | ||
| children: [], | ||
| slug: `/packages/${hit.objectID}/`, | ||
| readme___NODE: readmeNode.id, | ||
| title: `${hit.objectID}`, | ||
| internal: { | ||
| type: `NPMPackage`, | ||
| content: hit.readme, | ||
| }, | ||
| } | ||
| node.internal.contentDigest = createContentDigest(node) | ||
| createNode(readmeNode) | ||
| createNode(node) | ||
| }) | ||
|
|
||
| return | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -6,6 +6,11 @@ const fs = require(`fs-extra`) | |
| const slash = require(`slash`) | ||
| const slugify = require(`limax`) | ||
|
|
||
| const localPackages = `../packages` | ||
| const localPackagesArr = [] | ||
| fs.readdirSync(localPackages).forEach(file => { | ||
|
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 wasn't finished — the idea here is for packages in this repo to use that README instead of what's grabbed from Algolia. The reason is that the Algolia README often doesn't have good links to images. So take this 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. I still don't understand exactly what needs to change on this, do you mean 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. Yeah — Algolia (via NPM) has a copy of the READMEs for packages in this repo. We'd prefer to use those as they any referenced images. 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. I came back to this this evening to look into finishing it up, sorry for the confusion on this, I want to make sure I can wrap my head around the actual issue though. As of now And then the packages that are fetched but aren't in the docs (like the typegen packages) should be filtered out? 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. You should create two template components. One for local packages and the other for remote. They'd share the same components for rendering data but the local package would query the local README while remote packages would query the NPM readme. Make sense? So when you're creating pages, filter out of the NPM packages anything in 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. Okay I'm getting on this now, thanks for the explanation that helps a lot 🙂 So rather than just having the template-docs-packages that renders local and remote packages, there will be two templates for the packages (like template-docs-local-packages/template-docs-remote-packages) that renders its respective data. |
||
| localPackagesArr.push(file) | ||
| }) | ||
| // convert a string like `/some/long/path/name-of-docs/` to `name-of-docs` | ||
| const slugToAnchor = slug => | ||
| slug | ||
|
|
@@ -21,14 +26,17 @@ exports.createPages = ({ graphql, boundActionCreators }) => { | |
| const contributorPageTemplate = path.resolve( | ||
| `src/templates/template-contributor-page.js` | ||
| ) | ||
| const packageTemplate = path.resolve( | ||
| `src/templates/template-docs-packages.js` | ||
| const localPackageTemplate = path.resolve( | ||
| `src/templates/template-docs-local-packages.js` | ||
| ) | ||
| const remotePackageTemplate = path.resolve( | ||
| `src/templates/template-docs-remote-packages.js` | ||
| ) | ||
| // Query for markdown nodes to use in creating pages. | ||
| resolve( | ||
| graphql( | ||
| ` | ||
| { | ||
| query { | ||
| allMarkdownRemark( | ||
| sort: { order: DESC, fields: [frontmatter___date] } | ||
| limit: 1000 | ||
|
|
@@ -57,6 +65,21 @@ exports.createPages = ({ graphql, boundActionCreators }) => { | |
| } | ||
| } | ||
| } | ||
| allNpmPackage { | ||
| edges { | ||
| node { | ||
| id | ||
| title | ||
| readme { | ||
| id | ||
| childMarkdownRemark { | ||
| id | ||
| html | ||
| } | ||
| } | ||
| } | ||
| } | ||
| } | ||
| } | ||
| ` | ||
| ).then(result => { | ||
|
|
@@ -114,7 +137,7 @@ exports.createPages = ({ graphql, boundActionCreators }) => { | |
| createPage({ | ||
| path: `${edge.node.fields.slug}`, // required | ||
| component: slash( | ||
| edge.node.fields.package ? packageTemplate : docsTemplate | ||
| edge.node.fields.package ? localPackageTemplate : docsTemplate | ||
| ), | ||
| context: { | ||
| slug: edge.node.fields.slug, | ||
|
|
@@ -123,6 +146,54 @@ exports.createPages = ({ graphql, boundActionCreators }) => { | |
| } | ||
| }) | ||
|
|
||
| const allPackages = result.data.allNpmPackage.edges | ||
| // Create local package readme | ||
| // this will filter on markdownremark a lot like the blog example above | ||
| let allLocalPackages = _.filter(allPackages, edge => { | ||
| const slug = _.get(edge, `node.fields.slug`) | ||
| // maybe add a deprectaed variable here | ||
| if (!slug) return | ||
|
|
||
| if (_.includes(slug, `/packages/`)) { | ||
| return edge | ||
| } | ||
| }) | ||
|
|
||
| allLocalPackages = allLocalPackages.forEach(edge => { | ||
| const slug = `/packages/${edge.node.title}/` | ||
|
|
||
| createPage({ | ||
| path: slug, | ||
| component: slash(localPackageTemplate), | ||
| context: { | ||
| slug, | ||
| id: edge.node.id, | ||
| }, | ||
| }) | ||
| }) | ||
|
|
||
| // Create remote package readme | ||
| // this just needs to filter the localPackagesArr out to make sure those aren't used | ||
| // const allRemotePackages = _.differenceWith( | ||
| // allPackages, // array of objects with names at node.title | ||
| // localPackagesArr, // array full of names | ||
| // (package, localName) => | ||
| // _.isMatchWith(package, localName, "node.title") | ||
| // ) | ||
| allPackages.forEach(edge => { | ||
| const slug = `/packages/${edge.node.title}/` | ||
| if (_.includes(localPackagesArr, edge.node.title)) return | ||
|
|
||
| createPage({ | ||
| path: slug, | ||
| component: slash(remotePackageTemplate), | ||
| context: { | ||
| slug, | ||
| id: edge.node.id, | ||
| }, | ||
| }) | ||
| }) | ||
|
|
||
| return | ||
| }) | ||
| ) | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -5,6 +5,7 @@ | |
| "author": "Kyle Mathews <[email protected]>", | ||
| "dependencies": { | ||
| "bluebird": "^3.5.1", | ||
| "date-fns": "^1.29.0", | ||
| "email-validator": "^1.1.1", | ||
| "gatsby": "^1.9.210", | ||
| "gatsby-image": "^1.0.39", | ||
|
|
@@ -47,6 +48,7 @@ | |
| "parse-filepath": "^1.0.2", | ||
| "react-helmet": "^5.2.0", | ||
| "react-icons": "^2.2.7", | ||
| "react-instantsearch": "^4.5.1", | ||
| "slash": "^1.0.0", | ||
| "typeface-space-mono": "^0.0.54", | ||
| "typeface-spectral": "^0.0.54", | ||
|
|
||
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.
This needs fixed
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.
@KyleAMathews I pulled this out and found the problem packages, in terms of fixing is something like a little regular expression that replaces the badges and images with empty strings in the readme's content (so the markdown can still function) good?