Skip to content

Commit c8900e8

Browse files
committed
feat: declare version * 6
1 parent c22d0e9 commit c8900e8

File tree

2 files changed

+35
-1
lines changed

2 files changed

+35
-1
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
],
2222
"scripts": {
2323
"start": "pnpm storybook",
24-
"build": "npm-run-all clear:dist -p build:* && node ./scripts/copy-files.js && node scripts/add-banner.js && node -e \"const { version } = require('./package.json'); require('child_process').execSync('find dist -name \\\"*.js\\\" -exec sed -i \\\"\\\" \\\"s/__UIKIT_VERSION__/\\\\\\\"' + version + '\\\\\\\"/g\\\" {} +');\"",
24+
"build": "npm-run-all clear:dist -p build:* && node ./scripts/copy-files.js && node scripts/add-banner.js && node scripts/replace-version.js",
2525
"build:esm": "tsc -p tsconfig.es.json",
2626
"build:cjs": "tsc -p tsconfig.cjs.json",
2727
"watch": "pnpm build:esm --watch",

scripts/replace-version.js

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
const fs = require('fs');
2+
const path = require('path');
3+
4+
console.log('Replacing version in compiled files...');
5+
6+
// Read package.json and extract the version
7+
const packageJsonPath = path.resolve(__dirname, '../package.json');
8+
const packageJson = JSON.parse(fs.readFileSync(packageJsonPath, 'utf8'));
9+
const version = packageJson.version;
10+
11+
// Define the directory where compiled files are located
12+
const distDir = path.resolve(__dirname, '../dist');
13+
14+
// Function to replace version in all .js files in the dist directory
15+
function replaceVersionInFiles(dir) {
16+
const files = fs.readdirSync(dir);
17+
18+
files.forEach((file) => {
19+
const filePath = path.join(dir, file);
20+
const stat = fs.statSync(filePath);
21+
22+
if (stat.isDirectory()) {
23+
replaceVersionInFiles(filePath); // Recurse into subdirectories
24+
} else if (file.endsWith('.js')) {
25+
let content = fs.readFileSync(filePath, 'utf8');
26+
// Replace placeholder with version, wrapped in quotes
27+
content = content.replace(/__UIKIT_VERSION__/g, `${version}`);
28+
fs.writeFileSync(filePath, content);
29+
}
30+
});
31+
}
32+
33+
// Execute the replacement
34+
replaceVersionInFiles(distDir);

0 commit comments

Comments
 (0)