vimd 0.1.3 → 0.1.5
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/cli/commands/dev.d.ts.map +1 -1
- package/dist/cli/commands/dev.js +4 -4
- package/dist/core/server.d.ts.map +1 -1
- package/dist/core/server.js +2 -1
- package/dist/utils/temp-manager.d.ts +24 -0
- package/dist/utils/temp-manager.d.ts.map +1 -0
- package/dist/utils/temp-manager.js +90 -0
- package/package.json +1 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"dev.d.ts","sourceRoot":"","sources":["../../../src/cli/commands/dev.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"dev.d.ts","sourceRoot":"","sources":["../../../src/cli/commands/dev.ts"],"names":[],"mappings":"AAYA,UAAU,UAAU;IAClB,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,IAAI,CAAC,EAAE,OAAO,CAAC;CAChB;AAED,wBAAsB,UAAU,CAC9B,QAAQ,EAAE,MAAM,EAChB,OAAO,EAAE,UAAU,GAClB,OAAO,CAAC,IAAI,CAAC,CAmGf"}
|
package/dist/cli/commands/dev.js
CHANGED
|
@@ -6,6 +6,7 @@ import { LiveServer } from '../../core/server.js';
|
|
|
6
6
|
import { PandocDetector } from '../../core/pandoc-detector.js';
|
|
7
7
|
import { Logger } from '../../utils/logger.js';
|
|
8
8
|
import { ProcessManager } from '../../utils/process-manager.js';
|
|
9
|
+
import { TempManager } from '../../utils/temp-manager.js';
|
|
9
10
|
import * as path from 'path';
|
|
10
11
|
import fs from 'fs-extra';
|
|
11
12
|
export async function devCommand(filePath, options) {
|
|
@@ -33,9 +34,8 @@ export async function devCommand(filePath, options) {
|
|
|
33
34
|
Logger.error(`File not found: ${filePath}`);
|
|
34
35
|
process.exit(1);
|
|
35
36
|
}
|
|
36
|
-
// 4. Prepare output directory
|
|
37
|
-
const outputDir =
|
|
38
|
-
await fs.ensureDir(outputDir);
|
|
37
|
+
// 4. Prepare output directory in system temp
|
|
38
|
+
const outputDir = await TempManager.createSessionDir();
|
|
39
39
|
const htmlPath = path.join(outputDir, path.basename(filePath, path.extname(filePath)) + '.html');
|
|
40
40
|
// 5. Prepare converter
|
|
41
41
|
const converter = new MarkdownConverter({
|
|
@@ -81,7 +81,7 @@ export async function devCommand(filePath, options) {
|
|
|
81
81
|
Logger.info('Shutting down...');
|
|
82
82
|
await watcher.stop();
|
|
83
83
|
await server.stop();
|
|
84
|
-
await
|
|
84
|
+
await TempManager.removeSessionDir(outputDir);
|
|
85
85
|
Logger.info('Cleanup complete');
|
|
86
86
|
});
|
|
87
87
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"server.d.ts","sourceRoot":"","sources":["../../src/core/server.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAKlD,qBAAa,UAAU;IAGT,OAAO,CAAC,MAAM;IAF1B,OAAO,CAAC,OAAO,CAAS;gBAEJ,MAAM,EAAE,YAAY;IAElC,KAAK,CAAC,QAAQ,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;
|
|
1
|
+
{"version":3,"file":"server.d.ts","sourceRoot":"","sources":["../../src/core/server.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAKlD,qBAAa,UAAU;IAGT,OAAO,CAAC,MAAM;IAF1B,OAAO,CAAC,OAAO,CAAS;gBAEJ,MAAM,EAAE,YAAY;IAElC,KAAK,CAAC,QAAQ,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IA+BtC,IAAI,IAAI,OAAO,CAAC,IAAI,CAAC;IAUrB,WAAW,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAS7C,MAAM,IAAI,MAAM;CAGjB"}
|
package/dist/core/server.js
CHANGED
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
export declare class TempManager {
|
|
2
|
+
static readonly BASE_DIR = "vimd";
|
|
3
|
+
static readonly SESSION_PREFIX = "session-";
|
|
4
|
+
static readonly MAX_AGE_MS: number;
|
|
5
|
+
/**
|
|
6
|
+
* Get the base directory for vimd temp files
|
|
7
|
+
*/
|
|
8
|
+
static getBaseDir(): string;
|
|
9
|
+
/**
|
|
10
|
+
* Create a unique session directory
|
|
11
|
+
* @returns The path to the created session directory
|
|
12
|
+
*/
|
|
13
|
+
static createSessionDir(): Promise<string>;
|
|
14
|
+
/**
|
|
15
|
+
* Clean up sessions older than MAX_AGE_MS
|
|
16
|
+
*/
|
|
17
|
+
static cleanupOldSessions(): Promise<void>;
|
|
18
|
+
/**
|
|
19
|
+
* Remove a specific session directory
|
|
20
|
+
* @param sessionDir The path to the session directory to remove
|
|
21
|
+
*/
|
|
22
|
+
static removeSessionDir(sessionDir: string): Promise<void>;
|
|
23
|
+
}
|
|
24
|
+
//# sourceMappingURL=temp-manager.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"temp-manager.d.ts","sourceRoot":"","sources":["../../src/utils/temp-manager.ts"],"names":[],"mappings":"AAMA,qBAAa,WAAW;IACtB,MAAM,CAAC,QAAQ,CAAC,QAAQ,UAAU;IAClC,MAAM,CAAC,QAAQ,CAAC,cAAc,cAAc;IAC5C,MAAM,CAAC,QAAQ,CAAC,UAAU,SAAuB;IAEjD;;OAEG;IACH,MAAM,CAAC,UAAU,IAAI,MAAM;IAI3B;;;OAGG;WACU,gBAAgB,IAAI,OAAO,CAAC,MAAM,CAAC;IAgBhD;;OAEG;WACU,kBAAkB,IAAI,OAAO,CAAC,IAAI,CAAC;IAwChD;;;OAGG;WACU,gBAAgB,CAAC,UAAU,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;CAiBjE"}
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
// src/utils/temp-manager.ts
|
|
2
|
+
import * as os from 'os';
|
|
3
|
+
import * as path from 'path';
|
|
4
|
+
import fs from 'fs-extra';
|
|
5
|
+
import { Logger } from './logger.js';
|
|
6
|
+
export class TempManager {
|
|
7
|
+
/**
|
|
8
|
+
* Get the base directory for vimd temp files
|
|
9
|
+
*/
|
|
10
|
+
static getBaseDir() {
|
|
11
|
+
return path.join(os.tmpdir(), this.BASE_DIR);
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* Create a unique session directory
|
|
15
|
+
* @returns The path to the created session directory
|
|
16
|
+
*/
|
|
17
|
+
static async createSessionDir() {
|
|
18
|
+
const baseDir = this.getBaseDir();
|
|
19
|
+
await fs.ensureDir(baseDir);
|
|
20
|
+
// Clean up old sessions before creating a new one
|
|
21
|
+
await this.cleanupOldSessions();
|
|
22
|
+
const timestamp = Date.now();
|
|
23
|
+
const randomId = Math.random().toString(36).substring(2, 8);
|
|
24
|
+
const sessionName = `${this.SESSION_PREFIX}${timestamp}-${randomId}`;
|
|
25
|
+
const sessionDir = path.join(baseDir, sessionName);
|
|
26
|
+
await fs.ensureDir(sessionDir);
|
|
27
|
+
return sessionDir;
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* Clean up sessions older than MAX_AGE_MS
|
|
31
|
+
*/
|
|
32
|
+
static async cleanupOldSessions() {
|
|
33
|
+
const baseDir = this.getBaseDir();
|
|
34
|
+
if (!(await fs.pathExists(baseDir))) {
|
|
35
|
+
return;
|
|
36
|
+
}
|
|
37
|
+
try {
|
|
38
|
+
const entries = await fs.readdir(baseDir, { withFileTypes: true });
|
|
39
|
+
const now = Date.now();
|
|
40
|
+
for (const entry of entries) {
|
|
41
|
+
if (!entry.isDirectory() || !entry.name.startsWith(this.SESSION_PREFIX)) {
|
|
42
|
+
continue;
|
|
43
|
+
}
|
|
44
|
+
// Extract timestamp from session name
|
|
45
|
+
const match = entry.name.match(/^session-(\d+)-/);
|
|
46
|
+
if (!match) {
|
|
47
|
+
continue;
|
|
48
|
+
}
|
|
49
|
+
const sessionTimestamp = parseInt(match[1], 10);
|
|
50
|
+
const age = now - sessionTimestamp;
|
|
51
|
+
if (age > this.MAX_AGE_MS) {
|
|
52
|
+
const sessionPath = path.join(baseDir, entry.name);
|
|
53
|
+
try {
|
|
54
|
+
await fs.remove(sessionPath);
|
|
55
|
+
Logger.info(`Cleaned up old session: ${entry.name}`);
|
|
56
|
+
}
|
|
57
|
+
catch {
|
|
58
|
+
// Ignore errors when cleaning up individual sessions
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
catch {
|
|
64
|
+
// Ignore errors when listing directory
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
/**
|
|
68
|
+
* Remove a specific session directory
|
|
69
|
+
* @param sessionDir The path to the session directory to remove
|
|
70
|
+
*/
|
|
71
|
+
static async removeSessionDir(sessionDir) {
|
|
72
|
+
if (!sessionDir) {
|
|
73
|
+
return;
|
|
74
|
+
}
|
|
75
|
+
// Verify the directory is within our base directory
|
|
76
|
+
const baseDir = this.getBaseDir();
|
|
77
|
+
if (!sessionDir.startsWith(baseDir)) {
|
|
78
|
+
return;
|
|
79
|
+
}
|
|
80
|
+
try {
|
|
81
|
+
await fs.remove(sessionDir);
|
|
82
|
+
}
|
|
83
|
+
catch {
|
|
84
|
+
// Ignore errors when removing session directory
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
TempManager.BASE_DIR = 'vimd';
|
|
89
|
+
TempManager.SESSION_PREFIX = 'session-';
|
|
90
|
+
TempManager.MAX_AGE_MS = 24 * 60 * 60 * 1000; // 24 hours
|