Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions lib/deploy/defaultStrategy.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ const createArchive = async (env) => {
if (numberOfFiles == 0) throw 'Archive failed to create.';
};

const uploadArchive = async (env) => {
const res = await push(env);
const uploadArchive = async (env, { spinner } = {}) => {
const res = await push(env, { spinner });
if (!res) throw 'Server did not accept release file.';

return res;
Expand All @@ -27,7 +27,7 @@ const strategy = async ({ env, _authData, _params }) => {
const spinner = ora({ text: `Deploying to: ${url}`, stream: process.stdout });
spinner.start();

const duration = await uploadArchive(env);
const duration = await uploadArchive(env, { spinner });

spinner.succeed(`Deploy succeeded after ${duration}`);
report('[OK] Deploy: Default Strategy');
Expand Down
4 changes: 2 additions & 2 deletions lib/deploy/directAssetsUploadStrategy.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import report from '../logger/report.js';
import ServerError from '../ServerError.js';

const createArchive = (env) => makeArchive(env, { withoutAssets: true });
const uploadArchive = (env) => push(env);
const uploadArchive = (env, { spinner } = {}) => push(env, { spinner });

const deployAndUploadAssets = async (authData) => {
const assetsToDeploy = await files.getAssets();
Expand All @@ -34,7 +34,7 @@ const strategy = async ({ env, authData, _params }) => {

const t0 = performance.now();
if (numberOfFiles > 0) {
await uploadArchive(env);
await uploadArchive(env, { spinner });
} else {
logger.Warn('There are no files in release file, skipping.');
}
Expand Down
4 changes: 2 additions & 2 deletions lib/deploy/dryRunStrategy.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import report from '../logger/report.js';
import ServerError from '../ServerError.js';

const createArchive = (env) => makeArchive(env, { withoutAssets: true });
const uploadArchive = (env) => push(env);
const uploadArchive = (env, { spinner } = {}) => push(env, { spinner });

const strategy = async ({ env, _authData, _params }) => {
env.DRY_RUN = 'true';
Expand All @@ -24,7 +24,7 @@ const strategy = async ({ env, _authData, _params }) => {
spinner.start();

if (numberOfFiles > 0) {
await uploadArchive(env);
await uploadArchive(env, { spinner });
} else {
logger.Warn('There are no files in release file, skipping.');
}
Expand Down
10 changes: 7 additions & 3 deletions lib/push.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,14 +45,18 @@ const printDeployReport = (deployReport, { verbose = false } = {}) => {
const MAX_STATUS_RETRIES = 3;
const isTransientError = (e) => e.name === 'RequestError' || (e.name === 'StatusCodeError' && e.statusCode >= 500);

const getDeploymentStatus = ({ id }) => {
const getDeploymentStatus = ({ id }, { spinner } = {}) => {
return new Promise((resolve, reject) => {
let retries = 0;
let getStatus = () => {
gateway
.getStatus(id)
.then(response => {
if (response && response.status === 'ready_for_import') {
if (spinner) spinner.text = 'Deploy scheduled, waiting…';
setTimeout(getStatus, 1000);
} else if (response && response.status === 'in_progress') {
if (spinner) spinner.text = 'Deploy in progress…';
setTimeout(getStatus, 1000);
} else if (response && response.status === 'error') {
const body = response.error;
Expand Down Expand Up @@ -80,7 +84,7 @@ const getDeploymentStatus = ({ id }) => {
});
};

const push = async env => {
const push = async (env, { spinner } = {}) => {
const program = {
email: env.MARKETPLACE_EMAIL,
token: env.MARKETPLACE_TOKEN,
Expand All @@ -99,7 +103,7 @@ const push = async env => {
gateway = new Gateway(program);
return gateway
.push(formData)
.then(getDeploymentStatus)
.then(res => getDeploymentStatus(res, { spinner }))
.then((response) => {
logger.Debug('Release deployed');
printDeployReport(response.report, { verbose: env.VERBOSE === true || env.VERBOSE === 'true' });
Expand Down
51 changes: 11 additions & 40 deletions package-lock.json

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

3 changes: 2 additions & 1 deletion test/unit/deploy.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@ vi.mock('ora', () => ({
start: vi.fn().mockReturnThis(),
succeed: vi.fn().mockReturnThis(),
fail: vi.fn().mockReturnThis(),
stop: vi.fn().mockReturnThis()
stop: vi.fn().mockReturnThis(),
text: ''
})
}));

Expand Down