vimd 0.1.4 → 0.1.6

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.
@@ -1 +1 @@
1
- {"version":3,"file":"dev.d.ts","sourceRoot":"","sources":["../../../src/cli/commands/dev.ts"],"names":[],"mappings":"AAWA,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,CAoGf"}
1
+ {"version":3,"file":"dev.d.ts","sourceRoot":"","sources":["../../../src/cli/commands/dev.ts"],"names":[],"mappings":"AAWA,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,CAwGf"}
@@ -33,10 +33,11 @@ export async function devCommand(filePath, options) {
33
33
  Logger.error(`File not found: ${filePath}`);
34
34
  process.exit(1);
35
35
  }
36
- // 4. Prepare output directory (not starting with '.' to avoid live-server ignore)
37
- const outputDir = path.join(process.cwd(), 'vimd-preview');
38
- await fs.ensureDir(outputDir);
39
- const htmlPath = path.join(outputDir, path.basename(filePath, path.extname(filePath)) + '.html');
36
+ // 4. Prepare output HTML in source directory
37
+ const sourceDir = path.dirname(absolutePath);
38
+ const basename = path.basename(filePath, path.extname(filePath));
39
+ const htmlFileName = `vimd-preview-${basename}.html`;
40
+ const htmlPath = path.join(sourceDir, htmlFileName);
40
41
  // 5. Prepare converter
41
42
  const converter = new MarkdownConverter({
42
43
  theme: config.theme,
@@ -49,12 +50,12 @@ export async function devCommand(filePath, options) {
49
50
  const html = await converter.convertWithTemplate(absolutePath);
50
51
  await converter.writeHTML(html, htmlPath);
51
52
  Logger.success('Conversion complete');
52
- // 7. Start live server
53
+ // 7. Start live server from source directory
53
54
  const server = new LiveServer({
54
55
  port: config.port,
55
56
  host: config.host,
56
57
  open: config.open,
57
- root: outputDir,
58
+ root: sourceDir,
58
59
  });
59
60
  await server.start(htmlPath);
60
61
  Logger.info(`Watching: ${filePath}`);
@@ -76,12 +77,19 @@ export async function devCommand(filePath, options) {
76
77
  }
77
78
  });
78
79
  watcher.start();
79
- // 9. Register cleanup
80
+ // 9. Register cleanup - remove generated HTML file
80
81
  ProcessManager.onExit(async () => {
81
82
  Logger.info('Shutting down...');
82
83
  await watcher.stop();
83
84
  await server.stop();
84
- await fs.remove(outputDir);
85
+ // Remove the generated preview HTML file
86
+ try {
87
+ await fs.remove(htmlPath);
88
+ Logger.info(`Removed: ${htmlFileName}`);
89
+ }
90
+ catch {
91
+ // Ignore errors when removing file
92
+ }
85
93
  Logger.info('Cleanup complete');
86
94
  });
87
95
  }
@@ -10,7 +10,7 @@ export const DEFAULT_CONFIG = {
10
10
  },
11
11
  watch: {
12
12
  ignored: ['node_modules/**', '.git/**', 'dist/**'],
13
- debounce: 500,
13
+ debounce: 100,
14
14
  },
15
15
  build: {
16
16
  inlineCSS: false,
@@ -17,7 +17,7 @@ export class LiveServer {
17
17
  root: root,
18
18
  file: file,
19
19
  open: false, // manually open
20
- wait: 100,
20
+ wait: 50,
21
21
  logLevel: 0, // silent
22
22
  watch: [root], // explicitly watch the root directory
23
23
  };
@@ -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
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "vimd",
3
- "version": "0.1.4",
3
+ "version": "0.1.6",
4
4
  "description": "Real-time Markdown preview tool with pandoc (view markdown)",
5
5
  "type": "module",
6
6
  "keywords": [