0

I am on a windows machine with vscode and run commands from bash terminal inside it. However have found that the firebase deploy cli is more stable on my machine if called from cmd or powershell. Sometimes hangs with vscode.bash or gitbash terminal.

I have my cloud functions in typescript, and the firebase deploy --only functions runs the predeploy script e.g. npm run build

I have changed my npm build script to "build": "tsc && npm run copyKeys", so that it will always ensure changes to keys are copied before deploying. The keys are service account keys which are used by during the deployment.

The copyKeys script is "copyKeys": "cp -rf ./src/environments/service.acct.keys/ ./lib/environments/", this works nicely in bash.

But I need to a second xcopyKeys4Win script for when using powershell which becomes "xcopyKeys4Win": "XCOPY .\\src\\environments\\service.acct.keys .\\lib\\environments\\service.acct.keys /s /e /y /i" which works nicely from PS.

Now my issue is the when I call npm run deploy, this calls firebase deploy --only functions that runs the firebase predeploy scripts which call the npm run build and this build script is hard-coded to either ... npm run copyKeys or ... npm run xcopyKeys4Win.

I need someway to conditionally call 'npm run deploy' depending on whether needing bash cp e.g. on mac/linux/vscode.bash/gitbash, or xcopy if using cmd or PS.

E.g. either something similar to firebase hosting target setting or condition in the npm build script or something else, anyone got any ideas?

Frank van Puffelen
  • 565,676
  • 79
  • 828
  • 807
karlmnz
  • 138
  • 10

1 Answers1

0

ref: Cross-platform pipe command in NPM script

changed to "copyKeys": "node ./scripts/copy-keys.js" so build now can run a single script.

copy-keys.js is:

const fse = require('fs-extra');
const path = require('path');

const rootPath = path.resolve('./');
const sep = path.sep;
const head = `${rootPath}${sep}`;
const tail = `${sep}environments${sep}service.acct.keys`;

const src = `${head}src${tail}`;
const dest = `${head}lib${tail}`;

fse.copySync(src, dest);

So no longer need xcopyKeys4Win ...

karlmnz
  • 138
  • 10