@bobfrankston/extractids 1.0.15 → 1.0.17
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/.claude/settings.local.json +2 -1
- package/index.js +14 -8
- package/package.json +1 -1
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,18 +78,18 @@ 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(
|
|
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');
|
|
83
86
|
if (!html || html.length < 10) {
|
|
84
|
-
console.error(`[extractids] WARNING: ${htmlFile} read returned ${html.length} bytes — possible transient read failure, skipping update`);
|
|
87
|
+
console.error(`[extractids ${timestamp()}] WARNING: ${htmlFile} read returned ${html.length} bytes — possible transient read failure, skipping update`);
|
|
85
88
|
return;
|
|
86
89
|
}
|
|
87
90
|
const ids = getHtmlIDs(html);
|
|
88
91
|
if (ids.length === 0) {
|
|
89
|
-
console.warn(`[extractids] WARNING: No IDs found in ${htmlFile} (${html.length} bytes) — check file content`);
|
|
92
|
+
console.warn(`[extractids ${timestamp()}] WARNING: No IDs found in ${htmlFile} (${html.length} bytes) — check file content`);
|
|
90
93
|
}
|
|
91
94
|
const cssFiles = globReadCssFiles();
|
|
92
95
|
const allClasses = new Set();
|
|
@@ -95,8 +98,11 @@ function updateTypesFile(specifiedHtmlFile) {
|
|
|
95
98
|
getCssClasses(css).forEach(cls => allClasses.add(cls));
|
|
96
99
|
});
|
|
97
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;
|
|
98
104
|
fs.writeFileSync('generated-types.ts', types);
|
|
99
|
-
console.log(
|
|
105
|
+
console.log(`[extractids ${timestamp()}] Updated generated-types.ts`);
|
|
100
106
|
}
|
|
101
107
|
// Parse CLI arguments for -w or --watch and optional HTML filename
|
|
102
108
|
const args = process.argv.slice(2);
|
|
@@ -131,7 +137,7 @@ const watchMode = args.includes('-w') || args.includes('-watch') || args.include
|
|
|
131
137
|
const specifiedHtmlFile = args.find(arg => !arg.startsWith('-'));
|
|
132
138
|
if (watchMode) {
|
|
133
139
|
updateTypesFile(specifiedHtmlFile);
|
|
134
|
-
console.log(
|
|
140
|
+
console.log(`[extractids ${timestamp()}] Watching for changes...`);
|
|
135
141
|
const htmlFilesToWatch = specifiedHtmlFile
|
|
136
142
|
? [specifiedHtmlFile]
|
|
137
143
|
: ['index.html', 'default.html', 'default.htm'];
|
|
@@ -142,10 +148,10 @@ if (watchMode) {
|
|
|
142
148
|
debounceTimer = setTimeout(() => updateTypesFile(specifiedHtmlFile), 100);
|
|
143
149
|
});
|
|
144
150
|
watcher.on('ready', () => {
|
|
145
|
-
console.log(
|
|
151
|
+
console.log(`[extractids ${timestamp()}] Watcher is ready and running.`);
|
|
146
152
|
});
|
|
147
153
|
watcher.on('error', (error) => {
|
|
148
|
-
console.error(
|
|
154
|
+
console.error(`[extractids ${timestamp()}] Watcher error:`, error.message);
|
|
149
155
|
});
|
|
150
156
|
// No need for setInterval; watcher should keep process alive
|
|
151
157
|
}
|