@bobfrankston/extractids 1.0.11 → 1.0.13

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.
@@ -4,7 +4,9 @@
4
4
  "Bash(git add:*)",
5
5
  "Bash(git commit:*)",
6
6
  "Bash(npm publish:*)",
7
- "Bash(tsc:*)"
7
+ "Bash(tsc:*)",
8
+ "Bash(node:*)",
9
+ "Bash(extractids:*)"
8
10
  ],
9
11
  "deny": [],
10
12
  "ask": []
package/index.js CHANGED
@@ -4,6 +4,7 @@ import * as fs from 'node:fs';
4
4
  import * as path from 'node:path';
5
5
  import * as cheerio from 'cheerio';
6
6
  import chokidar from 'chokidar';
7
+ import pkg from './package.json' with { type: 'json' };
7
8
  // import * as glob from 'glob';
8
9
  // Helper function to extract all id attributes from HTML
9
10
  function getHtmlIDs(html) {
@@ -94,6 +95,11 @@ function updateTypesFile(specifiedHtmlFile) {
94
95
  }
95
96
  // Parse CLI arguments for -w or --watch and optional HTML filename
96
97
  const args = process.argv.slice(2);
98
+ // Check for version flag
99
+ if (args.includes('-v') || args.includes('--version')) {
100
+ console.log(pkg.version);
101
+ process.exit(0);
102
+ }
97
103
  // Check for help flags
98
104
  if (args.includes('-h') || args.includes('-help') || args.includes('--help')) {
99
105
  console.log(`
@@ -101,6 +107,7 @@ Usage: extractids [options] [htmlfile]
101
107
 
102
108
  Options:
103
109
  -h, -help, --help Show this help message
110
+ -v, --version Show version number
104
111
  -w, -watch, --watch Watch for changes and regenerate types automatically
105
112
 
106
113
  Arguments:
package/package.json CHANGED
@@ -1,11 +1,10 @@
1
1
  {
2
2
  "name": "@bobfrankston/extractids",
3
- "version": "1.0.11",
3
+ "version": "1.0.13",
4
4
  "description": "Extracd html and css as types",
5
5
  "main": "index.js",
6
6
  "bin": {
7
- "extractids": "index.js",
8
- "generate-importmap": "generate-importmap.js"
7
+ "extractids": "index.js"
9
8
  },
10
9
  "module": "main.js",
11
10
  "scripts": {
@@ -1,85 +0,0 @@
1
- #!/usr/bin/env node
2
- /**
3
- * Generate ES Module import map from package.json dependencies
4
- * Injects into HTML files for native browser module loading
5
- */
6
-
7
- import fs from 'fs';
8
- import path from 'path';
9
- import chokidar from 'chokidar';
10
-
11
- function generateImportMap(packageJsonPath, htmlFilePath) {
12
- try {
13
- // Read package.json
14
- const packageJson = JSON.parse(fs.readFileSync(packageJsonPath, 'utf-8'));
15
- const dependencies = packageJson.dependencies || {};
16
-
17
- // Generate import map
18
- const imports = {};
19
- for (const [name, version] of Object.entries(dependencies)) {
20
- imports[name] = `./node_modules/${name}/index.js`;
21
- }
22
-
23
- const importMapScript = `<script type="importmap">
24
- ${JSON.stringify({ imports }, null, 12)}
25
- </script>`;
26
-
27
- // Read HTML file
28
- let html = fs.readFileSync(htmlFilePath, 'utf-8');
29
-
30
- // Replace import map section
31
- const importMapRegex = /<!-- Import map.*?-->|<script type="importmap">[\s\S]*?<\/script>/;
32
-
33
- if (importMapRegex.test(html)) {
34
- html = html.replace(importMapRegex, importMapScript);
35
- } else {
36
- // Insert before </head> if not found
37
- html = html.replace('</head>', ` ${importMapScript}\n</head>`);
38
- }
39
-
40
- // Write back to HTML file
41
- fs.writeFileSync(htmlFilePath, html, 'utf-8');
42
-
43
- console.log('[generate-importmap] Updated import map');
44
- console.log(' Dependencies:', Object.keys(dependencies).join(', ') || '(none)');
45
- } catch (e) {
46
- console.error('[generate-importmap] Error:', e.message);
47
- process.exit(1);
48
- }
49
- }
50
-
51
- // Parse CLI arguments
52
- const args = process.argv.slice(2);
53
- const watchMode = args.includes('-w') || args.includes('--watch');
54
- const packageJsonPath = path.join(process.cwd(), 'package.json');
55
- const htmlFilePath = path.join(process.cwd(), 'index.html');
56
-
57
- // Check if files exist
58
- if (!fs.existsSync(packageJsonPath)) {
59
- console.error('[generate-importmap] Error: package.json not found in current directory');
60
- process.exit(1);
61
- }
62
- if (!fs.existsSync(htmlFilePath)) {
63
- console.error('[generate-importmap] Error: index.html not found in current directory');
64
- process.exit(1);
65
- }
66
-
67
- if (watchMode) {
68
- generateImportMap(packageJsonPath, htmlFilePath);
69
- console.log('[generate-importmap] Watching for changes...');
70
-
71
- const watcher = chokidar.watch([packageJsonPath], {
72
- persistent: true,
73
- ignoreInitial: true
74
- });
75
-
76
- watcher.on('change', () => generateImportMap(packageJsonPath, htmlFilePath));
77
- watcher.on('ready', () => {
78
- console.log('[generate-importmap] Watcher is ready and running.');
79
- });
80
- watcher.on('error', (error) => {
81
- console.error('[generate-importmap] Watcher error:', error.message);
82
- });
83
- } else {
84
- generateImportMap(packageJsonPath, htmlFilePath);
85
- }