Ionic-cli: Generate new page

Created on 6 Jan 2017  路  10Comments  路  Source: ionic-team/ionic-cli

_From @hoffmanjon on January 6, 2017 12:58_

Ionic version: (check one with "x")
[ ] 1.x
[X] 2.x

I'm submitting a ... (check one with "x")
[ ] bug report
[X] feature request
[ ] support request => Please do not submit support requests here, use one of these channels: https://forum.ionicframework.com/ or http://ionicworldwide.herokuapp.com/

Current behavior:
This request has two parts:

  1. When a new page is generated, we need to manually add the page to the app.module.ts file under declarations and also entryComponents. It would be nice to automatically add this when we run the command "ionic g page {nameOfPage}"
  2. When we generate a page with the command "ionic g page {nameOfPage}" the command does not check to see if the page/directory already exists.If it does exist it overwrites the existing page without asking or notifying the user. Overwriting an existing page is not ideal for the user.

Expected behavior:

  1. When we run the command "ionic g page {nameOfPage}", it would be preferable if the page was also added to the app.module.ts file so the user would not have to do that manually.
  2. If the page/directory already exist the command would generate an error and not overwrite the existing page

_Copied from original issue: driftyco/ionic#9899_

Most helpful comment

I just overwrote a very important file with the command "ionic g provider {nameOfProvider}" It was a dumb mistake, but very frustrating. It could have been avoided with the 2nd expected behavior outlined here. I'm trying to recover it by downloading my app's most recent version on ionic.io / Ionic View. I've contacted [email protected] to see what my options are.

All 10 comments

_From @astec on January 6, 2017 16:5_

Also please add support for sub-directories. E.g. "module1/page1" should generate Page1Page in "pages/module1/page1.ts" rather then Module1Page1Page in "pages/module1-page1.ts"

I echo this sentiment. When I generate new components (or else) using angular-cli, it automatically adds it to the app.module.ts file. Ionic-cli should provide the same behavior.

Any news about this feature ?

I just overwrote a very important file with the command "ionic g provider {nameOfProvider}" It was a dumb mistake, but very frustrating. It could have been avoided with the 2nd expected behavior outlined here. I'm trying to recover it by downloading my app's most recent version on ionic.io / Ionic View. I've contacted [email protected] to see what my options are.

2 is worth checking, I've also overwrites a provider file using "ionic g provider ProviderName".

Out of lazyness ive hit the "arrow up" in my command prompt so it will issue the last command,now after checking the file it was totally new, although the overwrited file is not very important to me as of now,a prompt for file duplicate is very important for other projects.

details:
ionic/cli-utils : 1.3.0
cordova cli : 7.0.1
ionic cli : 3.3.0

Generators will be improved. We're aware of the poor UX. In the meantime, we highly recommend using version control such as git.

@dwieeb using git is all fine and dandy, but what i have done before is:

  1. run the app using ionic run android
  2. generated page using ionic generate page test-page
  3. filled out page skeleton
  4. very quickly in command prompt: hit up key and enter (because most of what i use it for is building/running my app). - This overwrites my file with an empty one.

At this point whatever work I have done is gone and I wouldn't think anyone would commit before running to verify it is working at least once...

I imagine most of the people running into this issue are already using version control.

I'm curious why you've closed the issue? is #1 resolved? are you moving the issue elsewhere?

@goleary Because there are serious architectural problems with our generators. I don't even think it would be _possible_ right now to check if the file exists and prompt back for overwrite confirmation. I see our current generators as a stopgap and will take a serious look at them later, but I don't have time or energy to take a look at this right now.

Here's a placeholder issue: https://github.com/ionic-team/ionic-cli/issues/2407

+1. Just lost work because of this silly overwriting thing. Would love to see this reopened and fixed.

Was this page helpful?
0 / 5 - 0 ratings