Skip to content

Commit 1df6f60

Browse files
committed
feat(compat): create scripts to fetch metadata
1 parent 3d096cb commit 1df6f60

File tree

5 files changed

+57
-3
lines changed

5 files changed

+57
-3
lines changed

antwar.config.js

+1
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,7 @@ module.exports = {
8989
vote: () => require('./src/components/Vote/Vote.jsx').default,
9090
organization: () => require('./src/components/Organization/Organization.jsx').default,
9191
'starter-kits': () => require('./src/components/StarterKits/StarterKits.jsx').default,
92+
compatibility: () => require('./src/components/Compatibility/Compatibility.jsx').default,
9293

9394
/*************************
9495
Redirects for Old Content

package.json

+1
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,7 @@
8080
"ncp": "^2.0.0",
8181
"node-sass": "^4.5.3",
8282
"npm-run-all": "^4.1.1",
83+
"package-json": "^4.0.1",
8384
"postcss-loader": "^2.0.6",
8485
"prism-languages": "^0.3.3",
8586
"prismjs": "^1.9.0",

src/scripts/fetch_compat.js

+52
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
#!/usr/bin/env node
2+
3+
const fs = require('fs');
4+
const path = require('path');
5+
const fetchPackageNames = require("./fetch_package_names");
6+
const _ = require("lodash");
7+
8+
const fetchArgsArray = [
9+
{
10+
organization: "webpack-contrib",
11+
suffix: "-loader"
12+
},
13+
{
14+
organization: "webpack-contrib",
15+
suffix: "-plugin"
16+
}
17+
];
18+
19+
async function fetchPackageNamesPromise(organization, suffix) {
20+
return new Promise((resolve, reject) => {
21+
fetchPackageNames({organization, suffix}, (err, data) => {
22+
if (err) {
23+
reject(err);
24+
}
25+
resolve(data);
26+
});
27+
});
28+
}
29+
30+
async function getPackageJsonFiles(namesArray) {
31+
const packageJson = require("package-json");
32+
return Promise.all(namesArray.map((name) => packageJson(name, {allMetadata: true}) ));
33+
}
34+
35+
async function main() {
36+
try {
37+
const [loaderNames, pluginNames] = await Promise.all(
38+
fetchArgsArray.map(({organization, suffix}) => fetchPackageNamesPromise(organization, suffix))
39+
);
40+
41+
const packageFiles = await getPackageJsonFiles([...loaderNames, ...pluginNames].map(d => d.name));
42+
43+
console.log(packageFiles);
44+
45+
// TODO: Write to disk the JSON file that gets fetched and then add to script workflow.
46+
// This should be saved in ./src/Compatibility/packages.json
47+
} catch (e) {
48+
console.error(e);
49+
}
50+
}
51+
52+
main();

src/scripts/fetch_package_names.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,8 @@ function main() {
2121
}
2222

2323
fetchPackageNames({
24-
organization: organization,
25-
suffix: suffix
24+
organization,
25+
suffix
2626
}, function(err, d) {
2727
if (err) {
2828
return console.error(err);

yarn.lock

+1-1
Original file line numberDiff line numberDiff line change
@@ -5207,7 +5207,7 @@ p-map@^1.1.1:
52075207
version "1.1.1"
52085208
resolved "https://registry.yarnpkg.com/p-map/-/p-map-1.1.1.tgz#05f5e4ae97a068371bc2a5cc86bfbdbc19c4ae7a"
52095209

5210-
package-json@^4.0.0:
5210+
package-json@^4.0.0, package-json@^4.0.1:
52115211
version "4.0.1"
52125212
resolved "https://registry.yarnpkg.com/package-json/-/package-json-4.0.1.tgz#8869a0401253661c4c4ca3da6c2121ed555f5eed"
52135213
dependencies:

0 commit comments

Comments
 (0)