Skip to content

Commit

Permalink
Update build and publish workflow
Browse files Browse the repository at this point in the history
- add Readme
- add description
- fixes #8
  • Loading branch information
mayank1513 committed Aug 25, 2023
1 parent 1d7c347 commit 6a75572
Show file tree
Hide file tree
Showing 9 changed files with 167 additions and 17 deletions.
34 changes: 26 additions & 8 deletions .github/workflows/publish-to-npm-on-new-release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,23 +20,41 @@ jobs:
with:
node-version: 18
registry-url: https://registry.npmjs.org
- run: npm i -g pnpm && pnpm i --filter nextjs-themes
- run: npm i -g pnpm && pnpm i
name: Install dependencies
- name: Test
run: npm test
- name: Upload coverage reports to Codecov
uses: codecov/codecov-action@v3
env:
CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}
run: pnpm turbo build --filter persistnsync && npm test
- name: Setup Git
run: |
git config --global user.name "mayank1513"
git config --global user.email "[email protected]"
git fetch
git checkout main
- name: update version and push back to the repo
run: cp -r ../../.changeset . && pnpm changeset version && git push origin main
- name: Publish to npm
run: pnpm changeset version && git push origin main
working-directory: .

- name: Publish persistNsync to NPM
id: persistNsync
working-directory: ./packages/persistnsync
continue-on-error: true
run: pnpm publish-package && pnpm publish-package2 && pnpm publish-package3
- uses: actions/setup-node@v3
if: steps.persistNsync.outcome == 'success'
with:
registry-url: https://npm.pkg.github.com/
- name: Publish to GitHub Public Repository
if: steps.persistNsync.outcome == 'success'
working-directory: ./packages/persistnsync
run: pnpm publish-gpr && pnpm publish-package2 && pnpm publish-package3
env:
NODE_AUTH_TOKEN: ${{secrets.GITHUB_TOKEN}}
- uses: actions/setup-node@v3
if: steps.persistNsync.outcome == 'success'
with:
registry-url: https://registry.npmjs.org

- name: Publish nextjs-themes to NPM
run: pnpm build && pnpm publish-package && pnpm publish-package2
env:
NODE_AUTH_TOKEN: ${{secrets.NPM_AUTH_TOKEN}}
Expand Down
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
# Nextjs-Themes [![Version](https://img.shields.io/npm/v/nextjs-themes.svg?colorB=green)](https://www.npmjs.com/package/nextjs-themes) [![codecov](https://codecov.io/gh/mayank1513/nextjs-themes/branch/main/graph/badge.svg?token=SUTY0GHPHV)](https://codecov.io/gh/mayank1513/nextjs-themes) [![Downloads](https://img.jsdelivr.com/img.shields.io/npm/dt/nextjs-themes.svg)](https://www.npmjs.com/package/nextjs-themes) [![Publish to npm and GitHub](https://github.com/mayank1513/nextjs-themes/actions/workflows/publish-to-npm-on-new-release.yml/badge.svg)](https://github.com/mayank1513/nextjs-themes/actions/workflows/publish-to-npm-on-new-release.yml)

🤟 👉 [Unleash the Power of React Server Components](https://medium.com/javascript-in-plain-english/unleash-the-power-of-react-server-components-eb3fe7201231)

This project is inspired by next-themes. Next-themes is an awesome package, however, it requires wrapping everything in a provider. The provider has to be a client component as it uses hooks. And thus, it takes away all the benefits of Server Components.

`nextjs-themes` removes this limitation and enables you to unleash the full power of React 18 Server Components. In addition, more features are coming up soon... Stay tuned!

- ✅ Designed for excellence
- ✅ Full TypeScript Support
- ✅ Unleash the full power of React18 Server components
- ✅ Works with all build systems/tools/frameworks for React18
- ✅ Perfect dark mode in 2 lines of code
Expand Down
1 change: 1 addition & 0 deletions packages/nextjs-themes/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
"name": "nextjs-themes",
"author": "Mayank Kumar Chaudhari <https://mayank-chaudhari.vercel.app>",
"version": "0.3.0",
"description": "Unleash the Power of React Server Components! Use multiple themes on your site with confidence, without losing any advantages of React Server Components.",
"main": "./dist/index.js",
"types": "./dist/index.d.ts",
"repository": {
Expand Down
8 changes: 4 additions & 4 deletions packages/nextjs-themes/seo.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,17 @@

const fs = require("fs");
const path = require("path");
const packageJson = require(path.resolve(__dirname, "dist", "package.json"));

const packageJsonPath = path.resolve(__dirname, "dist", "package.json");
const packageJson = require(packageJsonPath);
packageJson.name = packageJson.name.replace("nextjs", "react18");

fs.writeFileSync(path.resolve(__dirname, "dist", "package.json"), JSON.stringify(packageJson, null, 2));
fs.writeFileSync(packageJsonPath, JSON.stringify(packageJson, null, 2));

const readMePath = path.resolve(__dirname, "dist", "README.md");
let readMe = fs.readFileSync(readMePath, { encoding: "utf8" });
readMe = readMe.replace(/nextjs-themes/g, "react18-themes");
readMe = readMe.replace(/Nextjs-themes/g, "React18-themes");
readMe = readMe.replace(/Nextjs-Themes/g, "React18-Themes");
readMe = readMe.replace(/mayank1513\/react18[^/\)]*/g, "mayank1513/nextjs-themes"); //codecov
readMe = readMe.replace(/mayank1513\/react18[^/\)]*/g, "mayank1513/nextjs-themes"); //codecov and action badge
console.log(readMePath, readMe);
fs.writeFileSync(readMePath, readMe);
55 changes: 55 additions & 0 deletions packages/persistnsync/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
# PersistAndSync Zustand Store [![Version](https://img.shields.io/npm/v/persistnsync.svg?colorB=green)](https://www.npmjs.com/package/persistnsync) [![Downloads](https://img.jsdelivr.com/img.shields.io/npm/dt/persistnsync.svg)](https://www.npmjs.com/package/persistnsync) [![Unit Tests](https://github.com/mayank1513/nextjs-themes/actions/workflows/test.yml/badge.svg)](https://github.com/mayank1513/nextjs-themes/actions/workflows/test.yml)

