From 451230e747736fc1b1ea8f7f95463138585f9c1d Mon Sep 17 00:00:00 2001 From: Lochie Axon Date: Wed, 19 Jul 2023 15:33:23 +1000 Subject: [PATCH] automatically update version number on build (#270) --- build.js | 18 ++++++++++++++++++ package.json | 2 +- packages/connectkit/package.json | 2 +- .../src/components/Common/Portal/index.tsx | 3 ++- packages/connectkit/src/index.ts | 7 +++---- 5 files changed, 25 insertions(+), 7 deletions(-) create mode 100644 build.js diff --git a/build.js b/build.js new file mode 100644 index 00000000..ae160a89 --- /dev/null +++ b/build.js @@ -0,0 +1,18 @@ +/* + * This script is used to copy over the version number in the package.json to + * the CONNECTKIT_VERSION constant in the index.ts file. This is done to + * ensure that the version number attribute on the ConnectKit wrapper is always + * up to date with the version number in the package.json file. + */ + +const fs = require('fs'); +const config = require('./packages/connectkit/package.json'); + +const file = fs.readFileSync('packages/connectkit/src/index.ts', 'utf8'); +const lines = file.split('\n'); +const versionLine = lines.findIndex((line) => + line.includes('export const CONNECTKIT_VERSION = ') +); +lines[versionLine] = `export const CONNECTKIT_VERSION = '${config.version}';`; + +fs.writeFileSync('packages/connectkit/src/index.ts', lines.join('\n'), 'utf8'); diff --git a/package.json b/package.json index d06058b9..b73ac48f 100644 --- a/package.json +++ b/package.json @@ -16,7 +16,7 @@ "dev:nextjs-siwe": "yarn workspace nextjs-siwe run dev", "dev:vite": "yarn workspace vite run dev", "dev:testbench": "yarn workspace testbench run dev", - "build": "yarn workspace connectkit run build && cp README.md packages/connectkit/README.md", + "build": "node build.js && yarn workspace connectkit run build && cp README.md packages/connectkit/README.md", "build:connectkit-next-siwe": "yarn workspace connectkit-next-siwe run build", "build:cra": "yarn build && yarn workspace cra build", "build:nextjs": "yarn build && yarn workspace nextjs build", diff --git a/packages/connectkit/package.json b/packages/connectkit/package.json index b161b77c..c035578f 100644 --- a/packages/connectkit/package.json +++ b/packages/connectkit/package.json @@ -1,6 +1,6 @@ { "name": "connectkit", - "version": "1.4.0", + "version": "1.5.0", "author": "Family", "homepage": "https://docs.family.co/connectkit", "license": "BSD-2-Clause license", diff --git a/packages/connectkit/src/components/Common/Portal/index.tsx b/packages/connectkit/src/components/Common/Portal/index.tsx index 4cc6e0d4..dbf8cc5c 100644 --- a/packages/connectkit/src/components/Common/Portal/index.tsx +++ b/packages/connectkit/src/components/Common/Portal/index.tsx @@ -1,5 +1,6 @@ import { useEffect, useState, useRef } from 'react'; import { createPortal } from 'react-dom'; +import { CONNECTKIT_VERSION } from '../../..'; const Portal = (props: any) => { props = { @@ -19,7 +20,7 @@ const Portal = (props: any) => { if (!ref.current) { const div = document.createElement('div'); div.setAttribute('id', selector); - div.setAttribute('data-connectkit', '1.4.0'); + div.setAttribute('data-connectkit', `${CONNECTKIT_VERSION}`); document.body.appendChild(div); ref.current = div; } diff --git a/packages/connectkit/src/index.ts b/packages/connectkit/src/index.ts index f71cc867..bd7d353c 100644 --- a/packages/connectkit/src/index.ts +++ b/packages/connectkit/src/index.ts @@ -1,3 +1,5 @@ +export const CONNECTKIT_VERSION = '1.5.0'; + export * as Types from './types'; export { default as getDefaultConfig } from './defaultConfig'; @@ -5,10 +7,7 @@ export { useModal } from './hooks/useModal'; export { SIWEProvider, useSIWE } from './siwe'; export type { SIWESession, SIWEConfig } from './siwe'; -export { - ConnectKitProvider, - Context, -} from './components/ConnectKit'; +export { ConnectKitProvider, Context } from './components/ConnectKit'; export { ConnectKitButton } from './components/ConnectButton'; export { default as SIWEButton } from './components/Standard/SIWE';