1+ import fs from 'fs' ;
2+ import path from 'path' ;
3+
14import { DEFAULT_TEMPLATE_REPO , DEFAULT_TEMPLATE_TOOL_NAME , PgpmPackage , sluggify } from '@pgpmjs/core' ;
2- import { Logger } from '@pgpmjs/logger' ;
35import { errors } from '@pgpmjs/types' ;
46import { Inquirerer , OptionValue , Question } from 'inquirerer' ;
57
6- const log = new Logger ( 'module-init' ) ;
8+ const DEFAULT_MOTD = `
9+ | _ _
10+ === |.===. '\\-//\`
11+ (o o) {}o o{} (o o)
12+ ooO--(_)--Ooo-ooO--(_)--Ooo-ooO--(_)--Ooo-
13+ ` ;
714
815export default async function runModuleSetup (
916 argv : Partial < Record < string , any > > ,
@@ -14,12 +21,12 @@ export default async function runModuleSetup(
1421 const project = new PgpmPackage ( cwd ) ;
1522
1623 if ( ! project . workspacePath ) {
17- log . error ( 'Not inside a PGPM workspace.' ) ;
24+ process . stderr . write ( 'Not inside a PGPM workspace.\n ' ) ;
1825 throw errors . NOT_IN_WORKSPACE ( { } ) ;
1926 }
2027
2128 if ( ! project . isInsideAllowedDirs ( cwd ) && ! project . isInWorkspace ( ) && ! project . isParentOfAllowedDirs ( cwd ) ) {
22- log . error ( 'You must be inside the workspace root or a parent directory of modules (like packages/).' ) ;
29+ process . stderr . write ( 'You must be inside the workspace root or a parent directory of modules (like packages/).\n ' ) ;
2330 throw errors . NOT_IN_WORKSPACE_MODULE ( { } ) ;
2431 }
2532
@@ -74,6 +81,28 @@ export default async function runModuleSetup(
7481 noTty : Boolean ( ( argv as any ) . noTty || argv [ 'no-tty' ] || process . env . CI === 'true' )
7582 } ) ;
7683
77- log . success ( `Initialized module: ${ modName } ` ) ;
84+ const isRoot = path . resolve ( project . getWorkspacePath ( ) ! ) === path . resolve ( cwd ) ;
85+ const modulePath = isRoot
86+ ? path . join ( cwd , 'packages' , modName )
87+ : path . join ( cwd , modName ) ;
88+
89+ const motdPath = path . join ( modulePath , '.motd' ) ;
90+ let motd = DEFAULT_MOTD ;
91+ if ( fs . existsSync ( motdPath ) ) {
92+ try {
93+ motd = fs . readFileSync ( motdPath , 'utf8' ) ;
94+ fs . unlinkSync ( motdPath ) ;
95+ } catch {
96+ // Ignore errors reading/deleting .motd
97+ }
98+ }
99+ process . stdout . write ( motd ) ;
100+ if ( ! motd . endsWith ( '\n' ) ) {
101+ process . stdout . write ( '\n' ) ;
102+ }
103+
104+ const relPath = isRoot ? `packages/${ modName } ` : modName ;
105+ process . stdout . write ( `\n✨ Enjoy!\n\ncd ./${ relPath } \n` ) ;
106+
78107 return { ...argv , ...answers } ;
79108}
0 commit comments