Remove unnecessary resources, add bulma, and add AdvMakefile

This commit is contained in:
2021-03-29 15:02:41 -07:00
parent 69f2d46a8c
commit bb2c9351d6
6084 changed files with 674187 additions and 0 deletions

View File

@@ -0,0 +1,31 @@
/// <reference types="node" />
import { EventEmitter } from 'events';
import * as fsScandir from '@nodelib/fs.scandir';
import Settings from '../settings';
import { Entry, Errno } from '../types';
import Reader from './reader';
declare type EntryEventCallback = (entry: Entry) => void;
declare type ErrorEventCallback = (error: Errno) => void;
declare type EndEventCallback = () => void;
export default class AsyncReader extends Reader {
protected readonly _settings: Settings;
protected readonly _scandir: typeof fsScandir.scandir;
protected readonly _emitter: EventEmitter;
private readonly _queue;
private _isFatalError;
private _isDestroyed;
constructor(_root: string, _settings: Settings);
read(): EventEmitter;
get isDestroyed(): boolean;
destroy(): void;
onEntry(callback: EntryEventCallback): void;
onError(callback: ErrorEventCallback): void;
onEnd(callback: EndEventCallback): void;
private _pushToQueue;
private _worker;
private _handleError;
private _handleEntry;
private _emitEntry;
}
export {};
//# sourceMappingURL=async.d.ts.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"async.d.ts","sourceRoot":"","sources":["../../src/readers/async.ts"],"names":[],"mappings":";AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,QAAQ,CAAC;AAEtC,OAAO,KAAK,SAAS,MAAM,qBAAqB,CAAC;AAGjD,OAAO,QAAQ,MAAM,aAAa,CAAC;AACnC,OAAO,EAAE,KAAK,EAAE,KAAK,EAAa,MAAM,UAAU,CAAC;AAEnD,OAAO,MAAM,MAAM,UAAU,CAAC;AAE9B,aAAK,kBAAkB,GAAG,CAAC,KAAK,EAAE,KAAK,KAAK,IAAI,CAAC;AACjD,aAAK,kBAAkB,GAAG,CAAC,KAAK,EAAE,KAAK,KAAK,IAAI,CAAC;AACjD,aAAK,gBAAgB,GAAG,MAAM,IAAI,CAAC;AAEnC,MAAM,CAAC,OAAO,OAAO,WAAY,SAAQ,MAAM;IAQnB,SAAS,CAAC,QAAQ,CAAC,SAAS,EAAE,QAAQ;IAPjE,SAAS,CAAC,QAAQ,CAAC,QAAQ,EAAE,OAAO,SAAS,CAAC,OAAO,CAAqB;IAC1E,SAAS,CAAC,QAAQ,CAAC,QAAQ,EAAE,YAAY,CAAsB;IAE/D,OAAO,CAAC,QAAQ,CAAC,MAAM,CAA2E;IAClG,OAAO,CAAC,aAAa,CAAkB;IACvC,OAAO,CAAC,YAAY,CAAkB;gBAE1B,KAAK,EAAE,MAAM,EAAqB,SAAS,EAAE,QAAQ;IAU1D,IAAI,IAAI,YAAY;IAW3B,IAAW,WAAW,IAAI,OAAO,CAEhC;IAEM,OAAO,IAAI,IAAI;IASf,OAAO,CAAC,QAAQ,EAAE,kBAAkB,GAAG,IAAI;IAI3C,OAAO,CAAC,QAAQ,EAAE,kBAAkB,GAAG,IAAI;IAI3C,KAAK,CAAC,QAAQ,EAAE,gBAAgB,GAAG,IAAI;IAI9C,OAAO,CAAC,YAAY;IAUpB,OAAO,CAAC,OAAO;IAcf,OAAO,CAAC,YAAY;IAUpB,OAAO,CAAC,YAAY;IAoBpB,OAAO,CAAC,UAAU;CAGlB"}

View File

