From 37c4da58f7e7c5d90b8f27ceae060c7e42e334e2 Mon Sep 17 00:00:00 2001 From: David Snelling Date: Mon, 23 Jun 2025 10:58:48 -0700 Subject: [PATCH] **refactor: consolidate folder structure and improve compatibility** MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ### Changes: - **rollup.config.js**: - Merged and reformatted `nodeBuiltins` definition for cleaner code. - Updated `input` path from `examples/browser_compatible_exports.ts` to `demo/browser_compatible_exports.ts`. - Reformatted `replace` plugin configuration for better readability. - **.github/workflows/deploy-demo.yml**: - Updated deployment folder from `examples` to `demo`. - **Renamed**: - `examples/browser_compatible_exports.ts` → `demo/browser_compatible_exports.ts`. - **scripts/generate-version.js**: - Removed unnecessary semicolons for consistent formatting. ### Purpose: Aligned folder structure by migrating from `examples` to `demo` for uniformity and better organization. Improved code readability and formatting across configurations and scripts. --- .github/workflows/deploy-demo.yml | 2 +- .../browser_compatible_exports.ts | 0 rollup.config.js | 23 ++++------ scripts/generate-version.js | 46 +++++++++---------- 4 files changed, 34 insertions(+), 37 deletions(-) rename {examples => demo}/browser_compatible_exports.ts (100%) diff --git a/.github/workflows/deploy-demo.yml b/.github/workflows/deploy-demo.yml index 25b4889e..10b4e5ed 100644 --- a/.github/workflows/deploy-demo.yml +++ b/.github/workflows/deploy-demo.yml @@ -31,6 +31,6 @@ jobs: - name: Deploy to GitHub Pages 🚀 uses: JamesIves/github-pages-deploy-action@v4 with: - folder: examples + folder: demo branch: gh-pages token: ${{ secrets.GITHUB_TOKEN }} diff --git a/examples/browser_compatible_exports.ts b/demo/browser_compatible_exports.ts similarity index 100% rename from examples/browser_compatible_exports.ts rename to demo/browser_compatible_exports.ts diff --git a/rollup.config.js b/rollup.config.js index 7f0b8542..af13a984 100644 --- a/rollup.config.js +++ b/rollup.config.js @@ -11,12 +11,7 @@ const nodeModuleShims = () => { name: 'node-module-shims', resolveId(source) { // List of Node.js built-in modules to shim - const nodeBuiltins = [ - 'fs', - 'path', - 'util', - 'child_process' - ] + const nodeBuiltins = ['fs', 'path', 'util', 'child_process'] if (nodeBuiltins.includes(source)) { // Return a virtual module ID for the shim @@ -99,7 +94,7 @@ globalThis.__ENV__ = { ` }, browser: { - input: 'examples/browser_compatible_exports.ts', + input: 'demo/browser_compatible_exports.ts', outputPrefix: 'brainy', tsconfig: './tsconfig.browser.json', declaration: false, @@ -135,12 +130,14 @@ export default { ], plugins: [ // Add environment replacement for unified build - ...(buildType === 'unified' ? [ - replace({ - preventAssignment: true, - 'process.env.NODE_ENV': JSON.stringify('production') - }) - ] : []), + ...(buildType === 'unified' + ? [ + replace({ + preventAssignment: true, + 'process.env.NODE_ENV': JSON.stringify('production') + }) + ] + : []), // Add our custom plugins fixThisReferences(), nodeModuleShims(), diff --git a/scripts/generate-version.js b/scripts/generate-version.js index 2b3a3767..2a462529 100755 --- a/scripts/generate-version.js +++ b/scripts/generate-version.js @@ -2,44 +2,44 @@ /** * Generate Version Script - * + * * This script generates a version.js file that exports the version from package.json. * This allows the CLI to access the version without having to read package.json directly, * which can be problematic when the package is installed globally. - * + * * It also updates the version in the README.md file to ensure it stays in sync with package.json. */ -import fs from 'fs'; -import path from 'path'; -import { fileURLToPath } from 'url'; +import fs from 'fs' +import path from 'path' +import { fileURLToPath } from 'url' // Get the directory of the current module -const __filename = fileURLToPath(import.meta.url); -const __dirname = path.dirname(__filename); +const __filename = fileURLToPath(import.meta.url) +const __dirname = path.dirname(__filename) // Path to the root directory -const rootDir = path.join(__dirname, '..'); +const rootDir = path.join(__dirname, '..') // Path to package.json -const packageJsonPath = path.join(rootDir, 'package.json'); +const packageJsonPath = path.join(rootDir, 'package.json') // Path to the output directory -const outputDir = path.join(rootDir, 'src', 'utils'); +const outputDir = path.join(rootDir, 'src', 'utils') // Path to the output file -const outputFile = path.join(outputDir, 'version.ts'); +const outputFile = path.join(outputDir, 'version.ts') // Path to README.md -const readmePath = path.join(rootDir, 'README.md'); +const readmePath = path.join(rootDir, 'README.md') // Read package.json -const packageJson = JSON.parse(fs.readFileSync(packageJsonPath, 'utf8')); -const version = packageJson.version; +const packageJson = JSON.parse(fs.readFileSync(packageJsonPath, 'utf8')) +const version = packageJson.version // Create the output directory if it doesn't exist if (!fs.existsSync(outputDir)) { - fs.mkdirSync(outputDir, { recursive: true }); + fs.mkdirSync(outputDir, { recursive: true }) } // Generate the version.ts file @@ -49,26 +49,26 @@ const content = `/** */ export const VERSION = '${version}'; -`; +` // Write the file -fs.writeFileSync(outputFile, content); +fs.writeFileSync(outputFile, content) -console.log(`Generated version.ts with version ${version}`); +console.log(`Generated version.ts with version ${version}`) // Update README.md with the current version try { - let readmeContent = fs.readFileSync(readmePath, 'utf8'); + let readmeContent = fs.readFileSync(readmePath, 'utf8') // Replace the version in the badge URL const updatedReadme = readmeContent.replace( /\[\!\[Version\]\(https:\/\/img\.shields\.io\/badge\/version-[0-9]+\.[0-9]+\.[0-9]+-blue\.svg\)\]/g, `[![Version](https://img.shields.io/badge/version-${version}-blue.svg)]` - ); + ) // Write the updated README back to disk - fs.writeFileSync(readmePath, updatedReadme); - console.log(`Updated README.md with version ${version}`); + fs.writeFileSync(readmePath, updatedReadme) + console.log(`Updated README.md with version ${version}`) } catch (error) { - console.error('Error updating README.md:', error); + console.error('Error updating README.md:', error) }