diff --git a/deploy/googleDeploy.js b/deploy/googleDeploy.js index 98360fa..ad209c0 100644 --- a/deploy/googleDeploy.js +++ b/deploy/googleDeploy.js @@ -17,6 +17,15 @@ class GoogleDeploy { this.options = options; this.provider = this.serverless.getProvider('google'); + let deployProgress; + + if (this.provider.progress) { + deployProgress = this.provider.progress.create({ + message: 'Beginning deployment', + name: 'deploy', + }); + } + Object.assign( this, validate, @@ -39,7 +48,10 @@ class GoogleDeploy { .then(this.uploadArtifacts) .then(this.updateDeployment), - 'after:deploy:deploy': () => BbPromise.bind(this).then(this.cleanupDeploymentBucket), + 'after:deploy:deploy': () => + BbPromise.bind(this) + .then(this.cleanupDeploymentBucket) + .finally(() => deployProgress && deployProgress.remove()), }; } } diff --git a/deploy/lib/cleanupDeploymentBucket.js b/deploy/lib/cleanupDeploymentBucket.js index d41f965..de20832 100644 --- a/deploy/lib/cleanupDeploymentBucket.js +++ b/deploy/lib/cleanupDeploymentBucket.js @@ -44,7 +44,11 @@ module.exports = { removeObjects(objectsToRemove) { if (!objectsToRemove.length) return BbPromise.resolve(); - this.serverless.cli.log('Removing old artifacts...'); + if (this.provider.progress) { + this.provider.progress.get('deploy').update('Removing old artifacts from deployment bucket'); + } else { + this.serverless.cli.log('Removing old artifacts...'); + } const removePromises = objectsToRemove.map((object) => { const params = { diff --git a/deploy/lib/createDeployment.js b/deploy/lib/createDeployment.js index 2f2ca9e..70a6008 100644 --- a/deploy/lib/createDeployment.js +++ b/deploy/lib/createDeployment.js @@ -34,7 +34,11 @@ module.exports = { createIfNotExists(foundDeployment) { if (foundDeployment) return BbPromise.resolve(); - this.serverless.cli.log('Creating deployment...'); + if (this.provider.progress) { + this.provider.progress.get('deploy').update('Creating deployment via Deployment Manager'); + } else { + this.serverless.cli.log('Creating deployment...'); + } const filePath = path.join( this.serverless.config.servicePath, diff --git a/deploy/lib/updateDeployment.js b/deploy/lib/updateDeployment.js index 07c7523..f05d6ce 100644 --- a/deploy/lib/updateDeployment.js +++ b/deploy/lib/updateDeployment.js @@ -28,7 +28,11 @@ module.exports = { }, update(deployment) { - this.serverless.cli.log('Updating deployment...'); + if (this.provider.progress) { + this.provider.progress.get('deploy').update('Updating deployment'); + } else { + this.serverless.cli.log('Updating deployment...'); + } const filePath = path.join( this.serverless.config.servicePath, diff --git a/deploy/lib/uploadArtifacts.js b/deploy/lib/uploadArtifacts.js index c9773e4..f847510 100644 --- a/deploy/lib/uploadArtifacts.js +++ b/deploy/lib/uploadArtifacts.js @@ -4,7 +4,11 @@ const fs = require('fs'); module.exports = { uploadArtifacts() { - this.serverless.cli.log('Uploading artifacts...'); + if (this.provider.progress) { + this.provider.progress.get('deploy').update('Uploading artifacts'); + } else { + this.serverless.cli.log('Uploading artifacts...'); + } const params = { bucket: this.serverless.service.provider.deploymentBucketName, @@ -19,7 +23,9 @@ module.exports = { }; return this.provider.request('storage', 'objects', 'insert', params).then(() => { - this.serverless.cli.log('Artifacts successfully uploaded...'); + if (!this.provider.progress) { + this.serverless.cli.log('Artifacts successfully uploaded...'); + } }); }, }; diff --git a/index.js b/index.js index b3295be..b02daaa 100644 --- a/index.js +++ b/index.js @@ -16,10 +16,16 @@ const GoogleLogs = require('./logs/googleLogs'); const GoogleInfo = require('./info/googleInfo'); class GoogleIndex { - constructor(serverless, options) { + constructor(serverless, options, v3Utils) { this.serverless = serverless; this.options = options; + if (v3Utils) { + this.log = v3Utils.log; + this.progress = v3Utils.progress; + this.writeText = v3Utils.writeText; + } + this.serverless.pluginManager.addPlugin(GoogleProvider); this.serverless.pluginManager.addPlugin(GooglePackage); this.serverless.pluginManager.addPlugin(GoogleDeploy); diff --git a/info/lib/displayServiceInfo.js b/info/lib/displayServiceInfo.js index 9e390ac..1e4c6a9 100644 --- a/info/lib/displayServiceInfo.js +++ b/info/lib/displayServiceInfo.js @@ -65,7 +65,7 @@ module.exports = { return BbPromise.resolve(data); }, - printInfo(data) { + printInfoV2(data) { let message = ''; // get all the service related information @@ -89,6 +89,37 @@ module.exports = { } this.serverless.cli.consoleLog(message); + }, + + printInfoV3(data) { + // get all the service related information + this.serverless.addServiceOutputSection('Service', data.service); + this.serverless.addServiceOutputSection('Project', data.project); + this.serverless.addServiceOutputSection('Stage', data.stage); + this.serverless.addServiceOutputSection('Region', data.region); + + // get all the functions + if (data.resources.functions.length) { + this.serverless.addServiceOutputSection( + 'Deployed Functions', + data.resources.functions.reduce((previous, current) => { + return previous.push(current.name); + }, []) + ); + } else { + this.serverless.addServiceOutputSection( + 'Deployed Functions', + 'No functions currently deployed' + ); + } + }, + + printInfo(data) { + if (this.provider.log) { + this.printInfoV3(data); + } else { + this.printInfoV2(data); + } return BbPromise.resolve(); }, diff --git a/invoke/lib/invokeFunction.js b/invoke/lib/invokeFunction.js index 5dccea8..fd5c8fb 100644 --- a/invoke/lib/invokeFunction.js +++ b/invoke/lib/invokeFunction.js @@ -47,7 +47,11 @@ module.exports = { const log = `${chalk.grey(res.executionId)} ${res.result}`; - this.serverless.cli.log(log); + if (this.provider.writeText) { + this.provider.writeText(log); + } else { + this.serverless.cli.log(log); + } return BbPromise.resolve(); }, diff --git a/logs/lib/retrieveLogs.js b/logs/lib/retrieveLogs.js index 32f0e2a..479197a 100644 --- a/logs/lib/retrieveLogs.js +++ b/logs/lib/retrieveLogs.js @@ -48,7 +48,11 @@ module.exports = { output = `Displaying the ${logs.entries.length} most recent log(s):\n\n${output}`; // prettify output output = output.slice(0, output.length - 1); // remove "\n---\n\n" for the last log entry - this.serverless.cli.log(output); + if (this.provider.writeText) { + this.provider.writeText(output); + } else { + this.serverless.cli.log(output); + } return BbPromise.resolve(); }, diff --git a/package/lib/compileFunctions.js b/package/lib/compileFunctions.js index caec35b..c5445f5 100644 --- a/package/lib/compileFunctions.js +++ b/package/lib/compileFunctions.js @@ -22,7 +22,11 @@ module.exports = { let vpcEgress = funcObject.vpcEgress || this.serverless.service.provider.vpcEgress; - this.serverless.cli.log(`Compiling function "${functionName}"...`); + if (this.log) { + this.log.notice(`Compiling function "${functionName}"...`); + } else { + this.serverless.cli.log(`Compiling function "${functionName}"...`); + } validateHandlerProperty(funcObject, functionName); validateEventsProperty(funcObject, functionName); diff --git a/remove/googleRemove.js b/remove/googleRemove.js index fb44a39..2f0fc42 100644 --- a/remove/googleRemove.js +++ b/remove/googleRemove.js @@ -15,6 +15,15 @@ class GoogleRemove { this.options = options; this.provider = this.serverless.getProvider('google'); + let removeProgress; + + if (this.provider.progress) { + removeProgress = this.provider.progress.create({ + message: 'Removing deployment', + name: 'remove', + }); + } + Object.assign( this, validate, @@ -33,7 +42,10 @@ class GoogleRemove { .then(this.setDeploymentBucketName), 'remove:remove': () => - BbPromise.bind(this).then(this.emptyDeploymentBucket).then(this.removeDeployment), + BbPromise.bind(this) + .then(this.emptyDeploymentBucket) + .then(this.removeDeployment) + .finally(() => removeProgress && removeProgress.remove()), }; } } diff --git a/remove/lib/emptyDeploymentBucket.js b/remove/lib/emptyDeploymentBucket.js index 3f187a9..c80a9db 100644 --- a/remove/lib/emptyDeploymentBucket.js +++ b/remove/lib/emptyDeploymentBucket.js @@ -22,7 +22,11 @@ module.exports = { removeObjects(objectsToRemove) { if (!objectsToRemove.length) return BbPromise.resolve(); - this.serverless.cli.log('Removing artifacts in deployment bucket...'); + if (this.log) { + this.provider.progress.get('remove').update('Removing artifacts from deployment bucket'); + } else { + this.serverless.cli.log('Removing artifacts in deployment bucket...'); + } const removePromises = objectsToRemove.map((object) => { const params = { diff --git a/remove/lib/removeDeployment.js b/remove/lib/removeDeployment.js index eb23413..71b17db 100644 --- a/remove/lib/removeDeployment.js +++ b/remove/lib/removeDeployment.js @@ -2,7 +2,11 @@ module.exports = { removeDeployment() { - this.serverless.cli.log('Removing deployment...'); + if (this.log) { + this.provider.progress.get('remove').update('Removing deployment from Deployment Manager'); + } else { + this.serverless.cli.log('Removing deployment...'); + } const deploymentName = `sls-${this.serverless.service.service}-${this.options.stage}`; diff --git a/shared/monitorDeployment.js b/shared/monitorDeployment.js index 89af79b..c89e825 100644 --- a/shared/monitorDeployment.js +++ b/shared/monitorDeployment.js @@ -11,7 +11,9 @@ module.exports = { let deploymentStatus = null; - this.serverless.cli.log(`Checking deployment ${action} progress...`); + if (!this.provider.log) { + this.serverless.cli.log(`Checking deployment ${action} progress...`); + } return new BbPromise((resolve, reject) => { async.whilst( @@ -53,9 +55,12 @@ module.exports = { }, () => { - // empty console.log for a prettier output - this.serverless.cli.consoleLog(''); - this.serverless.cli.log('Done...'); + if (!this.provider.log) { + // empty console.log for a prettier output + this.serverless.cli.consoleLog(''); + this.serverless.cli.log('Done...'); + } + resolve(deploymentStatus); } );