Skip to content

Commit

Permalink
Tweak version script (#233)
Browse files Browse the repository at this point in the history
* Update scripts

* Update script

* Updated version to 0.10.0 for UpscalerJS, Examples and Root

* Updated version to 0.11.0 for UpscalerJS, Examples and Root

* Finalize script

* Update changelog
  • Loading branch information
thekevinscott authored Mar 2, 2022
1 parent d12f102 commit 2c6c89f
Show file tree
Hide file tree
Showing 19 changed files with 87 additions and 38 deletions.
2 changes: 1 addition & 1 deletion examples/basic/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "basic",
"version": "0.10.0",
"version": "0.11.0",
"description": "Demonstration of basic usage of UpscalerJS",
"main": "index.js",
"scripts": {
Expand Down
2 changes: 1 addition & 1 deletion examples/comparisons/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "comparisons",
"version": "0.10.0",
"version": "0.11.0",
"description": "Demonstration of the different models of UpscalerJS",
"main": "index.js",
"scripts": {
Expand Down
2 changes: 1 addition & 1 deletion examples/models/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,5 +28,5 @@
"last 1 safari version"
]
},
"version": "0.10.0"
"version": "0.11.0"
}
2 changes: 1 addition & 1 deletion examples/nodejs-custom-model/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "nodejs-custom-model",
"version": "0.10.0",
"version": "0.11.0",
"description": "Demonstration of Node.js usage of UpscalerJS with a local custom model",
"author": "Kevin Scott",
"license": "MIT",
Expand Down
2 changes: 1 addition & 1 deletion examples/nodejs/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "nodejs",
"version": "0.10.0",
"version": "0.11.0",
"description": "Demonstration of Node.js usage of UpscalerJS",
"author": "Kevin Scott",
"license": "MIT",
Expand Down
2 changes: 1 addition & 1 deletion examples/patch-sizes/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,5 +30,5 @@
"last 1 safari version"
]
},
"version": "0.10.0"
"version": "0.11.0"
}
2 changes: 1 addition & 1 deletion examples/progress/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "progress",
"version": "0.10.0",
"version": "0.11.0",
"description": "Demonstration of upscale progress with UpscalerJS",
"main": "index.js",
"scripts": {
Expand Down
2 changes: 1 addition & 1 deletion examples/react-demo/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,5 +29,5 @@
"last 1 safari version"
]
},
"version": "0.10.0"
"version": "0.11.0"
}
2 changes: 1 addition & 1 deletion examples/tensor/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "tensor",
"version": "0.10.0",
"version": "0.11.0",
"description": "Demonstration of basic usage of UpscalerJS",
"main": "index.js",
"scripts": {
Expand Down
2 changes: 1 addition & 1 deletion examples/upload/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "upload",
"version": "0.10.0",
"version": "0.11.0",
"description": "Demonstration of uploading an image to UpscalerJS",
"main": "index.js",
"scripts": {
Expand Down
2 changes: 1 addition & 1 deletion examples/warmup/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "warmup",
"version": "0.10.0",
"version": "0.11.0",
"description": "Demonstration of warming up UpscalerJS",
"main": "index.js",
"scripts": {
Expand Down
2 changes: 1 addition & 1 deletion examples/webcam/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "webcam",
"version": "0.10.0",
"version": "0.11.0",
"description": "Demonstration of webcam usage of UpscalerJS",
"main": "index.js",
"scripts": {
Expand Down
2 changes: 1 addition & 1 deletion examples/webworker/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "webworker",
"version": "0.10.0",
"version": "0.11.0",
"description": "Demonstration of webworker integration with UpscalerJS",
"main": "index.js",
"scripts": {
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"version": "0.10.0",
"version": "0.11.0",
"private": true,
"workspaces": [
"packages/*",
Expand Down
2 changes: 1 addition & 1 deletion packages/models/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@upscalerjs/models",
"version": "0.9.0",
"version": "0.10.0",
"description": "Neural Network Models for upscalerjs",
"keywords": [
"image super resolution",
Expand Down
4 changes: 4 additions & 0 deletions packages/upscalerjs/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@
All notable changes to this project will be documented in this file.
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.

## [0.11.0](https://github.com/thekevinscott/UpscalerJS/compare/v0.11.0...v0.10.0) (2021-03-2)

feat: Add support for `progress` callback to receive a second argument, the current slice of procesed image

## [0.10.0](https://github.com/thekevinscott/UpscalerJS/compare/v0.10.0...v0.9.0) (2021-02-25)

feat: Add Node support
Expand Down
2 changes: 1 addition & 1 deletion packages/upscalerjs/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "upscaler",
"version": "0.10.0",
"version": "0.11.0",
"description": "Increase Image resolution with Tensorflow.js",
"exports": {
"./node": "./dist/node/cjs/cjs.js",
Expand Down
75 changes: 53 additions & 22 deletions scripts/package-scripts/update-version.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,10 @@ import path from 'path';
import inquirer from 'inquirer';
import findAllPackages from './find-all-packages';
import isValidVersion from './utils/isValidVersion';
import execute from './utils/execute';

type Package = 'UpscalerJS' | 'Models' | 'Examples' | 'Root';
type Answers = { packages: Array<Package>, version: string}
type Answers = { packages: Array<Package>, version: string, commit: boolean }

const ROOT_DIR = path.resolve(__dirname, '../..');
const PACKAGES_DIR = path.resolve(ROOT_DIR, 'packages');
Expand All @@ -17,37 +18,44 @@ const getFormattedName = (file: string) => {
return file.split(`${ROOT_DIR}/`).pop();
};

const updateMultiplePackages = (dir: string, version: string) => {
const updateMultiplePackages = async (dir: string, version: string, commit: boolean) => {
const packages = findAllPackages(dir);
for (let i = 0; i < packages.length; i++) {
const pkg = packages[i];
updateSinglePackage(pkg, version);
await updateSinglePackage(pkg, version, commit);
}
};

const updateSinglePackage = (dir: string, version: string) => {
const updateSinglePackage = async (dir: string, version: string, commit: boolean) => {
const packageJSON = getPackageJSON(dir);
packageJSON.version = version;
writePackageJSON(dir, packageJSON);
if (commit) {
await commitPackageJSON(dir);
}
console.log(`- Updated ${getFormattedName(dir)}`);
};

const writePackageJSON = (file: string, contents: Record<string, string | number | Object | Array<any>>) => {
const stringifiedContents = `${JSON.stringify(contents, null, 2)}\n`;
const getPackageJSONPath = (file: string) => {
if (file.endsWith('package.json')) {
fs.writeFileSync(file, stringifiedContents);
} else {
fs.writeFileSync(path.resolve(file, 'package.json'), stringifiedContents);
return file;
}
};
return path.resolve(file, 'package.json');
}

const getPackageJSON = (file: string) => {
if (file.endsWith('package.json')) {
return JSON.parse(fs.readFileSync(file, 'utf-8'));
}
return JSON.parse(fs.readFileSync(path.resolve(file, 'package.json'), 'utf-8'));
const commitPackageJSON = async (dir: string) => {
const file = getPackageJSONPath(dir);
const cmd = `git add "${file}"`
await execute(cmd);
}

const writePackageJSON = (file: string, contents: Record<string, string | number | Object | Array<any>>) => {
const stringifiedContents = `${JSON.stringify(contents, null, 2)}\n`;
fs.writeFileSync(getPackageJSONPath(file), stringifiedContents);
};

const getPackageJSON = (file: string) => JSON.parse(fs.readFileSync(getPackageJSONPath(file), 'utf-8'));

const getVersion = (dir: string) => {
return getPackageJSON(dir).version;
};
Expand Down Expand Up @@ -79,7 +87,13 @@ const updateVersion = () => new Promise(resolve => {
'UpscalerJS', 'Models', 'Examples', 'Root',
],
},
]).then(({ version, packages }) => {
{
name: 'commit',
message: `Do you wish to commit changes`,
type: 'confirm',
default: true,
},
]).then(async ({ version, packages, commit }) => {
if (!isValidVersion(version)) {
throw new Error(`Version is not in the format x.x.x. You specified: ${version}`);
}
Expand All @@ -88,17 +102,21 @@ const updateVersion = () => new Promise(resolve => {
return;
}

packages.forEach(packageKey => {
await Promise.all(packages.map(packageKey => {
if (packageKey === 'Examples') {
updateMultiplePackages(EXAMPLES_DIR, version)
return updateMultiplePackages(EXAMPLES_DIR, version, commit);
} else if (packageKey === 'Models') {
updateSinglePackage(MODELS_DIR, version)
return updateSinglePackage(MODELS_DIR, version, commit);
} else if (packageKey === 'UpscalerJS') {
updateSinglePackage(UPSCALERJS_DIR, version)
return updateSinglePackage(UPSCALERJS_DIR, version, commit);
} else if (packageKey === 'Root') {
updateSinglePackage(ROOT_DIR, version)
return updateSinglePackage(ROOT_DIR, version, commit);
}
});
}));
if (commit) {
const cmd = `git commit -m "Updated version to ${version} for ${formatArray(packages)}"`;
await execute(cmd);
}
resolve();
});
});
Expand All @@ -108,3 +126,16 @@ export default updateVersion;
if (require.main === module) {
updateVersion();
}

const formatArray = (packages: Array<string>) => {
if (packages.length === 1) {
return packages[0];
}
if (packages.length === 2) {
return packages.join(' and ');
}
return [
packages.slice(0, -1).join(', '),
packages.pop(),
].join(' and ');
}
14 changes: 14 additions & 0 deletions scripts/package-scripts/utils/execute.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import { exec } from 'child_process';
const execute = (cmd: string) => new Promise((resolve, reject) => {
const spawnedProcess = exec(cmd, {}, (error: Error | null) => {
if (error) {
reject(error.message);
} else {
resolve();
}
});
spawnedProcess.stderr?.pipe(process.stderr);
spawnedProcess.stdout?.pipe(process.stdout);
})
export default execute;

0 comments on commit 2c6c89f

Please sign in to comment.