@@ -169,10 +169,27 @@ function createComponentStructure(framework, overwrite) {
169
169
console . log ( chalk . gray ( ` • Created component directory structure at ${ chalk . cyan ( inboxDir ) } ` ) ) ;
170
170
171
171
console . log ( chalk . gray ( '\n• Creating component files...' ) ) ;
172
- const inboxComponentFilePath = path . join ( inboxDir , 'novuInbox .tsx' ) ;
172
+ const inboxComponentFilePath = path . join ( inboxDir , 'NovuInbox .tsx' ) ;
173
173
const inboxComponentContent = generateInboxComponentContent ( framework ) ;
174
174
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
+ }
176
193
}
177
194
178
195
/**
@@ -182,12 +199,19 @@ function createComponentStructure(framework, overwrite) {
182
199
*/
183
200
function generateInboxComponentContent ( framework ) {
184
201
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
+ }
190
213
214
+ const configCode = `
191
215
// The Novu inbox component is a React component that allows you to display a notification inbox.
192
216
// Learn more: https://docs.novu.co/platform/inbox/overview
193
217
@@ -211,8 +235,9 @@ const inboxConfig = {
211
235
// Learn more: https://docs.novu.co/platform/inbox/react/styling#elements
212
236
}
213
237
},
214
- };
238
+ };` ;
215
239
240
+ const componentCode = hasThemes ? `
216
241
export default function NovuInbox() {
217
242
const { resolvedTheme } = useTheme();
218
243
@@ -225,7 +250,12 @@ export default function NovuInbox() {
225
250
}}
226
251
/>
227
252
);
253
+ }` : `
254
+ export default function NovuInbox() {
255
+ return <Inbox {...inboxConfig} />;
228
256
}` ;
257
+
258
+ return `${ imports . join ( '\n' ) } ${ configCode } ${ componentCode } ` ;
229
259
}
230
260
231
261
// React (CRA, Vite, etc.)
@@ -269,7 +299,6 @@ export default function NovuInbox() {
269
299
}` ;
270
300
}
271
301
272
-
273
302
/**
274
303
* Creates or updates the .env.example file for Next.js projects.
275
304
* @param {boolean } updateExisting - Whether to append to an existing .env.example.
@@ -308,7 +337,7 @@ NEXT_PUBLIC_NOVU_SUBSCRIBER_ID=your_subscriber_id_here
308
337
* @param {string } framework - 'nextjs' or 'react'.
309
338
*/
310
339
function 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
312
341
313
342
console . log ( chalk . bold . blue ( '\n📝 Next Steps' ) ) ;
314
343
console . log ( chalk . gray ( '━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\n' ) ) ;
@@ -349,6 +378,33 @@ function displayNextSteps(framework) {
349
378
console . log ( chalk . bold . green ( '🎉 You\'re all set! Happy coding with Novu! 🎉\n' ) ) ;
350
379
}
351
380
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
+ }
352
408
353
409
// --- Main Installation Logic ---
354
410
async function init ( ) {
@@ -385,6 +441,11 @@ async function init() {
385
441
}
386
442
387
443
console . log ( chalk . green . bold ( '\n✅ Installation completed successfully!\n' ) ) ;
444
+
445
+
446
+ // Remove the package after successful installation
447
+ removeSelf ( packageManager ) ;
448
+
388
449
displayNextSteps ( framework ) ;
389
450
390
451
} catch ( error ) {
@@ -398,13 +459,12 @@ async function init() {
398
459
if ( error . stdout ) {
399
460
console . error ( chalk . gray ( ` Stdout: ${ error . stdout . toString ( ) . trim ( ) } ` ) ) ;
400
461
}
401
- // For more detailed debugging if needed:
402
- // console.error(error);
403
462
console . log ( chalk . yellow ( '\nPlease check the error messages above. If the issue persists, consult the Novu documentation or seek support.' ) ) ;
404
463
process . exit ( 1 ) ;
405
464
}
406
465
}
407
466
467
+
408
468
// --- Entry Point ---
409
469
if ( require . main === module ) {
410
470
init ( ) . catch ( ( error ) => {
0 commit comments