Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Grunt build and proper bower.json #91

Open
wants to merge 10 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .bowerrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"directory": "bower_components"
}
17 changes: 17 additions & 0 deletions .eslintrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{
"extends": [
"eslint:recommended"
],
"env": {
"node": true,
"browser": true,
"es6": true,
"jquery": true,
"mocha": true,
"amd": true
},
"rules": {
"quotes": [2, "double"],
"indent": [2, 3]
}
}
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
node_modules
bower_components
.tmp
.sass-cache
.svn
16 changes: 16 additions & 0 deletions .ibn-battutarc
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{
"src": "src",
"test": "test",
"dist": "dist",
"temp": ".tmp",
"browserSync": {
"testPort": 9998,
"testHost": "localhost"
},
"optimize": {
"js": {
"concat": true,
"minify": true
}
}
}
273 changes: 273 additions & 0 deletions Gruntfile.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,273 @@
/**
* @description The Gruntfile.js - build file. Tragets are:
* - grunt test
* - grunt package // package for production
* - options --concat, --minify, --no-concat, --no-minify
* - grunt // test, package
*
* @author Fahim Farook
*
*/
module.exports = function(grunt) {

"use strict";

// display the elapsed execution time of grunt tasks
require("time-grunt")(grunt);

// load grunt plugins automatically by looking at task names
// so no need explicit loading. i.e. grunt.loadNpmTasks('grunt-contrib-clean');
// task -- plugin matching rules
// - <task> -> <task>
// - <task> -> grunt-<task>
// - <task> -> grunt-contrib-<task>
require("jit-grunt")(grunt, {
// for tasks whose name doesn't match the plugin name, load it explicitily.
useminPrepare: "grunt-usemin"
});

// build properties
// build properties
var config = (function() {
var build = grunt.file.readJSON(".ibn-battutarc");
if (!build) {
grunt.fail.fatal([".ibn-battutarc doesnt exists"]);
}

// optimize
var defaults = {
js: {
minify: true,
concat: true
}
}
if (!build.optimize) {
grunt.log.error([".ibn-battutarc doesnt define optimize. Commnad line options or defaults will be used."]);
build.optimize = defaults;
} else {
for (var prop in defaults) {
if (!build.optimize[prop]) {
build.optimize[prop] = {};
}
}
}

// dirs
if (!(build.src && build.test && build.dist && build.temp)) {
grunt.fail.fatal([".ibn-battutarc doesnt define mandatory directories: src, test, dist, temp"]);
}

// .bowerrc
var bower = grunt.file.readJSON(".bowerrc");
if (bower) {
build.bower = bower;
} else {
build.bower = {
directory: "bower_components"
};
}
// bower.json
bower = grunt.file.readJSON("bower.json");
if (!bower || !bower.main) {
grunt.fail.fatal(["bower.json or main section in bower.json is missing. bower.json=" + bower]);
}
for (prop in bower) {
if (bower.hasOwnProperty(prop)) {
build.bower[prop] = bower[prop];
}
}

// routes
var routes = {};
routes["/" + build.bower.directory] = "./" + build.bower.directory;
build.routes = routes;

return build;
}());

// configuring grunt...
grunt.initConfig({

// settings
config: config,

// delete files/ directories
clean: {
dist: {
files: [{
dot: true, // .tmp
src: [
"<%= config.dist %>",
"<%= config.temp %>"
]
}]
},
temp: ["<%= config.temp %>"]
},

// copy resources to dist or tmp
copy: {
// copy js files
// from: src, to: temp
// to allow minification (without requirejs)
js_src_temp: {
expand: true,
dot: true,
cwd: "<%= config.src %>",
src: "**/*.js",
dest: "<%= config.temp %>"
},
// copy js files
// from: temp, to: dist
js_temp_dist: {
expand: true,
dot: true,
cwd: "<%= config.temp %>",
src: "**/*.js",
dest: "<%= config.dist %>"
}
},

concat: {
dist: {
src: ["<%= config.src %>/**/*.js"],
dest: "<%= config.temp %>/<%= config.bower.main %>"
}
},

// minify js files
uglify: {
target: {
options: {
mangle: false
},
files: [{
expand: true,
cwd: "<%= config.temp %>",
src: ["**/*.js", "!**/*.min.css"],
dest: "<%= config.dist %>"
}]
}
},

// run predefined tasks whenever watched file patterns are added, changed or deleted.
watch: {
// by default, if Gruntfile.js is being watched, then changes to it will trigger the watch task to restart
gruntfile: {
files: ["Gruntfile.js"]
},
scripts: {
files: ["<%= config.src %>/**/*.js"],
tasks: ["eslint"]
},
testScripts: {
files: ["<%= config.test %>/**/*.js"],
tasks: ["test"] // registered test task - basically run mocha
}
},

// start browserSync web server - for unit testing only
// https://github.com/Browsersync/recipes
// http://www.browsersync.io/docs/options/
browserSync: {
options: {
notify: false, // don't show any ui notifications in the browser.
background: true
},
fromTest: {
options: {
port: config.browserSync.testPort,
host: config.browserSync.testHost,
open: false,
server: {
baseDir: [config.temp, config.test, config.src],
routes: config.routes // The key - url to match : value - which folder to serve (relative to current directory)
}
}
}
},

// validate javascript
eslint: {
options: {
configFile: ".eslintrc" // where to find eslint configurations
},
target: [
"Gruntfile.js",
"<%= config.src %>/**/*.js",
"<%= config.test %>/**/*.js",
"!**/<%= config.bower.directory %>/**/*.js"
]
},

// mocha unit test configurations
mocha: {
task: {
options: {
run: true, // inject mocha run code to html. i.e. mocha.run(); into following url page
// urls to test via browserSync server
urls: ["http://<%= browserSync.fromTest.options.host %>:<%= browserSync.fromTest.options.port %>/index.html"]
},
dest: "<%= config.temp %>/mocha.out" // test report
}
}
});

// usage: grunt test
grunt.registerTask("test", function() {
grunt.task.run([
"clean:temp",
"browserSync:fromTest",
"mocha"
]);
});

// usage
// grunt package - package for production. Concat and minify based on settings provided in .zahrawirc
// grunt package --concat - Overrides settings provided in .zahrawirc
// grunt package --minify - Overrides settings provided in .zahrawirc
// grunt package --no-concat - Overrides settings provided in .zahrawirc
// grunt package --no-minify - Overrides settings provided in .zahrawirc
grunt.registerTask("package", function() {
// do configs
var options = [
"concat",
"minify",
"no-concat",
"no-minify"
];

for (var i = 0, len = options.length; i < len; i++) {
if (grunt.option(options[i])) {
var opts = options[i].split("-");

var val = opts[0] === "no" ? false : true;
var action = opts[opts.length - 1]; // concat or minify
config.optimize.js[action] = val;
}
}

var tasks = ["clean"]; // both .tmp and dist

if (config.optimize.js.concat) {
tasks.push("concat");
} else {
tasks.push("copy:js_src_temp"); // 2.a
}

if (config.optimize.js.minify) { // minify
tasks.push("uglify");
} else {
tasks.push("copy:js_temp_dist");
}

grunt.task.run(tasks);
});

// usage: grunt
grunt.registerTask("default", [
"newer:eslint",
"test",
"package"
]);
};
6 changes: 4 additions & 2 deletions README.markdown
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
# PathJS #
# Forked from PathJS #