@@ -0,0 +1,96 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const events_1 = require("events");
const fsScandir = require("@nodelib/fs.scandir");
const fastq = require("fastq");
const common = require("./common");
const reader_1 = require("./reader");
class AsyncReader extends reader_1.default {
constructor(_root, _settings) {
super(_root, _settings);
this._settings = _settings;
this._scandir = fsScandir.scandir;
this._emitter = new events_1.EventEmitter();
this._queue = fastq(this._worker.bind(this), this._settings.concurrency);
this._isFatalError = false;
this._isDestroyed = false;
this._queue.drain = () => {
if (!this._isFatalError) {
this._emitter.emit('end');
}
};
}
read() {
this._isFatalError = false;
this._isDestroyed = false;
setImmediate(() => {
this._pushToQueue(this._root, this._settings.basePath);
});
return this._emitter;
}
get isDestroyed() {
return this._isDestroyed;
}
destroy() {
if (this._isDestroyed) {
throw new Error('The reader is already destroyed');
}
this._isDestroyed = true;
this._queue.killAndDrain();
}
onEntry(callback) {
this._emitter.on('entry', callback);
}
onError(callback) {
this._emitter.once('error', callback);
}
onEnd(callback) {
this._emitter.once('end', callback);
}
_pushToQueue(directory, base) {
const queueItem = { directory, base };
this._queue.push(queueItem, (error) => {
if (error !== null) {
this._handleError(error);
}
});
}
_worker(item, done) {
this._scandir(item.directory, this._settings.fsScandirSettings, (error, entries) => {
if (error !== null) {
return done(error, undefined);
}
for (const entry of entries) {
this._handleEntry(entry, item.base);
}
done(null, undefined);
});
}
_handleError(error) {
if (this._isDestroyed || !common.isFatalError(this._settings, error)) {
return;
}
this._isFatalError = true;
this._isDestroyed = true;
this._emitter.emit('error', error);
}
_handleEntry(entry, base) {
if (this._isDestroyed || this._isFatalError) {
return;
}
const fullpath = entry.path;
if (base !== undefined) {
entry.path = common.joinPathSegments(base, entry.name, this._settings.pathSegmentSeparator);
}
if (common.isAppliedFilter(this._settings.entryFilter, entry)) {
this._emitEntry(entry);
}
if (entry.dirent.isDirectory() && common.isAppliedFilter(this._settings.deepFilter, entry)) {
this._pushToQueue(fullpath, entry.path);
}
}
_emitEntry(entry) {
this._emitter.emit('entry', entry);
}
}
exports.default = AsyncReader;

View File

@@ -0,0 +1,2 @@
export {};
//# sourceMappingURL=async.spec.d.ts.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"async.spec.d.ts","sourceRoot":"","sources":["../../src/readers/async.spec.ts"],"names":[],"mappings":""}

View File

