Skip to content

Commit

Permalink
Readd push --retry option
Browse files Browse the repository at this point in the history
  • Loading branch information
fantonangeli committed Nov 14, 2021
1 parent 5fa0905 commit 02fdf21
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 2 deletions.
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,9 @@ You do not need a .clasp.json file anymore.

The following clasp commands are supported. For the documentation refer to the official [documentation](https://github.com/google/clasp)

- [`mutli-clasp push [--force]`](https://github.com/google/clasp#push)
- [`mutli-clasp push [--force --retry <n>]`](https://github.com/google/clasp#push) <br>
in addition to the clasp arguments there is the --retry option: If the push of an App Script fail with it will retry times. Default is 1.

- [`mutli-clasp status [--json]`](https://github.com/google/clasp#status)
- [`mutli-clasp open [--webapp] [--creds] [--addon]`](https://github.com/google/clasp#open)
- [`mutli-clasp deployments`](https://github.com/google/clasp#deployments)
Expand Down
4 changes: 3 additions & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { Config } from './config';
import { genericAction, readMultiClaspConfig, runClasp } from './common';
import {version} from '../package.json';
import run from './run';
import push from './push';

const program = new Command();

Expand All @@ -19,7 +20,8 @@ program
.command('push')
.description('Update the remote project')
.option('-f, --force', 'Forcibly overwrites the remote manifest.')
.action(genericAction);
.option('--retry <n>', 'If the push of an App Script fail with it will retry n times. Default is 1.', '1')
.action(push);

program
.command('open')
Expand Down
48 changes: 48 additions & 0 deletions src/push.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
import {foreachClasp, runClasp} from "./common";

interface CommandOption {
readonly retry?: string;
readonly force?: boolean;
}

/**
* Get Clasp Arguments.
*
* @param options.nondev {boolean} If we want to push the last deployed version vs the latest code.
* @param options.retry {number} If the push of an App Script fail with it will retry n times
* @returns {string} the command arguments
*/
function getPushClaspArgs(options: CommandOption): string{
let claspArgs = "";

if (!options) {
return claspArgs;
}

claspArgs += options.force?" --force":"";

return claspArgs;
}

/**
* Uploads all files into the script.google.com filesystem.
* @param options.watch {boolean} If true, runs `clasp push` when any local file changes. Exit with ^C.
* @param options.retry {number} If the push of an App Script fail with it will retry n times
*/
export default async (options: CommandOption): Promise<void> => {
const retry = parseInt(options.retry);

foreachClasp(async (claspConfig)=>{
let retVal = false;

for (let r = 0; r < retry; r++) {
retVal = await runClasp(claspConfig, process.argv[2], getPushClaspArgs(options));
if(retVal){
break;
}
}
if(!retVal){
process.exit(1);
}
});
};

0 comments on commit 02fdf21

Please sign in to comment.