Fixed the ts library and add rollup config for build
All checks were successful
continuous-integration/drone/push Build is passing

Fixed log tests and updated config
This commit is contained in:
Sambo Chea 2021-03-11 11:32:42 +07:00
parent f2f0c823e2
commit b1b37b069f
7 changed files with 56 additions and 17 deletions

View File

@ -1,4 +1,7 @@
# CUBETIQ TypeScript Utils # 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 - Function Utils
- General Functions for TypeScript project(s) - General Functions for TypeScript project(s)
- Extends more - Extends more

View File

@ -2,9 +2,14 @@
"name": "@cubetiq/tsutil", "name": "@cubetiq/tsutil",
"version": "1.0.0", "version": "1.0.0",
"description": "CUBETIQ TypeScript Utils", "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", "repository": "https://github.com/CUBETIQ/cubetiq-ts-utils.git",
"author": "Sambo Chea", "author": "Sambo Chea <sombochea@cubetiqs.com>",
"license": "MIT", "license": "MIT",
"private": false, "private": false,
"dependencies": {}, "dependencies": {},
@ -16,12 +21,19 @@
"eslint-config-prettier": "^8.1.0", "eslint-config-prettier": "^8.1.0",
"eslint-plugin-prettier": "^3.3.1", "eslint-plugin-prettier": "^3.3.1",
"jest": "^26.6.3", "jest": "^26.6.3",
"lodash.camelcase": "^4.3.0",
"prettier": "^2.2.1", "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", "ts-jest": "^26.5.3",
"typescript": "^4.2.3" "typescript": "^4.2.3"
}, },
"scripts": { "scripts": {
"build": "tsc -p tsconfig.json", "build": "tsc --module commonjs && rollup -c rollup.config.ts",
"lint": "eslint . --ext .ts", "lint": "eslint . --ext .ts",
"prettier": "prettier --config .prettierrc 'src/**/*.ts' --write", "prettier": "prettier --config .prettierrc 'src/**/*.ts' --write",
"test": "jest", "test": "jest",

28
rollup.config.ts Normal file
View File

@ -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(),
],
}

View File

@ -1,5 +1 @@
const Index = (): void => { export * as Log from './log/index'
console.log('Index', 'Hello, you are init the default function!');
};
export default Index;

View File

@ -1,6 +1,6 @@
import { Loggable } from './interfaces'; import { Loggable } from './interfaces';
class Index { class Log {
static log(loggable: Loggable): void { static log(loggable: Loggable): void {
switch (loggable.type) { switch (loggable.type) {
case 'error': case 'error':
@ -28,4 +28,4 @@ class Index {
} }
} }
export default Index; export default Log;

View File

@ -1,20 +1,20 @@
import Index from '../src/Log'; import Log from '../src/log'
describe('logging into console', function () { describe('logging into console', function () {
it('info', function () { it('info', function () {
Index.info('I am an info!'); Log.info('I am an info!');
}); });
it('warn', function () { it('warn', function () {
Index.info('I am a warn!'); Log.info('I am a warn!');
}); });
it('error', function () { it('error', function () {
Index.info('I am an error!'); Log.info('I am an error!');
}); });
it('loggable', function () { it('loggable', function () {
Index.log({ Log.log({
type: 'info', type: 'info',
from: 'log.test.ts', from: 'log.test.ts',
data: 'I am loggable called' data: 'I am loggable called'

View File

@ -8,7 +8,7 @@
"strict": true, "strict": true,
"forceConsistentCasingInFileNames": true, "forceConsistentCasingInFileNames": true,
"noFallthroughCasesInSwitch": true, "noFallthroughCasesInSwitch": true,
"module": "commonjs", "module": "es2015",
"moduleResolution": "node", "moduleResolution": "node",
"resolveJsonModule": true, "resolveJsonModule": true,
"noEmit": true, "noEmit": true,
@ -17,6 +17,6 @@
"rootDir": "src", "rootDir": "src",
"lib": ["es2015", "es2016", "es2017", "dom"] "lib": ["es2015", "es2016", "es2017", "dom"]
}, },
"include": ["src/**/*"], "include": ["src"],
"exclude": ["node_modules"] "exclude": ["node_modules"]
} }