Skip to content

Commit

Permalink
feat(compat): create scripts to fetch metadata
Browse files Browse the repository at this point in the history
  • Loading branch information
TheLarkInn committed Feb 25, 2018
1 parent 3d096cb commit 1df6f60
Show file tree
Hide file tree
Showing 5 changed files with 57 additions and 3 deletions.
1 change: 1 addition & 0 deletions antwar.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ module.exports = {
vote: () => require('./src/components/Vote/Vote.jsx').default,
organization: () => require('./src/components/Organization/Organization.jsx').default,
'starter-kits': () => require('./src/components/StarterKits/StarterKits.jsx').default,
compatibility: () => require('./src/components/Compatibility/Compatibility.jsx').default,

/*************************
Redirects for Old Content
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@
"ncp": "^2.0.0",
"node-sass": "^4.5.3",
"npm-run-all": "^4.1.1",
"package-json": "^4.0.1",
"postcss-loader": "^2.0.6",
"prism-languages": "^0.3.3",
"prismjs": "^1.9.0",
Expand Down
52 changes: 52 additions & 0 deletions src/scripts/fetch_compat.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
#!/usr/bin/env node

const fs = require('fs');
const path = require('path');
const fetchPackageNames = require("./fetch_package_names");
const _ = require("lodash");

const fetchArgsArray = [
{
organization: "webpack-contrib",
suffix: "-loader"
},
{
organization: "webpack-contrib",
suffix: "-plugin"
}
];

async function fetchPackageNamesPromise(organization, suffix) {
return new Promise((resolve, reject) => {
fetchPackageNames({organization, suffix}, (err, data) => {
if (err) {
reject(err);
}
resolve(data);
});
});
}

async function getPackageJsonFiles(namesArray) {
const packageJson = require("package-json");
return Promise.all(namesArray.map((name) => packageJson(name, {allMetadata: true}) ));
}

async function main() {
try {
const [loaderNames, pluginNames] = await Promise.all(
fetchArgsArray.map(({organization, suffix}) => fetchPackageNamesPromise(organization, suffix))
);

This comment has been minimized.

Copy link
@lencioni

lencioni Feb 25, 2018

Contributor

We probably want to fill this out with relevant packages from other orgs/users. Do you happen to know if there is any canonicalish list sitting around somewhere?


const packageFiles = await getPackageJsonFiles([...loaderNames, ...pluginNames].map(d => d.name));

This comment has been minimized.

Copy link
@lencioni

lencioni Feb 25, 2018

Contributor

It seems that this strategy hinges on packages consistently specifying versions in their package json files, which I'm pretty sure is not very consistent across the ecosystem. As part of this tool (and perhaps the v4 release notes and other documentation), it might be a good idea to provide strong guidance to loaders and plugins about how to specify this dependency. Possibly even proactively reaching out via issues or PRs. I bet there are a lot of packages that just use * or specify no formal dependency at all.


console.log(packageFiles);

// TODO: Write to disk the JSON file that gets fetched and then add to script workflow.
// This should be saved in ./src/Compatibility/packages.json
} catch (e) {
console.error(e);
}
}

main();
4 changes: 2 additions & 2 deletions src/scripts/fetch_package_names.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ function main() {
}

fetchPackageNames({
organization: organization,
suffix: suffix
organization,
suffix
}, function(err, d) {
if (err) {
return console.error(err);
Expand Down
2 changes: 1 addition & 1 deletion yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -5207,7 +5207,7 @@ p-map@^1.1.1:
version "1.1.1"
resolved "https://registry.yarnpkg.com/p-map/-/p-map-1.1.1.tgz#05f5e4ae97a068371bc2a5cc86bfbdbc19c4ae7a"

package-json@^4.0.0:
package-json@^4.0.0, package-json@^4.0.1:
version "4.0.1"
resolved "https://registry.yarnpkg.com/package-json/-/package-json-4.0.1.tgz#8869a0401253661c4c4ca3da6c2121ed555f5eed"
dependencies:
Expand Down

0 comments on commit 1df6f60

Please sign in to comment.