-
-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathrelease.js
33 lines (24 loc) · 1.15 KB
/
release.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
import fs from 'fs';
import { execSync } from 'child_process';
// Get versioning argument from command line arguments and remove leading '--'
const versionType = process.argv[2]?.replace(/^--/, '') || 'patch';
// Validate versionType
const validVersionTypes = ['patch', 'minor', 'major'];
if (!validVersionTypes.includes(versionType)) {
console.error(`Invalid version type: ${versionType}. Valid types are: ${validVersionTypes.join(', ')}`);
process.exit(1);
}
execSync('yarn build', { stdio: 'inherit' });
// Run `yarn version` with the specified version type
execSync(`yarn version --${versionType}`, { stdio: 'inherit' });
// Read the updated version from package.json
const packageJson = JSON.parse(fs.readFileSync('package.json', 'utf-8'));
const newVersion = packageJson.version;
// Read module.json
const moduleJsonPath = 'module.json';
const moduleJson = JSON.parse(fs.readFileSync(moduleJsonPath, 'utf-8'));
// Update the version in module.json
moduleJson.version = newVersion;
// Write back the updated module.json
fs.writeFileSync(moduleJsonPath, JSON.stringify(moduleJson, null, 4), 'utf-8');
console.log(`Updated module.json to version ${newVersion}`);