**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 🚀
|
- name: Deploy to GitHub Pages 🚀
|
||||||
uses: JamesIves/github-pages-deploy-action@v4
|
uses: JamesIves/github-pages-deploy-action@v4
|
||||||
with:
|
with:
|
||||||
folder: examples
|
folder: demo
|
||||||
branch: gh-pages
|
branch: gh-pages
|
||||||
token: ${{ secrets.GITHUB_TOKEN }}
|
token: ${{ secrets.GITHUB_TOKEN }}
|
||||||
|
|
|
||||||
|
|
@ -11,12 +11,7 @@ const nodeModuleShims = () => {
|
||||||
name: 'node-module-shims',
|
name: 'node-module-shims',
|
||||||
resolveId(source) {
|
resolveId(source) {
|
||||||
// List of Node.js built-in modules to shim
|
// List of Node.js built-in modules to shim
|
||||||
const nodeBuiltins = [
|
const nodeBuiltins = ['fs', 'path', 'util', 'child_process']
|
||||||
'fs',
|
|
||||||
'path',
|
|
||||||
'util',
|
|
||||||
'child_process'
|
|
||||||
]
|
|
||||||
|
|
||||||
if (nodeBuiltins.includes(source)) {
|
if (nodeBuiltins.includes(source)) {
|
||||||
// Return a virtual module ID for the shim
|
// Return a virtual module ID for the shim
|
||||||
|
|
@ -99,7 +94,7 @@ globalThis.__ENV__ = {
|
||||||
`
|
`
|
||||||
},
|
},
|
||||||
browser: {
|
browser: {
|
||||||
input: 'examples/browser_compatible_exports.ts',
|
input: 'demo/browser_compatible_exports.ts',
|
||||||
outputPrefix: 'brainy',
|
outputPrefix: 'brainy',
|
||||||
tsconfig: './tsconfig.browser.json',
|
tsconfig: './tsconfig.browser.json',
|
||||||
declaration: false,
|
declaration: false,
|
||||||
|
|
@ -135,12 +130,14 @@ export default {
|
||||||
],
|
],
|
||||||
plugins: [
|
plugins: [
|
||||||
// Add environment replacement for unified build
|
// Add environment replacement for unified build
|
||||||
...(buildType === 'unified' ? [
|
...(buildType === 'unified'
|
||||||
replace({
|
? [
|
||||||
preventAssignment: true,
|
replace({
|
||||||
'process.env.NODE_ENV': JSON.stringify('production')
|
preventAssignment: true,
|
||||||
})
|
'process.env.NODE_ENV': JSON.stringify('production')
|
||||||
] : []),
|
})
|
||||||
|
]
|
||||||
|
: []),
|
||||||
// Add our custom plugins
|
// Add our custom plugins
|
||||||
fixThisReferences(),
|
fixThisReferences(),
|
||||||
nodeModuleShims(),
|
nodeModuleShims(),
|
||||||
|
|
|
||||||
|
|
@ -2,44 +2,44 @@
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Generate Version Script
|
* Generate Version Script
|
||||||
*
|
*
|
||||||
* This script generates a version.js file that exports the version from package.json.
|
* 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,
|
* 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.
|
* 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.
|
* It also updates the version in the README.md file to ensure it stays in sync with package.json.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import fs from 'fs';
|
import fs from 'fs'
|
||||||
import path from 'path';
|
import path from 'path'
|
||||||
import { fileURLToPath } from 'url';
|
import { fileURLToPath } from 'url'
|
||||||
|
|
||||||
// Get the directory of the current module
|
// Get the directory of the current module
|
||||||
const __filename = fileURLToPath(import.meta.url);
|
const __filename = fileURLToPath(import.meta.url)
|
||||||
const __dirname = path.dirname(__filename);
|
const __dirname = path.dirname(__filename)
|
||||||
|
|
||||||
// Path to the root directory
|
// Path to the root directory
|
||||||
const rootDir = path.join(__dirname, '..');
|
const rootDir = path.join(__dirname, '..')
|
||||||
|
|
||||||
// Path to package.json
|
// Path to package.json
|
||||||
const packageJsonPath = path.join(rootDir, 'package.json');
|
const packageJsonPath = path.join(rootDir, 'package.json')
|
||||||
|
|
||||||
// Path to the output directory
|
// Path to the output directory
|
||||||
const outputDir = path.join(rootDir, 'src', 'utils');
|
const outputDir = path.join(rootDir, 'src', 'utils')
|
||||||
|
|
||||||
// Path to the output file
|
// Path to the output file
|
||||||
const outputFile = path.join(outputDir, 'version.ts');
|
const outputFile = path.join(outputDir, 'version.ts')
|
||||||
|
|
||||||
// Path to README.md
|
// Path to README.md
|
||||||
const readmePath = path.join(rootDir, 'README.md');
|
const readmePath = path.join(rootDir, 'README.md')
|
||||||
|
|
||||||
// Read package.json
|
// Read package.json
|
||||||
const packageJson = JSON.parse(fs.readFileSync(packageJsonPath, 'utf8'));
|
const packageJson = JSON.parse(fs.readFileSync(packageJsonPath, 'utf8'))
|
||||||
const version = packageJson.version;
|
const version = packageJson.version
|
||||||
|
|
||||||
// Create the output directory if it doesn't exist
|
// Create the output directory if it doesn't exist
|
||||||
if (!fs.existsSync(outputDir)) {
|
if (!fs.existsSync(outputDir)) {
|
||||||
fs.mkdirSync(outputDir, { recursive: true });
|
fs.mkdirSync(outputDir, { recursive: true })
|
||||||
}
|
}
|
||||||
|
|
||||||
// Generate the version.ts file
|
// Generate the version.ts file
|
||||||
|
|
@ -49,26 +49,26 @@ const content = `/**
|
||||||
*/
|
*/
|
||||||
|
|
||||||
export const VERSION = '${version}';
|
export const VERSION = '${version}';
|
||||||
`;
|
`
|
||||||
|
|
||||||
// Write the file
|
// 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
|
// Update README.md with the current version
|
||||||
try {
|
try {
|
||||||
let readmeContent = fs.readFileSync(readmePath, 'utf8');
|
let readmeContent = fs.readFileSync(readmePath, 'utf8')
|
||||||
|
|
||||||
// Replace the version in the badge URL
|
// Replace the version in the badge URL
|
||||||
const updatedReadme = readmeContent.replace(
|
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-[0-9]+\.[0-9]+\.[0-9]+-blue\.svg\)\]/g,
|
||||||
`[]`
|
`[]`
|
||||||
);
|
)
|
||||||
|
|
||||||
// Write the updated README back to disk
|
// Write the updated README back to disk
|
||||||
fs.writeFileSync(readmePath, updatedReadme);
|
fs.writeFileSync(readmePath, updatedReadme)
|
||||||
console.log(`Updated README.md with version ${version}`);
|
console.log(`Updated README.md with version ${version}`)
|
||||||
} catch (error) {
|
} 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