filer/gruntfile.js

310 lines
8.0 KiB
JavaScript
Raw Normal View History

var semver = require('semver'),
fs = require('fs'),
currentVersion = JSON.parse(fs.readFileSync('./package.json', 'utf8')).version,
env = require('./config/environment');
// Globals
var PROMPT_CONFIRM_CONFIG = 'confirmation',
GIT_BRANCH = env.get('FILER_UPSTREAM_BRANCH'),
GIT_REMOTE = env.get('FILER_UPSTREAM_REMOTE_NAME'),
GIT_FULL_REMOTE = env.get('FILER_UPSTREAM_URI') + ' ' + GIT_BRANCH;
module.exports = function(grunt) {
// Project configuration.
grunt.initConfig({
pkg: grunt.file.readJSON('package.json'),
clean: ['dist/filer-test.js', 'dist/filer-issue225.js'],
uglify: {
options: {
banner: '/*! <%= pkg.name %> <%= pkg.version %> <%= grunt.template.today("yyyy-mm-dd") %> */\n'
},
develop: {
src: 'dist/filer.js',
dest: 'dist/filer.min.js'
}
},
jshint: {
// Don't bother with src/path.js
all: [
'gruntfile.js',
'config/environment.js',
'src/constants.js',
'src/errors.js',
'src/fs.js',
'src/index.js',
'src/shared.js',
'src/shell.js',
2014-03-08 01:21:10 +00:00
'src/fswatcher.js',
'src/environment.js',
'src/providers/**/*.js',
2014-03-18 16:29:20 +00:00
'src/adapters/**/*.js',
'src/directory-entry.js',
'src/open-file-description.js',
'src/super-node.js',
'src/node.js',
2014-03-18 18:16:12 +00:00
'src/stats.js',
'src/filesystem/**/*.js'
]
},
browserify: {
2014-05-26 20:57:08 +00:00
filerDist: {
src: "./src/index.js",
dest: "./dist/filer.js",
options: {
browserifyOptions: {
commondir: false
},
bundleOptions: {
standalone: 'Filer'
},
exclude: ["./node_modules/request/index.js"]
2014-12-03 22:25:30 +00:00
}
},
2014-12-04 14:23:38 +00:00
perf: {
2014-12-03 22:25:30 +00:00
src: "./tests/perf/index.js",
dest: "./tests/perf/filer-perf-test.js",
options: {
browserifyOptions: {
commondir: false
},
bundleOptions: {
standalone: 'Filer'
}
}
},
2014-05-26 20:57:08 +00:00
filerTest: {
src: "./tests/index.js",
dest: "./dist/filer-test.js"
},
// See tests/bugs/issue225.js
filerIssue225: {
src: "./src/index.js",
dest: "./dist/filer-issue225.js",
options: {
browserifyOptions: {
commondir: false
},
bundleOptions: {
standalone: 'Filer'
}
}
}
},
shell: {
mocha: {
// Run all tests (e.g., tests require()'ed in tests/index.js) and also tests/bugs/issue225.js
// separately, since it can't be included in a browserify build.
2014-09-09 16:43:20 +00:00
command: '"./node_modules/.bin/mocha" --reporter list tests/index.js && "./node_modules/.bin/mocha" --reporter list tests/bugs/issue225.js'
}
},
bump: {
options: {
files: ['package.json', 'bower.json'],
commit: true,
commitMessage: 'v%VERSION%',
commitFiles: ['package.json', 'bower.json', './dist/filer.js', './dist/filer.min.js'],
createTag: true,
tagName: 'v%VERSION%',
tagMessage: 'v%VERSION%',
push: true,
pushTo: GIT_FULL_REMOTE
}
},
'npm-checkBranch': {
options: {
branch: GIT_BRANCH
}
},
'npm-publish': {
options: {
abortIfDirty: false
}
},
prompt: {
confirm: {
options: {
questions: [
{
config: PROMPT_CONFIRM_CONFIG,
type: 'confirm',
message: 'Bump version from ' + (currentVersion).cyan +
' to ' + semver.inc(currentVersion, "patch").yellow + '?',
default: false
}
],
then: function(results) {
if (!results[PROMPT_CONFIRM_CONFIG]) {
return grunt.fatal('User aborted...');
}
}
}
}
},
gitcheckout: {
publish: {
options: {
branch: 'gh-pages',
force: true
}
},
revert: {
options: {
branch: GIT_BRANCH
}
}
},
gitpush: {
publish: {
options: {
remote: GIT_REMOTE,
branch: 'gh-pages',
force: true
},
}
},
gitcommit: {
publish: {
options: {
noStatus: true
}
}
},
gitadd: {
publish: {
files: {
src: ['./dist/filer-test.js']
}
}
},
gitstash: {
publish: {
},
pop: {
options: {
command: "pop"
}
}
},
gitrm: {
publish: {
files: {
src: ['./dist/filer-test.js']
}
}
},
connect: {
2014-05-26 20:57:08 +00:00
serverForNode: {
options: {
port: 1234,
base: '.'
}
},
2014-05-26 20:57:08 +00:00
serverForBrowser: {
options: {
port: 1234,
base: '.',
keepalive: true
}
}
},
usebanner: {
publish: {
options: {
position: "top"
},
files: {
src: ['./dist/filer-test.js']
}
}
}
});
grunt.loadNpmTasks('grunt-contrib-clean');
grunt.loadNpmTasks('grunt-contrib-uglify');
grunt.loadNpmTasks('grunt-contrib-jshint');
grunt.loadNpmTasks('grunt-contrib-connect');
grunt.loadNpmTasks('grunt-bump');
grunt.loadNpmTasks('grunt-npm');
grunt.loadNpmTasks('grunt-git');
grunt.loadNpmTasks('grunt-prompt');
grunt.loadNpmTasks('grunt-shell');
grunt.loadNpmTasks('grunt-contrib-connect');
grunt.loadNpmTasks('grunt-browserify');
grunt.loadNpmTasks('grunt-banner');
grunt.registerTask('develop', ['clean', 'browserify:filerDist', 'browserify:filerIssue225']);
2014-05-26 20:57:08 +00:00
grunt.registerTask('build-tests', ['clean', 'browserify:filerTest']);
2014-05-27 18:51:55 +00:00
grunt.registerTask('release', ['test', 'develop', 'uglify']);
grunt.registerTask('publish', 'Publish filer as a new version to NPM, bower and github.', function(patchLevel) {
var allLevels = ['patch', 'minor', 'major'];
// No level specified defaults to 'patch'
patchLevel = (patchLevel || 'patch').toLowerCase();
// Fail out if the patch level isn't recognized
if (allLevels.filter(function(el) { return el == patchLevel; }).length === 0) {
return grunt.fatal('Patch level not recognized! "Patch", "minor" or "major" only.');
}
// Set prompt message
var promptOpts = grunt.config('prompt.confirm.options');
promptOpts.questions[0].message = 'Bump version from ' + (currentVersion).cyan +
' to ' + semver.inc(currentVersion, patchLevel).yellow + '?';
grunt.config('prompt.confirm.options', promptOpts);
// Store the new version in the gh-pages commit message
var ghPagesMessage = 'Tests for Filer v' + semver.inc(currentVersion, patchLevel);
grunt.config('gitcommit.publish.options.message', ghPagesMessage);
// Store the new version as a banner in the test file
// NOTE: This is a hack intended to ensure that this build process
// succeeds even if no changes were made to the tests
// before publishing a new version. Otherwise, the automatic
// commit + push to github pages would break a normal build
var bannerMsg = "/* Test file for filerjs v" + semver.inc(currentVersion, patchLevel) + "*/";
grunt.config('usebanner.publish.options.banner', bannerMsg);
grunt.task.run([
'prompt:confirm',
'checkBranch',
'release',
'bump:' + patchLevel,
'build-tests',
'usebanner:publish',
'gitadd:publish',
'gitstash:publish',
'gitcheckout:publish',
'gitrm:publish',
'gitstash:pop',
'gitcommit:publish',
'gitpush:publish',
'gitcheckout:revert',
'npm-publish'
]);
});
grunt.registerTask('test-node', ['jshint', 'browserify:filerIssue225', 'connect:serverForNode', 'shell:mocha']);
2014-05-26 20:57:08 +00:00
grunt.registerTask('test-browser', ['jshint', 'build-tests', 'connect:serverForBrowser']);
grunt.registerTask('test', ['clean', 'test-node']);
grunt.registerTask('default', ['test']);
};