emitty
Advanced tools
Comparing version 1.4.0 to 1.4.1
@@ -6,3 +6,3 @@ /// <reference types="node" /> | ||
import { ILanguage } from './services/config'; | ||
import { Resolver } from './providers/resolver'; | ||
import { ResolverProvider } from './providers/resolver'; | ||
export interface IScannerOptions { | ||
@@ -64,3 +64,3 @@ /** | ||
*/ | ||
resolver: Resolver; | ||
resolver: ResolverProvider; | ||
/** | ||
@@ -67,0 +67,0 @@ * Scans directory or file and updates the Storage. |
@@ -8,4 +8,4 @@ 'use strict'; | ||
const stream_1 = require("./providers/stream"); | ||
const paths_1 = require("./utils/paths"); | ||
const fs_1 = require("./utils/fs"); | ||
const pathUtils = require("./utils/paths"); | ||
const fsUtils = require("./utils/fs"); | ||
function assertInput(directory, language) { | ||
@@ -19,3 +19,3 @@ if (!directory) { | ||
} | ||
if (!fs_1.pathExistsSync(directory)) { | ||
if (!fsUtils.pathExistsSync(directory)) { | ||
throw new Error('directory must exist'); | ||
@@ -26,3 +26,3 @@ } | ||
assertInput(root, language); | ||
const storage = new storage_1.Storage(); | ||
const storage = new storage_1.StorageService(); | ||
options = Object.assign({ | ||
@@ -49,9 +49,9 @@ snapshot: {}, | ||
if (options.scanner.exclude) { | ||
options.scanner.exclude = paths_1.expandGlobPatterns(options.scanner.exclude); | ||
options.scanner.exclude = pathUtils.expandGlobPatterns(options.scanner.exclude); | ||
} | ||
root = paths_1.normalize(root); | ||
const config = new config_1.Config(language); | ||
const scanner = new scanner_1.Scanner(root, storage, config.getConfig(), options); | ||
const resolver = new resolver_1.Resolver(storage); | ||
const stream = new stream_1.Stream(root, storage, config.getConfig(), options); | ||
root = pathUtils.normalize(root); | ||
const configService = new config_1.ConfigService(language); | ||
const scannerService = new scanner_1.ScannerService(root, storage, configService.getConfig(), options); | ||
const resolverProvider = new resolver_1.ResolverProvider(storage); | ||
const streamProvider = new stream_1.StreamProvider(root, storage, configService.getConfig(), options); | ||
return { | ||
@@ -61,8 +61,8 @@ storage: () => storage.snapshot(), | ||
load: (snapshot) => storage.load(snapshot), | ||
scan: (filepath, stats) => scanner.scan(filepath, stats), | ||
resolver, | ||
stream: (filepath, stats) => stream.run(filepath, stats), | ||
filter: (filepath) => stream.filter(filepath) | ||
scan: (filepath, stats) => scannerService.scan(filepath, stats), | ||
resolver: resolverProvider, | ||
stream: (filepath, stats) => streamProvider.run(filepath, stats), | ||
filter: (filepath) => streamProvider.filter(filepath) | ||
}; | ||
} | ||
exports.setup = setup; |
@@ -43,3 +43,4 @@ 'use strict'; | ||
if (indent === -1) { | ||
keyword = language.matcher.exec(line); | ||
// Trim trailing whitespaces | ||
keyword = language.matcher.exec(line.trim()); | ||
} | ||
@@ -46,0 +47,0 @@ } |
@@ -1,5 +0,5 @@ | ||
import { Storage } from '../services/storage'; | ||
export declare class Resolver { | ||
import { StorageService } from '../services/storage'; | ||
export declare class ResolverProvider { | ||
private storage; | ||
constructor(storage: Storage); | ||
constructor(storage: StorageService); | ||
/** | ||
@@ -6,0 +6,0 @@ * Returns all files that depends on the specified file. |
'use strict'; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
const micromatch = require("micromatch"); | ||
const paths_1 = require("../utils/paths"); | ||
class Resolver { | ||
const pathUtils = require("../utils/paths"); | ||
class ResolverProvider { | ||
constructor(storage) { | ||
@@ -14,3 +14,3 @@ this.storage = storage; | ||
getDependencies(filepath) { | ||
filepath = paths_1.normalize(filepath); | ||
filepath = pathUtils.normalize(filepath); | ||
if (!this.storage.has(filepath)) { | ||
@@ -27,3 +27,3 @@ return [filepath]; | ||
checkDependency(filepath, filepathToCheck) { | ||
filepathToCheck = paths_1.normalize(filepathToCheck); | ||
filepathToCheck = pathUtils.normalize(filepathToCheck); | ||
return this.getDependencies(filepath).indexOf(filepathToCheck) !== -1; | ||
@@ -57,2 +57,2 @@ } | ||
} | ||
exports.Resolver = Resolver; | ||
exports.ResolverProvider = ResolverProvider; |
/// <reference types="node" /> | ||
import * as fs from 'fs'; | ||
import * as stream from 'stream'; | ||
import { StorageService } from '../services/storage'; | ||
import { IOptions } from '../emitty'; | ||
import { Storage } from '../services/storage'; | ||
import { ILanguage } from '../services/config'; | ||
export declare class Stream { | ||
export declare class StreamProvider { | ||
private root; | ||
@@ -12,5 +12,5 @@ private storage; | ||
private options; | ||
private scanner; | ||
private resolver; | ||
constructor(root: string, storage: Storage, language: ILanguage, options: IOptions); | ||
private readonly scanner; | ||
private readonly resolver; | ||
constructor(root: string, storage: StorageService, language: ILanguage, options: IOptions); | ||
/** | ||
@@ -17,0 +17,0 @@ * Starts scanning the directory and push Vinyl file to a Stream if it is required. |
'use strict'; | ||
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { | ||
return new (P || (P = Promise))(function (resolve, reject) { | ||
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } | ||
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } | ||
function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); } | ||
step((generator = generator.apply(thisArg, _arguments || [])).next()); | ||
}); | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
const tslib_1 = require("tslib"); | ||
const path = require("path"); | ||
@@ -16,5 +9,5 @@ const through2 = require("through2"); | ||
const resolver_1 = require("../providers/resolver"); | ||
const paths_1 = require("../utils/paths"); | ||
const fs_1 = require("../utils/fs"); | ||
class Stream { | ||
const pathUtils = require("../utils/paths"); | ||
const fsUtils = require("../utils/fs"); | ||
class StreamProvider { | ||
constructor(root, storage, language, options) { | ||
@@ -25,4 +18,4 @@ this.root = root; | ||
this.options = options; | ||
this.scanner = new scanner_1.Scanner(this.root, this.storage, this.language, this.options); | ||
this.resolver = new resolver_1.Resolver(this.storage); | ||
this.scanner = new scanner_1.ScannerService(this.root, this.storage, this.language, this.options); | ||
this.resolver = new resolver_1.ResolverProvider(this.storage); | ||
} | ||
@@ -39,2 +32,4 @@ /** | ||
} | ||
// Protection against WIN32 paths | ||
filepath = pathUtils.normalize(filepath); | ||
return through2.obj(function (file, _enc, cb) { | ||
@@ -73,3 +68,3 @@ const mainFile = self.makeMainFilePath(self.root, file); | ||
filterFileByDependencies(filepath, mainFile, streamCtx, file, cb) { | ||
const changedFile = paths_1.normalize(filepath); | ||
const changedFile = pathUtils.normalize(filepath); | ||
if (this.resolver.checkDependency(mainFile, changedFile)) { | ||
@@ -100,8 +95,8 @@ if (this.options.makeVinylFile) { | ||
if (file.path) { | ||
filepath = path.relative(file.cwd, file.path); | ||
filepath = pathUtils.relative(file.cwd, file.path); | ||
} | ||
if (!filepath.startsWith(root)) { | ||
filepath = path.join(root, filepath); | ||
filepath = pathUtils.join(root, filepath); | ||
} | ||
return paths_1.normalize(filepath); | ||
return pathUtils.normalize(filepath); | ||
} | ||
@@ -112,10 +107,10 @@ /** | ||
makeVinylFile(filepath) { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
const exists = yield fs_1.pathExists(filepath); | ||
return tslib_1.__awaiter(this, void 0, void 0, function* () { | ||
const exists = yield fsUtils.pathExists(filepath); | ||
if (!exists) { | ||
return null; | ||
} | ||
const stat = yield fs_1.statFile(filepath); | ||
const content = yield fs_1.readFile(filepath); | ||
const fullpath = path.join(process.cwd(), filepath); | ||
const stat = yield fsUtils.statFile(filepath); | ||
const content = yield fsUtils.readFile(filepath); | ||
const fullpath = pathUtils.join(process.cwd(), filepath); | ||
return new Vinyl({ | ||
@@ -130,2 +125,2 @@ base: path.dirname(fullpath), | ||
} | ||
exports.Stream = Stream; | ||
exports.StreamProvider = StreamProvider; |
@@ -13,14 +13,5 @@ export interface ILanguageComment { | ||
} | ||
export declare const builtInConfigs: { | ||
jade: ILanguage; | ||
pug: ILanguage; | ||
nunjucks: ILanguage; | ||
sugarml: ILanguage; | ||
posthtml: ILanguage; | ||
less: ILanguage; | ||
stylus: ILanguage; | ||
sass: ILanguage; | ||
scss: ILanguage; | ||
}; | ||
export declare class Config { | ||
export declare type TBuiltInConfig = Record<string, ILanguage>; | ||
export declare const builtInConfigs: TBuiltInConfig; | ||
export declare class ConfigService { | ||
private matcher; | ||
@@ -27,0 +18,0 @@ private extensions; |
@@ -67,3 +67,3 @@ 'use strict'; | ||
}; | ||
class Config { | ||
class ConfigService { | ||
constructor(language) { | ||
@@ -134,2 +134,2 @@ if (typeof language === 'object') { | ||
} | ||
exports.Config = Config; | ||
exports.ConfigService = ConfigService; |
/// <reference types="node" /> | ||
import * as fs from 'fs'; | ||
import { StorageService } from './storage'; | ||
import { IOptions } from '../emitty'; | ||
import { ILanguage } from './config'; | ||
import { Storage } from './storage'; | ||
import { IOptions } from '../emitty'; | ||
export interface IFile { | ||
@@ -10,3 +10,3 @@ filepath: string; | ||
} | ||
export declare class Scanner { | ||
export declare class ScannerService { | ||
private root; | ||
@@ -18,3 +18,3 @@ private storage; | ||
private excludePatterns; | ||
constructor(root: string, storage: Storage, language: ILanguage, options: IOptions); | ||
constructor(root: string, storage: StorageService, language: ILanguage, options: IOptions); | ||
scan(filepath?: string, stats?: fs.Stats): Promise<any>; | ||
@@ -21,0 +21,0 @@ private scanFile(filepath, stats); |
@@ -7,5 +7,5 @@ 'use strict'; | ||
const dependencies_1 = require("../parser/dependencies"); | ||
const paths_1 = require("../utils/paths"); | ||
const fs_1 = require("../utils/fs"); | ||
class Scanner { | ||
const pathUtils = require("../utils/paths"); | ||
const fsUtils = require("../utils/fs"); | ||
class ScannerService { | ||
constructor(root, storage, language, options) { | ||
@@ -28,10 +28,6 @@ this.root = root; | ||
if (stats) { | ||
statPromise = fs_1.pathExists(filepath).then((exists) => { | ||
if (exists) { | ||
return Promise.resolve(stats); | ||
} | ||
}); | ||
statPromise = fsUtils.pathExists(filepath).then((exists) => exists ? Promise.resolve(stats) : null); | ||
} | ||
else { | ||
statPromise = fs_1.statFile(filepath); | ||
statPromise = fsUtils.statFile(filepath); | ||
} | ||
@@ -52,3 +48,3 @@ return statPromise.then((stat) => { | ||
const stream = readdir.readdirStreamStat(this.root, { | ||
basePath: path.resolve(this.root), | ||
basePath: pathUtils.relative(process.cwd(), this.root), | ||
filter: (stat) => this.scannerFilter(stat), | ||
@@ -63,6 +59,6 @@ deep: this.options.scanner.depth | ||
// Return Cache if it exists and not outdated | ||
const entryFilePath = paths_1.relative(process.cwd(), entry.filepath); | ||
const entryFilePath = pathUtils.relative(process.cwd(), entry.filepath); | ||
const cached = this.storage.get(entryFilePath); | ||
if (cached && cached.ctime >= entry.ctime) { | ||
listOfPromises.push(cached); | ||
listOfPromises.push(Promise.resolve(cached)); | ||
return; | ||
@@ -82,5 +78,5 @@ } | ||
// Remove base path | ||
const entryFilePath = paths_1.relative(process.cwd(), entry.filepath); | ||
const entryFilePath = pathUtils.relative(process.cwd(), entry.filepath); | ||
const entryDir = path.dirname(entryFilePath); | ||
return fs_1.readFile(entry.filepath).then((data) => { | ||
return fsUtils.readFile(entry.filepath).then((data) => { | ||
const item = { | ||
@@ -115,5 +111,5 @@ dependencies: dependencies_1.parseDependencies(data, this.language), | ||
if (filepath.startsWith('/') && this.options.basedir) { | ||
return paths_1.join(this.options.basedir, filepath); | ||
return pathUtils.join(this.options.basedir, filepath); | ||
} | ||
return paths_1.join(entryDir, filepath); | ||
return pathUtils.join(entryDir, filepath); | ||
} | ||
@@ -136,2 +132,2 @@ makeEntryFile(filepath, ctime) { | ||
} | ||
exports.Scanner = Scanner; | ||
exports.ScannerService = ScannerService; |
@@ -8,3 +8,3 @@ export interface IStorageItem { | ||
} | ||
export declare class Storage { | ||
export declare class StorageService { | ||
private store; | ||
@@ -11,0 +11,0 @@ private interval; |
'use strict'; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
class Storage { | ||
class StorageService { | ||
constructor() { | ||
@@ -46,2 +46,2 @@ this.store = {}; | ||
} | ||
exports.Storage = Storage; | ||
exports.StorageService = StorageService; |
{ | ||
"name": "emitty", | ||
"version": "1.4.0", | ||
"version": "1.4.1", | ||
"description": "Determine the inheritance of template and style files", | ||
@@ -33,18 +33,19 @@ "license": "MIT", | ||
"@types/micromatch": "^2.3.29", | ||
"@types/mocha": "^2.2.41", | ||
"@types/node": "^8.0.1", | ||
"@types/mocha": "^2.2.43", | ||
"@types/node": "^8.0.32", | ||
"@types/through2": "^2.0.33", | ||
"@types/vinyl": "^2.0.0", | ||
"mocha": "^3.4.2", | ||
"rimraf": "^2.6.1", | ||
"tslint": "^5.4.3", | ||
"@types/vinyl": "^2.0.1", | ||
"mocha": "^3.5.3", | ||
"rimraf": "^2.6.2", | ||
"tslint": "^5.7.0", | ||
"tslint-config-xo": "^1.3.0", | ||
"typescript": "^2.3.4", | ||
"vinyl": "^2.0.2" | ||
"typescript": "^2.5.3", | ||
"vinyl": "^2.1.0" | ||
}, | ||
"dependencies": { | ||
"micromatch": "^3.0.3", | ||
"micromatch": "^3.1.0", | ||
"readdir-enhanced": "^1.5.2", | ||
"through2": "^2.0.3", | ||
"vinyl": "^2.0.2" | ||
"tslib": "^1.7.1", | ||
"vinyl": "^2.1.0" | ||
}, | ||
@@ -51,0 +52,0 @@ "scripts": { |
44091
5
23
960
+ Addedtslib@^1.7.1
+ Addedtslib@1.14.1(transitive)
Updatedmicromatch@^3.1.0
Updatedvinyl@^2.1.0