-
Notifications
You must be signed in to change notification settings - Fork 5.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(CLI Onboarding): Add deploy step [WIP]
- Loading branch information
Showing
7 changed files
with
129 additions
and
0 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
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,82 @@ | ||
'use strict'; | ||
|
||
const Serverless = require('../../Serverless'); | ||
const chalk = require('chalk'); | ||
const { confirm } = require('./utils'); | ||
const _ = require('lodash'); | ||
const AWS = require('aws-sdk'); | ||
|
||
const printMessage = (serviceName, hasBeenDeployed) => { | ||
if (hasBeenDeployed) { | ||
process.stdout.write( | ||
`\n${chalk.green('Your new project is live and available in ')}${chalk.white.bold( | ||
serviceName | ||
)}\n` | ||
); | ||
} else { | ||
process.stdout.write( | ||
`\n${chalk.green('Your new project is available in ')}${chalk.white.bold(serviceName)}\n` | ||
); | ||
} | ||
|
||
process.stdout.write('\nInside that directory, you can run serveral commands:\n'); | ||
process.stdout.write(`\n ${chalk.blue('serverless info')}\n`); | ||
process.stdout.write(' View deployment and configuration details.\n'); | ||
process.stdout.write(`\n ${chalk.blue('serverless deploy')}\n`); | ||
if (hasBeenDeployed) { | ||
process.stdout.write(' Deploy your service again.\n'); | ||
} else { | ||
process.stdout.write(' Deploy your service.\n'); | ||
} | ||
process.stdout.write(`\n ${chalk.blue('serverless dashboard')}\n`); | ||
process.stdout.write(' Open the dashboard to view metrics, logs and alerts.\n\n'); | ||
}; | ||
|
||
module.exports = { | ||
isApplicable({ configuration, serviceDir, history }) { | ||
if (!serviceDir) { | ||
return false; | ||
} | ||
|
||
if (!history.has('service')) { | ||
return false; | ||
} | ||
|
||
if ( | ||
_.get(configuration, 'provider') !== 'aws' && | ||
_.get(configuration, 'provider.name') !== 'aws' | ||
) { | ||
return false; | ||
} | ||
|
||
if (new AWS.S3().config.credentials) return false; | ||
|
||
// TODO: CHECK IF PROVIDER HAS BEEN SETUP DURING AWS CREDETIALS STEP | ||
|
||
return true; | ||
}, | ||
async run({ configuration, configurationFilename, serviceDir }) { | ||
const serviceName = configuration.service; | ||
if (!(await confirm('Do you want to deploy your project?', { name: 'shouldDeploy' }))) { | ||
printMessage(serviceName, false); | ||
return; | ||
} | ||
|
||
// TODO: TESTS | ||
const serverless = new Serverless({ | ||
configuration, | ||
serviceDir, | ||
configurationFilename, | ||
isConfigurationResolved: true, | ||
hasResolvedCommandsExternally: true, | ||
isTelemetryReportedExternally: true, | ||
isInvokedByInteractive: true, | ||
commands: ['deploy'], | ||
options: {}, // Empty options as the original ones are for interactive command | ||
}); | ||
await serverless.init(); | ||
|
||
await serverless.run(); | ||
printMessage(serviceName, true); | ||
}, | ||
}; |
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,29 @@ | ||
'use strict'; | ||
|
||
const ora = require('ora'); | ||
|
||
class InteractiveDeployProgress { | ||
constructor(serverless) { | ||
this.serverless = serverless; | ||
this.deployProgress = ora('Deploying your project...'); | ||
this.packageProgress = ora('Packaging your project...'); | ||
|
||
this.hooks = { | ||
'before:deploy:deploy': async () => { | ||
this.deployProgress.start(); | ||
}, | ||
'deploy:finalize': async () => { | ||
this.deployProgress.succeed('Deployment succesful!'); | ||
}, | ||
|
||
'package:initialize': async () => { | ||
this.packageProgress.start(); | ||
}, | ||
'package:finalize': async () => { | ||
this.packageProgress.succeed('Packaging succesful!'); | ||
}, | ||
}; | ||
} | ||
} | ||
|
||
module.exports = InteractiveDeployProgress; |
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