Permalink
Browse files

first commit

  • Loading branch information...
0 parents commit 04d35478ad07d516968ac9121f00e0ee33642855 @jonschlinkert committed May 12, 2013
Showing with 359 additions and 0 deletions.
  1. +18 −0 .editorconfig
  2. +9 −0 .gitattributes
  3. +3 −0 .gitignore
  4. +14 −0 .jshintrc
  5. +6 −0 .travis.yml
  6. +4 −0 CHANGELOG
  7. +76 −0 Gruntfile.js
  8. +22 −0 LICENSE-MIT
  9. +103 −0 README.md
  10. +47 −0 package.json
  11. +57 −0 tasks/js2coffee.js
@@ -0,0 +1,18 @@
+; EditorConfig is awesome: http://EditorConfig.org
+
+; top-most EditorConfig file
+root = true
+
+; base rules
+[*]
+indent_style = space
+indent_size = 2
+charset = utf-8
+end_of_line = lf
+insert_final_newline = true
+trim_trailing_whitespace = true
+
+; Dont remove trailing whitespace from markdown
+; files since it messes up newlines
+[*.md]
+trim_trailing_whitespace = false
@@ -0,0 +1,9 @@
+# Set default behaviour, in case users don't have core.autocrlf set.
+* text=lf
+* text eol=lf
+*.* eol=lf
+
+*.jpg binary
+*.gif binary
+*.png binary
+*.jpeg binary
@@ -0,0 +1,3 @@
+node_modules
+tmp
+temp
@@ -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,6 @@
+language: node_js
+node_js:
+ - "0.8"
+before_script:
+ - npm install -g grunt-cli
+ - npm install grunt
@@ -0,0 +1,4 @@
+v0.1.0:
+ date: "2013-05-12"
+ changes:
+ - First commit.
@@ -0,0 +1,76 @@
+/*
+ * js2coffee
+ * https://github.com/jonschlinkert/grunt-js2coffee
+ *
+ * Copyright (c) 2013 Jon Schlinkert
+ * Licensed under the MIT license.
+ */
+
+'use strict';
+
+module.exports = function(grunt) {
+
+ // Project configuration.
+ grunt.initConfig({
+
+ jshint: {
+ all: [
+ 'Gruntfile.js',
+ 'tasks/*.js',
+ '<%= nodeunit.tests %>'
+ ],
+ options: {
+ jshintrc: '.jshintrc'
+ }
+ },
+
+ // Configuration to be run (and then tested).
+ js2coffee: {
+ single: {
+ files: {
+ 'test/result/single/ltrim.coffee': [
+ 'test/fixtures/mout/string/ltrim.js'
+ ]
+ }
+ },
+ each: {
+ options: {},
+ files: [
+ {
+ expand: true,
+ cwd: 'test/fixtures/mout',
+ src: ['**/*.js'],
+ dest: 'test/result/each/mout',
+ ext: '.coffee'
+ }
+ ]
+ }
+ },
+
+ // Unit tests.
+ nodeunit: {
+ tests: ['test/*_test.js']
+ },
+
+ // Before generating any new files,
+ // remove any previously-created files.
+ clean: {
+ tests: ['test/result/mout/**']
+ }
+ });
+
+ // 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');
+
+ // plugin's task(s), then test the result.
+ grunt.registerTask('test', ['clean', 'js2coffee']);
+
+ // By default, lint and run all tests.
+ grunt.registerTask('default', ['jshint', 'test']);
+
+};
@@ -0,0 +1,22 @@
+Copyright (c) 2013 assemble
+
+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.
103 README.md
@@ -0,0 +1,103 @@
+# grunt-js2coffee
+
+> Convert JavaScript to coffee-script.
+
+## Getting Started
+_If you haven't used [grunt][] before, be sure to check out the [Getting Started][] guide._
+
+From the same directory as your project's [Gruntfile][Getting Started] and [package.json][], install this plugin with the following command:
+
+```bash
+npm install js2coffee --save-dev
+```
+
+Once that's done, add this line to your project's Gruntfile:
+
+```js
+grunt.loadNpmTasks('js2coffee');
+```
+
+If the plugin has been installed correctly, running `grunt --help` at the command line should list the newly-installed plugin's task or tasks. In addition, the plugin should be listed in package.json as a `devDependency`, which ensures that it will be installed whenever the `npm install` command is run.
+
+[grunt]: http://gruntjs.com/
+[Getting Started]: https://github.com/gruntjs/grunt/blob/devel/docs/getting_started.md
+[package.json]: https://npmjs.org/doc/json.html
+
+## The "js2coffee" task
+
+### Overview
+In your project's Gruntfile, add a section named `js2coffee` to the data object passed into `grunt.initConfig()`.
+
+```js
+grunt.initConfig({
+ js2coffee: {
+ options: {
+ // Task-specific options go here.
+ },
+ your_target: {
+ // Target-specific file lists and/or options go here.
+ },
+ },
+})
+```
+
+### Options
+
+#### options.separator
+Type: `String`
+Default value: `', '`
+
+A string value that is used to do something with whatever.
+
+#### options.punctuation
+Type: `String`
+Default value: `'.'`
+
+A string value that is used to do something else with whatever else.
+
+### Usage Examples
+
+#### Default Options
+In this example, the default options are used to do something with whatever. So if the `testing` file has the content `Testing` and the `123` file had the content `1 2 3`, the generated result would be `Testing, 1 2 3.`
+
+```js
+grunt.initConfig({
+ js2coffee: {
+ options: {},
+ files: {
+ 'dest/default_options': ['src/testing', 'src/123'],
+ },
+ },
+})
+```
+
+#### Custom Options
+In this example, custom options are used to do something else with whatever else. So if the `testing` file has the content `Testing` and the `123` file had the content `1 2 3`, the generated result in this case would be `Testing: 1 2 3 !!!`
+
+```js
+grunt.initConfig({
+ js2coffee: {
+ options: {
+ separator: ': ',
+ punctuation: ' !!!',
+ },
+ files: {
+ 'dest/default_options': ['src/testing', 'src/123'],
+ },
+ },
+})
+```
+
+## 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][].
+
+## Author
+
+**Jon Schlinkert**
+
++ [http://twitter.com/jonschlinkert](http://twitter.com/jonschlinkert)
++ [http://github.com/jonschlinkert](http://github.com/jonschlinkert)
+
+
+## Release History
+_(Nothing yet)_
@@ -0,0 +1,47 @@
+{
+ "name": "grunt-js2coffee",
+ "description": "Convert JavaScript to coffee-script.",
+ "version": "0.1.0",
+ "homepage": "https://github.com/jonschlinkert/grunt-js2coffee/",
+ "author": {
+ "name": "Jon Schlinkert",
+ "url": "https://github.com/jonschlinkert/grunt-js2coffee"
+ },
+ "repository": {
+ "type": "git",
+ "url": "git://github.com/jonschlinkert/grunt-js2coffee.git"
+ },
+ "bugs": {
+ "url": "https://github.com/jonschlinkert/grunt-js2coffee/issues"
+ },
+ "licenses": [
+ {
+ "type": "MIT",
+ "url": "https://github.com/jonschlinkert/grunt-js2coffee/blob/master/LICENSE-MIT"
+ }
+ ],
+ "main": "Gruntfile.js",
+ "engines": {
+ "node": ">= 0.8.0"
+ },
+ "scripts": {
+ "test": "grunt test"
+ },
+ "devDependencies": {
+ "coffee-script": "~1.6.2",
+ "grunt": "~0.4.1",
+ "grunt-contrib-clean": "~0.4.0a",
+ "grunt-contrib-jshint": "~0.1.0",
+ "grunt-contrib-nodeunit": "~0.1.0",
+ "js2coffee": "~0.2.0"
+ },
+ "keywords": [
+ "gruntplugin",
+ "coffee-script",
+ "coffeescript",
+ "js to coffee",
+ "javascript to coffee-script",
+ "grunt coffee-script",
+ "js to coffee"
+ ]
+}
@@ -0,0 +1,57 @@
+/*
+ * js2coffee
+ * https://github.com/assemble/assemble-examples/
+ *
+ * Copyright (c) 2013 assemble
+ * Licensed under the MIT license.
+ */
+
+'use strict';
+
+module.exports = function(grunt) {
+
+ var path = require('path');
+
+ grunt.registerMultiTask('js2coffee', 'Your task description goes here.', function() {
+
+ // Merge task-specific and/or target-specific options with these defaults.
+ var options = this.options({});
+
+ // Iterate over all specified file groups.
+ this.files.forEach(function(fp) {
+
+ var srcFile = fp.src.filter(function(filepath) {
+ // Verify that files exist. Warn if a source file/pattern was invalid.
+ if (!grunt.file.exists(filepath)) {
+ grunt.log.warn('Source file "' + filepath + '" not found.');
+ return false;
+ } else {
+ return true;
+ }
+ }).map(grunt.file.read).join(grunt.util.normalizelf(grunt.util.linefeed)); // Read source files.
+
+ // Handle options.
+ var coffee = convertToCoffee(srcFile);
+ if (coffee.length < 1) {
+ grunt.log.warn('Destination not written because dest file was empty.');
+ } else {
+
+ // Write the destination file.
+ grunt.file.write(fp.dest, coffee);
+
+ // Print a success message.
+ grunt.log.ok('File "' + fp.dest + '"' + ' >> '.green + 'to coffee');
+ }
+ });
+ });
+
+ var convertToCoffee = function(source, options) {
+ var js2coffee;
+ try {
+ return js2coffee = require("js2coffee").build(source, options);
+ } catch (e) {
+ grunt.log.error(e);
+ grunt.fail.warn('Coffee-scriptification failed.');
+ }
+ };
+};

0 comments on commit 04d3547

Please sign in to comment.