Skip to content
This repository was archived by the owner on May 1, 2020. It is now read-only.

Commit 178ccac

Browse files
committed
Merge branch 'topic/dot-psci-task'
2 parents dcc0263 + 988f523 commit 178ccac

File tree

4 files changed

+55
-0
lines changed

4 files changed

+55
-0
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
.DS_Store
22
*.log
3+
.psci
34
node_modules

README.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,11 @@ Invokes the `psc-make` command.
6363
- browserNamespace: String value that sets `--browser-namespace=<string>`
6464
- output: String value that sets `--output=<string>`
6565

66+
### purescript.dotPsci()
67+
68+
Generates a `.psci` file in the current directory. Each source file is
69+
added with the `:m` command.
70+
6671
### purescript.docgen(options)
6772

6873
Invokes the `docgen` command.

index.js

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,12 @@ var gutil = require('gulp-util')
44
, through = require('through2')
55
, lodash = require('lodash')
66
, cp = require('child_process')
7+
, fs = require('fs')
8+
, path = require('path')
79
, PLUGIN = 'gulp-purescript'
10+
, DOTPSCI = '.psci'
11+
, LOADM = ':m'
12+
, CWD = process.cwd()
813
, OPTIONS = {
914
psc: {
1015
flags: {
@@ -121,6 +126,23 @@ function pscMake(opts) {
121126
});
122127
}
123128

129+
function dotPsci(opts) {
130+
var stream = through.obj(function(file, env, cb){
131+
if (file.isNull()) {
132+
this.push(file);
133+
return cb();
134+
}
135+
if (file.isStream()) {
136+
this.emit('error', new gutil.PluginError(PLUGIN, 'Streaming not supported'));
137+
return cb();
138+
}
139+
this.push(new Buffer(LOADM + ' ' + path.relative(CWD, file.path) + '\n'));
140+
cb();
141+
});
142+
stream.pipe(fs.createWriteStream(DOTPSCI));
143+
return stream;
144+
}
145+
124146
function docgen(opts) {
125147
return acc(function(files, cb){
126148
var args = options(OPTIONS.docgen, opts).concat(files)
@@ -146,6 +168,7 @@ function docgen(opts) {
146168

147169
module.exports = {
148170
docgen: docgen,
171+
dotPsci: dotPsci,
149172
psc: psc,
150173
pscMake: pscMake
151174
}

test.js

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,3 +84,29 @@ it('should fail to compile with an error message', function(cb){
8484
}
8585
});
8686
});
87+
88+
it('should write a .psci file', function(cb){
89+
var stream = purescript.dotPsci()
90+
, fixture = 'Fixture1.purs'
91+
, output = ':m ' + fixture + '\n'
92+
;
93+
94+
stream.on('data', function(line){
95+
assert.equal(output, line.toString());
96+
cb();
97+
});
98+
99+
fs.readFile(fixture, function(e, buffer){
100+
if (e) cb(assert(false));
101+
else {
102+
stream.write(new gutil.File({
103+
cwd: __dirname,
104+
base: __dirname,
105+
path: __dirname + '/' + fixture,
106+
contents: buffer,
107+
stat: {mtime: new Date()}
108+
}));
109+
stream.end();
110+
}
111+
});
112+
});

0 commit comments

Comments
 (0)