Skip to content

Commit 8f179c7

Browse files
committed
Adapt to using file pattern
1 parent 98e087b commit 8f179c7

File tree

3 files changed

+37
-18
lines changed

3 files changed

+37
-18
lines changed

lib/extra-files.js

+34-15
Original file line numberDiff line numberDiff line change
@@ -9,15 +9,41 @@ const OsHelpers = require('./os-helpers');
99

1010
/**
1111
* Collect the extra files requested by the rules.
12-
* @param {Options} options
13-
* @param {Path[]} requestedFiles
12+
* @param {{ files : { pattern: string, included: boolean }[], excludedFolders: string[] }[]} requests
1413
* @returns {Promise<ExtraFile[]>}
1514
*/
16-
async function collect(options, requestedFiles) {
15+
async function collect(requests) {
1716
const {globby} = await import('globby');
18-
const files = await globby(
19-
requestedFiles.map((file) => OsHelpers.makePathOsAgnostic(file)),
17+
const files = await Promise.all(
18+
requests.map((request) => getFiles(globby, request))
19+
)
20+
.then((files) => files.reduce((acc, items) => acc.concat(items), []))
21+
.then(unique);
22+
23+
return Promise.all(
24+
files.map(async (filePath) => {
25+
const content = await FS.readFile(filePath);
26+
return {
27+
path: filePath,
28+
content: content
29+
};
30+
})
31+
);
32+
}
33+
34+
/** .
35+
* @param {any} globby
36+
* @param {{ files : { pattern: string, included: boolean }[], excludedFolders: string[] }} request
37+
* @returns {Promise<ExtraFile[]>}
38+
*/
39+
function getFiles(globby, request) {
40+
return globby(
41+
request.files.map(
42+
(file) =>
43+
(file.included ? '' : '!') + OsHelpers.makePathOsAgnostic(file.pattern)
44+
),
2045
{
46+
ignore: request.excludedFolders,
2147
followSymbolicLinks: true,
2248
expandDirectories: false,
2349
caseSensitiveMatch: true,
@@ -26,17 +52,10 @@ async function collect(options, requestedFiles) {
2652
extglob: false
2753
}
2854
);
29-
console.log(files.sort())
55+
}
3056

31-
return Promise.all(
32-
files.sort().map(async (filePath) => {
33-
const content = await FS.readFile(filePath);
34-
return {
35-
path: filePath,
36-
content: content
37-
};
38-
})
39-
);
57+
function unique(array) {
58+
return [...new Set(array)];
4059
}
4160

4261
module.exports = {

lib/runner.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ async function initializeApp(options, elmModulePath, reviewElmJson, appHash) {
133133
let resolve = null;
134134
const requestedFilesP = new Promise((r) => {
135135
resolve = r;
136-
}).then((files) => ExtraFiles.collect(options, files));
136+
}).then(ExtraFiles.collect);
137137
AppState.subscribe(app.ports.requestReadingFiles, resolve);
138138

139139
ModuleCache.subscribe(options, app);

template/src/Elm/Review/Main.elm

+2-2
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ import Set exposing (Set)
2929
-- PORTS
3030

3131

32-
port requestReadingFiles : List String -> Cmd msg
32+
port requestReadingFiles : List { files : List { pattern : String, included : Bool }, excludedFolders : List String } -> Cmd msg
3333

3434

3535
port collectFile : (Decode.Value -> msg) -> Sub msg
@@ -302,7 +302,7 @@ I recommend you take a look at the following documents:
302302
[ cmd
303303

304304
-- TODO Don't trigger when the other cmd is `abort`
305-
, rules |> List.concatMap Rule.ruleRequestedFiles |> Set.fromList |> Set.toList |> requestReadingFiles
305+
, rules |> List.concatMap Rule.ruleRequestedFiles |> requestReadingFiles
306306
]
307307

308308
configurationErrors ->

0 commit comments

Comments
 (0)