Skip to content

Commit 4ee2aef

Browse files
devversiontinayuangao
authored andcommitted
build: run tslint on tool files (#3436)
* Since we had a lot of TSLint issues on our tooling scripts & tasks, we should run TSLint on those as well. * Also updates Dgeni to latest version, because it now supports TypeScript typings.
1 parent 819fa0b commit 4ee2aef

File tree

6 files changed

+28
-25
lines changed

6 files changed

+28
-25
lines changed

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@
5454
"axe-core": "^2.1.7",
5555
"axe-webdriverjs": "^0.5.0",
5656
"conventional-changelog": "^1.1.0",
57-
"dgeni": "^0.4.2",
57+
"dgeni": "^0.4.7",
5858
"dgeni-packages": "^0.16.5",
5959
"firebase-admin": "^4.0.6",
6060
"firebase-tools": "^2.2.1",

tools/gulp/tasks/docs.ts

+14-13
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,14 @@
1-
import gulp = require('gulp');
1+
import {task, src, dest} from 'gulp';
2+
import {Dgeni} from 'dgeni';
3+
import * as path from 'path';
4+
5+
// Node packages that lack of types.
26
const markdown = require('gulp-markdown');
37
const transform = require('gulp-transform');
48
const highlight = require('gulp-highlight-files');
59
const rename = require('gulp-rename');
610
const flatten = require('gulp-flatten');
711
const hljs = require('highlight.js');
8-
import {task} from 'gulp';
9-
import * as path from 'path';
1012

1113
// Our docs contain comments of the form `<!-- example(...) -->` which serve as placeholders where
1214
// example code should be inserted. We replace these comments with divs that have a
@@ -19,10 +21,10 @@ const EXAMPLE_PATTERN = /<!--\W*example\(([^)]+)\)\W*-->/g;
1921
// documentation page. Using a RegExp to rewrite links in HTML files to work in the docs.
2022
const LINK_PATTERN = /(<a[^>]*) href="([^"]*)"/g;
2123

22-
gulp.task('docs', ['markdown-docs', 'highlight-docs', 'api-docs'])
24+
task('docs', ['markdown-docs', 'highlight-docs', 'api-docs']);
2325

