forked from electricessence/TypeScript.NET
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgulpfile.js
More file actions
241 lines (199 loc) · 5.4 KB
/
Copy pathgulpfile.js
File metadata and controls
241 lines (199 loc) · 5.4 KB
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
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
// List of all tasks by name and for reuse as dependencies.
const
TASK_TYPESCRIPT = 'typescript',
TASK_TYPESCRIPT_MIN = 'typescript.min',
TASK_TYPESCRIPT_ES6 = 'typescript.es6',
TASK_TYPEDOC = 'typedoc',
TASK_VERSION_BUMP_MINOR = 'version-bump-minor',
TASK_VERSION_BUMP_PATCH = 'version-bump-patch',
TASK_NUGET_PACK = 'nuget-pack',
TASK_DEFAULT = 'default';
var gulp = require('gulp'),
del = require('del'),
rename = require('gulp-rename'),
sourcemaps = require('gulp-sourcemaps'),
uglify = require('gulp-uglify'),
typescript = require('gulp-typescript'),
typedoc = require('gulp-typedoc'),
replace = require('gulp-replace'),
semver = require('semver'),
nugetpack = require('gulp-nuget-pack');
const EVENT_END = 'end';
const DOCS = './documentation';
gulp.task(
// This renders the same output as WebStorm's configuration.
TASK_TYPESCRIPT, function()
{
var options = {
tscPath: './node_modules/typescript/bin/tsc',
outDir: './source',
noImplicitAny: true,
module: 'amd',
target: 'es5',
removeComments: true,
sourceMap: true
};
// In order to mirror WebStorm's compiler option, gulp-tsc is used.
return gulp
.src(['./source/**/*.ts'])
.pipe(require('gulp-tsc')(options))
.pipe(gulp.dest('./source'))
;
}
)
;
gulp.task(
TASK_TYPESCRIPT_MIN, function()
{
del(['./min/**/*']);
var typescriptOptions/*:typescript.Params*/ = {
noImplicitAny: true,
module: 'amd',
target: 'es5',
removeComments: true
};
// This isn't ideal, but it works and points the maps to the original source.
var sourceMapOptions/*:sourcemaps.WriteOptions*/ = {
sourceRoot: function(file/*:VinylFile*/)/*:string*/
{
var count = (file.relative + '').split("\\").length;
var result = '';
for(var i = 1; i<count; i++)
{
result += '../';
}
return result + '../source/';
},
includeContent: false
};
var uglifyOptions = {
preserveComments: 'license'
};
return gulp
.src(['./source/**/*.ts'])
.pipe(sourcemaps.init())
.pipe(typescript(typescriptOptions))
.pipe(uglify(uglifyOptions))
.pipe(sourcemaps.write('.', sourceMapOptions))
.pipe(gulp.dest('./min'));
});
gulp.task(
TASK_TYPESCRIPT_ES6, function()
{
del(['./es6/**/*']);
var typescriptOptions/*:typescript.Params*/ = {
noImplicitAny: true,
target: 'es6',
removeComments: true
};
return gulp
.src(['./source/**/*.ts'])
.pipe(sourcemaps.init())
.pipe(typescript(typescriptOptions))
.pipe(sourcemaps.write('.'))
.pipe(gulp.dest('./es6'));
});
gulp.task(
TASK_TYPEDOC, function(done)
{
var typedocOptions = {
name: 'TypeScript.NET',
out: './documentation',
module: 'amd',
target: 'es5',
// excludeNotExported: true // Disable till fixed.
includeDeclarations: true,
ignoreCompilerErrors: false,
version: true
};
// Step 1: Render type-docs..
console.log('TypeDocs: rendering');
return gulp
.src('source')
.pipe(typedoc(typedocOptions))
.on(EVENT_END, typedocFixes);
function typedocFixes()
{
// Step 2-A: Fix for issue with search that places a [BACK-SLASH] instead of a [SLASH].
console.log('TypeDocs: applying fixes');
const SEARCH_FOLDER = DOCS + '/assets/js';
gulp
.src(SEARCH_FOLDER + '/search.js')
.pipe(replace('\\\\', '/'))
.pipe(replace('/_', '/'))
.pipe(gulp.dest(SEARCH_FOLDER));
// Step 2-B: Refactor (rewrite) html files.
gulp.src(DOCS + '/**/*.html')
.pipe(replace('/_', '/'))
.pipe(replace(' href="_', ' href="'))
.pipe(rename(function(path)
{
path.basename = path.basename.replace(/^_/, '');
}))
.pipe(gulp.dest(DOCS))
.on(EVENT_END, cleanup);
}
function cleanup()
{
// Step 3: Delete all old underscored html files.
del.sync(DOCS + '/**/_*.html', function()
{
console.log('TypeDocs: fixes complete');
done();
});
}
});
/**
* @param {string} type
* @returns {NodeJS.ReadableStream}
*/
function bumpVersion(type)
{
// No tsd yet.
var fs = require('fs'),
bump = require('gulp-bump');
var pkg = JSON.parse(fs.readFileSync('./package.json', 'utf8'));
// increment version
var newVer = semver.inc(pkg.version, type);
return gulp.src(['./bower.json', './package.json'])
.pipe(bump({ version: newVer }))
.pipe(gulp.dest('./'));
}
gulp.task(TASK_VERSION_BUMP_PATCH, function() { bumpVersion('patch'); });
gulp.task(TASK_VERSION_BUMP_MINOR, function() { bumpVersion('minor'); });
gulp.task(TASK_NUGET_PACK,
[
TASK_TYPESCRIPT,
TASK_TYPESCRIPT_MIN
],
function(callback) {
var fs = require('fs');
var pkg = JSON.parse(fs.readFileSync('./package.json', 'utf8'));
nugetpack({
id: "TypeScript.NET.AMD",
title: pkg.name,
version: pkg.version,
authors: "https://github.com/electricessence/",
description: pkg.description,
summary: "See http://electricessence.github.io/TypeScript.NET/ for details.",
language: "en-us",
projectUrl: "https://github.com/electricessence/TypeScript.NET",
licenseUrl: "https://raw.githubusercontent.com/electricessence/TypeScript.NET/master/LICENSE.md",
tags: "typescript tsc .NET TypeScript.NET LINQ",
excludes: ["js/**/*.dev.js"],
outputDir: ".nuget"
},
[
'source',
'min',
'*.json',
'*.md'
],
callback
);
});
gulp.task(TASK_DEFAULT, [
TASK_TYPESCRIPT,
TASK_TYPESCRIPT_MIN,
TASK_TYPEDOC
]);