astro-accelerator-utils 0.2.35 → 0.2.37
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/lib/v1/accelerator.d.mts +3 -0
- package/lib/v1/accelerator.mjs +4 -1
- package/lib/v1/cache.d.mts +3 -3
- package/lib/v1/statistics-stub.d.mts +5 -0
- package/lib/v1/statistics-stub.mjs +10 -0
- package/lib/v1/statistics.d.mts +39 -0
- package/lib/v1/statistics.mjs +6 -1
- package/package.json +1 -1
- package/types/Site.d.ts +1 -0
package/lib/v1/accelerator.d.mts
CHANGED
|
@@ -11,6 +11,7 @@ export class Accelerator {
|
|
|
11
11
|
siteUrl: string;
|
|
12
12
|
subfolder: string;
|
|
13
13
|
useTrailingUrlSlash: boolean;
|
|
14
|
+
captureStatistics: boolean;
|
|
14
15
|
get authors(): Authors;
|
|
15
16
|
get cache(): Cache;
|
|
16
17
|
get dateFormatter(): DateFormatter;
|
|
@@ -20,6 +21,7 @@ export class Accelerator {
|
|
|
20
21
|
get posts(): Posts;
|
|
21
22
|
get taxonomy(): Taxonomy;
|
|
22
23
|
get urlFormatter(): UrlFormatter;
|
|
24
|
+
get statistics(): typeof StatisticsStub;
|
|
23
25
|
}
|
|
24
26
|
export type Site = import("../../types/Site").Site;
|
|
25
27
|
import { Authors } from "./authors.mjs";
|
|
@@ -31,3 +33,4 @@ import { Paging } from "./paging.mjs";
|
|
|
31
33
|
import { Posts } from "./posts.mjs";
|
|
32
34
|
import { Taxonomy } from "./taxonomy.mjs";
|
|
33
35
|
import { UrlFormatter } from "./urls.mjs";
|
|
36
|
+
import { StatisticsStub } from "./statistics-stub.mjs";
|
package/lib/v1/accelerator.mjs
CHANGED
|
@@ -8,6 +8,7 @@ import { Posts } from './posts.mjs';
|
|
|
8
8
|
import { Taxonomy } from './taxonomy.mjs';
|
|
9
9
|
import { UrlFormatter } from './urls.mjs';
|
|
10
10
|
import { Statistics } from './statistics.mjs';
|
|
11
|
+
import { StatisticsStub } from './statistics-stub.mjs';
|
|
11
12
|
|
|
12
13
|
/**
|
|
13
14
|
* @typedef { import("../../types/Site").Site } Site
|
|
@@ -63,6 +64,8 @@ export class Accelerator {
|
|
|
63
64
|
}
|
|
64
65
|
|
|
65
66
|
get statistics() {
|
|
66
|
-
return
|
|
67
|
+
return (this.captureStatistics)
|
|
68
|
+
? Statistics
|
|
69
|
+
: StatisticsStub;
|
|
67
70
|
}
|
|
68
71
|
}
|
package/lib/v1/cache.d.mts
CHANGED
|
@@ -30,9 +30,9 @@ export class Cache {
|
|
|
30
30
|
*/
|
|
31
31
|
clear(): Promise<void>;
|
|
32
32
|
/**
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
33
|
+
* Get's the path of the cache files
|
|
34
|
+
* @returns {string}
|
|
35
|
+
*/
|
|
36
36
|
getCachePath(): string;
|
|
37
37
|
/**
|
|
38
38
|
* Gets the file path for a cache item
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
export class Statistics {
|
|
2
|
+
/**
|
|
3
|
+
* Clears the stats file
|
|
4
|
+
*/
|
|
5
|
+
static purge(): void;
|
|
6
|
+
/**
|
|
7
|
+
* Get's the path of the log files
|
|
8
|
+
* @returns {string}
|
|
9
|
+
*/
|
|
10
|
+
static getLogPath(): string;
|
|
11
|
+
/**
|
|
12
|
+
* Gets the file path for a log item
|
|
13
|
+
* @returns {string}
|
|
14
|
+
*/
|
|
15
|
+
static getItemPath(): string;
|
|
16
|
+
/**
|
|
17
|
+
* Creates a new stats instance - all instances append to the stats file
|
|
18
|
+
* Use Statistics.purge() to reset the file
|
|
19
|
+
* After creating a timer, use start() and stop() to record an event
|
|
20
|
+
* @param {string} operation
|
|
21
|
+
*/
|
|
22
|
+
constructor(operation: string);
|
|
23
|
+
operation: string;
|
|
24
|
+
/**
|
|
25
|
+
* Gets high resolution time in ms
|
|
26
|
+
* @returns number
|
|
27
|
+
*/
|
|
28
|
+
getMilliseconds(): number;
|
|
29
|
+
/**
|
|
30
|
+
* Start the timer
|
|
31
|
+
*/
|
|
32
|
+
start(): void;
|
|
33
|
+
/**
|
|
34
|
+
* Stop the timer (logs to .logs/statistics.csv)
|
|
35
|
+
*/
|
|
36
|
+
stop(): void;
|
|
37
|
+
end: number;
|
|
38
|
+
duration: number;
|
|
39
|
+
}
|
package/lib/v1/statistics.mjs
CHANGED
|
@@ -50,7 +50,12 @@ export class Statistics {
|
|
|
50
50
|
this.duration = this.end - this.start;
|
|
51
51
|
|
|
52
52
|
const path = Statistics.getItemPath();
|
|
53
|
-
|
|
53
|
+
|
|
54
|
+
if (!fs.existsSync(path)) {
|
|
55
|
+
Statistics.purge();
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
fs.appendFileSync(path, `"${this.operation}",${new Date().toJSON()},${Math.round(this.duration)}${EOL}`);
|
|
54
59
|
}
|
|
55
60
|
|
|
56
61
|
/**
|
package/package.json
CHANGED