Skip to content

Commit

Permalink
chore(typescript): add typescript architecture
Browse files Browse the repository at this point in the history
  • Loading branch information
hisasann committed Jan 27, 2019
1 parent 6ecf545 commit f2dc1f4
Show file tree
Hide file tree
Showing 11 changed files with 4,182 additions and 23 deletions.
33 changes: 33 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
# EditorConfig is awesome: https://EditorConfig.org

# top-most EditorConfig file
root = true

# Unix-style newlines with a newline ending every file
[*]
end_of_line = lf
insert_final_newline = true

# Matches multiple files with brace expansion notation
# Set default charset
[*.{js,py}]
charset = utf-8

# 4 space indentation
[*.py]
indent_style = space
indent_size = 4

# Tab indentation (no size specified)
[Makefile]
indent_style = tab

# Indentation override for all JS under lib directory
[lib/**.js]
indent_style = space
indent_size = 2

# Matches the exact files either package.json or .travis.yml
[{package.json,.travis.yml}]
indent_style = space
indent_size = 2
4 changes: 4 additions & 0 deletions .prettierrc.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# .prettierrc.toml
trailingComma = "all"
semi = true
singleQuote = true
85 changes: 76 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,17 +1,84 @@
# node-log-rotate
:lipstick: node-log-rotate :lipstick:
===============

[![MIT License](http://img.shields.io/badge/license-MIT-blue.svg?style=flat)](LICENSE)
[![npm version](https://badge.fury.io/js/node-log-rotate.svg)](https://badge.fury.io/js/node-log-rotate)


## Usage
## Description

inspire:

[megahertz/electron-log: Just a very simple logging module for your Electron application](https://github.com/megahertz/electron-log)

Just a very simple logging module for your Electron application.
No dependencies. No complicated configuration. Just require and use.
Also it can be used without Electron.

```
$ node-log-rotate
```
By default it writes logs to the following locations:

* **on Linux:** `~/.config/<app name>/<date+time>log.log`
* **on OS X:** `~/Library/Logs/<app name>/<date+time>log.log`
* **on Windows:** `$HOME/AppData/Roaming/<app name>/<date+time>log.log`


## Installation

```
$ npm install node-log-rotate -g
```
Install with [npm](https://npmjs.org/package/node-log-rotate):

npm install node-log-rotate

or

Yarn

yarn add node-log-rotate


## Usage

### ES2015

```js
import { setup, log } from 'node-log-rotate';
setup({
appName: 'project-name', // require for directory name
maxSize: 10 * 1024 * 1024
});

log('Hello, log');
```

### CommonJS

```js
var log = require('node-log-rotate');
log.setup({
appName: 'project-name', // require for directory name
maxSize: 10 * 1024 * 1024
});

log.log('Hello, log');
```


## About deleting log files

For this sample, log files before 10 days ago will be deleted.

```js
import { setup, deleteLog } from 'node-log-rotate';
setup({
appName: 'project-name' // require for directory name
});

deleteLog(10);
```


## Maintainers

- [hisasann](https://github.com/hisasann)

## License

MIT © [hisasann](https://github.com/hisasann)
6 changes: 0 additions & 6 deletions bin/node-log-rotate

This file was deleted.

3 changes: 3 additions & 0 deletions lib/main.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
"use strict";
const s = 'hoge';
console.log(s);
4 changes: 0 additions & 4 deletions main.js

This file was deleted.

53 changes: 49 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,41 @@
"description": "",
"main": "main.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
"build": "tsc",
"dev": "npm run build && node -r esm ./lib/main.js",
"test": "jest",
"test:coverage": "jest --no-cache --forceExit --coverage",
"tsc:init": "tsc --init",
"lint": "prettier --list-different \"{src,__tests__}/**/*.{js,ts,tsx,json}\"",
"lint:format": "prettier --write \"{src,__tests__}/**/*.{js,ts,tsx,json}\"",
"lint-staged": "lint-staged"
},
"bin": {
"node-log-rotate": "bin/node-log-rotate"
"lint-staged": {
"linters": {
"{src,__tests__}/**/*.{js,ts,tsx,json}": [
"npm run lint:format",
"git add"
]
}
},
"jest": {
"transform": {
"^.+\\.tsx?$": "ts-jest"
},
"testRegex": "(/__tests__/.*|(\\.|/)(test|spec))\\.(jsx?|tsx?)$",
"moduleFileExtensions": [
"ts",
"tsx",
"js",
"jsx",
"json",
"node"
],
"coverageDirectory": "./coverage/",
"collectCoverage": false,
"collectCoverageFrom": [
"src/**/*.{ts,tsx}"
]
},
"repository": {
"type": "git",
Expand All @@ -18,5 +49,19 @@
"bugs": {
"url": "https://github.com/lemon-sour/node-log-rotate/issues"
},
"homepage": "https://github.com/lemon-sour/node-log-rotate#readme"
"homepage": "https://github.com/lemon-sour/node-log-rotate#readme",
"dependencies": {
"lint-staged": "^8.1.0"
},
"devDependencies": {
"@types/jest": "^23.3.12",
"@types/node": "^10.12.18",
"esm": "^3.0.84",
"jest": "^23.6.0",
"nodemon": "^1.18.9",
"prettier": "^1.15.3",
"rimraf": "^2.6.3",
"ts-jest": "^23.10.5",
"typescript": "^3.2.2"
}
}
2 changes: 2 additions & 0 deletions src/main.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
const s: string = 'hoge';
console.log(s);
62 changes: 62 additions & 0 deletions tsconfig.base.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
{
"compilerOptions": {
/* Basic Options */
"target": "es6", /* Specify ECMAScript target version: 'ES3' (default), 'ES5', 'ES2015', 'ES2016', 'ES2017','ES2018' or 'ESNEXT'. */
"module": "commonjs", /* Specify module code generation: 'none', 'commonjs', 'amd', 'system', 'umd', 'es2015', or 'ESNext'. */
"lib": ["es6"], /* Specify library files to be included in the compilation. */
// "allowJs": true, /* Allow javascript files to be compiled. */
// "checkJs": true, /* Report errors in .js files. */
// "jsx": "preserve", /* Specify JSX code generation: 'preserve', 'react-native', or 'react'. */
// "declaration": true, /* Generates corresponding '.d.ts' file. */
// "declarationMap": true, /* Generates a sourcemap for each corresponding '.d.ts' file. */
// "sourceMap": true, /* Generates corresponding '.map' file. */
// "outFile": "./", /* Concatenate and emit output to single file. */
// "outDir": "./lib", /* Redirect output structure to the directory. */
// "rootDir": "./", /* Specify the root directory of input files. Use to control the output directory structure with --outDir. */
// "composite": true, /* Enable project compilation */
// "removeComments": true, /* Do not emit comments to output. */
// "noEmit": true, /* Do not emit outputs. */
// "importHelpers": true, /* Import emit helpers from 'tslib'. */
// "downlevelIteration": true, /* Provide full support for iterables in 'for-of', spread, and destructuring when targeting 'ES5' or 'ES3'. */
// "isolatedModules": true, /* Transpile each file as a separate module (similar to 'ts.transpileModule'). */

/* Strict Type-Checking Options */
"strict": true, /* Enable all strict type-checking options. */
// "noImplicitAny": true, /* Raise error on expressions and declarations with an implied 'any' type. */
// "strictNullChecks": true, /* Enable strict null checks. */
// "strictFunctionTypes": true, /* Enable strict checking of function types. */
// "strictBindCallApply": true, /* Enable strict 'bind', 'call', and 'apply' methods on functions. */
// "strictPropertyInitialization": true, /* Enable strict checking of property initialization in classes. */
// "noImplicitThis": true, /* Raise error on 'this' expressions with an implied 'any' type. */
// "alwaysStrict": true, /* Parse in strict mode and emit "use strict" for each source file. */

/* Additional Checks */
// "noUnusedLocals": true, /* Report errors on unused locals. */
// "noUnusedParameters": true, /* Report errors on unused parameters. */
// "noImplicitReturns": true, /* Report error when not all code paths in function return a value. */
// "noFallthroughCasesInSwitch": true, /* Report errors for fallthrough cases in switch statement. */

/* Module Resolution Options */
// "moduleResolution": "node", /* Specify module resolution strategy: 'node' (Node.js) or 'classic' (TypeScript pre-1.6). */
// "baseUrl": "./", /* Base directory to resolve non-absolute module names. */
// "paths": {}, /* A series of entries which re-map imports to lookup locations relative to the 'baseUrl'. */
// "rootDirs": [], /* List of root folders whose combined content represents the structure of the project at runtime. */
// "typeRoots": [], /* List of folders to include type definitions from. */
// "types": ["node", "jest"], /* Type declaration files to be included in compilation. */
// "allowSyntheticDefaultImports": true, /* Allow default imports from modules with no default export. This does not affect code emit, just typechecking. */
// "esModuleInterop": true, /* Enables emit interoperability between CommonJS and ES Modules via creation of namespace objects for all imports. Implies 'allowSyntheticDefaultImports'. */
// "preserveSymlinks": true, /* Do not resolve the real path of symlinks. */

/* Source Map Options */
// "sourceRoot": "", /* Specify the location where debugger should locate TypeScript files instead of source locations. */
// "mapRoot": "", /* Specify the location where debugger should locate map files instead of generated locations. */
// "inlineSourceMap": true, /* Emit a single file with source maps instead of having a separate file. */
// "inlineSources": true, /* Emit the source alongside the sourcemaps within a single file; requires '--inlineSourceMap' or '--sourceMap' to be set. */

/* Experimental Options */
"experimentalDecorators": true, /* Enables experimental support for ES7 decorators. */
"emitDecoratorMetadata": true /* Enables experimental support for emitting type metadata for decorators. */
},
// "include": ["src/**/*.ts"],
"exclude": ["node_modules"]
}
19 changes: 19 additions & 0 deletions tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{
"extends": "./tsconfig.base.json",
"compilerOptions": {
"outDir": "./lib", /* Redirect output structure to the directory. */
"rootDir": "./src", /* Specify the root directory of input files. Use to control the output directory structure with --outDir. */
// "paths": {
// "*": ["types/*"]
// }, /* A series of entries which re-map imports to lookup locations relative to the 'baseUrl'. */
// "typeRoots": ["types", "node_modules/@types", "../../node_modules/@types"], /* List of folders to include type definitions from. */
// "types": [
// "node",
// "jest",
// "lodash",
// "minimist"
// ], /* Type declaration files to be included in compilation. */
"baseUrl": "./" /* Base directory to resolve non-absolute module names. */
},
"include": ["src/**/*.ts"]
}
Loading

0 comments on commit f2dc1f4

Please sign in to comment.