From 28cc88c2cd148882337bb5ad7a4abde3e65206b5 Mon Sep 17 00:00:00 2001 From: Daniel Lockyer Date: Thu, 6 Oct 2022 15:32:08 +0700 Subject: [PATCH] Added `--stripe` support to `yarn dev` refs https://ghost.slack.com/archives/C02G9E68C/p1665043198507819?thread_ts=1664955131.950719&cid=C02G9E68C - this adds support for `yarn dev --stripe` which will spin up the Stripe CLI to listen for webhooks, and configures Ghost with the secret key it needs to communicate - also fixes a minor typing error with a missing `env: {}` --- .github/dev.js | 39 +++++++++++++++++++++++++++++++++------ 1 file changed, 33 insertions(+), 6 deletions(-) diff --git a/.github/dev.js b/.github/dev.js index b7d1ea6258..168c021e82 100644 --- a/.github/dev.js +++ b/.github/dev.js @@ -1,8 +1,12 @@ const path = require('path'); +const util = require('util'); +const exec = util.promisify(require('child_process').exec); + const concurrently = require('concurrently'); const config = require('../ghost/core/core/shared/config'); const liveReloadBaseUrl = config.getSubdir() || '/ghost/'; +const siteUrl = config.getSiteUrl(); const DASH_DASH_ARGS = process.argv.filter(a => a.startsWith('--')).map(a => a.slice(2)); @@ -36,17 +40,40 @@ if (DASH_DASH_ARGS.includes('portal')) { name: 'portal', command: 'yarn dev', cwd: path.resolve(__dirname, '../ghost/portal'), - prefixColor: 'magenta' + prefixColor: 'magenta', + env: {} }); COMMAND_GHOST.env['portal__url'] = 'http://localhost:5368/umd/portal.min.js'; } -if (!commands.length) { - console.log(`No commands provided`); - process.exit(0); -} - (async () => { + if (DASH_DASH_ARGS.includes('stripe')) { + let stripeSecret; + try { + stripeSecret = await exec('stripe listen --print-secret'); + } catch (err) { + console.error('Failed to fetch Stripe secret token, do you need to connect Stripe CLI?', err); + } + + if (!stripeSecret || !stripeSecret.stdout) { + console.error('No Stripe secret was present'); + return; + } + + COMMAND_GHOST.env['WEBHOOK_SECRET'] = stripeSecret.stdout.trim(); + commands.push({ + name: 'stripe', + command: `stripe listen --forward-to ${siteUrl}members/webhooks/stripe/`, + prefixColor: 'yellow', + env: {} + }); + } + + if (!commands.length) { + console.log(`No commands provided`); + process.exit(0); + } + const {result} = concurrently(commands, { prefix: 'name', killOthers: ['failure', 'success']