> Zustand middleware to easily persist and sync Zustand state between tabs / windows / iframes (SameOrigin)
> Motivation: Recently I got cought up in several issues working with persist miggleware and syncing tabs with zustand. This is a simple light weight middleware to persist and instantly share state between tabs or windows
- ✅ 🐙 size cross-tab state sharing for zustand
- ✅ Full TypeScript Support
- ✅ solid reliability in 1 writing and n reading tab-scenarios (with changing writing tab)
- ✅ Fire and forget approach of always using the latest state. Perfect for single user systems
- ✅ Share state between multiple browsing contexts

## Install

```bash
$ pnpm add persistnsync
# or
$ npm install persistnsync
# or
$ yarn add persistnsync
```

## Usage

Simply add the middleware while creating the store and the rest will be taken care.

```ts
import { create } from "zustand";
import { persistNSync } from "persistnsync";

type MyStore = {
count: number;
set: (n: number) => void;
};

const useStore = create<MyStore>(
persistNSync(
set => ({
count: 0,
set: n => set({ count: n }),
}),
{ name: "my-channel" },
),
);
```

⚡🎉Boom! Just a couple of lines and your state perfectly syncs between tabs/windows and it is also persisted using `localStorage`!

## License

Licensed as MIT open source.

<hr />

<p align="center" style="text-align:center">with 💖 by <a href="https://mayank-chaudhari.vercel.app" target="_blank">Mayank Kumar Chaudhari</a></p>
37 changes: 32 additions & 5 deletions packages/persistnsync/package.json
Original file line number Diff line number Diff line change
@@ -1,20 +1,47 @@
{
"name": "persistnsync",
"author": "Mayank Kumar Chaudhari <https://mayank-chaudhari.vercel.app>",
"version": "0.0.0",
"description": "",
"description": "Zustand middleware to easily persist and sync Zustand state between tabs and windows",
"main": "dist/index.js",
"types": "dist/index.d.ts",
"homepage": "https://github.com/mayank1513/nextjs-themes#readme",
"sideEffects": false,
"license": "MIT",
"scripts": {
"build": "tsc && node createPackageJSON.js"
"build": "tsc && node createPackageJSON.js",
"publish-package": "cp README.md dist && cd dist && npm publish && cd ..",
"publish-package2": "node seo.js && cd dist && npm publish && cd ..",
"publish-package3": "node seo1.js && cd dist && npm publish && cd ..",
"publish-gpr": "node createPackageJSON.js && cp README.md dist && node prepGPR.js && cd dist && npm publish && cd .."
},
"funding": {
"type": "github",
"url": "https://github.com/sponsors/mayank1513"
},
"author": "",
"license": "ISC",
"devDependencies": {
"@types/node": "^20.4.5",
"typescript": "^5.1.6",
"zustand": "^4.4.1"
},
"peerDependencies": {
"zustand": "^3 || ^4"
}
},
"keywords": [
"web",
"api",
"broadcast",
"channel",
"broadcast-channel",
"hooks",
"react",
"react 18",
"zustand",
"middleware",
"state",
"optimized",
"tiny",
"typescript",
"javascript"
]
}
12 changes: 12 additions & 0 deletions packages/persistnsync/prepGPR.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
"use strict";

const fs = require("fs");
const path = require("path");

const packageJsonPath = path.resolve(__dirname, "dist", "package.json");
const packageJson = require(packageJsonPath);
packageJson.name = `@mayank1513/${packageJson.name}`;
packageJson.publishConfig = {
"@mayank1513:registry": "https://npm.pkg.github.com",
};
fs.writeFileSync(packageJsonPath, JSON.stringify(packageJson, null, 2));
17 changes: 17 additions & 0 deletions packages/persistnsync/seo.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
"use strict";

const fs = require("fs");
const path = require("path");

const name = "persist-n-sync";
const ref = "persistnsync";

const packageJsonPath = path.resolve(__dirname, "dist", "package.json");
const packageJson = require(packageJsonPath);
packageJson.name = packageJson.name.replace(ref, name);
fs.writeFileSync(packageJsonPath, JSON.stringify(packageJson, null, 2));

const readMePath = path.resolve(__dirname, "dist", "README.md");
let readMe = fs.readFileSync(readMePath, { encoding: "utf8" });
readMe = readMe.replace(new RegExp(ref, "g"), name);
fs.writeFileSync(readMePath, readMe);
17 changes: 17 additions & 0 deletions packages/persistnsync/seo1.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
"use strict";

const fs = require("fs");
const path = require("path");

const name = "persist-and-sync";
const ref = "persist-n-sync";

const packageJsonPath = path.resolve(__dirname, "dist", "package.json");
const packageJson = require(packageJsonPath);
packageJson.name = packageJson.name.replace(ref, name);
fs.writeFileSync(packageJsonPath, JSON.stringify(packageJson, null, 2));

const readMePath = path.resolve(__dirname, "dist", "README.md");
let readMe = fs.readFileSync(readMePath, { encoding: "utf8" });
readMe = readMe.replace(new RegExp(ref, "g"), name);
fs.writeFileSync(readMePath, readMe);

0 comments on commit 6a75572

Please sign in to comment.