2014-05-14 16:16:14 +00:00
|
|
|
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;
|
|
|
|
|
2013-03-11 19:14:26 +00:00
|
|
|
module.exports = function(grunt) {
|
|
|
|
// Project configuration.
|
|
|
|
grunt.initConfig({
|
|
|
|
pkg: grunt.file.readJSON('package.json'),
|
|
|
|
|
2014-12-16 23:53:29 +00:00
|
|
|
clean: ['dist/filer-test.js', 'dist/filer-issue225.js', 'dist/filer-perf.js'],
|
2013-03-11 19:14:26 +00:00
|
|
|
|
|
|
|
uglify: {
|
|
|
|
options: {
|
2014-05-14 16:16:14 +00:00
|
|
|
banner: '/*! <%= pkg.name %> <%= pkg.version %> <%= grunt.template.today("yyyy-mm-dd") %> */\n'
|
2013-03-11 19:14:26 +00:00
|
|
|
},
|
|
|
|
develop: {
|
2014-01-14 15:56:36 +00:00
|
|
|
src: 'dist/filer.js',
|
|
|
|
dest: 'dist/filer.min.js'
|
2013-03-11 19:14:26 +00:00
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2013-11-08 20:33:44 +00:00
|
|
|
jshint: {
|
|
|
|
// Don't bother with src/path.js
|
2014-02-15 20:43:38 +00:00
|
|
|
all: [
|
|
|
|
'gruntfile.js',
|
2014-05-14 16:16:14 +00:00
|
|
|
'config/environment.js',
|
2014-02-15 20:43:38 +00:00
|
|
|
'src/constants.js',
|
2014-03-10 18:28:22 +00:00
|
|
|
'src/errors.js',
|
2014-02-15 20:43:38 +00:00
|
|
|
'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',
|
2014-02-15 20:43:38 +00:00
|
|
|
'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'
|
2014-02-15 20:43:38 +00:00
|
|
|
]
|
2013-11-08 20:33:44 +00:00
|
|
|
},
|
|
|
|
|
2014-05-26 17:57:20 +00:00
|
|
|
browserify: {
|
2014-05-26 20:57:08 +00:00
|
|
|
filerDist: {
|
2014-05-26 17:57:20 +00:00
|
|
|
src: "./src/index.js",
|
|
|
|
dest: "./dist/filer.js",
|
2014-05-21 17:06:37 +00:00
|
|
|
options: {
|
2014-05-26 20:29:46 +00:00
|
|
|
browserifyOptions: {
|
|
|
|
commondir: false
|
2014-05-27 14:32:41 +00:00
|
|
|
},
|
2014-05-28 18:48:00 +00:00
|
|
|
bundleOptions: {
|
|
|
|
standalone: 'Filer'
|
|
|
|
},
|
2014-05-27 14:32:41 +00:00
|
|
|
exclude: ["./node_modules/request/index.js"]
|
2014-12-03 22:25:30 +00:00
|
|
|
}
|
|
|
|
},
|
2014-12-16 23:53:29 +00:00
|
|
|
filerPerf: {
|
|
|
|
src: "./perf/index.js",
|
|
|
|
dest: "./dist/filer-perf.js",
|
2014-12-03 22:25:30 +00:00
|
|
|
options: {
|
|
|
|
browserifyOptions: {
|
|
|
|
commondir: false
|
|
|
|
},
|
|
|
|
bundleOptions: {
|
|
|
|
standalone: 'Filer'
|
|
|
|
}
|
2014-05-21 17:06:37 +00:00
|
|
|
}
|
|
|
|
},
|
2014-05-26 20:57:08 +00:00
|
|
|
filerTest: {
|
2014-05-26 20:29:46 +00:00
|
|
|
src: "./tests/index.js",
|
2014-05-28 18:48:00 +00:00
|
|
|
dest: "./dist/filer-test.js"
|
2014-06-11 14:54:43 +00:00
|
|
|
},
|
|
|
|
// See tests/bugs/issue225.js
|
|
|
|
filerIssue225: {
|
|
|
|
src: "./src/index.js",
|
|
|
|
dest: "./dist/filer-issue225.js",
|
|
|
|
options: {
|
|
|
|
browserifyOptions: {
|
|
|
|
commondir: false
|
|
|
|
},
|
|
|
|
bundleOptions: {
|
|
|
|
standalone: 'Filer'
|
|
|
|
}
|
|
|
|
}
|
2014-05-26 17:57:20 +00:00
|
|
|
}
|
2014-05-21 17:06:37 +00:00
|
|
|
},
|
2014-05-26 17:57:20 +00:00
|
|
|
|
|
|
|
shell: {
|
|
|
|
mocha: {
|
2014-06-11 14:54:43 +00:00
|
|
|
// 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'
|
2013-03-11 19:14:26 +00:00
|
|
|
}
|
2014-05-14 16:16:14 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
bump: {
|
|
|
|
options: {
|
|
|
|
files: ['package.json', 'bower.json'],
|
|
|
|
commit: true,
|
|
|
|
commitMessage: 'v%VERSION%',
|
2014-11-06 15:59:51 +00:00
|
|
|
commitFiles: ['package.json', 'bower.json', './dist/filer.js', './dist/filer.min.js'],
|
2014-05-14 16:16:14 +00:00
|
|
|
createTag: true,
|
|
|
|
tagName: 'v%VERSION%',
|
|
|
|
tagMessage: 'v%VERSION%',
|
|
|
|
push: true,
|
|
|
|
pushTo: GIT_FULL_REMOTE
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
'npm-checkBranch': {
|
|
|
|
options: {
|
|
|
|
branch: GIT_BRANCH
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
'npm-publish': {
|
|
|
|
options: {
|
2014-05-27 18:47:52 +00:00
|
|
|
abortIfDirty: false
|
2014-05-14 16:16:14 +00:00
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
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',
|
2014-11-11 23:29:55 +00:00
|
|
|
force: true
|
2014-05-14 16:16:14 +00:00
|
|
|
}
|
|
|
|
},
|
|
|
|
revert: {
|
|
|
|
options: {
|
|
|
|
branch: GIT_BRANCH
|
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
gitpush: {
|
|
|
|
publish: {
|
|
|
|
options: {
|
|
|
|
remote: GIT_REMOTE,
|
|
|
|
branch: 'gh-pages',
|
|
|
|
force: true
|
2014-05-19 20:47:24 +00:00
|
|
|
},
|
|
|
|
}
|
|
|
|
},
|
2014-11-06 15:59:51 +00:00
|
|
|
|
2014-11-11 23:29:55 +00:00
|
|
|
gitcommit: {
|
2014-11-06 15:59:51 +00:00
|
|
|
publish: {
|
|
|
|
options: {
|
2014-11-11 23:29:55 +00:00
|
|
|
noStatus: true
|
|
|
|
}
|
2014-11-06 15:59:51 +00:00
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2014-11-11 23:29:55 +00:00
|
|
|
gitadd: {
|
|
|
|
publish: {
|
|
|
|
files: {
|
2014-12-17 07:52:20 +00:00
|
|
|
src: ['./dist/filer-test.js', './dist/filer-perf.js']
|
2014-11-11 23:29:55 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
gitstash: {
|
2014-11-06 15:59:51 +00:00
|
|
|
publish: {
|
2014-11-11 23:29:55 +00:00
|
|
|
},
|
|
|
|
pop: {
|
2014-11-06 15:59:51 +00:00
|
|
|
options: {
|
2014-11-11 23:29:55 +00:00
|
|
|
command: "pop"
|
2014-11-06 15:59:51 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2014-11-11 23:29:55 +00:00
|
|
|
gitrm: {
|
2014-11-06 15:59:51 +00:00
|
|
|
publish: {
|
2014-12-17 07:47:48 +00:00
|
|
|
options: {
|
|
|
|
force: true
|
|
|
|
},
|
2014-11-06 15:59:51 +00:00
|
|
|
files: {
|
2014-12-17 07:52:20 +00:00
|
|
|
src: ['./dist/filer-test.js', './dist/filer-perf.js']
|
2014-11-06 15:59:51 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2014-05-19 20:47:24 +00:00
|
|
|
connect: {
|
2014-05-26 20:57:08 +00:00
|
|
|
serverForBrowser: {
|
2014-05-19 20:47:24 +00:00
|
|
|
options: {
|
|
|
|
port: 1234,
|
2015-01-20 19:56:48 +00:00
|
|
|
base: './',
|
2014-05-19 20:47:24 +00:00
|
|
|
keepalive: true
|
2014-05-14 16:16:14 +00:00
|
|
|
}
|
|
|
|
}
|
2014-11-11 23:29:55 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
usebanner: {
|
|
|
|
publish: {
|
|
|
|
options: {
|
|
|
|
position: "top"
|
|
|
|
},
|
|
|
|
files: {
|
2014-12-16 23:53:29 +00:00
|
|
|
src: ['./dist/filer-test.js', './dist/filer-perf.js']
|
2014-11-11 23:29:55 +00:00
|
|
|
}
|
|
|
|
}
|
2013-11-27 18:08:26 +00:00
|
|
|
}
|
2013-03-11 19:14:26 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
grunt.loadNpmTasks('grunt-contrib-clean');
|
|
|
|
grunt.loadNpmTasks('grunt-contrib-uglify');
|
2013-11-08 20:33:44 +00:00
|
|
|
grunt.loadNpmTasks('grunt-contrib-jshint');
|
2014-03-27 01:07:10 +00:00
|
|
|
grunt.loadNpmTasks('grunt-contrib-connect');
|
2014-05-14 16:16:14 +00:00
|
|
|
grunt.loadNpmTasks('grunt-bump');
|
|
|
|
grunt.loadNpmTasks('grunt-npm');
|
|
|
|
grunt.loadNpmTasks('grunt-git');
|
|
|
|
grunt.loadNpmTasks('grunt-prompt');
|
2014-05-16 17:28:48 +00:00
|
|
|
grunt.loadNpmTasks('grunt-shell');
|
2014-05-19 20:47:24 +00:00
|
|
|
grunt.loadNpmTasks('grunt-contrib-connect');
|
2014-05-26 17:57:20 +00:00
|
|
|
grunt.loadNpmTasks('grunt-browserify');
|
2014-11-11 23:29:55 +00:00
|
|
|
grunt.loadNpmTasks('grunt-banner');
|
2013-03-11 19:14:26 +00:00
|
|
|
|
2015-01-20 19:56:48 +00:00
|
|
|
grunt.registerTask('develop', ['browserify:filerDist', 'uglify']);
|
|
|
|
grunt.registerTask('build-tests', ['clean', 'browserify:filerTest', 'browserify:filerPerf', 'browserify:filerIssue225']);
|
|
|
|
grunt.registerTask('release', ['test', 'develop']);
|
2013-03-11 19:14:26 +00:00
|
|
|
|
2014-05-14 16:16:14 +00:00
|
|
|
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);
|
|
|
|
|
2014-11-11 23:29:55 +00:00
|
|
|
// 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);
|
|
|
|
|
2014-05-14 16:16:14 +00:00
|
|
|
grunt.task.run([
|
|
|
|
'prompt:confirm',
|
|
|
|
'checkBranch',
|
|
|
|
'release',
|
|
|
|
'bump:' + patchLevel,
|
2014-11-06 15:59:51 +00:00
|
|
|
'build-tests',
|
2014-11-11 23:29:55 +00:00
|
|
|
'usebanner:publish',
|
2014-11-06 15:59:51 +00:00
|
|
|
'gitadd:publish',
|
2014-11-11 23:29:55 +00:00
|
|
|
'gitstash:publish',
|
|
|
|
'gitcheckout:publish',
|
|
|
|
'gitrm:publish',
|
|
|
|
'gitstash:pop',
|
2014-11-06 15:59:51 +00:00
|
|
|
'gitcommit:publish',
|
2014-05-14 16:16:14 +00:00
|
|
|
'gitpush:publish',
|
|
|
|
'gitcheckout:revert',
|
|
|
|
'npm-publish'
|
|
|
|
]);
|
|
|
|
});
|
2015-01-20 19:56:48 +00:00
|
|
|
grunt.registerTask('test-node', ['jshint', 'browserify:filerIssue225', 'shell:mocha']);
|
2014-05-26 20:57:08 +00:00
|
|
|
grunt.registerTask('test-browser', ['jshint', 'build-tests', 'connect:serverForBrowser']);
|
2015-01-20 19:56:48 +00:00
|
|
|
grunt.registerTask('test', ['test-node']);
|
2014-05-14 16:16:14 +00:00
|
|
|
|
2014-05-16 18:34:01 +00:00
|
|
|
grunt.registerTask('default', ['test']);
|
2013-11-22 21:12:31 +00:00
|
|
|
};
|