Skip to content

Commit 421cdfc

Browse files
committed
added some fixes
1 parent dc9da30 commit 421cdfc

File tree

5 files changed

+278
-15
lines changed

5 files changed

+278
-15
lines changed

.github/workflows/publish.yml

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
name: Publish to NPM
2+
3+
on:
4+
release:
5+
types: [created]
6+
workflow_dispatch:
7+
inputs:
8+
version:
9+
description: 'Version bump type (major, minor, patch)'
10+
required: true
11+
default: 'patch'
12+
type: choice
13+
options:
14+
- patch
15+
- minor
16+
- major
17+
18+
jobs:
19+
publish:
20+
runs-on: ubuntu-latest
21+
steps:
22+
- name: Checkout code
23+
uses: actions/checkout@v4
24+
with:
25+
fetch-depth: 0
26+
27+
- name: Setup Git
28+
run: |
29+
git config --local user.email "[email protected]"
30+
git config --local user.name "GitHub Action"
31+
32+
- name: Setup Node.js
33+
uses: actions/setup-node@v4
34+
with:
35+
node-version: '18'
36+
registry-url: 'https://registry.npmjs.org'
37+
38+
- name: Install dependencies
39+
run: npm ci
40+
41+
- name: Run tests
42+
run: npm test
43+
continue-on-error: true # Skip if no tests exist
44+
45+
- name: Bump version
46+
if: github.event_name == 'workflow_dispatch'
47+
run: |
48+
npm version ${{ github.event.inputs.version }} -m "chore(release): %s"
49+
50+
- name: Set version from release
51+
if: github.event_name == 'release'
52+
run: |
53+
VERSION=${GITHUB_REF#refs/tags/v}
54+
npm version $VERSION --no-git-tag-version
55+
56+
- name: Publish to NPM
57+
run: npm publish --access public
58+
env:
59+
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
60+
61+
- name: Push changes
62+
run: |
63+
git push
64+
git push --tags
65+
env:
66+
github_token: ${{ secrets.GITHUB_TOKEN }}

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
# Changelog
2+
3+
All notable changes to this project will be documented in this file.
4+
5+
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
6+
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

index.js

Lines changed: 72 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -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
*/
183200
function 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 ? `
216241
export 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
*/
310339
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
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 ---
354410
async 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 ---
409469
if (require.main === module) {
410470
init().catch((error) => {

package-lock.json

Lines changed: 121 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,14 @@
1313
"files": [
1414
"index.js",
1515
"README.md",
16-
"LICENSE"
16+
"LICENSE",
17+
"CHANGELOG.md"
1718
],
1819
"scripts": {
19-
"test": "echo \"Error: no test specified\" && exit 1"
20+
"test": "echo \"No tests configured\" && exit 0",
21+
"prepublishOnly": "npm test",
22+
"version": "conventional-changelog -p angular -i CHANGELOG.md -s && git add CHANGELOG.md",
23+
"postversion": "git push && git push --tags"
2024
},
2125
"keywords": [
2226
"novu",
@@ -34,12 +38,18 @@
3438
"chalk": "^4.1.2",
3539
"prompts": "^2.4.2"
3640
},
41+
"devDependencies": {
42+
"conventional-changelog-cli": "^4.1.0"
43+
},
3744
"repository": {
3845
"type": "git",
3946
"url": "git+https://github.com/iampearceman/add-inbox.git"
4047
},
4148
"bugs": {
4249
"url": "https://github.com/iampearceman/add-inbox/issues"
4350
},
44-
"homepage": "https://github.com/iampearceman/add-inbox#readme"
51+
"homepage": "https://github.com/iampearceman/add-inbox#readme",
52+
"publishConfig": {
53+
"access": "public"
54+
}
4555
}

0 commit comments

Comments
 (0)