static-web-apps-cli icon indicating copy to clipboard operation
static-web-apps-cli copied to clipboard

Get Deploy Token

Open khill-fbmc opened this issue 2 years ago • 1 comments

Problem

I'm frustrated that the deploy --print-token command produces extraneous output

Idea

Remove all extra output and print just the token

Alternatives

This is my current solution

Additional context

This is the code from the above link to save a click

const { spawnSync } = require("node:child_process");

// Find the SWA CLI script
const binPath = require.resolve("@azure/static-web-apps-cli/dist/cli/bin.js");

// Run the script and capture the output
const { stdout } = spawnSync("node", [binPath, "deploy", "--print-token"], {
  stdio: "pipe",
});

// Remove empty lines from the output
const lines = `${stdout}`.split("\n").filter(Boolean);

// The last line is the token
const token = lines.pop();

process.stdout.write(token);

khill-fbmc avatar Sep 20 '23 13:09 khill-fbmc

Or just ouput a json which is easier to parse, for now I'm using this:

swa deploy --print-token | awk '/Deployment token:/{getline; print}'

gabynevada avatar Feb 11 '24 15:02 gabynevada