Skip to content

Commit

Permalink
Merge pull request #4 from Polymer/is-sources
Browse files Browse the repository at this point in the history
add isSource() method to check against source globs
  • Loading branch information
FredKSchott authored Jan 20, 2017
2 parents c0d27d0 + 18ffb01 commit 8610325
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 0 deletions.
7 changes: 7 additions & 0 deletions custom_typings/minimatch-all.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
declare module 'minimatch-all' {

function minimatchAll(filePath: string, globs: string[])
: boolean;

export = minimatchAll;
}
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
},
"dependencies": {
"@types/node": "^6.0.41",
"minimatch-all": "^1.1.0",
"plylog": "^0.4.0"
},
"devDependencies": {
Expand Down
5 changes: 5 additions & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import * as fs from 'fs';
import * as path from 'path';
import * as logging from 'plylog';
import minimatchAll = require('minimatch-all');

const logger = logging.getLogger('polymer-project-config');

Expand Down Expand Up @@ -227,6 +228,10 @@ export class ProjectConfig {
return (!!this.shell && (this.shell === filepath));
}

isSource(filepath: string): boolean {
return minimatchAll(filepath, this.sources);
}

/**
* Validates that a configuration is accurate, and that all paths are
* contained within the project root.
Expand Down
21 changes: 21 additions & 0 deletions test/index_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -238,6 +238,27 @@ suite('Project Config', () => {

});

suite('isSource()', () => {

test('matches source file paths and does not match other file paths', () => {
const relativeRoot = 'public';
const absoluteRoot = path.resolve(relativeRoot);
const config = new ProjectConfig({
root: relativeRoot,
entrypoint: 'foo.html',
fragments: ['bar.html'],
shell: 'baz.html',
});
assert.isTrue(config.isSource(config.entrypoint));
assert.isTrue(config.isSource(config.shell));
assert.isTrue(config.isSource(path.resolve(absoluteRoot, 'foo.html')));
assert.isTrue(config.isSource(path.resolve(absoluteRoot, 'bar.html')));
assert.isTrue(config.isSource(path.resolve(absoluteRoot, 'baz.html')));
assert.isFalse(config.isSource(path.resolve(absoluteRoot, 'not-a-fragment.html')));
});

});

suite('validate()', () => {

test('returns true for valid configuration', () => {
Expand Down

0 comments on commit 8610325

Please sign in to comment.