24-
gulp.task('markdown-docs', () => {
25-
return gulp.src(['src/lib/**/*.md', 'guides/*.md'])
26+
task('markdown-docs', () => {
27+
return src(['src/lib/**/*.md', 'guides/*.md'])
2628
.pipe(markdown({
2729
// Add syntax highlight using highlight.js
2830
highlight: (code: string, language: string) => {
@@ -36,28 +38,27 @@ gulp.task('markdown-docs', () => {
3638
}
3739
}))
3840
.pipe(transform(transformMarkdownFiles))
39-
.pipe(gulp.dest('dist/docs/markdown'));
41+
.pipe(dest('dist/docs/markdown'));
4042
});
4143

42-
gulp.task('highlight-docs', () => {
44+
task('highlight-docs', () => {
4345
// rename files to fit format: [filename]-[filetype].html
4446
const renameFile = (path: any) => {
4547
const extension = path.extname.slice(1);
4648
path.basename = `${path.basename}-${extension}`;
4749
};
4850

49-
return gulp.src('src/examples/**/*.+(html|css|ts)')
51+
return src('src/examples/**/*.+(html|css|ts)')
5052
.pipe(flatten())
5153
.pipe(rename(renameFile))
5254
.pipe(highlight())
53-
.pipe(gulp.dest('dist/docs/examples'));
55+
.pipe(dest('dist/docs/examples'));
5456
});
5557

5658
task('api-docs', () => {
57-
const Dgeni = require('dgeni');
5859
const docsPackage = require(path.resolve(__dirname, '../../dgeni'));
59-
const dgeni = new Dgeni([docsPackage]);
60-
return dgeni.generate();
60+
const docs = new Dgeni([docsPackage]);
61+
return docs.generate();
6162
});
6263

6364
/** Updates the markdown file's content to work inside of the docs app. */

tools/gulp/tasks/e2e.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import * as path from 'path';
33

44
import {SOURCE_ROOT, DIST_ROOT, PROJECT_ROOT} from '../constants';
55
import {
6-
tsBuildTask, sassBuildTask, copyTask, buildAppTask, execNodeTask,
6+
tsBuildTask, copyTask, buildAppTask, execNodeTask,
77
vendorTask, sequenceTask, serverTask
88
} from '../task_helpers';
99

tools/gulp/tasks/lint.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,4 +12,4 @@ gulp.task('stylelint', execNodeTask(
1212
));
1313

1414
/** Task to run TSLint against the e2e/ and src/ directories. */
15-
gulp.task('tslint', execNodeTask('tslint', ['-c', 'tslint.json', 'src/**/*.ts', 'e2e/**/*.ts']));
15+
gulp.task('tslint', execNodeTask('tslint', ['-c', 'tslint.json', '+(src|e2e|tools)/**/*.ts']));

tools/gulp/tasks/screenshots.ts

+8-6
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ import * as admin from 'firebase-admin';
55
import {openScreenshotsBucket, openFirebaseScreenshotsDatabase} from '../task_helpers';
66
import {updateGithubStatus} from '../util-functions';
77

8-
const request = require('request');
98
const imageDiff = require('image-diff');
109

1110
const SCREENSHOT_DIR = './screenshots';
@@ -37,12 +36,15 @@ task('screenshots', () => {
3736

3837
function updateFileResult(database: admin.database.Database, prNumber: string,
3938
filenameKey: string, result: boolean) {
40-
return database.ref(FIREBASE_REPORT).child(prNumber).child('results').child(filenameKey).set(result);
39+
return getPullRequestRef(database, prNumber).child('results').child(filenameKey).set(result);
4140
}
4241

43-
function updateResult(database: admin.database.Database, prNumber: string,
44-
result: boolean) {
45-
return database.ref(FIREBASE_REPORT).child(prNumber).child('result').set(result).then(() => result);
42+
function updateResult(database: admin.database.Database, prNumber: string, result: boolean) {
43+
return getPullRequestRef(database, prNumber).child('result').set(result).then(() => result);
44+
}
45+
46+
function getPullRequestRef(database: admin.database.Database, prNumber: string) {
47+
return database.ref(FIREBASE_REPORT).child(prNumber);
4648
}
4749

4850
function updateTravis(database: admin.database.Database,
@@ -58,7 +60,7 @@ function updateTravis(database: admin.database.Database,
5860
function getScreenshotFiles(database: admin.database.Database) {
5961
let bucket = openScreenshotsBucket();
6062
return bucket.getFiles({ prefix: 'golds/' }).then(function(data: any) {
61-
return data[0].filter((file:any) => file.name.endsWith('.screenshot.png'));
63+
return data[0].filter((file: any) => file.name.endsWith('.screenshot.png'));
6264
});
6365
}
6466

tools/gulp/util-functions.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ export function updateGithubStatus(result: boolean, prNumber: string) {
99
let data = JSON.stringify({
1010
state: state,
1111
target_url: `http://material2-screenshots.firebaseapp.com/${prNumber}`,
12-
context: "screenshot-diff",
12+
context: 'screenshot-diff',
1313
description: `Screenshot test ${state}`
1414
});
1515

@@ -20,13 +20,13 @@ export function updateGithubStatus(result: boolean, prNumber: string) {
2020
'Content-Length': Buffer.byteLength(data)
2121
};
2222

23-
return new Promise((resolve, reject) => {
23+
return new Promise((resolve) => {
2424
request({
2525
url: `https://api.github.com/repos/angular/material2/statuses/${sha}`,
2626
method: 'POST',
2727
form: data,
2828
headers: headers
29-
}, function (error: any, response: any, body: any){
29+
}, function (error: any, response: any) {
3030
resolve(response.statusCode);
3131
});
3232
});

0 commit comments

Comments
 (0)