Skip to content

Commit

Permalink
v0.1.0, not tested
Browse files Browse the repository at this point in the history
  • Loading branch information
wryk committed Aug 7, 2013
1 parent 7b6dd7f commit 564cd27
Show file tree
Hide file tree
Showing 4 changed files with 92 additions and 1 deletion.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
node_modules
32 changes: 31 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,34 @@
component-livescript
====================

Component(1) plugin to compile LiveScript
Component(1) plugin to compile LiveScript files on-the-fly. This allows you to write components in LiveScript.
Based on [anthonyshort/component-coffee](https://github.com/anthonyshort/component-coffee).


## Installation

```bash
npm install component-livescript
```

## Usage

```bash
component build --use component-livescript
```

Add you LiveScript files to the `scripts` section of your `component.json`

```json
{
"name": "foo",
"scripts": ["index.ls", "foo.ls", "bar.ls"]
}
```

Now in your `index.ls` file you can require or [require!](http://livescript.net/#operators) it:

```livescript
foo = require 'foo'
require! bar
```
31 changes: 31 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
var livescript = require('livescript');
var path = require('path');
var fs = require('fs');

module.exports = function (builder) {
builder.hook('before scripts', function (pkg, next) {
if (pkg.config.scripts === undefined) {
return next();
}

var ls = pkg.config.scripts.filter(function(file) {
return path.extname(file) === '.ls';
});

if (ls.length === 0) {
return next();
}

ls.forEach(function (file) {
var realpath = pkg.path(file);
var str = fs.readFileSync(realpath, 'utf8');
var compiled = livescript.compile(str, { filename: realpath, bare: true });
var filename = file.replace('.ls', '.js');

pkg.addFile('scripts', filename, compiled);
pkg.removeFile('scripts', file);
});

next();
});
};
29 changes: 29 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
{
"name": "component-livescript",
"version": "0.1.0",
"description": "LiveScript plugin for Component(1)",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"repository": {
"type": "git",
"url": "https://github.com/wryk/component-livescript.git"
},
"keywords": [
"component",
"livescript",
"plugin"
],
"author": "Mathieu Gallé-Tessonneau",
"license": "MIT",
"bugs": {
"url": "https://github.com/wryk/component-livescript/issues"
},
"dependencies": {
"LiveScript": "~1.2.0"
},
"peerDependencies": {
"component": ">= 0.14"
}
}

0 comments on commit 564cd27

Please sign in to comment.