Skip to content

Commit

Permalink
fix(cli): fix new plugin platform codegen related issue (#2266)
Browse files Browse the repository at this point in the history
* fix(cli): fix new plugin platform codegen related issue

* minor fix

* minor fix
  • Loading branch information
UnleashedMind authored Sep 12, 2019
1 parent 89c9036 commit c557182
Show file tree
Hide file tree
Showing 7 changed files with 47 additions and 28 deletions.
1 change: 1 addition & 0 deletions packages/amplify-cli/src/domain/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ export default {
VERSION_SHORT: 'v',
YES: 'yes',
YES_SHORT: 'y',
PLUGIN_DEFAULT_COMMAND: 'PLUGIN_DEFAULT_COMMAND',
MANIFEST_FILE_NAME: 'amplify-plugin.json',
PACKAGEJSON_FILE_NAME: 'package.json',
PLUGINS_FILE_NAME: 'plugins.json',
Expand Down
2 changes: 1 addition & 1 deletion packages/amplify-cli/src/execution-manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ export async function executeCommand(context: Context) {

if (pluginCandidates.length === 1) {
await executePluginModuleCommand(context, pluginCandidates[0]);
} else {
} else if (pluginCandidates.length > 1) {
const answer = await inquirer.prompt({
type: 'list',
name: 'section',
Expand Down
52 changes: 38 additions & 14 deletions packages/amplify-cli/src/input-manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,29 +62,29 @@ export function getCommandLineInput(pluginPlatform: PluginPlatform): Input {
return result;
}

export function normailizeInput(input: Input): Input {
function normailizeInput(input: Input): Input {
// -v --version => version command
// -h --help => help command
// -y --yes => yes option
if (!input.command && input.options) {
if (input.options) {
if (input.options[Constant.VERSION] || input.options[Constant.VERSION_SHORT]) {
input.command = Constant.VERSION;
input.options[Constant.VERSION] = true;
delete input.options[Constant.VERSION_SHORT];
} else if (input.options[Constant.HELP] || input.options[Constant.HELP_SHORT]) {
input.command = Constant.HELP;
}

if (input.options[Constant.HELP] || input.options[Constant.HELP_SHORT]) {
input.options[Constant.HELP] = true;
delete input.options[Constant.HELP_SHORT];
}
}

input.command = input.command || Constant.HELP;

if (input.options && input.options[Constant.YES_SHORT]) {
input.options[Constant.YES] = true;
delete input.options[Constant.YES_SHORT];
if (input.options && input.options[Constant.YES_SHORT]) {
input.options[Constant.YES] = true;
delete input.options[Constant.YES_SHORT];
}
}

input.command = input.command || Constant.PLUGIN_DEFAULT_COMMAND;

return input;
}

Expand All @@ -99,17 +99,41 @@ export function verifyInput(pluginPlatform: PluginPlatform, input: Input): Input

if (pluginCandidates.length > 0) {
for (let i = 0; i < pluginCandidates.length; i++) {
const { commands, commandAliases } = pluginCandidates[i].manifest;
const { name, commands, commandAliases } = pluginCandidates[i].manifest;

if ((commands && commands!.includes(Constant.HELP)) ||
(commandAliases && Object.keys(commandAliases).includes(Constant.HELP))) {
result.helpCommandAvailable = true;
}
if ((commands && commands!.includes(input.command!)) ||
(commandAliases && Object.keys(commandAliases).includes(input.command!))) {

if ((commands && commands!.includes(input.command!))) {
result.verified = true;
break;
}

if (commandAliases && Object.keys(commandAliases).includes(input.command!)) {
input.command = commandAliases[input.command!];
result.verified = true;
break;
}

if (input.command! === Constant.PLUGIN_DEFAULT_COMMAND) {
if (commands && commands!.includes(name)) {
input.command = name;
result.verified = true;
break;
}
if (commands && commands!.includes(Constant.HELP)) {
input.command = Constant.HELP;
result.verified = true;
break;
}
if (commands && commands!.includes(Constant.VERSION)) {
input.command = Constant.VERSION;
result.verified = true;
break;
}
}
}
if (!result.verified) {
if (input.plugin === constants.CORE) {
Expand Down
5 changes: 3 additions & 2 deletions packages/amplify-codegen/amplify-plugin.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,12 @@
"codegen",
"configure",
"remove",
"statement",
"statements",
"types"
],
"commandAliases":{
"update": "configure"
"update": "configure",
"statement": "statements"
},
"eventHandlers": []
}
2 changes: 1 addition & 1 deletion packages/amplify-codegen/src/amplify-plugin-index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ const path = require('path');
const pluginName = 'codegen';

async function executeAmplifyCommand(context) {
let commandPath = path.normalize(path.join(__dirname, 'commands'));
let commandPath = path.normalize(path.join(__dirname, '../commands'));
commandPath = path.join(commandPath, pluginName, context.input.command);
const commandModule = require(commandPath);
await commandModule.run(context);
Expand Down
1 change: 1 addition & 0 deletions packages/amplify-util-mock/amplify-plugin.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
"commands": [
"api",
"function",
"mock",
"storage",
"help"
],
Expand Down
12 changes: 2 additions & 10 deletions packages/amplify-util-mock/src/amplify-plugin-index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,8 @@ import * as path from 'path';
const pluginName = 'mock';

export async function executeAmplifyCommand(context: any) {
let commandPath = path.normalize(path.join(__dirname, '../commands/mock'));
if (context.input.command === 'help') {
//help command could be added by the cli platform
if(context.input.argv.length > 3 && context.input.argv[3] === 'help'){
commandPath = path.join(commandPath, context.input.command);
}else{
commandPath = path.join(commandPath, pluginName);
}
}

let commandPath = path.normalize(path.join(__dirname, '../commands'));
commandPath = path.join(commandPath, pluginName, context.input.command);
const commandModule = require(commandPath);
await commandModule.run(context);
}
Expand Down

0 comments on commit c557182

Please sign in to comment.