diff --git a/bin/stencil-push b/bin/stencil-push index b70310a5..edea7f83 100755 --- a/bin/stencil-push +++ b/bin/stencil-push @@ -16,6 +16,7 @@ Program .option('-f, --file [filename]', 'specify the filename of the bundle to upload') .option('-s, --save [filename]', 'specify the filename to save the bundle as') .option('-a, --activate [variationname]', 'specify the variation of the theme to activate') + .option('-d, --delete', 'delete oldest private theme if upload limit reached') .parse(process.argv); if (!versionCheck()) { @@ -26,7 +27,8 @@ stencilPush(Object.assign({}, options, { apiHost: Program.host || apiHost, bundleZipPath: Program.file, activate: Program.activate, - saveBundleName: Program.save + saveBundleName: Program.save, + deleteOldest: Program.delete, }), (err, result) => { if (err) { console.log("\n\n" + 'not ok'.red + ` -- ${err} see details below:`); diff --git a/lib/stencil-push.utils.js b/lib/stencil-push.utils.js index a00fec8f..e867961f 100644 --- a/lib/stencil-push.utils.js +++ b/lib/stencil-push.utils.js @@ -131,7 +131,6 @@ utils.uploadBundle = (options, callback) => { error.name = 'ThemeUploadError'; return callback(error); } - callback(null, Object.assign({}, options, { jobId: result.jobId, themeLimitReached: !!result.themeLimitReached, @@ -140,7 +139,7 @@ utils.uploadBundle = (options, callback) => { }; utils.notifyUserOfThemeLimitReachedIfNecessary = (options, callback) => { - if (options.themeLimitReached) { + 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.`); } @@ -152,6 +151,14 @@ utils.promptUserToDeleteThemesIfNecessary = (options, callback) => { return async.nextTick(callback.bind(null, null, options)); } + if (options.deleteOldest) { + const oldestTheme = options.themes + .filter(theme => theme.is_private && !theme.is_active) + .map(theme => ({uuid: theme.uuid, updated_at : new Date(theme.updated_at).valueOf()})) + .reduce((prev, current) => prev.updated_at < current.updated_at ? prev : current) + return callback(null, Object.assign({}, options, {themeIdsToDelete: [oldestTheme.uuid]})); + } + const questions = [{ choices: options.themes.map(theme => ({ disabled: theme.is_active || !theme.is_private,