forked from microsoft/vscode-docs
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgulpfile.releasenotes.js
125 lines (97 loc) · 4.04 KB
/
gulpfile.releasenotes.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
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
var gulp = require('gulp');
var es = require('event-stream');
var markdownIt = require('markdown-it');
var frontMatter = require('gulp-front-matter');
var rename = require('gulp-rename');
var keybindings = require('./keybindings/doc.keybindings');
var imagemin = require('gulp-imagemin');
var File = require('vinyl');
var common = require('./gulpfile.common');
var RN_SRC_ROOT = 'release-notes';
var DEST_ROOT = 'out/vscode-website/src';
var RAW_ROOT = DEST_ROOT + '/views/raw';
var releaseNotes = [];
var sources = [
RN_SRC_ROOT + '/**/*.md'
];
var css = [
RN_SRC_ROOT + '/**/css/*.{css,CSS}'
];
function getStaticContent() {
var images = gulp.src([RN_SRC_ROOT + '/**/images/**/*.{png,PNG,jpg,JPG}']).pipe(imagemin());
var gifs = gulp.src([RN_SRC_ROOT + '/**/images/**/*.{gif,GIF}']);
return [images, gifs];
}
gulp.task('copy-releasenotes-images', function () {
console.log('Copying over rest of release notes static content files...');
return es.merge(getStaticContent())
.pipe(rename(function (path) {
path.basename = path.dirname + '_' + path.basename; path.dirname = '';
}))
.pipe(gulp.dest(DEST_ROOT + '/dist'));
});
gulp.task('copy-releasenotes-raw-images', function () {
console.log('Copying over release note images for raw services...');
return es.merge(getStaticContent())
.pipe(gulp.dest(RAW_ROOT));
});
gulp.task('compile-releasenotes', ['compile-releasenotes-handlebars', 'copy-releasenotes-raw-images', 'copy-releasenotes-images', 'compile-releasenotes-markdown', 'compile-releasenotes-css'], function () {
console.log('Creating release notes index...');
var tpl = common.swigCompiler('scripts/templates/releasenotes-nav-template.html');
releaseNotes = releaseNotes.sort(function (a, b) {
return parseFloat(b.Order) - parseFloat(a.Order);
});
// Compile most recent releasenotes as latest.handlebars
var template = common.swigCompiler('scripts/templates/releasenotes-template.html');
var latest = new File({
path: 'latest.handlebars',
contents: new Buffer(template(releaseNotes[0]))
});
es.readArray([latest])
.pipe(gulp.dest(DEST_ROOT + '/views/updates'));
var file = new File({
path: 'updateNav.handlebars',
contents: new Buffer(tpl({ articles: releaseNotes }))
});
return es.readArray([file])
.pipe(gulp.dest(DEST_ROOT + '/views/partials'));
});
function applyHtmlTemplate(file) {
var rn = common.mapFileToArticle(file);
// if (rn.Link.toLowerCase() == 'latest') {
// rn.Link = '';
// }
console.log("Compiling RN: " + rn.Title);
rn = common.compileMarkdown(file, rn);
if (rn.Order) { // Only add articles that have the order metadata
releaseNotes.push(rn);
}
// Render template
var tpl = common.swigCompiler('scripts/templates/releasenotes-template.html');
var result = tpl(rn);
file.contents = new Buffer(result, 'utf8');
return file;
}
gulp.task('compile-releasenotes-handlebars', function () {
console.log('Parsing release notes MD, applying templates...');
return gulp.src(sources)
.pipe(frontMatter({ property: 'data', remove: true }))
.pipe(es.mapSync(applyHtmlTemplate))
.pipe(rename({ extname: '.handlebars' }))
.pipe(gulp.dest(DEST_ROOT + '/views/updates'));
});
gulp.task('compile-releasenotes-markdown', function() {
console.log('Parsing markdown and moving to public folder...');
return gulp.src(sources)
.pipe(frontMatter({ property: 'data', remove: true }))
.pipe(gulp.dest(RAW_ROOT));
});
gulp.task('compile-releasenotes-css', function () {
console.log('Copying CSS styles for in-product release notes markdown...');
return gulp.src(css)
.pipe(gulp.dest(RAW_ROOT));
});