-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathgulpfile.js
131 lines (115 loc) · 3.53 KB
/
gulpfile.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
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
// configuration
var SRC_LIGHTER_DIR = 'examples/hello-lighter/src-lighter';
var SRC_MODULES_DIR = 'examples/hello-lighter/src-modules';
var DEST_DIR = 'examples/hello-lighter/dest';
// dependencies
var fs = require('fs');
var gulp = require('gulp');
var runSequence = require('run-sequence');
var yamljs = require('yamljs');
var replaceTask = require('gulp-replace-task');
var through = require('through-gulp');
var yaml = require('gulp-yaml');
var mergeJson = require('gulp-merge-json');
var rename = require('gulp-rename');
var wrap = require("gulp-wrap");
var mergeJsonIndividual = require('gulp-merge-json-individual');
var jsonToYaml = require('gulp-json-to-yaml');
var jsonExtends = require('gulp-json-include-and-merge');
var lighterAutoRef = require('./src/gulp-lighter-auto-ref');
// configuration by src-lighter files
// TODO: Dont load these at startup. They should load at runtime so that gulp watch could update files on change.
var DIALOG_PROTOTYPE = yamljs.load(SRC_LIGHTER_DIR + '/prototypes/dialog.yaml');
var TEMPLATE_PROTOTYPE = yamljs.load(SRC_LIGHTER_DIR + '/prototypes/template.yaml');
var APP_TEMPLATE = fs.readFileSync(SRC_LIGHTER_DIR + '/config-templates/app-template.yaml.hbs', 'utf8');
var DIALOG_FIELD_REPLACEMENTS = fs.readFileSync(SRC_LIGHTER_DIR + '/replacements/dialog-fields.yaml', 'utf8');
/**
Default.
Runs when you type 'gulp'.
*/
gulp.task('default', ['all']);
/**
Runs all task on any file change.
*/
gulp.task('watch', function() {
console.log('watch start.');
gulp.watch([SRC_MODULES_DIR + '/**/*.*', SRC_LIGHTER_DIR + '/**/*.*'], ['all']);
});
/**
Runs when you type 'gulp all'.
Note: steps run in parallel.
*/
gulp.task('all', function() {
processWebResources();
processTemplates();
processDialogs();
processApps();
});
/**
Process Apps
*/
function processApps(){
gulp.src(SRC_MODULES_DIR + '/*/apps/**/*.*')
.pipe(yaml({ space: 2 }))
.pipe(wrap(APP_TEMPLATE,{},{engine:'handlebars'}))
.pipe(rename({extname: ".yaml"}))
.pipe(gulp.dest(DEST_DIR))
}
gulp.task('apps', function () {
console.log('Start task: apps');
processApps();
})
/**
Copy WebResources
*/
function processWebResources(){
gulp.src(SRC_MODULES_DIR + '/*/webresources/**/*.*') // Get source files with gulp.src
.pipe(gulp.dest(DEST_DIR)) // Outputs the file in the destination folder
}
gulp.task('webResources', function () {
console.log('Start task: webResources');
processWebResources();
})
/**
Process templates.
TODO: Exclude fragments & prototypes - maybe put those in special src directory.
*/
function processTemplates(){
console.log('Start task: templates');
// Copy the ftl files.
gulp.src(SRC_MODULES_DIR + '/*/templates/**/*.ftl')
.pipe(gulp.dest(DEST_DIR))
// Process the yaml files.
gulp.src(SRC_MODULES_DIR + '/*/templates/**/*.yaml')
.pipe(yaml({ space: 2 }))
.pipe(jsonExtends())
.pipe(mergeJsonIndividual(TEMPLATE_PROTOTYPE))
.pipe(lighterAutoRef())
.pipe(jsonToYaml())
.pipe(gulp.dest(DEST_DIR))
}
gulp.task('templates', function(){
processTemplates();
});
/**
Processes dialogs
*/
function processDialogs(){
console.log('Start task: dialogs');
gulp.src(SRC_MODULES_DIR + '/*/dialogs/**/*.yaml')
.pipe(replaceTask({
usePrefix: false,
patterns: [
{
yaml: DIALOG_FIELD_REPLACEMENTS
}]
}))
.pipe(yaml({ space: 2 }))
.pipe(jsonExtends())
.pipe(mergeJsonIndividual(DIALOG_PROTOTYPE))
.pipe(jsonToYaml())
.pipe(gulp.dest(DEST_DIR))
}
gulp.task('dialogs', function(){
processDialogs();
});