Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
88 changes: 45 additions & 43 deletions .vscode/tasks.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,63 +9,65 @@
"tasks": [
{
"label": "Compile",
"type": "npm",
"script": "compile",
"isBackground": true,
"problemMatcher": [
"$tsc-watch",
{
"base": "$tslint5",
"fileLocation": "relative"
}
],
"group": {
"kind": "build",
"isDefault": true
}
},
{
"label": "Hygiene",
"type": "gulp",
"task": "hygiene-watch",
"task": "watch",
"isBackground": true,
"presentation": {
"echo": true,
"reveal": "always",
"reveal": "never",
"focus": false,
"panel": "shared"
"panel": "dedicated"
},
"problemMatcher": [
"$tsc-watch",
{
"base": "$tslint5",
"fileLocation": "relative"
"applyTo": "allDocuments",
"fileLocation": "relative",
"background": {
"beginsPattern": {
"regexp": "^Hygiene started"
},
"endsPattern": {
"regexp": "^(Hygiene failed with errors|Hygiene passed with 0 errors)"
}
},
"pattern": [
{
"regexp": "^([^\\s].*)\\((\\d+|\\d+,\\d+|\\d+,\\d+,\\d+,\\d+)\\):\\s+(error|warning|info)\\s+(TS\\d+)\\s*:\\s*(.*)$",
"file": 1,
"location": 2,
"severity": 3,
"code": 4,
"message": 5
}
]
},
{
"applyTo": "allDocuments",
"fileLocation": "relative",
"background": {
"beginsPattern": {
"regexp": "^Hygiene started"
},
"endsPattern": {
"regexp": "^(Hygiene failed with errors|Hygiene passed with 0 errors)"
}
},
"pattern": [
{
"regexp": "^(WARNING|ERROR):(\\s+\\(\\S*\\))?\\s+(\\S.*)\\[(\\d+), (\\d+)\\]:\\s+(.*)$",
"severity": 1,
"file": 3,
"line": 4,
"column": 5,
"message": 6
}
]
}
],
"group": {
"kind": "build",
"isDefault": true
}
},
{
// Task that will replace 'Compile' and 'Hygiene', after being battle-tested.
"label": "Watch",
"type": "gulp",
"task": "watch",
"isBackground": true,
"presentation": {
"echo": true,
"reveal": "always",
"focus": false,
"panel": "shared"
},
"problemMatcher": [
"$tsc-watch",
{
"base": "$tslint5",
"fileLocation": "relative"
}
]
}
]
}
7 changes: 2 additions & 5 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,14 +28,11 @@ You may see warnings that ```The engine "vscode" appears to be invalid.```, you

### Incremental Build

Run the `Compile` and `Hygiene` build Tasks from the [Command Palette](https://code.visualstudio.com/docs/editor/tasks) (short cut `CTRL+SHIFT+B` or `⇧⌘B`)
Run the `Compile` build Tasks from the [Command Palette](https://code.visualstudio.com/docs/editor/tasks) (short cut `CTRL+SHIFT+B` or `⇧⌘B`)

### Errors and Warnings

TypeScript errors and warnings will be displayed in VS Code in the following areas:
* Problems Panel (`CTRL+SHIFT+M` or `⇧⌘M`)
* Terminal running the `Compile` task
* Terminal running the `Hygiene` task
TypeScript errors and warnings will be displayed in the `Problems` window of Visual Studio Code:

### Validate your changes

Expand Down
49 changes: 45 additions & 4 deletions gulpfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ const path = require('path');
const debounce = require('debounce');
const jeditor = require("gulp-json-editor");
const del = require('del');
const sourcemaps = require('gulp-sourcemaps');
const fs = require('fs');

/**
* Hygiene works by creating cascading subsets of all our files and
Expand Down Expand Up @@ -53,6 +55,13 @@ const tslintFilter = [
'!**/typings/**/*',
];

const copyrightHeader = [
'// Copyright (c) Microsoft Corporation. All rights reserved.',
'// Licensed under the MIT License.',
'',
'\'use strict\';'
].join('\n');

gulp.task('hygiene', () => run({ mode: 'all', skipFormatCheck: true, skipIndentationCheck: true }));

gulp.task('compile', () => run({ mode: 'compile', skipFormatCheck: true, skipIndentationCheck: true, skipLinter: true }));
Expand Down Expand Up @@ -105,6 +114,18 @@ gulp.task('cover:disable', () => {
const hygiene = (options) => {
options = options || {};
let errorCount = 0;
const addedFiles = getAddedFilesSync();
console.log(colors.blue('Hygiene started.'));

const copyrights = es.through(function (file) {
if (addedFiles.indexOf(file.path) !== -1 && file.contents.toString('utf8').indexOf(copyrightHeader) !== 0) {
// Use tslint format.
console.error(`ERROR: (copyright) ${file.relative}[1,1]: Missing or bad copyright statement`);
errorCount++;
}

this.emit('data', file);
});

const indentation = es.through(function (file) {
file.contents
Expand Down Expand Up @@ -245,7 +266,8 @@ const hygiene = (options) => {
}

result = result
.pipe(filter(tslintFilter));
.pipe(filter(tslintFilter))
.pipe(copyrights);

if (!options.skipFormatCheck) {
// result = result
Expand All @@ -259,8 +281,18 @@ const hygiene = (options) => {

result = result
.pipe(tscFilesTracker)
.pipe(sourcemaps.init())
.pipe(tsc())
.js.pipe(gulp.dest(dest))
.pipe(sourcemaps.mapSources(function (sourcePath, file) {
const tsFileName = path.basename(file.path).replace(/js$/, 'ts');
const qualifiedSourcePath = path.dirname(file.path).replace('out/', 'src/').replace('out\\', 'src\\');
if (!fs.existsSync(path.join(qualifiedSourcePath, tsFileName))) {
console.error(`ERROR: (source-maps) ${file.path}[1,1]: Source file not found`);
}
return path.join(path.relative(path.dirname(file.path), qualifiedSourcePath), tsFileName);
}))
.pipe(sourcemaps.write('.', { includeContent: false }))
.pipe(gulp.dest(dest))
.pipe(es.through(null, function () {
if (errorCount > 0) {
const errorMessage = `Hygiene failed with errors 👎 . Check 'gulpfile.js'.`;
Expand All @@ -275,6 +307,8 @@ const hygiene = (options) => {
this.emit('end');
}))
.on('error', exitHandler.bind(this, options));

return result;
};

/**
Expand Down Expand Up @@ -320,10 +354,17 @@ function run(options) {
}
function getStagedFilesSync() {
const out = cp.execSync('git diff --cached --name-only', { encoding: 'utf8' });
const some = out
return out
.split(/\r?\n/)
.filter(l => !!l);
return some;
}
function getAddedFilesSync() {
const out = cp.execSync('git status -u -s', { encoding: 'utf8' });
return out
.split(/\r?\n/)
.filter(l => !!l)
.filter(l => l.startsWith('A') || l.startsWith('??'))
.map(l => path.join(__dirname, l.substring(2).trim()));
}

/**
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -1713,6 +1713,7 @@
"gulp-filter": "^5.0.1",
"gulp-gitmodified": "^1.1.1",
"gulp-json-editor": "^2.2.1",
"gulp-sourcemaps": "^2.6.4",
"gulp-typescript": "^3.2.2",
"gulp-watch": "^4.3.11",
"husky": "^0.14.3",
Expand Down
Loading