Skip to content

Commit

Permalink
Move __version__ to a script
Browse files Browse the repository at this point in the history
  • Loading branch information
pdehaan committed Jun 23, 2017
1 parent 2b01bb7 commit 314e756
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 13 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
.DS_Store
node_modules
public/bundle.js
public/version.json
static/*
!static/info.txt
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
"cross-env": "^5.0.1",
"express": "^4.15.3",
"express-handlebars": "^3.0.0",
"git-rev-sync": "1.9.1",
"git-rev-sync": "^1.9.1",
"helmet": "^3.6.1",
"jquery": "^3.2.1",
"mozlog": "^2.1.1",
Expand Down Expand Up @@ -42,9 +42,9 @@
"license": "MPL-2.0",
"repository": "mozilla/something-awesome",
"scripts": {
"bundle": "browserify frontend/src/main.js | uglifyjs > public/bundle.js",
"bundle": "browserify frontend/src/main.js | uglifyjs > public/bundle.js && node scripts/version",
"dev": "watchify frontend/src/main.js -o public/bundle.js -d | node server/portal_server",
"format": "prettier 'frontend/src/*.js' 'public/*.css' 'server/*.js' 'test/*.js' --single-quote --write",
"format": "prettier '{frontend/src/,scripts/,server/,test/}*.js' 'public/*.css' --single-quote --write",
"lint": "npm-run-all lint:*",
"lint:css": "stylelint 'public/*.css'",
"lint:js": "eslint .",
Expand Down
20 changes: 20 additions & 0 deletions scripts/version.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
const fs = require('fs');
const path = require('path');
const pkg = require('../package.json');

let commit;

try {
commit = require('git-rev-sync').short();
} catch (err) {
// Whatever...
}

const filename = path.join(__dirname, '..', 'public', 'version.json');
const filedata = {
commit,
source: pkg.homepage,
version: pkg.version
};

fs.writeFileSync(filename, JSON.stringify(filedata, null, 2) + '\n');
14 changes: 4 additions & 10 deletions server/portal_server.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,15 @@ const helmet = require('helmet');
const bytes = require('bytes');
const conf = require('./config.js');
const storage = require('./storage.js');
const pkg = require('../package.json');

const gitSHA = require('git-rev-sync').short();

const notLocalHost = conf.notLocalHost;

const mozlog = require('./log.js');

const log = mozlog('portal.server');

const STATIC_PATH = path.join(__dirname, '../public');

const app = express();

app.engine('handlebars', exphbs({
Expand All @@ -28,8 +27,7 @@ app.set('view engine', 'handlebars');
app.use(helmet());
app.use(busboy());
app.use(bodyParser.json());
app.use(express.static(path.join(__dirname, '../public')));

app.use(express.static(STATIC_PATH));

app.get('/', (req, res) => {
res.render('index', {
Expand Down Expand Up @@ -154,11 +152,7 @@ app.get('/__lbheartbeat__', (req, res) => {
});

app.get('/__version__', (req, res) => {
res.json({
commit: gitSHA,
source: pkg.homepage,
version: pkg.version
});
res.sendFile(path.join(STATIC_PATH, 'version.json'));
});

app.listen(conf.listen_port, () => {
Expand Down

0 comments on commit 314e756

Please sign in to comment.