Skip to content

Commit 69f4ea2

Browse files
Merge pull request #6 from bruno-sartori/develop
Changes how images are consumed to decrease package size
2 parents 3ae26da + 6aa4e44 commit 69f4ea2

File tree

10 files changed

+608
-82
lines changed

10 files changed

+608
-82
lines changed

.eslintrc.js

Lines changed: 0 additions & 23 deletions
This file was deleted.

.husky/pre-commit

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# npx lint-staged
1+
npx lint-staged
22

33
red='\033[0;31m'
44
green='\033[0;32m'

README.md

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,19 @@ Please make sure all tests pass before submiting a PR
114114

115115
![Log in DevTools](https://raw.githubusercontent.com/bruno-sartori/weeb-logger/main/docs/test.jpg)
116116

117+
## Roadmap
118+
Would love Pull requests that build towards these objectives and even ideas for new objectives :3
119+
- [x] ~~Decrease package size (As waifu images increase, we'll need to store them on a CDN or something like that)~~ Solved by using GitHub URL to the raw image LOL
120+
- [x] Configure ESLint
121+
- [ ] Tests
122+
- [ ] Resize (aparently jest-dom doesn't support getting element dimensions)
123+
- [ ] !isNode (maybe find another way to determine if environment is nodejs or browser other than ```typeof process === 'object' && `${process}\` === '[object process]')```
124+
- [ ] Add a CI pipeline that runs the tests
125+
- [ ] Add more waifus! It would be very cool if some artist drew them for us :heart_eyes:
126+
- [ ] Log levels
127+
- [ ] Increase customization options
128+
- [ ] Organize this mess I call code :laughing:
129+
117130
## Technologies used in this project
118131

119132
| Name | Description |

eslint.config.mjs

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
import globals from "globals";
2+
import pluginJs from "@eslint/js";
3+
import tseslint from "typescript-eslint";
4+
5+
6+
export default [
7+
{files: ["**/*.{js,mjs,cjs,ts}"]},
8+
{languageOptions: { globals: {...globals.browser, ...globals.node} }},
9+
pluginJs.configs.recommended,
10+
...tseslint.configs.recommended,
11+
{
12+
rules: {
13+
'@typescript-eslint/no-var-requires': 'off',
14+
'@typescript-eslint/no-explicit-any': 'off',
15+
'prefer-spread': 'off',
16+
'arrow-body-style': 'off',
17+
'prefer-const': 'off',
18+
'@typescript-eslint/ban-ts-comment': 'off',
19+
'@typescript-eslint/no-empty-function': 'off'
20+
}
21+
},
22+
];

package.json

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@bsartori/weeb-logger",
3-
"version": "1.0.16",
3+
"version": "1.1.0",
44
"author": "Bruno Sartori <brunosartori.dev@gmail.com>",
55
"license": "MIT",
66
"repository": {
@@ -14,6 +14,9 @@
1414
"dist"
1515
],
1616
"scripts": {
17+
"lint": "eslint src/**/*.ts",
18+
"format": "eslint src/**/*.ts --fix",
19+
"prebuild": "shx rm -rf dist && shx mkdir dist",
1720
"prepare-assets": "node ./scripts/generateBase64Assets.js",
1821
"build": "tsc",
1922
"prepublishOnly": "yarn build",
@@ -43,18 +46,25 @@
4346
"chalk": "4.1.2"
4447
},
4548
"devDependencies": {
46-
"shx": "^0.3.4",
47-
"copyfiles": "^2.4.1",
48-
"ts-node": "^10.9.2",
49-
"cross-env": "^7.0.3",
49+
"@eslint/js": "^9.9.1",
5050
"@types/jest": "^29.5.12",
5151
"@types/node": "^22.5.0",
52+
"copyfiles": "^2.4.1",
53+
"cross-env": "^7.0.3",
54+
"eslint": "^9.9.1",
55+
"globals": "^15.9.0",
5256
"husky": "^9.1.5",
5357
"jest": "^29.7.0",
5458
"jest-canvas-mock": "^2.5.2",
5559
"jest-environment-jsdom": "^29.7.0",
56-
"ts-jest-mock-import-meta": "1.2.0",
60+
"shx": "^0.3.4",
5761
"ts-jest": "^29.2.4",
58-
"typescript": "^5.5.4"
62+
"ts-jest-mock-import-meta": "1.2.0",
63+
"ts-node": "^10.9.2",
64+
"typescript": "^5.5.4",
65+
"typescript-eslint": "^8.3.0"
66+
},
67+
"lint-staged": {
68+
"src/*.{js,ts}": ["eslint --fix"]
5969
}
6070
}

scripts/generateBase64Assets.js

Lines changed: 0 additions & 30 deletions
This file was deleted.

src/CanvasHandler.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ class WeebLoggerCanvasHandler {
3535
let lineArray: Array<{ line: string, x: number, y: number }> = []; // This is an array of lines, which the function will return
3636

3737
// Lets iterate over each word
38-
for (var n = 0; n < words.length; n++) {
38+
for (let n = 0; n < words.length; n++) {
3939
// Create a test line, and measure it..
4040
testLine += `${words[n]} `;
4141
let metrics = this.ctx.measureText(testLine);

src/index.ts

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ import { BORDER_RADIUS, SCROLLBAR_WIDTH, WAIFU_SIZE, WAIFU_THEME } from './const
44
import WeebLoggerCanvasHandler from './CanvasHandler'
55
import { IWeebLog, IWeebLoggerConfig } from './interfaces';
66
import { IWeebRequiredLoggerConfig, LogType } from './types';
7-
import waifus from './waifus.json';
87

98
const isNode = typeof process === 'object' && `${process}` === '[object process]';
109

@@ -51,7 +50,7 @@ class WeebLogger {
5150
position: newConfig.containerStyle?.position ?? initialConfig.containerStyle.position,
5251
opacity: newConfig.containerStyle?.opacity ?? initialConfig.containerStyle.opacity,
5352
lineHeight: newConfig.containerStyle?.lineHeight ?? initialConfig.containerStyle?.lineHeight,
54-
} || {},
53+
},
5554
waifu: {
5655
showWaifu: newConfig.waifu?.showWaifu ?? initialConfig.waifu.showWaifu,
5756
name: newConfig.waifu?.name ?? initialConfig.waifu.name,
@@ -202,7 +201,7 @@ class WeebLogger {
202201
if (this.config.waifu.showWaifu) {
203202
const img = document.createElement('img');
204203
// @ts-ignore
205-
img.src = `data:image/webp;base64, ${waifus[this.config.waifu.name]}`;
204+
img.src = `https://raw.githubusercontent.com/bruno-sartori/weeb-logger/main/docs/waifus/${this.config.waifu.name}_300.webp`;
206205
img.width = parseInt(WAIFU_SIZE[this.config.waifu.size], 10);
207206
img.height = parseInt(WAIFU_SIZE[this.config.waifu.size], 10);
208207
img.id = 'weeb-logger-waifu';
@@ -211,26 +210,26 @@ class WeebLogger {
211210
}
212211

213212
switch (this.config.containerStyle.position) {
214-
case 'top-right':
213+
case 'top-right': {
215214
const resizerBottomLeft = document.createElement('div');
216215
resizerBottomLeft.className = 'resizer bottom-left';
217216
this.resizable.appendChild(resizerBottomLeft);
218-
break;
219-
case 'top-left':
217+
} break;
218+
case 'top-left': {
220219
const resizerBottomRight = document.createElement('div');
221220
resizerBottomRight.className = 'resizer bottom-right';
222221
this.resizable.appendChild(resizerBottomRight);
223-
break;
224-
case 'bottom-right':
222+
} break;
223+
case 'bottom-right': {
225224
const resizerTopLeft = document.createElement('div');
226225
resizerTopLeft.className = 'resizer top-left';
227226
this.resizable.appendChild(resizerTopLeft);
228-
break;
229-
case 'bottom-left':
227+
} break;
228+
case 'bottom-left': {
230229
const resizerTopRight = document.createElement('div');
231230
resizerTopRight.className = 'resizer top-right';
232231
this.resizable.appendChild(resizerTopRight);
233-
break;
232+
} break;
234233
}
235234

236235
const container = document.createElement('div');

src/waifus.json

Lines changed: 0 additions & 1 deletion
This file was deleted.

0 commit comments

Comments
 (0)