static-web-apps-cli
static-web-apps-cli copied to clipboard
Get Deploy Token
Problem
I'm frustrated that the deploy --print-token command produces extraneous output
Idea
Remove all extra output and print just the token
Alternatives
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);
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}'