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-05-21 17:06:37 +00:00
|
|
|
clean: ['dist/filer-test.js', 'dist/filer_node-test.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-16 17:28:48 +00:00
|
|
|
shell: {
|
|
|
|
mocha: {
|
|
|
|
command: './node_modules/.bin/mocha --reporter list --no-exit tests/node-runner.js'
|
2014-01-21 21:25:09 +00:00
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2013-03-11 19:14:26 +00:00
|
|
|
requirejs: {
|
2014-05-21 17:06:37 +00:00
|
|
|
browser_develop: {
|
2013-03-11 19:14:26 +00:00
|
|
|
options: {
|
|
|
|
paths: {
|
|
|
|
"src": "../src",
|
2014-03-12 20:49:20 +00:00
|
|
|
"build": "../build"
|
2013-03-11 19:14:26 +00:00
|
|
|
},
|
|
|
|
baseUrl: "lib",
|
|
|
|
name: "build/almond",
|
2013-12-15 03:36:24 +00:00
|
|
|
include: ["src/index"],
|
2014-01-14 15:56:36 +00:00
|
|
|
out: "dist/filer.js",
|
2013-03-11 19:14:26 +00:00
|
|
|
optimize: "none",
|
|
|
|
wrap: {
|
2014-05-21 17:06:37 +00:00
|
|
|
startFile: 'build/browser_wrap.start',
|
|
|
|
endFile: 'build/browser_wrap.end'
|
2013-11-27 18:08:26 +00:00
|
|
|
},
|
|
|
|
shim: {
|
2013-12-02 20:10:43 +00:00
|
|
|
// TextEncoder and TextDecoder shims. encoding-indexes must get loaded first,
|
|
|
|
// and we use a fake one for reduced size, since we only care about utf8.
|
2013-11-27 18:08:26 +00:00
|
|
|
"encoding": {
|
2013-12-02 20:10:43 +00:00
|
|
|
deps: ["encoding-indexes-shim"]
|
2013-11-27 18:08:26 +00:00
|
|
|
}
|
2013-03-11 19:14:26 +00:00
|
|
|
}
|
|
|
|
}
|
2014-05-17 18:44:29 +00:00
|
|
|
},
|
2014-05-21 17:06:37 +00:00
|
|
|
node_develop: {
|
|
|
|
options: {
|
|
|
|
paths: {
|
|
|
|
"src": "../src",
|
|
|
|
"build": "../build"
|
|
|
|
},
|
|
|
|
baseUrl: "lib",
|
|
|
|
name: "require",
|
|
|
|
include: ["src/index"],
|
|
|
|
out: "dist/filer_node.js",
|
|
|
|
optimize: "none",
|
|
|
|
wrap: {
|
|
|
|
startFile: 'build/node_wrap.start',
|
|
|
|
endFile: 'build/node_wrap.end'
|
|
|
|
},
|
|
|
|
shim: {
|
|
|
|
// TextEncoder and TextDecoder shims. encoding-indexes must get loaded first,
|
|
|
|
// and we use a fake one for reduced size, since we only care about utf8.
|
|
|
|
"encoding": {
|
|
|
|
deps: ["encoding-indexes-shim"]
|
|
|
|
}
|
|
|
|
},
|
|
|
|
nodeRequire: require
|
|
|
|
}
|
|
|
|
},
|
|
|
|
browser_test: {
|
2014-05-17 18:44:29 +00:00
|
|
|
options: {
|
|
|
|
paths: {
|
|
|
|
"src": "../src",
|
|
|
|
"build": "../build"
|
|
|
|
},
|
|
|
|
baseUrl: "lib",
|
|
|
|
name: "build/almond",
|
|
|
|
include: ["src/index"],
|
|
|
|
out: "dist/filer-test.js",
|
|
|
|
optimize: "none",
|
|
|
|
wrap: {
|
2014-05-21 17:06:37 +00:00
|
|
|
startFile: 'build/browser_wrap.start',
|
|
|
|
endFile: 'build/browser_wrap.end'
|
2014-05-17 18:44:29 +00:00
|
|
|
},
|
|
|
|
shim: {
|
|
|
|
// TextEncoder and TextDecoder shims. encoding-indexes must get loaded first,
|
|
|
|
// and we use a fake one for reduced size, since we only care about utf8.
|
|
|
|
"encoding": {
|
|
|
|
deps: ["encoding-indexes-shim"]
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2014-05-21 17:06:37 +00:00
|
|
|
},
|
|
|
|
node_test: {
|
|
|
|
options: {
|
|
|
|
paths: {
|
|
|
|
"src": "../src",
|
|
|
|
"build": "../build"
|
|
|
|
},
|
|
|
|
baseUrl: "lib",
|
|
|
|
name: "require",
|
|
|
|
include: ["src/index"],
|
|
|
|
out: "dist/filer_node-test.js",
|
|
|
|
optimize: "none",
|
|
|
|
wrap: {
|
|
|
|
startFile: 'build/node_wrap.start',
|
|
|
|
endFile: 'build/node_wrap.end'
|
|
|
|
},
|
|
|
|
shim: {
|
|
|
|
// TextEncoder and TextDecoder shims. encoding-indexes must get loaded first,
|
|
|
|
// and we use a fake one for reduced size, since we only care about utf8.
|
|
|
|
"encoding": {
|
|
|
|
deps: ["encoding-indexes-shim"]
|
|
|
|
}
|
|
|
|
},
|
|
|
|
nodeRequire: require
|
|
|
|
}
|
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%',
|
|
|
|
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: true
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
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',
|
|
|
|
overwrite: true
|
|
|
|
}
|
|
|
|
},
|
|
|
|
revert: {
|
|
|
|
options: {
|
|
|
|
branch: GIT_BRANCH
|
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
gitpush: {
|
|
|
|
publish: {
|
|
|
|
options: {
|
|
|
|
remote: GIT_REMOTE,
|
|
|
|
branch: 'gh-pages',
|
|
|
|
force: true
|
2014-05-19 20:47:24 +00:00
|
|
|
},
|
|
|
|
}
|
|
|
|
},
|
|
|
|
connect: {
|
|
|
|
server_for_node: {
|
|
|
|
options: {
|
|
|
|
port: 1234,
|
|
|
|
base: '.'
|
|
|
|
}
|
|
|
|
},
|
|
|
|
server_for_browser: {
|
|
|
|
options: {
|
|
|
|
port: 1234,
|
|
|
|
base: '.',
|
|
|
|
keepalive: true
|
2014-05-14 16:16:14 +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');
|
|
|
|
grunt.loadNpmTasks('grunt-contrib-requirejs');
|
2013-11-08 20:33:44 +00:00
|
|
|
grunt.loadNpmTasks('grunt-contrib-jshint');
|
2014-01-21 21:25:09 +00:00
|
|
|
grunt.loadNpmTasks('grunt-mocha');
|
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');
|
2013-03-11 19:14:26 +00:00
|
|
|
|
2014-05-21 17:06:37 +00:00
|
|
|
grunt.registerTask('develop', ['clean', 'requirejs:browser_develop', 'requirejs:node_develop']);
|
|
|
|
grunt.registerTask('filer-test', ['clean', 'requirejs:node_test', 'requirejs:browser_test']);
|
2013-03-11 19:14:26 +00:00
|
|
|
grunt.registerTask('release', ['develop', 'uglify']);
|
2013-11-08 20:33:44 +00:00
|
|
|
grunt.registerTask('check', ['jshint']);
|
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);
|
|
|
|
|
|
|
|
grunt.task.run([
|
|
|
|
'prompt:confirm',
|
|
|
|
'checkBranch',
|
|
|
|
'release',
|
|
|
|
'bump:' + patchLevel,
|
|
|
|
'gitcheckout:publish',
|
|
|
|
'gitpush:publish',
|
|
|
|
'gitcheckout:revert',
|
|
|
|
'npm-publish'
|
|
|
|
]);
|
|
|
|
});
|
2014-05-19 20:47:24 +00:00
|
|
|
grunt.registerTask('test-node', ['check', 'filer-test', 'connect:server_for_node', 'shell:mocha']);
|
|
|
|
grunt.registerTask('test-browser', ['check', 'filer-test', 'connect:server_for_browser']);
|
|
|
|
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
|
|
|
};
|