@larkiny/astro-github-loader 0.11.2 → 0.12.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/README.md +69 -61
- package/dist/github.assets.d.ts +70 -0
- package/dist/github.assets.js +253 -0
- package/dist/github.auth.js +13 -9
- package/dist/github.cleanup.d.ts +3 -2
- package/dist/github.cleanup.js +30 -23
- package/dist/github.constants.d.ts +0 -16
- package/dist/github.constants.js +0 -16
- package/dist/github.content.d.ts +6 -132
- package/dist/github.content.js +154 -789
- package/dist/github.dryrun.d.ts +9 -5
- package/dist/github.dryrun.js +46 -25
- package/dist/github.link-transform.d.ts +2 -2
- package/dist/github.link-transform.js +65 -57
- package/dist/github.loader.js +45 -51
- package/dist/github.logger.d.ts +2 -2
- package/dist/github.logger.js +33 -24
- package/dist/github.paths.d.ts +76 -0
- package/dist/github.paths.js +190 -0
- package/dist/github.storage.d.ts +15 -0
- package/dist/github.storage.js +109 -0
- package/dist/github.types.d.ts +41 -4
- package/dist/index.d.ts +8 -6
- package/dist/index.js +3 -6
- package/dist/test-helpers.d.ts +130 -0
- package/dist/test-helpers.js +194 -0
- package/package.json +3 -1
- package/src/github.assets.spec.ts +717 -0
- package/src/github.assets.ts +365 -0
- package/src/github.auth.spec.ts +245 -0
- package/src/github.auth.ts +24 -10
- package/src/github.cleanup.spec.ts +380 -0
- package/src/github.cleanup.ts +91 -47
- package/src/github.constants.ts +0 -17
- package/src/github.content.spec.ts +305 -454
- package/src/github.content.ts +261 -950
- package/src/github.dryrun.spec.ts +586 -0
- package/src/github.dryrun.ts +105 -54
- package/src/github.link-transform.spec.ts +1345 -0
- package/src/github.link-transform.ts +174 -95
- package/src/github.loader.spec.ts +75 -50
- package/src/github.loader.ts +113 -78
- package/src/github.logger.spec.ts +795 -0
- package/src/github.logger.ts +77 -35
- package/src/github.paths.spec.ts +523 -0
- package/src/github.paths.ts +259 -0
- package/src/github.storage.spec.ts +367 -0
- package/src/github.storage.ts +127 -0
- package/src/github.types.ts +55 -9
- package/src/index.ts +43 -6
- package/src/test-helpers.ts +215 -0
package/src/github.logger.ts
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
* Multi-level logging system for astro-github-loader
|
|
3
3
|
*/
|
|
4
4
|
|
|
5
|
-
export type LogLevel =
|
|
5
|
+
export type LogLevel = "silent" | "default" | "verbose" | "debug";
|
|
6
6
|
|
|
7
7
|
export interface LoggerOptions {
|
|
8
8
|
level: LogLevel;
|
|
@@ -19,7 +19,7 @@ export interface ImportSummary {
|
|
|
19
19
|
assetsDownloaded?: number;
|
|
20
20
|
assetsCached?: number;
|
|
21
21
|
duration: number;
|
|
22
|
-
status:
|
|
22
|
+
status: "success" | "error" | "cancelled";
|
|
23
23
|
error?: string;
|
|
24
24
|
}
|
|
25
25
|
|
|
@@ -43,13 +43,13 @@ export class Logger {
|
|
|
43
43
|
private level: LogLevel;
|
|
44
44
|
private prefix: string;
|
|
45
45
|
private spinnerInterval?: NodeJS.Timeout;
|
|
46
|
-
private spinnerChars = [
|
|
46
|
+
private spinnerChars = ["⠋", "⠙", "⠹", "⠸", "⠼", "⠴", "⠦", "⠧", "⠇", "⠏"];
|
|
47
47
|
private spinnerIndex = 0;
|
|
48
48
|
private spinnerStartTime?: number;
|
|
49
49
|
|
|
50
50
|
constructor(options: LoggerOptions) {
|
|
51
51
|
this.level = options.level;
|
|
52
|
-
this.prefix = options.prefix ||
|
|
52
|
+
this.prefix = options.prefix || "";
|
|
53
53
|
}
|
|
54
54
|
|
|
55
55
|
/**
|
|
@@ -98,7 +98,7 @@ export class Logger {
|
|
|
98
98
|
* Default level - summary information only
|
|
99
99
|
*/
|
|
100
100
|
info(message: string): void {
|
|
101
|
-
if (this.shouldLog(
|
|
101
|
+
if (this.shouldLog("default")) {
|
|
102
102
|
console.log(this.formatMessage(message));
|
|
103
103
|
}
|
|
104
104
|
}
|
|
@@ -107,7 +107,7 @@ export class Logger {
|
|
|
107
107
|
* Verbose level - detailed operation information
|
|
108
108
|
*/
|
|
109
109
|
verbose(message: string): void {
|
|
110
|
-
if (this.shouldLog(
|
|
110
|
+
if (this.shouldLog("verbose")) {
|
|
111
111
|
console.log(this.formatMessage(message));
|
|
112
112
|
}
|
|
113
113
|
}
|
|
@@ -116,7 +116,7 @@ export class Logger {
|
|
|
116
116
|
* Debug level - all information including diagnostics
|
|
117
117
|
*/
|
|
118
118
|
debug(message: string): void {
|
|
119
|
-
if (this.shouldLog(
|
|
119
|
+
if (this.shouldLog("debug")) {
|
|
120
120
|
console.log(this.formatMessage(message));
|
|
121
121
|
}
|
|
122
122
|
}
|
|
@@ -125,7 +125,7 @@ export class Logger {
|
|
|
125
125
|
* Error - always shown unless silent
|
|
126
126
|
*/
|
|
127
127
|
error(message: string): void {
|
|
128
|
-
if (this.shouldLog(
|
|
128
|
+
if (this.shouldLog("default")) {
|
|
129
129
|
console.error(this.formatMessage(message));
|
|
130
130
|
}
|
|
131
131
|
}
|
|
@@ -134,7 +134,7 @@ export class Logger {
|
|
|
134
134
|
* Warning - shown at default level and above
|
|
135
135
|
*/
|
|
136
136
|
warn(message: string): void {
|
|
137
|
-
if (this.shouldLog(
|
|
137
|
+
if (this.shouldLog("default")) {
|
|
138
138
|
console.warn(this.formatMessage(message));
|
|
139
139
|
}
|
|
140
140
|
}
|
|
@@ -143,34 +143,50 @@ export class Logger {
|
|
|
143
143
|
* Log structured import summary (default level)
|
|
144
144
|
*/
|
|
145
145
|
logImportSummary(summary: ImportSummary): void {
|
|
146
|
-
if (!this.shouldLog(
|
|
146
|
+
if (!this.shouldLog("default")) return;
|
|
147
147
|
|
|
148
|
-
const statusIcon =
|
|
148
|
+
const statusIcon =
|
|
149
|
+
summary.status === "success"
|
|
150
|
+
? "✅"
|
|
151
|
+
: summary.status === "error"
|
|
152
|
+
? "❌"
|
|
153
|
+
: "🚫";
|
|
149
154
|
|
|
150
|
-
this.info(
|
|
155
|
+
this.info("");
|
|
151
156
|
this.info(`📊 Import Summary: ${summary.configName}`);
|
|
152
|
-
this.info(
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
157
|
+
this.info(
|
|
158
|
+
`├─ Repository: ${summary.repository}${summary.ref ? `@${summary.ref}` : ""}`,
|
|
159
|
+
);
|
|
160
|
+
this.info(
|
|
161
|
+
`├─ Files: ${summary.filesProcessed} processed, ${summary.filesUpdated} updated, ${summary.filesUnchanged} unchanged`,
|
|
162
|
+
);
|
|
163
|
+
|
|
164
|
+
if (
|
|
165
|
+
summary.assetsDownloaded !== undefined ||
|
|
166
|
+
summary.assetsCached !== undefined
|
|
167
|
+
) {
|
|
156
168
|
const downloaded = summary.assetsDownloaded || 0;
|
|
157
169
|
const cached = summary.assetsCached || 0;
|
|
158
170
|
this.info(`├─ Assets: ${downloaded} downloaded, ${cached} cached`);
|
|
159
171
|
}
|
|
160
172
|
|
|
161
173
|
this.info(`├─ Duration: ${(summary.duration / 1000).toFixed(1)}s`);
|
|
162
|
-
this.info(
|
|
163
|
-
|
|
174
|
+
this.info(
|
|
175
|
+
`└─ Status: ${statusIcon} ${summary.status === "success" ? "Success" : summary.status === "error" ? `Error: ${summary.error}` : "Cancelled"}`,
|
|
176
|
+
);
|
|
177
|
+
this.info("");
|
|
164
178
|
}
|
|
165
179
|
|
|
166
180
|
/**
|
|
167
181
|
* Log sync operation summary (default level)
|
|
168
182
|
*/
|
|
169
183
|
logSyncSummary(configName: string, summary: SyncSummary): void {
|
|
170
|
-
if (!this.shouldLog(
|
|
184
|
+
if (!this.shouldLog("default")) return;
|
|
171
185
|
|
|
172
186
|
if (summary.added > 0 || summary.updated > 0 || summary.deleted > 0) {
|
|
173
|
-
this.info(
|
|
187
|
+
this.info(
|
|
188
|
+
`Sync completed for ${configName}: ${summary.added} added, ${summary.updated} updated, ${summary.deleted} deleted (${summary.duration}ms)`,
|
|
189
|
+
);
|
|
174
190
|
} else {
|
|
175
191
|
this.info(`No changes needed for ${configName} (${summary.duration}ms)`);
|
|
176
192
|
}
|
|
@@ -180,10 +196,12 @@ export class Logger {
|
|
|
180
196
|
* Log cleanup operation summary (default level)
|
|
181
197
|
*/
|
|
182
198
|
logCleanupSummary(configName: string, summary: CleanupSummary): void {
|
|
183
|
-
if (!this.shouldLog(
|
|
199
|
+
if (!this.shouldLog("default")) return;
|
|
184
200
|
|
|
185
201
|
if (summary.deleted > 0) {
|
|
186
|
-
this.info(
|
|
202
|
+
this.info(
|
|
203
|
+
`Cleanup completed for ${configName}: ${summary.deleted} obsolete files deleted (${summary.duration}ms)`,
|
|
204
|
+
);
|
|
187
205
|
} else {
|
|
188
206
|
this.debug(`No cleanup needed for ${configName} (${summary.duration}ms)`);
|
|
189
207
|
}
|
|
@@ -193,15 +211,23 @@ export class Logger {
|
|
|
193
211
|
* Log file-level processing (verbose level)
|
|
194
212
|
*/
|
|
195
213
|
logFileProcessing(action: string, filePath: string, details?: string): void {
|
|
196
|
-
const message = details
|
|
214
|
+
const message = details
|
|
215
|
+
? `${action}: ${filePath} - ${details}`
|
|
216
|
+
: `${action}: ${filePath}`;
|
|
197
217
|
this.verbose(message);
|
|
198
218
|
}
|
|
199
219
|
|
|
200
220
|
/**
|
|
201
221
|
* Log asset processing (verbose level)
|
|
202
222
|
*/
|
|
203
|
-
logAssetProcessing(
|
|
204
|
-
|
|
223
|
+
logAssetProcessing(
|
|
224
|
+
action: string,
|
|
225
|
+
assetPath: string,
|
|
226
|
+
details?: string,
|
|
227
|
+
): void {
|
|
228
|
+
const message = details
|
|
229
|
+
? `Asset ${action}: ${assetPath} - ${details}`
|
|
230
|
+
: `Asset ${action}: ${assetPath}`;
|
|
205
231
|
this.verbose(message);
|
|
206
232
|
}
|
|
207
233
|
|
|
@@ -254,8 +280,8 @@ export class Logger {
|
|
|
254
280
|
/**
|
|
255
281
|
* Start a spinner with duration timer for long-running operations
|
|
256
282
|
*/
|
|
257
|
-
startSpinner(message: string =
|
|
258
|
-
if (this.level ===
|
|
283
|
+
startSpinner(message: string = "Processing..."): void {
|
|
284
|
+
if (this.level === "silent") return;
|
|
259
285
|
|
|
260
286
|
this.spinnerStartTime = Date.now();
|
|
261
287
|
this.spinnerIndex = 0;
|
|
@@ -264,7 +290,9 @@ export class Logger {
|
|
|
264
290
|
const elapsed = Math.floor((Date.now() - this.spinnerStartTime!) / 1000);
|
|
265
291
|
const spinner = this.spinnerChars[this.spinnerIndex];
|
|
266
292
|
const duration = this.formatDuration(elapsed);
|
|
267
|
-
const formattedMessage = this.formatMessage(
|
|
293
|
+
const formattedMessage = this.formatMessage(
|
|
294
|
+
`${message} ${spinner} (${duration})`,
|
|
295
|
+
);
|
|
268
296
|
process.stdout.write(`\r${formattedMessage}`);
|
|
269
297
|
this.spinnerIndex = (this.spinnerIndex + 1) % this.spinnerChars.length;
|
|
270
298
|
};
|
|
@@ -288,13 +316,15 @@ export class Logger {
|
|
|
288
316
|
if (finalMessage && this.spinnerStartTime) {
|
|
289
317
|
const totalTime = Math.floor((Date.now() - this.spinnerStartTime) / 1000);
|
|
290
318
|
const duration = this.formatDuration(totalTime);
|
|
291
|
-
const formattedMessage = this.formatMessage(
|
|
319
|
+
const formattedMessage = this.formatMessage(
|
|
320
|
+
`${finalMessage} (${duration})`,
|
|
321
|
+
);
|
|
292
322
|
process.stdout.write(`\r${formattedMessage}\n`);
|
|
293
323
|
} else if (finalMessage) {
|
|
294
324
|
const formattedMessage = this.formatMessage(finalMessage);
|
|
295
325
|
process.stdout.write(`\r${formattedMessage}\n`);
|
|
296
326
|
} else {
|
|
297
|
-
process.stdout.write(
|
|
327
|
+
process.stdout.write("\r\x1b[K"); // Clear the line
|
|
298
328
|
}
|
|
299
329
|
|
|
300
330
|
this.spinnerStartTime = undefined;
|
|
@@ -303,14 +333,23 @@ export class Logger {
|
|
|
303
333
|
/**
|
|
304
334
|
* Execute a function with spinner feedback
|
|
305
335
|
*/
|
|
306
|
-
async withSpinner<T>(
|
|
336
|
+
async withSpinner<T>(
|
|
337
|
+
message: string,
|
|
338
|
+
fn: () => Promise<T>,
|
|
339
|
+
successMessage?: string,
|
|
340
|
+
errorMessage?: string,
|
|
341
|
+
): Promise<T> {
|
|
307
342
|
this.startSpinner(message);
|
|
308
343
|
try {
|
|
309
344
|
const result = await fn();
|
|
310
|
-
this.stopSpinner(
|
|
345
|
+
this.stopSpinner(
|
|
346
|
+
successMessage || `✅ ${message.replace(/^[🔄⏳]?\s*/, "")} completed`,
|
|
347
|
+
);
|
|
311
348
|
return result;
|
|
312
349
|
} catch (error) {
|
|
313
|
-
this.stopSpinner(
|
|
350
|
+
this.stopSpinner(
|
|
351
|
+
errorMessage || `❌ ${message.replace(/^[🔄⏳]?\s*/, "")} failed`,
|
|
352
|
+
);
|
|
314
353
|
throw error;
|
|
315
354
|
}
|
|
316
355
|
}
|
|
@@ -319,6 +358,9 @@ export class Logger {
|
|
|
319
358
|
/**
|
|
320
359
|
* Create a logger instance with the specified level
|
|
321
360
|
*/
|
|
322
|
-
export function createLogger(
|
|
361
|
+
export function createLogger(
|
|
362
|
+
level: LogLevel = "default",
|
|
363
|
+
prefix?: string,
|
|
364
|
+
): Logger {
|
|
323
365
|
return new Logger({ level, prefix });
|
|
324
|
-
}
|
|
366
|
+
}
|