Initial commit
This commit is contained in:
commit
5a8a6c1ba3
81 changed files with 39269 additions and 0 deletions
47
scripts/encode-image.js
Normal file
47
scripts/encode-image.js
Normal file
|
|
@ -0,0 +1,47 @@
|
|||
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);
|
||||
|
||||
// Path to the image file
|
||||
const imagePath = path.join(__dirname, '..', 'brainy.png');
|
||||
|
||||
// Read the image file
|
||||
const imageBuffer = fs.readFileSync(imagePath);
|
||||
|
||||
// Convert the image to base64
|
||||
const base64Image = imageBuffer.toString('base64');
|
||||
|
||||
// Get the MIME type based on file extension
|
||||
const getMimeType = (filePath) => {
|
||||
const ext = path.extname(filePath).toLowerCase();
|
||||
switch (ext) {
|
||||
case '.png':
|
||||
return 'image/png';
|
||||
case '.jpg':
|
||||
case '.jpeg':
|
||||
return 'image/jpeg';
|
||||
case '.gif':
|
||||
return 'image/gif';
|
||||
case '.svg':
|
||||
return 'image/svg+xml';
|
||||
default:
|
||||
return 'application/octet-stream';
|
||||
}
|
||||
};
|
||||
|
||||
const mimeType = getMimeType(imagePath);
|
||||
|
||||
// Create the data URL
|
||||
const dataUrl = `data:${mimeType};base64,${base64Image}`;
|
||||
|
||||
// Output the complete HTML img tag
|
||||
const imgTag = `<img src="${dataUrl}" alt="Brainy Logo" width="200"/>`;
|
||||
|
||||
// Write to a file instead of console.log to avoid truncation
|
||||
fs.writeFileSync(path.join(__dirname, '..', 'encoded-image.html'), imgTag);
|
||||
|
||||
console.log('Base64 encoded image has been saved to encoded-image.html');
|
||||
107
scripts/generate-version.js
Executable file
107
scripts/generate-version.js
Executable file
|
|
@ -0,0 +1,107 @@
|
|||
#!/usr/bin/env node
|
||||
|
||||
/**
|
||||
* 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'
|
||||
|
||||
// Get the directory of the current module
|
||||
const __filename = fileURLToPath(import.meta.url)
|
||||
const __dirname = path.dirname(__filename)
|
||||
|
||||
// Path to the root directory
|
||||
const rootDir = path.join(__dirname, '..')
|
||||
|
||||
// Path to package.json
|
||||
const packageJsonPath = path.join(rootDir, 'package.json')
|
||||
|
||||
// Path to the output directory
|
||||
const outputDir = path.join(rootDir, 'src', 'utils')
|
||||
|
||||
// Path to the output file
|
||||
const outputFile = path.join(outputDir, 'version.ts')
|
||||
|
||||
// Path to README.md
|
||||
const readmePath = path.join(rootDir, 'README.md')
|
||||
|
||||
// Read package.json
|
||||
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 })
|
||||
}
|
||||
|
||||
// Generate the version.ts file
|
||||
const content = `/**
|
||||
* This file is auto-generated during the build process.
|
||||
* Do not modify this file directly.
|
||||
*/
|
||||
|
||||
export const VERSION = '${version}';
|
||||
`
|
||||
|
||||
// Write the file
|
||||
fs.writeFileSync(outputFile, content)
|
||||
|
||||
console.log(`Generated version.ts with version ${version}`)
|
||||
|
||||
// Update README.md with the current version, Node.js version, and TypeScript version
|
||||
try {
|
||||
let readmeContent = fs.readFileSync(readmePath, 'utf8')
|
||||
|
||||
// Get Node.js version requirement from package.json
|
||||
const nodeVersion = packageJson.engines.node.replace('>=', '')
|
||||
|
||||
// Get TypeScript version from package.json devDependencies
|
||||
const typescriptVersion = packageJson.devDependencies.typescript.replace('^', '')
|
||||
|
||||
// Update npm badge - using a more flexible approach with explicit version
|
||||
const npmBadgeRegex = /\[\!\[npm\].*?\]\(https:\/\/www\.npmjs\.com\/package\/@soulcraft\/brainy\)/g
|
||||
if (npmBadgeRegex.test(readmeContent)) {
|
||||
readmeContent = readmeContent.replace(
|
||||
npmBadgeRegex,
|
||||
`[](https://www.npmjs.com/package/@soulcraft/brainy)`
|
||||
)
|
||||
} else {
|
||||
console.log('Warning: Could not find npm badge in README.md')
|
||||
}
|
||||
|
||||
// Update Node.js badge - using a more flexible approach
|
||||
const nodeBadgeRegex = /\[\!\[Node\.js\].*?\]\(https:\/\/nodejs\.org\/\)/g
|
||||
if (nodeBadgeRegex.test(readmeContent)) {
|
||||
readmeContent = readmeContent.replace(
|
||||
nodeBadgeRegex,
|
||||
`[](https://nodejs.org/)`
|
||||
)
|
||||
} else {
|
||||
console.log('Warning: Could not find Node.js badge in README.md')
|
||||
}
|
||||
|
||||
// Update TypeScript badge - using a more flexible approach
|
||||
const tsBadgeRegex = /\[\!\[TypeScript\].*?\]\(https:\/\/www\.typescriptlang\.org\/\)/g
|
||||
if (tsBadgeRegex.test(readmeContent)) {
|
||||
readmeContent = readmeContent.replace(
|
||||
tsBadgeRegex,
|
||||
`[](https://www.typescriptlang.org/)`
|
||||
)
|
||||
} else {
|
||||
console.log('Warning: Could not find TypeScript badge in README.md')
|
||||
}
|
||||
|
||||
// Write the updated README back to disk
|
||||
fs.writeFileSync(readmePath, readmeContent)
|
||||
console.log(`Updated README.md with npm version ${version}, Node.js version ${nodeVersion}, and TypeScript version ${typescriptVersion}`)
|
||||
} catch (error) {
|
||||
console.error('Error updating README.md:', error)
|
||||
}
|
||||
26
scripts/update-readme.js
Normal file
26
scripts/update-readme.js
Normal file
|
|
@ -0,0 +1,26 @@
|
|||
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);
|
||||
|
||||
// Paths to the files
|
||||
const readmePath = path.join(__dirname, '..', 'README.md');
|
||||
const encodedImagePath = path.join(__dirname, '..', 'encoded-image.html');
|
||||
|
||||
// Read the files
|
||||
const readmeContent = fs.readFileSync(readmePath, 'utf8');
|
||||
const encodedImageTag = fs.readFileSync(encodedImagePath, 'utf8');
|
||||
|
||||
// Replace the image tag in the README
|
||||
const updatedReadme = readmeContent.replace(
|
||||
/<img src="brainy\.png" alt="Brainy Logo" width="200"\/>/,
|
||||
encodedImageTag
|
||||
);
|
||||
|
||||
// Write the updated README
|
||||
fs.writeFileSync(readmePath, updatedReadme);
|
||||
|
||||
console.log('README.md has been updated with the base64-encoded image.');
|
||||
Loading…
Add table
Add a link
Reference in a new issue