Skip to content

Commit

Permalink
feat: (strf-8674) update "async" npm package
Browse files Browse the repository at this point in the history
  • Loading branch information
MaxGenash committed Sep 21, 2020
1 parent 4dea617 commit 9f64096
Show file tree
Hide file tree
Showing 6 changed files with 32 additions and 38 deletions.
3 changes: 1 addition & 2 deletions bin/stencil-download.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
require('colors');
const inquirer = require('inquirer');
const program = require('../lib/commander');
const { promisify } = require("util");

const { API_HOST, PACKAGE_INFO, DOT_STENCIL_FILE_PATH } = require('../constants');
const stencilDownload = require('../lib/stencil-download');
Expand Down Expand Up @@ -50,7 +49,7 @@ async function run (opts) {
console.log(`${'ok'.green} -- ${overwriteType} will be overwritten by change`);

try {
await promisify(stencilDownload)(opts);
await stencilDownload(opts);
} catch (err) {
printCliResultError(err);
return;
Expand Down
23 changes: 11 additions & 12 deletions lib/stencil-download.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,15 @@ let stencilDownloadUtil = require('./stencil-download.utils');

module.exports = stencilDownload;

function stencilDownload(options, callback) {
async.waterfall(
[
async.constant(options),
stencilPushUtils.readStencilConfigFile,
stencilPushUtils.getStoreHash,
stencilPushUtils.getThemes,
stencilPullUtils.selectActiveTheme,
stencilPullUtils.startThemeDownloadJob,
stencilPushUtils.pollForJobCompletion(({download_url: downloadUrl}) => ({downloadUrl})),
stencilDownloadUtil.downloadThemeFiles,
], callback);
function stencilDownload(options) {
return async.waterfall([
async.constant(options),
stencilPushUtils.readStencilConfigFile,
stencilPushUtils.getStoreHash,
stencilPushUtils.getThemes,
stencilPullUtils.selectActiveTheme,
stencilPullUtils.startThemeDownloadJob,
stencilPushUtils.pollForJobCompletion(({ download_url: downloadUrl }) => ({ downloadUrl })),
stencilDownloadUtil.downloadThemeFiles,
]);
}
16 changes: 7 additions & 9 deletions lib/stencil-push.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
const fetchMock = require('node-fetch');
const { promisify } = require('util');

const StencilPush = require('./stencil-push');
const stencilPush = require('./stencil-push');
const utils = require('./stencil-push.utils.js');
const { MockDB } = require('../test/_mocks/MockDB');

Expand Down Expand Up @@ -36,25 +36,23 @@ describe('stencil push', () => {
mockDb.data = {};
});

it('should throw an error if dotStencilFilePath is not provided', () => {
const throws = () => {
StencilPush();
};

expect(throws).toThrow('dotStencilFilePath is required!');
it('should throw an error if dotStencilFilePath is not provided', async () => {
await expect(
promisify(stencilPush)({}),
).rejects.toThrow('dotStencilFilePath is required!');
});

it('should return an error if dotStencilFilePath does not map to a file', async () => {
await expect(
promisify(StencilPush)({ dotStencilFilePath: 'DNE' }),
promisify(stencilPush)({ dotStencilFilePath: 'DNE' }),
).rejects.toThrow(/ENOENT/);
});

it('should return an error if it fails to retrieve the store hash', async () => {
const dotStencilFilePath = `${__dirname}/../test/_mocks/bin/dotStencilFile.json`;

await expect(
promisify(StencilPush)({ dotStencilFilePath }),
promisify(stencilPush)({ dotStencilFilePath }),
).rejects.toThrow('Received empty store_hash value in the server response');
});
});
17 changes: 9 additions & 8 deletions lib/stencil-push.utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ utils.generateBundle = (options, callback) => {
};

if (options.bundleZipPath) {
return async.nextTick(callback.bind(null, null, options));
return callback(null, options);
}

if (options.saveBundleName) {
Expand Down Expand Up @@ -134,12 +134,12 @@ utils.uploadBundle = async options => {
}
};

utils.notifyUserOfThemeLimitReachedIfNecessary = (options, callback) => {
utils.notifyUserOfThemeLimitReachedIfNecessary = async options => {
if (options.themeLimitReached && !options.deleteOldest) {
console.log('warning'.yellow + ` -- You have reached your upload limit. In order to proceed, you'll need to delete at least one theme.`);
}

return async.nextTick(callback.bind(null, null, options));
return options;
};

utils.promptUserToDeleteThemesIfNecessary = async options => {
Expand Down Expand Up @@ -198,17 +198,18 @@ utils.deleteThemesIfNecessary = async options => {
return options;
};

utils.uploadBundleAgainIfNecessary = (options, callback) => {
utils.uploadBundleAgainIfNecessary = async options => {
if (!options.themeLimitReached) {
return async.nextTick(callback.bind(null, null, options));
return options;
}

utils.uploadBundle(options, callback);
return utils.uploadBundle(options);
};

utils.notifyUserOfThemeUploadCompletion = (options, callback) => {
utils.notifyUserOfThemeUploadCompletion = async options => {
console.log('ok'.green + ' -- Theme Upload Finished');
return async.nextTick(callback.bind(null, null, options));

return options;
};

utils.markJobProgressPercentage = percentComplete => {
Expand Down
9 changes: 3 additions & 6 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@
"accept-language-parser": "^1.5.0",
"ajv": "^6.12.4",
"archiver": "^5.0.0",
"async": "^2.4.0",
"async": "^3.2.0",
"browser-sync": "^2.26.12",
"cheerio": "^0.22.0",
"colors": "^1.4.0",
Expand Down

0 comments on commit 9f64096

Please sign in to comment.