From e6c085876d2a35bd87f8c12a94797bb8c7510d1d Mon Sep 17 00:00:00 2001 From: Mayank Kumar Chaudhari Date: Wed, 5 Jun 2024 19:45:07 +0530 Subject: [PATCH 1/2] Fix publish script and format --- lib/src/client/color-switch/color-switch.tsx | 2 +- .../client/theme-switcher/theme-switcher.tsx | 30 ++++++++---- lib/src/constants.ts | 5 +- scripts/publish.js | 48 +++++++++++-------- 4 files changed, 54 insertions(+), 31 deletions(-) diff --git a/lib/src/client/color-switch/color-switch.tsx b/lib/src/client/color-switch/color-switch.tsx index 6a6b4b90..b6a1c208 100644 --- a/lib/src/client/color-switch/color-switch.tsx +++ b/lib/src/client/color-switch/color-switch.tsx @@ -58,4 +58,4 @@ export const ColorSwitch = ({ targetId, skipSystem, size, ...props }: ColorSwitc type="button" /> ); -} +}; diff --git a/lib/src/client/theme-switcher/theme-switcher.tsx b/lib/src/client/theme-switcher/theme-switcher.tsx index 0a2018ca..c21f1110 100644 --- a/lib/src/client/theme-switcher/theme-switcher.tsx +++ b/lib/src/client/theme-switcher/theme-switcher.tsx @@ -1,6 +1,6 @@ import type { SetStateAction } from "r18gs"; import type { ColorSchemePreference, ThemeState } from "../../constants"; -import { DEFAULT_ID, useRGSMinify } from "../../constants"; +import { DEFAULT_ID, useRGSMinify } from "../../constants"; import { useEffect } from "react"; const useEffectMinify = useEffect; export interface ThemeSwitcherProps { @@ -37,13 +37,17 @@ const parseState = (str?: string | null): Partial => { let tInit = 0; -const useLoadSyncedState = ( setThemeState: SetStateAction, dontSync?:boolean, targetId?:string ) => { +const useLoadSyncedState = ( + setThemeState: SetStateAction, + dontSync?: boolean, + targetId?: string, +) => { useEffectMinify(() => { if (dontSync) return; tInit = Date.now(); const key = targetId ?? DEFAULT_ID; setThemeState(state => ({ ...state, ...parseState(localStorage.getItem(key)) })); - const storageListener = (e: StorageEvent):void => { + const storageListener = (e: StorageEvent): void => { if (e.key === key) setThemeState(state => ({ ...state, ...parseState(e.newValue) })); }; addEventListener("storage", storageListener); @@ -80,7 +84,12 @@ const modifyTransition = (themeTransition = "none", targetId?: string) => { }; /** Apply classes to the targets */ -const applyClasses = ( targets: (HTMLElement | null)[], theme: string, resolvedColorScheme: "light" | "dark", styles?: Record) => { +const applyClasses = ( + targets: (HTMLElement | null)[], + theme: string, + resolvedColorScheme: "light" | "dark", + styles?: Record, +) => { let cls = ["dark", "light", `th-${theme}`, resolvedColorScheme]; if (styles) cls = cls.map(c => styles[c] ?? c); @@ -96,7 +105,12 @@ const applyClasses = ( targets: (HTMLElement | null)[], theme: string, resolvedC }; /** Update DOM */ -const updateDOM = (themeState: ThemeState, targetId?: string, dontSync?: boolean, styles?:Record) => { +const updateDOM = ( + themeState: ThemeState, + targetId?: string, + dontSync?: boolean, + styles?: Record, +) => { const { t: theme, c: csp, s: scs } = themeState; const resolvedColorScheme = csp === "system" ? scs : csp; const key = targetId ?? DEFAULT_ID; @@ -109,7 +123,7 @@ const updateDOM = (themeState: ThemeState, targetId?: string, dontSync?: boolean /** do not update documentElement for local targets */ const targets = targetId ? [target] : [target, documentMinify.documentElement]; - applyClasses( targets,theme, resolvedColorScheme, styles); + applyClasses(targets, theme, resolvedColorScheme, styles); if (shoulCreateCookie) documentMinify.cookie = `${key}=${theme},${resolvedColorScheme}; max-age=31536000; SameSite=Strict;`; @@ -130,12 +144,12 @@ export const ThemeSwitcher = ({ useMediaQuery(setThemeState); - useLoadSyncedState(setThemeState , dontSync, targetId); + useLoadSyncedState(setThemeState, dontSync, targetId); /** update DOM and storage */ useEffectMinify(() => { const restoreTransitions = modifyTransition(themeTransition, targetId); - updateDOM(themeState, targetId, dontSync, styles); + updateDOM(themeState, targetId, dontSync, styles); if (!dontSync && tInit < Date.now() - 300) { // save to localStorage const { t: theme, c: colorSchemePreference } = themeState; diff --git a/lib/src/constants.ts b/lib/src/constants.ts index f0b2661a..de2c7202 100644 --- a/lib/src/constants.ts +++ b/lib/src/constants.ts @@ -14,11 +14,12 @@ export interface ThemeState { t: string; } -const DEFAULT_THEME_STATE:ThemeState = { +const DEFAULT_THEME_STATE: ThemeState = { c: "system" as ColorSchemePreference, s: "light", t: "", }; /** To avoid multiple r18gs imports */ -export const useRGSMinify = (targetId?:string) => useRGS(targetId??DEFAULT_ID, DEFAULT_THEME_STATE); \ No newline at end of file +export const useRGSMinify = (targetId?: string) => + useRGS(targetId ?? DEFAULT_ID, DEFAULT_THEME_STATE); diff --git a/scripts/publish.js b/scripts/publish.js index 8ec0608a..c25a8de4 100644 --- a/scripts/publish.js +++ b/scripts/publish.js @@ -18,8 +18,8 @@ try { // no changesets to be applied } -const packageJSON = require("../lib/package.json"); -const { version: VERSION, name } = packageJSON; +const pkgJSON = require("../lib/package.json"); +const { version: VERSION, name } = pkgJSON; const LATEST_VERSION = execSync(`npm view ${name} version`).toString(); console.log({ VERSION, LATEST_VERSION }); @@ -36,33 +36,41 @@ if (!isPatch) { } /** Create release */ -execSync("cd lib && pnpm build && npm publish --provenance --access public"); - -/** Create GitHub release */ -execSync( - `gh release create ${VERSION} --generate-notes --latest -n "$(sed '1,/^## /d;/^## /,$d' CHANGELOG.md)" --title "Release v${VERSION}"`, -); +try { + execSync("cd lib && pnpm build && npm publish --provenance --access public"); + /** Create GitHub release */ + execSync( + `gh release create ${VERSION} --generate-notes --latest -n "$(sed '1,/^## /d;/^## /,$d' ./lib/CHANGELOG.md)" --title "Release v${VERSION}"`, + ); +} catch (e) { + console.error(e); +} // update canonicals -const publishCanonical = (canonical) => { - packageJSON.name = canonical; - fs.writeFileSync(pkgPath, JSON.stringify(packageJSON, null, 2)); +const canonicals = [`@mayank1513/${name}`, "nextjs-themes-ultra"]; +const pkgPath = path.join(__dirname, "../lib/package.json"); + +/** Publish canonical packages */ +const publishCanonical = canonical => { + pkgJSON.name = canonical; + fs.writeFileSync(pkgPath, JSON.stringify(pkgJSON, null, 2)); exec("cd lib && pnpm build && npm publish --provenance --access public"); -} +}; -const canonicals = [`@mayank1513/${name}`, 'nextjs-themes-ultra'] -const pkgPath = path.join(__dirname, "../lib/package.json"); canonicals.forEach(publishCanonical); -// lite version -packageJson.peerDependencies.r18gs = "^1"; -delete packageJson.dependencies; +pkgJSON.peerDependencies.r18gs = "^1"; +delete pkgJSON.dependencies; -const liteCanonicals = ['nthul-lite', '@mayank1513/nthul-lite', 'nextjs-themes-ultralite']; +const liteCanonicals = ["nthul-lite", "@mayank1513/nthul-lite", "nextjs-themes-ultralite"]; liteCanonicals.forEach(publishCanonical); -const toDeprecate = ['@mayank1513/nthul', '@mayank1513/nthul-lite'] +const toDeprecate = ["@mayank1513/nthul", "@mayank1513/nthul-lite"]; -toDeprecate.forEach(pkg => exec(`npm deprecate ${pkg} "Please use instead. We initially created scoped packages to have similarities with the GitHub Public Repository (which requires packages to be scoped). We are no longer using GPR and thus deprecating all scoped packages for which corresponding un-scoped packages exist.`)) +toDeprecate.forEach(pkg => + exec( + `npm deprecate ${pkg} "Please use instead. We initially created scoped packages to have similarities with the GitHub Public Repository (which requires packages to be scoped). We are no longer using GPR and thus deprecating all scoped packages for which corresponding un-scoped packages exist.`, + ), +); From c3d590e6c838494c78455d01e8195523eb9a1bf1 Mon Sep 17 00:00:00 2001 From: Mayank Kumar Chaudhari Date: Wed, 5 Jun 2024 19:45:39 +0530 Subject: [PATCH 2/2] trigger publish --- lib/package.json | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/lib/package.json b/lib/package.json index 3e8e9da3..45e08ae8 100644 --- a/lib/package.json +++ b/lib/package.json @@ -103,7 +103,6 @@ "API-routes", "dynamic-routing", "static-site-generation", - "PWA", - "SEO-friendly" + "PWA" ] }