@@ -169,10 +169,27 @@ function createComponentStructure(framework, overwrite) {
169169 console . log ( chalk . gray ( ` • Created component directory structure at ${ chalk . cyan ( inboxDir ) } ` ) ) ;
170170
171171 console . log ( chalk . gray ( '\n• Creating component files...' ) ) ;
172- const inboxComponentFilePath = path . join ( inboxDir , 'novuInbox .tsx' ) ;
172+ const inboxComponentFilePath = path . join ( inboxDir , 'NovuInbox .tsx' ) ;
173173 const inboxComponentContent = generateInboxComponentContent ( framework ) ;
174174 fs . writeFileSync ( inboxComponentFilePath , inboxComponentContent ) ;
175- console . log ( chalk . green ( ` ✓ Created ${ chalk . cyan ( path . join ( inboxRelativeDir , 'novuInbox.tsx' ) ) } ` ) ) ;
175+ console . log ( chalk . green ( ` ✓ Created ${ chalk . cyan ( path . join ( inboxRelativeDir , 'NovuInbox.tsx' ) ) } ` ) ) ;
176+ }
177+
178+ /**
179+ * Checks if next-themes is installed by looking at package.json
180+ * @returns {boolean } Whether next-themes is present in dependencies or devDependencies
181+ */
182+ function hasNextThemes ( ) {
183+ try {
184+ const packageJsonPath = path . join ( process . cwd ( ) , 'package.json' ) ;
185+ const packageJson = JSON . parse ( fs . readFileSync ( packageJsonPath , 'utf-8' ) ) ;
186+ return (
187+ ( packageJson . dependencies && packageJson . dependencies [ 'next-themes' ] ) ||
188+ ( packageJson . devDependencies && packageJson . devDependencies [ 'next-themes' ] )
189+ ) ;
190+ } catch ( error ) {
191+ return false ;
192+ }
176193}
177194
178195/**
@@ -182,12 +199,19 @@ function createComponentStructure(framework, overwrite) {
182199 */
183200function generateInboxComponentContent ( framework ) {
184201 if ( framework === 'nextjs' ) {
185- return `'use client';
186-
187- import { Inbox } from '@novu/nextjs';
188- import { dark } from '@novu/nextjs/themes';
189- import { useTheme } from 'next-themes';
202+ const hasThemes = hasNextThemes ( ) ;
203+ const imports = [
204+ "'use client';" ,
205+ "" ,
206+ "import { Inbox } from '@novu/nextjs';" ,
207+ ] ;
208+
209+ if ( hasThemes ) {
210+ imports . push ( "import { dark } from '@novu/nextjs/themes';" ) ;
211+ imports . push ( "import { useTheme } from 'next-themes';" ) ;
212+ }
190213
214+ const configCode = `
191215// The Novu inbox component is a React component that allows you to display a notification inbox.
192216// Learn more: https://docs.novu.co/platform/inbox/overview
193217
@@ -211,8 +235,9 @@ const inboxConfig = {
211235 // Learn more: https://docs.novu.co/platform/inbox/react/styling#elements
212236 }
213237 },
214- };
238+ };` ;
215239
240+ const componentCode = hasThemes ? `
216241export default function NovuInbox() {
217242 const { resolvedTheme } = useTheme();
218243
@@ -225,7 +250,12 @@ export default function NovuInbox() {
225250 }}
226251 />
227252 );
253+ }` : `
254+ export default function NovuInbox() {
255+ return <Inbox {...inboxConfig} />;
228256}` ;
257+
258+ return `${ imports . join ( '\n' ) } ${ configCode } ${ componentCode } ` ;
229259 }
230260
231261 // React (CRA, Vite, etc.)
@@ -269,7 +299,6 @@ export default function NovuInbox() {
269299}` ;
270300}
271301
272-
273302/**
274303 * Creates or updates the .env.example file for Next.js projects.
275304 * @param {boolean } updateExisting - Whether to append to an existing .env.example.
@@ -308,7 +337,7 @@ NEXT_PUBLIC_NOVU_SUBSCRIBER_ID=your_subscriber_id_here
308337 * @param {string } framework - 'nextjs' or 'react'.
309338 */
310339function displayNextSteps ( framework ) {
311- const componentImportPath = './components/ui/inbox/novuInbox ' ; // Updated import path
340+ const componentImportPath = './components/ui/inbox/NovuInbox ' ; // Updated import path with new filename
312341
313342 console . log ( chalk . bold . blue ( '\n📝 Next Steps' ) ) ;
314343 console . log ( chalk . gray ( '━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\n' ) ) ;
@@ -349,6 +378,33 @@ function displayNextSteps(framework) {
349378 console . log ( chalk . bold . green ( '🎉 You\'re all set! Happy coding with Novu! 🎉\n' ) ) ;
350379}
351380
381+ /**
382+ * Removes the add-inbox package after successful installation.
383+ * @param {object } packageManager - The package manager object { name, install }
384+ */
385+ function removeSelf ( packageManager ) {
386+ console . log ( chalk . yellow ( '\n🧹 Cleaning up...' ) ) ;
387+ console . log ( chalk . gray ( '━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\n' ) ) ;
388+
389+ try {
390+ // Check if we're running from the source directory
391+ const isSourceDir = __dirname === process . cwd ( ) ;
392+
393+ if ( isSourceDir ) {
394+ console . log ( chalk . blue ( ' • Running from source directory - skipping self-removal' ) ) ;
395+ console . log ( chalk . gray ( ' This is expected when testing locally.' ) ) ;
396+ return ;
397+ }
398+
399+ const command = `${ packageManager . name } remove add-inbox` ;
400+ console . log ( chalk . gray ( ` $ ${ command } ` ) ) ;
401+ execSync ( command , { stdio : 'inherit' } ) ;
402+ console . log ( chalk . green ( ' ✓ Removed add-inbox package' ) ) ;
403+ } catch ( error ) {
404+ console . log ( chalk . yellow ( ' • Could not remove add-inbox package automatically.' ) ) ;
405+ console . log ( chalk . gray ( ' You can manually remove it later if desired.' ) ) ;
406+ }
407+ }
352408
353409// --- Main Installation Logic ---
354410async function init ( ) {
@@ -385,6 +441,11 @@ async function init() {
385441 }
386442
387443 console . log ( chalk . green . bold ( '\n✅ Installation completed successfully!\n' ) ) ;
444+
445+
446+ // Remove the package after successful installation
447+ removeSelf ( packageManager ) ;
448+
388449 displayNextSteps ( framework ) ;
389450
390451 } catch ( error ) {
@@ -398,13 +459,12 @@ async function init() {
398459 if ( error . stdout ) {
399460 console . error ( chalk . gray ( ` Stdout: ${ error . stdout . toString ( ) . trim ( ) } ` ) ) ;
400461 }
401- // For more detailed debugging if needed:
402- // console.error(error);
403462 console . log ( chalk . yellow ( '\nPlease check the error messages above. If the issue persists, consult the Novu documentation or seek support.' ) ) ;
404463 process . exit ( 1 ) ;
405464 }
406465}
407466
467+
408468// --- Entry Point ---
409469if ( require . main === module ) {
410470 init ( ) . catch ( ( error ) => {
0 commit comments