Skip to content

Commit

Permalink
fix: [#1731] Replace TSC build constant + Simplify version generation (
Browse files Browse the repository at this point in the history
…#2053)

* fix: [#1731] Replace TSC build constant + Simplify version generation

Closes: #1731

* fix: lock
  • Loading branch information
eonarheim authored Oct 21, 2021
1 parent 3eb1925 commit a2a245e
Show file tree
Hide file tree
Showing 4 changed files with 97 additions and 19 deletions.
76 changes: 76 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
"start": "npm run core:watch",
"build": "npm run core",
"core": "npm run core:tsc && npm run core:copy && npm run core:bundle",
"core:tsc": "tsc --project src/engine/tsconfig.json --incremental true --tsBuildInfoFile .tsbuildinfo",
"core:tsc": "tsc --project src/engine/tsconfig.json --incremental true --tsBuildInfoFile .tsbuildinfo && node ./scripts/excalibur-version.js",
"core:copy": "copyfiles -u 2 ./src/engine/**/*.png ./src/engine/**/*.css ./src/engine/**/*.glsl ./build/dist/",
"core:bundle": "webpack --progress --config webpack.config.js --mode production",
"core:watch": "npm run core:bundle -- --watch",
Expand Down Expand Up @@ -91,6 +91,7 @@
"karma-jasmine": "4.0.1",
"karma-webpack": "5.0.0",
"puppeteer": "10.4.0",
"replace-in-file": "6.2.0",
"react": "^17.0.2",
"react-dom": "^17.0.2",
"rimraf": "3.0.2",
Expand Down
13 changes: 13 additions & 0 deletions scripts/excalibur-version.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
const replace = require('replace-in-file');
const version = require('../version').getCiVersion();
const options = {
files: 'build/dist/index.js',
from: /process\.env\.__EX_VERSION/g,
to: `'${version}'`
};

try {
replace.sync(options);
} catch (e) {
console.error(e);
}
24 changes: 6 additions & 18 deletions version.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
const { execSync } = require('child_process');
const semver = require('semver');
const package = require('./package.json');

function getCiOptions() {
return {
Expand All @@ -18,17 +19,8 @@ function getCurrentCommit() {
return commit;
}

function getLatestTag(commit) {
execSync('git fetch --depth=1000');
execSync('git fetch --all --tags');
const tag = execSync(`git describe --tags ${commit} --abbrev=0`).toString().trim();
return tag;
}

function getLatestVersion() {
const commit = getCurrentCommit();
const tag = getLatestTag(commit);
return tag.match(/^v?([0-9\.]+)$/)[1];
function getNextVersion() {
return package.exNextVersion;
}

function isTaggedRelease(options) {
Expand All @@ -52,8 +44,7 @@ function generateLocalVersion() {
try {
execSync('git fetch');
const commit = getCurrentCommit();
version = getLatestVersion();
version = semver.inc(version, 'minor');
version = getNextVersion();
version = version + '-' + commit.substring(0, 7);
} catch (err) {
console.error(err);
Expand All @@ -78,9 +69,7 @@ function generateCommunityVersion(options) {

function generateAlphaVersion(options) {
let commit = getCurrentCommit();
let version = getLatestVersion();
// Alpha builds target next projected release pre 1.0
version = semver.inc(version, 'minor');
let version = getNextVersion();

// Nuget doesn't yet support the + suffix in versions
const appveyVersion = version + '.' + options.appveyorBuild + '-alpha';
Expand Down Expand Up @@ -117,8 +106,7 @@ function getCiVersion(ciOptions, log = true) {

exports.getCiOptions = getCiOptions;
exports.getCurrentCommit = getCurrentCommit;
exports.getLatestTag = getLatestTag;
exports.getLatestVersion = getLatestVersion;
exports.getNextVersion = getNextVersion;
exports.isTaggedRelease = isTaggedRelease;
exports.isLocal = isLocal;
exports.isFork = isFork;
Expand Down

0 comments on commit a2a245e

Please sign in to comment.