简体   繁体   中英

NX: How to create a NX workspace in an existing empty git repository instead of creating it under a workspace name?

I have an existing repository. I have cleared all the unwanted files as I wanted to start a new NX-integrated project. But, I want to continue using the same repository as there are some files which I would prefer to be present in the root directory.

If I run npx create-nx-workspace@latest --preset=next --packageManager=yarn , it will ask a bunch of questions and create the project under the workspace name. I want the files to reside directly under the existing current directory rather than creating a new directory with the workspace name under the current directory.

For example, instead of

my-project
--nx-workspace-name
----package.json
----lib

I want the files to be under

my-project
--package.json
--lib

I went through all the create work space flags but didn't find a relevant flag which could resolve this issue. At present, I copy all the files and place them in the root directory. Then, I delete the folder with the workspace name.

An example would be to use something like the --flat flag while creating the NX react component which creates the files in the same directory without nesting the files under any new directory.

Is it possible to avoid this extra step?

I had the same issue and it seems create-nx-workspace command do not have any build-in flag to ignore hidden ".git" directory. I tried to use " --skipGit=true " flag but still it complains about hidden ".git" directory. What worked for me is to do things from scratch by using local git repo and then connecting it to remote git repo.

Steps:

  1. Empty your existing repository on remote/server and make sure there are no files or folders in the "main" branch and there are no other branches. Delete other branches as it might cause inconsistency.
  2. Delete your existing git repository folder. For eg say your existing repository name was "my-org-repo" then delete "my-org-repo" folder
  3. Go to the parent directory in terminal/cmd inside which you want to create the new nx-workspace folder and run " create-nx-workspace " command
  4. "create-nx-workspace" initializes the new git repo for you if you need to initialize manually and provide specific branch name you can pass the "skipGit" flag
  5. Now cd inside newly created directory cd my-org-repo and run git remote add origin [your-git-repo-url]
  6. Check if the remote is successfully added by running git remote -v . It should show something like origin [your-git-repo-url] (fetch) origin [your-git-repo-url] (push)
  7. Push your local repo changes to remote repo branch by running git push --set-upstream origin main . Replace main with your branch name in case it's different
  8. Now you have new repo setup with Nx at root level

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM