Reputation: 511
I am using npm to download a private git repository with npm install
command. However, the downloaded repository does not contain a .git folder or a .gitignore file. Is there any way that I can solve this problem?
Upvotes: 1
Views: 618
Reputation: 511
I found the way to generate .git folder and .gitignore via git command. I write the script in postinstall field of package.json. Here is my example of package.json.
...
"dependencies": {
"test": "git+ssh://[email protected]/repo.git"
},
"scripts": {
"start": "npm config set tmp `pwd`",
"postinstall": "cd node_module/repo && mv .npmignore .gitignore && git clone --no-checkout repo && mv repo/.git/ .git/ && git read-tree --reset HEAD && rm -r repo"
}
...
Then first I run npm start to setup npm tmp config, then I run npm install to generate .git folder and .gitignore file back.
However, I encounter another problem that the content of downloaded package.json will change with add more content like "_id", "_resolved", "_from", etc. Not knowing how to solve this problem now.
Upvotes: 0