I've got a bare repository from which we start new projects. Inside this repository is another repository that has to be updated seperately. Every project starts with these two repositories, but sometimes during the project they should not both be updated.
I'm trying to create an Npm script that clones the parent repository, after that it opens the folder and clones the child repository.
The script has a variable that represents the project and thus folder name.
Based on this answer, I came up with the following:
"new_project": "git clone x:/parent_repo $PROJECT & cd $PROJECT & git clone x:/child_repo"
I run the command like so: PROJECT=new_project_name npm run new_project
Have also tried PROJECT="new_project_name" npm run new_project
Unfortunately this creates a folder named $PROJECT
in stead of actualy reading the variable.
Also tried:
"new_project": "git clone x:/parent_repo $PROJECT & cd $PROJECT & git clone x:/child_repo"
npm run new_project --PROJECT new_project_name
or run with
npm run new_project -- --PROJECT=new_project
Same result.
Most of these sollutions seem to work on linux machines but not for Windows.
It appears the variables in the string are not being read as such. I tried
"git clone x:/parent_repo "+$PROJECT+" & cd "+$PROJECT+" & git clone x:/child_repo"
But that just gave me syntax errors.
How do I succesfully pass a variable from the command line that I can use in my npm script?
The command has to be a single line.
I'm using Git bash on windows as cli
npm version: 2.14.20
You can use the package.json
config.
{
"name" : "myapp",
"config" : { "folder": "myfolder" },
"scripts" : {
"new_project": "git clone x:/parent_repo $npm_package_config_folder & cd $npm_package_config_folder & git clone x:/child_repo"
}
}
Then :
npm config set myapp:folder mynewfolder
npm run newproject
But in my opinion, the better way is to use an external NodeJS custom script and run it with a npm script.
If you look at the following page: https://github.com/npm/npm/pull/5518 (it's on the answer you linked to)
"new_project": "git clone x:/parent_repo $PROJECT & cd $PROJECT & git clone x:/child_repo"
Then:
npm run --PROJECT new_project_name
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With