Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ before_script:

script:
- "gulp lint"
- "gulp htmlhint"
- "gulp test"

after_success:
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,5 +26,5 @@ open http://localhost:8080
* Long term caching
* Karma, mocha and Sinon.js
* Istanbul test coverage
* ESLint
* ESLint, HTMLHint
* TravisCI
41 changes: 41 additions & 0 deletions build_signature_loader.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
const Promise = require('bluebird');
const _ = require('lodash');
const path = require('path');

const cwd = path.join(__dirname, '.');
const exec = Promise.promisify(require('child_process').exec);

function inspectRepository() {
function revParse(args) {
return exec(`git rev-parse ${args}`, { cwd })
.then((result) => result.trim());
}

return Promise.all([
revParse('--abbrev-ref HEAD'),
revParse('HEAD')
]).spread((branch, commit) => {
return { branch, commit };
}).catch(() => {
return {
branch: '?',
commit: '?'
};
});
}

module.exports = function(source) {
const callback = this.async();

inspectRepository().then(({ branch, commit }) => {
const compiled = _.template(source);

const signature = compiled({
timestamp: new Date().toISOString(),
branch,
commit
});

callback(null, `module.exports = ${JSON.stringify(signature)}`);
});
};
9 changes: 8 additions & 1 deletion gulpfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ const _ = require('lodash');
const KarmaServer = require('karma').Server;
const gulp = require('gulp');
const gutil = require('gulp-util');
const htmlhint = require('gulp-htmlhint');
const path = require('path');

gulp.task('lint', () => {
Expand All @@ -18,6 +19,12 @@ gulp.task('lint', () => {
.pipe(eslint.failAfterError());
});

gulp.task('htmlhint', () => {
gulp.src('src/**/*.html')
.pipe(htmlhint({ 'doctype-first': false }))
.pipe(htmlhint.reporter('htmlhint-stylish'));
});

function karmaStart(config, done) {
config = _.extend({
configFile: path.join(__dirname, 'karma.conf.js'),
Expand Down Expand Up @@ -55,4 +62,4 @@ gulp.task('tdd', (done) => {
karmaStart({ singleRun: false }, done);
});

gulp.task('default', ['lint', 'test']);
gulp.task('default', ['lint', 'htmlhint', 'test']);
2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,11 @@
"file-loader": "^0.9.0",
"gulp": "^3.9.1",
"gulp-eslint": "^3.0.1",
"gulp-htmlhint": "^0.3.1",
"gulp-util": "^3.0.7",
"html-loader": "^0.4.3",
"html-webpack-plugin": "^2.22.0",
"htmlhint-stylish": "^1.0.3",
"imports-loader": "^0.6.5",
"karma": "^1.3.0",
"karma-chrome-launcher": "^2.0.0",
Expand Down
5 changes: 5 additions & 0 deletions src/app/build_signature.tpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@

__ (\_ timestamp: <%= timestamp %>
(_ \ ( '> branch: <%= branch %>
) \/ )= commit: <%= commit %>
(_(_ )_
5 changes: 5 additions & 0 deletions src/app/module.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import angular from 'angular';
import appAbout from './about/module';
import appContacts from './contacts/module';
import appHome from './home/module';
import buildSignature from '../../build_signature_loader!./build_signature.tpl';
import template404 from './404.html';
import uiRouter from 'angular-ui-router';

Expand Down Expand Up @@ -41,4 +42,8 @@ export default angular.module('app', [
$log.error('$stateChangeError', error);
$state.go('404');
});
}).run(($log) => {
'ngInject';

$log.info(buildSignature);
});