@bobfrankston/extractids 1.0.19 → 1.0.21

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.
Files changed (2) hide show
  1. package/index.js +19 -4
  2. package/package.json +1 -1
package/index.js CHANGED
@@ -59,9 +59,21 @@ function generateTypes(ids, classes) {
59
59
  const classType = classes.length > 0
60
60
  ? `export type cssClasses = ${classes.map(cls => `"${cls}"`).join(' |\n')};\n`
61
61
  : `export type cssClasses = never;\n`;
62
- return `${idType}\n\n${queryType}\n\n${classType}`;
62
+ const now = new Date();
63
+ const localTime = now.toLocaleString();
64
+ const header = `// AUTO-GENERATED FILE — DO NOT EDIT\n// Generated by extractids on ${localTime}\n// Any manual changes will be overwritten on the next run.\n\n`;
65
+ return `${header}${idType}\n\n${queryType}\n\n${classType}`;
63
66
  }
64
67
  const sleep = (ms) => new Promise(resolve => setTimeout(resolve, ms));
68
+ /** Strip the auto-generated header (first 4 lines) so we compare only the type content */
69
+ function stripHeader(content) {
70
+ const lines = content.split('\n');
71
+ // Skip lines starting with "// " at the top, plus the blank line after
72
+ let i = 0;
73
+ while (i < lines.length && (lines[i].startsWith('//') || lines[i] === ''))
74
+ i++;
75
+ return lines.slice(i).join('\n');
76
+ }
65
77
  async function updateTypesFile(specifiedHtmlFile) {
66
78
  let htmlFile;
67
79
  if (specifiedHtmlFile) {
@@ -111,10 +123,13 @@ async function updateTypesFile(specifiedHtmlFile) {
111
123
  });
112
124
  const types = generateTypes(ids, Array.from(allClasses));
113
125
  const existing = fs.existsSync('generated-types.ts') ? fs.readFileSync('generated-types.ts', 'utf8') : '';
114
- if (types === existing)
126
+ // Compare only the type content, ignoring the timestamp header
127
+ if (stripHeader(types) === stripHeader(existing)) {
128
+ console.log(`[extractids ${timestamp()}] No type changes detected`);
115
129
  return;
130
+ }
116
131
  fs.writeFileSync('generated-types.ts', types);
117
- console.log(`[extractids ${timestamp()}] Updated generated-types.ts`);
132
+ console.log(`[extractids ${timestamp()}] ** Updated generated-types.ts **`);
118
133
  }
119
134
  // Parse CLI arguments for -w or --watch and optional HTML filename
120
135
  const args = process.argv.slice(2);
@@ -158,7 +173,7 @@ if (watchMode) {
158
173
  watcher.on('change', (path) => {
159
174
  console.log(`[extractids ${timestamp()}] Change detected: ${path}`);
160
175
  clearTimeout(debounceTimer);
161
- debounceTimer = setTimeout(() => updateTypesFile(specifiedHtmlFile), 100);
176
+ debounceTimer = setTimeout(() => updateTypesFile(specifiedHtmlFile), 500);
162
177
  });
163
178
  watcher.on('ready', () => {
164
179
  console.log(`[extractids ${timestamp()}] Watcher is ready and running.`);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bobfrankston/extractids",
3
- "version": "1.0.19",
3
+ "version": "1.0.21",
4
4
  "description": "Extracd html and css as types",
5
5
  "main": "index.js",
6
6
  "bin": {