Skip to content

Commit

Permalink
feat: remove modeling stack prompt from ask new, add --ac flag to…
Browse files Browse the repository at this point in the history
… view ac templates
  • Loading branch information
tydonelson committed Apr 13, 2023
1 parent 4aac826 commit cb24ad8
Show file tree
Hide file tree
Showing 9 changed files with 15 additions and 121 deletions.
12 changes: 3 additions & 9 deletions lib/commands/new/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,8 @@ export type NewSkillDeployerTypeInfo = {
NAME: string;
DESCRIPTION: string;
};
export type NewSkillModelingStackTypes = "Interaction Model" | "Alexa Conversations";
export const MODELING_STACK_IM: NewSkillModelingStackTypes = "Interaction Model";
export const MODELING_STACK_IM_DESCRIPTION: string =
"The Interaction Model stack enables you to define the user interactions with a combination of utterances, intents, and slots.";
export const MODELING_STACK_AC: NewSkillModelingStackTypes = "Alexa Conversations";
export const MODELING_STACK_AC_DESCRIPTION: string =
"Alexa Conversations (AC) uses deep learning to manage the dialog flow. User utterances, APL, and APLA documents train the skill model to create natural, human-like Alexa voice experiences.";
export const MODELING_STACK_IM = "im";
export const MODELING_STACK_AC = "ac";
export type NewSkillTemplateInfo = {
templateUrl?: string;
templateName?: string;
Expand All @@ -42,7 +37,6 @@ export type NewSkillUserInput = {
templateInfo?: NewSkillTemplateInfo;
skillName?: string;
projectFolderName?: string;
modelingStack?: NewSkillModelingStackTypes;
};

export default class NewCommand extends AbstractCommand {
Expand All @@ -59,7 +53,7 @@ export default class NewCommand extends AbstractCommand {
}

optionalOptions() {
return ["templateUrl", "templateBranch", "profile", "debug"];
return ["templateUrl", "templateBranch", "profile", "debug", "ac"];
}

async handle(cmd: Record<string, any>): Promise<void> {
Expand Down
6 changes: 1 addition & 5 deletions lib/commands/new/template-helper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import httpClient from "../../clients/http-client";
import R from "ramda";
import {TEMPLATES, HTTP_REQUEST, DEPLOYER_TYPE} from "../../utils/constants";
import {SampleTemplate, SampleTemplateFilterValues} from "../../model/sample-template";
import {CODE_LANGUAGE_JAVA, CODE_LANGUAGE_NODEJS, CODE_LANGUAGE_PYTHON, MODELING_STACK_AC, MODELING_STACK_IM} from ".";
import {CODE_LANGUAGE_JAVA, CODE_LANGUAGE_NODEJS, CODE_LANGUAGE_PYTHON} from ".";

export function getSampleTemplatesFromS3(doDebug: boolean): Promise<SampleTemplate[]> {
return new Promise<SampleTemplate[]>((resolve, reject) => {
Expand All @@ -24,10 +24,6 @@ export function getSampleTemplatesFromS3(doDebug: boolean): Promise<SampleTempla

export function convertUserInputToFilterValue(inputValue: string): SampleTemplateFilterValues {
switch (inputValue.toLowerCase()) {
case MODELING_STACK_IM.toLowerCase():
return "im";
case MODELING_STACK_AC.toLowerCase():
return "ac";
case CODE_LANGUAGE_NODEJS.toLowerCase():
return "node";
case CODE_LANGUAGE_PYTHON.toLowerCase():
Expand Down
35 changes: 0 additions & 35 deletions lib/commands/new/ui.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,7 @@ import {callbackError, uiCallback} from "../../model/callback";
import {isNonBlankString} from "../../utils/string-utils";
import {
NewSkillDeployerTypeInfo,
MODELING_STACK_IM,
MODELING_STACK_AC,
NewSkillCodeLanguage,
MODELING_STACK_IM_DESCRIPTION,
MODELING_STACK_AC_DESCRIPTION,
} from ".";
import {SampleTemplate} from "../../model/sample-template";

Expand Down Expand Up @@ -204,34 +200,3 @@ export function getDeploymentType(deployType: NewSkillDeployerTypeInfo[], callba
callback(error);
});
}

/**
* Prompts the user to select the modeling stack type they want the samples to use
* i.e. Interaction Model vs Alexa Conversations
*
* @param {uiCallback} callback function that will be called with the resulting value or error
*/
export function getModelingStackType(callback: uiCallback): void {
const modelingStackChoices = [
`${MODELING_STACK_IM}\n ${gray(MODELING_STACK_IM_DESCRIPTION)}`,
`${MODELING_STACK_AC}\n ${gray(MODELING_STACK_AC_DESCRIPTION)}`,
];
inquirer
.prompt([
{
message: "Choose a modeling stack for your skill: ",
type: "list",
name: "modelingStack",
choices: modelingStackChoices,
default: MODELING_STACK_IM,
pageSize: 5,
filter: (input) => input.replace(/\n.*/g, ""),
},
])
.then((answer) => {
callback(null, answer.modelingStack);
})
.catch((error) => {
callback(error);
});
}
17 changes: 2 additions & 15 deletions lib/commands/new/wizard-helper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ import {
NewSkillRegion,
NewSkillTemplateInfo,
NewSkillUserInput,
NewSkillModelingStackTypes,
MODELING_STACK_IM,
MODELING_STACK_AC,
CODE_LANGUAGE_NODEJS,
CODE_LANGUAGE_PYTHON,
CODE_LANGUAGE_JAVA,
Expand Down Expand Up @@ -48,8 +48,7 @@ export async function collectUserCreationProjectInfo(
const sampleTemplateFilter: SampleTemplatesFilter = new SampleTemplatesFilter(sampleTemplates);

// MODELING STACK TYPE
await promptForModelingStackType().then((modelingStack) => (userInput.modelingStack = modelingStack));
sampleTemplateFilter.filter("stack", convertUserInputToFilterValue(userInput.modelingStack || MODELING_STACK_IM));
sampleTemplateFilter.filter("stack", cmd.ac ? MODELING_STACK_AC : MODELING_STACK_IM);

// CODE LANGUAGE
// ignore when template url supplied
Expand Down Expand Up @@ -144,18 +143,6 @@ function promptForDeployerType(samples: SampleTemplate[]): Promise<NewSkillDeplo
});
}

/**
* A Promise that fetches and returns the NewSkillModelingStackTypes the user wants the samples to use.
* i.e. interaction-model vs alexa-conversations
*
* @returns {Promise<NewSkillModelingStackTypes>} a Promise that will provide a Modeling Stack
*/
function promptForModelingStackType(): Promise<NewSkillModelingStackTypes> {
return new Promise((resolve, reject) => {
ui.getModelingStackType((error, modelingStack) => (error ? reject(error) : resolve(modelingStack)));
});
}

/**
* A Promise that fetches and returns the default AWS Region to use for deploying the Alexa hosted skill
*
Expand Down
5 changes: 5 additions & 0 deletions lib/commands/option-model.json
Original file line number Diff line number Diff line change
Expand Up @@ -234,5 +234,10 @@
"name": "watch",
"description": "Uses nodemon to monitor changes and automatically restart the run session.",
"stringInput": "NONE"
},
"ac": {
"name": "ac",
"description": "Displays Alexa skill templates that use the Alexa Conversations modeling stack.",
"stringInput": "NONE"
}
}
2 changes: 1 addition & 1 deletion test/unit/commands/new/index-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ describe("Commands new test - command class test", () => {
expect(instance.name()).equal("new");
expect(instance.description()).equal("create a new skill project from Alexa skill templates");
expect(instance.requiredOptions()).deep.equal([]);
expect(instance.optionalOptions()).deep.equal(["templateUrl", "templateBranch", "profile", "debug"]);
expect(instance.optionalOptions()).deep.equal(["templateUrl", "templateBranch", "profile", "debug", "ac"]);
});

describe("validate command handle", () => {
Expand Down
10 changes: 3 additions & 7 deletions test/unit/commands/new/template-helper-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@ import {
CODE_LANGUAGE_JAVA,
CODE_LANGUAGE_NODEJS,
CODE_LANGUAGE_PYTHON,
MODELING_STACK_AC,
MODELING_STACK_IM,
} from "../../../../lib/commands/new";
import {getSampleTemplatesFromS3, convertUserInputToFilterValue} from "../../../../lib/commands/new/template-helper";
import {SampleTemplate} from "../../../../lib/model/sample-template";
Expand Down Expand Up @@ -123,8 +121,6 @@ describe("Commands new test - template helper test", () => {

describe("convertUserInputToFilterValue", () => {
it("should convert values to correct mapping", () => {
expect(convertUserInputToFilterValue(MODELING_STACK_IM)).to.equal("im");
expect(convertUserInputToFilterValue(MODELING_STACK_AC)).to.equal("ac");
expect(convertUserInputToFilterValue(CODE_LANGUAGE_NODEJS)).to.equal("node");
expect(convertUserInputToFilterValue(CODE_LANGUAGE_PYTHON)).to.equal("python");
expect(convertUserInputToFilterValue(CODE_LANGUAGE_JAVA)).to.equal("java");
Expand All @@ -135,9 +131,9 @@ describe("Commands new test - template helper test", () => {
});

it("should be case insensitive", () => {
expect(convertUserInputToFilterValue(MODELING_STACK_IM)).to.equal("im");
expect(convertUserInputToFilterValue(MODELING_STACK_IM.toLowerCase())).to.equal("im");
expect(convertUserInputToFilterValue(MODELING_STACK_IM.toUpperCase())).to.equal("im");
expect(convertUserInputToFilterValue(CODE_LANGUAGE_NODEJS)).to.equal("node");
expect(convertUserInputToFilterValue(CODE_LANGUAGE_NODEJS.toLowerCase())).to.equal("node");
expect(convertUserInputToFilterValue(CODE_LANGUAGE_NODEJS.toUpperCase())).to.equal("node");
});

it("should fail fast and throw and error if not identified", (done) => {
Expand Down
45 changes: 0 additions & 45 deletions test/unit/commands/new/ui-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import {
getTargetTemplateName,
confirmUsingUnofficialTemplate,
getDeploymentType,
getModelingStackType,
} from "../../../../lib/commands/new/ui";
import {SampleTemplate} from "../../../../lib/model/sample-template";
import { CODE_LANGUAGE_JAVA, CODE_LANGUAGE_NODEJS, CODE_LANGUAGE_PYTHON } from "../../../../lib/commands/new";
Expand Down Expand Up @@ -430,48 +429,4 @@ describe("Commands new - UI test", () => {
});
});
});

describe("| getModelingStackType", () => {
let inquirerPrompt: SinonStub;

beforeEach(() => {
inquirerPrompt = sinon.stub(inquirer, "prompt");
});

afterEach(() => {
sinon.restore();
});

it("| getModelingStackType selected by user is retrieved correctly", (done) => {
// setup
inquirerPrompt.resolves({modelingStack: "Alexa Conversations"});
// call
getModelingStackType((err, response) => {
// verify
validateInquirerConfig(inquirerPrompt.args[0][0][0], {
message: "Choose a modeling stack for your skill: ",
type: "list",
});
expect(err).equal(null);
expect(response).equal("Alexa Conversations");
done();
});
});

it("| getModelingStackType inquirer throws exception", (done) => {
// setup
inquirerPrompt.rejects(new Error(TEST_ERROR));
// call
getModelingStackType((err, response) => {
// verify
validateInquirerConfig(inquirerPrompt.args[0][0][0], {
message: "Choose a modeling stack for your skill: ",
type: "list",
});
expect(err?.message).equal(TEST_ERROR);
expect(response).equal(undefined);
done();
});
});
});
});
4 changes: 0 additions & 4 deletions test/unit/commands/new/wizard-helper-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import urlUtils from "../../../../lib/utils/url-utils";
import * as wizardHelper from "../../../../lib/commands/new/wizard-helper";
import Messenger from "../../../../lib/view/messenger";
import {TEST_SAMPLE_1_IM_HOSTED_NODE, TEST_SAMPLE_2_AC_CFN_PYTHON} from "./template-helper-test";
import { MODELING_STACK_IM } from "../../../../lib/commands/new";

describe("Commands new test - wizard helper test", () => {
const TEST_ERROR = "TEST_ERROR";
Expand Down Expand Up @@ -38,7 +37,6 @@ describe("Commands new test - wizard helper test", () => {
let getSkillDefaultRegionStub: SinonStub;
let getSkillLocaleStub: SinonStub;
let getInstanceStub: SinonStub;
let getModelingStackTypeStub: SinonStub;
let getSampleTemplatesFromS3Stub: SinonStub;

beforeEach(() => {
Expand All @@ -63,8 +61,6 @@ describe("Commands new test - wizard helper test", () => {
getSkillLocaleStub = sinon.stub(ui, "getSkillLocale");
getSkillLocaleStub.yields(null, "en-US");
getSkillLocaleStub.yields(null, "us-east-1");
getModelingStackTypeStub = sinon.stub(ui, "getModelingStackType");
getModelingStackTypeStub.callsArgWith(0, null, MODELING_STACK_IM);
getSampleTemplatesFromS3Stub = sinon.stub(templateHelper, "getSampleTemplatesFromS3");
getSampleTemplatesFromS3Stub.resolves(TEST_TEMPLATE_SAMPLES);
});
Expand Down

0 comments on commit cb24ad8

Please sign in to comment.