-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgulpfile.js
123 lines (88 loc) · 2.54 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
const gulp = require('gulp')
const livereload = require('gulp-livereload');
const directoryName = 'public';
const fs = require('fs')
var exec = require('child_process').exec;
let flags = process.argv.splice(3)
flags = flags.map((item) => {
return item.replace('--', '');
})
let isDev = flags.indexOf('dev') >= 0;
let isProd = !isDev;
console.log('isProd',isProd);
require('marko/node-require');
require('lasso').configure({
"plugins": [{
"plugin": "lasso-marko"
},
{
"plugin": "lasso-less"
},
{
"plugin": "lasso-sass",
"config":{
"includePaths":["./node_modules","./src/styles"]
}
}
],
"fileWriter": {
"outputDir": `${directoryName}/static`,
"fingerprintsEnabled": isProd,
"urlPrefix": "static"
},
"minify": isProd,
"resolveCssUrls": true,
"bundlingEnabled": isProd,
"bundles": [
],
flags: flags
});
function copy() {
return gulp.src(['./media/**/*'])
.pipe(gulp.dest(`./${directoryName}/media`))
}
exports.copy = copy;
function marko(cb) {
return Promise.all([
renderPage('app-editor', 'index.html')
]);
};
exports.marko = marko;
function renderPage(pageName, htmlFileName) {
console.log('rendering ', pageName);
return new Promise(function (resolve, reject) {
let main = require(`./src/components/${pageName}/${pageName}`);
var htmlProm = main.render({});
htmlProm.then((html) => {
fs.writeFileSync(`./${directoryName}/` + htmlFileName, html)
console.log('done rendering: ', `${htmlFileName}`)
resolve();
})
})
}
var build = gulp.series(copy, marko);
let lastRun = new Date().getTime();
function buildShell(done) {
let now = new Date().getTime();
let shouldBuild = Math.abs(now - lastRun) > 7000;
console.log('shouldbuild', shouldBuild);
let cmd = `./build.sh`
for (let flag of flags) {
cmd = cmd + ` --${flag}`
}
shouldBuild && exec(cmd, function (err, stdout, stderr) {
console.log(stdout);
err && console.log(err);
livereload.reload();
});
lastRun = shouldBuild ? now : lastRun;
done();
}
function watch() {
livereload.listen();
gulp.watch(['src/lib/**/*.js','src/components/**/*.scss','src/styles/**/*.scss' ,'src/components/**/*.js', 'src/components/**/*.marko'], buildShell);
}
exports.watch = watch;
gulp.task('build', build);
gulp.task('default', build);
// gulp.task('watch', );