@@ -0,0 +1,165 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const assert = require("assert");
const path = require("path");
const sinon = require("sinon");
const settings_1 = require("../settings");
const tests = require("../tests");
const async_1 = require("./async");
class TestReader extends async_1.default {
constructor(_root, _settings = new settings_1.default()) {
super(_root, _settings);
this._scandir = sinon.stub();
}
get scandir() {
return this._scandir;
}
}
describe('Readers → Async', () => {
describe('.read', () => {
it('should emit "error" event when the first call of scandir is broken', (done) => {
const reader = new TestReader('non-exist-directory');
reader.scandir.yields(tests.EPERM_ERRNO);
reader.onError((error) => {
assert.ok(error);
done();
});
reader.read();
});
it('should emit "end" event when the first call of scandir is broken but this error can be suppressed', (done) => {
const settings = new settings_1.default({
errorFilter: (error) => error.code === 'EPERM'
});
const reader = new TestReader('non-exist-directory', settings);
reader.scandir.yields(tests.EPERM_ERRNO);
reader.onEnd(() => {
done();
});
reader.read();
});
it('should do not emit events after first broken scandir call', (done) => {
const reader = new TestReader('directory');
const firstFakeDirectoryEntry = tests.buildFakeDirectoryEntry({ name: 'a', path: 'directory/a' });
const secondFakeDirectoryEntry = tests.buildFakeDirectoryEntry({ name: 'b', path: 'directory/b' });
reader.scandir.onFirstCall().yields(null, [firstFakeDirectoryEntry, secondFakeDirectoryEntry]);
reader.scandir.onSecondCall().yieldsAsync(tests.EPERM_ERRNO);
reader.scandir.onThirdCall().yieldsAsync(tests.EPERM_ERRNO);
/**
* If the behavior is broken, then a third scandir call will trigger an unhandled error.
*/
reader.onError((error) => {
assert.ok(error);
done();
});
reader.read();
});
it('should return entries', (done) => {
const reader = new TestReader('directory');
const fakeDirectoryEntry = tests.buildFakeDirectoryEntry();
const fakeFileEntry = tests.buildFakeFileEntry();
reader.scandir.onFirstCall().yields(null, [fakeDirectoryEntry]);
reader.scandir.onSecondCall().yields(null, [fakeFileEntry]);
const entries = [];
reader.onEntry((entry) => entries.push(entry));
reader.onEnd(() => {
assert.deepStrictEqual(entries, [fakeDirectoryEntry, fakeFileEntry]);
done();
});
reader.read();
});
it('should push to results only directories', (done) => {
const settings = new settings_1.default({ entryFilter: (entry) => !entry.dirent.isFile() });
const reader = new TestReader('directory', settings);
const fakeDirectoryEntry = tests.buildFakeDirectoryEntry();
const fakeFileEntry = tests.buildFakeFileEntry();
reader.scandir.onFirstCall().yields(null, [fakeDirectoryEntry]);
reader.scandir.onSecondCall().yields(null, [fakeFileEntry]);
const entries = [];
reader.onEntry((entry) => entries.push(entry));
reader.onEnd(() => {
assert.deepStrictEqual(entries, [fakeDirectoryEntry]);
done();
});
reader.read();
});
it('should do not read root directory', (done) => {
const settings = new settings_1.default({ deepFilter: () => false });
const reader = new TestReader('directory', settings);
const fakeDirectoryEntry = tests.buildFakeDirectoryEntry();
const fakeFileEntry = tests.buildFakeFileEntry();
reader.scandir.onFirstCall().yields(null, [fakeDirectoryEntry]);
reader.scandir.onSecondCall().yields(null, [fakeFileEntry]);
const entries = [];
reader.onEntry((entry) => entries.push(entry));
reader.onEnd(() => {
assert.deepStrictEqual(entries, [fakeDirectoryEntry]);
done();
});
reader.read();
});
it('should set base path to entry when the `basePath` option is exist', (done) => {
const settings = new settings_1.default({ basePath: 'base' });
const reader = new TestReader('directory', settings);
const fakeDirectoryEntry = tests.buildFakeDirectoryEntry();
const fakeFileEntry = tests.buildFakeFileEntry();
reader.scandir.onFirstCall().yields(null, [fakeDirectoryEntry]);
reader.scandir.onSecondCall().yields(null, [fakeFileEntry]);
const entries = [];
reader.onEntry((entry) => entries.push(entry));
reader.onEnd(() => {
assert.strictEqual(entries[0].path, path.join('base', fakeDirectoryEntry.name));
assert.strictEqual(entries[1].path, path.join('base', 'fake', fakeFileEntry.name));
done();
});
reader.read();
});
it('should set base path to entry when the `basePath` option is exist and value is an empty string', (done) => {
const settings = new settings_1.default({ basePath: '' });
const reader = new TestReader('directory', settings);
const fakeDirectoryEntry = tests.buildFakeDirectoryEntry();
const fakeFileEntry = tests.buildFakeFileEntry();
reader.scandir.onFirstCall().yields(null, [fakeDirectoryEntry]);
reader.scandir.onSecondCall().yields(null, [fakeFileEntry]);
const entries = [];
reader.onEntry((entry) => entries.push(entry));
reader.onEnd(() => {
assert.strictEqual(entries[0].path, path.join(fakeDirectoryEntry.name));
assert.strictEqual(entries[1].path, path.join('fake', fakeFileEntry.name));
done();
});
reader.read();
});
});
describe('.destroy', () => {
it('should do not emit entries after destroy', (done) => {
const reader = new TestReader('directory');
const firstFakeDirectoryEntry = tests.buildFakeDirectoryEntry({ name: 'a', path: 'directory/a' });
const fakeFileEntry = tests.buildFakeFileEntry();
reader.scandir.onFirstCall().yields(null, [firstFakeDirectoryEntry]);
reader.scandir.onSecondCall().yields(null, [fakeFileEntry]);
reader.onEntry((entry) => {
if (entry.name === 'a') {
reader.destroy();
}
else {
assert.fail('should do not emit entries after destroy');
}
});
reader.onEnd(() => {
done();
});
reader.read();
});
it('should mark stream as "destroyed" after first destroy', () => {
const reader = new TestReader('directory');
reader.destroy();
assert.ok(reader.isDestroyed);
});
it('should throw an error when trying to destroy reader twice', () => {
const reader = new TestReader('directory');
const expectedErrorMessageRe = /The reader is already destroyed/;
reader.destroy();
assert.throws(() => reader.destroy(), expectedErrorMessageRe);
});
});
});

