feat: add version generation script and auto-generated version.ts file
Introduced a script to generate a `version.ts` file exporting the package version from `package.json`. This simplifies accessing version data in the CLI, especially for global installations. Included auto-generated `version.ts` in the project structure.
This commit is contained in:
parent
e2f65c8146
commit
430ba65f41
2 changed files with 57 additions and 0 deletions
51
scripts/generate-version.js
Executable file
51
scripts/generate-version.js
Executable file
|
|
@ -0,0 +1,51 @@
|
||||||
|
#!/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.
|
||||||
|
*/
|
||||||
|
|
||||||
|
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');
|
||||||
|
|
||||||
|
// Read package.json
|
||||||
|
const packageJson = JSON.parse(fs.readFileSync(packageJsonPath, 'utf8'));
|
||||||
|
|
||||||
|
// 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 = '${packageJson.version}';
|
||||||
|
`;
|
||||||
|
|
||||||
|
// Write the file
|
||||||
|
fs.writeFileSync(outputFile, content);
|
||||||
|
|
||||||
|
console.log(`Generated version.ts with version ${packageJson.version}`);
|
||||||
6
src/utils/version.ts
Normal file
6
src/utils/version.ts
Normal file
|
|
@ -0,0 +1,6 @@
|
||||||
|
/**
|
||||||
|
* This file is auto-generated during the build process.
|
||||||
|
* Do not modify this file directly.
|
||||||
|
*/
|
||||||
|
|
||||||
|
export const VERSION = '0.7.1';
|
||||||
Loading…
Add table
Add a link
Reference in a new issue