-
Notifications
You must be signed in to change notification settings - Fork 0
/
gulpfile.js
145 lines (111 loc) · 3.17 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
132
133
134
135
136
137
138
139
140
141
142
143
144
145
const gulp = require('gulp')
const livereload = require('gulp-livereload');
const directoryName = 'public';
const rename = require("gulp-rename");
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').install();
require('babel-core/register');
require('lasso').configure({
require: {
transforms: [
{
transform: 'lasso-babel-transform',
config: {
// directly specify babel options
babelOptions: {
presets: [
"es2015",
"stage-3"
],
plugins: ["syntax-dynamic-import"]
}
}
}
]
},
"plugins": [{
"plugin": "lasso-marko"
},
{
"plugin": "lasso-sass",
"config":{
"includePaths":["./node_modules"]
}
}
],
"fileWriter": {
"outputDir": `${directoryName}/static`,
"fingerprintsEnabled": isProd,
"urlPrefix": "static"
},
"minify": isProd,
"resolveCssUrls": true,
"bundlingEnabled": isProd,
"bundles": [
],
flags: flags
});
function material(cb){
return gulp.src(['./node_modules/@material/**/*'])
.pipe(gulp.dest(`./node_modules/@material-ts/`))
}
exports.material = material
function materialConvert(cb){
return gulp.src("./node_modules/@material/**/*.js")
.pipe(rename(function (path) {
path.extname = ".ts";
}))
.pipe(gulp.dest("./node_modules/@material"));
}
exports.matconvert = materialConvert
function marko(cb) {
return Promise.all([
renderPage('main', 'main.html')
]);
};
exports.marko = marko;
function renderPage(pageName, htmlFileName) {
return new Promise(function (resolve, reject) {
let main = require(`./examples/${pageName}`);
var htmlProm = main.render({});
htmlProm.then((html) => {
fs.writeFileSync(`./${directoryName}/` + htmlFileName, html)
console.log('done rendering: ', `${htmlFileName}`)
resolve();
})
})
}
var build = gulp.series(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/**/*.js', 'src/components/**/*.marko'], buildShell);
}
exports.watch = watch;
gulp.task('build', build);
gulp.task('default', build);
// gulp.task('watch', );