From 17a85ac049d66786a4814b6718b3332f63cfa411 Mon Sep 17 00:00:00 2001 From: Paul Gschwendtner Date: Sat, 4 Mar 2017 19:36:58 +0100 Subject: [PATCH] build: run tslint on tool files * 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. --- package.json | 2 +- tools/gulp/tasks/docs.ts | 27 ++++++++++++++------------- tools/gulp/tasks/e2e.ts | 2 +- tools/gulp/tasks/lint.ts | 2 +- tools/gulp/tasks/screenshots.ts | 14 ++++++++------ tools/gulp/util-functions.ts | 6 +++--- 6 files changed, 28 insertions(+), 25 deletions(-) diff --git a/package.json b/package.json index 302cdd0297bc..7a6295f8a841 100644 --- a/package.json +++ b/package.json @@ -54,7 +54,7 @@ "axe-core": "^2.1.7", "axe-webdriverjs": "^0.5.0", "conventional-changelog": "^1.1.0", - "dgeni": "^0.4.2", + "dgeni": "^0.4.7", "dgeni-packages": "^0.16.5", "firebase-admin": "^4.0.6", "firebase-tools": "^2.2.1", diff --git a/tools/gulp/tasks/docs.ts b/tools/gulp/tasks/docs.ts index 551ebcff984f..9007f9df2334 100644 --- a/tools/gulp/tasks/docs.ts +++ b/tools/gulp/tasks/docs.ts @@ -1,12 +1,14 @@ -import gulp = require('gulp'); +import {task, src, dest} from 'gulp'; +import {Dgeni} from 'dgeni'; +import * as path from 'path'; + +// Node packages that lack of types. const markdown = require('gulp-markdown'); const transform = require('gulp-transform'); const highlight = require('gulp-highlight-files'); const rename = require('gulp-rename'); const flatten = require('gulp-flatten'); const hljs = require('highlight.js'); -import {task} from 'gulp'; -import * as path from 'path'; // Our docs contain comments of the form `` which serve as placeholders where // example code should be inserted. We replace these comments with divs that have a @@ -19,10 +21,10 @@ const EXAMPLE_PATTERN = //g; // documentation page. Using a RegExp to rewrite links in HTML files to work in the docs. const LINK_PATTERN = /(]*) href="([^"]*)"/g; -gulp.task('docs', ['markdown-docs', 'highlight-docs', 'api-docs']) +task('docs', ['markdown-docs', 'highlight-docs', 'api-docs']); -gulp.task('markdown-docs', () => { - return gulp.src(['src/lib/**/*.md', 'guides/*.md']) +task('markdown-docs', () => { + return src(['src/lib/**/*.md', 'guides/*.md']) .pipe(markdown({ // Add syntax highlight using highlight.js highlight: (code: string, language: string) => { @@ -36,28 +38,27 @@ gulp.task('markdown-docs', () => { } })) .pipe(transform(transformMarkdownFiles)) - .pipe(gulp.dest('dist/docs/markdown')); + .pipe(dest('dist/docs/markdown')); }); -gulp.task('highlight-docs', () => { +task('highlight-docs', () => { // rename files to fit format: [filename]-[filetype].html const renameFile = (path: any) => { const extension = path.extname.slice(1); path.basename = `${path.basename}-${extension}`; }; - return gulp.src('src/examples/**/*.+(html|css|ts)') + return src('src/examples/**/*.+(html|css|ts)') .pipe(flatten()) .pipe(rename(renameFile)) .pipe(highlight()) - .pipe(gulp.dest('dist/docs/examples')); + .pipe(dest('dist/docs/examples')); }); task('api-docs', () => { - const Dgeni = require('dgeni'); const docsPackage = require(path.resolve(__dirname, '../../dgeni')); - const dgeni = new Dgeni([docsPackage]); - return dgeni.generate(); + const docs = new Dgeni([docsPackage]); + return docs.generate(); }); /** Updates the markdown file's content to work inside of the docs app. */ diff --git a/tools/gulp/tasks/e2e.ts b/tools/gulp/tasks/e2e.ts index ccc1d0f4901c..5b5a87f1ab4c 100644 --- a/tools/gulp/tasks/e2e.ts +++ b/tools/gulp/tasks/e2e.ts @@ -3,7 +3,7 @@ import * as path from 'path'; import {SOURCE_ROOT, DIST_ROOT, PROJECT_ROOT} from '../constants'; import { - tsBuildTask, sassBuildTask, copyTask, buildAppTask, execNodeTask, + tsBuildTask, copyTask, buildAppTask, execNodeTask, vendorTask, sequenceTask, serverTask } from '../task_helpers'; diff --git a/tools/gulp/tasks/lint.ts b/tools/gulp/tasks/lint.ts index 971c417267e1..3de5960740f1 100644 --- a/tools/gulp/tasks/lint.ts +++ b/tools/gulp/tasks/lint.ts @@ -12,4 +12,4 @@ gulp.task('stylelint', execNodeTask( )); /** Task to run TSLint against the e2e/ and src/ directories. */ -gulp.task('tslint', execNodeTask('tslint', ['-c', 'tslint.json', 'src/**/*.ts', 'e2e/**/*.ts'])); +gulp.task('tslint', execNodeTask('tslint', ['-c', 'tslint.json', '+(src|e2e|tools)/**/*.ts'])); diff --git a/tools/gulp/tasks/screenshots.ts b/tools/gulp/tasks/screenshots.ts index 699a77b14fde..f9cfc0ab0b0d 100644 --- a/tools/gulp/tasks/screenshots.ts +++ b/tools/gulp/tasks/screenshots.ts @@ -5,7 +5,6 @@ import * as admin from 'firebase-admin'; import {openScreenshotsBucket, openFirebaseScreenshotsDatabase} from '../task_helpers'; import {updateGithubStatus} from '../util-functions'; -const request = require('request'); const imageDiff = require('image-diff'); const SCREENSHOT_DIR = './screenshots'; @@ -37,12 +36,15 @@ task('screenshots', () => { function updateFileResult(database: admin.database.Database, prNumber: string, filenameKey: string, result: boolean) { - return database.ref(FIREBASE_REPORT).child(prNumber).child('results').child(filenameKey).set(result); + return getPullRequestRef(database, prNumber).child('results').child(filenameKey).set(result); } -function updateResult(database: admin.database.Database, prNumber: string, - result: boolean) { - return database.ref(FIREBASE_REPORT).child(prNumber).child('result').set(result).then(() => result); +function updateResult(database: admin.database.Database, prNumber: string, result: boolean) { + return getPullRequestRef(database, prNumber).child('result').set(result).then(() => result); +} + +function getPullRequestRef(database: admin.database.Database, prNumber: string) { + return database.ref(FIREBASE_REPORT).child(prNumber); } function updateTravis(database: admin.database.Database, @@ -58,7 +60,7 @@ function updateTravis(database: admin.database.Database, function getScreenshotFiles(database: admin.database.Database) { let bucket = openScreenshotsBucket(); return bucket.getFiles({ prefix: 'golds/' }).then(function(data: any) { - return data[0].filter((file:any) => file.name.endsWith('.screenshot.png')); + return data[0].filter((file: any) => file.name.endsWith('.screenshot.png')); }); } diff --git a/tools/gulp/util-functions.ts b/tools/gulp/util-functions.ts index e78f9b94b07d..8acc5d4ca3b6 100644 --- a/tools/gulp/util-functions.ts +++ b/tools/gulp/util-functions.ts @@ -9,7 +9,7 @@ export function updateGithubStatus(result: boolean, prNumber: string) { let data = JSON.stringify({ state: state, target_url: `http://material2-screenshots.firebaseapp.com/${prNumber}`, - context: "screenshot-diff", + context: 'screenshot-diff', description: `Screenshot test ${state}` }); @@ -20,13 +20,13 @@ export function updateGithubStatus(result: boolean, prNumber: string) { 'Content-Length': Buffer.byteLength(data) }; - return new Promise((resolve, reject) => { + return new Promise((resolve) => { request({ url: `https://api.github.com/repos/angular/material2/statuses/${sha}`, method: 'POST', form: data, headers: headers - }, function (error: any, response: any, body: any){ + }, function (error: any, response: any) { resolve(response.statusCode); }); });