View File

@@ -0,0 +1,7 @@
import Settings, { FilterFunction } from '../settings';
import { Errno } from '../types';
export declare function isFatalError(settings: Settings, error: Errno): boolean;
export declare function isAppliedFilter<T>(filter: FilterFunction<T> | null, value: T): boolean;
export declare function replacePathSegmentSeparator(filepath: string, separator: string): string;
export declare function joinPathSegments(a: string, b: string, separator: string): string;
//# sourceMappingURL=common.d.ts.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"common.d.ts","sourceRoot":"","sources":["../../src/readers/common.ts"],"names":[],"mappings":"AAAA,OAAO,QAAQ,EAAE,EAAE,cAAc,EAAE,MAAM,aAAa,CAAC;AACvD,OAAO,EAAE,KAAK,EAAE,MAAM,UAAU,CAAC;AAEjC,wBAAgB,YAAY,CAAC,QAAQ,EAAE,QAAQ,EAAE,KAAK,EAAE,KAAK,GAAG,OAAO,CAMtE;AAED,wBAAgB,eAAe,CAAC,CAAC,EAAE,MAAM,EAAE,cAAc,CAAC,CAAC,CAAC,GAAG,IAAI,EAAE,KAAK,EAAE,CAAC,GAAG,OAAO,CAEtF;AAED,wBAAgB,2BAA2B,CAAC,QAAQ,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,GAAG,MAAM,CAEvF;AAED,wBAAgB,gBAAgB,CAAC,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,GAAG,MAAM,CAahF"}

View File

@@ -0,0 +1,31 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.joinPathSegments = exports.replacePathSegmentSeparator = exports.isAppliedFilter = exports.isFatalError = void 0;
function isFatalError(settings, error) {
if (settings.errorFilter === null) {
return true;
}
return !settings.errorFilter(error);
}
exports.isFatalError = isFatalError;
function isAppliedFilter(filter, value) {
return filter === null || filter(value);
}
exports.isAppliedFilter = isAppliedFilter;
function replacePathSegmentSeparator(filepath, separator) {
return filepath.split(/[/\\]/).join(separator);
}
exports.replacePathSegmentSeparator = replacePathSegmentSeparator;
function joinPathSegments(a, b, separator) {
if (a === '') {
return b;
}
/**
* The correct handling of cases when the first segment is a root (`/`, `C:/`) or UNC path (`//?/C:/`).
*/
if (a.endsWith(separator)) {
return a + b;
}
return a + separator + b;
}
exports.joinPathSegments = joinPathSegments;

View File

@@ -0,0 +1,2 @@
export {};
//# sourceMappingURL=common.spec.d.ts.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"common.spec.d.ts","sourceRoot":"","sources":["../../src/readers/common.spec.ts"],"names":[],"mappings":""}

View File

