Skip to content

Commit

Permalink
some tech refresh
Browse files Browse the repository at this point in the history
  • Loading branch information
iccicci committed Jun 9, 2020
1 parent e822526 commit 6da86e2
Show file tree
Hide file tree
Showing 8 changed files with 139 additions and 66 deletions.
15 changes: 0 additions & 15 deletions .prettierrc

This file was deleted.

2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
The MIT License (MIT)

Copyright (c) 2015-2017 Daniele Ricci
Copyright (c) 2015-2020 Daniele Ricci

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
5 changes: 4 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,12 @@
[![Build Status][travis-badge]][travis-url]
[![Code Climate][code-badge]][code-url]
[![Test Coverage][cover-badge]][code-url]
[![Donate][donate-badge]][donate-url]

[![NPM version][npm-badge]][npm-url]
[![NPM downloads][npm-downloads-badge]][npm-url]
[![Stars][stars-badge]][github-url]
[![Types][types-badge]][npm-url]
[![Donate][donate-badge]][donate-url]

[![Dependencies][dep-badge]][dep-url]
[![Dev Dependencies][dev-dep-badge]][dev-dep-url]
Expand All @@ -23,9 +24,11 @@
[dev-dep-url]: https://david-dm.org/iccicci/rotating-file-stream?type=dev
[donate-badge]: https://badgen.net/badge/donate/bitcoin?icon=bitcoin
[donate-url]: https://blockchain.info/address/12p1p5q7sK75tPyuesZmssiMYr4TKzpSCN
[github-url]: https://github.com/iccicci/rotating-file-stream
[npm-downloads-badge]: https://badgen.net/npm/dm/rotating-file-stream?icon=npm
[npm-badge]: https://badgen.net/npm/v/rotating-file-stream?color=green&icon=npm
[npm-url]: https://www.npmjs.com/package/rotating-file-stream
[stars-badge]: https://badgen.net/github/stars/iccicci/rotating-file-stream?icon=github
[travis-badge]: https://badgen.net/travis/iccicci/rotating-file-stream?icon=travis
[travis-url]: https://travis-ci.org/iccicci/rotating-file-stream?branch=master
[types-badge]: https://badgen.net/npm/types/rotating-file-stream?color=green&icon=typescript
Expand Down
109 changes: 109 additions & 0 deletions index.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
/// <reference types="node" />
import { Writable } from "stream";
export declare type Compressor = (source: string, dest: string) => string;
export declare type Generator = (time: number | Date, index?: number) => string;
export interface Options {
compress?: boolean | string | Compressor;
encoding?: BufferEncoding;
history?: string;
immutable?: boolean;
initialRotation?: boolean;
interval?: string;
intervalBoundary?: boolean;
maxFiles?: number;
maxSize?: string;
mode?: number;
path?: string;
rotate?: number;
size?: string;
teeToStdout?: boolean;
}
interface Opts {
compress?: string | Compressor;
encoding?: BufferEncoding;
history?: string;
immutable?: boolean;
initialRotation?: boolean;
interval?: {
num: number;
unit: string;
};
intervalBoundary?: boolean;
maxFiles?: number;
maxSize?: number;
mode?: number;
path?: string;
rotate?: number;
size?: number;
teeToStdout?: boolean;
}
declare type Callback = (error?: Error) => void;
interface Chunk {
chunk: Buffer;
encoding: BufferEncoding;
next: Chunk;
}
export declare class RotatingFileStream extends Writable {
private createGzip;
private destroyer;
private error;
private exec;
private filename;
private finished;
private fsClose;
private fsCreateReadStream;
private fsCreateWriteStream;
private fsMkdir;
private fsOpen;
private fsReadFile;
private fsRename;
private fsStat;
private fsUnlink;
private fsWrite;
private fsWriteFile;
private generator;
private last;
private maxTimeout;
private next;
private opened;
private options;
private prev;
private rotatedName;
private rotation;
private size;
private stream;
private timer;
constructor(generator: Generator, options: Opts);
_destroy(error: Error, callback: Callback): void;
_final(callback: Callback): void;
_write(chunk: Buffer, encoding: BufferEncoding, callback: Callback): void;
_writev(chunks: Chunk[], callback: Callback): void;
private rewrite;
private init;
private makePath;
private reopen;
private reclose;
private now;
private rotate;
private findName;
private move;
private touch;
private classical;
private clear;
private intervalBoundsBig;
private intervalBounds;
private interval;
private compress;
private external;
private gzip;
private rotated;
private history;
private historyGather;
private historyRemove;
private historyCheckFiles;
private historyCheckSize;
private historyWrite;
private immutate;
}
export declare function createStream(filename: string | Generator, options?: Options): RotatingFileStream;
export {};
20 changes: 18 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,7 @@
"coverage": "tsc && TZ=\"Europe/Rome\" nyc -r lcov -r text -r text-summary -r html mocha -r ts-node/register test/*ts",
"eslint": "eslint index.ts utils.ts test/*ts",
"ignore": "node -r ts-node/register utils.ts ignore",
"prepare": "npm run ignore && tsc && npm run readme",
"readme": "node -r ts-node/register utils.ts readme",
"prepare": "npm run ignore && tsc",
"test": "npm run clean && mocha -r ts-node/register test/*ts"
},
"bugs": "https://github.com/iccicci/rotating-file-stream/issues",
Expand Down Expand Up @@ -48,5 +47,22 @@
"nyc": "15.0.1",
"ts-node": "8.10.1",
"typescript": "3.9.2"
},
"prettier": {
"arrowParens": "avoid",
"jsxBracketSameLine": true,
"printWidth": 200,
"trailingComma": "none",
"useTabs": true,
"overrides": [
{
"files": [
"*.md"
],
"options": {
"useTabs": false
}
}
]
}
}
2 changes: 1 addition & 1 deletion test/05options.ts
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ describe("options", () => {
});

