Update: Adding build scripts to prepare for split of rive-react into 2 package derivatives for canvas and webgl

This commit is contained in:
Zach Plata
2022-03-17 16:44:00 -07:00
committed by Zachary Plata
parent 6e72ed5271
commit 5c4336b84f
10 changed files with 148 additions and 0 deletions

View File

@@ -0,0 +1,3 @@
# rive-react-canvas
Output for `rive-react` using the backing `@rive-app/canvas` JS runtime

View File

@@ -0,0 +1,3 @@
# rive-react-webgl
Output for `rive-react` using the backing `@rive-app/webgl` JS runtime

19
scripts/build.sh Executable file
View File

@@ -0,0 +1,19 @@
#!/bin/bash
set -e
# Run the build and copy to the rive-react-webgl build for npm release
npm run build
cp -r ./dist ./npm/rive-react-webgl
cp -r ./dist ./npm/rive-react-canvas
echo Replacing the webgl with canvas references
pushd ./npm/rive-react-canvas/dist
if [[ "$OSTYPE" == "darwin"* ]]; then
find . -type f -name "*.ts" -print0 | xargs -0 sed -i '' -e 's/@rive-app\/webgl/@rive-app\/canvas/g'
find . -type f -name "*.js" -print0 | xargs -0 sed -i '' -e 's/@rive-app\/webgl/@rive-app\/canvas/g'
else
find . -type f -name "*.ts" -print0 | xargs -0 sed -i -e 's/@rive-app\/webgl/@rive-app\/canvas/g'
find . -type f -name "*.js" -print0 | xargs -0 sed -i -e 's/@rive-app\/webgl/@rive-app\/canvas/g'
fi
popd

11
scripts/bump_all_versions.sh Executable file
View File

@@ -0,0 +1,11 @@
#!/bin/bash
set -e
# Bump the version number of every npm module in the npm folder.
for dir in ./npm/*; do
pushd $dir > /dev/null
repo_name=`echo $dir | sed 's:.*/::' | sed 's/_/-/g'`
echo Bumping version of $repo_name
../../scripts/bump_version.sh $repo_name
popd > /dev/null
done

9
scripts/bump_version.sh Executable file
View File

@@ -0,0 +1,9 @@
#!/bin/bash
# Bumps the version of a single npm module found in the current working
# directory. Call bump_version.sh from the path with package.json in it.
set -e
SCRIPT_DIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )
NPM_VERSIONS=`npm show rive-react versions`
node $SCRIPT_DIR/nextVersion.js "$NPM_VERSIONS" `pwd`

44
scripts/nextVersion.js Normal file
View File

@@ -0,0 +1,44 @@
const fs = require('fs');
const path = process.argv[3];
const package = require(path + '/package.json');
let versions = JSON.parse(process.argv[2].trim().replace(/\'/g, '"'));
const current = package.version;
// Don't work with alpha/beta/rc tags, maybe a better regex here?
versions = versions.filter((ver) => {
return !/[a-zA-Z]/.test(ver);
});
const latest = versions[versions.length - 1];
// Returns -1 if first is less than second, 1 if first is greater than second, otherwise 0 if equal.
function compareVersion(first, second) {
// Assumption: only numbers in our versions.
const firstParts = first.split('.').map((value) => parseInt(value));
const secondParts = second.split('.').map((value) => parseInt(value));
for (let i = 0; i < firstParts.length; i++) {
if (secondParts.length === i) {
return 1;
}
if (firstParts[i] < secondParts[i]) {
return -1;
} else if (firstParts[i] > secondParts[i]) {
return 1;
}
}
if (firstParts.length !== secondParts.length) {
return -1;
}
return 0;
}
if (compareVersion(current, latest) <= 0) {
const parts = latest.split('.').map((value) => parseInt(value));
// TODO: Need to make this smarter, because the semver can change on rive-react
parts[parts.length - 1] = parts[parts.length - 1] + 1;
package.version = parts.join('.');
fs.writeFileSync(path + '/package.json', JSON.stringify(package, null, 2));
}

10
scripts/publish_all.sh Executable file
View File

@@ -0,0 +1,10 @@
#!/bin/bash
set -e
# Bump the version number of every npm module in the npm folder.
for dir in ./npm/*; do
pushd $dir > /dev/null
echo Publishing `echo $dir | sed 's:.*/::'`
npm publish $@
popd > /dev/null
done

21
scripts/setup_all_packages.sh Executable file
View File

@@ -0,0 +1,21 @@
#!/bin/bash
set -e
echo Copying package.json to rive-react npm package folders
cp package.json npm/rive-react-canvas
cp package.json npm/rive-react-webgl
# Bump the version number of every npm module in the npm folder.
for dir in ./npm/*; do
echo $dir
pushd $dir > /dev/null
echo $dir
repo_name=`echo $dir | sed 's:.*/::' | sed 's/_/-/g'`
echo Setting package.json on npm packages
echo $repo_name
../../scripts/setup_package.sh $repo_name
echo Finished setting up package.json
popd > /dev/null
done

6
scripts/setup_package.sh Executable file
View File

@@ -0,0 +1,6 @@
#!/bin/bash
set -e
# Setup the package.json for a given npm module
SCRIPT_DIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )
node $SCRIPT_DIR/trimPackageJson.js `pwd` "$1"

View File

@@ -0,0 +1,22 @@
const fs = require('fs');
const path = process.argv[2];
const npmPackageSplit = process.argv[3].split('-');
const renderer = npmPackageSplit[npmPackageSplit.length - 1];
const package = require(path + '/package.json');
function trimNpmPackage() {
package.name = `${package.name}-${renderer}`;
package.description = `React wrapper around the @rive-app/${renderer} library`;
const webDependencyName = `@rive-app/${renderer}`;
const canvasDep = package.dependencies[webDependencyName];
package.dependencies = {
[webDependencyName]: canvasDep,
};
delete package.devDependencies;
delete package.scripts;
fs.writeFileSync(path + '/package.json', JSON.stringify(package, null, 2));
}
if (renderer) {
trimNpmPackage();
}