chore: put everything in the _analyze.dart file
6x faster dart analyze
This commit is contained in:
parent
6ab19dd095
commit
867705bd2c
|
@ -5,6 +5,7 @@ var path = require('path');
|
||||||
var glob = require('glob');
|
var glob = require('glob');
|
||||||
var fs = require('fs');
|
var fs = require('fs');
|
||||||
var util = require('./util');
|
var util = require('./util');
|
||||||
|
var yaml = require('js-yaml');
|
||||||
|
|
||||||
module.exports = function(gulp, plugins, config) {
|
module.exports = function(gulp, plugins, config) {
|
||||||
return function() {
|
return function() {
|
||||||
|
@ -12,7 +13,15 @@ module.exports = function(gulp, plugins, config) {
|
||||||
return util.forEachSubDirSequential(
|
return util.forEachSubDirSequential(
|
||||||
config.dest,
|
config.dest,
|
||||||
function(dir) {
|
function(dir) {
|
||||||
var srcFiles = [].slice.call(glob.sync('web/**/*.dart', {
|
var pubspecContents = fs.readFileSync(path.join(dir, 'pubspec.yaml'));
|
||||||
|
var pubspec = yaml.safeLoad(pubspecContents);
|
||||||
|
var packageName = pubspec.name;
|
||||||
|
|
||||||
|
var libFiles = [].slice.call(glob.sync('lib/**/*.dart', {
|
||||||
|
cwd: dir
|
||||||
|
}));
|
||||||
|
|
||||||
|
var webFiles = [].slice.call(glob.sync('web/**/*.dart', {
|
||||||
cwd: dir
|
cwd: dir
|
||||||
}));
|
}));
|
||||||
|
|
||||||
|
@ -20,9 +29,12 @@ module.exports = function(gulp, plugins, config) {
|
||||||
cwd: dir
|
cwd: dir
|
||||||
}));
|
}));
|
||||||
var analyzeFile = ['library _analyzer;'];
|
var analyzeFile = ['library _analyzer;'];
|
||||||
srcFiles.concat(testFiles).forEach(function(fileName, index) {
|
libFiles.concat(testFiles).concat(webFiles).forEach(function(fileName, index) {
|
||||||
if (fileName !== tempFile && fileName.indexOf("/packages/") === -1) {
|
if (fileName !== tempFile && fileName.indexOf("/packages/") === -1) {
|
||||||
analyzeFile.push('import "./' + fileName + '" as mod' + index + ';');
|
if (fileName.indexOf('lib') == 0) {
|
||||||
|
fileName = 'package:' + packageName + '/' + path.relative('lib', fileName);
|
||||||
|
}
|
||||||
|
analyzeFile.push('import "' + fileName + '" as mod' + index + ';');
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
fs.writeFileSync(path.join(dir, tempFile), analyzeFile.join('\n'));
|
fs.writeFileSync(path.join(dir, tempFile), analyzeFile.join('\n'));
|
||||||
|
@ -33,15 +45,8 @@ module.exports = function(gulp, plugins, config) {
|
||||||
);
|
);
|
||||||
|
|
||||||
function analyze(dirName, done) {
|
function analyze(dirName, done) {
|
||||||
// analyze files in lib directly – or you mess up package: urls
|
|
||||||
var sources = [].slice.call(glob.sync('lib/**/*.dart', {
|
|
||||||
cwd: dirName
|
|
||||||
}));
|
|
||||||
|
|
||||||
sources.push(tempFile);
|
|
||||||
|
|
||||||
//TODO remove --package-warnings once dartanalyzer handles transitive libraries
|
//TODO remove --package-warnings once dartanalyzer handles transitive libraries
|
||||||
var args = ['--fatal-warnings', '--package-warnings'].concat(sources);
|
var args = ['--fatal-warnings', '--package-warnings'].concat(tempFile);
|
||||||
|
|
||||||
var stream = spawn(config.command, args, {
|
var stream = spawn(config.command, args, {
|
||||||
// inherit stdin and stderr, but filter stdout
|
// inherit stdin and stderr, but filter stdout
|
||||||
|
|
Loading…
Reference in New Issue