Skip to content

Commit

Permalink
Merge pull request #13 from CodeNow/SAN-3550-static-site
Browse files Browse the repository at this point in the history
SAN-3550 static site
  • Loading branch information
Myztiq committed Feb 26, 2016
2 parents cbedee7 + 47336bf commit ac47e4b
Show file tree
Hide file tree
Showing 6 changed files with 97 additions and 17 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,5 @@
*.iml
.publish/
node_modules/
dist/
dist/
.awspublish*
70 changes: 64 additions & 6 deletions gulpfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ var imagemin = require('gulp-imagemin'); // image optimizer
var ghPages = require('gulp-gh-pages'); // deploy to gh pages
var handlebars = require('gulp-compile-handlebars'); // handlebars
var rename = require('gulp-rename'); // rename files
var awspublish = require('gulp-awspublish');
var exec = require('child_process').exec;

// file locations
var src = 'src/';
Expand Down Expand Up @@ -49,15 +51,32 @@ gulp.task('html', function() {
.pipe(gulp.dest(hbsDist));
});

var commitTime;
gulp.task('getCommitTime', function (cb) {
exec('git log -1 --format=%cd', {cwd: __dirname}, function (err, stdout, stderr) {
commitTime = stdout.split('\n').join('');
cb();
});
});

var commitHash;
gulp.task('getCommitHash', function (cb) {
exec('git rev-parse HEAD', {cwd: __dirname}, function (err, stdout, stderr) {
commitHash = stdout.split('\n').join('');
cb();
})
});

// hbs files
gulp.task('hbs', function() {
return gulp.src(hbsSrc)
.pipe(handlebars({
// We include this for when we use this in Runnable Angular
apiHost: 'https://api-staging-codenow.runnableapp.com',
env: 'staging',
commitHash: 'NOT_VALID',
commitTime: 'NOT_VALID'
apiUrl: process.env.API_URL,
env: process.env.NODE_ENV,
commitHash: commitHash,
commitTime: commitTime,
angularUrl: process.env.ANGULAR_URL
}, {
helpers: {
if_eq: function(a, b, opts) {
Expand Down Expand Up @@ -150,16 +169,55 @@ gulp.task('ghPages', function() {
.pipe(ghPages());
});

gulp.task('s3', function() {
// create a new publisher using S3 options
// http://docs.aws.amazon.com/AWSJavaScriptSDK/latest/AWS/S3.html#constructor-property
var publisher = awspublish.create({
accessKeyId: process.env.AWS_ACCESS_KEY,
secretAccessKey: process.env.AWS_SECRET_KEY,
params: {
Bucket: process.env.AWS_BUCKET
}
});

// define custom headers
var headers = {
'Cache-Control': 'max-age=' + (60 * 5) + ', no-transform, public'
};

return gulp.src(dist + '**/*')
// gzip, Set Content-Encoding headers
.pipe(awspublish.gzip())

// publisher will add Content-Length, Content-Type and headers specified above
// If not specified it will set x-amz-acl to public-read by default
.pipe(publisher.publish(headers))

// Delete files in the bucket that aren't in the local folder
.pipe(publisher.sync())

// create a cache file to speed up consecutive uploads
.pipe(publisher.cache())

// print upload updates to console
.pipe(awspublish.reporter());
});

// build and optimize
gulp.task('build', function(cb) {
runSequence('clean', 'html', 'hbs', ['sassCompressed', 'images', 'favicon'], 'imagemin', cb);
runSequence('getCommitTime', 'getCommitHash', 'clean', 'html', 'hbs', ['sassCompressed', 'images', 'favicon'], 'imagemin', cb);
});

// build and deploy to gh pages
gulp.task('deploy', function(cb) {
gulp.task('deploy:gh', function(cb) {
runSequence('build', 'ghPages', cb);
});

// build and deploy to amazon s3
gulp.task('deploy:s3', function(cb) {
runSequence('build', 's3', cb);
});

// build and watch
gulp.task('default', function(cb) {
runSequence('clean', 'html', 'hbs', ['sass', 'images', 'favicon'], cb);
Expand Down
19 changes: 13 additions & 6 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,23 +5,30 @@
"main": "gulpfile.js",
"dependencies": {
"del": "^2.2.0",
"git": "^0.1.5",
"gulp": "~3.9.0",
"gulp-autoprefixer": "~2.3.1",
"gulp-awspublish": "^3.0.1",
"gulp-cli": "^1.2.1",
"gulp-compile-handlebars": "^0.6.1",
"gulp-debug": "~2.0.1",
"gulp-file-include": "^0.13.2",
"gulp-imagemin": "~2.3.0",
"gulp-gh-pages": "^0.5.4",
"gulp-imagemin": "~2.4.0",
"gulp-newer": "~0.5.1",
"gulp-rename": "^1.2.2",
"gulp-sass": "~2.0.3",
"run-sequence": "^1.1.5"
},
"devDependencies": {
"git": "^0.1.5",
"gulp-debug": "~2.0.1",
"gulp-gh-pages": "^0.5.4",
"gulp-newer": "~0.5.1"
"engine": {
"node": "4.2.2",
"npm": "3.7.5"
},
"repository": {
"type": "git",
"url": "https://github.com/CodeNow/runnable.com.git"
},
"scripts": {
"deploy": "node_modules/.bin/gulp deploy:s3"
}
}
5 changes: 5 additions & 0 deletions src/html/index.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,11 @@
@@include('../js/index.js')
</script>

<!--
Commit Hash: {{{commitHash}}}
Commit Time: {{{commitTime}}}
-->

<body class="page-landing" ng-app="homeApp" ng-controller="MainCtrl" ontouchstart>

<header class="grid-block shrink header">
Expand Down
2 changes: 1 addition & 1 deletion src/html/production.hbs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{{#if_eq env 'production'}}
{{#if_eq env 'production-delta'}}
@@include('external/facebook.html')
<script>
window._trackJs = {
Expand Down
15 changes: 12 additions & 3 deletions src/js/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ var whitelisted = window.location.search !== '?whitelist=false';
var app = angular.module('homeApp', []);

app.controller('MainCtrl', function ($scope, $window, $http) {
$scope.loginUrl = '{{{apiHost}}}/auth/github?redirect=' + $window.location.protocol + '//' + $window.location.host + '/?auth';
$scope.loginUrl = '{{{apiUrl}}}/auth/github?redirect={{{angularUrl}}}/?auth';
$scope.data = {
embedActive: false,
hideUnauthorizedModal: whitelisted
Expand All @@ -13,7 +13,7 @@ app.controller('MainCtrl', function ($scope, $window, $http) {
location.hash = '#sign-up';
}

$http.get('{{{apiHost}}}/users/me', {
$http.get('{{{apiUrl}}}/users/me', {
withCredentials: true
})
.then(function (user) {
Expand All @@ -23,7 +23,16 @@ app.controller('MainCtrl', function ($scope, $window, $http) {
} catch (e) {
org = user.data.accounts.github.username;
}
$window.location = '/' + org;
var prevInstance;
try {
prevInstance = user.data.userOptions.uiState.previousLocation.instance;
} catch (e) {
}
var newURL = '{{{angularUrl}}}/' + org;
if (prevInstance) {
newURL += '/' + prevInstance
}
$window.location = newURL;
});

// confirming form submit
Expand Down

0 comments on commit ac47e4b

Please sign in to comment.