Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

initial commit

  • Loading branch information...
commit 4513eff3c40913c4a13a2c7ebd62d220383574cc 0 parents
@jgallen23 authored
1  .gitignore
@@ -0,0 +1 @@
+node_modules
1  .npmignore
@@ -0,0 +1 @@
+/node_modules/
22 LICENSE-MIT
@@ -0,0 +1,22 @@
+Copyright (c) 2012 Greg Allen
+
+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.
28 README.md
@@ -0,0 +1,28 @@
+# grunt-clientside
+
+Generate clientside js code from CommonJS modules
+
+## Getting Started
+Install this grunt plugin next to your project's [grunt.js gruntfile][getting_started] with: `npm install grunt-clientside`
+
+Then add this line to your project's `grunt.js` gruntfile:
+
+```javascript
+grunt.loadNpmTasks('grunt-clientside');
+```
+
+[grunt]: http://gruntjs.com/
+[getting_started]: https://github.com/gruntjs/grunt/blob/master/docs/getting_started.md
+
+## Documentation
+_(Coming soon)_
+
+## Contributing
+In lieu of a formal styleguide, take care to maintain the existing coding style. Add unit tests for any new or changed functionality. Lint and test your code using [grunt][grunt].
+
+## Release History
+_(Nothing yet)_
+
+## License
+Copyright (c) 2012 Greg Allen
+Licensed under the MIT license.
2  bin/grunt-clientside
@@ -0,0 +1,2 @@
+#!/usr/bin/env node
+require('grunt').npmTasks('grunt-clientside').cli();
5 example/a.js
@@ -0,0 +1,5 @@
+var fnA = function() {
+ return 'a';
+};
+
+module.exports = fnA;
8 example/b.js
@@ -0,0 +1,8 @@
+var fnA = require('./a');
+
+var fnB = function() {
+ var a = fnA();
+ return a + 'b';
+};
+
+module.exports = fnB;
10 example/c.js
@@ -0,0 +1,10 @@
+var fnA = require('./a');
+var fnB = require('./b');
+
+var a = fnA();
+var b = fnB();
+
+module.exports = {
+ a: a,
+ b: b
+};
54 example/out.js
@@ -0,0 +1,54 @@
+//built with clientside 0.4.0 https://github.com/jgallen23/clientside
+if (typeof __cs == 'undefined') {
+ var __cs = {
+ map: {},
+ libs: {},
+ r: function(p) {
+ var mod = __cs.libs[__cs.map[p]];
+ if (!mod) {
+ throw new Error(p + ' not found');
+ }
+ return mod;
+ }
+ };
+ window.require = __cs.r;
+}
+__cs.map['./a'] = 'csbebf3768';
+__cs.map['./b'] = 'csb3bd7f56';
+
+//a.js
+__cs.libs.csbebf3768 = (function(require, module, exports) {
+var fnA = function() {
+ return 'a';
+};
+module.exports = fnA;
+return module.exports || exports;
+})(__cs.r, {}, {});
+
+//b.js
+__cs.libs.csb3bd7f56 = (function(require, module, exports) {
+var fnA = require('./a');
+var fnB = function() {
+ var a = fnA();
+ return a + 'b';
+};
+module.exports = fnB;
+return module.exports || exports;
+})(__cs.r, {}, {});
+
+//c.js
+__cs.libs.cs349afabb = (function(require, module, exports) {
+var fnA = require('./a');
+var fnB = require('./b');
+var a = fnA();
+var b = fnB();
+module.exports = {
+ a: a,
+ b: b
+};
+return module.exports || exports;
+})(__cs.r, {}, {});
+
+window['testing'] = __cs.libs.cs349afabb;
+__cs.map['testing'] = 'cs349afabb';
+
30 grunt.js
@@ -0,0 +1,30 @@
+module.exports = function(grunt) {
+
+ // Project configuration.
+ grunt.initConfig({
+ test: {
+ files: ['test/**/*.js']
+ },
+ lint: {
+ files: ['grunt.js', 'tasks/**/*.js', 'test/**/*.js']
+ },
+ watch: {
+ files: '<config:lint.files>',
+ tasks: 'default'
+ },
+ clientside: {
+ main: {
+ main: 'example/c.js',
+ name: 'testing',
+ output: 'example/out.js'
+ }
+ }
+ });
+
+ // Load local tasks.
+ grunt.loadTasks('tasks');
+
+ // Default task.
+ grunt.registerTask('default', 'lint test');
+
+};
40 package.json
@@ -0,0 +1,40 @@
+{
+ "name": "grunt-clientside",
+ "description": "Generate clientside js code from CommonJS modules",
+ "version": "0.1.0",
+ "homepage": "https://github.com/jgallen23/grunt-clientside",
+ "author": {
+ "name": "Greg Allen",
+ "email": "me@jga.me"
+ },
+ "repository": {
+ "type": "git",
+ "url": "git://github.com/jgallen23/grunt-clientside.git"
+ },
+ "bugs": {
+ "url": "https://github.com/jgallen23/grunt-clientside/issues"
+ },
+ "licenses": [
+ {
+ "type": "MIT",
+ "url": "https://github.com/jgallen23/grunt-clientside/blob/master/LICENSE-MIT"
+ }
+ ],
+ "main": "grunt.js",
+ "bin": "bin/grunt-clientside",
+ "engines": {
+ "node": "*"
+ },
+ "scripts": {
+ "test": "grunt test"
+ },
+ "devDependencies": {
+ "grunt": "~0.3.17"
+ },
+ "keywords": [
+ "gruntplugin"
+ ],
+ "dependencies": {
+ "clientside": "~0.4.0"
+ }
+}
43 tasks/clientside.js
@@ -0,0 +1,43 @@
+/*
+ * grunt-clientside
+ * https://github.com/jgallen23/grunt-clientside
+ *
+ * Copyright (c) 2012 Greg Allen
+ * Licensed under the MIT license.
+ */
+
+module.exports = function(grunt) {
+
+ // Please see the grunt documentation for more information regarding task and
+ // helper creation: https://github.com/gruntjs/grunt/blob/master/docs/toc.md
+
+ var clientside = require('clientside');
+ var fs = require('fs');
+
+ // ==========================================================================
+ // TASKS
+ // ==========================================================================
+
+ grunt.registerMultiTask('clientside', 'Generate clientside js code from CommonJS modules', function() {
+ this.requiresConfig('clientside');
+ var self = this;
+ var done = this.async();
+
+ clientside(this.data, function(err, src) {
+ if (err) {
+ return grunt.log.error(err.message);
+ }
+
+ fs.writeFile(self.data.output, src, function(err) {
+ if (err) {
+ return grunt.log.error(err.message);
+ }
+ grunt.log.writeln(self.data.output + ' created.');
+ done();
+ });
+
+ });
+ });
+
+
+};
22 test/clientside_test.js
@@ -0,0 +1,22 @@
+var grunt = require('grunt');
+
+/*
+ ======== 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)
+*/
+
Please sign in to comment.
Something went wrong with that request. Please try again.