Skip to content

Commit

Permalink
updated
Browse files Browse the repository at this point in the history
  • Loading branch information
WebReflection committed Jun 18, 2015
1 parent 8dc6901 commit e36b2c7
Show file tree
Hide file tree
Showing 11 changed files with 204 additions and 11 deletions.
5 changes: 4 additions & 1 deletion .npmignore
@@ -1,7 +1,10 @@
src/*
test/*
template/*
utils/*
node_modules/*
build/*.amd.js
Makefile
index.html
index.html
.travis.yml
testrunner.js
3 changes: 2 additions & 1 deletion .travis.yml
@@ -1,7 +1,8 @@
language: node_js
node_js:
- 0.8
- 0.9
- 0.10
- 0.12
git:
depth: 1
branches:
Expand Down
2 changes: 1 addition & 1 deletion LICENSE.txt
@@ -1,4 +1,4 @@
Copyright (C) 2013 by WebReflection
Copyright (C) 2015 by WebReflection

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
22 changes: 20 additions & 2 deletions Makefile
Expand Up @@ -123,5 +123,23 @@ dependencies:
npm install uglify-js@1
npm install jshint
npm install markdown


npm install browserify
npm install watchify

# bundle: creates the browserified version of the project as js/bundle.max.js
bundle:
sh utils/browserify.sh

# watch: update the browserified version of the project as soon as file changes
watch:
sh utils/watchify.sh

# minified: create the minifeid version of the project as js/bundle.js
minified:
make -s bundle
sh utils/uglifyjs.sh $(LICENSE)
make -s size

# jshint: recursively checks for javascript files inside the src folder and lint them
jshint:
sh utils/jshint.sh
4 changes: 3 additions & 1 deletion index.html
Expand Up @@ -11,7 +11,9 @@
var TESTS = ["main"];
</script>
<script>// don't change code here
for(var i = 0; i < TESTS.length; ++i && document.write('<script src="src/' + TESTS + '.js"><' + '/script>'));
for(var i = 0; i < TESTS.length; ++i && document.write(
'<script src="build/' + TESTS[i] + '.js"><' + '/script>'
));
function wru(wru){
var
all = [],
Expand Down
18 changes: 13 additions & 5 deletions package.json
Expand Up @@ -6,18 +6,26 @@
"homepage": "https://github.com/WebReflection/main",
"keywords": [],
"author": {
"name": "",
"web": ""
"name": "Andrea Giammarchi",
"web": "http://webreflection.blogspot.com/"
},
"repository": {
"type": "git",
"url": "git://github.com/WebReflection/main.git"
},
"main": "./build/main.node.js",
"scripts": {
"test": "node test/.test.js"
"test": "node test/.test.js",
"test": "phantomjs testrunner.js",
"web": "IP=0.0.0.0 node node_modules/polpetta"
},
"dependencies": {
"wru": ">= 0.0.0"
"devDependencies": {
"wru": "~0.2.x",
"uglify-js": "1.x",
"jshint": "~2.x",
"polpetta": "~0.3.x",
"phantomjs": "~1.x",
"browserify": "~0.0.0",
"watchify": "~0.0.0"
}
}
52 changes: 52 additions & 0 deletions testruner.js
@@ -0,0 +1,52 @@
console.log('Loading: test.html');
var page = require('webpage').create();
var url = 'index.html';
page.open(url, function (status) {
if (status === 'success') {
setTimeout(function () {
var results = page.evaluate(function() {
// remove the first node with the total from the following counts
var passed = Math.max(0, document.querySelectorAll('.pass').length - 1);
return {
// retrieve the total executed tests number
total: ''.concat(
passed,
' blocks (',
document.querySelector('#wru strong').textContent.replace(/\D/g, ''),
' single tests)'
),
passed: passed,
failed: Math.max(0, document.querySelectorAll('.fail').length - 1),
failures: [].map.call(document.querySelectorAll('.fail'), function (node) {
return node.textContent;
}),
errored: Math.max(0, document.querySelectorAll('.error').length - 1),
errors: [].map.call(document.querySelectorAll('.error'), function (node) {
return node.textContent;
})
};
});
console.log('- - - - - - - - - -');
console.log('total: ' + results.total);
console.log('- - - - - - - - - -');
console.log('passed: ' + results.passed);
if (results.failed) {
console.log('failures: \n' + results.failures.join('\n'));
} else {
console.log('failed: ' + results.failed);
}
if (results.errored) {
console.log('errors: \n' + results.errors.join('\n'));
} else {
console.log('errored: ' + results.errored);
}
console.log('- - - - - - - - - -');
if (0 < results.failed + results.errored) {
status = 'failed';
}
phantom.exit(0);
}, 2000);
} else {
phantom.exit(1);
}
});
23 changes: 23 additions & 0 deletions utils/browserify.sh
@@ -0,0 +1,23 @@
#!/usr/bin/env bash

program () {
local bin="$1"
if [ -d "node_modules/$bin" ]; then
bin="$2"
else
if [ "$(which $bin)" = "" ]; then
mkdir -p node_modules
echo "installing $1"
npm install $bin >/dev/null 2>&1
bin="$2"
fi
fi
echo $bin
}

run () {
local bin="$(program 'browserify' 'node_modules/browserify/bin/cmd.js')"
$bin src/main.js -o build/bundle.max.js -d
}

run
43 changes: 43 additions & 0 deletions utils/jshint.sh
@@ -0,0 +1,43 @@
#!/usr/bin/env bash

program () {
local bin="$1"
if [ -d "node_modules/$bin" ]; then
bin="$2"
else
if [ "$(which $bin)" = "" ]; then
mkdir -p node_modules
echo "installing $1"
npm install $bin >/dev/null 2>&1
bin="$2"
fi
fi
echo $bin
}

run () {
local bin="$(program 'jshint' 'node_modules/jshint/bin/jshint')"
local folder=$1
local js=""
# drop some info in the stdout
echo "linting $f ... "
for f in $folder/*; do
# if it's a fodler, go for recursion
if [ -d "$f" ]; then
run "$f"
else
# grab .js files only
js=$(echo "$f" | sed 's/.js//')
if [ "$js" != "$f" ]; then
# finally use jshint to verify the file
$bin "$f"
# in case there was an error
if [[ $? -ne 0 ]] ; then
exit 1
fi
fi
fi
done
}

run src
20 changes: 20 additions & 0 deletions utils/uglifyjs.sh
@@ -0,0 +1,20 @@
#!/usr/bin/env bash

run () {
local bin="uglifyjs"
if [ -d "node_modules/uglify-js" ]; then
bin="node_modules/uglify-js/bin/uglifyjs"
else
if [ "$(which $bin)" = "" ]; then
mkdir -p node_modules
echo "installing uglify-js"
npm install "uglify-js@1" >/dev/null 2>&1
bin="node_modules/uglify-js/bin/uglifyjs"
fi
fi
echo "$@" >build/bundle.js
$bin --verbose build/bundle.max.js >>build/bundle.js

}

run "$@"
23 changes: 23 additions & 0 deletions utils/watchify.sh
@@ -0,0 +1,23 @@
#!/usr/bin/env bash

program () {
local bin="$1"
if [ -d "node_modules/$bin" ]; then
bin="$2"
else
if [ "$(which $bin)" = "" ]; then
mkdir -p node_modules
echo "installing $1"
npm install $bin >/dev/null 2>&1
bin="$2"
fi
fi
echo $bin
}

run () {
local bin="$(program 'watchify' 'node_modules/watchify/bin/cmd.js')"
$bin src/main.js -o build/bundle.max.js -v
}

run

0 comments on commit e36b2c7

Please sign in to comment.