1 | 'use strict';
|
2 |
|
3 | var path = require('path');
|
4 | var globby = require('globby');
|
5 | var multimatch = require('multimatch');
|
6 | var util = require('../util');
|
7 |
|
8 | function deleteFile(path, store) {
|
9 | var file = store.get(path);
|
10 | file.state = 'deleted';
|
11 | file.contents = null;
|
12 | store.add(file);
|
13 | }
|
14 |
|
15 | module.exports = function (paths, options) {
|
16 | if (!Array.isArray(paths)) {
|
17 | paths = [paths];
|
18 | }
|
19 |
|
20 | paths = paths.map(function (filePath) {
|
21 | return path.resolve(filePath);
|
22 | });
|
23 | paths = util.globify(paths);
|
24 | options = options || {};
|
25 |
|
26 | var globOptions = options.globOptions || {};
|
27 | var files = globby.sync(paths, globOptions);
|
28 | files.forEach(function (file) {
|
29 | deleteFile(file, this.store);
|
30 | }.bind(this));
|
31 |
|
32 | this.store.each(function (file) {
|
33 | if (multimatch([file.path], paths).length !== 0) {
|
34 | deleteFile(file.path, this.store);
|
35 | }
|
36 | }.bind(this));
|
37 | };
|