Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature request: Initialize a new CLI project without having CLI globally installed #4768

Closed
kuncevic opened this issue Feb 17, 2017 · 15 comments

Comments

@kuncevic
Copy link

kuncevic commented Feb 17, 2017

Reason

Due to major breaking changes with each CLI release to be able to initialize a new project without having CLI globally installed so this way we can run multiple projects with different CLI versions on single PC and it is what was the purpose of this PR 761e86f

Current situation

Before beta30 without having CLI globally installed it was possible to create CLI app just like that :

  • npm init -y
  • npm install @angular/cli --save
  • alter package.json by adding "ng":"ng" script section (761e86f)
  • npm run ng -- init

Now it is seams to be it is not longer possible due to this PR #4628

Proposal

How about if you run npm run ng -- new on an empty folder it will create the new CLI app?

Right now it is also not an option because just by having a folder with just node_modules folder and a simple package.json like that:

{
  "name": "expl.beta.32.3",
  "version": "1.0.0",
  "description": "",
  "main": "index.js",
  "scripts": {
    "ng": "ng"
  },
  "keywords": [],
  "author": "",
  "license": "ISC",
  "devDependencies": {
    "@angular/cli": "^1.0.0-beta.32.3"
  }
} 

When running npm run ng -- new I am getting an error You cannot use the new command inside an Angular CLI project. which is not quite right because there is no Angular CLI app in my folder.

@Meligy
Copy link
Contributor

Meligy commented Feb 17, 2017

Related #4762

I think if we fix it, this one will be fixed as well.

@kuncevic
Copy link
Author

kuncevic commented Feb 17, 2017

@Meligy, comment that saying it is not quite 'by design' #4762 (comment) :

The Angular CLI does use node_modules to detect if it's in a project. This is by design and unlikely to change (it's Ember-CLI specific logic).

@filipesilva
Copy link
Contributor

ng init has been removed in #4628.

@Meligy
Copy link
Contributor

Meligy commented Feb 17, 2017

@filipesilva this is more related to #4762, which is also closed, but has a pending discussion that I hope you or @hansl can look at, so, it's either completely killed, or maybe opened for further consideration.

It also makes implementing your suggestion here 3ad2856#commitcomment-20929880 a bit easier.

@kuncevic
Copy link
Author

kuncevic commented Feb 17, 2017

@filipesilva I saw the PR you mentioned, that is why I raised the Feature request, why you do not want to keep for further discussion?

@filipesilva
Copy link
Contributor

@kuncevic this isn't a functionality that we want to explicitly support, but we might end up supporting via a bugfix that I discussed with @Meligy. He'll be looking into it.

@denofevil
Copy link

denofevil commented Feb 21, 2017

Hi everyone, Dennis from the WebStorm team.
We're using ng init to generate the project because due to some platform limitations project directory with .idea in it is already present at the time when we can finally invoke real project generator. We can generate the project in some temp directory for sure and then copy over, but this looks like a messy solution.
I'm not seeing a problem of keeping ng init in place as currently ng new just delegates the command line options to init (https://github.com/angular/angular-cli/blob/master/packages/%40angular/cli/commands/new.ts#L66)

@filipesilva
Copy link
Contributor

@denofevil the problem for us is that we don't want to support the command at all. It's not as much a matter of technical feasibility but rather a question of the set of commands we want to have in the CLI.

@Meligy did you have time to look at the bug we discussed?

@denofevil
Copy link

@filipesilva so how about handling non-empty directory in ng new like create-react-app does?

@filipesilva
Copy link
Contributor

That is @Meligy's suggestion in #4762. Maybe you can even use it in your scenario right now with no change: ng new sample -dir=..

Currently @Meligy's full scenario (using a local CLI install) doesn't work because the CLI uses package.json/node_modules as project identity, and thus it considers to already be inside of a project.

We were looking at fixing a related bug (#1079) that would enable #4762.

@denofevil
Copy link

@filipesilva actually that was the second thing I've tried and I'm getting

ng new sample -dir=.
Directory '.' already exists.

which seems to be handled here. This exception is causing then block in new command to be never invoked.
I'm trying with completely empty directory on the command line (and there are no package.json files in upper folders), in case of WebStorm/IntelliJ there would be .idea folder and [ProjectName].iml file

@filipesilva
Copy link
Contributor

Ok, that's a bit more problematic. Maybe we need a force flag or something.

@denofevil
Copy link

Yes, that would work ok for us.
If you think that --force would be ok I can probably come up with a PR.

@hansl
Copy link
Contributor

hansl commented Feb 22, 2017

Hi @denofevil @filipesilva,

Sorry about the lack of discussion on this, I've been away all weekend. I think Filipe has done a good job explaining why we removed init.

ng new --dir=. my-project should work, in my opinion. I'll make a PR to do it and try to merge it before RC. Cheers!

@hansl hansl reopened this Feb 22, 2017
@hansl
Copy link
Contributor

hansl commented Feb 22, 2017

Dupe of #4762. Will use that one to track. Thanks!

@hansl hansl closed this as completed Feb 22, 2017
@angular angular locked and limited conversation to collaborators Feb 22, 2017
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants