From be8dbd697c97717e71594dc03792083d2f8df342 Mon Sep 17 00:00:00 2001 From: synw Date: Mon, 1 May 2023 13:10:20 +0200 Subject: [PATCH] Improve typescript lib: compile with Rollup --- lang/typescript/dist/emo.min.cjs | 1 + lang/typescript/dist/emo.min.js | 1 + lang/typescript/dist/emo.mjs | 128 ++++++++++++++++++++++ lang/typescript/dist/emo_gen.d.ts | 63 +++++++++++ lang/typescript/dist/interfaces.d.ts | 8 ++ lang/typescript/dist/main.d.ts | 4 + lang/typescript/dist/types.d.ts | 2 + lang/typescript/package.json | 28 +++-- lang/typescript/rollup.config.js | 35 ++++++ lang/typescript/src/{index.ts => main.ts} | 0 lang/typescript/tsconfig.json | 10 +- 11 files changed, 266 insertions(+), 14 deletions(-) create mode 100644 lang/typescript/dist/emo.min.cjs create mode 100644 lang/typescript/dist/emo.min.js create mode 100644 lang/typescript/dist/emo.mjs create mode 100644 lang/typescript/dist/emo_gen.d.ts create mode 100644 lang/typescript/dist/interfaces.d.ts create mode 100644 lang/typescript/dist/main.d.ts create mode 100644 lang/typescript/dist/types.d.ts create mode 100644 lang/typescript/rollup.config.js rename lang/typescript/src/{index.ts => main.ts} (100%) diff --git a/lang/typescript/dist/emo.min.cjs b/lang/typescript/dist/emo.min.cjs new file mode 100644 index 0000000..15faadb --- /dev/null +++ b/lang/typescript/dist/emo.min.cjs @@ -0,0 +1 @@ +"use strict";Object.defineProperty(exports,"__esModule",{value:!0});class t{constructor({zone:t=null,activatePrint:r=!0,activateEmojis:e=!0,hook:o=null}={zone:null,activatePrint:!0,activateEmojis:!0,hook:null}){this.zone=t,this.activatePrint=r,this.activateEmojis=e,this.hook=o}info(...t){return this.emo("ℹī¸",t)}warning(...t){return this.emo("🔔",t)}error(...t){return this.emo("đŸ’ĸ",t)}query(...t){return this.emo("🗄ī¸",t)}queryError(...t){return this.emo("🗄ī¸",t)}encrypt(...t){return this.emo("đŸŽŧ",t)}encryptError(...t){return this.emo("đŸŽŧ",t)}decrypt(...t){return this.emo("🗝ī¸",t)}decryptError(...t){return this.emo("🗝ī¸",t)}time(...t){return this.emo("⏱ī¸",t)}timeError(...t){return this.emo("⏱ī¸",t)}param(...t){return this.emo("📩",t)}paramError(...t){return this.emo("📩",t)}debug(...t){return this.emo("💊",t)}state(...t){return this.emo("đŸ“ĸ",t)}save(...t){return this.emo("💾",t)}delete(...t){return this.emo("❌",t)}data(...t){return this.emo("đŸ’ŧ",t)}line(...t){return this.emo("➖",t)}init(...t){return this.emo("đŸŽŦ",t)}update(...t){return this.emo("🆙",t)}ok(...t){return this.emo("🆗",t)}build(...t){return this.emo("🔧",t)}aconstructor(...t){return this.emo("🛠ī¸",t)}notFound(...t){return this.emo("đŸšĢ",t)}found(...t){return this.emo("👁ī¸â€đŸ—¨ī¸",t)}result(...t){return this.emo("📌",t)}input(...t){return this.emo("đŸ“Ĩ",t)}output(...t){return this.emo("📤",t)}function(...t){return this.emo("🔨",t)}key(...t){return this.emo("🔑",t)}security(...t){return this.emo("🔒",t)}accessToken(...t){return this.emo("🔑",t)}refreshToken(...t){return this.emo("🗝ī¸",t)}transmit(...t){return this.emo("📡",t)}start(...t){return this.emo("🏁",t)}stop(...t){return this.emo("🛑",t)}in(...t){return this.emo("→",t)}out(...t){return this.emo("←",t)}arrowIn(...t){return this.emo("=>",t)}arrowOut(...t){return this.emo("<=",t)}smallArrowIn(...t){return this.emo("->",t)}smallArrowOut(...t){return this.emo("<-",t)}requestGet(...t){return this.emo("🔷",t)}requestPost(...t){return this.emo("đŸ”ļ",t)}msg(...t){return this.emo("",t)}ready(...t){return 0===t.length&&(t[0]="ready"),this.emo("⏲ī¸",t)}sep(){const t="➖➖➖➖➖➖➖➖➖➖➖";return this.activatePrint&&console.log(t),t}section(t){const r="➖➖➖➖➖ "+t+" ➖➖➖➖➖";return this.activatePrint&&console.log(r),r}sectionEnd(){return this.sep()}emo(t,r){const e=this._getEmoString(t,r);return this.activatePrint&&console.log(e),null!=this.hook&&this.hook(e),e}print(r){t.json(r)}static json(t){console.log(JSON.stringify(t,null," "))}_getEmoString(t,r){const e=new Array;return this.activateEmojis&&null!=t&&e.push(t),null!=this.zone&&e.push("["+this.zone+"]"),r.length>0&&r.forEach((t=>{"object"==typeof t?e.push(JSON.stringify(t)):e.push(t.toString())})),e.join(" ")}}exports.Emo=t; diff --git a/lang/typescript/dist/emo.min.js b/lang/typescript/dist/emo.min.js new file mode 100644 index 0000000..897e282 --- /dev/null +++ b/lang/typescript/dist/emo.min.js @@ -0,0 +1 @@ +var $emo=function(t){"use strict";class r{constructor({zone:t=null,activatePrint:r=!0,activateEmojis:e=!0,hook:o=null}={zone:null,activatePrint:!0,activateEmojis:!0,hook:null}){this.zone=t,this.activatePrint=r,this.activateEmojis=e,this.hook=o}info(...t){return this.emo("ℹī¸",t)}warning(...t){return this.emo("🔔",t)}error(...t){return this.emo("đŸ’ĸ",t)}query(...t){return this.emo("🗄ī¸",t)}queryError(...t){return this.emo("🗄ī¸",t)}encrypt(...t){return this.emo("đŸŽŧ",t)}encryptError(...t){return this.emo("đŸŽŧ",t)}decrypt(...t){return this.emo("🗝ī¸",t)}decryptError(...t){return this.emo("🗝ī¸",t)}time(...t){return this.emo("⏱ī¸",t)}timeError(...t){return this.emo("⏱ī¸",t)}param(...t){return this.emo("📩",t)}paramError(...t){return this.emo("📩",t)}debug(...t){return this.emo("💊",t)}state(...t){return this.emo("đŸ“ĸ",t)}save(...t){return this.emo("💾",t)}delete(...t){return this.emo("❌",t)}data(...t){return this.emo("đŸ’ŧ",t)}line(...t){return this.emo("➖",t)}init(...t){return this.emo("đŸŽŦ",t)}update(...t){return this.emo("🆙",t)}ok(...t){return this.emo("🆗",t)}build(...t){return this.emo("🔧",t)}aconstructor(...t){return this.emo("🛠ī¸",t)}notFound(...t){return this.emo("đŸšĢ",t)}found(...t){return this.emo("👁ī¸â€đŸ—¨ī¸",t)}result(...t){return this.emo("📌",t)}input(...t){return this.emo("đŸ“Ĩ",t)}output(...t){return this.emo("📤",t)}function(...t){return this.emo("🔨",t)}key(...t){return this.emo("🔑",t)}security(...t){return this.emo("🔒",t)}accessToken(...t){return this.emo("🔑",t)}refreshToken(...t){return this.emo("🗝ī¸",t)}transmit(...t){return this.emo("📡",t)}start(...t){return this.emo("🏁",t)}stop(...t){return this.emo("🛑",t)}in(...t){return this.emo("→",t)}out(...t){return this.emo("←",t)}arrowIn(...t){return this.emo("=>",t)}arrowOut(...t){return this.emo("<=",t)}smallArrowIn(...t){return this.emo("->",t)}smallArrowOut(...t){return this.emo("<-",t)}requestGet(...t){return this.emo("🔷",t)}requestPost(...t){return this.emo("đŸ”ļ",t)}msg(...t){return this.emo("",t)}ready(...t){return 0===t.length&&(t[0]="ready"),this.emo("⏲ī¸",t)}sep(){const t="➖➖➖➖➖➖➖➖➖➖➖";return this.activatePrint&&console.log(t),t}section(t){const r="➖➖➖➖➖ "+t+" ➖➖➖➖➖";return this.activatePrint&&console.log(r),r}sectionEnd(){return this.sep()}emo(t,r){const e=this._getEmoString(t,r);return this.activatePrint&&console.log(e),null!=this.hook&&this.hook(e),e}print(t){r.json(t)}static json(t){console.log(JSON.stringify(t,null," "))}_getEmoString(t,r){const e=new Array;return this.activateEmojis&&null!=t&&e.push(t),null!=this.zone&&e.push("["+this.zone+"]"),r.length>0&&r.forEach((t=>{"object"==typeof t?e.push(JSON.stringify(t)):e.push(t.toString())})),e.join(" ")}}return t.Emo=r,Object.defineProperty(t,"__esModule",{value:!0}),t}({}); diff --git a/lang/typescript/dist/emo.mjs b/lang/typescript/dist/emo.mjs new file mode 100644 index 0000000..e6f22c8 --- /dev/null +++ b/lang/typescript/dist/emo.mjs @@ -0,0 +1,128 @@ +// Code generated by https://github.com/teal-finance/emo/blob/main/codegen/ts/gen.go ; DO NOT EDIT. +class Emo { + /// Default constructor + constructor({ zone = null, activatePrint = true, activateEmojis = true, hook = null } = { + zone: null, + activatePrint: true, + activateEmojis: true, + hook: null + }) { + this.zone = zone; + this.activatePrint = activatePrint; + this.activateEmojis = activateEmojis; + this.hook = hook; + } + info(...obj) { return this.emo("ℹī¸", obj); } + warning(...obj) { return this.emo("🔔", obj); } + error(...obj) { return this.emo("đŸ’ĸ", obj); } + query(...obj) { return this.emo("🗄ī¸", obj); } + queryError(...obj) { return this.emo("🗄ī¸", obj); } + encrypt(...obj) { return this.emo("đŸŽŧ", obj); } + encryptError(...obj) { return this.emo("đŸŽŧ", obj); } + decrypt(...obj) { return this.emo("🗝ī¸", obj); } + decryptError(...obj) { return this.emo("🗝ī¸", obj); } + time(...obj) { return this.emo("⏱ī¸", obj); } + timeError(...obj) { return this.emo("⏱ī¸", obj); } + param(...obj) { return this.emo("📩", obj); } + paramError(...obj) { return this.emo("📩", obj); } + debug(...obj) { return this.emo("💊", obj); } + state(...obj) { return this.emo("đŸ“ĸ", obj); } + save(...obj) { return this.emo("💾", obj); } + delete(...obj) { return this.emo("❌", obj); } + data(...obj) { return this.emo("đŸ’ŧ", obj); } + line(...obj) { return this.emo("➖", obj); } + init(...obj) { return this.emo("đŸŽŦ", obj); } + update(...obj) { return this.emo("🆙", obj); } + ok(...obj) { return this.emo("🆗", obj); } + build(...obj) { return this.emo("🔧", obj); } + aconstructor(...obj) { return this.emo("🛠ī¸", obj); } + notFound(...obj) { return this.emo("đŸšĢ", obj); } + found(...obj) { return this.emo("👁ī¸â€đŸ—¨ī¸", obj); } + result(...obj) { return this.emo("📌", obj); } + input(...obj) { return this.emo("đŸ“Ĩ", obj); } + output(...obj) { return this.emo("📤", obj); } + function(...obj) { return this.emo("🔨", obj); } + key(...obj) { return this.emo("🔑", obj); } + security(...obj) { return this.emo("🔒", obj); } + accessToken(...obj) { return this.emo("🔑", obj); } + refreshToken(...obj) { return this.emo("🗝ī¸", obj); } + transmit(...obj) { return this.emo("📡", obj); } + start(...obj) { return this.emo("🏁", obj); } + stop(...obj) { return this.emo("🛑", obj); } + in(...obj) { return this.emo("→", obj); } + out(...obj) { return this.emo("←", obj); } + arrowIn(...obj) { return this.emo("=>", obj); } + arrowOut(...obj) { return this.emo("<=", obj); } + smallArrowIn(...obj) { return this.emo("->", obj); } + smallArrowOut(...obj) { return this.emo("<-", obj); } + requestGet(...obj) { return this.emo("🔷", obj); } + requestPost(...obj) { return this.emo("đŸ”ļ", obj); } + /// A simple message with no emoji + msg(...obj) { return this.emo("", obj); } + /// A debug message for a ready state + /// + /// emoji: ⏲ī¸ + ready(...obj) { + if (obj.length === 0) { + obj[0] = "ready"; + } + return this.emo("⏲ī¸", obj); + } + /// A separator line + sep() { + const msg = "➖➖➖➖➖➖➖➖➖➖➖"; + if (this.activatePrint) { + console.log(msg); + } + return msg; + } + /// A section start + section(name) { + const msg = "➖➖➖➖➖ " + name + " ➖➖➖➖➖"; + if (this.activatePrint) { + console.log(msg); + } + return msg; + } + /// A section end + sectionEnd() { return this.sep(); } + /// Print a debug message from an emoji + emo(emoji, obj) { + const msg = this._getEmoString(emoji, obj); + if (this.activatePrint) { + console.log(msg); + } + if (this.hook != null) { + this.hook(msg); + } + return msg; + } + print(data) { + Emo.json(data); + } + static json(data) { + console.log(JSON.stringify(data, null, " ")); + } + _getEmoString(emoji, obj) { + const l = new Array(); + if (this.activateEmojis && emoji != null) { + l.push(emoji); + } + if (this.zone != null) { + l.push("[" + this.zone + "]"); + } + if (obj.length > 0) { + obj.forEach((o) => { + if (typeof o === 'object') { + l.push(JSON.stringify(o)); + } + else { + l.push(o.toString()); + } + }); + } + return l.join(" "); + } +} + +export { Emo }; diff --git a/lang/typescript/dist/emo_gen.d.ts b/lang/typescript/dist/emo_gen.d.ts new file mode 100644 index 0000000..cbfd173 --- /dev/null +++ b/lang/typescript/dist/emo_gen.d.ts @@ -0,0 +1,63 @@ +import { EmoParams } from './interfaces'; +import { EmoHook } from './types'; +export default class Emo { + activatePrint: boolean; + zone: string | null; + hook: EmoHook | null; + activateEmojis: boolean; + constructor({ zone, activatePrint, activateEmojis, hook }?: EmoParams); + info(...obj: any[]): string; + warning(...obj: any[]): string; + error(...obj: any[]): string; + query(...obj: any[]): string; + queryError(...obj: any[]): string; + encrypt(...obj: any[]): string; + encryptError(...obj: any[]): string; + decrypt(...obj: any[]): string; + decryptError(...obj: any[]): string; + time(...obj: any[]): string; + timeError(...obj: any[]): string; + param(...obj: any[]): string; + paramError(...obj: any[]): string; + debug(...obj: any[]): string; + state(...obj: any[]): string; + save(...obj: any[]): string; + delete(...obj: any[]): string; + data(...obj: any[]): string; + line(...obj: any[]): string; + init(...obj: any[]): string; + update(...obj: any[]): string; + ok(...obj: any[]): string; + build(...obj: any[]): string; + aconstructor(...obj: any[]): string; + notFound(...obj: any[]): string; + found(...obj: any[]): string; + result(...obj: any[]): string; + input(...obj: any[]): string; + output(...obj: any[]): string; + function(...obj: any[]): string; + key(...obj: any[]): string; + security(...obj: any[]): string; + accessToken(...obj: any[]): string; + refreshToken(...obj: any[]): string; + transmit(...obj: any[]): string; + start(...obj: any[]): string; + stop(...obj: any[]): string; + in(...obj: any[]): string; + out(...obj: any[]): string; + arrowIn(...obj: any[]): string; + arrowOut(...obj: any[]): string; + smallArrowIn(...obj: any[]): string; + smallArrowOut(...obj: any[]): string; + requestGet(...obj: any[]): string; + requestPost(...obj: any[]): string; + msg(...obj: any[]): string; + ready(...obj: any[]): string; + sep(): string; + section(name: string): string; + sectionEnd(): string; + emo(emoji: string, obj: Array): string; + print(data: Array | Record): void; + static json(data: Array | Record): void; + private _getEmoString; +} diff --git a/lang/typescript/dist/interfaces.d.ts b/lang/typescript/dist/interfaces.d.ts new file mode 100644 index 0000000..0c9c1fd --- /dev/null +++ b/lang/typescript/dist/interfaces.d.ts @@ -0,0 +1,8 @@ +import { EmoHook } from './types'; +interface EmoParams { + zone?: string | null; + activatePrint?: boolean; + activateEmojis?: boolean; + hook?: EmoHook | null; +} +export { EmoParams }; diff --git a/lang/typescript/dist/main.d.ts b/lang/typescript/dist/main.d.ts new file mode 100644 index 0000000..b2f8447 --- /dev/null +++ b/lang/typescript/dist/main.d.ts @@ -0,0 +1,4 @@ +import Emo from "./emo_gen"; +import { EmoHook } from "./types"; +import { EmoParams } from "./interfaces"; +export { Emo, EmoHook, EmoParams }; diff --git a/lang/typescript/dist/types.d.ts b/lang/typescript/dist/types.d.ts new file mode 100644 index 0000000..db15a4e --- /dev/null +++ b/lang/typescript/dist/types.d.ts @@ -0,0 +1,2 @@ +declare type EmoHook = (msg: string) => void; +export { EmoHook }; diff --git a/lang/typescript/package.json b/lang/typescript/package.json index 415d0bb..15437f4 100644 --- a/lang/typescript/package.json +++ b/lang/typescript/package.json @@ -1,14 +1,9 @@ { "name": "emosd", - "version": "0.3.0", + "version": "0.4.0", "description": "Emoji based semantic debuging", - "main": "lib/index.js", - "types": "lib/index.d.ts", - "files": [ - "/lib" - ], "scripts": { - "build": "tsc", + "build": "rm -f dist/* && rollup -c", "test": "echo \"Error: no test specified\" && exit 1" }, "repository": { @@ -22,9 +17,24 @@ "devDependencies": { "@types/node": "^14.14.28", "tslib": "^2.1.0", - "typescript": "^4.1.3" + "typescript": "^4.1.3", + "@rollup/plugin-commonjs": "^21.0.2", + "@rollup/plugin-node-resolve": "^13.1.3", + "@rollup/plugin-typescript": "^8.3.1", + "rollup-plugin-terser": "^7.0.2" + }, + "main": "./dist/emo.min.cjs", + "module": "./dist/emo.mjs", + "types": "./dist/main.d.ts", + "exports": { + ".": { + "import": "./dist/emo.mjs", + "require": "./dist/emo.min.cjs" + } }, - "prepublish": "tsc", + "files": [ + "/dist" + ], "author": "synw", "license": "MIT" } \ No newline at end of file diff --git a/lang/typescript/rollup.config.js b/lang/typescript/rollup.config.js new file mode 100644 index 0000000..f6df45b --- /dev/null +++ b/lang/typescript/rollup.config.js @@ -0,0 +1,35 @@ +import resolve from '@rollup/plugin-node-resolve'; +import commonjs from '@rollup/plugin-commonjs'; +import typescript from '@rollup/plugin-typescript'; +import { terser } from 'rollup-plugin-terser'; + +//const isProduction = !process.env.ROLLUP_WATCH; + +export default { + input: 'src/main.ts', + output: [ + { + file: 'dist/emo.min.cjs', + format: 'cjs', + plugins: [terser(),] + }, + { + file: 'dist/emo.mjs', + format: 'esm' + }, + { + file: 'dist/emo.min.js', + format: 'iife', + name: '$emo', + plugins: [terser()] + }], + plugins: [ + typescript(), + resolve({ + jsnext: true, + main: true, + browser: true, + }), + commonjs(), + ], +}; \ No newline at end of file diff --git a/lang/typescript/src/index.ts b/lang/typescript/src/main.ts similarity index 100% rename from lang/typescript/src/index.ts rename to lang/typescript/src/main.ts diff --git a/lang/typescript/tsconfig.json b/lang/typescript/tsconfig.json index 60b844c..f33ee31 100644 --- a/lang/typescript/tsconfig.json +++ b/lang/typescript/tsconfig.json @@ -1,7 +1,7 @@ { "compilerOptions": { - "target": "es5", - "module": "es2015", + "target": "ES6", + "module": "ESNext", "moduleResolution": "node", "strict": true, "importHelpers": true, @@ -11,7 +11,7 @@ "sourceMap": false, "baseUrl": ".", "rootDir": "src", - "outDir": "lib", + "outDir": "dist", "declaration": true, "types": [ "node" @@ -23,7 +23,7 @@ }, "lib": [ "es6", - "ES2015", + "ESNext", "DOM" ], }, @@ -31,7 +31,7 @@ "src/**/*.ts" ], "exclude": [ - "lib", + "dist", "node_modules", "src/**/*.spec.ts" ]