Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 29 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,35 @@ Type: `Object`

[aster-generate](https://github.com/asterjs/aster-generate)/[escodegen](https://github.com/Constellation/escodegen) code generation options.

#### options.generator

Allows customizing generator to be used. By default [aster-generate](https://github.com/asterjs/aster-generate) is used, passing `options` to create the `Observable` factory function.



#### options.destinator

Allows customization of the destinator function. By default the following is used. Note that `options.generate` will be the `generator` Obserable factory function (see `options.generator` above)

```js
function defaultDestinator(options) {
return function (files) {
files = options.generate(files);

return files
.flatMap(function (file) {
// ...
}
.flatMap(function (file) {
return writeFile(file.path, file.contents);
})
.zip(files, function (result, file) { return file });
}
}
```

This customization can be useful if you want to write to a destination that is not the file system, such as a database or simply to `console.log` for debugging, for testing etc.

## License

[MIT License](http://en.wikipedia.org/wiki/MIT_License)
Expand Down
26 changes: 21 additions & 5 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,13 @@ var path = require('path');
var pathJoin = path.join;
var dirName = path.dirname;

module.exports = function (path, options) {
var generate = asterGenerate(options);

function defaultDestinator(options) {
return function (files) {
files = generate(files);
files = options.generate(files);

return files
.flatMap(function (file) {
var filePath = pathJoin(path, file.path);
var filePath = pathJoin(options.path, file.path);

return createPath(dirName(filePath)).map(function () {
return {
Expand All @@ -31,4 +29,22 @@ module.exports = function (path, options) {
})
.zip(files, function (result, file) { return file });
};
}

module.exports = function (path, options) {
if (path === Object(path)) {
options = path
}
options = options || {};

var generator = options.generator || asterGenerate;
var generate = typeof generator === 'function' ? generator(options) : generator;

options.generate = generate
options.path = path

var destinator = options.destinator || defaultDestinator
var dest = typeof destinator === 'function' ? destinator(options) : destinator

return dest
};
10 changes: 5 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,14 @@
"test": "mocha"
},
"dependencies": {
"aster-generate": "^0.1.1",
"mkdirp": "^0.5.0",
"rx": "^2.3.11"
"aster-generate": "*",
"mkdirp": "^0.5.1",
"rx": "^4.1.0"
},
"devDependencies": {
"chai": "*",
"esprima": "^1.2.2",
"esprima": "^3.1.1",
"mocha": "*",
"rimraf": "^2.2.8"
"rimraf": "*"
}
}
7 changes: 6 additions & 1 deletion test/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,16 @@ it('test', function (done) {
contents: '{"version":3,"sources":["file.js"],"names":["a"],"mappings":"AAAmB;AAAAA,CAAA,GAAE,CAAF"}'
}
];
var index = 0;

// simulating file sequence and applying transformation
dest('.tmp', {comment: true, sourceMap: true})(Rx.Observable.fromArray(input))
// checking against array of expected results iteratively
.zip(expected, assert.deepEqual)
// .zip(expected, assert.deepEqual)
.do(function (file) {
assert.deepEqual(file, expected[index++]);
})

// subscribing to check results
.subscribe(function () {}, done, done);
});
Expand Down
Loading