'Save current projects path to variable package.json

So i have multiple projects in which a run a script to install librarys and such. My question now is how do i save/get the path of the current project into a var so that i don't have to change the path at every project. Or if there is any other solution to this. I have tried this so far

    {
      "name": "myApp",
      "config": {
        "currentProjectPath": "./../../../Project/myProject"
      },
      "scripts": {
        "lib-install":"cd ./../library/ && npm run package && cd '%npm_package_config_currentProjectPath%'"
      }
    }
    //And then i do : npm run lib-install

So here i get the correct pathing but there is still an nstance where i have to change a single path so i tried setting the path to this and add | cmd at end:

  "config": {
    "currentProjectPath": "%cd%"
  },

But now it goes to the lib file since it goes there first.

So how would i save the projectPath at the start and hte nreuse it at the end ?

I assume it would look something like this:

  "scripts": {
    "ilib-prepare-for-prod": "set npm_package_config_currentProjectPath%=%cd% && cd ./../library/ && npm run package && cd %npm_package_config_currentProjectPath% |cmd",
}


Solution 1:[1]

$ awk -v OFS=, '{$1=(NR==1?"subjectID":25000) OFS $1}1' file


subjectID,LabelID,Mean,StdD,Max,Min,Count,Vol(mm^3),Extent(Vox)
25000,0,0.00000,0.00000,0.00000,0.00000,14121856,2973312.714,512,512,54
25000,1,1.00000,0.00000,1.00000,1.00000,2802,589.952,51,32,31
25000,2,2.00000,0.00000,2.00000,2.00000,127,26.739,11,14,18
25000,3,3.00000,0.00000,3.00000,3.00000,2379,500.891,34,21,27
25000,4,4.00000,0.00000,4.00000,4.00000,462,97.273,29,20,21

Solution 2:[2]

awk -v OFS="," '{$0=$1FS$0} NR==1 {$1="subjectID"} NR!=1 {$1=2500}1' input_file
subjectID,LabelID,Mean,StdD,Max,Min,Count,Vol(mm^3),Extent(Vox)
2500,0,0.00000,0.00000,0.00000,0.00000,14121856,2973312.714,512,512,54
2500,1,1.00000,0.00000,1.00000,1.00000,2802,589.952,51,32,31
2500,2,2.00000,0.00000,2.00000,2.00000,127,26.739,11,14,18
2500,3,3.00000,0.00000,3.00000,3.00000,2379,500.891,34,21,27
2500,4,4.00000,0.00000,4.00000,4.00000,462,97.273,29,20,21
2500,5,5.00000,0.00000,5.00000,5.00000,2913,613.323,45,32,9
2500,8,8.00000,0.00000,8.00000,8.00000,5235,1102.213,49,31,31
2500,9,9.00000,0.00000,9.00000,9.00000,4483,943.882,47,43,22
2500,10,10.00000,0.00000,10.00000,10.00000,2492,524.683,38,27,23
2500,11,11.00000,0.00000,11.00000,11.00000,11424,2405.288,44,47,24
2500,12,12.00000,0.00000,12.00000,12.00000,1603,337.507,56,18,9

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 karakfa
Solution 2 HatLess