PathJS is a lightweight, client-side routing library that allows you to create "single page" applications using Hashbangs and/or HTML5 pushState.
PathJS is a lightweight, client-side routing library that allows you to create "single page" applications using Hashbangs and/or HTML5 pushState.

Even though PathJS available on bower, it does not have proper bower.json with main:{} section. Also the bower.json files are missing on git repository. Ibn-Battuta is the restructured version of Path JS with proper bower configurations.

# Features #
* Lightweight
Expand Down
24 changes: 24 additions & 0 deletions bower.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
{
"name": "ibn-battuta",
"description": "Bower friendly routing libraray forked from PathJS",
"main": "dist/ibn-battuta.min.js",
"authors": [
"Fahim Farook"
],
"license": "ISC",
"keywords": [
"router",
"pathjs"
],
"moduleType": [
"globals"
],
"homepage": "https://github.com/fahimfarookme/ibn-battuta#readme",
"ignore": [
"**/.*",
"node_modules",
"bower_components",
"test",
"tests"
]
}
1 change: 1 addition & 0 deletions dist/ibn-battuta.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

39 changes: 39 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
{
"name": "ibn-battuta",
"version": "1.0.1",
"description": "Bower friendly routing libraray forked from PathJS",
"main": "ibn-battuta.min.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"repository": {
"type": "git",
"url": "git+https://github.com/fahimfarookme/ibn-battuta.git"
},
"keywords": [
"router",
"pathjs"
],
"author": "Fahim Farook",
"license": "ISC",
"bugs": {
"url": "https://github.com/fahimfarookme/ibn-battuta/issues"
},
"homepage": "https://github.com/fahimfarookme/ibn-battuta#readme",
"devDependencies": {
"eslint": "^2.2.0",
"grunt": "^0.4.5",
"grunt-browser-sync": "^2.1.2",
"grunt-concurrent": "^1.0.0",
"grunt-contrib-clean": "^0.6.0",
"grunt-contrib-concat": "^0.5.1",
"grunt-contrib-copy": "^0.8.2",
"grunt-contrib-uglify": "^0.10.0",
"grunt-contrib-watch": "^0.6.1",
"grunt-eslint": "^17.3.1",
"grunt-mocha": "^0.4.13",
"grunt-newer": "^1.1.1",
"jit-grunt": "^0.9.1",
"time-grunt": "^1.2.2"
}
}
Loading