@xsynaptic/astro-build-logger 0.1.0 → 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.d.mts +0 -1
- package/dist/index.mjs +42 -42
- package/dist/index.mjs.map +1 -1
- package/package.json +3 -3
package/dist/index.d.mts
CHANGED
package/dist/index.mjs
CHANGED
|
@@ -9,13 +9,39 @@ const optionsSchema = z.object({
|
|
|
9
9
|
* @default `"astro-build.jsonl"`
|
|
10
10
|
*/
|
|
11
11
|
logFileName: z.string().optional() }).optional();
|
|
12
|
-
function
|
|
13
|
-
const
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
12
|
+
function buildLogger(options) {
|
|
13
|
+
const logFileName = optionsSchema.parse(options)?.logFileName ?? "astro-build.jsonl";
|
|
14
|
+
let buildStartTime;
|
|
15
|
+
return {
|
|
16
|
+
hooks: {
|
|
17
|
+
"astro:build:done": async ({ dir, logger, pages }) => {
|
|
18
|
+
const buildEndTime = Date.now();
|
|
19
|
+
const durationSeconds = Number(((buildEndTime - buildStartTime) / 1e3).toFixed(2));
|
|
20
|
+
const outputBytes = await getDirectorySize(dir);
|
|
21
|
+
const summary = formatSummary(durationSeconds, pages.length, outputBytes);
|
|
22
|
+
const entry = {
|
|
23
|
+
astroVersion: astroPackage.version,
|
|
24
|
+
durationSeconds,
|
|
25
|
+
nodeVersion: process.versions.node,
|
|
26
|
+
outputBytes,
|
|
27
|
+
pageCount: pages.length,
|
|
28
|
+
summary,
|
|
29
|
+
timestamp: new Date(buildEndTime).toISOString()
|
|
30
|
+
};
|
|
31
|
+
try {
|
|
32
|
+
await appendFile(logFileName, JSON.stringify(entry) + "\n");
|
|
33
|
+
logger.info(`Build time logged: ${summary}`);
|
|
34
|
+
} catch (error) {
|
|
35
|
+
logger.error(`Failed to write build log: ${error instanceof Error ? error.message : "unknown error"}`);
|
|
36
|
+
}
|
|
37
|
+
},
|
|
38
|
+
"astro:build:start": ({ logger }) => {
|
|
39
|
+
buildStartTime = Date.now();
|
|
40
|
+
logger.info(`Build timing started at ${new Date(buildStartTime).toISOString()}`);
|
|
41
|
+
}
|
|
42
|
+
},
|
|
43
|
+
name: "@xsynaptic/astro-build-logger"
|
|
44
|
+
};
|
|
19
45
|
}
|
|
20
46
|
function formatBytes(bytes) {
|
|
21
47
|
const units = [
|
|
@@ -30,9 +56,17 @@ function formatBytes(bytes) {
|
|
|
30
56
|
value /= 1024;
|
|
31
57
|
unitIndex += 1;
|
|
32
58
|
}
|
|
33
|
-
const precision =
|
|
59
|
+
const precision = unitIndex === 0 || value >= 10 ? 0 : 1;
|
|
34
60
|
return `${value.toFixed(precision)} ${units[unitIndex] ?? "B"}`;
|
|
35
61
|
}
|
|
62
|
+
function formatDuration(totalSeconds) {
|
|
63
|
+
const hours = Math.floor(totalSeconds / 3600);
|
|
64
|
+
const minutes = Math.floor(totalSeconds % 3600 / 60);
|
|
65
|
+
const seconds = Math.round(totalSeconds % 60);
|
|
66
|
+
if (hours > 0) return `${String(hours)}h ${String(minutes)}m ${String(seconds)}s`;
|
|
67
|
+
if (minutes > 0) return `${String(minutes)}m ${String(seconds)}s`;
|
|
68
|
+
return `${String(seconds)}s`;
|
|
69
|
+
}
|
|
36
70
|
function formatSummary(durationSeconds, pageCount, outputBytes) {
|
|
37
71
|
return `${formatDuration(durationSeconds)} (${String(pageCount)} pages, ${formatBytes(outputBytes)})`;
|
|
38
72
|
}
|
|
@@ -49,40 +83,6 @@ async function getDirectorySize(dir) {
|
|
|
49
83
|
}
|
|
50
84
|
return total;
|
|
51
85
|
}
|
|
52
|
-
function buildLogger(options) {
|
|
53
|
-
const logFileName = optionsSchema.parse(options)?.logFileName ?? "astro-build.jsonl";
|
|
54
|
-
let buildStartTime;
|
|
55
|
-
return {
|
|
56
|
-
name: "@xsynaptic/astro-build-logger",
|
|
57
|
-
hooks: {
|
|
58
|
-
"astro:build:start": ({ logger }) => {
|
|
59
|
-
buildStartTime = Date.now();
|
|
60
|
-
logger.info(`Build timing started at ${new Date(buildStartTime).toISOString()}`);
|
|
61
|
-
},
|
|
62
|
-
"astro:build:done": async ({ logger, pages, dir }) => {
|
|
63
|
-
const buildEndTime = Date.now();
|
|
64
|
-
const durationSeconds = Number(((buildEndTime - buildStartTime) / 1e3).toFixed(2));
|
|
65
|
-
const outputBytes = await getDirectorySize(dir);
|
|
66
|
-
const summary = formatSummary(durationSeconds, pages.length, outputBytes);
|
|
67
|
-
const entry = {
|
|
68
|
-
timestamp: new Date(buildEndTime).toISOString(),
|
|
69
|
-
durationSeconds,
|
|
70
|
-
pageCount: pages.length,
|
|
71
|
-
outputBytes,
|
|
72
|
-
astroVersion: astroPackage.version,
|
|
73
|
-
nodeVersion: process.versions.node,
|
|
74
|
-
summary
|
|
75
|
-
};
|
|
76
|
-
try {
|
|
77
|
-
await appendFile(logFileName, JSON.stringify(entry) + "\n");
|
|
78
|
-
logger.info(`Build time logged: ${summary}`);
|
|
79
|
-
} catch (error) {
|
|
80
|
-
logger.error(`Failed to write build log: ${error instanceof Error ? error.message : "unknown error"}`);
|
|
81
|
-
}
|
|
82
|
-
}
|
|
83
|
-
}
|
|
84
|
-
};
|
|
85
|
-
}
|
|
86
86
|
//#endregion
|
|
87
87
|
export { buildLogger as default };
|
|
88
88
|
|
package/dist/index.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.mjs","names":[],"sources":["../src/index.ts"],"sourcesContent":["import type { AstroIntegration } from 'astro';\n\nimport astroPackage from 'astro/package.json' with { type: 'json' };\nimport { appendFile, readdir, stat } from 'node:fs/promises';\nimport { z } from 'zod';\n\nconst optionsSchema = z\n\t.object({\n\t\t/**\n\t\t * Path to the JSONL log file\n\t\t *\n\t\t * @default `\"astro-build.jsonl\"`\n\t\t */\n\t\tlogFileName: z.string().optional(),\n\t})\n\t.optional();\n\
|
|
1
|
+
{"version":3,"file":"index.mjs","names":[],"sources":["../src/index.ts"],"sourcesContent":["import type { AstroIntegration } from 'astro';\n\nimport astroPackage from 'astro/package.json' with { type: 'json' };\nimport { appendFile, readdir, stat } from 'node:fs/promises';\nimport { z } from 'zod';\n\nconst optionsSchema = z\n\t.object({\n\t\t/**\n\t\t * Path to the JSONL log file\n\t\t *\n\t\t * @default `\"astro-build.jsonl\"`\n\t\t */\n\t\tlogFileName: z.string().optional(),\n\t})\n\t.optional();\n\ninterface BuildLogEntry {\n\tastroVersion: string;\n\tdurationSeconds: number;\n\tnodeVersion: string;\n\tnotes?: string;\n\toutputBytes: number;\n\tpageCount: number;\n\tsummary: string;\n\ttimestamp: string;\n}\n\ntype Options = z.input<typeof optionsSchema>;\n\nexport default function buildLogger(options?: Options): AstroIntegration {\n\tconst parsed = optionsSchema.parse(options);\n\tconst logFileName = parsed?.logFileName ?? 'astro-build.jsonl';\n\n\tlet buildStartTime: number;\n\n\treturn {\n\t\thooks: {\n\t\t\t'astro:build:done': async ({ dir, logger, pages }) => {\n\t\t\t\tconst buildEndTime = Date.now();\n\t\t\t\tconst durationSeconds = Number(((buildEndTime - buildStartTime) / 1000).toFixed(2));\n\t\t\t\tconst outputBytes = await getDirectorySize(dir);\n\t\t\t\tconst summary = formatSummary(durationSeconds, pages.length, outputBytes);\n\n\t\t\t\tconst entry: BuildLogEntry = {\n\t\t\t\t\tastroVersion: astroPackage.version,\n\t\t\t\t\tdurationSeconds,\n\t\t\t\t\tnodeVersion: process.versions.node,\n\t\t\t\t\toutputBytes,\n\t\t\t\t\tpageCount: pages.length,\n\t\t\t\t\tsummary,\n\t\t\t\t\ttimestamp: new Date(buildEndTime).toISOString(),\n\t\t\t\t};\n\n\t\t\t\ttry {\n\t\t\t\t\tawait appendFile(logFileName, JSON.stringify(entry) + '\\n');\n\t\t\t\t\tlogger.info(`Build time logged: ${summary}`);\n\t\t\t\t} catch (error) {\n\t\t\t\t\tlogger.error(\n\t\t\t\t\t\t`Failed to write build log: ${error instanceof Error ? error.message : 'unknown error'}`,\n\t\t\t\t\t);\n\t\t\t\t}\n\t\t\t},\n\t\t\t'astro:build:start': ({ logger }) => {\n\t\t\t\tbuildStartTime = Date.now();\n\t\t\t\tlogger.info(`Build timing started at ${new Date(buildStartTime).toISOString()}`);\n\t\t\t},\n\t\t},\n\t\tname: '@xsynaptic/astro-build-logger',\n\t};\n}\n\nfunction formatBytes(bytes: number): string {\n\tconst units = ['B', 'KB', 'MB', 'GB'];\n\tlet value = bytes;\n\tlet unitIndex = 0;\n\n\twhile (value >= 1024 && unitIndex < units.length - 1) {\n\t\tvalue /= 1024;\n\t\tunitIndex += 1;\n\t}\n\n\tconst precision = unitIndex === 0 || value >= 10 ? 0 : 1;\n\n\treturn `${value.toFixed(precision)} ${units[unitIndex] ?? 'B'}`;\n}\n\nfunction formatDuration(totalSeconds: number): string {\n\tconst hours = Math.floor(totalSeconds / 3600);\n\tconst minutes = Math.floor((totalSeconds % 3600) / 60);\n\tconst seconds = Math.round(totalSeconds % 60);\n\n\tif (hours > 0) return `${String(hours)}h ${String(minutes)}m ${String(seconds)}s`;\n\tif (minutes > 0) return `${String(minutes)}m ${String(seconds)}s`;\n\n\treturn `${String(seconds)}s`;\n}\n\nfunction formatSummary(durationSeconds: number, pageCount: number, outputBytes: number): string {\n\treturn `${formatDuration(durationSeconds)} (${String(pageCount)} pages, ${formatBytes(outputBytes)})`;\n}\n\nasync function getDirectorySize(dir: URL): Promise<number> {\n\tconst entries = await readdir(dir, { withFileTypes: true });\n\tlet total = 0;\n\n\tfor (const entry of entries) {\n\t\tconst child = new URL(entry.isDirectory() ? `${entry.name}/` : entry.name, dir);\n\n\t\tif (entry.isDirectory()) {\n\t\t\ttotal += await getDirectorySize(child);\n\t\t} else if (entry.isFile()) {\n\t\t\tconst stats = await stat(child);\n\t\t\ttotal += stats.size;\n\t\t}\n\t}\n\treturn total;\n}\n"],"mappings":";;;;AAMA,MAAM,gBAAgB,EACpB,OAAO;;;;;;AAMP,aAAa,EAAE,OAAO,CAAC,CAA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QAAQ,KAAK,MAAM,eAAe,IAAI;CAC5C,MAAM,UAAU,KAAK,MAAO,eAAe,OAAQ,EAAE;CACrD,MAAM,UAAU,KAAK,MAAM,eAAe,EAAE;CAE5C,IAAI,QAAQ,GAAG,OAAO,GAAG,OAAO,KAAK,EAAE,IAAI,OAAO,OAAO,EAAE,IAAI,OAAO,OAAO,EAAE;CAC/E,IAAI,UAAU,GAAG,OAAO,GAAG,OAAO,OAAO,EAAE,IAAI,OAAO,OAAO,EAAE;CAE/D,OAAO,GAAG,OAAO,OAAO,EAAE;AAC3B;AAEA,SAAS,cAAc,iBAAyB,WAAmB,aAA6B;CAC/F,OAAO,GAAG,eAAe,eAAe,EAAE,IAAI,OAAO,SAAS,EAAE,UAAU,YAAY,WAAW,EAAE;AACpG;AAEA,eAAe,iBAAiB,KAA2B;CAC1D,MAAM,UAAU,MAAM,QAAQ,KAAK,EAAE,eAAe,KAAK,CAAC;CAC1D,IAAI,QAAQ;CAEZ,KAAK,MAAM,SAAS,SAAS;EAC5B,MAAM,QAAQ,IAAI,IAAI,MAAM,YAAY,IAAI,GAAG,MAAM,KAAK,KAAK,MAAM,MAAM,GAAG;EAE9E,IAAI,MAAM,YAAY,GACrB,SAAS,MAAM,iBAAiB,KAAK;OAC/B,IAAI,MAAM,OAAO,GAAG;GAC1B,MAAM,QAAQ,MAAM,KAAK,KAAK;GAC9B,SAAS,MAAM;EAChB;CACD;CACA,OAAO;AACR"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@xsynaptic/astro-build-logger",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "1.0.0",
|
|
4
4
|
"description": "Astro integration that appends build duration, page count, and output size to a JSONL log file",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"license": "MIT",
|
|
@@ -37,10 +37,10 @@
|
|
|
37
37
|
"zod": "^4.4.3"
|
|
38
38
|
},
|
|
39
39
|
"peerDependencies": {
|
|
40
|
-
"astro": "^6.0.0"
|
|
40
|
+
"astro": "^6.0.0 || ^7.0.0"
|
|
41
41
|
},
|
|
42
42
|
"devDependencies": {
|
|
43
|
-
"astro": "^
|
|
43
|
+
"astro": "^7.1.3"
|
|
44
44
|
},
|
|
45
45
|
"scripts": {
|
|
46
46
|
"build": "tsdown",
|