@bobfrankston/extractids 1.0.9 → 1.0.11

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.
@@ -3,9 +3,10 @@
3
3
  "allow": [
4
4
  "Bash(git add:*)",
5
5
  "Bash(git commit:*)",
6
- "Bash(npm publish:*)"
6
+ "Bash(npm publish:*)",
7
+ "Bash(tsc:*)"
7
8
  ],
8
9
  "deny": [],
9
10
  "ask": []
10
11
  }
11
- }
12
+ }
package/index.js CHANGED
@@ -51,13 +51,36 @@ function generateTypes(ids, classes) {
51
51
  const idType = ids.length > 0
52
52
  ? `export type htmlIDs = ${ids.map(id => `"${id}"`).join(' |\n')};\n`
53
53
  : `export type htmlIDs = never;\n`;
54
+ const queryType = ids.length > 0
55
+ ? `export type queryIDs = ${ids.map(id => `"#${id}"`).join(' |\n')};\n`
56
+ : `export type queryIDs = never;\n`;
54
57
  const classType = classes.length > 0
55
58
  ? `export type cssClasses = ${classes.map(cls => `"${cls}"`).join(' |\n')};\n`
56
59
  : `export type cssClasses = never;\n`;
57
- return idType + classType;
60
+ return idType + queryType + classType;
58
61
  }
59
- function updateTypesFile() {
60
- const html = fs.readFileSync('index.html', 'utf8');
62
+ function updateTypesFile(specifiedHtmlFile) {
63
+ let htmlFile;
64
+ if (specifiedHtmlFile) {
65
+ // Use the specified file if provided
66
+ if (fs.existsSync(specifiedHtmlFile)) {
67
+ htmlFile = specifiedHtmlFile;
68
+ }
69
+ else {
70
+ console.error(`[extractids] Specified HTML file not found: ${specifiedHtmlFile}`);
71
+ return;
72
+ }
73
+ }
74
+ else {
75
+ // Check for HTML files in order of preference
76
+ const possibleHtmlFiles = ['index.html', 'default.html', 'default.htm'];
77
+ htmlFile = possibleHtmlFiles.find(file => fs.existsSync(file));
78
+ if (!htmlFile) {
79
+ console.error('[extractids] No HTML file found. Looking for:', possibleHtmlFiles.join(', '));
80
+ return;
81
+ }
82
+ }
83
+ const html = fs.readFileSync(htmlFile, 'utf8');
61
84
  const ids = getHtmlIDs(html);
62
85
  const cssFiles = globReadCssFiles();
63
86
  const allClasses = new Set();
@@ -69,14 +92,39 @@ function updateTypesFile() {
69
92
  fs.writeFileSync('generated-types.ts', types);
70
93
  console.log('[Type generation] Updated generated-types.ts');
71
94
  }
72
- // Parse CLI arguments for -w or --watch
95
+ // Parse CLI arguments for -w or --watch and optional HTML filename
73
96
  const args = process.argv.slice(2);
97
+ // Check for help flags
98
+ if (args.includes('-h') || args.includes('-help') || args.includes('--help')) {
99
+ console.log(`
100
+ Usage: extractids [options] [htmlfile]
101
+
102
+ Options:
103
+ -h, -help, --help Show this help message
104
+ -w, -watch, --watch Watch for changes and regenerate types automatically
105
+
106
+ Arguments:
107
+ htmlfile Optional HTML file to parse (default: searches for index.html, default.html, or default.htm)
108
+
109
+ Examples:
110
+ extractids # Parse default HTML file once
111
+ extractids mypage.html # Parse specific HTML file once
112
+ extractids --watch # Watch default HTML file for changes
113
+ extractids mypage.html -w # Watch specific HTML file for changes
114
+ `);
115
+ process.exit(0);
116
+ }
74
117
  const watchMode = args.includes('-w') || args.includes('-watch') || args.includes('--watch');
118
+ // Find first argument that doesn't start with '-' as the HTML filename
119
+ const specifiedHtmlFile = args.find(arg => !arg.startsWith('-'));
75
120
  if (watchMode) {
76
- updateTypesFile();
121
+ updateTypesFile(specifiedHtmlFile);
77
122
  console.log('[extractids] Watching for changes...');
78
- const watcher = chokidar.watch(['index.html', '**/*.css'], { ignored: /node_modules/ });
79
- watcher.on('change', () => updateTypesFile());
123
+ const htmlFilesToWatch = specifiedHtmlFile
124
+ ? [specifiedHtmlFile]
125
+ : ['index.html', 'default.html', 'default.htm'];
126
+ const watcher = chokidar.watch([...htmlFilesToWatch, '**/*.css'], { ignored: /node_modules/ });
127
+ watcher.on('change', () => updateTypesFile(specifiedHtmlFile));
80
128
  watcher.on('ready', () => {
81
129
  console.log('[extractids] Watcher is ready and running.');
82
130
  });
@@ -86,6 +134,6 @@ if (watchMode) {
86
134
  // No need for setInterval; watcher should keep process alive
87
135
  }
88
136
  else {
89
- updateTypesFile();
137
+ updateTypesFile(specifiedHtmlFile);
90
138
  }
91
139
  //# sourceMappingURL=index.js.map
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bobfrankston/extractids",
3
- "version": "1.0.9",
3
+ "version": "1.0.11",
4
4
  "description": "Extracd html and css as types",
5
5
  "main": "index.js",
6
6
  "bin": {
@@ -21,7 +21,7 @@
21
21
  "esm": "^3.2.25"
22
22
  },
23
23
  "devDependencies": {
24
- "@types/node": "^24.5.2"
24
+ "@types/node": "^25.2.1"
25
25
  },
26
26
  "repository": {
27
27
  "type": "git",
@@ -30,5 +30,8 @@
30
30
  "bugs": {
31
31
  "url": "https://github.com/BobFrankston/extractids/issues"
32
32
  },
33
- "homepage": "https://github.com/BobFrankston/extractids#readme"
33
+ "homepage": "https://github.com/BobFrankston/extractids#readme",
34
+ "publishConfig": {
35
+ "access": "public"
36
+ }
34
37
  }