@@ -0,0 +1,85 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const assert = require("assert");
const path = require("path");
const settings_1 = require("../settings");
const tests = require("../tests");
const common = require("./common");
describe('Readers → Common', () => {
describe('.isFatalError', () => {
it('should return true when filter is not defined', () => {
const settings = new settings_1.default();
const actual = common.isFatalError(settings, tests.EPERM_ERRNO);
assert.ok(actual);
});
it('should return true when the error cannot be suppressed', () => {
const settings = new settings_1.default({
errorFilter: (error) => error.code === 'ENOENT'
});
const actual = common.isFatalError(settings, tests.EPERM_ERRNO);
assert.ok(actual);
});
it('should return false when the error can be suppressed', () => {
const settings = new settings_1.default({
errorFilter: (error) => error.code === 'EPERM'
});
const actual = common.isFatalError(settings, tests.EPERM_ERRNO);
assert.ok(!actual);
});
});
describe('.isAppliedFilter', () => {
it('should return true when the filter is not defined', () => {
const settings = new settings_1.default();
const entry = tests.buildFakeFileEntry();
const actual = common.isAppliedFilter(settings.entryFilter, entry);
assert.ok(actual);
});
it('should return true when the entry will be applied', () => {
const settings = new settings_1.default({
entryFilter: (entry) => entry.name === 'fake.txt'
});
const fakeEntry = tests.buildFakeFileEntry();
const actual = common.isAppliedFilter(settings.entryFilter, fakeEntry);
assert.ok(actual);
});
it('should return false when the entry will be skipped', () => {
const settings = new settings_1.default({
entryFilter: (entry) => entry.name !== 'fake.txt'
});
const fakeEntry = tests.buildFakeFileEntry();
const actual = common.isAppliedFilter(settings.entryFilter, fakeEntry);
assert.ok(!actual);
});
});
describe('.replacePathSegmentSeparator', () => {
it('should replace path segment separator', () => {
const filepath = path.join('directory', 'file.txt');
const expected = 'directory_file.txt';
const actual = common.replacePathSegmentSeparator(filepath, '_');
assert.strictEqual(actual, expected);
});
});
describe('.joinPathSegments', () => {
it('should return concatenated string', () => {
const expected = 'a&b';
const actual = common.joinPathSegments('a', 'b', '&');
assert.strictEqual(actual, expected);
});
it('should return second part of path when the first path is an empty string', () => {
const expected = 'b';
const actual = common.joinPathSegments('', 'b', '&');
assert.strictEqual(actual, expected);
});
it('should return correct string when the first segment ens with the separator symbol', () => {
// Unix
assert.strictEqual(common.joinPathSegments('/', 'a', '/'), '/a');
assert.strictEqual(common.joinPathSegments('//', 'a', '/'), '//a');
assert.strictEqual(common.joinPathSegments('/a/', 'b', '/'), '/a/b');
// Windows
assert.strictEqual(common.joinPathSegments('C:/', 'Users', '/'), 'C:/Users');
assert.strictEqual(common.joinPathSegments('C:\\', 'Users', '\\'), 'C:\\Users');
assert.strictEqual(common.joinPathSegments('//?/C:/', 'Users', '/'), '//?/C:/Users');
assert.strictEqual(common.joinPathSegments('\\\\?\\C:\\', 'Users', '\\'), '\\\\?\\C:\\Users');
});
});
});

View File

@@ -0,0 +1,7 @@
import Settings from '../settings';
export default class Reader {
protected readonly _root: string;
protected readonly _settings: Settings;
constructor(_root: string, _settings: Settings);
}
//# sourceMappingURL=reader.d.ts.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"reader.d.ts","sourceRoot":"","sources":["../../src/readers/reader.ts"],"names":[],"mappings":"AAAA,OAAO,QAAQ,MAAM,aAAa,CAAC;AAGnC,MAAM,CAAC,OAAO,OAAO,MAAM;IACd,SAAS,CAAC,QAAQ,CAAC,KAAK,EAAE,MAAM;IAAE,SAAS,CAAC,QAAQ,CAAC,SAAS,EAAE,QAAQ;gBAArD,KAAK,EAAE,MAAM,EAAqB,SAAS,EAAE,QAAQ;CAGpF"}

View File

@@ -0,0 +1,11 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const common = require("./common");
class Reader {
constructor(_root, _settings) {
this._root = _root;
this._settings = _settings;
this._root = common.replacePathSegmentSeparator(_root, _settings.pathSegmentSeparator);
}
}
exports.default = Reader;

View File

@@ -0,0 +1,2 @@
export {};
//# sourceMappingURL=reader.spec.d.ts.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"reader.spec.d.ts","sourceRoot":"","sources":["../../src/readers/reader.spec.ts"],"names":[],"mappings":""}

