Skip to content
This repository has been archived by the owner on Feb 15, 2022. It is now read-only.

Commit

Permalink
Bug #55/#54, CLI to add version to app/config Javascript [iet:102…
Browse files Browse the repository at this point in the history
…64031]
  • Loading branch information
nfreear committed Nov 16, 2017
1 parent 41dfbd3 commit cb69025
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 10 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ Client-side & Javascript dependencies are listed in [`package.json`][].
## Install, build, test

```sh
cp app/pom.TEMPLATE.xml app/pom.xml
cp static/src/index.DIST.html static/src/index.html
cp -n app/pom.TEMPLATE.xml app/pom.xml
npm run copy-conf
npm install
npm run java
npm run cp-compiled
Expand Down
4 changes: 2 additions & 2 deletions bin/git-version.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ var directory = __dirname + '/..'
, split = true
, version = {
'#': 'ok',
file_date: new Date().toISOString(),
build_time: new Date().toISOString(),
lib: 'git-version.js'
};

Expand All @@ -33,7 +33,7 @@ if (matchArgv('--all')) {
git_version: exec('git --version').replace(/(git )?(version )?/, '')
};
}
version.describe = exec('git describe --tags', null, carryon);
version.describe = exec('git describe --tags --long', null, carryon);
version.branch = exec('git rev-parse --abbrev-ref HEAD');
version.origin = exec('git config --get remote.origin.url');
version.url = version.origin.replace(/git@/, 'https://').replace('.com:', '.com/');
Expand Down
23 changes: 20 additions & 3 deletions bin/replace.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,15 @@
const replace = require('replace');
const version = require('./../static/src/version.json');
const INDEX_HTML = path('/../static/src/index.html');
const rand = getRandomInt(11, 1000);
const CONFIG_JS = path('/../static/src/js/app/config.js');
const RAND = getRandomInt(11, 1000);

console.warn('Version.json ~ describe, rand:', version.describe, rand);
console.warn('Version.json ~ describe, rand:', version.describe, RAND);

replace({
paths: [ INDEX_HTML ],
regex: /\.(css|js)\?r=(_RAND_|[^\"]+)/g,
replacement: '.$1?r=' + rand,
replacement: '.$1?r=' + RAND,
count: true,
recursive: false
});
Expand All @@ -30,6 +31,22 @@ replace({
recursive: false
});

replace({
paths: [ CONFIG_JS ],
regex: /version: ['"][\w_\.\-]+['"],/,
replacement: 'version: "%s",'.replace(/%s/, version.describe),
count: true,
recursive: false
});

replace({
paths: [ CONFIG_JS ],
regex: /build_time: ['"][\w_\.\-:]+['"],/,
replacement: 'build_time: "%s",'.replace(/%s/, new Date().toISOString()),
count: true,
recursive: false
});

function getRandomInt(min, max) {
min = Math.ceil(min);
max = Math.floor(max);
Expand Down
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -68,9 +68,9 @@
"cp-compiled": "cp -r app/target/classes/org/greengin/nquireit/ ../nquire-web-compiled/classes/org/greengin/nquireit",
"echo-versions": "printf 'npm: '; npm --version; echo ''; mvn --version",
"ps": "ps -af | egrep '(tomcat|httpd)' #| grep -v sh # grep",
"pull": "#git checkout package.json; git pull;\n grunt; npm run version",
"setup-config-js": "cp -n static/src/js/app/config.js.DIST.html static/src/js/app/config.js",
"setup-java": "cp -n app/pom.TEMPLATE.xml app/pom.xml",
"pull": "# git checkout package.json; git pull;\n grunt; npm run version",
"copy-conf": "cp -n static/src/js/app/config.js.DIST.html static/src/js/app/config.js; cp -n static/src/index.DIST.html static/src/index.html",
"copy-java-pom": "cp -n app/pom.TEMPLATE.xml app/pom.xml",
"test": "grunt test",
"test-all": "npm run version || grunt test",
"tr-compile-java": "mvn compile -f app/pom.xml | tee app/mvn.log | egrep '(ERROR|WARN|INFO)'",
Expand Down
3 changes: 3 additions & 0 deletions static/src/js/app/config.js.DIST.html
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@
siteKey: "6Lf2DhUTAAAAAFHjZKAbauPlEtiegg0nFf41-msN"
},

version: '_VERSION_',
build_time: '_TIME_',

// LEAVE me in the '.DIST.html' file - just for translation purposes!
other_texts_to_translate: [
"{{ 'nQuire-it — join missions to explore your world' | translate }}",
Expand Down

0 comments on commit cb69025

Please sign in to comment.