Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
199 additions
and
165 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
import { | ||
loadAPICredentials, | ||
script, | ||
} from './../auth'; | ||
import { | ||
ERROR, | ||
LOG, | ||
PROJECT_MANIFEST_BASENAME, | ||
checkIfOnline, | ||
getProjectSettings, | ||
logError, | ||
spinner, | ||
} from './../utils'; | ||
|
||
/** | ||
* Deploys an Apps Script project. | ||
* @param cmd.versionNumber {string} The project version to deploy at. | ||
* @param cmd.description {string} The deployment description. | ||
* @param cmd.deploymentId {string} The deployment ID to redeploy. | ||
*/ | ||
export default 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(); | ||
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, | ||
}, | ||
}); | ||
spinner.stop(true); | ||
if (version.status !== 200) { | ||
return logError(null, ERROR.ONE_DEPLOYMENT_CREATE); | ||
} | ||
versionNumber = version.data.versionNumber || 0; | ||
console.log(LOG.VERSION_CREATED(versionNumber)); | ||
} | ||
|
||
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, | ||
}, | ||
}); | ||
} 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}.`); | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
import * as pluralize from 'pluralize'; | ||
import { | ||
loadAPICredentials, | ||
script, | ||
} from './../auth'; | ||
import { | ||
LOG, | ||
checkIfOnline, | ||
getProjectSettings, | ||
logError, | ||
spinner, | ||
} from './../utils'; | ||
|
||
/** | ||
* Lists a script's deployments. | ||
*/ | ||
export default async () => { | ||
await checkIfOnline(); | ||
await loadAPICredentials(); | ||
const { scriptId } = await getProjectSettings(); | ||
if (!scriptId) return; | ||
spinner.setSpinnerTitle(LOG.DEPLOYMENT_LIST(scriptId)).start(); | ||
const deployments = await script.projects.deployments.list({ | ||
scriptId, | ||
}); | ||
spinner.stop(true); | ||
if (deployments.status !== 200) { | ||
return logError(deployments.statusText); | ||
} | ||
const deploymentsList = deployments.data.deployments || []; | ||
const numDeployments = deploymentsList.length; | ||
const deploymentWord = pluralize('Deployment', numDeployments); | ||
console.log(`${numDeployments} ${deploymentWord}.`); | ||
deploymentsList.map(({ deploymentId, deploymentConfig }: any) => { | ||
const versionString = !!deploymentConfig.versionNumber ? `@${deploymentConfig.versionNumber}` : '@HEAD'; | ||
const description = deploymentConfig.description ? '- ' + deploymentConfig.description : ''; | ||
console.log(`- ${deploymentId} ${versionString} ${description}`); | ||
}); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
import { | ||
loadAPICredentials, | ||
script, | ||
} from './../auth'; | ||
import { | ||
ERROR, | ||
LOG, | ||
checkIfOnline, | ||
getProjectSettings, | ||
logError, | ||
spinner, | ||
} from './../utils'; | ||
|
||
/** | ||
* Removes a deployment from the Apps Script project. | ||
* @param deploymentId {string} The deployment's ID | ||
*/ | ||
export default async (deploymentId: string, cmd: { all: boolean }) => { | ||
await checkIfOnline(); | ||
await loadAPICredentials(); | ||
const { scriptId } = await getProjectSettings(); | ||
if (!scriptId) return; | ||
if (cmd.all) { | ||
const deploymentsList = await script.projects.deployments.list({ | ||
scriptId, | ||
}); | ||
if (deploymentsList.status !== 200) { | ||
return logError(deploymentsList.statusText); | ||
} | ||
const deployments = deploymentsList.data.deployments || []; | ||
if (!deployments.length) { | ||
logError(null, ERROR.SCRIPT_ID_INCORRECT(scriptId)); | ||
} | ||
deployments.shift(); // @HEAD (Read-only deployments) may not be deleted. | ||
for (const deployment of deployments) { | ||
const deploymentId = deployment.deploymentId || ''; | ||
spinner.setSpinnerTitle(LOG.UNDEPLOYMENT_START(deploymentId)).start(); | ||
const result = await script.projects.deployments.delete({ | ||
scriptId, | ||
deploymentId, | ||
}); | ||
spinner.stop(true); | ||
if (result.status !== 200) { | ||
return logError(null, ERROR.READ_ONLY_DELETE); | ||
} | ||
console.log(LOG.UNDEPLOYMENT_FINISH(deploymentId)); | ||
} | ||
console.log(LOG.UNDEPLOYMENT_ALL_FINISH); | ||
return; | ||
} | ||
if (!deploymentId) { | ||
const deploymentsList = await script.projects.deployments.list({ | ||
scriptId, | ||
}); | ||
if (deploymentsList.status !== 200) { | ||
return logError(deploymentsList.statusText); | ||
} | ||
const deployments = deploymentsList.data.deployments || []; | ||
if (!deployments.length) { | ||
logError(null, ERROR.SCRIPT_ID_INCORRECT(scriptId)); | ||
} | ||
if (deployments.length <= 1) { | ||
// @HEAD (Read-only deployments) may not be deleted. | ||
logError(null, ERROR.NO_VERSIONED_DEPLOYMENTS); | ||
} | ||
deploymentId = deployments[deployments.length - 1].deploymentId || ''; | ||
} | ||
spinner.setSpinnerTitle(LOG.UNDEPLOYMENT_START(deploymentId)).start(); | ||
const deployment = await script.projects.deployments.delete({ | ||
scriptId, | ||
deploymentId, | ||
}); | ||
spinner.stop(true); | ||
if (deployment.status !== 200) { | ||
return logError(null, ERROR.READ_ONLY_DELETE); | ||
} else { | ||
console.log(LOG.UNDEPLOYMENT_FINISH(deploymentId)); | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.