**refactor: consolidate folder structure and improve compatibility**
### 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.
This commit is contained in:
parent
151aeb1e87
commit
37c4da58f7
4 changed files with 34 additions and 37 deletions
2
.github/workflows/deploy-demo.yml
vendored
2
.github/workflows/deploy-demo.yml
vendored
|
|
@ -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 }}
|
||||
|
|
|
|||
|
|
@ -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(),
|
||||
|
|
|
|||
|
|
@ -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,
|
||||
`[]`
|
||||
);
|
||||
)
|
||||
|
||||
// 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)
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue