From 180304b8412ca1f9f310e9920115d0b5509d36ff Mon Sep 17 00:00:00 2001 From: Gabriel Grubba <70247653+Grubba27@users.noreply.github.com> Date: Thu, 29 Jun 2023 10:04:48 -0300 Subject: [PATCH] chore: updated getExampleJSON abstraction --- tools/cli/commands.js | 47 ++++++++++++++++++++++++++----------------- 1 file changed, 29 insertions(+), 18 deletions(-) diff --git a/tools/cli/commands.js b/tools/cli/commands.js index 3cf8d0eccb..94a748bf07 100644 --- a/tools/cli/commands.js +++ b/tools/cli/commands.js @@ -554,6 +554,31 @@ main.registerCommand({ /////////////////////////////////////////////////////////////////////////////// // create /////////////////////////////////////////////////////////////////////////////// + +/** + * list of all the available skeletons similar to the property below + * { + * clock: { repo: 'https://github.com/meteor/clock' }, + * leaderboard: { repo: 'https://github.com/meteor/leaderboard' }, + * } + * @typedef {Object.} Skeletons + */ +/** + * Resolves into json with + * @returns {Promise<[Skeletons, null]> | Promise<[null, Error]>} + */ +function getExamplesJSON(){ + return tryRun(async () => { + const response = await httpHelpers.request({ + url: "https://cdn.meteor.com/static/meteor.json", + method: "GET", + useSessionHeader: true, + useAuthHeader: true, + }); + return JSON.parse(response.body); + }); +} + const DEFAULT_SKELETON = "react"; export const AVAILABLE_SKELETONS = [ "apollo", @@ -737,19 +762,12 @@ main.registerCommand({ if (options.list) { Console.info("Available examples:"); - const [json, err] = await tryRun(() => - httpHelpers.request({ - url: 'https://cdn.meteor.com/static/meteor.json', - method: "GET", - useSessionHeader: true, - useAuthHeader: true, - }) - ); + const [json, err] = await getExamplesJSON() if (err) { Console.error("Failed to fetch examples:", err.message); Console.info("Using cached examples.json"); } - const examples = err ? EXAMPLE_REPOSITORIES : JSON.parse(json); + const examples = err ? EXAMPLE_REPOSITORIES : json; _.each(examples, function (repoInfo, name) { const branchInfo = repoInfo.branch ? `/tree/${repoInfo.branch}` : ""; Console.info( @@ -961,21 +979,14 @@ main.registerCommand({ }; if (options.example) { - const [json, err] = await tryRun(() => - httpHelpers.request({ - url: 'https://cdn.meteor.com/static/meteor.json', - method: "GET", - useSessionHeader: true, - useAuthHeader: true, - }) - ); + const [json, err] = await getExamplesJSON(); if (err) { Console.error("Failed to fetch examples:", err.message); Console.info("Using cached examples.json"); } - const examples = err ? EXAMPLE_REPOSITORIES : JSON.parse(json); + const examples = err ? EXAMPLE_REPOSITORIES : json; const repoInfo = examples[options.example]; if (!repoInfo) { Console.error(`${options.example}: no such example.`);