MCPcopy Index your code
hub / github.com/acode/cli / readFiles

Function readFiles

cli/commands/up.js:21–54  ·  view source on GitHub ↗
(base, properties, dir, data)

Source from the content-addressed store, hash-verified

19const RELEASE_ENV = 'release';
20
21function readFiles (base, properties, dir, data) {
22
23 dir = dir || '/';
24 data = data || [];
25 properties = properties || {};
26
27 let ignore = properties.ignore || [];
28
29 return fs.readdirSync(path.join(base, dir)).reduce((data, f) => {
30
31 let pathname = path.join(dir, f);
32 let fullpath = path.join(base, pathname);
33
34 for (let i = 0; i < ignore.length; i++) {
35 let filename = pathname.split(path.sep).join('/').slice(1);
36 let pattern = ignore[i];
37 if (minimatch(filename, pattern, {matchBase: true, dot: true})) {
38 return data;
39 }
40 }
41
42 if (fs.statSync(fullpath).isDirectory()) {
43 return readFiles(base, properties, pathname, data);
44 } else {
45 let filename = pathname[0] === path.sep ? pathname.substr(1) : pathname;
46 let buffer = fs.readFileSync(fullpath);
47 filename = filename.split(path.sep).join('/'); // Windows
48 data.push({filename: filename, buffer: buffer});
49 return data;
50 }
51
52 }, data);
53
54};
55
56class UpCommand extends Command {
57

Callers 1

runMethod · 0.70

Calls

no outgoing calls

Tested by

no test coverage detected