This repository has been archived by the owner on Dec 5, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathindex.js
101 lines (89 loc) · 2.45 KB
/
index.js
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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
const gulp = require('gulp');
const Elixir = require('laravel-elixir');
let gulpNunjucksRender;
/*
|----------------------------------------------------------------
| Nunjucks Compilation Task
|----------------------------------------------------------------
|
| This task offers a simple way to render your Nunjucks assets.
| You can either render a single file or a entire directory.
| Don't forget the path if you specify alternate options.
|
*/
Elixir.config.nunjucks = {
folder: 'nunjucks',
outputFolder: '',
search: '/**/*',
options: {
path: 'resources/assets/nunjucks',
},
};
class NunjucksTask extends Elixir.Task {
/**
* Create a new NunjucksTask instance.
*
* @param {string} name
* @param {GulpPaths} paths
* @param {object|null} options
*/
constructor(name, paths, options) {
super(name, null, paths);
this.options = options;
}
/**
* Lazy load the task dependencies.
*/
loadDependencies() {
gulpNunjucksRender = require('gulp-nunjucks-render');
}
/**
* Build the Gulp task.
*/
gulpTask($) {
return (
gulp
.src(this.src.path)
.pipe(this.nunjucks())
.on('error', this.onError())
.pipe($.if(!this.output.isDir, $.rename(this.output.name)))
.pipe(this.saveAs(gulp))
.pipe(this.onSuccess())
);
}
/**
* Run the files through Nunjucks.
*/
nunjucks() {
this.recordStep('Running Nunjucks');
return gulpNunjucksRender(Object.assign(
Elixir.config.nunjucks.options,
this.options
));
}
/**
* Register file watchers.
*/
registerWatchers() {
this
.watch(`${Elixir.config.get('assets.nunjucks.folder')}/**/*`)
.ignore(this.output.path)
;
}
}
Elixir.extend('nunjucks', (src, output, baseDir, options) => {
new NunjucksTask('nunjucks', getPaths(src, baseDir, output), options);
});
/**
* Prep the Gulp src and output paths.
*
* @param {string|Array} src
* @param {string|null} baseDir
* @param {string|null} output
* @return {GulpPaths}
*/
var getPaths = function(src, baseDir, output) {
return new Elixir.GulpPaths()
.src(src || '', baseDir || Elixir.config.get('assets.nunjucks.folder'))
.output(output || Elixir.config.get('public.nunjucks.outputFolder'), 'app.html');
};