describe("teeToStdout", () => {
const content = [];
const content: { str: string | Uint8Array; encoding: string | ((err?: Error) => void); cb: undefined | ((err?: Error) => void) }[] = [];

const events = test({ options: { size: "10B", teeToStdout: true } }, rfs => {
const write = process.stdout.write;
Expand Down
2 changes: 2 additions & 0 deletions tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
"compilerOptions": {
"declaration": true,
"module": "commonjs",
"noImplicitAny": true,
"suppressImplicitAnyIndexErrors": true,
"target": "es6"
},
"include": ["./index.ts"]
Expand Down
50 changes: 4 additions & 46 deletions utils.ts
Original file line number Diff line number Diff line change
@@ -1,52 +1,10 @@
"use strict";

import { readFile, unlink, writeFile } from "fs";
import { unlink, writeFile } from "fs";

const common: string[] = ["*gz", "*log", "*tmp", "*txt", ".gitignore", ".npmignore", ".nyc_output", "coverage", "node_modules", ""];
const git: string[] = ["index.d.ts", "index.js"];
const npm: string[] = [".*", "index.ts", "test", "tsconfig.json", "tslint.json", "utils.ts"];
const git: string[] = ["index.js"];
const npm: string[] = [".*", "index.ts", "test", "tsconfig.json", "utils.ts"];

const readme: (err: Error, data: string) => void = (err, data) => {
if(err) return process.stderr.write(`Error reading README.md: ${err.message}`);

const input = data.split("\n");

readFile("index.d.ts", "utf8", (err: Error, data: string) => {
if(err) return process.stderr.write(`Error reading index.d.ts: ${err.message}`);

const output = [];
let begin: boolean, end: boolean;

input.map((line: string) => {
if(begin) {
if(end) output.push(line);
else if(line === "```") {
output.push(line);
end = true;
}
}

if(! begin) {
output.push(line);
if(line === "```typescript") {
let first: boolean, interf: boolean;
begin = true;
data.split("\n").map((line: string) => {
if(! first) return (first = true);
if(interf) return (interf = ! line.match(/}$/));
if(line.match(/interface Chunk/) || line.match(/interface Opts/)) return (interf = true);
if(line.match(/class RotatingFileStream/)) interf = ((line = line.replace("{", "{}")) as unknown) as boolean;
if(! line.match(/Callback/) && ! line.match(/export \{}/)) output.push(line.replace(" ", " "));
});
output.pop();
}
}
});

writeFile("README.md", output.join("\n"), () => {});
});
};

if(process.argv[2] === "clean") unlink("index.js", (): void => unlink("index.d.ts", (): void => {}));
if(process.argv[2] === "clean") unlink("index.js", (): void => {});
if(process.argv[2] === "ignore") writeFile(".gitignore", git.concat(common).join("\n"), (): void => writeFile(".npmignore", npm.concat(common).join("\n"), (): void => {}));
if(process.argv[2] === "readme") readFile("README.md", "utf8", readme);

0 comments on commit 6da86e2

Please sign in to comment.