Skip to content

Instantly share code, notes, and snippets.

@ndrake
Last active August 20, 2019 21:37
Show Gist options
  • Save ndrake/47e81063795fa8716d7df217cca63803 to your computer and use it in GitHub Desktop.
Save ndrake/47e81063795fa8716d7df217cca63803 to your computer and use it in GitHub Desktop.
Insert version from package.json into Ionic 4 page
<ion-header>
<ion-toolbar>
<ion-buttons slot="start">
<ion-menu-button></ion-menu-button>
</ion-buttons>
<ion-title>About</ion-title>
</ion-toolbar>
</ion-header>
<ion-content padding>
<ion-list>
<ion-item>
Version @APP_VERSION@
</ion-item>
</ion-list>
</ion-content>
var git = require('git-rev-sync');
var appVersion = require('../package.json').version;
var replace = require('replace-in-file');
module.exports = function(ctx) {
const versionString = appVersion + ' (' + git.short() + ')';
console.log('Replacing @APP_VERSION@ with ' + versionString);
const options = {
files: [
'./www/*.js',
'./www/*.js.map'
],
from: '@APP_VERSION@',
to: versionString
}
try {
const result = replace.sync(options);
console.log('Changed files: ', result.join(', '));
} catch(error) {
console.log('Error doing text replacement: ', error);
}
}
{
"name": "APP_NAME",
"integrations": {
"cordova": {}
},
"type": "angular",
"hooks": {
"build:after": "./scripts/after_build.js"
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment