Skip to content

Commit

Permalink
build: replace stamp bash script with node script (#367)
Browse files Browse the repository at this point in the history
* build: replace stamp bash script with node script

* build: move stamp script to tools dir

* build: fix npm stamp script
  • Loading branch information
fredericbonnet committed Oct 5, 2020
1 parent d693942 commit e79d468
Show file tree
Hide file tree
Showing 5 changed files with 188 additions and 28 deletions.
9 changes: 0 additions & 9 deletions angular.json
Expand Up @@ -91,15 +91,6 @@
"jestConfig": "apps/xlayers/jest.config.js",
"passWithNoTests": true
}
},
"stamp": {
"builder": "@nrwl/workspace:run-commands",
"options": {
"commands": [
"chmod u+x ./scripts/stamp.bash",
"./scripts/stamp.bash"
]
}
}
}
},
Expand Down
157 changes: 157 additions & 0 deletions package-lock.json

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

4 changes: 3 additions & 1 deletion package.json
Expand Up @@ -25,7 +25,7 @@
"update": "ng update @nrwl/workspace",
"workspace-schematic": "nx workspace-schematic",
"dep-graph": "nx dep-graph",
"stamp": "nx run xlayers:stamp",
"stamp": "node tools/stamp.js",
"release": "release-it --config .release-it.json",
"deploy": "npm run build -- --prod && npm run stamp && firebase deploy --only hosting",
"help": "nx help"
Expand Down Expand Up @@ -95,6 +95,8 @@
"ng-packagr": "^10.0.3",
"prettier": "2.0.4",
"release-it": "^14.0.3",
"replace-in-file": "^6.1.0",
"simple-git": "^2.20.1",
"ts-jest": "26.1.4",
"ts-node": "~7.0.0",
"tslint": "~6.0.0",
Expand Down
18 changes: 0 additions & 18 deletions scripts/stamp.bash

This file was deleted.

28 changes: 28 additions & 0 deletions tools/stamp.js
@@ -0,0 +1,28 @@
const simpleGit = require('simple-git');
const replace = require('replace-in-file');
const git = simpleGit();

/** Get build number from current git revision */
const getBuildNumber = () =>
Promise.all([
git.revparse(['--abbrev-ref', 'HEAD']),
git.revparse(['--short', 'HEAD']),
]).then(([b, v]) => `${b}+sha.${v}`);

/** Replace _BUILD_HASH_ in dist files with the current build number */
const replaceBuildHash = (buildNumber) =>
replace({
from: /_BUILD_HASH_/g,
to: buildNumber,
files: 'dist/**/**/*.js',
}).then(() => buildNumber);

// Run script
getBuildNumber()
.then(replaceBuildHash)
.then((buildNumber) => {
console.log(`Build was stamped: ${buildNumber}`);
})
.catch((e) => {
console.error('Could not stamp this build!', e);
});

0 comments on commit e79d468

Please sign in to comment.