View File

@@ -0,0 +1,25 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const assert = require("assert");
const path = require("path");
const settings_1 = require("../settings");
const reader_1 = require("./reader");
class TestReader extends reader_1.default {
get root() {
return this._root;
}
}
function getReader(root, options = {}) {
return new TestReader(root, new settings_1.default(options));
}
describe('Readers → Reader', () => {
describe('Constructor', () => {
it('should return root path with replaced path segment separators', () => {
const root = path.join('directory', 'file.txt');
const reader = getReader(root, { pathSegmentSeparator: '_' });
const expected = 'directory_file.txt';
const actual = reader.root;
assert.strictEqual(actual, expected);
});
});
});

View File

@@ -0,0 +1,16 @@
import * as fsScandir from '@nodelib/fs.scandir';
import { Entry } from '../types';
import Reader from './reader';
export default class SyncReader extends Reader {
protected readonly _scandir: typeof fsScandir.scandirSync;
private readonly _storage;
private readonly _queue;
read(): Entry[];
private _pushToQueue;
private _handleQueue;
private _handleDirectory;
private _handleError;
private _handleEntry;
private _pushToStorage;
}
//# sourceMappingURL=sync.d.ts.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"sync.d.ts","sourceRoot":"","sources":["../../src/readers/sync.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,SAAS,MAAM,qBAAqB,CAAC;AAEjD,OAAO,EAAE,KAAK,EAAoB,MAAM,UAAU,CAAC;AAEnD,OAAO,MAAM,MAAM,UAAU,CAAC;AAE9B,MAAM,CAAC,OAAO,OAAO,UAAW,SAAQ,MAAM;IAC7C,SAAS,CAAC,QAAQ,CAAC,QAAQ,EAAE,OAAO,SAAS,CAAC,WAAW,CAAyB;IAElF,OAAO,CAAC,QAAQ,CAAC,QAAQ,CAAyB;IAClD,OAAO,CAAC,QAAQ,CAAC,MAAM,CAA6B;IAE7C,IAAI,IAAI,KAAK,EAAE;IAOtB,OAAO,CAAC,YAAY;IAIpB,OAAO,CAAC,YAAY;IAMpB,OAAO,CAAC,gBAAgB;IAYxB,OAAO,CAAC,YAAY;IAQpB,OAAO,CAAC,YAAY;IAgBpB,OAAO,CAAC,cAAc;CAGtB"}

View File

@@ -0,0 +1,59 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const fsScandir = require("@nodelib/fs.scandir");
const common = require("./common");
const reader_1 = require("./reader");
class SyncReader extends reader_1.default {
constructor() {
super(...arguments);
this._scandir = fsScandir.scandirSync;
this._storage = new Set();
this._queue = new Set();
}
read() {
this._pushToQueue(this._root, this._settings.basePath);
this._handleQueue();
return [...this._storage];
}
_pushToQueue(directory, base) {
this._queue.add({ directory, base });
}
_handleQueue() {
for (const item of this._queue.values()) {
this._handleDirectory(item.directory, item.base);
}
}
_handleDirectory(directory, base) {
try {
const entries = this._scandir(directory, this._settings.fsScandirSettings);
for (const entry of entries) {
this._handleEntry(entry, base);
}
}
catch (error) {
this._handleError(error);
}
}
_handleError(error) {
if (!common.isFatalError(this._settings, error)) {
return;
}
throw error;
}
_handleEntry(entry, base) {
const fullpath = entry.path;
if (base !== undefined) {
entry.path = common.joinPathSegments(base, entry.name, this._settings.pathSegmentSeparator);
}
if (common.isAppliedFilter(this._settings.entryFilter, entry)) {
this._pushToStorage(entry);
}
if (entry.dirent.isDirectory() && common.isAppliedFilter(this._settings.deepFilter, entry)) {
this._pushToQueue(fullpath, entry.path);
}
}
_pushToStorage(entry) {
this._storage.add(entry);
}
}
exports.default = SyncReader;

View File

@@ -0,0 +1,2 @@
export {};
//# sourceMappingURL=sync.spec.d.ts.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"sync.spec.d.ts","sourceRoot":"","sources":["../../src/readers/sync.spec.ts"],"names":[],"mappings":""}

