Permalink
Browse files

Initial commit of topcoat init grunt task

  • Loading branch information...
kristoferjoseph committed Mar 20, 2013
0 parents commit 32c9c58536698765fdc87f7940ca86778ed13dc9
Showing with 267 additions and 0 deletions.
  1. +3 −0 .gitignore
  2. +14 −0 .jshintrc
  3. +60 −0 Gruntfile.js
  4. +22 −0 LICENSE-MIT
  5. +2 −0 README.md
  6. +52 −0 package.json
  7. +81 −0 tasks/topcoat_init.js
  8. +33 −0 test/topcoat_init_test.js
@@ -0,0 +1,3 @@
+node_modules
+npm-debug.log
+tmp
@@ -0,0 +1,14 @@
+{
+ "curly": true,
+ "eqeqeq": true,
+ "immed": true,
+ "latedef": true,
+ "newcap": true,
+ "noarg": true,
+ "sub": true,
+ "undef": true,
+ "boss": true,
+ "eqnull": true,
+ "node": true,
+ "es5": true
+}
@@ -0,0 +1,60 @@
+/*
+ * grunt-clone
+ * https://github.com/krjoseph/grunt-clone
+ *
+ * Copyright (c) 2013 @dam
+ * Licensed under the MIT license.
+ */
+
+'use strict';
+
+module.exports = function(grunt) {
+
+ // Project configuration.
+ grunt.initConfig({
+ pkg: grunt.file.readJSON('package.json'),
+ jshint: {
+ all: ['Gruntfile.js', 'tasks/*.js', '<%= nodeunit.tests %>', ],
+ options: {
+ jshintrc: '.jshintrc',
+ },
+ },
+
+ // Before generating any new files, remove any previously-created files.
+ clean: {
+ tests: ['tmp']
+ },
+
+ // Configuration to be run (and then tested).
+ topcoat_init: {
+ init: {
+ options: {
+ srcPath: 'tmp/src/',
+ repos: '<%= pkg.topcoat %>'
+ }
+ }
+ },
+
+ // Unit tests.
+ nodeunit: {
+ tests: ['test/*_test.js'],
+ },
+
+ });
+
+ // Actually load this plugin's task(s).
+ grunt.loadTasks('tasks');
+
+ // These plugins provide necessary tasks.
+ grunt.loadNpmTasks('grunt-contrib-jshint');
+ grunt.loadNpmTasks('grunt-contrib-clean');
+ grunt.loadNpmTasks('grunt-contrib-nodeunit');
+
+ // Whenever the "test" task is run, first clean the "tmp" dir, then run this
+ // plugin's task(s), then test the result.
+ grunt.registerTask('test', ['clean', 'topcoat_init', 'nodeunit']);
+
+ // By default, lint and run all tests.
+ grunt.registerTask('default', ['jshint', 'test']);
+
+};
@@ -0,0 +1,22 @@
+Copyright (c) 2013 @dam
+
+Permission is hereby granted, free of charge, to any person
+obtaining a copy of this software and associated documentation
+files (the "Software"), to deal in the Software without
+restriction, including without limitation the rights to use,
+copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the
+Software is furnished to do so, subject to the following
+conditions:
+
+The above copyright notice and this permission notice shall be
+included in all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
+OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
+HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
+WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
+OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,2 @@
+grunt-topcoat-init
+==================
@@ -0,0 +1,52 @@
+{
+ "name": "grunt-topcoat-init",
+ "description": "grunt plugin to download topcoat dependencies.",
+ "version": "0.0.0",
+ "homepage": "https://github.com/krjoseph/grunt-topcoat-init",
+ "author": {
+ "name": "@dam",
+ "email": "kristoferjoseph@gmail.com",
+ "url": "http://www.kristoferjoseph.com"
+ },
+ "topcoat": {
+ "controls": {
+ "topcoat/button": "0.1.0",
+ "topcoat/button-skin": "0.1.0"
+ },
+ "skins": {
+ "topcoat/button-skin": "0.1.0"
+ },
+ "theme": {
+ "topcoat/theme": "0.2.0"
+ }
+ },
+ "repository": {
+ "type": "git",
+ "url": "git://github.com/krjoseph/grunt-topcoat-init.git"
+ },
+ "bugs": {
+ "url": "https://github.com/krjoseph/grunt-topcoat-init/issues"
+ },
+ "licenses": [
+ {
+ "type": "MIT",
+ "url": "https://github.com/krjoseph/grunt-topcoat-init/blob/master/LICENSE-MIT"
+ }
+ ],
+ "main": "Gruntfile.js",
+ "engines": {
+ "node": ">= 0.8.0"
+ },
+ "scripts": {
+ "test": "grunt test"
+ },
+ "devDependencies": {
+ "grunt-contrib-jshint": "0.1.1rc6",
+ "grunt-contrib-clean": "0.4.0rc6",
+ "grunt-contrib-nodeunit": "0.1.2rc6",
+ "grunt": "0.4.0rc6"
+ },
+ "keywords": [
+ "gruntplugin"
+ ]
+}
@@ -0,0 +1,81 @@
+/*
+ * grunt-topcoat-init
+ * https://github.com/krjoseph/grunt-topcoat-init
+ *
+ * Copyright (c) 2013 @dam
+ * Licensed under the MIT license.
+ */
+
+'use strict';
+
+module.exports = function(grunt) {
+
+ // Please see the grunt documentation for more information regarding task
+ // creation: https://github.com/gruntjs/grunt/blob/devel/docs/toc.md
+ grunt.registerMultiTask('topcoat_init', 'Clones git projects to specified directory.', function() {
+ var _ = grunt.util._;
+ var async = grunt.util.async;
+ var done = this.async();
+ var spawn = grunt.util.spawn;
+ var file = grunt.file;
+ var options = this.options();
+ var prefix = "https://github.com/";
+ var suffix = "/archive/";
+ var ext = ".zip";
+ var srcPath = options.srcPath || "src/";
+ var deps = options.repos;
+ var controls = deps.controls || {};
+ var skins = deps.skins || {};
+ var theme = deps.theme || {};
+ var controlsUrls, skinsUrls;
+
+ // If a version number is given we assume it is a tag and use this url
+ // convention:
+ // https://github.com/topcoat/topcoat/archive/0.1.0.zip
+ // If no version is given we use the download api with this url convention:
+ // https://api.github.com/repos/user/repo/zipball/dev
+ // Loop over controls object
+ // Example:
+ // "controls": {
+ // "topcoat/button": "0.1.0"
+ // }
+ //
+ // controls becomes the name of the directory under src. src/controls
+ // download url is constructed with:
+ // prefix + key + suffix + value + ext
+ //
+ // Example:
+ // https://github.com/topcoat/button/archive/0.1.0.zip
+ //
+ if (!_.isEmpty(controls)) {
+ controlsUrls = [];
+ var controlName;
+ var controlsPath = srcPath + "controls/";
+
+ file.mkdir(controlsPath);
+
+ _.forIn(controls, function(value, key) {
+ controlName = key.split('/')[1];
+ controlsUrls.push({
+ name: controlName,
+ url: prefix + key + suffix + value + ext
+ });
+ });
+
+ async.forEachSeries(controlsUrls, function(obj, next) {
+ var zipPath = controlsPath + obj.name + ext;
+ var downloadProcess = spawn({
+ cmd: 'curl',
+ args: ['-o', zipPath, obj.url]
+ }, next);
+
+ downloadProcess.stdout.pipe(process.stdout);
+ downloadProcess.stderr.pipe(process.stderr);
+ }, done);
+
+ } else {
+ console.log("Controls was empty");
+ }
+
+ });
+};
@@ -0,0 +1,33 @@
+'use strict';
+
+var grunt = require('grunt');
+var fs = require('fs');
+
+/*
+ ======== A Handy Little Nodeunit Reference ========
+ https://github.com/caolan/nodeunit
+
+ Test methods:
+ test.expect(numAssertions)
+ test.done()
+ Test assertions:
+ test.ok(value, [message])
+ test.equal(actual, expected, [message])
+ test.notEqual(actual, expected, [message])
+ test.deepEqual(actual, expected, [message])
+ test.notDeepEqual(actual, expected, [message])
+ test.strictEqual(actual, expected, [message])
+ test.notStrictEqual(actual, expected, [message])
+ test.throws(block, [error], [message])
+ test.doesNotThrow(block, [error], [message])
+ test.ifError(value)
+*/
+
+exports.topcoat_init = {
+ init: function(test) {
+ fs.exists("tmp/src/controls/button", function(exists) {
+ test.ok(exists);
+ });
+ test.done();
+ }
+};

0 comments on commit 32c9c58

Please sign in to comment.