From b1b37b069fe97fe24e5a4d79657d82b373bf11d5 Mon Sep 17 00:00:00 2001 From: Sambo Chea Date: Thu, 11 Mar 2021 11:32:42 +0700 Subject: [PATCH] Fixed the ts library and add rollup config for build Fixed log tests and updated config --- README.md | 3 +++ package.json | 18 +++++++++++++++--- rollup.config.ts | 28 ++++++++++++++++++++++++++++ src/index.ts | 6 +----- src/log/index.ts | 4 ++-- tests/log.test.ts | 10 +++++----- tsconfig.json | 4 ++-- 7 files changed, 56 insertions(+), 17 deletions(-) create mode 100644 rollup.config.ts diff --git a/README.md b/README.md index 1c85497..0f05948 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,7 @@ # CUBETIQ TypeScript Utils +[![code style: prettier](https://img.shields.io/badge/code_style-prettier-ff69b4.svg?style=flat-square)](https://github.com/prettier/prettier) +[![Build Status](https://dci.osa.cubetiqs.com/api/badges/CUBETIQ/cubetiq-ts-utils/status.svg)](https://dci.osa.cubetiqs.com/CUBETIQ/cubetiq-ts-utils) + - Function Utils - General Functions for TypeScript project(s) - Extends more diff --git a/package.json b/package.json index 3f5a5a8..4ee96ca 100644 --- a/package.json +++ b/package.json @@ -2,9 +2,14 @@ "name": "@cubetiq/tsutil", "version": "1.0.0", "description": "CUBETIQ TypeScript Utils", - "main": "index.ts", + "main": "dist/index.js.umd.js", + "module": "dist/index.es5.js", + "typings": "dist/types/index.d.ts", + "files": [ + "dist" + ], "repository": "https://github.com/CUBETIQ/cubetiq-ts-utils.git", - "author": "Sambo Chea", + "author": "Sambo Chea ", "license": "MIT", "private": false, "dependencies": {}, @@ -16,12 +21,19 @@ "eslint-config-prettier": "^8.1.0", "eslint-plugin-prettier": "^3.3.1", "jest": "^26.6.3", + "lodash.camelcase": "^4.3.0", "prettier": "^2.2.1", + "rollup": "^2.41.0", + "rollup-plugin-commonjs": "^10.1.0", + "rollup-plugin-json": "^4.0.0", + "rollup-plugin-node-resolve": "^5.2.0", + "rollup-plugin-sourcemaps": "^0.6.3", + "rollup-plugin-typescript2": "^0.30.0", "ts-jest": "^26.5.3", "typescript": "^4.2.3" }, "scripts": { - "build": "tsc -p tsconfig.json", + "build": "tsc --module commonjs && rollup -c rollup.config.ts", "lint": "eslint . --ext .ts", "prettier": "prettier --config .prettierrc 'src/**/*.ts' --write", "test": "jest", diff --git a/rollup.config.ts b/rollup.config.ts new file mode 100644 index 0000000..f94b94c --- /dev/null +++ b/rollup.config.ts @@ -0,0 +1,28 @@ +import resolve from 'rollup-plugin-node-resolve' +import commonjs from 'rollup-plugin-commonjs' +import sourceMaps from 'rollup-plugin-sourcemaps' +import camelCase from 'lodash.camelcase' +import typescript from 'rollup-plugin-typescript2' +import json from 'rollup-plugin-json' + +const pkg = require('./package.json') +const libraryName = 'tsutil' + +export default { + input: `src/index.ts`, + output: [ + { file: pkg.main, name: camelCase(libraryName), format: 'umd', sourcemap: true }, + { file: pkg.module, format: 'es', sourcemap: true }, + ], + external: [], + watch: { + include: 'src/**', + }, + plugins: [ + json(), + typescript({ useTsconfigDeclarationDir: true }), + commonjs(), + resolve(), + sourceMaps(), + ], +} \ No newline at end of file diff --git a/src/index.ts b/src/index.ts index f8cc5e1..65cd7fc 100644 --- a/src/index.ts +++ b/src/index.ts @@ -1,5 +1 @@ -const Index = (): void => { - console.log('Index', 'Hello, you are init the default function!'); -}; - -export default Index; +export * as Log from './log/index' \ No newline at end of file diff --git a/src/log/index.ts b/src/log/index.ts index bf32174..84a675e 100644 --- a/src/log/index.ts +++ b/src/log/index.ts @@ -1,6 +1,6 @@ import { Loggable } from './interfaces'; -class Index { +class Log { static log(loggable: Loggable): void { switch (loggable.type) { case 'error': @@ -28,4 +28,4 @@ class Index { } } -export default Index; +export default Log; diff --git a/tests/log.test.ts b/tests/log.test.ts index a19c288..48ee22f 100644 --- a/tests/log.test.ts +++ b/tests/log.test.ts @@ -1,20 +1,20 @@ -import Index from '../src/Log'; +import Log from '../src/log' describe('logging into console', function () { it('info', function () { - Index.info('I am an info!'); + Log.info('I am an info!'); }); it('warn', function () { - Index.info('I am a warn!'); + Log.info('I am a warn!'); }); it('error', function () { - Index.info('I am an error!'); + Log.info('I am an error!'); }); it('loggable', function () { - Index.log({ + Log.log({ type: 'info', from: 'log.test.ts', data: 'I am loggable called' diff --git a/tsconfig.json b/tsconfig.json index 1d118dc..f6b187a 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -8,7 +8,7 @@ "strict": true, "forceConsistentCasingInFileNames": true, "noFallthroughCasesInSwitch": true, - "module": "commonjs", + "module": "es2015", "moduleResolution": "node", "resolveJsonModule": true, "noEmit": true, @@ -17,6 +17,6 @@ "rootDir": "src", "lib": ["es2015", "es2016", "es2017", "dom"] }, - "include": ["src/**/*"], + "include": ["src"], "exclude": ["node_modules"] }