This repository has been archived by the owner on Jan 21, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 4
/
gulpfile.js
178 lines (159 loc) · 4.46 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
'use strict'
const gulp = require('gulp')
const browserify = require('browserify')
const tsify = require('tsify')
const babelify = require('babelify')
const source = require('vinyl-source-stream')
const buffer = require('vinyl-buffer')
const sourcemaps = require('gulp-sourcemaps')
const browserSync = require('browser-sync').create()
const sass = require('gulp-sass')
const cleanCSS = require('gulp-clean-css')
const log = require('fancy-log')
function bundleHandler (name) {
return function bundle () {
return browserify({ standalone: name })
.add([
`./src/${name}/view_model.ts`
])
.plugin(tsify)
.transform(babelify, { extensions: ['.tsx', '.ts'] })
.bundle().on('error', log)
.pipe(source(`${name}.js`))
.pipe(buffer())
.pipe(sourcemaps.init({ loadMaps: true }))
.pipe(sourcemaps.write('./'))
.pipe(gulp.dest('./docs/js'))
.pipe(browserSync.stream({ once: true }))
}
}
function serveHandler (name) {
return function serve () {
return browserSync.init({
server: 'docs',
startPath: `/${name}.html`
})
}
}
function watchHandler (name, bundlerName) {
return function watch () {
gulp.watch(
[
`./src/${name}/*.ts`,
'./src/main/*.ts',
'./src/view_models/*.ts'
],
gulp.series(bundlerName, 'browserSyncReload')
)
gulp.watch(
'./docs/scss/**/*.scss',
gulp.series('css', 'browserSyncReload')
)
}
}
gulp.task('browserSyncReload', function (done) {
browserSync.reload()
done()
})
gulp.task('css', function () {
return gulp
.src('./docs/scss/**/*.scss')
.pipe(sass().on('error', sass.logError))
.pipe(cleanCSS({ level: { 2: { all: true } } }))
.pipe(gulp.dest('./docs/css'))
})
/* Bundlers */
gulp.task('bundleRamlOas', bundleHandler('raml_oas'))
gulp.task('bundleVisualization', bundleHandler('visualization'))
gulp.task('bundleCustomValidation', bundleHandler('custom_validation'))
gulp.task('bundleDiff', bundleHandler('diff'))
gulp.task('bundleLearnRaml', bundleHandler('learn_raml'))
gulp.task('bundleResolution', bundleHandler('resolution'))
/* Servers */
gulp.task('serveRamlOas', gulp.series(
'css',
'bundleRamlOas',
gulp.parallel(
serveHandler('raml_oas'),
watchHandler('raml_oas', 'bundleRamlOas')
)
))
gulp.task('serveVisualization', gulp.series(
'css',
'bundleVisualization',
gulp.parallel(
serveHandler('visualization'),
watchHandler('visualization', 'bundleVisualization')
)
))
gulp.task('serveCustomValidation', gulp.series(
'css',
'bundleCustomValidation',
gulp.parallel(
serveHandler('custom_validation'),
watchHandler('custom_validation', 'bundleCustomValidation')
)
))
gulp.task('serveDiff', gulp.series(
'css',
'bundleDiff',
gulp.parallel(
serveHandler('diff'),
watchHandler('diff', 'bundleDiff')
)
))
gulp.task('serveLearnRaml', gulp.series(
'css',
'bundleLearnRaml',
gulp.parallel(
serveHandler('learn_raml'),
watchHandler('learn_raml', 'bundleLearnRaml')
)
))
gulp.task('serveResolution', gulp.series(
'css',
'bundleResolution',
gulp.parallel(
serveHandler('resolution'),
watchHandler('resolution', 'bundleResolution')
)
))
/*
Reloads RAML examples from "raml-org/raml-examples" and writes them
into "docs/raml-examples.json". The JSON file is then used by
the Load Modal to populate "Load RAML File" dropdown.
*/
gulp.task('reloadRamlExamples', async () => {
const fs = require('fs')
const path = require('path')
const axios = require('axios')
const apiBase = 'https://api.github.com/repos/raml-org/raml-examples'
const ghExamples = []
const commitsResp = await axios.get(`${apiBase}/commits`)
const latestCommit = commitsResp.data[0].sha
const filesResp = await axios.get(`${apiBase}/git/trees/${latestCommit}?recursive=1`)
const ramlFiles = filesResp.data.tree.filter(el => {
return el.type === 'blob' && el.path.endsWith('.raml')
})
ramlFiles.forEach(el => {
ghExamples.push({
name: el.path,
url: `https://raw.githubusercontent.com/raml-org/raml-examples/master/${el.path}`
})
})
fs.writeFileSync(
path.join(__dirname, 'docs', 'raml-examples.json'),
JSON.stringify(ghExamples, null, 2))
})
/* Bundle all the demos */
gulp.task('bundleAll', gulp.series(
'css',
'bundleRamlOas',
'bundleVisualization',
'bundleCustomValidation',
'bundleDiff',
'bundleLearnRaml',
'bundleResolution',
'reloadRamlExamples'
))
gulp.task('serve', gulp.series('serveLearnRaml'))