This repository has been archived by the owner on Jul 24, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 33
/
gulpfile.js
185 lines (155 loc) · 5.71 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
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
const { src, dest, series, parallel, watch } = require('gulp');
const plugins = require('gulp-load-plugins')();
const jsLibs = [
'./node_modules/scrollpos-styler/scrollPosStyler.js',
'./node_modules/jquery/dist/jquery.slim.min.js',
'./node_modules/tether/dist/js/tether.min.js',
'./node_modules/bootstrap/dist/js/bootstrap.min.js',
'./node_modules/anchor-js/anchor.js',
'./themes/syndesis/js/**/*.js'
];
const port = 7000;
function css() {
return src('./themes/syndesis/scss/**/*.scss')
.pipe(plugins.sass())
.pipe(plugins.postcss())
.pipe(dest('./themes/syndesis/static/css'));
}
function js() {
return src(jsLibs)
.pipe(plugins.concat('syndesis.js'))
.pipe(dest('./themes/syndesis/static/js'));
}
function fonts() {
return src('./node_modules/@fortawesome/fontawesome-free/webfonts/*')
.pipe(dest('./themes/syndesis/static/fonts'));
}
function hugo(cb) {
const exec = require('child_process').exec;
const githubProject = process.env['CIRCLE_PROJECT_USERNAME'];
let baseURLArg = '';
if (githubProject && githubProject !== "syndesisio" && process.env['CIRCLE_PROJECT_REPONAME']) {
baseURLArg = ' --baseURL https://' + githubProject + '.github.io/' + process.env['CIRCLE_PROJECT_REPONAME'] + '/';
}
exec('hugo' + baseURLArg, function (err, stdout, stderr) {
console.log(stdout);
console.log(stderr);
cb(err);
});
}
function hugo_serve(cb) {
const exec = require('child_process').exec;
console.log('\n' +
' _______.____ ____ .__ __. _______ _______ _______. __ _______.\n' +
' / |\\ \\ / / | \\ | | | \\ | ____| / || | / |\n' +
' | (----` \\ \\/ / | \\| | | .--. || |__ | (----`| | | (----`\n' +
' \\ \\ \\_ _/ | . ` | | | | || __| \\ \\ | | \\ \\ \n' +
'.----) | | | | |\\ | | \'--\' || |____.----) | | | .----) | \n' +
'|_______/ |__| |__| \\__| |_______/ |_______|_______/ |__| |_______/ \n' +
' \n' +
'');
console.log('SYNDESIS is now running on port ' + port);
exec('hugo serve --port ' + port + ' --bind 0.0.0.0', function (err, stdout, stderr) {
console.log(stdout);
console.log(stderr);
cb(err);
});
}
function optimize_css() {
return src(['./public/**/*.css'])
.pipe(plugins.purgecss({
content: ['./public/**/*.html'],
safelist: [/^\.sps.*/, /\.collapse\.show$/, /\.collapsing$/, '.sidenav.active', '.anchorjs-icon']
}))
.pipe(dest('./public'));
}
function optimize_html() {
return src(['./public/**/*.html'])
.pipe(plugins.cacheBust({
type: 'timestamp'
}))
.pipe(plugins.htmlmin({
collapseBooleanAttributes: true,
collapseWhitespace: true,
minifyCSS: true,
minifyJS: true,
minifyURLs: true,
removeComments: true
}))
.pipe(dest('./public'));
}
function optimize_js() {
return src(['./public/**/*.js'])
.pipe(plugins.uglify())
.pipe(dest('./public'));
}
const optimize = series(optimize_html, optimize_css, optimize_js);
function live() {
console.log('Watching for changes...');
watch('./themes/syndesis/scss/**/*.scss', css),
watch(jsLibs, js)
watch('asciidoc-processor.js', manual_render)
}
function manual_export(cb) {
const svn = require('node-svn-ultimate');
return svn.commands.export('https://github.com/syndesisio/syndesis/trunk/doc', 'build/documentation', {
quiet: true,
force: true
}, cb)
}
function manual_render(done) {
const Asciidoctor = require('asciidoctor.js');
const asciidoctor = Asciidoctor();
const logger = asciidoctor.MemoryLogger.$new();
asciidoctor.LoggerManager.setLogger(logger);
const registry = asciidoctor.Extensions.create();
require('./asciidoc-processor.js')(registry);
delete require.cache[require.resolve('./asciidoc-processor.js')];
const asciidoctor_render = function(section) {
const name = `manual_render:asciidoctor (${section})`;
return {[name]: function(cb) {
asciidoctor.convertFile(`build/documentation/${section}/master.adoc`, {
'doctype': 'book',
'safe': 'safe',
'mkdirs': true,
'to_file': `documentation/manual/${section}/index.html`,
'attributes': {
'linkcss': true,
'stylesheet': '/css/syndesis.css',
'toc': 'left',
'toclevels': 1,
'toc-title': 'On this page'
},
'extension_registry': registry
});
const messages = logger.getMessages();
const hasErrors = messages.find(m => m.severity === 'ERROR');
if (hasErrors) {
const text = messages
.map(m => `${m.severity}: ${m.message['text']}`)
.join('\n');
cb(new Error(text));
}
cb();
}}[name];
}
const images = function(section) {
const name = `manual_render:images (${section})`;
return {[name]: function(cb) {
return src(`build/documentation/${section}/images/**/*.png`, {
base: `build/documentation/${section}`
}).pipe(dest(`documentation/manual/${section}`));
}}[name];
}
const sections = ['tutorials', 'integrating-applications', 'connecting', 'developing_extensions', 'managing_environments'];
const tasks = sections.flatMap(s => [asciidoctor_render(s), images(s)])
function manual_render_done(tasksDone) {
tasksDone();
done();
}
return parallel(...tasks, manual_render_done)();
}
const manual = series(manual_export, manual_render);
const serve = parallel(live, hugo_serve);
exports.build = series(parallel(manual, fonts, css, js), hugo, optimize);
exports.default = series(parallel(manual, js, css), parallel(hugo_serve, live));