2017-07-20 04:54:07 -04:00
|
|
|
/**
|
|
|
|
* @license
|
|
|
|
* Copyright Google Inc. All Rights Reserved.
|
|
|
|
*
|
|
|
|
* Use of this source code is governed by an MIT-style license that can be
|
|
|
|
* found in the LICENSE file at https://angular.io/license
|
|
|
|
*/
|
|
|
|
|
|
|
|
const {I18N_FOLDER, I18N_DATA_FOLDER} = require('./cldr/extract');
|
|
|
|
|
2017-02-03 03:10:41 -05:00
|
|
|
// clang-format entry points
|
|
|
|
const srcsToFmt = [
|
2017-03-07 14:04:30 -05:00
|
|
|
'packages/**/*.{js,ts}',
|
2017-02-03 03:10:41 -05:00
|
|
|
'modules/benchmarks/**/*.{js,ts}',
|
|
|
|
'modules/e2e_util/**/*.{js,ts}',
|
|
|
|
'modules/playground/**/*.{js,ts}',
|
|
|
|
'tools/**/*.{js,ts}',
|
|
|
|
'!tools/public_api_guard/**/*.d.ts',
|
|
|
|
'./*.{js,ts}',
|
2017-08-02 22:15:30 -04:00
|
|
|
'!**/node_modules/**',
|
|
|
|
'!**/dist/**',
|
|
|
|
'!**/built/**',
|
2017-02-03 03:10:41 -05:00
|
|
|
'!shims_for_IE.js',
|
2017-07-20 04:54:07 -04:00
|
|
|
`!${I18N_DATA_FOLDER}/**/*.{js,ts}`,
|
|
|
|
`!${I18N_FOLDER}/available_locales.ts`,
|
|
|
|
`!${I18N_FOLDER}/currencies.ts`,
|
|
|
|
`!${I18N_FOLDER}/locale_en.ts`,
|
|
|
|
'!tools/gulp-tasks/cldr/extract.js',
|
2018-03-01 13:41:35 -05:00
|
|
|
'!tools/ts-api-guardian/test/fixtures/**',
|
2017-02-03 03:10:41 -05:00
|
|
|
];
|
|
|
|
|
2018-07-18 12:09:55 -04:00
|
|
|
/**
|
|
|
|
* Gulp stream that wraps the gulp-git status task
|
|
|
|
* and converts the stdout into a stream of files
|
|
|
|
*/
|
|
|
|
function gulpStatus() {
|
|
|
|
const Vinyl = require('vinyl');
|
|
|
|
const path = require('path');
|
|
|
|
const gulpGit = require('gulp-git');
|
|
|
|
const through = require('through2');
|
|
|
|
const srcStream = through.obj();
|
|
|
|
|
|
|
|
const opt = {cwd: process.cwd()};
|
|
|
|
|
|
|
|
// https://git-scm.com/docs/git-status#_short_format
|
|
|
|
const RE_STATUS = /^((\s\w)|(\w+)|\?{0,2})\s([\w\+\-\/\\\.]+)(\s->\s)?([\w\+\-\/\\\.]+)*\n/gm;
|
|
|
|
|
|
|
|
gulpGit.status({args: '--porcelain', quiet: true}, function(err, stdout) {
|
|
|
|
if (err) return srcStream.emit('error', err);
|
|
|
|
|
|
|
|
const data = stdout.toString();
|
|
|
|
let currentMatch;
|
|
|
|
|
|
|
|
while ((currentMatch = RE_STATUS.exec(data)) !== null) {
|
|
|
|
// This is necessary to avoid infinite loops with zero-width matches
|
|
|
|
if (currentMatch.index === RE_STATUS.lastIndex) {
|
|
|
|
RE_STATUS.lastIndex++;
|
|
|
|
}
|
|
|
|
|
|
|
|
// status
|
|
|
|
const status = currentMatch[1].trim().toLowerCase();
|
|
|
|
|
|
|
|
// File has been deleted
|
|
|
|
if (status.includes('d')) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
// file path
|
|
|
|
const currentFilePath = currentMatch[4];
|
|
|
|
|
|
|
|
// new file path in case its been moved
|
|
|
|
const newFilePath = currentMatch[6];
|
|
|
|
const filePath = newFilePath || currentFilePath;
|
|
|
|
|
|
|
|
srcStream.write(new Vinyl({
|
|
|
|
path: path.resolve(opt.cwd, filePath),
|
|
|
|
cwd: opt.cwd,
|
|
|
|
}));
|
|
|
|
}
|
|
|
|
|
|
|
|
srcStream.end();
|
|
|
|
});
|
|
|
|
|
|
|
|
return srcStream;
|
|
|
|
}
|
|
|
|
|
2017-02-03 03:10:41 -05:00
|
|
|
module.exports = {
|
|
|
|
// Check source code for formatting errors (clang-format)
|
|
|
|
enforce: (gulp) => () => {
|
|
|
|
const format = require('gulp-clang-format');
|
|
|
|
const clangFormat = require('clang-format');
|
|
|
|
return gulp.src(srcsToFmt).pipe(
|
|
|
|
format.checkFormat('file', clangFormat, {verbose: true, fail: true}));
|
|
|
|
},
|
|
|
|
|
|
|
|
// Format the source code with clang-format (see .clang-format)
|
|
|
|
format: (gulp) => () => {
|
|
|
|
const format = require('gulp-clang-format');
|
|
|
|
const clangFormat = require('clang-format');
|
|
|
|
return gulp.src(srcsToFmt, {base: '.'})
|
|
|
|
.pipe(format.format('file', clangFormat))
|
|
|
|
.pipe(gulp.dest('.'));
|
2018-07-18 12:09:55 -04:00
|
|
|
},
|
|
|
|
|
|
|
|
// Format only the changed source code files with clang-format (see .clang-format)
|
|
|
|
'format-changed': (gulp) => () => {
|
|
|
|
const format = require('gulp-clang-format');
|
|
|
|
const clangFormat = require('clang-format');
|
|
|
|
const gulpFilter = require('gulp-filter');
|
|
|
|
|
|
|
|
return gulpStatus()
|
|
|
|
.pipe(gulpFilter(srcsToFmt))
|
|
|
|
.pipe(format.format('file', clangFormat))
|
|
|
|
.pipe(gulp.dest('.'));
|
2017-02-03 03:10:41 -05:00
|
|
|
}
|
|
|
|
};
|