Compare commits

...

6 Commits

11 changed files with 35 additions and 95 deletions

View File

@@ -7,4 +7,4 @@ steps:
commands:
- npm config set registry https://r.ctdn.net
- npm install
- npm run build
- npm run build

View File

@@ -21,7 +21,6 @@ module.exports = {
sourceType: "module",
},
plugins: [
"eslint-plugin-jsdoc",
"eslint-plugin-prefer-arrow",
"@typescript-eslint",
],
@@ -153,4 +152,4 @@ module.exports = {
"use-isnan": "error",
"valid-typeof": "off",
},
}
}

View File

@@ -1,4 +1,4 @@
#!/bin/sh
. "$(dirname "$0")/_/husky.sh"
npx lint-staged
npx lint-staged

View File

@@ -1,10 +1,11 @@
# TS Project (Template for TypeScript)
- TypeScript
- TS Node Dev
- Husky
- Prettier
- ESLint
- TypeScript
- TS Node Dev
- Husky
- Prettier
- ESLint
### Contributors
- Sambo Chea <sombochea@cubetiqs.com>
- Sambo Chea <sombochea@cubetiqs.com>

View File

@@ -3,9 +3,11 @@
"version": "1.0.0",
"description": "Typescript common and web utils",
"main": "dist/index.js",
"source": "src/index.ts",
"scripts": {
"start": "tsc -w",
"build": "rm -rf dist && tsc"
"build": "rm -rf dist && tsc",
"prepare": "husky install"
},
"repository": {
"type": "git",
@@ -25,7 +27,6 @@
"@typescript-eslint/parser": "^4.30.0",
"eslint": "^7.32.0",
"eslint-config-prettier": "^8.3.0",
"eslint-plugin-jsdoc": "^36.0.8",
"eslint-plugin-prefer-arrow": "^1.2.3",
"husky": "^7.0.2",
"lint-staged": "^11.1.2",
@@ -38,4 +39,4 @@
"lint-staged": {
"**/*": "prettier --write --ignore-unknown"
}
}
}

View File

@@ -36,4 +36,4 @@ export const millisToSeconds = (millis: number) => {
export const randomThenGetOne = (data: any[]): any => {
const randomIndex = Math.floor(Math.random() * data.length)
return data[randomIndex]
}
}

View File

@@ -1,16 +1,16 @@
// import { formatDate, formatDateOnly, formatDateFromTimestamp } from "./date"
// import { debug, info,error, warn } from './log'
// import { parse2Int, parse2IntOrNull, parseToBoolean } from "./number/parser"
import { formatDate, formatDateOnly, formatDateFromTimestamp } from "./date"
import { debug, info, error, warn } from "./log"
import { parse2Int, parse2IntOrNull, parseToBoolean } from "./number/parser"
// export {
// formatDate,
// formatDateOnly,
// formatDateFromTimestamp,
// debug,
// info,
// error,
// warn,
// parse2Int,
// parse2IntOrNull,
// parseToBoolean,
// }
export {
formatDate,
formatDateOnly,
formatDateFromTimestamp,
debug,
info,
error,
warn,
parse2Int,
parse2IntOrNull,
parseToBoolean,
}

View File

@@ -1,8 +1,7 @@
import chalk from "chalk"
import { formatDate } from "../date"
import Logger from "./writter"
let logger = Logger.getProvider()
const logger = console
const prefixColor = (
prefix: string,
@@ -10,10 +9,6 @@ const prefixColor = (
color: string = "green"
) => {
const timestamp = formatDate(new Date())
if (Logger.isEnabled()) {
return `[${timestamp}] - ${prefix}: ${message}`
}
const firstStep = chalk`[${timestamp}] - {${color} ${prefix}}:`
return `${firstStep} ${message}`
}
@@ -41,4 +36,4 @@ export const info = (message?: any, ...args: any[]) => {
export const success = (message?: any, ...args: any[]) => {
const msg = prefixColor("SUCCESS", message)
args.length === 0 ? logger.info(msg) : logger.info(msg, ...args)
}
}

View File

@@ -1,55 +0,0 @@
import * as fs from "fs"
import { Console } from "console"
import * as path from "path"
import { formatDateOnly } from "../date"
class Logger {
private static enabled: boolean = false
public static setEnabled(enabled: boolean): void {
this.enabled = enabled
}
public static isEnabled(): boolean {
return this.enabled
}
private static logDir?: string
public static setLogDir(logDir: string): void {
this.logDir = logDir
}
public static getLogDir(): string | null | undefined {
return this.logDir
}
public static getProvider(): Console {
if (this.isEnabled()) {
const rootPath = path.resolve(this.getLogDir() || "./")
const logPath = `${rootPath}/logs`
if (!fs.existsSync(logPath)) {
fs.mkdirSync(logPath, { recursive: true })
}
const time = formatDateOnly(new Date()).replace(/\//g, "-")
console.log("Logs writing to path =>", logPath)
const output = fs.createWriteStream(
`${logPath}/stdout-${time}.log`,
{
flags: "a",
}
)
const errorOutput = fs.createWriteStream(
`${logPath}/stderr-${time}.log`,
{
flags: "a",
}
)
return new Console({ stdout: output, stderr: errorOutput })
}
return console
}
}
export default Logger

View File

@@ -18,4 +18,4 @@ export const parseToBoolean = (
): boolean => {
if (!val) return defaultValue
return val === true || val.toLowerCase() === "true"
}
}

View File

@@ -12,8 +12,7 @@
"lib": ["ES2015"],
"skipLibCheck": true,
"allowJs": true,
"declaration": true,
"emitDeclarationOnly": false
"declaration": true
},
"include": ["src/**/*"]
}
}