2022-09-23 15:30:23 +03:00
|
|
|
const path = require('path');
|
2022-10-06 11:32:08 +03:00
|
|
|
const util = require('util');
|
|
|
|
const exec = util.promisify(require('child_process').exec);
|
|
|
|
|
2022-09-23 15:30:23 +03:00
|
|
|
const concurrently = require('concurrently');
|
|
|
|
|
2023-06-08 15:33:42 +03:00
|
|
|
// check we're running on Node 18 and above
|
|
|
|
const nodeVersion = parseInt(process.versions.node.split('.')[0]);
|
|
|
|
if (nodeVersion < 18) {
|
|
|
|
console.error('`yarn dev` requires Node v18 or above. Please upgrade your version of Node.');
|
|
|
|
process.exit(1);
|
|
|
|
}
|
|
|
|
|
2022-10-06 12:13:46 +03:00
|
|
|
const config = require('../ghost/core/core/shared/config/loader').loadNconf({
|
2022-10-06 11:58:51 +03:00
|
|
|
customConfigPath: path.join(__dirname, '../ghost/core')
|
|
|
|
});
|
|
|
|
|
2022-09-23 15:30:23 +03:00
|
|
|
const liveReloadBaseUrl = config.getSubdir() || '/ghost/';
|
2022-10-06 11:32:08 +03:00
|
|
|
const siteUrl = config.getSiteUrl();
|
2022-09-23 15:30:23 +03:00
|
|
|
|
|
|
|
const DASH_DASH_ARGS = process.argv.filter(a => a.startsWith('--')).map(a => a.slice(2));
|
|
|
|
|
|
|
|
let commands = [];
|
|
|
|
|
|
|
|
const COMMAND_GHOST = {
|
|
|
|
name: 'ghost',
|
2023-03-21 17:57:41 +03:00
|
|
|
// Note: if this isn't working for you, please use Node 18 and above
|
|
|
|
command: 'node --watch index.js',
|
|
|
|
cwd: path.resolve(__dirname, '../ghost/core'),
|
2022-09-23 15:30:23 +03:00
|
|
|
prefixColor: 'blue',
|
|
|
|
env: {}
|
|
|
|
};
|
|
|
|
|
|
|
|
const COMMAND_ADMIN = {
|
|
|
|
name: 'admin',
|
|
|
|
command: `yarn start --live-reload-base-url=${liveReloadBaseUrl} --live-reload-port=4201`,
|
|
|
|
cwd: path.resolve(__dirname, '../ghost/admin'),
|
|
|
|
prefixColor: 'green',
|
|
|
|
env: {}
|
|
|
|
};
|
|
|
|
|
|
|
|
if (DASH_DASH_ARGS.includes('ghost')) {
|
|
|
|
commands = [COMMAND_GHOST];
|
|
|
|
} else if (DASH_DASH_ARGS.includes('admin')) {
|
|
|
|
commands = [COMMAND_ADMIN];
|
|
|
|
} else {
|
|
|
|
commands = [COMMAND_GHOST, COMMAND_ADMIN];
|
|
|
|
}
|
|
|
|
|
2023-05-03 20:58:03 +03:00
|
|
|
if (DASH_DASH_ARGS.includes('revisions') || DASH_DASH_ARGS.includes('all')) {
|
|
|
|
commands.push({
|
|
|
|
name: 'post-revisions',
|
|
|
|
command: 'yarn dev',
|
|
|
|
cwd: path.resolve(__dirname, '../ghost/post-revisions'),
|
|
|
|
prefixColor: 'green',
|
|
|
|
env: {}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2023-05-10 16:23:16 +03:00
|
|
|
if (DASH_DASH_ARGS.includes('in-memory-repository') || DASH_DASH_ARGS.includes('all')) {
|
|
|
|
commands.push({
|
|
|
|
name: 'in-memory-repository',
|
|
|
|
command: 'yarn dev',
|
|
|
|
cwd: path.resolve(__dirname, '../ghost/in-memory-repository'),
|
|
|
|
prefixColor: 'pink',
|
|
|
|
env: {}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2023-05-19 11:32:13 +03:00
|
|
|
if (DASH_DASH_ARGS.includes('admin-x') || DASH_DASH_ARGS.includes('adminx') || DASH_DASH_ARGS.includes('adminX') || DASH_DASH_ARGS.includes('all')) {
|
|
|
|
commands.push({
|
|
|
|
name: 'adminX',
|
|
|
|
command: 'yarn dev',
|
|
|
|
cwd: path.resolve(__dirname, '../ghost/admin-x-settings'),
|
|
|
|
prefixColor: '#C35831',
|
|
|
|
env: {}
|
|
|
|
});
|
|
|
|
COMMAND_GHOST.env['adminX__url'] = 'http://localhost:4174/admin-x-settings.umd.js';
|
|
|
|
}
|
|
|
|
|
2023-04-27 02:55:03 +03:00
|
|
|
if (DASH_DASH_ARGS.includes('portal') || DASH_DASH_ARGS.includes('all')) {
|
2022-10-05 07:51:06 +03:00
|
|
|
commands.push({
|
|
|
|
name: 'portal',
|
|
|
|
command: 'yarn dev',
|
|
|
|
cwd: path.resolve(__dirname, '../ghost/portal'),
|
2022-10-06 11:32:08 +03:00
|
|
|
prefixColor: 'magenta',
|
|
|
|
env: {}
|
2022-10-05 07:51:06 +03:00
|
|
|
});
|
2023-06-02 12:32:13 +03:00
|
|
|
COMMAND_GHOST.env['portal__url'] = 'http://localhost:4175/portal.min.js';
|
2022-10-05 07:51:06 +03:00
|
|
|
}
|
|
|
|
|
2023-06-01 11:20:37 +03:00
|
|
|
if (DASH_DASH_ARGS.includes('signup') || DASH_DASH_ARGS.includes('all')) {
|
|
|
|
commands.push({
|
|
|
|
name: 'signup-form',
|
|
|
|
command: DASH_DASH_ARGS.includes('signup') ? 'yarn dev' : 'yarn preview',
|
|
|
|
cwd: path.resolve(__dirname, '../ghost/signup-form'),
|
|
|
|
prefixColor: 'magenta',
|
|
|
|
env: {}
|
|
|
|
});
|
|
|
|
COMMAND_GHOST.env['signupForm__url'] = 'http://localhost:6174/signup-form.min.js';
|
|
|
|
}
|
|
|
|
|
2023-05-22 16:23:17 +03:00
|
|
|
if (DASH_DASH_ARGS.includes('announcement-bar') || DASH_DASH_ARGS.includes('announcementBar') || DASH_DASH_ARGS.includes('announcementbar') || DASH_DASH_ARGS.includes('all')) {
|
|
|
|
commands.push({
|
|
|
|
name: 'announcement-bar',
|
|
|
|
command: 'yarn dev',
|
2023-06-14 13:14:33 +03:00
|
|
|
cwd: path.resolve(__dirname, '../apps/announcement-bar'),
|
2023-05-22 16:23:17 +03:00
|
|
|
prefixColor: '#DC9D00',
|
|
|
|
env: {}
|
|
|
|
});
|
|
|
|
COMMAND_GHOST.env['announcementBar__url'] = 'http://localhost:5371/announcement-bar';
|
|
|
|
}
|
|
|
|
|
2023-04-27 02:55:03 +03:00
|
|
|
if (DASH_DASH_ARGS.includes('search') || DASH_DASH_ARGS.includes('all')) {
|
2023-03-17 13:51:42 +03:00
|
|
|
commands.push({
|
|
|
|
name: 'search',
|
|
|
|
command: 'yarn dev',
|
2023-06-13 15:14:53 +03:00
|
|
|
cwd: path.resolve(__dirname, '../apps/sodo-search'),
|
2023-03-17 13:51:42 +03:00
|
|
|
prefixColor: '#23de43',
|
|
|
|
env: {}
|
|
|
|
});
|
|
|
|
COMMAND_GHOST.env['sodoSearch__url'] = 'http://localhost:5370/umd/sodo-search.min.js';
|
|
|
|
COMMAND_GHOST.env['sodoSearch__styles'] = 'http://localhost:5370/umd/main.css';
|
|
|
|
}
|
|
|
|
|
2023-05-18 16:14:36 +03:00
|
|
|
if (DASH_DASH_ARGS.includes('lexical')) {
|
|
|
|
COMMAND_GHOST.env['editor__url'] = 'http://localhost:4173/koenig-lexical.umd.js';
|
|
|
|
}
|
|
|
|
|
2023-04-27 02:55:03 +03:00
|
|
|
async function handleStripe() {
|
|
|
|
if (DASH_DASH_ARGS.includes('stripe') || DASH_DASH_ARGS.includes('all')) {
|
|
|
|
if (DASH_DASH_ARGS.includes('offline')) {
|
|
|
|
return;
|
|
|
|
}
|
2022-10-06 12:47:54 +03:00
|
|
|
console.log('Fetching Stripe secret token..');
|
|
|
|
|
2022-10-06 11:32:08 +03:00
|
|
|
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);
|
2022-10-06 11:42:19 +03:00
|
|
|
return;
|
2022-10-06 11:32:08 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
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: {}
|
|
|
|
});
|
|
|
|
}
|
2023-04-27 02:55:03 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
(async () => {
|
|
|
|
await handleStripe();
|
2022-10-06 11:32:08 +03:00
|
|
|
|
|
|
|
if (!commands.length) {
|
|
|
|
console.log(`No commands provided`);
|
|
|
|
process.exit(0);
|
|
|
|
}
|
|
|
|
|
2022-09-23 15:30:23 +03:00
|
|
|
const {result} = concurrently(commands, {
|
|
|
|
prefix: 'name',
|
|
|
|
killOthers: ['failure', 'success']
|
|
|
|
});
|
|
|
|
|
|
|
|
try {
|
|
|
|
await result;
|
|
|
|
} catch (err) {
|
2022-12-12 13:22:21 +03:00
|
|
|
console.error('\nExecuting dev command failed, ensure dependencies are up-to-date by running `yarn fix`\n');
|
2022-09-23 15:30:23 +03:00
|
|
|
}
|
|
|
|
})();
|