Skip to content

Commit 327d8e9

Browse files
committed
Add packaging for Meteor.js, http://meteor.com
1 parent 08f59e9 commit 327d8e9

File tree

8 files changed

+254
-1
lines changed

8 files changed

+254
-1
lines changed

Gruntfile.js

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,13 +54,23 @@ module.exports = function( grunt ) {
5454
banner: banner
5555
}
5656
}
57+
},
58+
59+
shell: {
60+
'meteor-test': {
61+
command: 'meteor/runtests.sh'
62+
},
63+
'meteor-publish': {
64+
command: 'meteor/publish.sh'
65+
}
5766
}
5867

5968
});
6069

6170
grunt.loadNpmTasks('grunt-contrib-jshint');
6271
grunt.loadNpmTasks('grunt-contrib-uglify');
6372
grunt.loadNpmTasks('grunt-requirejs');
73+
grunt.loadNpmTasks('grunt-shell');
6474

6575
grunt.registerTask( 'pkgd-edit', function() {
6676
var outFile = grunt.config.get('requirejs.pkgd.options.out');
@@ -77,6 +87,13 @@ module.exports = function( grunt ) {
7787
grunt.log.writeln( 'Edited ' + outFile );
7888
});
7989

90+
grunt.registerTask('meteor-test', 'shell:meteor-test');
91+
grunt.registerTask('meteor-publish', 'shell:meteor-publish');
92+
// ideally we'd run tests before publishing, but the chances of tests breaking (given that
93+
// Meteor is orthogonal to the library) are so small that it's not worth the maintainer's time
94+
// grunt.regsterTask('meteor', ['shell:meteor-test', 'shell:meteor-publish']);
95+
grunt.registerTask('meteor', 'shell:meteor-publish');
96+
8097
grunt.registerTask( 'default', [
8198
'jshint',
8299
'requirejs',

meteor/README.md

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
Packaging [Isotope](http://isotope.metafizzy.co/) for [Meteor.js](http://meteor.com).
2+
3+
4+
# Meteor
5+
6+
If you're new to Meteor, here's what the excitement is all about -
7+
[watch the first two minutes](https://www.youtube.com/watch?v=fsi0aJ9yr2o); you'll be hooked by 1:28.
8+
9+
That screencast is from 2012. In the meantime, Meteor has become a mature JavaScript-everywhere web
10+
development framework. Read more at [Why Meteor](http://www.meteorpedia.com/read/Why_Meteor).
11+
12+
13+
# Issues
14+
15+
If you encounter an issue while using this package, please CC @dandv when you file it in this repo.
16+
17+
18+
# DONE
19+
20+
* Automated and visual test for the fitRows layout
21+
22+
23+
# TODO
24+
25+
* Add other tests; however, that is overkill, and the responsibiity of Isotope, not of the Meteor integration.

meteor/export.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
// expose Isotope to Meteor.js
2+
if (typeof Package !== 'undefined') {
3+
/*global Isotope:true*/ // Meteor.js creates a file-scope global for exporting. This comment prevents a potential JSHint warning.
4+
Isotope = window.Isotope;
5+
delete window.Isotope;
6+
}

meteor/package.js

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
// package metadata file for Meteor.js
2+
'use strict';
3+
4+
var packageName = 'isotope:isotope'; // http://atmospherejs.com/isotope/isotope
5+
var where = 'client'; // where to install: 'client', 'server', or ['client', 'server']
6+
7+
var packageJson = JSON.parse(Npm.require("fs").readFileSync('package.json'));
8+
9+
Package.describe({
10+
name: packageName,
11+
summary: 'Isotope (official): filter and sort magical layouts: fit rows, packery, masonry, fit columns etc.', // limited to 100 characters
12+
version: packageJson.version,
13+
git: 'https://github.com/metafizzy/isotope.git'
14+
});
15+
16+
Package.onUse(function (api) {
17+
api.versionsFrom('[email protected]');
18+
api.export('Isotope');
19+
api.addFiles([
20+
'dist/isotope.pkgd.js',
21+
'meteor/export.js'
22+
], where);
23+
});
24+
25+
Package.onTest(function (api) {
26+
api.use(packageName, where);
27+
api.use(['tinytest', 'http'], where);
28+
29+
api.addFiles([
30+
'test/tests.css',
31+
'meteor/test.js'
32+
], where);
33+
});

meteor/publish.sh

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
#!/bin/bash
2+
# Publish package on Meteor's Atmosphere.js
3+
4+
# Make sure Meteor is installed, per https://www.meteor.com/install. The curl'ed script is totally safe; takes 2 minutes to read its source and check.
5+
type meteor >/dev/null 2>&1 || { curl https://install.meteor.com/ | sh; }
6+
7+
# sanity check: make sure we're in the root directory of the checkout
8+
cd "$( dirname "$0" )/.."
9+
10+
11+
function cleanup() {
12+
# we copied the file as package.js, regardless of its original name
13+
rm package.js
14+
15+
# temporary build files
16+
rm -rf ".build.$PACKAGE_NAME" versions.json
17+
}
18+
19+
20+
# publish separately any package*.js files we have, e.g. package.js, package-compat.js
21+
for PACKAGE_FILE in meteor/package*.js; do
22+
23+
# Meteor expects package.js to be in the root directory of the checkout, so copy there our package file under that name, temporarily
24+
cp $PACKAGE_FILE ./package.js
25+
26+
# publish package, creating it if it's the first time we're publishing
27+
PACKAGE_NAME=$(grep -i name $PACKAGE_FILE | head -1 | cut -d "'" -f 2)
28+
ATMOSPHERE_NAME=${PACKAGE_NAME/://}
29+
30+
echo "Publishing $PACKAGE_NAME..."
31+
32+
# attempt to re-publish the package - the most common operation once the initial release has been made
33+
OUTPUT=$( meteor publish 2>&1 )
34+
35+
if (( $? > 0 )); then
36+
# there was an error
37+
38+
if [[ $OUTPUT =~ "There is no package named" ]]; then
39+
# actually this is the first time the package is created, so pass the special --create flag and congratulate the maintainer
40+
echo "Thank you for creating the official Meteor package for this library!"
41+
if meteor publish --create; then
42+
echo "Please post the following to https://github.com/raix/Meteor-community-discussions/issues/14:
43+
44+
--------------------------------------------- 8< --------------------------------------------------------
45+
46+
Happy to announce that I've published the official $PACKAGE_NAME to Atmosphere. Please star!
47+
https://atmospherejs.com/$ATMOSPHERE_NAME
48+
49+
--------------------------------------------- >8 --------------------------------------------------------
50+
51+
"
52+
else
53+
echo "We got an error. Please post it at https://github.com/raix/Meteor-community-discussions/issues/14"
54+
cleanup
55+
exit 1
56+
fi
57+
else
58+
# the error wasn't that the package didn't exist, so we need to ask for help
59+
echo "We got an error. Please post it at https://github.com/raix/Meteor-community-discussions/issues/14:
60+
--------------------------------------------- 8< --------------------------------------------------------
61+
$OUTPUT
62+
--------------------------------------------- >8 --------------------------------------------------------
63+
"
64+
cleanup
65+
exit 1
66+
fi
67+
else
68+
# no error on the first `meteor publish` attempt
69+
echo "$OUTPUT" # just in case meteor said something interesting
70+
echo "Thanks for releasing a new version of $PACKAGE_NAME! You can see it at
71+
https://atmospherejs.com/$ATMOSPHERE_NAME"
72+
fi
73+
74+
cleanup
75+
76+
done

meteor/runtests.sh

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
#!/bin/sh
2+
# Test Meteor package before publishing to Atmospherejs.com
3+
4+
# Make sure Meteor is installed, per https://www.meteor.com/install. The curl'ed script is totally safe; takes 2 minutes to read its source and check.
5+
type meteor >/dev/null 2>&1 || { curl https://install.meteor.com/ | sh; }
6+
7+
# sanity check: make sure we're in the root directory of the checkout
8+
cd "$( dirname "$0" )/.."
9+
10+
# run tests and delete the temporary package.js even if Ctrl+C is pressed
11+
int_trap() {
12+
echo
13+
printf "Tests interrupted. Hopefully you verified in the browser that tests pass?\n\n"
14+
}
15+
16+
trap int_trap INT
17+
18+
# test any package*.js packages we may have, e.g. package.js, package-compat.js
19+
for PACKAGE_FILE in meteor/package*.js; do
20+
21+
PACKAGE_NAME=$(grep -i name $PACKAGE_FILE | head -1 | cut -d "'" -f 2)
22+
23+
echo "Testing $PACKAGE_NAME..."
24+
25+
# Meteor expects package.js to be in the root directory of the checkout, so copy there our package file under that name, temporarily
26+
cp $PACKAGE_FILE ./package.js
27+
28+
# provide an invalid MONGO_URL so Meteor doesn't bog us down with an empty Mongo database
29+
MONGO_URL=mongodb:// meteor test-packages ./
30+
31+
rm -rf ".build.$PACKAGE_NAME"
32+
rm -rf ".build.local-test:$PACKAGE_NAME"
33+
rm versions.json 2>/dev/null
34+
35+
rm package.js
36+
37+
done

meteor/test.js

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
'use strict';
2+
3+
Tinytest.addAsync('Isotope - fitRows', function (test, done) {
4+
var isotopeDropZone = document.createElement('div');
5+
document.body.appendChild(isotopeDropZone);
6+
7+
// TODO ideally we'd get the htmls straight from this repo, but no idea how to do this from TinyTest - http://stackoverflow.com/questions/27180892/pull-an-html-file-into-a-tinytest
8+
HTTP.get('https://rawgit.com/metafizzy/isotope/master/test/index.html', function callback(error, result) {
9+
10+
// adapted from test/fit-rows.js
11+
function checkPosition(item, x, y) {
12+
var elem = item.element;
13+
var left = parseInt(elem.style.left, 10);
14+
var top = parseInt(elem.style.top, 10);
15+
test.equal([ left, top ], [ x, y ], 'item position ' + x + ', ' + y);
16+
}
17+
18+
if (error) {
19+
test.fail({message: 'Error getting the test file. Do we have an Internet connection to rawgit.com?'});
20+
} else {
21+
// [^] matches across newlines. Stay within the <body>, or else the fragment will attempt to load resources on its own.
22+
isotopeDropZone.innerHTML = result.content.match(/<h2>fitRows[^]+<\/div>/);
23+
24+
test.ok({message: 'Visual test passed if the fitRows look like two towers, and failed if they look like a rotated L'});
25+
26+
var iso = new Isotope('#fitrows-gutter', {
27+
layoutMode: 'fitRows',
28+
itemSelector: '.item',
29+
transitionDuration: 0
30+
});
31+
32+
checkPosition(iso.items[0], 0, 0);
33+
checkPosition(iso.items[1], 60, 0);
34+
35+
// check gutter
36+
iso.options.fitRows = {
37+
gutter: 10
38+
};
39+
iso.layout();
40+
41+
checkPosition(iso.items[0], 0, 0);
42+
checkPosition(iso.items[1], 70, 0);
43+
44+
// check gutter, with element sizing
45+
iso.options.fitRows = {
46+
gutter: '.gutter-sizer'
47+
};
48+
iso.layout();
49+
50+
checkPosition(iso.items[0], 0, 0);
51+
checkPosition(iso.items[1], 78, 0);
52+
}
53+
54+
done();
55+
56+
});
57+
58+
});

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,8 @@
2323
"grunt": "~0.4.0",
2424
"grunt-contrib-jshint": "~0.4.1",
2525
"grunt-contrib-uglify": "~0.1.1",
26-
"grunt-requirejs": "~0.4.0"
26+
"grunt-requirejs": "~0.4.0",
27+
"grunt-shell": "*"
2728
},
2829
"repository": {
2930
"type": "git",

0 commit comments

Comments
 (0)