Skip to content

Commit

Permalink
Change args in deploy command (#376)
Browse files Browse the repository at this point in the history
#366 

This PR follows the design of  #372 (comment) .

- [ ] `npm run test` succeeds.
- [x] `npm run lint` succeeds.
- [x] Appropriate changes to README are included in PR.

I am struggling to think of the name of args and I want your idea.
#366 (comment)
  • Loading branch information
takanakahiko authored and grant committed Nov 4, 2018
1 parent 6d21e0f commit dab3a58
Show file tree
Hide file tree
Showing 3 changed files with 60 additions and 36 deletions.
15 changes: 9 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ clasp
- [`clasp status`](#status)
- [`clasp open [scriptId] [--webapp]`](#open)
- [`clasp deployments`](#deployments)
- [`clasp deploy [version] [description]`](#deploy)
- [`clasp deploy [--versionNumber <version>] [--desc <description>] [--deploymentId <id>]`](#deploy)
- [`clasp undeploy <deploymentId>`](#undeploy)
- [`clasp redeploy [deploymentId] [version] [description]`](#redeploy)
- [`clasp version [description]`](#version)
Expand Down Expand Up @@ -223,14 +223,17 @@ The response gives the version of the deployment.

#### Options

- `version`: The version number.
- `description`: The deployment description.
- `-V <version>` `--versionNumber <version>`: The project version to deploy at.
- `-d <description>` `--description <description>`: The deployment description.
- `-i <id>` `--deploymentId <id>`: The deployment ID to redeploy.

#### Examples

- `clasp deploy`
- `clasp deploy 4`
- `clasp deploy 7 "Updates sidebar logo."`
- `clasp deploy` (create new deployment and new version)
- `clasp deploy --versionNumber 4` (create new deployment)
- `clasp deploy --desc "Updates sidebar logo."` (deploy with description)
- `clasp deploy --deploymentId 123` (create new version)
- `clasp deploy -V 7 -d "Updates sidebar logo." -i 456`

### Undeploy

Expand Down
66 changes: 42 additions & 24 deletions src/commands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -513,50 +513,68 @@ export const run = async (functionName: string, cmd: { nondev: boolean }) => {

/**
* Deploys an Apps Script project.
* @param version {string} The project version to deploy at.
* @param description {string} The deployment's description.
* @param cmd.versionNumber {string} The project version to deploy at.
* @param cmd.desc {string} The deployment description.
* @param cmd.deploymentId {string} The deployment ID to redeploy.
*/
export const deploy = async (version: number, description = '') => {
export const deploy = async (cmd: {
versionNumber: number,
description: string,
deploymentId: string,
}) => {
await checkIfOnline();
await loadAPICredentials();
const { scriptId } = await getProjectSettings();
if (!scriptId) return;
spinner.setSpinnerTitle(LOG.DEPLOYMENT_START(scriptId)).start();
async function createDeployment(versionNumber: number) {
spinner.setSpinnerTitle(LOG.DEPLOYMENT_CREATE);
const deployments = await script.projects.deployments.create({
let { versionNumber } = cmd;
const { description='', deploymentId } = cmd;

// if no version, create a new version
if (!versionNumber){
const version = await script.projects.versions.create({
scriptId,
requestBody: {
description,
manifestFileName: PROJECT_MANIFEST_BASENAME,
versionNumber,
},
});
spinner.stop(true);
if (deployments.status !== 200) {
logError(null, ERROR.DEPLOYMENT_COUNT);
} else {
console.log(`- ${deployments.data.deploymentId} @${versionNumber}.`);
if (version.status !== 200) {
return logError(null, ERROR.ONE_DEPLOYMENT_CREATE);
}
versionNumber = version.data.versionNumber || 0;
console.log(LOG.VERSION_CREATED(versionNumber));
}

// If the version is specified, update that deployment
if (version) {
createDeployment(version);
} else { // if no version, create a new version and deploy that
const version = await script.projects.versions.create({
spinner.setSpinnerTitle(LOG.DEPLOYMENT_CREATE);
let deployments;
if (!deploymentId) { // if no deploymentId, create a new deployment
deployments = await script.projects.deployments.create({
scriptId,
requestBody: {
versionNumber,
manifestFileName: PROJECT_MANIFEST_BASENAME,
description,
},
});
spinner.stop(true);
if (version.status !== 200) {
return logError(null, ERROR.ONE_DEPLOYMENT_CREATE);
}
const versionNumber = version.data.versionNumber || 0;
console.log(LOG.VERSION_CREATED(versionNumber));
createDeployment(versionNumber);
} else { // elseif, update deployment
deployments = await script.projects.deployments.update({
scriptId,
deploymentId,
requestBody: {
deploymentConfig: {
versionNumber,
manifestFileName: PROJECT_MANIFEST_BASENAME,
description,
},
},
});
}
spinner.stop(true);
if (deployments.status !== 200) {
logError(null, ERROR.DEPLOYMENT_COUNT);
} else {
console.log(`- ${deployments.data.deploymentId} @${versionNumber}.`);
}
};

Expand Down
15 changes: 9 additions & 6 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -184,15 +184,18 @@ commander
* Creates a version and deploys a script.
* The response gives the version of the deployment.
* @name deploy
* @param {number} [version] The version number.
* @param {string} [description] The deployment description.
* @example deploy
* @example deploy 4
* @example deploy 7 "Updates sidebar logo."
* @example deploy (create new deployment and new version)
* @example deploy --versionNumber 4 (create new deployment)
* @example deploy --description "Updates sidebar logo." (deploy with description)
* @example deploy --deploymentId 123 (create new version)
* @example deploy -V 7 -d "Updates sidebar logo." -i 456
*/
commander
.command('deploy [version] [description]')
.command('deploy')
.description('Deploy a project')
.option('-V, --versionNumber <version>', 'The project version') //we can't use `version` in subcommand
.option('-d, --description <description>', 'The deployment description')
.option('-i, --deploymentId <id>', 'The deployment ID to redeploy')
.action(deploy);

/**
Expand Down

0 comments on commit dab3a58

Please sign in to comment.