Skip to content
2 changes: 1 addition & 1 deletion packages/cli-plugin-ionic-angular/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@
"@angular/compiler": "^4.2.4",
"@angular/compiler-cli": "^4.2.4",
"@angular/core": "^4.2.4",
"@ionic/app-scripts": "^2.0.0",
"@ionic/app-scripts": "^2.1.0",
"@ionic/cli-scripts": "0.2.1",
"@types/chalk": "^0.4.31",
"@types/clean-css": "^3.4.30",
Expand Down
13 changes: 7 additions & 6 deletions packages/cli-plugin-ionic-angular/src/generate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import {
import * as AppScriptsType from '@ionic/app-scripts';

import { load } from './lib/modules';
import { prompt, tabsPrompt } from './utils/generate';
import { getModules, prompt, tabsPrompt } from './utils/generate';

export async function generate(args: CommandHookArgs): Promise<string[]> {
if (!args.env.project.directory) {
Expand All @@ -37,21 +37,22 @@ export async function generate(args: CommandHookArgs): Promise<string[]> {
const context = AppScripts.generateContext();

const [ type, name ] = args.inputs;
const commandOptions = args.options;

switch (type) {
case 'page':
await AppScripts.processPageRequest(context, name);
await AppScripts.processPageRequest(context, name, commandOptions);
break;
case 'component':
const componentData = await promptQuestions(context);
const componentData = await getModules(context, 'component');
await AppScripts.processComponentRequest(context, name, componentData);
break;
case 'directive':
const directiveData = await promptQuestions(context);
const directiveData = await getModules(context, 'directive');
await AppScripts.processDirectiveRequest(context, name, directiveData);
break;
case 'pipe':
const pipeData = await promptQuestions(context);
const pipeData = await getModules(context, 'pipe');
await AppScripts.processPipeRequest(context, name, pipeData);
break;
case 'provider':
Expand All @@ -60,7 +61,7 @@ export async function generate(args: CommandHookArgs): Promise<string[]> {
break;
case 'tabs':
const tabsData = await tabsPrompt(args.env);
await AppScripts.processTabsRequest(context, name, tabsData);
await AppScripts.processTabsRequest(context, name, tabsData, commandOptions);
break;
}

Expand Down
11 changes: 11 additions & 0 deletions packages/cli-plugin-ionic-angular/src/utils/generate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,17 @@ export async function prompt(context: AppScriptsType.BuildContext) {
return context.appNgModulePath;
}

export async function getModules(context: AppScriptsType.BuildContext, kind: string) {
switch (kind) {
case 'component':
return context.componentsNgModulePath ? context.componentsNgModulePath : context.appNgModulePath;
case 'pipe':
return context.pipesNgModulePath ? context.pipesNgModulePath : context.appNgModulePath;
case 'directive':
return context.directivesNgModulePath ? context.directivesNgModulePath : context.appNgModulePath;
}
}

export async function tabsPrompt(env: IonicEnvironment) {
const tabNames = [];

Expand Down
26 changes: 24 additions & 2 deletions packages/ionic/src/commands/generate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,15 @@ Automatically create components for your Ionic app.

The given ${chalk.green('name')} is normalized into an appropriate naming convention. For example, ${chalk.green('ionic generate page neat')} creates a page by the name of ${chalk.green('NeatPage')} in ${chalk.green('src/pages/neat/')}.
`,
exampleCommands: ['', ...TYPE_CHOICES, 'component foo', 'page Login', 'pipe MyFilterPipe'],
exampleCommands: [
'',
...TYPE_CHOICES,
'component foo',
'page Login',
'page Detail --no-module',
'page About --constants',
'pipe MyFilterPipe'
],
inputs: [
{
name: 'type',
Expand All @@ -35,6 +43,20 @@ The given ${chalk.green('name')} is normalized into an appropriate naming conven
description: 'The name of the component being generated',
}
],
options: [
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can provide examples of these options using the exampleCommands list above.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it is done

{
name: 'module',
description: 'Skip generating a NgModule',
type: Boolean,
default: true
},
{
name: 'constants',
description: 'Generate a page constant files for lazy loaded pages',
type: Boolean,
default: false
}
]
})
export class GenerateCommand extends Command implements CommandPreRun {
async preRun(inputs: CommandLineInputs, options: CommandLineOptions): Promise<void | number> {
Expand Down Expand Up @@ -89,7 +111,7 @@ export class GenerateCommand extends Command implements CommandPreRun {
}

async run(inputs: CommandLineInputs, options: CommandLineOptions): Promise<void> {
const [ type, name ] = inputs;
const [type, name] = inputs;

await this.env.hooks.fire('command:generate', { cmd: this, env: this.env, inputs, options }); // TODO: print generated templates

Expand Down