-
Notifications
You must be signed in to change notification settings - Fork 33
/
index.civet
43 lines (37 loc) · 1.1 KB
/
index.civet
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
through = require 'through2'
replaceExt = require 'replace-ext'
PluginError = require 'plugin-error'
interface Options
extension?: string
inlineMap?: boolean
js?: boolean
// or any other Civet options
module.exports = (options?: Options) ->
function transform(file, encoding: string, callback)
if file.isNull()
return callback null, file
if file.isStream()
return callback new PluginError 'gulp-civet', 'Streaming not supported'
compileOptions := {
inlineMap: Boolean file.sourceMap
filename: file.path
...options
}
extension :=
if compileOptions.extension?
compileOptions.extension
else if compileOptions.js
".civet.jsx"
else
".civet.tsx"
dest := replaceExt file.path, extension
input := file.contents.toString encoding
let compiled: string
try
compiled = await require('@danielx/civet').compile input, options
catch err
return callback new PluginError 'gulp-civet', err
file.contents = Buffer.from compiled
file.path = dest;
callback null, file
through.obj transform