@bobfrankston/extractids 1.0.14 → 1.0.16

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.
@@ -6,7 +6,8 @@
6
6
  "Bash(npm publish:*)",
7
7
  "Bash(tsc:*)",
8
8
  "Bash(node:*)",
9
- "Bash(extractids:*)"
9
+ "Bash(extractids:*)",
10
+ "Bash(npmglobalize)"
10
11
  ],
11
12
  "deny": [],
12
13
  "ask": []
package/index.js CHANGED
@@ -6,6 +6,9 @@ import * as cheerio from 'cheerio';
6
6
  import chokidar from 'chokidar';
7
7
  import pkg from './package.json' with { type: 'json' };
8
8
  // import * as glob from 'glob';
9
+ function timestamp() {
10
+ return new Date().toLocaleTimeString();
11
+ }
9
12
  // Helper function to extract all id attributes from HTML
10
13
  function getHtmlIDs(html) {
11
14
  const $ = cheerio.load(html);
@@ -66,7 +69,7 @@ function updateTypesFile(specifiedHtmlFile) {
66
69
  htmlFile = specifiedHtmlFile;
67
70
  }
68
71
  else {
69
- console.error(`[extractids] Specified HTML file not found: ${specifiedHtmlFile}`);
72
+ console.error(`[extractids ${timestamp()}] Specified HTML file not found: ${specifiedHtmlFile}`);
70
73
  return;
71
74
  }
72
75
  }
@@ -75,12 +78,19 @@ function updateTypesFile(specifiedHtmlFile) {
75
78
  const possibleHtmlFiles = ['index.html', 'default.html', 'default.htm'];
76
79
  htmlFile = possibleHtmlFiles.find(file => fs.existsSync(file));
77
80
  if (!htmlFile) {
78
- console.error('[extractids] No HTML file found. Looking for:', possibleHtmlFiles.join(', '));
81
+ console.error(`[extractids ${timestamp()}] No HTML file found. Looking for:`, possibleHtmlFiles.join(', '));
79
82
  return;
80
83
  }
81
84
  }
82
85
  const html = fs.readFileSync(htmlFile, 'utf8');
86
+ if (!html || html.length < 10) {
87
+ console.error(`[extractids ${timestamp()}] WARNING: ${htmlFile} read returned ${html.length} bytes — possible transient read failure, skipping update`);
88
+ return;
89
+ }
83
90
  const ids = getHtmlIDs(html);
91
+ if (ids.length === 0) {
92
+ console.warn(`[extractids ${timestamp()}] WARNING: No IDs found in ${htmlFile} (${html.length} bytes) — check file content`);
93
+ }
84
94
  const cssFiles = globReadCssFiles();
85
95
  const allClasses = new Set();
86
96
  cssFiles.forEach(file => {
@@ -88,8 +98,11 @@ function updateTypesFile(specifiedHtmlFile) {
88
98
  getCssClasses(css).forEach(cls => allClasses.add(cls));
89
99
  });
90
100
  const types = generateTypes(ids, Array.from(allClasses));
101
+ const existing = fs.existsSync('generated-types.ts') ? fs.readFileSync('generated-types.ts', 'utf8') : '';
102
+ if (types === existing)
103
+ return;
91
104
  fs.writeFileSync('generated-types.ts', types);
92
- console.log('[Type generation] Updated generated-types.ts');
105
+ console.log(`[extractids ${timestamp()}] Updated generated-types.ts`);
93
106
  }
94
107
  // Parse CLI arguments for -w or --watch and optional HTML filename
95
108
  const args = process.argv.slice(2);
@@ -124,20 +137,25 @@ const watchMode = args.includes('-w') || args.includes('-watch') || args.include
124
137
  const specifiedHtmlFile = args.find(arg => !arg.startsWith('-'));
125
138
  if (watchMode) {
126
139
  updateTypesFile(specifiedHtmlFile);
127
- console.log('[extractids] Watching for changes...');
140
+ console.log(`[extractids ${timestamp()}] Watching for changes...`);
128
141
  const htmlFilesToWatch = specifiedHtmlFile
129
142
  ? [specifiedHtmlFile]
130
143
  : ['index.html', 'default.html', 'default.htm'];
144
+ let debounceTimer;
131
145
  const watcher = chokidar.watch([...htmlFilesToWatch, '**/*.css'], { ignored: /node_modules/ });
132
- watcher.on('change', () => updateTypesFile(specifiedHtmlFile));
146
+ watcher.on('change', () => {
147
+ clearTimeout(debounceTimer);
148
+ debounceTimer = setTimeout(() => updateTypesFile(specifiedHtmlFile), 100);
149
+ });
133
150
  watcher.on('ready', () => {
134
- console.log('[extractids] Watcher is ready and running.');
151
+ console.log(`[extractids ${timestamp()}] Watcher is ready and running.`);
135
152
  });
136
153
  watcher.on('error', (error) => {
137
- console.error('[extractids] Watcher error:', error.message);
154
+ console.error(`[extractids ${timestamp()}] Watcher error:`, error.message);
138
155
  });
139
156
  // No need for setInterval; watcher should keep process alive
140
157
  }
141
158
  else {
142
159
  updateTypesFile(specifiedHtmlFile);
143
160
  }
161
+ //# sourceMappingURL=index.js.map
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bobfrankston/extractids",
3
- "version": "1.0.14",
3
+ "version": "1.0.16",
4
4
  "description": "Extracd html and css as types",
5
5
  "main": "index.js",
6
6
  "bin": {
@@ -8,7 +8,8 @@
8
8
  },
9
9
  "module": "main.js",
10
10
  "scripts": {
11
- "test": "echo \"Error: no test specified\" && exit 1"
11
+ "test": "echo \"Error: no test specified\" && exit 1",
12
+ "release": "npmglobalize"
12
13
  },
13
14
  "keywords": [],
14
15
  "author": "Bob Frankston",