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);
|
|
|
|
}
|
|
|
|
|
2023-07-05 09:16:46 +03:00
|
|
|
const config = require('../../ghost/core/core/shared/config/loader').loadNconf({
|
|
|
|
customConfigPath: path.join(__dirname, '../../ghost/core')
|
2022-10-06 11:58:51 +03:00
|
|
|
});
|
|
|
|
|
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
|
2023-07-13 12:14:08 +03:00
|
|
|
command: 'nx run ghost:dev',
|
2023-07-05 09:16:46 +03:00
|
|
|
cwd: path.resolve(__dirname, '../../ghost/core'),
|
2022-09-23 15:30:23 +03:00
|
|
|
prefixColor: 'blue',
|
2023-09-26 18:29:17 +03:00
|
|
|
env: {
|
|
|
|
// In development mode, we allow self-signed certificates (for sending webmentions and oembeds)
|
|
|
|
NODE_TLS_REJECT_UNAUTHORIZED: '0',
|
|
|
|
}
|
2022-09-23 15:30:23 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
const COMMAND_ADMIN = {
|
|
|
|
name: 'admin',
|
2023-09-18 16:11:45 +03:00
|
|
|
command: `nx run ghost-admin:dev --live-reload-base-url=${liveReloadBaseUrl} --live-reload-port=4201`,
|
2023-07-05 09:16:46 +03:00
|
|
|
cwd: path.resolve(__dirname, '../../ghost/admin'),
|
2022-09-23 15:30:23 +03:00
|
|
|
prefixColor: 'green',
|
|
|
|
env: {}
|
|
|
|
};
|
|
|
|
|
2023-07-12 14:42:39 +03:00
|
|
|
const COMMAND_TYPESCRIPT = {
|
|
|
|
name: 'ts',
|
2023-09-01 12:52:16 +03:00
|
|
|
command: 'nx watch --projects=ghost/collections,ghost/in-memory-repository,ghost/bookshelf-repository,ghost/mail-events,ghost/model-to-domain-event-interceptor,ghost/post-revisions,ghost/nql-filter-expansions,ghost/post-events,ghost/donations,ghost/recommendations -- nx run \\$NX_PROJECT_NAME:build:ts',
|
2023-07-12 14:42:39 +03:00
|
|
|
cwd: path.resolve(__dirname, '../../'),
|
|
|
|
prefixColor: 'cyan',
|
|
|
|
env: {}
|
|
|
|
};
|
|
|
|
|
2023-09-28 13:36:17 +03:00
|
|
|
const COMMAND_ADMINX = {
|
|
|
|
name: 'adminX',
|
|
|
|
command: 'yarn dev',
|
|
|
|
cwd: path.resolve(__dirname, '../../apps/admin-x-settings'),
|
|
|
|
prefixColor: '#C35831',
|
|
|
|
env: {}
|
|
|
|
};
|
|
|
|
|
2022-09-23 15:30:23 +03:00
|
|
|
if (DASH_DASH_ARGS.includes('ghost')) {
|
2023-07-12 14:42:39 +03:00
|
|
|
commands = [COMMAND_GHOST, COMMAND_TYPESCRIPT];
|
2022-09-23 15:30:23 +03:00
|
|
|
} else if (DASH_DASH_ARGS.includes('admin')) {
|
2023-09-28 13:36:17 +03:00
|
|
|
commands = [COMMAND_ADMIN, COMMAND_ADMINX];
|
2022-09-23 15:30:23 +03:00
|
|
|
} else {
|
2023-09-28 13:36:17 +03:00
|
|
|
commands = [COMMAND_GHOST, COMMAND_TYPESCRIPT, COMMAND_ADMIN, COMMAND_ADMINX];
|
2023-05-19 11:32:13 +03:00
|
|
|
}
|
|
|
|
|
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',
|
2023-07-05 09:16:46 +03:00
|
|
|
cwd: path.resolve(__dirname, '../../apps/portal'),
|
2022-10-06 11:32:08 +03:00
|
|
|
prefixColor: 'magenta',
|
|
|
|
env: {}
|
2022-10-05 07:51:06 +03:00
|
|
|
});
|
2023-07-05 18:04:39 +03:00
|
|
|
|
|
|
|
if (DASH_DASH_ARGS.includes('https')) {
|
|
|
|
// Safari needs HTTPS for it to work
|
|
|
|
// To make this work, you'll need a CADDY server running in front
|
|
|
|
// Note the port is different because of this extra layer. Use the following Caddyfile:
|
|
|
|
// https://localhost:4176 {
|
|
|
|
// reverse_proxy http://localhost:4175
|
|
|
|
// }
|
|
|
|
|
|
|
|
COMMAND_GHOST.env['portal__url'] = 'https://localhost:4176/portal.min.js';
|
|
|
|
} else {
|
|
|
|
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',
|
2023-07-05 09:16:46 +03:00
|
|
|
cwd: path.resolve(__dirname, '../../apps/signup-form'),
|
2023-06-01 11:20:37 +03:00
|
|
|
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-07-05 09:16:46 +03:00
|
|
|
cwd: path.resolve(__dirname, '../../apps/announcement-bar'),
|
2023-05-22 16:23:17 +03:00
|
|
|
prefixColor: '#DC9D00',
|
|
|
|
env: {}
|
|
|
|
});
|
2023-07-27 10:09:01 +03:00
|
|
|
COMMAND_GHOST.env['announcementBar__url'] = 'http://localhost:4177/announcement-bar.min.js';
|
2023-05-22 16:23:17 +03:00
|
|
|
}
|
|
|
|
|
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-07-05 09:16:46 +03:00
|
|
|
cwd: path.resolve(__dirname, '../../apps/sodo-search'),
|
2023-03-17 13:51:42 +03:00
|
|
|
prefixColor: '#23de43',
|
|
|
|
env: {}
|
|
|
|
});
|
2023-07-27 10:09:01 +03:00
|
|
|
COMMAND_GHOST.env['sodoSearch__url'] = 'http://localhost:4178/sodo-search.min.js';
|
|
|
|
COMMAND_GHOST.env['sodoSearch__styles'] = 'http://localhost:4178/main.css';
|
2023-03-17 13:51:42 +03:00
|
|
|
}
|
|
|
|
|
2023-05-18 16:14:36 +03:00
|
|
|
if (DASH_DASH_ARGS.includes('lexical')) {
|
2023-06-23 11:47:35 +03:00
|
|
|
if (DASH_DASH_ARGS.includes('https')) {
|
|
|
|
// Safari needs HTTPS for it to work
|
|
|
|
// To make this work, you'll need a CADDY server running in front
|
|
|
|
// Note the port is different because of this extra layer. Use the following Caddyfile:
|
2023-08-18 16:30:59 +03:00
|
|
|
// https://localhost:41730 {
|
2023-06-27 15:51:37 +03:00
|
|
|
// reverse_proxy http://127.0.0.1:4173
|
2023-06-23 11:47:35 +03:00
|
|
|
// }
|
|
|
|
|
2023-10-02 22:32:05 +03:00
|
|
|
COMMAND_ADMIN.env['EDITOR_URL'] = 'https://localhost:41730/';
|
2023-06-23 11:47:35 +03:00
|
|
|
} else {
|
2023-10-02 22:32:05 +03:00
|
|
|
COMMAND_ADMIN.env['EDITOR_URL'] = 'http://localhost:4173/';
|
2023-06-23 11:47:35 +03:00
|
|
|
}
|
2023-05-18 16:14:36 +03:00
|
|
|
}
|
|
|
|
|
2023-06-22 11:22:14 +03:00
|
|
|
if (DASH_DASH_ARGS.includes('comments') || DASH_DASH_ARGS.includes('all')) {
|
2023-06-27 15:51:37 +03:00
|
|
|
if (DASH_DASH_ARGS.includes('https')) {
|
|
|
|
// Safari needs HTTPS for it to work
|
|
|
|
// To make this work, you'll need a CADDY server running in front
|
|
|
|
// Note the port is different because of this extra layer. Use the following Caddyfile:
|
|
|
|
// https://localhost:7174 {
|
|
|
|
// reverse_proxy http://127.0.0.1:7173
|
|
|
|
// }
|
|
|
|
COMMAND_GHOST.env['comments__url'] = 'https://localhost:7174/comments-ui.min.js';
|
|
|
|
} else {
|
|
|
|
COMMAND_GHOST.env['comments__url'] = 'http://localhost:7173/comments-ui.min.js';
|
|
|
|
}
|
|
|
|
|
2023-06-22 11:22:14 +03:00
|
|
|
commands.push({
|
|
|
|
name: 'comments',
|
|
|
|
command: 'yarn dev',
|
2023-07-05 09:16:46 +03:00
|
|
|
cwd: path.resolve(__dirname, '../../apps/comments-ui'),
|
2023-06-22 11:22:14 +03:00
|
|
|
prefixColor: '#E55137',
|
|
|
|
env: {}
|
|
|
|
});
|
2023-06-21 17:41:00 +03:00
|
|
|
}
|
|
|
|
|
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
|
|
|
}
|
|
|
|
})();
|