Skip to content

Commit eb8cb72

Browse files
iqbalhasandevgithub-actions[bot]
authored andcommitted
style: fix code formatting [skip ci]
1 parent 3b5b4d7 commit eb8cb72

File tree

10 files changed

+4190
-4157
lines changed

10 files changed

+4190
-4157
lines changed

README.md

Lines changed: 31 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -38,18 +38,18 @@ This plugin is package-manager agnostic and works with npm, pnpm, or yarn. The r
3838
Add the plugin to your `vite.config.ts`:
3939

4040
```ts
41-
import { defineConfig } from 'vite';
42-
import laravel from 'laravel-vite-plugin';
43-
import enumify from '@devwizard/vite-plugin-enumify';
41+
import { defineConfig } from "vite";
42+
import laravel from "laravel-vite-plugin";
43+
import enumify from "@devwizard/vite-plugin-enumify";
4444

4545
export default defineConfig({
46-
plugins: [
47-
enumify(),
48-
laravel({
49-
input: ['resources/js/app.ts'],
50-
refresh: true,
51-
}),
52-
],
46+
plugins: [
47+
enumify(),
48+
laravel({
49+
input: ["resources/js/app.ts"],
50+
refresh: true,
51+
}),
52+
],
5353
});
5454
```
5555

@@ -63,23 +63,23 @@ export default defineConfig({
6363

6464
```ts
6565
enumify({
66-
// PHP binary path (default: "php")
67-
artisanBin: 'php',
66+
// PHP binary path (default: "php")
67+
artisanBin: "php",
6868

69-
// Path to the artisan file (default: "artisan")
70-
artisanFile: 'artisan',
69+
// Path to the artisan file (default: "artisan")
70+
artisanFile: "artisan",
7171

72-
// Command to run (default: "enumify:sync")
73-
syncCommand: 'enumify:sync',
72+
// Command to run (default: "enumify:sync")
73+
syncCommand: "enumify:sync",
7474

75-
// Working directory (default: process.cwd())
76-
cwd: process.cwd(),
75+
// Working directory (default: process.cwd())
76+
cwd: process.cwd(),
7777

78-
// Enable watch mode in development (default: runtime.watch from config/enumify.php)
79-
watch: true,
78+
// Enable watch mode in development (default: runtime.watch from config/enumify.php)
79+
watch: true,
8080

81-
// Additional environment variables
82-
env: {},
81+
// Additional environment variables
82+
env: {},
8383
});
8484
```
8585

@@ -122,23 +122,23 @@ The plugin generates:
122122
```ts
123123
// resources/js/enums/order-status.ts
124124
export enum OrderStatus {
125-
Pending = 'pending',
126-
Processing = 'processing',
127-
Shipped = 'shipped',
125+
Pending = "pending",
126+
Processing = "processing",
127+
Shipped = "shipped",
128128
}
129129

130130
export type OrderStatusValue = `${OrderStatus}`;
131131

132132
export const OrderStatusLabels: Record<OrderStatus, string> = {
133-
[OrderStatus.Pending]: 'Pending',
134-
[OrderStatus.Processing]: 'Processing',
135-
[OrderStatus.Shipped]: 'Shipped',
133+
[OrderStatus.Pending]: "Pending",
134+
[OrderStatus.Processing]: "Processing",
135+
[OrderStatus.Shipped]: "Shipped",
136136
};
137137

138138
export const OrderStatusColors: Record<OrderStatus, string> = {
139-
[OrderStatus.Pending]: 'yellow',
140-
[OrderStatus.Processing]: 'blue',
141-
[OrderStatus.Shipped]: 'green',
139+
[OrderStatus.Pending]: "yellow",
140+
[OrderStatus.Processing]: "blue",
141+
[OrderStatus.Shipped]: "green",
142142
};
143143
```
144144

__tests__/vite-plugin.test.ts

Lines changed: 131 additions & 125 deletions
Original file line numberDiff line numberDiff line change
@@ -1,85 +1,85 @@
1-
import { spawn } from 'child_process';
2-
import fs from 'fs';
3-
import os from 'os';
4-
import path from 'path';
5-
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest';
6-
import { enumify } from '../src/vite-plugin-enumify';
7-
8-
vi.mock('child_process', () => ({
9-
spawn: vi.fn(),
1+
import { spawn } from "child_process";
2+
import fs from "fs";
3+
import os from "os";
4+
import path from "path";
5+
import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
6+
import { enumify } from "../src/vite-plugin-enumify";
7+
8+
vi.mock("child_process", () => ({
9+
spawn: vi.fn(),
1010
}));
1111

1212
const spawnMock = spawn as unknown as ReturnType<typeof vi.fn>;
1313

1414
function createTempProject(): string {
15-
const tempDir = fs.mkdtempSync(path.join(os.tmpdir(), 'enumify-'));
16-
fs.mkdirSync(path.join(tempDir, 'config'), { recursive: true });
17-
return tempDir;
15+
const tempDir = fs.mkdtempSync(path.join(os.tmpdir(), "enumify-"));
16+
fs.mkdirSync(path.join(tempDir, "config"), { recursive: true });
17+
return tempDir;
1818
}
1919

2020
function writeEnumifyConfig(cwd: string, contents: string): void {
21-
fs.writeFileSync(path.join(cwd, 'config', 'enumify.php'), contents, 'utf8');
21+
fs.writeFileSync(path.join(cwd, "config", "enumify.php"), contents, "utf8");
2222
}
2323

2424
function createLogger() {
25-
return {
26-
info: vi.fn(),
27-
warn: vi.fn(),
28-
error: vi.fn(),
29-
hasWarned: false,
30-
hasErrorLogged: false,
31-
clearScreen: vi.fn(),
32-
};
25+
return {
26+
info: vi.fn(),
27+
warn: vi.fn(),
28+
error: vi.fn(),
29+
hasWarned: false,
30+
hasErrorLogged: false,
31+
clearScreen: vi.fn(),
32+
};
3333
}
3434

3535
function mockSpawnExit(code = 0) {
36-
spawnMock.mockImplementation(() => ({
37-
on(event: string, handler: (value?: unknown) => void) {
38-
if (event === 'close') {
39-
handler(code);
40-
}
41-
if (event === 'error' && code !== 0) {
42-
handler(new Error('spawn error'));
43-
}
44-
return this;
45-
},
46-
}));
36+
spawnMock.mockImplementation(() => ({
37+
on(event: string, handler: (value?: unknown) => void) {
38+
if (event === "close") {
39+
handler(code);
40+
}
41+
if (event === "error" && code !== 0) {
42+
handler(new Error("spawn error"));
43+
}
44+
return this;
45+
},
46+
}));
4747
}
4848

49-
describe('vite-plugin-enumify', () => {
50-
beforeEach(() => {
51-
spawnMock.mockReset();
52-
mockSpawnExit(0);
53-
});
54-
55-
afterEach(() => {
56-
vi.useRealTimers();
57-
});
58-
59-
it('runs enum sync on build with defaults', async () => {
60-
const cwd = createTempProject();
61-
const plugin = enumify({ cwd });
62-
const logger = createLogger();
63-
64-
plugin.configResolved?.({ command: 'build', logger } as any);
65-
await plugin.buildStart?.call({ error: vi.fn() });
66-
67-
expect(spawnMock).toHaveBeenCalledTimes(1);
68-
expect(spawnMock).toHaveBeenCalledWith(
69-
'php',
70-
['artisan', 'enumify:sync', '--force', '--quiet'],
71-
expect.objectContaining({
72-
cwd,
73-
stdio: 'inherit',
74-
}),
75-
);
76-
});
77-
78-
it('respects configured enum paths for watching', () => {
79-
const cwd = createTempProject();
80-
writeEnumifyConfig(
81-
cwd,
82-
`<?php
49+
describe("vite-plugin-enumify", () => {
50+
beforeEach(() => {
51+
spawnMock.mockReset();
52+
mockSpawnExit(0);
53+
});
54+
55+
afterEach(() => {
56+
vi.useRealTimers();
57+
});
58+
59+
it("runs enum sync on build with defaults", async () => {
60+
const cwd = createTempProject();
61+
const plugin = enumify({ cwd });
62+
const logger = createLogger();
63+
64+
plugin.configResolved?.({ command: "build", logger } as any);
65+
await plugin.buildStart?.call({ error: vi.fn() });
66+
67+
expect(spawnMock).toHaveBeenCalledTimes(1);
68+
expect(spawnMock).toHaveBeenCalledWith(
69+
"php",
70+
["artisan", "enumify:sync", "--force", "--quiet"],
71+
expect.objectContaining({
72+
cwd,
73+
stdio: "inherit",
74+
}),
75+
);
76+
});
77+
78+
it("respects configured enum paths for watching", () => {
79+
const cwd = createTempProject();
80+
writeEnumifyConfig(
81+
cwd,
82+
`<?php
8383
return [
8484
'paths' => [
8585
'enums' => ['app/Enums', 'domain/Enums'],
@@ -90,51 +90,55 @@ return [
9090
],
9191
];
9292
`,
93-
);
94-
95-
const plugin = enumify({ cwd });
96-
const logger = createLogger();
97-
const watcher = { add: vi.fn() };
98-
99-
plugin.configResolved?.({ command: 'serve', logger } as any);
100-
plugin.configureServer?.({ watcher } as any);
101-
102-
expect(watcher.add).toHaveBeenCalledWith(path.join(cwd, 'app/Enums'));
103-
expect(watcher.add).toHaveBeenCalledWith(path.join(cwd, 'domain/Enums'));
104-
});
105-
106-
it('ignores changes in output directory', () => {
107-
vi.useFakeTimers();
108-
const cwd = createTempProject();
109-
const plugin = enumify({ cwd });
110-
const logger = createLogger();
111-
112-
plugin.configResolved?.({ command: 'serve', logger } as any);
113-
plugin.handleHotUpdate?.({ file: path.join(cwd, 'resources/js/enums/Status.ts') } as any);
114-
115-
vi.advanceTimersByTime(300);
116-
expect(spawnMock).not.toHaveBeenCalled();
117-
});
118-
119-
it('triggers sync on enum changes when watching', () => {
120-
vi.useFakeTimers();
121-
const cwd = createTempProject();
122-
const plugin = enumify({ cwd });
123-
const logger = createLogger();
124-
125-
plugin.configResolved?.({ command: 'serve', logger } as any);
126-
plugin.handleHotUpdate?.({ file: path.join(cwd, 'app/Enums/Status.php') } as any);
127-
128-
vi.advanceTimersByTime(300);
129-
expect(spawnMock).toHaveBeenCalledTimes(1);
130-
});
131-
132-
it('does not watch when runtime.watch is false', () => {
133-
vi.useFakeTimers();
134-
const cwd = createTempProject();
135-
writeEnumifyConfig(
136-
cwd,
137-
`<?php
93+
);
94+
95+
const plugin = enumify({ cwd });
96+
const logger = createLogger();
97+
const watcher = { add: vi.fn() };
98+
99+
plugin.configResolved?.({ command: "serve", logger } as any);
100+
plugin.configureServer?.({ watcher } as any);
101+
102+
expect(watcher.add).toHaveBeenCalledWith(path.join(cwd, "app/Enums"));
103+
expect(watcher.add).toHaveBeenCalledWith(path.join(cwd, "domain/Enums"));
104+
});
105+
106+
it("ignores changes in output directory", () => {
107+
vi.useFakeTimers();
108+
const cwd = createTempProject();
109+
const plugin = enumify({ cwd });
110+
const logger = createLogger();
111+
112+
plugin.configResolved?.({ command: "serve", logger } as any);
113+
plugin.handleHotUpdate?.({
114+
file: path.join(cwd, "resources/js/enums/Status.ts"),
115+
} as any);
116+
117+
vi.advanceTimersByTime(300);
118+
expect(spawnMock).not.toHaveBeenCalled();
119+
});
120+
121+
it("triggers sync on enum changes when watching", () => {
122+
vi.useFakeTimers();
123+
const cwd = createTempProject();
124+
const plugin = enumify({ cwd });
125+
const logger = createLogger();
126+
127+
plugin.configResolved?.({ command: "serve", logger } as any);
128+
plugin.handleHotUpdate?.({
129+
file: path.join(cwd, "app/Enums/Status.php"),
130+
} as any);
131+
132+
vi.advanceTimersByTime(300);
133+
expect(spawnMock).toHaveBeenCalledTimes(1);
134+
});
135+
136+
it("does not watch when runtime.watch is false", () => {
137+
vi.useFakeTimers();
138+
const cwd = createTempProject();
139+
writeEnumifyConfig(
140+
cwd,
141+
`<?php
138142
return [
139143
'paths' => [
140144
'enums' => ['app/Enums'],
@@ -145,18 +149,20 @@ return [
145149
],
146150
];
147151
`,
148-
);
149-
150-
const plugin = enumify({ cwd });
151-
const logger = createLogger();
152-
const watcher = { add: vi.fn() };
153-
154-
plugin.configResolved?.({ command: 'serve', logger } as any);
155-
plugin.configureServer?.({ watcher } as any);
156-
plugin.handleHotUpdate?.({ file: path.join(cwd, 'app/Enums/Status.php') } as any);
157-
158-
vi.advanceTimersByTime(300);
159-
expect(watcher.add).not.toHaveBeenCalled();
160-
expect(spawnMock).not.toHaveBeenCalled();
161-
});
152+
);
153+
154+
const plugin = enumify({ cwd });
155+
const logger = createLogger();
156+
const watcher = { add: vi.fn() };
157+
158+
plugin.configResolved?.({ command: "serve", logger } as any);
159+
plugin.configureServer?.({ watcher } as any);
160+
plugin.handleHotUpdate?.({
161+
file: path.join(cwd, "app/Enums/Status.php"),
162+
} as any);
163+
164+
vi.advanceTimersByTime(300);
165+
expect(watcher.add).not.toHaveBeenCalled();
166+
expect(spawnMock).not.toHaveBeenCalled();
167+
});
162168
});

0 commit comments

Comments
 (0)