]> git.ipfire.org Git - thirdparty/moment.git/commitdiff
Grunt task to meteor publish; improved scripts 2062/head
authorDan Dascalescu <ddascalescu+github@gmail.com>
Sat, 29 Nov 2014 11:11:59 +0000 (03:11 -0800)
committerDan Dascalescu <ddascalescu+github@gmail.com>
Sat, 29 Nov 2014 11:47:54 +0000 (03:47 -0800)
Gruntfile.js
meteor/README.md [new file with mode: 0644]
meteor/package.js
meteor/publish.sh
meteor/runtests.sh
meteor/test.js
package.json

index 490f4ce8e3c8e9bab36bf0086b2d82923aef780d..5db19b4868408c2319e07d36679c354aa72c0893 100644 (file)
@@ -195,10 +195,20 @@ module.exports = function (grunt) {
             all: {
                 src: ['benchmarks/*.js']
             }
+        },
+        shell: {
+            'meteor-test': {
+                command: 'meteor/runtests.sh'
+            },
+            'meteor-publish': {
+                command: 'meteor/publish.sh'
+            }
         }
+
     });
 
     grunt.loadTasks('tasks');
+    grunt.loadNpmTasks('grunt-shell');
 
     // These plugins provide necessary tasks.
     require('load-grunt-tasks')(grunt);
