angular / angular-cli

CLI tool for Angular
https://cli.angular.dev
MIT License
26.78k stars 11.98k forks source link

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

Closed kuncevic closed 7 years ago

kuncevic commented 7 years ago

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 https://github.com/angular/angular-cli/commit/761e86f2224c718f62dcc100059096d5752c0726

Current situation

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

Now it is seams to be it is not longer possible due to this PR https://github.com/angular/angular-cli/pull/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 commented 7 years ago

Related https://github.com/angular/angular-cli/issues/4762

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

kuncevic commented 7 years ago

@Meligy, comment that saying it is not quite 'by design' https://github.com/angular/angular-cli/issues/4762#issuecomment-280508118 :

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 commented 7 years ago

ng init has been removed in https://github.com/angular/angular-cli/pull/4628.

Meligy commented 7 years ago

@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 https://github.com/angular/angular-cli/commit/3ad2856b27889a50a742c9dca9554a190c8509bf#commitcomment-20929880 a bit easier.

kuncevic commented 7 years ago

@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 commented 7 years ago

@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 commented 7 years ago

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 commented 7 years ago

@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 commented 7 years ago

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

filipesilva commented 7 years ago

That is @Meligy's suggestion in https://github.com/angular/angular-cli/issues/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 (https://github.com/angular/angular-cli/issues/1079) that would enable #4762.

denofevil commented 7 years ago

@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 commented 7 years ago

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

denofevil commented 7 years ago

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

hansl commented 7 years ago

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 commented 7 years ago

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