-
Notifications
You must be signed in to change notification settings - Fork 8
/
gulpfile.js
138 lines (121 loc) · 3.5 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
'use strict';
const gulp = require('gulp');
const rename = require('gulp-rename');
const del = require('del');
const filter = require('gulp-filter');
const gutil = require('gulp-util');
const path = require('path');
const sass = require('gulp-sass')(require('sass'));
const tildeImporter = require('node-sass-tilde-importer');
const paths = {
src: {
jekyll: 'projects/docs/jekyll.yaml',
fonts: 'src/assets/fonts/*.*',
scss: ['src/**/*.scss', '!src/docs/**/*.scss'],
scssMain: 'src/styles/core.scss',
readme: '*.md'
},
out: {
docs: {
base: 'docs',
css: 'docs/css',
fonts: 'docs/fonts',
images: 'docs/images',
},
dist: {
docs: 'dist/docs/**',
lib: 'dist/gentics-ui-core'
}
},
vendorStatics: []
};
// Allow to versions docs
prefixDocsVersion();
gulp.task('assets', gulp.series(
buildUiCoreTasks,
buildDocsTasks
));
// Run only when gentics-ui-core is building
function buildDocsTasks() {
return new Promise(gulp.series(
cleanDocsFolder,
copyDocsFiles,
copyJekyllConfig
));
}
// Run only when gentics-ui-core is not building
function buildUiCoreTasks() {
return new Promise(gulp.series(compileDistStyles, copyDistReadme));
}
function cleanDocsFolder() {
return del([`${paths.out.docs.base}/**`, `!${paths.out.docs.base}/_versions`, `!${paths.out.docs.base}/_versions/**`, `!${paths.out.docs.base}`]);
}
function copyDocsFiles() {
return streamToPromise(
gulp.src(paths.out.dist.docs)
.pipe(gulp.dest(paths.out.docs.base))
);
}
// Copy GH Pages publish configuration
function copyJekyllConfig() {
return streamToPromise(
gulp.src(paths.src.jekyll)
.pipe(rename('_config.yaml'))
.pipe(gulp.dest(paths.out.docs.base))
);
}
function compileDistStyles() {
return checkDistSASS().then(copyDistSASS);
}
function checkDistSASS() {
let stream = (
gulp.src(paths.src.scssMain, { base: '.' })
.pipe(sass({
errLogToConsole: true,
outputStyle: 'expanded',
includePaths: ['node_modules'],
importer: tildeImporter
}))
.on('error', () => {
process.exitCode = 1;
})
.on('error', sass.logError)
);
stream.pipe(gutil.noop());
return streamToPromise(stream);
}
function copyDistSASS() {
return streamToPromise(
gulp.src(paths.src.scss)
.pipe(gulp.dest(paths.out.dist.lib))
);
}
function copyDistReadme() {
return streamToPromise(
gulp.src(paths.src.readme)
.pipe(gulp.dest(paths.out.dist.lib))
);
}
/**
* Utility function to chain stream success/fail state as promises
*/
function streamToPromise(stream) {
return new Promise((resolve, reject) => {
stream.on('error', reject);
stream.on('end', resolve);
});
}
function resolvePromiseDummy() {
return new Promise(function(resolve, reject) {
resolve();
})
}
function prefixDocsVersion() {
const docsOutPathKeys = ['css', 'base', 'fonts', 'images'];
if (process.env.npm_config_docsVersion !== undefined) {
const version = process.env.npm_config_docsVersion.trim();
for ( let i in docsOutPathKeys ) {
paths.out.docs[docsOutPathKeys[i]] = paths.out.docs[docsOutPathKeys[i]].replace('docs', 'docs/_versions/' + version);
}
}
}