dpa99c/cordova-plugin-androidx-adapter

Provide the source to generate the JSON mapping files

Closed this issue · 4 comments

This would interested developers and easy way to re-generate those files and submit those as a PR, because some libraries already have newer versions published. 🤓

As mentioned in the documentation, the mappings are scraped from the Android docs:

I used a regex to parse the CSV into JSON format.
It would be good to write a node script to perform that task but I haven't had time.

Thanks for the information. I imagined there already exists a script :)

Thanks for the information. I imagined there already exists a script :)

Hi, something in the lines of

(echo "{" ; while IFS=, read -r f1 f2; do echo "\"$f1\":\"$f2\","; done < androidx-artifact-mapping.csv ; echo "}" ) > output.json

This, with some kind of adaptation might do.

I've built a little scraper around mvnrepository.com since I haven't found a good API for their site nor maven.google.com. It pulls the latest available versions (releases and RCs) and updates the JSON file.

But I'm too ashamed to check my dirty script into scm - so here we go:

const fs = require("fs");
const puppeteer = require("puppeteer");

const artifactMappings = JSON.parse(
  fs.readFileSync("../artifact-mappings.json", "utf-8")
);

(async () => {
  const browser = await puppeteer.launch();
  const page = await browser.newPage();
  for (let [key, value] of Object.entries(artifactMappings)) {
    const parts = value.split(":");
    await page.goto(
      `https://mvnrepository.com/artifact/${parts[0]}/${parts[1]}`
    );
    const newVersion = await page
      .evaluate(() => {
        return document.querySelector("a.vbtn.release").textContent;
      })
      .catch((_) => {
        console.log(
          `Warning, artifact not found, please check ${value} manually!`
        );
      });
    if (newVersion) {
      artifactMappings[key] = [parts[0], parts[1], newVersion].join(":");
    }
  }
  await browser.close();

  fs.writeFileSync(
    "../artifact-mappings.json",
    JSON.stringify(artifactMappings, null, "\t")
  );
})();