Skip to content
This repository has been archived by the owner on Apr 1, 2020. It is now read-only.

Commit

Permalink
refactor rebuild function
Browse files Browse the repository at this point in the history
 🐿 v2.11.0
  • Loading branch information
kitkat119 committed Dec 5, 2018
1 parent 27d34d6 commit 8623a57
Showing 1 changed file with 17 additions and 8 deletions.
25 changes: 17 additions & 8 deletions build/app/cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ const grabNUiAssets = require('./grab-n-ui-assets');
const assetHashes = require('../lib/generate-asset-hashes');
const fetchres = require('fetchres');
const circleFetch = require('./circle-fetch');
const fetch = require('node-fetch');

const exit = err => {
logger.error(err);
Expand Down Expand Up @@ -72,8 +73,20 @@ const getRepoName = ({ repository }) => {

const serves = type => app => type ? app.types && app.types.includes(type) : true;

const allAppsToRebuild = async (allApps, registry, servesType) => {
let appsToRebuildArray = [];

const registryData = await fetch(registry).then(fetchres.json);
appsToRebuildArray = registryData
.filter(serves(servesType))
.map(getRepoName)
.filter(repo => repo);

return appsToRebuildArray;
};

async function rebuild (options) {
const { apps, allApps, registry = DEFAULT_REGISTRY_URI } = options;
const { apps, allApps, servesType, registry = DEFAULT_REGISTRY_URI } = options;
let appsToRebuild = [];

const areAppsToRebuild = (apps.length) || allApps;
Expand All @@ -85,11 +98,7 @@ async function rebuild (options) {
if (apps.length) {
appsToRebuild = apps;
} else if (allApps) {
const registryData = await fetch(registry).then(fetchres.json);
appsToRebuild = registryData
.filter(serves(options.serves))
.map(getRepoName)
.filter(repo => repo);
appsToRebuild = await allAppsToRebuild(allApps, registry, servesType);
}

return Promise.all(appsToRebuild.map(async app => {
Expand Down Expand Up @@ -183,9 +192,9 @@ program
devAdvice();
return rebuild({
apps: apps,
serves: opts.serves,
servesType: opts.serves,
registry: opts.registry,
all: opts.all
allApps: opts.all
}).catch(exit);
});

Expand Down

0 comments on commit 8623a57

Please sign in to comment.