View File

@@ -0,0 +1,89 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const assert = require("assert");
const path = require("path");
const sinon = require("sinon");
const settings_1 = require("../settings");
const tests = require("../tests");
const sync_1 = require("./sync");
class TestReader extends sync_1.default {
constructor(_root, _settings = new settings_1.default()) {
super(_root, _settings);
this._scandir = sinon.stub();
}
get scandir() {
return this._scandir;
}
}
describe('Readers → Sync', () => {
describe('.read', () => {
it('should throw an error when the first call of scandir is broken', () => {
const reader = new TestReader('non-exist-directory');
reader.scandir.throws(tests.EPERM_ERRNO);
assert.throws(() => reader.read(), { code: 'EPERM' });
});
it('should return empty array when the first call of scandir is broken but this error can be suppressed', () => {
const settings = new settings_1.default({
errorFilter: (error) => error.code === 'EPERM'
});
const reader = new TestReader('non-exist-directory', settings);
reader.scandir.throws(tests.EPERM_ERRNO);
const actual = reader.read();
assert.deepStrictEqual(actual, []);
});
it('should return entries', () => {
const reader = new TestReader('directory');
const fakeDirectoryEntry = tests.buildFakeDirectoryEntry();
const fakeFileEntry = tests.buildFakeFileEntry();
reader.scandir.onFirstCall().returns([fakeDirectoryEntry]);
reader.scandir.onSecondCall().returns([fakeFileEntry]);
const expected = [fakeDirectoryEntry, fakeFileEntry];
const actual = reader.read();
assert.deepStrictEqual(actual, expected);
});
it('should push to results only directories', () => {
const settings = new settings_1.default({ entryFilter: (entry) => !entry.dirent.isFile() });
const reader = new TestReader('directory', settings);
const fakeDirectoryEntry = tests.buildFakeDirectoryEntry();
const fakeFileEntry = tests.buildFakeFileEntry();
reader.scandir.onFirstCall().returns([fakeDirectoryEntry]);
reader.scandir.onSecondCall().returns([fakeFileEntry]);
const expected = [fakeDirectoryEntry];
const actual = reader.read();
assert.deepStrictEqual(actual, expected);
});
it('should do not read root directory', () => {
const settings = new settings_1.default({ deepFilter: () => false });
const reader = new TestReader('directory', settings);
const fakeDirectoryEntry = tests.buildFakeDirectoryEntry();
const fakeFileEntry = tests.buildFakeFileEntry();
reader.scandir.onFirstCall().returns([fakeDirectoryEntry]);
reader.scandir.onSecondCall().returns([fakeFileEntry]);
const expected = [fakeDirectoryEntry];
const actual = reader.read();
assert.deepStrictEqual(actual, expected);
});
it('should set base path to entry when the `basePath` option is exist', () => {
const settings = new settings_1.default({ basePath: 'base' });
const reader = new TestReader('directory', settings);
const fakeDirectoryEntry = tests.buildFakeDirectoryEntry();
const fakeFileEntry = tests.buildFakeFileEntry();
reader.scandir.onFirstCall().returns([fakeDirectoryEntry]);
reader.scandir.onSecondCall().returns([fakeFileEntry]);
const actual = reader.read();
assert.strictEqual(actual[0].path, path.join('base', fakeDirectoryEntry.name));
assert.strictEqual(actual[1].path, path.join('base', 'fake', fakeFileEntry.name));
});
it('should set base path to entry when the `basePath` option is exist and value is an empty string', () => {
const settings = new settings_1.default({ basePath: '' });
const reader = new TestReader('directory', settings);
const fakeDirectoryEntry = tests.buildFakeDirectoryEntry();
const fakeFileEntry = tests.buildFakeFileEntry();
reader.scandir.onFirstCall().returns([fakeDirectoryEntry]);
reader.scandir.onSecondCall().returns([fakeFileEntry]);
const actual = reader.read();
assert.strictEqual(actual[0].path, fakeDirectoryEntry.name);
assert.strictEqual(actual[1].path, path.join('fake', fakeFileEntry.name));
});
});
});