Skip to content

Commit

Permalink
Merge pull request #2 from teal-finance/updatejslib
Browse files Browse the repository at this point in the history
Improve typescript lib: compile with Rollup
  • Loading branch information
synw authored May 1, 2023
2 parents 605890c + be8dbd6 commit bdf5f3c
Show file tree
Hide file tree
Showing 11 changed files with 266 additions and 14 deletions.
1 change: 1 addition & 0 deletions lang/typescript/dist/emo.min.cjs
Original file line number Diff line number Diff line change
@@ -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;
1 change: 1 addition & 0 deletions lang/typescript/dist/emo.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

128 changes: 128 additions & 0 deletions lang/typescript/dist/emo.mjs
Original file line number Diff line number Diff line change
@@ -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 };
63 changes: 63 additions & 0 deletions lang/typescript/dist/emo_gen.d.ts
Original file line number Diff line number Diff line change
@@ -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<any>): string;
print(data: Array<any> | Record<string, any>): void;
static json(data: Array<any> | Record<string, any>): void;
private _getEmoString;
}
8 changes: 8 additions & 0 deletions lang/typescript/dist/interfaces.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import { EmoHook } from './types';
interface EmoParams {
zone?: string | null;
activatePrint?: boolean;
activateEmojis?: boolean;
hook?: EmoHook | null;
}
export { EmoParams };
4 changes: 4 additions & 0 deletions lang/typescript/dist/main.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
import Emo from "./emo_gen";
import { EmoHook } from "./types";
import { EmoParams } from "./interfaces";
export { Emo, EmoHook, EmoParams };
2 changes: 2 additions & 0 deletions lang/typescript/dist/types.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
declare type EmoHook = (msg: string) => void;
export { EmoHook };
28 changes: 19 additions & 9 deletions lang/typescript/package.json
Original file line number Diff line number Diff line change
@@ -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": {
Expand All @@ -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"
}
35 changes: 35 additions & 0 deletions lang/typescript/rollup.config.js
Original file line number Diff line number Diff line change
@@ -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(),
],
};
File renamed without changes.
10 changes: 5 additions & 5 deletions lang/typescript/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"compilerOptions": {
"target": "es5",
"module": "es2015",
"target": "ES6",
"module": "ESNext",
"moduleResolution": "node",
"strict": true,
"importHelpers": true,
Expand All @@ -11,7 +11,7 @@
"sourceMap": false,
"baseUrl": ".",
"rootDir": "src",
"outDir": "lib",
"outDir": "dist",
"declaration": true,
"types": [
"node"
Expand All @@ -23,15 +23,15 @@
},
"lib": [
"es6",
"ES2015",
"ESNext",
"DOM"
],
},
"include": [
"src/**/*.ts"
],
"exclude": [
"lib",
"dist",
"node_modules",
"src/**/*.spec.ts"
]
Expand Down

0 comments on commit bdf5f3c

Please sign in to comment.