Skip to content

Commit

Permalink
feat: adding amplify cli predictions category (#1936)
Browse files Browse the repository at this point in the history
  • Loading branch information
kaustavghosh06 committed Jul 31, 2019
1 parent 07c6243 commit b7b7c2c
Show file tree
Hide file tree
Showing 85 changed files with 8,228 additions and 463 deletions.
1 change: 1 addition & 0 deletions Readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ The Amplify CLI supports the commands shown in the following table.
- [hosting (Amazon S3 and Amazon CloudFront distribution)](packages/amplify-category-hosting/Readme.md)
- [notifications (Amazon Pinpoint)](packages/amplify-category-notifications/Readme.md)
- [interactions (Amazon Lex)](packages/amplify-category-interactions/Readme.md)
- [predictions (Amazon Rekognition, Amazon Textract, Amazon Translate, Amazon Polly, Amazon Transcribe, Amazon Comprehend, and Amazon SageMaker)](packages/amplify-category-predictions/Readme.md)

## Tutorials

Expand Down
4 changes: 2 additions & 2 deletions packages/amplify-category-analytics/package.json
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
{
"name": "amplify-category-analytics",
"version": "1.5.7",
"version": "1.5.8",
"description": "amplify-cli analytics plugin",
"main": "index.js",
"dependencies": {
"amplify-category-auth": "1.7.3",
"amplify-category-auth": "^1.7.4",
"eslint": "^4.19.1",
"fs-extra": "^7.0.0",
"inquirer": "6.3.1",
Expand Down
10 changes: 5 additions & 5 deletions packages/amplify-category-api/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "amplify-category-api",
"version": "1.7.11",
"version": "1.7.12",
"description": "amplify-cli api plugin",
"main": "index.js",
"author": "Amazon Web Services",
Expand All @@ -10,14 +10,14 @@
"lint-fix": "eslint . --fix"
},
"dependencies": {
"amplify-category-auth": "1.7.3",
"amplify-category-function": "1.7.3",
"amplify-category-storage": "1.8.3",
"amplify-category-auth": "^1.7.4",
"amplify-category-function": "^1.7.4",
"amplify-category-storage": "^1.8.4",
"aws-sdk": "^2.391.0",
"eslint": "^4.9.0",
"fs-extra": "^7.0.0",
"graphql": "^0.13.2",
"graphql-relational-schema-transformer": "1.0.13",
"graphql-relational-schema-transformer": "^1.0.14",
"inquirer": "6.3.1",
"merge-graphql-schemas": "^1.5.8",
"moment": "^2.22.2",
Expand Down
4 changes: 2 additions & 2 deletions packages/amplify-category-auth/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "amplify-category-auth",
"version": "1.7.3",
"version": "1.7.4",
"description": "amplify-cli authentication plugin",
"main": "index.js",
"author": "Amazon Web Services",
Expand All @@ -13,7 +13,7 @@
"test-ci": "jest --ci -i"
},
"dependencies": {
"amplify-category-function": "1.7.3",
"amplify-category-function": "^1.7.4",
"aws-sdk": "^2.475.0",
"chalk": "^2.4.1",
"chalk-pipe": "^2.0.0",
Expand Down
4 changes: 2 additions & 2 deletions packages/amplify-category-function/package.json
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
{
"name": "amplify-category-function",
"version": "1.7.3",
"version": "1.7.4",
"main": "index.js",
"description": "amplify-cli function plugin",
"dependencies": {
"amplify-category-storage": "1.8.3",
"amplify-category-storage": "^1.8.4",
"eslint": "^4.19.1",
"fs-extra": "^7.0.0",
"inquirer": "6.3.1",
Expand Down
2 changes: 1 addition & 1 deletion packages/amplify-category-hosting/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "amplify-category-hosting",
"version": "1.2.2",
"version": "1.2.3",
"description": "amplify-cli hosting plugin",
"main": "index.js",
"author": "Amazon Web Services",
Expand Down
6 changes: 3 additions & 3 deletions packages/amplify-category-interactions/package.json
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
{
"name": "amplify-category-interactions",
"version": "1.6.3",
"version": "1.6.4",
"main": "index.js",
"description": "amplify-cli interactions plugin",
"dependencies": {
"amplify-category-auth": "1.7.3",
"amplify-category-function": "1.7.3",
"amplify-category-auth": "^1.7.4",
"amplify-category-function": "^1.7.4",
"fs-extra": "^7.0.0",
"fuzzy": "^0.1.3",
"inquirer": "6.3.1",
Expand Down
4 changes: 2 additions & 2 deletions packages/amplify-category-notifications/package.json
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
{
"name": "amplify-category-notifications",
"version": "1.4.14",
"version": "1.4.15",
"description": "amplify-cli notifications plugin",
"main": "index.js",
"dependencies": {
"amplify-category-auth": "1.7.3",
"amplify-category-auth": "^1.7.4",
"eslint": "^4.19.1",
"fs-extra": "^7.0.0",
"inquirer": "6.3.1",
Expand Down
5 changes: 5 additions & 0 deletions packages/amplify-category-predictions/.eslintignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
node_modules
__tests__
__mocks__
coverage
cfn-response.js
19 changes: 19 additions & 0 deletions packages/amplify-category-predictions/.eslintrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{
"extends": "airbnb-base",
"rules": {
"no-param-reassign": "off",
"no-return-await" : "off",
"no-continue": "off",
"no-await-in-loop": "off",
"no-use-before-define": "off",
"no-console": "off",
"no-plusplus": "off",
"prefer-destructuring": "off",
"max-len": "off",
"no-loop-func": "off",
"global-require": "off",
"no-inner-declarations": "off",
"import/no-dynamic-require": "off",
"consistent-return": "off"
}
}
4 changes: 4 additions & 0 deletions packages/amplify-category-predictions/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# Change Log

All notable changes to this project will be documented in this file.
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
20 changes: 20 additions & 0 deletions packages/amplify-category-predictions/Readme.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# Amplify CLI Predictions Plugin

## Commands Summary

The current set of commands supported by the Amplify Predictions Category Plugin

| Command | Description |
| --- | --- |
| amplify predictions add | Walks you through a CLI flow to add a predictions resource to your backend |
| amplify predictions update | Walks you through steps in the CLI to update a predictions resource. |
| amplify predictions remove | Removes predictions resource from your local backend which would be removed from the cloud on the next push command |
| amplify predictions console | Opens a web console to view your predictions resources |

## Prediction Categories
| Type | Description |
| --- | --- |
| Identify | Identify images, labels, and/or entities |
| Convert | Convert text to another language, text to speech and/or speech to text |
| Interpret | Interpretation on text. (Language, Entities, Keyphrases, Sentiment, Syntax) |
| Infer | Infererence on models |
31 changes: 31 additions & 0 deletions packages/amplify-category-predictions/commands/predictions.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
const categoryName = 'predictions';

module.exports = {
name: categoryName,
alias: ['Predictions'],
run: async (context) => {
const header = `amplify ${categoryName} <subcommand>`;

const commands = [
{
name: 'add',
description: `Takes you through a CLI flow to add a ${categoryName} resource to your local backend`,
},
{
name: 'remove',
description: `Removes ${categoryName} resource from your local backend which would be removed from the cloud on the next push command`,
},
{
name: 'update',
description: `Takes you through steps in the CLI to update an ${categoryName} resource`,
},
{
name: 'console',
description: `Opens a web console to view your ${categoryName} resource`,
},
];

context.amplify.showHelp(header, commands);
context.print.info('');
},
};
36 changes: 36 additions & 0 deletions packages/amplify-category-predictions/commands/predictions/add.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import { promptCategory } from '../../provider-utils/supportedPredictions';

const subcommand = 'add';
const category = 'predictions';
let options;


module.exports = {
name: subcommand,
run: async context => promptCategory()
.then((result) => {
result = result.predictionsCategory;
options = {
providerPlugin: result.provider,
};
const providerController = require(`../../provider-utils/${result.provider}/index`);
if (!providerController) {
context.print.error('Provider not configured for this category');
return;
}
return providerController.addResource(context, category, result.fileName, options);
})
.then((resourceName) => {
const { print } = context;
print.success(`Successfully added resource ${resourceName} locally`);
print.info('');
print.success('Some next steps:');
print.info('"amplify push" builds all of your local backend resources and provisions them in the cloud');
print.info('"amplify publish" builds all of your local backend and front-end resources (if you added hosting category) and provisions them in the cloud');
print.info('');
})
.catch((err) => {
context.print.info(err.stack);
context.print.error('An error occurred when adding the predictions resource');
}),
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
const subcommand = 'console';
const indexModule = require('../../index');

module.exports = {
name: subcommand,
run: async (context) => {
await indexModule.console(context);
},
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
const path = require('path');
const fs = require('fs-extra');

const subcommand = 'remove';
const category = 'predictions';
const storageCategory = 'storage';
const parametersFileName = 'parameters.json';
const amplifyMetaFilename = 'amplify-meta.json';
const s3CloudFormationTemplateFile = 's3-cloudformation-template.json';

module.exports = {
name: subcommand,
run: async (context) => {
const { amplify, parameters } = context;
const resourceName = parameters.first;

return amplify.removeResource(context, category, resourceName)
.then(() => {
const projectDetails = context.amplify.getProjectDetails();
const projectStorage = projectDetails.amplifyMeta.storage;
if (!projectStorage) {
process.exit(0);
return;
}
const keys = Object.keys(projectStorage);
let s3ResourceName = '';
keys.forEach((resource) => {
if (projectStorage[resource].service === 'S3') {
s3ResourceName = resource;
}
});

if (s3ResourceName === '') {
process.exit(0);
return;
}

const projectBackendDirPath = context.amplify.pathManager.getBackendDirPath();
const resourceDirPath = path.join(projectBackendDirPath, storageCategory, s3ResourceName);
const parametersFilePath = path.join(resourceDirPath, parametersFileName);
const bucketParameters = context.amplify.readJsonFile(parametersFilePath);
const adminTriggerFunction = bucketParameters.adminTriggerFunction;

if (adminTriggerFunction) {
const predictionCtgWalkthroughSrc = `${__dirname}/../../provider-utils/awscloudformation/prediction-category-walkthroughs/identify-walkthrough`;
const { removeS3AdminLambdaTrigger } = require(predictionCtgWalkthroughSrc);
const storageCFNFilePath = path.join(projectBackendDirPath, storageCategory, s3ResourceName, s3CloudFormationTemplateFile);
let storageCFNFile = context.amplify.readJsonFile(storageCFNFilePath);
storageCFNFile = removeS3AdminLambdaTrigger(storageCFNFile, adminTriggerFunction);
delete bucketParameters.adminTriggerFunction;
const amplifyMetaFilePath = path.join(projectBackendDirPath, amplifyMetaFilename);
const amplifyMetaFile = context.amplify.readJsonFile(amplifyMetaFilePath);
const s3DependsOnResources = amplifyMetaFile.storage[s3ResourceName].dependsOn;
const s3Resources = [];
s3DependsOnResources.forEach((resource) => {
if (resource.resourceName !== adminTriggerFunction) {
s3Resources.push(resource);
}
});

const jsonString = JSON.stringify(bucketParameters, null, 4);
fs.writeFileSync(parametersFilePath, jsonString, 'utf8');

const storageCFNString = JSON.stringify(storageCFNFile, null, 4);
fs.writeFileSync(storageCFNFilePath, storageCFNString, 'utf8');
context.amplify.updateamplifyMetaAfterResourceUpdate(
storageCategory,
s3ResourceName,
'dependsOn',
s3Resources,
);
}
})
.catch((err) => {
context.print.info(err.stack);
context.print.error('An error occurred when removing the predictions resource');
});
},
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import { promptCategory } from '../../provider-utils/supportedPredictions';


const subcommand = 'update';

module.exports = {
name: subcommand,
alias: ['configure'],
run: async context => promptCategory()
.then((result) => {
result = result.predictionsCategory;
const providerController = require(`../../provider-utils/${result.provider}/index`);
if (!providerController) {
context.print.error('Provider not configured for this category');
return;
}
return providerController.updateResource(context, result.fileName);
})
.then((resourceName) => {
context.print.success(`Successfully updated resource ${resourceName} locally`);
})
.catch((err) => {
context.print.info(err.stack);
context.print.error('An error occurred when updating predictions resource!');
}),
};

0 comments on commit b7b7c2c

Please sign in to comment.