angular-cli icon indicating copy to clipboard operation
angular-cli copied to clipboard

Provide a way to generate a new project in an existing directory

Open frosiere opened this issue 9 years ago • 25 comments

The current implementation of ng new does not allow creating a new project in an existing directory.

It would be interesting to have an option to generate the project in the current directory without removing everything.

frosiere avatar Mar 15 '17 10:03 frosiere

This is already possible, try using this arguments:

ng new appName --directory ./

alvaro450 avatar Mar 17 '17 03:03 alvaro450

Closing as answered by @alvaro450, thanks!

filipesilva avatar Mar 18 '17 13:03 filipesilva

This does not work. I used exactly the command described above, result:

Error: Schematic input does not validate against the Schema: {"directory":"./","name":"appName","skipGit":false,"style":"css","version":"1.7.0","commit":{"message":"chore: initial commit from @angular/cli\n\n _ _ ____ _ ___\n / \\ _ __ __ _ _ _| | __ _ _ __ / ___| | |_ _|\n / △ \\ | '_ \\ / _\\` | | | | |/ _\\` | '__| | | | | | |\n / ___ \\| | | | (_| | |_| | | (_| | | | |___| |___ | |\n/_/ \\_\\_| |_|\\__, |\\__,_|_|\\__,_|_| \\____|_____|___|\n |___/\n","name":"Angular CLI","email":"[email protected]"},"path":"app","sourceDir":"src","inlineStyle":false,"inlineTemplate":false,"routing":false,"prefix":"app","skipTests":false,"skipInstall":false,"linkCli":false,"minimal":false,"serviceWorker":false} Errors: .directory should match format "path"

sokraflex avatar Feb 16 '18 19:02 sokraflex

I am running angular-cli as a project dependency (i.e. not installed globally), in an existing node electron project.

I want to initialize the existing project as angular project, copying/adding the file structure to the existing project.

The command ng new appName --directory ./ does not work, as I get: You cannot use the new command inside an Angular CLI project.

My project does not have any angular-cli.json file, but it has the angular-cli node_modules folder and is listed as dependency in package.json.

Since ng init command is no longer available, is there a way of achieving what I want to do?

I'm using Node.js 7.9.0, npm 4.6.1, and the local angular-cli version is same as npm.

javlc avatar Feb 18 '18 17:02 javlc

for me just ng new appName did the trick it generated inside existing directory

Angular CLI: 1.7.2 Node: 6.11.3 OS: win32 x64

markopill avatar Mar 07 '18 15:03 markopill

I get the same error as @javlc, solution from @markopill didn't work either.

Angular CLI: 1.7.3, Ndoe: 8.1.3, OS: Windows 10 x64

WaveMeUp avatar Mar 12 '18 13:03 WaveMeUp

ng new proj_name --directory ./

is not working for me as well producing the following error:

Error: Schematic input does not validate against the Schema: ...
Errors:
  .directory should match format "path"

PS: not even working with absolute paths, it's trying to re-create entire directory structure inside project's folder.

ab0ris avatar Mar 17 '18 18:03 ab0ris

Should be a bug, .directory should match format "path" also showing for me.

Also, I made --directory ./ in the past and it worked before...

thismarcoantonio avatar Mar 23 '18 00:03 thismarcoantonio

Work around i've found is to be one level higher then the directory you want. Ex: -develop (here) -- project_folder (where you want to init angular) so the command would be; ng new myAwesomeApp --directory project_folder

matthewwwillard avatar Mar 29 '18 19:03 matthewwwillard

Additionally I get

error! project-name/README.md already exists.
error! project-name/.gitignore already exists.

If I'm trying to add this to a project where I have already put a lot of work into the gitignore/ README. Bummer.

TylerGubala avatar Mar 31 '18 22:03 TylerGubala

@matthewwwillard it works for me, thanks! ng new myAwesomeApp --directory project_folder

Akiq2016 avatar Apr 03 '18 05:04 Akiq2016

ng new appName --directory ./ is failing for Angular CLI: 6.0.1

Error message is:

Schematic input does not validate against the Schema: {"dryRun":false,"directory":".","version":"6.0.1","skipGit":false,"skipInstall":false,"linkCli":false,"commit":true,"newProjectRoot":"projects","inlineStyle":false,"inlineTemplate":false,"routing":false,"prefix":"app","style":"css","skipTests":false}
Errors:

  Data path ".directory" should match format "path".

Although, going back up one directory and doing this is fine: ng new appName --directory project_folder

Also: is there a reason why the --directory flag is missing from ng new --help? It could save at least one Google search :)

jericdeleon avatar May 11 '18 15:05 jericdeleon

Thanks @jericdeleon It works for me. Thanks. 👍

Amitesh avatar May 12 '18 17:05 Amitesh

@jericdeleon in Angular CLI 6 try to use --directory . - works for me.

skrzepij avatar Jun 30 '18 18:06 skrzepij

For folks having the same situation as @TylerGubala. Just backup those files and replace them after the project generation.

NOTE: Make sure the .gitignore file includes, at least, all of the generated .gitignore configuration.

sebastiandg7 avatar Jul 06 '18 16:07 sebastiandg7

ng new appName --directory ./ only works if its a fresh blank directory. Say i have an express app created already and i want to install and create a cli app , it won't allow as having a package.json already present there. Can this append to the package.json and help people out.

For now i did a workaround where renamed my existing package.json and copied things back.

abhishek-g avatar Jul 13 '18 09:07 abhishek-g

I had the same problem about README.md file.

I run the ng new command from the upper directory

cd ../
ng new my-project --directory './existing-folder'

Works like a charm.

ip7e avatar Aug 02 '18 11:08 ip7e

I ended up just copying the files manually. Is there an issue created to get this added to the documentation and maybe even to all ./?

pcnate avatar Aug 08 '18 01:08 pcnate

@jericdeleon in Angular CLI 6 try to use --directory . - works for me.

Yes to create angular new project using cli in existing directory ng new project_name --directory .

Tested in angular 7

narendrasinghrathore avatar Nov 06 '18 04:11 narendrasinghrathore

Not working with @angular/cli 7.0.5. ng new proj-name --directory . creates a new directory proj-name in the current directory. Same as without the --directory flag.

charsi avatar Nov 13 '18 00:11 charsi