@bobfrankston/extractids 1.0.13 → 1.0.15
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 -5
- package/package.json +3 -2
package/index.js
CHANGED
|
@@ -52,13 +52,11 @@ function generateTypes(ids, classes) {
|
|
|
52
52
|
const idType = ids.length > 0
|
|
53
53
|
? `export type htmlIDs = ${ids.map(id => `"${id}"`).join(' |\n')};\n`
|
|
54
54
|
: `export type htmlIDs = never;\n`;
|
|
55
|
-
const queryType =
|
|
56
|
-
? `export type queryIDs = ${ids.map(id => `"#${id}"`).join(' |\n')};\n`
|
|
57
|
-
: `export type queryIDs = never;\n`;
|
|
55
|
+
const queryType = `export type queryIDs = \`#\${htmlIDs}\`;\n`;
|
|
58
56
|
const classType = classes.length > 0
|
|
59
57
|
? `export type cssClasses = ${classes.map(cls => `"${cls}"`).join(' |\n')};\n`
|
|
60
58
|
: `export type cssClasses = never;\n`;
|
|
61
|
-
return idType
|
|
59
|
+
return `${idType}\n\n${queryType}\n\n${classType}`;
|
|
62
60
|
}
|
|
63
61
|
function updateTypesFile(specifiedHtmlFile) {
|
|
64
62
|
let htmlFile;
|
|
@@ -82,7 +80,14 @@ function updateTypesFile(specifiedHtmlFile) {
|
|
|
82
80
|
}
|
|
83
81
|
}
|
|
84
82
|
const html = fs.readFileSync(htmlFile, 'utf8');
|
|
83
|
+
if (!html || html.length < 10) {
|
|
84
|
+
console.error(`[extractids] WARNING: ${htmlFile} read returned ${html.length} bytes — possible transient read failure, skipping update`);
|
|
85
|
+
return;
|
|
86
|
+
}
|
|
85
87
|
const ids = getHtmlIDs(html);
|
|
88
|
+
if (ids.length === 0) {
|
|
89
|
+
console.warn(`[extractids] WARNING: No IDs found in ${htmlFile} (${html.length} bytes) — check file content`);
|
|
90
|
+
}
|
|
86
91
|
const cssFiles = globReadCssFiles();
|
|
87
92
|
const allClasses = new Set();
|
|
88
93
|
cssFiles.forEach(file => {
|
|
@@ -130,8 +135,12 @@ if (watchMode) {
|
|
|
130
135
|
const htmlFilesToWatch = specifiedHtmlFile
|
|
131
136
|
? [specifiedHtmlFile]
|
|
132
137
|
: ['index.html', 'default.html', 'default.htm'];
|
|
138
|
+
let debounceTimer;
|
|
133
139
|
const watcher = chokidar.watch([...htmlFilesToWatch, '**/*.css'], { ignored: /node_modules/ });
|
|
134
|
-
watcher.on('change', () =>
|
|
140
|
+
watcher.on('change', () => {
|
|
141
|
+
clearTimeout(debounceTimer);
|
|
142
|
+
debounceTimer = setTimeout(() => updateTypesFile(specifiedHtmlFile), 100);
|
|
143
|
+
});
|
|
135
144
|
watcher.on('ready', () => {
|
|
136
145
|
console.log('[extractids] Watcher is ready and running.');
|
|
137
146
|
});
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@bobfrankston/extractids",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.15",
|
|
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",
|