Skip to content

Instantly share code, notes, and snippets.

@sergebat
Created September 9, 2013 20:40
Show Gist options
  • Save sergebat/6501181 to your computer and use it in GitHub Desktop.
Save sergebat/6501181 to your computer and use it in GitHub Desktop.
My grunt file for HTML5 game build: TypeScript, copy, tag, uglify, upload to demo server (SFTP)
module.exports = function(grunt) {
// Project configuration.
grunt.initConfig({
pkg: grunt.file.readJSON('package.json'),
clean: ["deploy"],
typescript: {
base: {
src: ['src/main.ts'],
dest: 'js/game.min.js',
options: {
allowbool: true,
module: 'amd', //or commonjs
target: 'es3', //or es3
base_path: '',
fullSourceMapPath: true,
declaration: false
}
}
},
copy: {
resources: {
src: ['assets/**', 'css/**', 'lib/**', 'index.html'],
dest: 'deploy/<%= pkg.name %>-<%= global["mercurialRevision"] %>/'
},
jsNoMin: {
src: ['js/game.min.js'],
dest: 'deploy/<%= pkg.name %>-<%= global["mercurialRevision"] %>/'
}
},
shell: {
getMercurialRevision: {
command: 'hg id -i -r tip',
options: {
callback: function(err, stdout, stderr, cb) {
var revision = stdout;
global["mercurialRevision"] = revision.trim();
console.log("Current mercurial revision:", revision);
cb();
}
}
},
failOnUncommittedFiles: {
command: 'hg st',
options: {
callback: function(err, stdout, stderr, cb) {
// using --ic option to ignore uncommitted files
if (stdout != "" && !grunt.option("ic")) {
grunt.warn("'hg status' indicates there are locally added/removed/modified files. \n" +
"You should commit them to make sure deployed builds matches changeset id. \n" +
"You may use --ic option to suppress this check for debug purposes. \n");
}
cb();
}
}
},
browseLatestDeploy: {
command: 'start <%= sftpCredentials.deployBaseURL %>/<%= pkg.name %>-<%= global["mercurialRevision"] %>/'
}
},
uglify: {
options: {
banner: '/*! <%= pkg.name %> - <%= global["mercurialRevision"] %> minimified build */\n'
},
build: {
src: 'js/game.min.js',
dest: 'deploy/<%= pkg.name %>-<%= global["mercurialRevision"] %>/js/game.min.js'
}
},
sftpCredentials: getGruntCredentials(),
sftp: {
upload: {
files: {
"./": "deploy/**"
},
options: {
"path": "<%= sftpCredentials.path %>",
"host": "<%= sftpCredentials.host %>",
"username": "<%= sftpCredentials.username %>",
"port": "<%= sftpCredentials.port %>",
"password": "<%= sftpCredentials.password %>",
"srcBasePath": "deploy/",
"createDirectories": true
}
}
},
qunit: {
all: ["test.html"]
}
});
// Load plugings
grunt.loadNpmTasks('grunt-typescript');
grunt.loadNpmTasks('grunt-contrib-copy');
grunt.loadNpmTasks('grunt-contrib-clean');
grunt.loadNpmTasks('grunt-shell');
grunt.loadNpmTasks('grunt-ssh');
grunt.loadNpmTasks('grunt-contrib-uglify');
grunt.loadNpmTasks('grunt-contrib-qunit');
// Tasks
grunt.registerTask('default', ['make']);
grunt.registerTask('make', ['shell:failOnUncommittedFiles', 'shell:getMercurialRevision', 'clean', 'typescript', 'uglify', 'copy:resources']);
grunt.registerTask('upload', ['shell:getMercurialRevision', 'sftp:upload', 'shell:browseLatestDeploy']);
// Utilities
function getGruntCredentials() {
var gruntCredentialsfileName = 'sftp-credentials.json';
if (!grunt.file.exists(gruntCredentialsfileName)) {
return {};
}
return grunt.file.readJSON('sftp-credentials.json');
}
};
{
"name": "jelly-collapse",
"version": "0.2.0",
"devDependencies": {
"grunt-cli": "*",
"grunt": "~0.4.1",
"typescript": "~0.9.0",
"grunt-typescript": "~0.2.4",
"grunt-contrib-copy": "~0.4.1",
"grunt-contrib-clean": "~0.5.0",
"grunt-shell": "~0.3.1",
"grunt-ssh": "~0.6.2",
"grunt-contrib-uglify": "~0.2.2",
"grunt-contrib-qunit": "~0.2.2"
},
"private": true
}
{
"path": "/var/www/default/public_html/pgb/",
"host": "IP_GOES_HERE",
"username": "USER_NAME_GOES_HERE",
"port": 99999,
"password": "PASSWORD_GOES_HERE",
"deployBaseURL": "http://example.com/mybuild"
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment