2023-12-13 15:07:48 +03:00
const fs = require ( 'fs' ) ;
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 ) ;
2023-11-15 11:55:10 +03:00
const chalk = require ( 'chalk' ) ;
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
} ) ;
2023-12-13 15:07:48 +03:00
const tsPackages = fs . readdirSync ( path . resolve ( _ _dirname , '../../ghost' ) , { withFileTypes : true } )
. filter ( dirent => dirent . isDirectory ( ) )
. map ( dirent => dirent . name )
. filter ( packageFolder => {
try {
const packageJson = require ( path . resolve ( _ _dirname , ` ../../ghost/ ${ packageFolder } /package.json ` ) ) ;
return packageJson . scripts ? . [ 'build:ts' ] ;
} catch ( err ) {
return false ;
}
} )
. map ( packageFolder => ` ghost/ ${ packageFolder } ` )
. join ( ',' ) ;
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-12-13 15:07:48 +03:00
command : ` while [ 1 ]; do nx watch --projects= ${ tsPackages } -- nx run \\ $ NX_PROJECT_NAME:build:ts; done ` ,
2023-07-12 14:42:39 +03:00
cwd : path . resolve ( _ _dirname , '../../' ) ,
prefixColor : 'cyan' ,
env : { }
} ;
2024-04-25 11:44:29 +03:00
const adminXApps = '@tryghost/admin-x-demo,@tryghost/admin-x-settings,@tryghost/admin-x-activitypub' ;
2023-11-20 16:30:15 +03:00
2023-11-08 15:33:18 +03:00
const COMMANDS _ADMINX = [ {
2023-11-14 16:50:08 +03:00
name : 'adminXDeps' ,
2023-12-13 12:26:33 +03:00
command : 'while [ 1 ]; do nx watch --projects=apps/admin-x-design-system,apps/admin-x-framework -- nx run \\$NX_PROJECT_NAME:build; done' ,
2023-11-08 15:33:18 +03:00
cwd : path . resolve ( _ _dirname , '../..' ) ,
prefixColor : '#C35831' ,
env : { }
} , {
2023-09-28 13:36:17 +03:00
name : 'adminX' ,
2023-12-13 12:26:33 +03:00
command : ` nx run-many --projects= ${ adminXApps } --parallel= ${ adminXApps . length } --targets=dev ` ,
2024-04-25 11:44:29 +03:00
cwd : path . resolve ( _ _dirname , '../../apps/admin-x-settings' , '../../apps/admin-x-activitypub' ) ,
2023-09-28 13:36:17 +03:00
prefixColor : '#C35831' ,
env : { }
2023-11-08 15:33:18 +03:00
} ] ;
2023-09-28 13:36:17 +03:00
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-11-08 15:33:18 +03:00
commands = [ COMMAND _ADMIN , ... COMMANDS _ADMINX ] ;
2022-09-23 15:30:23 +03:00
} else {
2023-11-08 15:33:18 +03:00
commands = [ COMMAND _GHOST , COMMAND _TYPESCRIPT , COMMAND _ADMIN , ... COMMANDS _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' ,
2023-11-15 11:54:09 +03:00
command : 'nx run @tryghost/portal: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' ,
2023-11-15 11:54:09 +03:00
command : DASH _DASH _ARGS . includes ( 'signup' ) ? 'nx run @tryghost/signup-form:dev' : 'nx run @tryghost/signup-form: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' ,
2023-11-15 11:54:09 +03:00
command : 'nx run @tryghost/announcement-bar: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' ,
2023-11-15 11:54:09 +03:00
command : 'nx run @tryghost/sodo-search: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' ,
2023-11-15 11:54:09 +03:00
command : 'nx run @tryghost/comments-ui: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
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 ) ;
}
2023-11-15 11:55:10 +03:00
console . log ( ` Running projects: ${ commands . map ( c => chalk . green ( c . name ) ) . join ( ', ' ) } ` ) ;
2022-09-23 15:30:23 +03:00
const { result } = concurrently ( commands , {
prefix : 'name' ,
killOthers : [ 'failure' , 'success' ]
} ) ;
try {
await result ;
} catch ( err ) {
2023-11-15 12:23:57 +03:00
console . error ( ) ;
console . error ( chalk . red ( ` Executing dev command failed: ` ) + ` \n ` ) ;
console . error ( chalk . red ( ` If you've recently done a \` yarn main \` , dependencies might be out of sync. Try running \` ${ chalk . green ( 'yarn fix' ) } \` to fix this. ` ) ) ;
console . error ( chalk . red ( ` If not, something else went wrong. Please report this to the Ghost team. ` ) ) ;
console . error ( ) ;
2022-09-23 15:30:23 +03:00
}
} ) ( ) ;