Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions test/version.test.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
import { version as manifestVersion, minAppVersion as manifestMinAppVersion } from '../manifest.json';
import { version as packageVersion } from '../package.json';
import { version as packageLockVersion } from '../package.json';
import versions from '../versions.json';

test('Versions matching', () => {
expect(manifestVersion).toBe(packageVersion);
expect(manifestVersion).toBe(packageLockVersion);
expect(Object.keys(versions).find(value => value === manifestVersion)).toBe(manifestVersion);
expect(Object.entries(versions).find(value => value[0] === manifestVersion)?.[1]).toBe(manifestMinAppVersion);
});
40 changes: 24 additions & 16 deletions version-change.mjs
Original file line number Diff line number Diff line change
@@ -1,45 +1,53 @@
import { readFileSync, writeFileSync } from "fs";
import { valid } from "semver";
import { execSync } from 'child_process';
import { readFileSync, writeFileSync } from 'fs';
import { valid } from 'semver';

const newVersion = process.argv.find(value => value.startsWith('--new_version'));
if (!newVersion) {
throw Error('Param --new_version is missing!');
throw Error('Param --new_version is missing!');
}
const targetVersion = newVersion.split('=')[1];
if (!targetVersion) {
throw Error('Param --new_version is empty!');
throw Error('Param --new_version is empty!');
}
if (!valid(targetVersion)) {
throw Error('New version is invalid!')
throw Error('New version is invalid!')
}

// read minAppVersion from manifest.json
let manifestFile = JSON.parse(readFileSync("manifest.json", "utf8"));
let manifestFile = JSON.parse(readFileSync('manifest.json', 'utf8'));
const { minAppVersion } = manifestFile;
if (!minAppVersion || minAppVersion === "") {
throw Error('Missing minAppVersion in "manifest.json"');
if (!minAppVersion || minAppVersion === '') {
throw Error(`Missing minAppVersion in 'manifest.json'`);
}

// update version to target version
manifestFile.version = targetVersion;
writeFileSync("manifest.json", JSON.stringify(manifestFile, null, "\t"));
writeFileSync('manifest.json', JSON.stringify(manifestFile, null, '\t'));

// update version in package
let packageFile = JSON.parse(readFileSync("package.json", "utf8"));
let packageFile = JSON.parse(readFileSync('package.json', 'utf8'));
packageFile.version = targetVersion;
writeFileSync("package.json", JSON.stringify(packageFile, null, "\t"));
writeFileSync('package.json', JSON.stringify(packageFile, null, '\t'));

// update version in package-lock
try {
execSync('npm install', { stdio: 'inherit' });
} catch (error) {
throw Error('npm installed failed: ' + error);
}

// read versions file
let versionsFile = JSON.parse(readFileSync("versions.json", "utf8"));
let versionsFile = JSON.parse(readFileSync('versions.json', 'utf8'));
let keys = Object.keys(versionsFile);

// remove existing versions with same minAppVersion
keys.forEach(key => {
if (minAppVersion === versionsFile[key]) {
delete versionsFile[key];
}
if (minAppVersion === versionsFile[key]) {
delete versionsFile[key];
}
});

// update versions.json with target version and minAppVersion from manifest.json
versionsFile[targetVersion] = minAppVersion;
writeFileSync("versions.json", JSON.stringify(versionsFile, null, "\t"));
writeFileSync('versions.json', JSON.stringify(versionsFile, null, '\t'));
Loading