Skip to content

Commit 413aa1e

Browse files
committed
fix(cookbooks): move log file creation from postinstall to methods
1 parent f58b15a commit 413aa1e

File tree

4 files changed

+9
-25
lines changed

4 files changed

+9
-25
lines changed

cookbooks/portal-analytics/dev-server.config.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ export default defineDevServerConfig(() => {
2828
middleware: async (req, res) => {
2929
const body = await readBody(req);
3030
try {
31-
appendFileContents(LOG_FILE, body);
31+
await appendFileContents(LOG_FILE, body);
3232
} catch (err) {
3333
res.statusCode = 500;
3434
res.end(err);

cookbooks/portal-analytics/middleware/logs.ts

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,15 @@ import { existsSync } from 'node:fs';
33
import { resolve } from 'node:path';
44
import type { IncomingMessage } from 'node:http';
55

6+
const createLogFile = async (filePath: string): Promise<void> => {
7+
await writeFile(filePath, '', { encoding: 'utf8' });
8+
};
9+
610
export const readFileContents = async (filePath: string): Promise<string> => {
711
const absolutePath = resolve(filePath);
812
try {
913
if (!existsSync(absolutePath)) {
10-
throw new Error(`File does not exist: ${absolutePath}`);
14+
await createLogFile(absolutePath);
1115
}
1216
const data = await readFile(absolutePath, 'utf-8');
1317
return data;
@@ -38,7 +42,7 @@ export const appendFileContents = async (filePath: string, content: string): Pro
3842

3943
try {
4044
if (!existsSync(absolutePath)) {
41-
throw new Error(`File does not exist: ${absolutePath}`);
45+
await createLogFile(absolutePath);
4246
}
4347
await appendFile(absolutePath, `${content}\n`, 'utf8');
4448
} catch (error) {
@@ -54,7 +58,7 @@ export const clearFileContents = async (filePath: string): Promise<void> => {
5458

5559
try {
5660
if (!existsSync(absolutePath)) {
57-
throw new Error(`File does not exist: ${absolutePath}`);
61+
await createLogFile(absolutePath);
5862
}
5963
await writeFile(absolutePath, '', { encoding: 'utf8' });
6064
} catch (error) {

cookbooks/portal-analytics/package.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,7 @@
1010
"build": "fusion-framework-cli portal build",
1111
"schema": "fusion-framework-cli portal schema",
1212
"pack:portals": "fusion-framework-cli portal pack",
13-
"publish:portals": "fusion-framework-cli portal publish",
14-
"postinstall": "node postinstall.js"
13+
"publish:portals": "fusion-framework-cli portal publish"
1514
},
1615
"keywords": [],
1716
"author": "",

cookbooks/portal-analytics/postinstall.js

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

0 commit comments

Comments
 (0)