@@ -213,6 +223,7 @@ module.exports = function (grunt) {
     grunt.registerTask('test:browser', ['concat', 'embedLocales', 'karma:chrome', 'karma:firefox']);
     grunt.registerTask('test:sauce-browser', ['concat', 'embedLocales', 'env:sauceLabs', 'karma:sauce']);
     grunt.registerTask('test:travis-sauce-browser', ['concat', 'embedLocales', 'karma:sauce']);
+    grunt.registerTask('test:meteor', ['shell:meteor-test']);
 
     // travis build task
     grunt.registerTask('build:travis', [
@@ -225,6 +236,6 @@ module.exports = function (grunt) {
     // Task to be run when releasing a new version
     grunt.registerTask('release', [
         'jshint', 'nodeunit', 'concat', 'embedLocales',
-        'component', 'uglify:main'
+        'component', 'uglify:main', 'shell:meteor-publish'
     ]);
 };
diff --git a/meteor/README.md b/meteor/README.md
new file mode 100644 (file)
index 0000000..9bcb50b
--- /dev/null
@@ -0,0 +1,25 @@
+Packaging [Moment](momentjs.org) for [Meteor.js](http://meteor.com).
+
+
+# Meteor
+
+If you're new to Meteor, here's what the excitement is all about -
+[watch the first two minutes](https://www.youtube.com/watch?v=fsi0aJ9yr2o); you'll be hooked by 1:28.
+
+That screencast is from 2012. In the meantime, Meteor has become a mature JavaScript-everywhere web
+development framework. Read more at [Why Meteor](http://www.meteorpedia.com/read/Why_Meteor).
+
+
+# Issues
+
+If you encounter an issue while using this package, please CC @dandv when you file it in this repo.
+
+
+# DONE
+
+* Simple test. Should be enough.
+
+
+# TODO
+
+* Add other tests; however, that is overkill, and the responsibiity of Moment, not of the Meteor integration.
index ab473821d930b66f217171113a686f942d97154a..b52734dc8386022467a4936e6165ea824d8c26a6 100644 (file)
@@ -1,24 +1,29 @@
-var packageName = 'moment:moment';
+// package metadata file for Meteor.js
+'use strict';
+
+var packageName = 'momentjs:moment';  // https://atmospherejs.com/momentjs/moment
+
+var packageJson = JSON.parse(Npm.require("fs").readFileSync('package.json'));
 
 Package.describe({
   name: packageName,
-  summary: 'Moment.js: parse, validate, manipulate, and display dates - official Meteor packaging',
-  version: '2.8.4',
+  summary: 'Moment.js (official): parse, validate, manipulate, and display dates - official Meteor packaging',
+  version: packageJson.version,
   git: 'https://github.com/moment/moment.git'
 });
 
 Package.onUse(function (api) {
-  api.versionsFrom('0.9.0');
-  api.export('moment', ['client', 'server']);
+  api.versionsFrom('METEOR@1.0');
+  api.export('moment');
   api.addFiles([
-    'moment.js', 'meteor/export.js'
-  ], ['client', 'server']
-  );
+    'moment.js',
+    'meteor/export.js'
+  ]);
 });
 
 Package.onTest(function (api) {
-  api.use(packageName, ['client', 'server']);
-  api.use('tinytest', ['client', 'server']);
+  api.use(packageName);
+  api.use('tinytest');
 
-  api.addFiles('meteor/test.js', ['client', 'server']);
+  api.addFiles('meteor/test.js');
 });
index f8892ced14cb5a8238d2a0ecaba423874f125a9f..d6fcab5a1d1803b953e9f9ba6b22987c93856a3e 100755 (executable)
@@ -1,25 +1,77 @@
+#!/bin/bash
 # Publish package on Meteor's Atmosphere.js
 
 # 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.
 type meteor >/dev/null 2>&1 || { curl https://install.meteor.com/ | sh; }
 
 # sanity check: make sure we're in the root directory of the checkout
-DIR=$( cd "$( dirname "$0" )" && pwd )
-cd $DIR/..
+cd "$( dirname "$0" )/.."
 
-# move away the package.js for Dojo
-mv package.js package.dojo
-cp meteor/package.js ./
 
-# publish package, creating it if it's the first time we're publishing
-PACKAGE_NAME=$(grep -i name package.js | head -1 | cut -d "'" -f 2)
-PACKAGE_EXISTS=$(meteor search $PACKAGE_NAME 2>/dev/null | wc -l)
+function cleanup() {
+  # restore package.js for Dojo
+  mv package.dojo package.js
 
-if [ $PACKAGE_EXISTS -gt 0 ]; then
-  meteor publish
-else
-  meteor publish --create
-fi
+  # temporary build files
+  rm -rf ".build.$PACKAGE_NAME" versions.json
+}
 
-# restore the Dojo package.js
-mv package.dojo package.js
+
+# publish separately any package*.js files we have, e.g. package.js, package-compat.js
+for PACKAGE_FILE in meteor/package*.js; do
+
+  # Meteor expects package.js to be in the root directory of the checkout, but we already have a package.js for Dojo
+  mv package.js package.dojo
+  cp $PACKAGE_FILE ./package.js
+
+  # publish package, creating it if it's the first time we're publishing
+  PACKAGE_NAME=$(grep -i name $PACKAGE_FILE | head -1 | cut -d "'" -f 2)
+  ATMOSPHERE_NAME=${PACKAGE_NAME/://}
+
+  echo "Publishing $PACKAGE_NAME..."
+
+  # attempt to re-publish the package - the most common operation once the initial release has been made
+  OUTPUT=$( meteor publish 2>&1 )
+
+  if (( $? > 0 )); then
+    # there was an error
+
+    if [[ $OUTPUT =~ "There is no package named" ]]; then
+      # actually this is the first time the package is created, so pass the special --create flag and congratulate the maintainer
+      echo "Thank you for creating the official Meteor package for this library!"
+      if meteor publish --create; then
+        echo "Please post the following to https://github.com/raix/Meteor-community-discussions/issues/14:
+
+--------------------------------------------- 8< --------------------------------------------------------
+
+Happy to announce that I've published the official $PACKAGE_NAME to Atmosphere. Please star!
+https://atmospherejs.com/$ATMOSPHERE_NAME
+
+--------------------------------------------- >8 --------------------------------------------------------
+
+"
+      else
+        echo "We got an error. Please post it at https://github.com/raix/Meteor-community-discussions/issues/14"
+        cleanup
+        exit 1
+      fi
+    else
+      # the error wasn't that the package didn't exist, so we need to ask for help
+      echo "We got an error. Please post it at https://github.com/raix/Meteor-community-discussions/issues/14:
+--------------------------------------------- 8< --------------------------------------------------------
+$OUTPUT
+--------------------------------------------- >8 --------------------------------------------------------
+"
+      cleanup
+      exit 1
+    fi
+  else
+    # no error on the first `meteor publish` attempt
+    echo "$OUTPUT"  # just in case meteor said something interesting
+    echo "Thanks for releasing a new version of $PACKAGE_NAME! You can see it at
+https://atmospherejs.com/$ATMOSPHERE_NAME"
+  fi
+
+  cleanup
+
+done
index 1be2a1a604dc3e6b552f1e49e6d2781e87793554..c0e80a33e9a0c9643fc21f78ef9efdd143efd629 100755 (executable)
@@ -1,29 +1,38 @@
-# Test Meteor package before publishing to Atmosphere.js
+#!/bin/sh
+# Test Meteor package before publishing to Atmospherejs.com
 
-# Make sure Meteor is installed, per https://www.meteor.com/install
+# 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.
 type meteor >/dev/null 2>&1 || { curl https://install.meteor.com/ | sh; }
 
 # sanity check: make sure we're in the root directory of the checkout
-DIR=$( cd "$( dirname "$0" )" && pwd )
-cd $DIR/..
+cd "$( dirname "$0" )/.."
 
-# move away the package.js for Dojo
-mv package.js package.dojo
-cp meteor/package.js ./
-
-# run tests and restore the Dojo package.js even if Ctrl+C is pressed
+# run tests and delete the temporary package.js even if Ctrl+C is pressed
 int_trap() {
   echo
-  echo "Tests interrupted."
+  printf "Tests interrupted. Hopefully you verified in the browser that tests pass?\n\n"
 }
 
 trap int_trap INT
 
-meteor test-packages ./
+# test any package*.js packages we may have, e.g. package.js, package-compat.js
+for PACKAGE_FILE in meteor/package*.js; do
+
+  PACKAGE_NAME=$(grep -i name $PACKAGE_FILE | head -1 | cut -d "'" -f 2)
+
+  echo "Testing $PACKAGE_NAME..."
+
+  # Meteor expects package.js to be in the root directory of the checkout, but we already have a package.js for Dojo
+  mv package.js package.dojo
+  cp $PACKAGE_FILE ./package.js
+
+  # provide an invalid MONGO_URL so Meteor doesn't bog us down with an empty Mongo database
+  MONGO_URL=mongodb:// meteor test-packages ./
+
+  rm -rf ".build.$PACKAGE_NAME"
+  rm -rf ".build.local-test:$PACKAGE_NAME"
+  rm versions.json 2>/dev/null
 
-PACKAGE_NAME=$(grep -i name package.js | head -1 | cut -d "'" -f 2)
-rm -rf ".build.$PACKAGE_NAME"
-rm -rf ".build.local-test:$PACKAGE_NAME"
-rm versions.json
+  mv package.dojo package.js
 
-mv package.dojo package.js
+done
index 6553a67170b65032d3d4cb86b25218979aa737d0..6bf706a6028318950873fcf0301354152ea888de 100644 (file)
@@ -1,5 +1,5 @@
 'use strict';
 
 Tinytest.add('Moment.is', function (test) {
-  test.ok(moment.isMoment(moment()), 'simple moment object');
+  test.ok(moment.isMoment(moment()), {message: 'simple moment object'});
 });
index 262ca83f04b7db73369da655425ae34eec75085b..fc86e8a4d49a17295b6da4278568d2368e185f53 100644 (file)
@@ -53,6 +53,7 @@
         "grunt-karma": "latest",
         "grunt-benchmark": "latest",
         "grunt-string-replace": "latest",
+        "grunt-shell": "latest",
         "load-grunt-tasks": "latest",
         "karma": "latest",
         "karma-chrome-launcher": "latest",