-
-
Save mythmon/c8587ed7cbccddc16f49412f9d49f0f0 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* This Source Code Form is subject to the terms of the Mozilla Public | |
* License, v. 2.0. If a copy of the MPL was not distributed with this | |
* file, You can obtain one at http://mozilla.org/MPL/2.0/. | |
*/ | |
/* | |
* This is a Node.js script to get a list of all add-on studies deployed | |
* through Normandy by their slug name and file size. This requires joining | |
* information from the Normandy API and response header info from AWS, where | |
* each add-on's XPI is hosted. | |
* | |
* How to run: | |
* | |
* cd addoninfo | |
* yarn install | |
* node index.js | |
* | |
* Generated output is 'addonInfo.json' | |
*/ | |
const fetch = require("node-fetch"); | |
const fs = require("fs"); | |
const { promisify } = require("util"); | |
const NORMANDY_API_BASE = "https://normandy.cdn.mozilla.net/api/v3"; | |
async function getAddonInfo() { | |
const addonInfo = {}; | |
for await (const recipe of getAllRecipesByAction("opt-out-study")) { | |
const { name, addonUrl } = recipe.arguments; | |
if (!addonUrl) { | |
console.error(`recipe ${name} has no addonUrl`); | |
continue; | |
} | |
if (!recipe.filter_expression.includes("isFirstRun")) { | |
continue; | |
} | |
const res = await fetch(addonUrl, { method: 'HEAD' }); | |
addonInfo[name] = { | |
addonUrl, | |
name, | |
addonSize: parseInt(res.headers.get("content-length")), | |
} | |
} | |
await promisify(fs.writeFile)("addonInfo.json", JSON.stringify(addonInfo, null, 4)); | |
} | |
async function* getAllRecipesByAction(action) { | |
let url = `${NORMANDY_API_BASE}/recipe/?action=${action}`; | |
while (url) { | |
const res = await fetch(url); | |
const data = await res.json(); | |
for (const recipe of data.results) { | |
yield recipe; | |
} | |
url = data.next; | |
} | |
} | |
getAddonInfo(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"name": "addoninfo", | |
"version": "1.0.0", | |
"main": "index.js", | |
"license": "MIT", | |
"dependencies": { | |
"node-fetch": "^2.1.2" | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY. | |
# yarn lockfile v1 | |
node-fetch@^2.1.2: | |
version "2.1.2" | |
resolved "https://registry.yarnpkg.com/node-fetch/-/node-fetch-2.1.2.tgz#ab884e8e7e57e38a944753cec706f788d1768bb5" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment