Skip to content

Commit

Permalink
fix: versioning script now updates package.json (#551)
Browse files Browse the repository at this point in the history
* fix: npm run version upgrades root package.json
also resets minor and patch versions to zero for higher-level upgrades

Co-authored-by: Eric Swanson <64809312+ericswanson-dfinity@users.noreply.github.com>
  • Loading branch information
krpeacock and ericswanson-dfinity committed Apr 1, 2022
1 parent d1b5e24 commit 1bf5ac3
Show file tree
Hide file tree
Showing 4 changed files with 117 additions and 379 deletions.
21 changes: 8 additions & 13 deletions bin/version.ts
Expand Up @@ -34,8 +34,11 @@ const newVersion = (() => {
patch = Number(patch) + 1;
} else if (argv._.includes('minor')) {
minor = Number(minor) + 1;
patch = 0;
} else if (argv._.includes('major')) {
major = Number(major) + 1;
minor = 0;
patch = 0;
} else {
// else use the first argument
return argv._[0].toString();
Expand All @@ -53,8 +56,12 @@ const packages = workspaces
.filter(workspace => workspace.includes('packages'))
.map(packagePath => packagePath.replace('packages', '@dfinity'));

// Update version in root package.json
workspaces.push('.');

workspaces.forEach(async workspace => {
const packagePath = path.resolve(__dirname, '..', workspace, 'package.json');
console.log(packagePath);
const json = JSON.parse(fs.readFileSync(packagePath).toString());

// Set version for package
Expand All @@ -74,6 +81,7 @@ workspaces.forEach(async workspace => {
// Write file
fs.writeFileSync(packagePath, JSON.stringify(json));
});

function updateDeps(dependencies: Record<string, string>) {
for (const dep in dependencies) {
if (Object.prototype.hasOwnProperty.call(dependencies, dep)) {
Expand All @@ -84,16 +92,3 @@ function updateDeps(dependencies: Record<string, string>) {
}
return dependencies;
}
// Update version in root package.json
fs.writeFileSync(path.resolve(__dirname, '..', 'package.json'), JSON.stringify(rootPackage));

// Prettier format the modified package.json files
exec(`npm run prettier:format`, error => {
if (error) {
throw new Error(JSON.stringify(error));
}

// wrap up
console.log('success!');
console.timeEnd('script duration');
});
4 changes: 4 additions & 0 deletions docs/generated/changelog.html
Expand Up @@ -23,6 +23,10 @@ <h2>Version 0.10.5</h2>
Readme for more details
</li>
<li>Reduces the maxTimeToLive default setting from 24 hours to 8</li>
<li>
Versioning tool now sets patch version to 0 for minor version updates, or patch and minor
versions to 0 for major version updates
</li>
</ul>
<h2>Version 0.10.3</h2>
<ul>
Expand Down

0 comments on commit 1bf5ac3

Please sign in to comment.