Reputation: 5755
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?
Upvotes: 9
Views: 10637
Reputation: 3151
create-nx-workspace --[params]
git remote add origin git@github.com:org_name/repository.git
git branch -M main
git pull origin main --allow-unrelated-histories --rebase=false
git push -u origin main
At step 4, assuming you have a new repository, you may have conflicts in only 2 files, .gitignore
and README.md
, which are pretty easy to resolve (even auto); if it's a blank repo, there will be none!
Upvotes: 0
Reputation: 66
Looks like this cannot be done at the moment so I opened an issue here.
Clone your project (let's say it's called urproject
)
git clone urproject
Enter the cloned directory.
cd urproject
Create the workspace via the wizard as normal. FOR THE DIRECTORY INPUT ENTER ANY NAME (like urproject
)
npx nx create-nx-workspace
Move the created project from the created subdirectory to the current one.
It's important to match the .gitignore
and other dotfiles as well.
mv ./urproject/* /urproject/.* .
Remove the temporary directory created by the wizard.
rm -rf ./urproject
Upvotes: 0
Reputation: 11
I think you need to install nx in an existing repo/workspace. Run the following command in your root folder:
npx nx@latest init
Check out more here: https://nx.dev/getting-started/installation
Upvotes: 1
Reputation: 388
I ran into the same situation and I just moved the resulting files one directory up.
Upvotes: 1
Reputation: 61
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:
cd my-org-repo
and run git remote add origin [your-git-repo-url]
git remote -v
.
It should show something like origin [your-git-repo-url] (fetch)
origin [your-git-repo-url] (push)
git push --set-upstream origin main
. Replace main
with your branch name
in case it's differentUpvotes: 1