This repository has been archived by the owner on Apr 17, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathgulpfile.js
97 lines (81 loc) · 2.35 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
////////////////////////////////////////////////////////////////////////////////
// Imports
////////////////////////////////////////////////////////////////////////////////
// Gulp
const gulp = require('gulp');
const gutil = require('gulp-util');
const clean = require('gulp-clean');
// Markdown & JSON
const marked = require('marked');
const markdownToJSON = require('gulp-markdown-to-json');
////////////////////////////////////////////////////////////////////////////////
// Project Settings
////////////////////////////////////////////////////////////////////////////////
// Paths
const path = {
api: './api/',
src: './src/'
};
// Markdown Options
marked.setOptions({
pedantic: true,
smartypants: true
});
////////////////////////////////////////////////////////////////////////////////
// Tooling
////////////////////////////////////////////////////////////////////////////////
const createAPIResponse = src => (dist, filename) => {
gulp.src(src)
.pipe(filename ? gutil.buffer() : gutil.noop())
.pipe(markdownToJSON(marked, filename ? filename : false))
.pipe(gulp.dest(dist));
};
const createRootAPI = createAPIResponse(path.src + '**/*.md');
////////////////////////////////////////////////////////////////////////////////
// Building Tasks
////////////////////////////////////////////////////////////////////////////////
// Markdown to API Tasks - You edit, and make new versions of these, as you see
// fit
gulp.task('api', () => {
createRootAPI(path.api, 'global.json');
createRootAPI(path.api);
});
// Image Tasks
gulp.task('copyImages', () => {
gulp.src(path.src + '**/*.{jpg, png, gif, tif, svg}')
.pipe(gulp.dest(path.api));
});
//Cleaning Tasks
gulp.task('clean', () => {
return gulp.src(path.api, {read: false})
.pipe(clean());
});
////////////////////////////////////////////////////////////////////////////////
// Meta Tasks
////////////////////////////////////////////////////////////////////////////////
// Build
gulp.task('build', [
'clean',
'api',
'copyImages'
]);
// Watch
gulp.task('watch', ['build'], () => {
gulp.watch(path.src + '**/*.md', [
'api-path',
]);
gulp.watch(path.src + '**/*.{jpg, png, gif, tif, svg}', [
'copyImages'
]);
});
// Default
gulp.task('default', () => {
console.log(
`
Avaliable Gulp Tasks
--------------------
- Build: gulp build
- Watch: gulp watch
`
);
});