Skip to content

Commit a27d2a9

Browse files
authored
Merge pull request #12 from jycouet/feat/vite-add-kind-of-watch
Feat/vite add kind of watch
2 parents 60f2690 + 73474d8 commit a27d2a9

File tree

15 files changed

+303
-111
lines changed

15 files changed

+303
-111
lines changed

.changeset/fair-jars-cross.md

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@kitql/vite-plugin-watch-and-run': patch
3+
---
4+
5+
new option to watch only ADD / CHANGE / DELETE

.changeset/wild-cameras-doubt.md

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@kitql/helper': patch
3+
---
4+
5+
Adding new options for logging (formats)

.github/workflows/release.yml

+3
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,9 @@ jobs:
3737
- name: Install Dependencies
3838
run: yarn
3939

40+
- name: Bump versions
41+
run: yarn release:prepareVersion
42+
4043
- name: Create Release Pull Request or Publish to npm
4144
id: changesets
4245
uses: changesets/action@v1

README.md

+3-2
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,13 @@
1515

1616
[![Release](https://github.com/jycouet/kitql/actions/workflows/release.yml/badge.svg)](https://github.com/jycouet/kitql/actions/workflows/release.yml)
1717
[![Tests](https://github.com/jycouet/kitql/actions/workflows/ci.yml/badge.svg)](https://github.com/jycouet/kitql/actions/workflows/ci.yml)
18-
![check-code-coverage](https://img.shields.io/badge/code--coverage-78.88%25-yellow)
18+
![check-code-coverage](https://img.shields.io/badge/code--coverage-82.35%25-green)
1919

2020
| | Coverage by package |
2121
| ------------------------------------------------------------------------------------------------------------------ | ---------------------------------------------------------------------------------------------------------------------------: |
2222
| [KitQL - graphql-codegen](https://github.com/jycouet/kitql/tree/main/packages/graphql-codegen) | ![check-code-coverage-graphql-codegen](https://img.shields.io/badge/graphql--codegen-100.0%25-success) |
23-
| [KitQL - vite-plugin-watch-and-run](https://github.com/jycouet/kitql/tree/main/packages/vite-plugin-watch-and-run) | ![check-code-coverage-vite-plugin-watch-and-run](https://img.shields.io/badge/vite--plugin--watch--and--run-54.76%25-yellow) |
23+
| [KitQL - helper](https://github.com/jycouet/kitql/tree/main/packages/helper) | ![check-code-coverage-helper](https://img.shields.io/badge/helper-100.0%25-success) |
24+
| [KitQL - vite-plugin-watch-and-run](https://github.com/jycouet/kitql/tree/main/packages/vite-plugin-watch-and-run) | ![check-code-coverage-vite-plugin-watch-and-run](https://img.shields.io/badge/vite--plugin--watch--and--run-57.66%25-yellow) |
2425

2526
# ⚡How to start?
2627

package.json

+3-1
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,13 @@
66
"license": "MIT",
77
"scripts": {
88
"dev": "yarn build && yarn workspace @kitql/template dev",
9-
"test": "vitest",
9+
"test": "vitest --coverage",
1010
"test:ci": "vitest run --coverage",
1111
"test:update-badge": "yarn update-badge",
1212
"prebuild": "rimraf packages/*/dist",
1313
"build": "tsc --project tsconfig.json && bob build",
14+
"release:prepareMsg": "yarn changeset",
15+
"release:prepareVersion": "yarn changeset version",
1416
"release": "yarn build && changeset publish",
1517
"reset": "git clean -xdf",
1618
"update": "npm exec --workspaces -- npx ncu -u -p yarn"

packages/client/src/kitQLClient.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ export class KitQLClient {
8888
this.credentials = credentials;
8989
this.headersContentType = options.headersContentType ?? 'application/graphql+json';
9090
this.logType = options.logType ?? [];
91-
this.log = new Log('KitQL Client');
91+
this.log = new Log('KitQL Client', { withTime: false });
9292
}
9393

9494
private logOperation(

packages/helper/src/Log.ts

+22-17
Original file line numberDiff line numberDiff line change
@@ -1,36 +1,41 @@
1-
import pino, { type Logger } from 'pino';
1+
import pino from 'pino';
2+
import PinoPretty from 'pino-pretty';
23

3-
export function logGreen(str) {
4+
export function logGreen(str: string) {
45
return `\x1b[32m${str}\x1b[37m\x1b[0m`;
56
}
67

7-
export function logMagneta(str) {
8+
export function logMagneta(str: string) {
89
return `\x1b[35m${str}\x1b[37m\x1b[0m`;
910
}
1011

11-
export function logRed(str) {
12+
export function logRed(str: string) {
1213
return `\u001B[31m${str}\x1b[37m\x1b[0m`;
1314
}
1415

15-
export function logCyan(str) {
16+
export function logCyan(str: string) {
1617
return `\x1b[36m${str}\x1b[37m\x1b[0m`;
1718
}
1819

20+
export type Options = {
21+
sync?: boolean | null;
22+
withTime?: boolean | null;
23+
withlevelKey?: boolean | null;
24+
};
1925
export class Log {
20-
private toolName: String;
21-
private logger: Logger;
26+
private toolName: string;
27+
private logger: any;
2228

23-
constructor(toolName: String) {
29+
constructor(toolName: string, options: Options | null = null) {
30+
const { sync = false, withTime = false, withlevelKey = true } = options ?? {};
2431
this.toolName = toolName;
25-
26-
this.logger = pino({
27-
transport: {
28-
target: 'pino-pretty',
29-
options: {
30-
colorize: true
31-
}
32-
}
33-
});
32+
this.logger = pino(
33+
PinoPretty({
34+
sync,
35+
translateTime: withTime ? true : false,
36+
ignore: `pid,hostname${withTime ? '' : ',time'}${withlevelKey ? '' : ',level'}`
37+
})
38+
);
3439
}
3540

3641
info(msg: string) {

packages/helper/test/Log.spec.ts

+75
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
import { afterEach, describe, expect, it, vi } from 'vitest';
2+
import { Log, logCyan, logGreen, logMagneta, logRed } from '../src/Log';
3+
4+
describe('kitql - helper - Log', () => {
5+
afterEach(() => {
6+
vi.restoreAllMocks();
7+
});
8+
9+
it('Minimal config', async () => {
10+
let log = new Log('tool name');
11+
expect(log).to.have.property('toolName', 'tool name');
12+
13+
const spy = vi.spyOn(log, 'info');
14+
log.info('Minimal config');
15+
expect(spy).toHaveBeenCalledOnce();
16+
});
17+
18+
it('Config with sync', async () => {
19+
let log = new Log('tool name', { sync: true });
20+
expect(log).to.have.property('toolName', 'tool name');
21+
22+
const spy = vi.spyOn(log, 'info');
23+
log.info('Config with sync');
24+
expect(spy).toHaveBeenCalledOnce();
25+
});
26+
27+
it('Config without sync', async () => {
28+
let log = new Log('tool name', { sync: false });
29+
expect(log).to.have.property('toolName', 'tool name');
30+
31+
const spy = vi.spyOn(log, 'info');
32+
log.info('Config without sync');
33+
expect(spy).toHaveBeenCalledOnce();
34+
});
35+
36+
it('Config with time', async () => {
37+
let log = new Log('tool name', { withTime: true });
38+
expect(log).to.have.property('toolName', 'tool name');
39+
40+
const spy = vi.spyOn(log, 'info');
41+
log.info('Config with time');
42+
expect(spy).toHaveBeenCalledOnce();
43+
});
44+
45+
it('Config with withlevelKey: false, should not print level', async () => {
46+
let log = new Log('tool name', { withlevelKey: false, sync: true });
47+
expect(log).to.have.property('toolName', 'tool name');
48+
49+
const spy = vi.spyOn(log, 'info');
50+
log.info('Config with key level');
51+
expect(spy).toHaveBeenCalledOnce();
52+
});
53+
54+
it('with an error', async () => {
55+
let log = new Log('tool name');
56+
expect(log).to.have.property('toolName', 'tool name');
57+
58+
const spy = vi.spyOn(log, 'error');
59+
log.error('with an error');
60+
expect(spy).toHaveBeenCalledOnce();
61+
});
62+
63+
it('with all colors', async () => {
64+
let log = new Log('tool name');
65+
expect(log).to.have.property('toolName', 'tool name');
66+
67+
const spy = vi.spyOn(log, 'info');
68+
log.info(
69+
`with all colors: ${logGreen('green')}, ${logMagneta('magneta')}, ${logRed('red')}, ${logCyan(
70+
'cyan'
71+
)}, `
72+
);
73+
expect(spy).toHaveBeenCalledOnce();
74+
});
75+
});

packages/helper/test/plugins.spec.ts

Whitespace-only changes.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
import { afterEach, describe, expect, it, vi } from 'vitest';
2+
import { queryStringApprend } from '../src/queryStringApprend';
3+
4+
describe('kitql - helper - queryStringApprend', () => {
5+
it('with empty searchParams', async () => {
6+
let searchParams = new URLSearchParams();
7+
let qs = queryStringApprend(searchParams, { focus: 'Hello' });
8+
expect(qs).toMatchInlineSnapshot('"focus=Hello"');
9+
});
10+
11+
it('with default searchParams', async () => {
12+
let searchParams = new URLSearchParams();
13+
searchParams.set('page', '7');
14+
let qs = queryStringApprend(searchParams, { focus: 'Hello' });
15+
expect(qs).toMatchInlineSnapshot('"focus=Hello&page=7"');
16+
});
17+
18+
it('check sorting qs', async () => {
19+
let searchParams = new URLSearchParams();
20+
searchParams.set('page', '7');
21+
let qs = queryStringApprend(searchParams, { focus: 'Hello', sort: 'bestFirst' });
22+
expect(qs).toMatchInlineSnapshot('"focus=Hello&page=7&sort=bestFirst"');
23+
});
24+
});

packages/module-codegen/src/index.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import { actionTypeDefs } from './actionTypeDefs';
1313
import { actionContext } from './actionContexts';
1414
import { actionModules } from './actionModules';
1515

16-
let log = new Log('KitQL module-codegen');
16+
let log = new Log('KitQL module-codegen', { sync: true, withlevelKey: false });
1717

1818
const configFilePath = getFullPath('.kitql.yaml');
1919

packages/vite-plugin-watch-and-run/package.json

+1
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
"tslib": "2.3.1"
1818
},
1919
"dependencies": {
20+
"@kitql/helper": "0.1.1",
2021
"micromatch": "4.0.4"
2122
},
2223
"main": "dist/index.js",

0 commit comments

Comments
 (0)