# A generator for Ionic Apps, Components, Directives, Modules, Pages, Pipes and Services

**URL:** <https://forum.ionicframework.com/t/a-generator-for-ionic-apps-components-directives-modules-pages-pipes-and-services/117179>\
**Category:** ionic-v3\
**Created:** [January 4, 2018, 5:51am UTC](https://forum.ionicframework.com/t/a-generator-for-ionic-apps-components-directives-modules-pages-pipes-and-services/117179 "2018-01-04T05:51:19Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![robinyo](https://sea1.discourse-cdn.com/ionicframework/user_avatar/forum.ionicframework.com/robinyo/32/115964_2.png) [@robinyo](https://forum.ionicframework.com/u/robinyo)\
**Post date:** [January 4, 2018, 5:51am UTC](https://forum.ionicframework.com/t/a-generator-for-ionic-apps-components-directives-modules-pages-pipes-and-services/117179/1 "2018-01-04T05:51:19Z")

</div>

# A generator for Ionic Apps that uses Angular Schematics

## Goals

- A standardised Ionic project structure aligned with the Angular style guide’s:
  - [X] [Overall structural guidelines](https://angular.io/guide/styleguide#overall-structural-guidelines)
  - [X] [Folders-by-feature structure](https://angular.io/guide/styleguide#folders-by-feature-structure)
  - [X] [App Module](https://angular.io/guide/styleguide#app-root-module)
  - [X] [Core Feature Module](https://angular.io/guide/styleguide#core-feature-module)
  - [X] [Shared Feature Module](https://angular.io/guide/styleguide#shared-feature-module)

```auto
    ├── <PROJECT_ROOT>
        └── /src
            └── /app - App Module
                ├── app.component.ts
                ├── app.html
                ├── app.module.ts
                ├── app.scss
                ├── main.ts
                └── /core - Core Feature Module (e.g., Singleton Services/Providers)
                    ├── core.module.ts
                    ├── module-import-guard.ts  
                    └── /logger
                        ├── console-logger.service.ts
                        ├── logger.service.ts                               
                └── /pages - Page (Component) Modules
                    └── /home
                        ├── home.page.html
                        ├── home.page.module.ts 
                        ├── home.page.scss   
                        ├── home.page.spec.ts
                        ├── home.page.ts                                                                                                               
                └── /shared - Shared Feature Module (shared Components, Directives and Pipes)
                    ├── shared.module.ts                
            └── /assets
            └── /environments - Environment specific configuration   
                ├── environment.dev.ts
                ├── environment.ts                        
            └── /theme
                ├── facebook-messenger-theme.scss            
                ├── gradient-mixins.scss
                ├── gradient.scss
                ├── green-and-blue-theme.scss                    
                ├── variables.scss
            ├── index.html
            ├── manifest.json
            ├── service-worker.js
        └── /config - Webpack Configuration
            ├── webpack.config.json
        └── /e2e - E2E Test Configuration
            ├── app.e2e-spec.ts
            ├── app.po.ts
            ├── tsconfig.e2e.json
        └── /resources - Default Resources (e.g., Icon and Splash)
        └── /www - Ionics dist directory
            └── /assets
            └── /build   
            ├── index.html
            ├── manifest.json
            ├── service-worker.js
        ├── .editorconfig
        ├── .gitignore
        ├── config.xml
        ├── ionic.config.json
        ├── karma.conf.json           
        ├── package.json
        ├── protractor.conf.json
        ├── README.md     
        ├── tsconfig.json
        ├── tsconfig.ng-cli.json        
        ├── tslint.json             

```

- [Code scaffolding](#generating-pages-and-services)
  - [X] Application
  - [X] Component
  - [X] Directive
  - [X] Enum
  - [X] Interface
  - [X] Module
  - [X] Page
  - [X] Pipe
  - [X] Service

- [X] [Aliases](https://robferguson.org/blog/2017/11/22/working-with-typescript-webpack-and-ionic-3/)
- [X] [Environment specific configuration](https://github.com/Robinyo/big-top#aliases-and-environment-specific-variables)
- [X] [Dynamic Themes](https://robferguson.org/blog/2017/11/12/theming-your-ionic-3-app/)
- [X] [Logging](https://robferguson.org/blog/2017/09/09/a-simple-logging-service-for-angular-4/)
- [X] [Unit and E2E Testing](https://robferguson.org/blog/2017/11/28/testing-your-ionic-3-app/)
- [X] Baked in best practices that have been discovered by the community over time

**Note:** See this [post](http://blog.ionicframework.com/ionic-and-lazy-loading-pt-2/) re Shared Feature Module (Shared Common Modules) v Encapsulated Modules.

### Generating a new project

You can use the `ng new` command to generate a new Ionic project:

```bash
ng new --collection=@ionic-angular/schematics my-app
cd my-app
ionic serve

```

If you have set `@ionic-angular/schematics` as the default collection:

```bash
ng new my-app
cd my-app 
ionic serve

```

You can also use the Schematics CLI to generate a new Ionic project:

```bash
schematics @ionic-angular/schematics:application --directory my-app --name MyApp
cd my-app
npm install
ionic serve

```

### Generating Components, Directives, Modules, Pages, Pipes and Services

You can use the `ng generate` (or just `ng g`) command to generate Ionic pages:

```bash
ng generate page --collection=@ionic-angular/schematics pages/my-page --skip-import
ng g page --collection=@ionic-angular/schematics pages/my-page --skip-import # using the alias
ng g page pages/my-page --skip-import # if @ionic-angular/schematics is the default collection

```

**Note:** Pages are lazy loaded by default.

You can also use the Schematics CLI to generate Ionic pages:

```bash
schematics @ionic-angular/schematics:page --name my-page

```

You can find all possible blueprints in the table below:

| Scaffold | Usage |
| --- | --- |
| Component | `ng g component my-new-component --spec` |
| Directive | `ng g directive my-new-directive --spec` |
| Enum | `ng g enum my-new-enum` |
| Interface | `ng g interface my-new-interface` |
| Module | `ng g module my-new-module --spec` |
| Page | `ng g page pages/my-new-page --skip-import` |
| Pipe | `ng g pipe my-new-pipe --spec` |
| Service | `ng g service my-new-service --spec` |

See:

- [https://github.com/Robinyo/ionic-angular-schematics](https://github.com/Robinyo/ionic-angular-schematics)
- [https://www.npmjs.com/package/@ionic-angular/schematics](https://www.npmjs.com/package/@ionic-angular/schematics)

---

<div class="post-metadata">

**Author:** ![JAR19](https://sea1.discourse-cdn.com/ionicframework/user_avatar/forum.ionicframework.com/jar19/32/113216_2.png) [@JAR19](https://forum.ionicframework.com/u/JAR19)\
**Post date:** [January 12, 2018, 7:38am UTC](https://forum.ionicframework.com/t/a-generator-for-ionic-apps-components-directives-modules-pages-pipes-and-services/117179/2 "2018-01-12T07:38:35Z")

</div>

> [@robinyo](#):
>
> home.page.spec.ts

Perhaps you could explain the advantages of using the Angular Schematics over the Ionic layout.

What does for example “home.page.spec.ts” do?

---

<div class="post-metadata">

**Author:** ![robinyo](https://sea1.discourse-cdn.com/ionicframework/user_avatar/forum.ionicframework.com/robinyo/32/115964_2.png) [@robinyo](https://forum.ionicframework.com/u/robinyo)\
**Post date:** [January 12, 2018, 6:27pm UTC](https://forum.ionicframework.com/t/a-generator-for-ionic-apps-components-directives-modules-pages-pipes-and-services/117179/3 "2018-01-12T18:27:33Z")

</div>

> [@JAR19](#):
>
> What does for example “home.page.spec.ts” do?

Tests written in Jasmine are called **specs**. The filename extension must be `.spec.ts`, the convention adhered to by karma.conf.js and other testing tools.

See: [https://robferguson.org/blog/2017/11/28/testing-your-ionic-3-app/](https://robferguson.org/blog/2017/11/28/testing-your-ionic-3-app/)

> [@JAR19](#):
>
> Perhaps you could explain the advantages of using the Angular Schematics over the Ionic layout.

[@ionic-angular/schematics](https://github.com/Robinyo/ionic-angular-schematics) provides a standardised project structure aligned with Angular’s style guide. The Angular style guide presents preferred conventions and, as importantly, explains why:

See:

- [Angular](https://angular.io/guide/styleguide#style-guide)

---

<div class="post-metadata">

**Author:** ![JAR19](https://sea1.discourse-cdn.com/ionicframework/user_avatar/forum.ionicframework.com/jar19/32/113216_2.png) [@JAR19](https://forum.ionicframework.com/u/JAR19)\
**Post date:** [January 12, 2018, 8:31pm UTC](https://forum.ionicframework.com/t/a-generator-for-ionic-apps-components-directives-modules-pages-pipes-and-services/117179/4 "2018-01-12T20:31:13Z")

</div>

> [@robinyo](#):
>
> provides a standardised project structure aligned with Angular’s style guide.

Thanks @robinyo it will be interesting to see what Ionic approach will be with Ionic 4 - will it include a testing system?

---

<div class="post-metadata">

**Author:** ![mhartington](https://sea1.discourse-cdn.com/ionicframework/user_avatar/forum.ionicframework.com/mhartington/32/137757_2.png) [@mhartington](https://forum.ionicframework.com/u/mhartington)\
**Post date:** [July 19, 2021, 9:56pm UTC](https://forum.ionicframework.com/t/a-generator-for-ionic-apps-components-directives-modules-pages-pipes-and-services/117179/5 "2021-07-19T21:56:30Z")

</div>

Closed on July 19, 2021, 9:56pm UTC


