New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

grunt-eco

Package Overview
Dependencies
Maintainers
1
Versions
7
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

grunt-eco - npm Package Compare versions

Comparing version 0.0.2 to 0.1.0

Gruntfile.js

60

package.json
{
"name": "grunt-eco",
"description": "JavaScripts your Embedded CoffeeScript Templates",
"version": "0.0.2",
"description": "Compiles embedded CoffeeScript templates",
"keywords": [
"gruntplugin"
],
"version": "0.1.0",
"licenses": [
{
"type": "MIT",
"url": "https://github.com/gr2m/grunt-eco/blob/master/LICENSE-MIT"
}
],
"homepage": "https://github.com/gr2m/grunt-eco",
"repository": {
"type": "git",
"url": "git://github.com/gr2m/grunt-eco.git"
},
"bugs": {
"url": "https://github.com/gr2m/grunt-eco/issues"
},
"author": {

@@ -46,36 +63,25 @@ "name": "Gregor Martynus",

"url": "https://github.com/brewster1134"
}
],
"repository": {
"type": "git",
"url": "git://github.com/gr2m/grunt-eco.git"
},
"bugs": {
"url": "https://github.com/gr2m/grunt-eco/issues"
},
"licenses": [
},
{
"type": "MIT",
"url": "https://github.com/gr2m/grunt-eco/blob/master/LICENSE-MIT"
"name": "srigi",
"url": "https://github.com/srigi"
}
],
"main": "grunt.js",
"main": "Gruntfile.js",
"engines": {
"node": "*"
"node": ">=0.8"
},
"dependencies": {
"grunt": "~0.4.0",
"grunt-lib-contrib": "~0.3.0",
"eco": "~1.0.3"
"eco": "~1.0"
},
"devDependencies": {
"grunt": "~0.4.0",
"eco": "~1.0.3"
"grunt": "~0.4",
"grunt-contrib-clean": ">=0.4",
"grunt-contrib-jshint": ">=0.1.1",
"grunt-contrib-nodeunit": ">=0.1.2"
},
"keywords": [
"gruntplugin"
],
"readme": "# grunt-eco\n\nJavaScripts your Embedded CoffeeScript Templates\n\n## Getting Started\n\nInstall this grunt plugin next to your project's [grunt.js gruntfile][getting_started] with: `npm install grunt-eco`\n\nThen add this line to your project's `grunt.js` gruntfile:\n\n```javascript\ngrunt.loadNpmTasks('grunt-eco');\n```\n\n[grunt]: https://github.com/cowboy/grunt\n[getting_started]: https://github.com/cowboy/grunt/blob/master/docs/getting_started.md\n\n## Documentation\nYou'll need to install `grunt-eco` first:\n\n npm install grunt-eco\n\nThen modify your `grunt.js` file by adding the following line:\n\n grunt.loadNpmTasks('grunt-eco');\n\nThen add some configuration for the plugin like so:\n\n grunt.initConfig({\n ...\n eco: {\n app: {\n src: ['path/to/eco/files/*.eco'],\n dest: 'where/you/want/your/js/files'\n }\n },\n ...\n });\n\nThen just run `grunt eco` and enjoy!\n\nIf you have `dest` path and want to preserve the directory structure of your eco files, pass the `preserve_dirs` option.\n\n options: {\n preserve_dirs: true\n }\n\nAlso, if you just want to preserve the directory structure, starting from a base path, pass the `base_path` option.\n\n options: {\n preserve_dirs: true,\n base_path: 'path/to'\n }\n\nThis will create the files under `where/you/want/your/js/files/eco/files/`.\n\n## Acknowledgment\nThis grunt plugin is based on and heavily inspired by [grunt-coffee](https://github.com/avalade/grunt-coffee). Thanks @avalade\n\n## Todo\n\n* add specs\n\n## License\nCopyright (c) 2012 Gregor Martynus\nLicensed under the MIT license.\n",
"_id": "grunt-eco@0.0.1",
"_from": "grunt-eco"
"peerDependencies": {
"grunt": "~0.4"
}
}
# grunt-eco
JavaScripts your Embedded CoffeeScript Templates
Compiles [Embedded CoffeeScript templates](https://github.com/sstephenson/eco) (`.eco`) into JavaScript functions.
## Getting Started
Install this grunt plugin next to your project's [grunt.js gruntfile][getting_started] with: `npm install grunt-eco`
This plugin requires Grunt `~0.4`
Then add this line to your project's `grunt.js` gruntfile:
If you haven't used [Grunt](http://gruntjs.com/) before, be sure to check out the [Getting Started](http://gruntjs.com/getting-started) guide, as it explains how to create a [Gruntfile](http://gruntjs.com/sample-gruntfile) as well as install and use Grunt plugins. Once you're familiar with that process, you may install this plugin with this command:
```javascript
```shell
npm install grunt-eco --save-dev
```
Once the plugin has been installed, it may be enabled inside your `Gruntfile.js` with this line of JavaScript:
```js
grunt.loadNpmTasks('grunt-eco');
```
[grunt]: https://github.com/cowboy/grunt
[getting_started]: https://github.com/cowboy/grunt/blob/master/docs/getting_started.md
*This plugin was designed to work with Grunt 0.4.x. If you're still using grunt v0.3.x it's strongly recommended that [you upgrade](http://gruntjs.com/upgrading-from-0.3-to-0.4), but in case you can't please use [v0.3.1](https://github.com/gruntjs/grunt-contrib-stylus/tree/grunt-0.3-stable).*
## Documentation
You'll need to install `grunt-eco` first:
## eco task
npm install grunt-eco
Run this task with the `grunt eco` command.
Then modify your `grunt.js` file by adding the following line:
Task targets, files and options may be specified according to the grunt [Configuring tasks](http://gruntjs.com/configuring-tasks) guide.
grunt.loadNpmTasks('grunt-eco');
### Options
Then add some configuration for the plugin like so:
#### amd
Type: `Boolean`
Default: `false`
grunt.initConfig({
...
eco: {
app: {
src: ['path/to/eco/files/*.eco'],
dest: 'where/you/want/your/js/files'
}
},
...
});
Defines if compiled function will be wrapped in AMD `define` function.
Then just run `grunt eco` and enjoy!
### emptyWarning
If you have `dest` path and want to preserve the directory structure of your eco files, pass the `preserve_dirs` option.
Type: `Boolean`
Default: `true`
options: {
preserve_dirs: true
Defines if task will warn about empty files on console.
#### jstGlobalCheck
Type: `Boolean`
Default: `true`
Defines if compiled function is prepended by code checking/defining presence of `JST` object on `window`.
*please note when `amd` is set to `true` the `jstGlobalCheck` is ignored*.
### Warning
`preserve_dirs` and `base_path` options are not supported anymore! See examples how task's paths are configured now.
### Examples
Two most common ways of compiling all [globbed paths](http://gruntjs.com/configuring-tasks#globbing-patterns) into single file:
```js
eco: {
app: {
files: {
'path/to/templates.js': ['src/templates/**/*.eco']
}
}
}
```
Also, if you just want to preserve the directory structure, starting from a base path, pass the `base_path` option.
```js
eco: {
app: {
src: ['src/templates/**/*.eco'],
dest: 'path/to/templates.js'
}
}
```
If you need to compile `.eco` templates into individual files in some sort of destination folder, you can [dynamiccally build path object](http://gruntjs.com/configuring-tasks#building-the-files-object-dynamically):
```js
eco: {
app: {
files: [{
expand: true,
src: ['src/templates/**/*.eco'],
dest: 'path/to/templates',
ext: '.js'
}]
}
}
```
If you ommit `dest` key, templates will be compiled right next to your `.eco` files.
To configure `eco` task simply define `options` object:
```js
eco: {
app: {
options: {
preserve_dirs: true,
base_path: 'path/to'
amd: true
}
files: {
'path/to/templates.js': ['src/templates/**/*.eco']
}
}
}
```
This will create the files under `where/you/want/your/js/files/eco/files/`.
## Acknowledgment
This grunt plugin is based on and heavily inspired by [grunt-coffee](https://github.com/avalade/grunt-coffee). Thanks @avalade
## Todo
This grunt plugin is based on and heavily inspired by [grunt-contrib-stylus](https://github.com/gruntjs/grunt-contrib-stylus).
* add specs
## Contributing
To start, just clone project and then run `npm install` in project root.
In lieu of a formal styleguide, take care to maintain the existing coding style. Add unit tests for any new or changed functionality. Always lint and test your code by running `grunt` in project's root.
Create new GIT branch (`git checkout -b my_feature`) when sending pull request.
## Release History
* `Jun 16, 2013 v0.1.0` - Refactoring, tests, AMD support
* `Mar 04, 2013 v0.0.2` - Grunt 0.4 compatibility
* `Nov 18, 2012 v0.0.1` - Initial commit
## License
Copyright (c) 2012 Gregor Martynus
Licensed under the MIT license.

@@ -10,84 +10,83 @@ /*

module.exports = function(grunt) {
var path = require('path');
'use strict';
var path = require('path'),
eco = require('eco');
// Please see the grunt documentation for more information regarding task and
// helper creation: https://github.com/cowboy/grunt/blob/master/docs/toc.md
var compile = function(src, options) {
var input = grunt.file.read(src),
output = '',
JSTpath = path.dirname(src) + '/' + path.basename(src, '.eco');
// ==========================================================================
// TASKS
// ==========================================================================
if (input.length < 1) {
if (options.emptyWarning) {
grunt.log.warn('Template ' + src.cyan + ' not compiled because file is empty.');
}
grunt.registerMultiTask('eco', 'Compile Embedded CoffeeScript Templates', function() {
this.requiresConfig('eco');
return false;
}
var helpers = require('grunt-lib-contrib').init(grunt);
try {
output = eco.compile(grunt.file.read(src)).replace(/module\.exports/, '');
} catch (e) {
grunt.log.error("Error in " + src + ":\n" + e);
return false;
}
if (options.amd) {
output = 'define(function(){\n' +
' var template' + output + '\n' +
' return template;\n' +
'});\n';
} else {
output = 'window.JST["' + JSTpath + '"]' + output + '\n';
var basePath;
var srcFiles;
var newFileDest;
if (options.jstGlobalCheck) {
output = "if (!window.JST) {\n window.JST = {};\n}\n" + output;
}
}
this.files.forEach(function (file) {
file.dest = path.normalize(file.dest);
srcFiles = grunt.file.expand(file.src);
return output;
};
basePath = helpers.findBasePath(srcFiles, file.basePath);
console.log("basePath")
console.log(basePath)
grunt.registerMultiTask('eco', 'Compile Embedded CoffeeScript Templates', function() {
var options = this.options({
amd: false,
emptyWarning: true,
jstGlobalCheck: true
});
srcFiles.forEach(function (srcFile) {
newFileDest = helpers.buildIndividualDest(file.dest, srcFile, basePath);
compile(srcFile, newFileDest, basePath);
})
})
})
var compile = function(src, destPath, basePath) {
var eco = require('eco'),
js = '';
options = grunt.config('eco.app');
extension = typeof extension === "undefined" ? '.js' : extension;
var dirname = path.dirname(src);
var basename = path.basename(src, '.eco'),
dest = destPath + extension;
var JSTpath
// De-dup dest if we have .js.js - see issue #16
if (dest.match(/\.js\.js/)) {
dest = dest.replace(/\.js\.js/, ".js");
if (options.basePath) {
grunt.fail.warn('basePath is no longer supported. please refer to README.');
}
if (path.extname(src) === '.js') {
grunt.file.copy(src, dest);
return true;
}
this.files.forEach(function(file) {
var destFile = path.normalize(file.dest);
var srcFiles = file.src.filter(function(filepath) {
if (!grunt.file.exists(filepath)) {
grunt.log.warn('Source file "' + filepath + '" not found.');
return false;
} else {
return true;
}
});
if( options.bare !== false ) {
options.bare = true;
}
var compiled = [];
srcFiles.forEach(function(src) {
var res = compile(src, options);
try {
js = eco.compile(grunt.file.read(src));
if (res) {
compiled.push(res);
}
});
JSTpath = dirname + '/' + basename
JSTpath = JSTpath.replace(basePath, '').substr(1)
JSTpath = JSTpath.replace(/views\//, '')
if (compiled.length) {
grunt.file.write(destFile, compiled.join(grunt.util.normalizelf(grunt.util.linefeed)));
grunt.log.writeln('File ' + destFile.cyan + ' created.');
}
});
console.log('compiling %s', JSTpath)
js = js.replace(/module\.exports/, "if (! window.JST) { window.JST = {}}; window.JST['"+JSTpath+"']")
});
grunt.file.write(dest, js);
return true;
} catch (e) {
grunt.log.error("Error in " + src + ":\n" + e);
return false;
}
};
}
};

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc