Compare commits

...

3 Commits

Author SHA1 Message Date
40905708fd remove eslint jsdoc 2023-05-06 10:44:55 +07:00
596d6e92d2 Task: Fixed ts common package 2021-12-22 16:30:34 +07:00
e26ee50faf Updated format 2021-09-16 18:18:04 +07:00
10 changed files with 32 additions and 92 deletions

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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