@bobfrankston/extractids 1.0.0

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/.gitattributes ADDED
@@ -0,0 +1,7 @@
1
+ * text=auto
2
+ *.ts text eol=lf
3
+ *.json text eol=lf
4
+ *.gitignore text eol=lf
5
+ *.npmignore text eol=lf
6
+ *.gitattributes text eol=lf
7
+ *.md text eol=lf
@@ -0,0 +1,21 @@
1
+ {
2
+ // Use IntelliSense to learn about possible attributes.
3
+ // Hover to view descriptions of existing attributes.
4
+ // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
5
+ "version": "0.2.0",
6
+ "configurations": [
7
+ {
8
+ "type": "node",
9
+ "request": "launch",
10
+ "name": "Launch Program",
11
+ "program": "${workspaceFolder}/index.js",
12
+ "skipFiles": [
13
+ "<node_internals>/**"
14
+ ],
15
+ "outFiles": [
16
+ "${workspaceFolder}/**/*.js"
17
+ ],
18
+ "cwd": "y:\\x\\bin\\WallClock"
19
+ }
20
+ ]
21
+ }
@@ -0,0 +1,23 @@
1
+ {
2
+ // Template 1.0 y:\x\bin\MakeCodeTemplates\vscode\
3
+ // See https://go.microsoft.com/fwlink/?LinkId=733558
4
+ // for the documentation about the tasks.json format
5
+ "version": "2.0.0",
6
+ "tasks": [
7
+ {
8
+ "type": "typescript",
9
+ "tsconfig": "tsconfig.json",
10
+ "option": "watch",
11
+ "runOptions": {
12
+ "runOn": "folderOpen"
13
+ },
14
+ "problemMatcher": [
15
+ "$tsc-watch"
16
+ ],
17
+ "group": {
18
+ "kind": "build",
19
+ "isDefault": true
20
+ }
21
+ }
22
+ ]
23
+ }
@@ -0,0 +1,2 @@
1
+ {
2
+ }
@@ -0,0 +1,20 @@
1
+ {
2
+ "version": "2.0.0",
3
+ "tasks": [
4
+ {
5
+ "label": "tsc: watch",
6
+ "type": "shell",
7
+ "command": "tsc",
8
+ "args": ["--watch"],
9
+ "runOptions": {
10
+ "runOn": "folderOpen"
11
+ },
12
+ "problemMatcher": "$tsc-watch",
13
+ "isBackground": true,
14
+ "group": {
15
+ "kind": "build",
16
+ "isDefault": true
17
+ }
18
+ }
19
+ ]
20
+ }
package/Perplexity.url ADDED
@@ -0,0 +1,2 @@
1
+ [InternetShortcut]
2
+ URL=https://www.perplexity.ai/search/using-node-with-express-it-par-i1pUpv5YRHyQOxglUk3joQ#5
package/index.js ADDED
@@ -0,0 +1,77 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ // scripts/generateTypes.ts
4
+ var fs = require("node:fs");
5
+ var path = require("node:path");
6
+ var cheerio = require("cheerio");
7
+ var chokidar_1 = require("chokidar");
8
+ // import * as glob from 'glob';
9
+ // Helper function to extract all id attributes from HTML
10
+ function getHtmlIDs(html) {
11
+ var $ = cheerio.load(html);
12
+ var ids = new Set();
13
+ $('[id]').each(function (_, elem) {
14
+ var id = $(elem).attr('id');
15
+ if (id)
16
+ ids.add(id);
17
+ });
18
+ return Array.from(ids).sort();
19
+ }
20
+ // Helper function to extract all class names from CSS files
21
+ function getCssClasses(css) {
22
+ // Match any .classname { or .classname,
23
+ var classPattern = /\.([a-zA-Z0-9_-]+)\s*[{,]/g;
24
+ var classes = new Set();
25
+ var match;
26
+ while ((match = classPattern.exec(css))) {
27
+ classes.add(match[1]);
28
+ }
29
+ return Array.from(classes).sort();
30
+ }
31
+ function globReadCssFiles() {
32
+ // Recursively find all .css files in project folder, ignoring node_modules
33
+ var result = [];
34
+ function walk(dir) {
35
+ var entries = fs.readdirSync(dir, { withFileTypes: true });
36
+ for (var _i = 0, entries_1 = entries; _i < entries_1.length; _i++) {
37
+ var entry = entries_1[_i];
38
+ var fullPath = path.join(dir, entry.name);
39
+ if (entry.isDirectory()) {
40
+ if (entry.name === 'node_modules')
41
+ continue;
42
+ walk(fullPath);
43
+ }
44
+ else if (entry.isFile() && fullPath.endsWith('.css')) {
45
+ result.push(fullPath);
46
+ }
47
+ }
48
+ }
49
+ walk(process.cwd());
50
+ return result;
51
+ }
52
+ function generateTypes(ids, classes) {
53
+ var idType = ids.length > 0
54
+ ? "export type htmlIDs = ".concat(ids.map(function (id) { return "\"".concat(id, "\""); }).join(' | '), ";\n")
55
+ : "export type htmlIDs = never;\n";
56
+ var classType = classes.length > 0
57
+ ? "export type cssClasses = ".concat(classes.map(function (cls) { return "\"".concat(cls, "\""); }).join(' | '), ";\n")
58
+ : "export type cssClasses = never;\n";
59
+ return idType + classType;
60
+ }
61
+ function updateTypesFile() {
62
+ var html = fs.readFileSync('index.html', 'utf8');
63
+ var ids = getHtmlIDs(html);
64
+ var cssFiles = globReadCssFiles();
65
+ var allClasses = new Set();
66
+ cssFiles.forEach(function (file) {
67
+ var css = fs.readFileSync(file, 'utf8');
68
+ getCssClasses(css).forEach(function (cls) { return allClasses.add(cls); });
69
+ });
70
+ var types = generateTypes(ids, Array.from(allClasses));
71
+ fs.writeFileSync('generated-types.ts', types);
72
+ console.log('[Type generation] Updated generated-types.ts');
73
+ }
74
+ // Initial run
75
+ updateTypesFile();
76
+ // Watch for changes on HTML and CSS
77
+ chokidar_1.default.watch(['index.html', '**/*.css'], { ignored: /node_modules/ }).on('change', function () { return updateTypesFile(); });
package/index.ts ADDED
@@ -0,0 +1,83 @@
1
+ // scripts/generateTypes.ts
2
+ import * as fs from 'node:fs';
3
+ import * as path from 'node:path';
4
+ import * as cheerio from 'cheerio';
5
+ import chokidar from 'chokidar';
6
+ // import * as glob from 'glob';
7
+
8
+ // Helper function to extract all id attributes from HTML
9
+ function getHtmlIDs(html: string) {
10
+ const $ = cheerio.load(html);
11
+ const ids = new Set<string>();
12
+ $('[id]').each((_, elem) => {
13
+ const id = $(elem).attr('id');
14
+ if (id) ids.add(id);
15
+ });
16
+ return Array.from(ids).sort();
17
+ }
18
+
19
+ // Helper function to extract all class names from CSS files
20
+ function getCssClasses(css: string) {
21
+ // Match any .classname { or .classname,
22
+ const classPattern = /\.([a-zA-Z0-9_-]+)\s*[{,]/g;
23
+ const classes = new Set<string>();
24
+ let match: RegExpExecArray | null;
25
+ while ((match = classPattern.exec(css))) {
26
+ classes.add(match[1]);
27
+ }
28
+ return Array.from(classes).sort();
29
+ }
30
+
31
+
32
+ function globReadCssFiles(): string[] {
33
+ // Recursively find all .css files in project folder, ignoring node_modules
34
+ const result: string[] = [];
35
+ function walk(dir: string) {
36
+ const entries = fs.readdirSync(dir, { withFileTypes: true });
37
+ for (const entry of entries) {
38
+ const fullPath = path.join(dir, entry.name);
39
+ if (entry.isDirectory()) {
40
+ if (entry.name === 'node_modules') continue;
41
+ walk(fullPath);
42
+ } else if (entry.isFile() && fullPath.endsWith('.css')) {
43
+ result.push(fullPath);
44
+ }
45
+ }
46
+ }
47
+ walk(process.cwd());
48
+ return result;
49
+ }
50
+
51
+ function generateTypes(ids: string[], classes: string[]) {
52
+ const idType =
53
+ ids.length > 0
54
+ ? `export type htmlIDs = ${ids.map(id => `"${id}"`).join(' | ')};\n`
55
+ : `export type htmlIDs = never;\n`;
56
+ const classType =
57
+ classes.length > 0
58
+ ? `export type cssClasses = ${classes.map(cls => `"${cls}"`).join(' | ')};\n`
59
+ : `export type cssClasses = never;\n`;
60
+ return idType + classType;
61
+ }
62
+
63
+ function updateTypesFile() {
64
+ const html = fs.readFileSync('index.html', 'utf8');
65
+ const ids = getHtmlIDs(html);
66
+
67
+ const cssFiles = globReadCssFiles();
68
+ const allClasses = new Set<string>();
69
+ cssFiles.forEach(file => {
70
+ const css = fs.readFileSync(file, 'utf8');
71
+ getCssClasses(css).forEach(cls => allClasses.add(cls));
72
+ });
73
+
74
+ const types = generateTypes(ids, Array.from(allClasses));
75
+ fs.writeFileSync('generated-types.ts', types);
76
+ console.log('[Type generation] Updated generated-types.ts');
77
+ }
78
+
79
+ // Initial run
80
+ updateTypesFile();
81
+
82
+ // Watch for changes on HTML and CSS
83
+ chokidar.watch(['index.html', '**/*.css'], { ignored: /node_modules/ }).on('change', () => updateTypesFile());
package/package.json ADDED
@@ -0,0 +1,21 @@
1
+ {
2
+ "name": "@bobfrankston/extractids",
3
+ "version": "1.0.0",
4
+ "description": "",
5
+ "main": "index.js",
6
+ "scripts": {
7
+ "test": "echo \"Error: no test specified\" && exit 1"
8
+ },
9
+ "keywords": [],
10
+ "author": "",
11
+ "license": "ISC",
12
+ "type": "module",
13
+ "dependencies": {
14
+ "cheerio": "^1.1.2",
15
+ "chokidar": "^4.0.3",
16
+ "esm": "^3.2.25"
17
+ },
18
+ "devDependencies": {
19
+ "@types/node": "^24.5.2"
20
+ }
21
+ }
package/tsconfig.json ADDED
@@ -0,0 +1,26 @@
1
+ {
2
+ "compilerOptions": {
3
+ "target": "esnext",
4
+ "module": "NodeNext",
5
+ "moduleResolution": "NodeNext",
6
+ "allowImportingTsExtensions": true,
7
+ "sourceMap": true,
8
+ "noEmit": true,
9
+ "esModuleInterop": true,
10
+ "forceConsistentCasingInFileNames": true,
11
+ "strict": true,
12
+ "noImplicitAny": true,
13
+ "noImplicitReturns": false,
14
+ "noImplicitThis": true,
15
+ "strictBindCallApply": true,
16
+ "strictFunctionTypes": true,
17
+ "strictNullChecks": false,
18
+ "skipLibCheck": true
19
+ },
20
+ "include": [
21
+ "**/*.ts"
22
+ ],
23
+ "exclude": [
24
+ "node_modules",
25
+ ]
26
+ }