tailwind-hyperclay 0.1.4 → 0.1.9
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/index.js +25 -18
- package/package.json +1 -5
- package/test/test.js +1 -1
package/index.js
CHANGED
|
@@ -1,12 +1,8 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
import { pathToFileURL } from 'url';
|
|
5
|
-
import path from 'path';
|
|
1
|
+
const { readFile, writeFile } = require('fs/promises');
|
|
2
|
+
const path = require('path');
|
|
3
|
+
const { compile } = require('tailwindcss');
|
|
6
4
|
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
export async function generateCSS({ input, output }) {
|
|
5
|
+
async function generateCSS({ input, output }) {
|
|
10
6
|
const html = await readFile(input, 'utf-8');
|
|
11
7
|
|
|
12
8
|
const css = await compileTailwind(html);
|
|
@@ -18,7 +14,8 @@ export async function generateCSS({ input, output }) {
|
|
|
18
14
|
return css;
|
|
19
15
|
}
|
|
20
16
|
|
|
21
|
-
|
|
17
|
+
async function compileTailwind(html) {
|
|
18
|
+
|
|
22
19
|
const inputCSS = `
|
|
23
20
|
@import "tailwindcss";
|
|
24
21
|
@plugin "@tailwindcss/typography";
|
|
@@ -52,13 +49,13 @@ export async function compileTailwind(html) {
|
|
|
52
49
|
},
|
|
53
50
|
loadModule: async (id, base) => {
|
|
54
51
|
const resolved = require.resolve(id, { paths: [base || process.cwd()] });
|
|
55
|
-
const mod =
|
|
56
|
-
return { module: mod.default, base: path.dirname(resolved) };
|
|
52
|
+
const mod = require(resolved);
|
|
53
|
+
return { module: mod.default || mod, base: path.dirname(resolved) };
|
|
57
54
|
},
|
|
58
55
|
loadPlugin: async (plugin) => {
|
|
59
56
|
const resolved = require.resolve(plugin);
|
|
60
|
-
const mod =
|
|
61
|
-
return mod.default;
|
|
57
|
+
const mod = require(resolved);
|
|
58
|
+
return mod.default || mod;
|
|
62
59
|
}
|
|
63
60
|
});
|
|
64
61
|
|
|
@@ -68,7 +65,7 @@ export async function compileTailwind(html) {
|
|
|
68
65
|
return css;
|
|
69
66
|
}
|
|
70
67
|
|
|
71
|
-
|
|
68
|
+
function extractCandidates(html) {
|
|
72
69
|
const candidates = new Set();
|
|
73
70
|
|
|
74
71
|
// Extract class attribute values
|
|
@@ -102,7 +99,7 @@ function extractHrefs(html) {
|
|
|
102
99
|
return hrefs;
|
|
103
100
|
}
|
|
104
101
|
|
|
105
|
-
|
|
102
|
+
function getTailwindCssName(html) {
|
|
106
103
|
for (const href of extractHrefs(html)) {
|
|
107
104
|
const name = getTailwindName(href);
|
|
108
105
|
if (name) return name;
|
|
@@ -110,15 +107,15 @@ export function getTailwindCssName(html) {
|
|
|
110
107
|
return null;
|
|
111
108
|
}
|
|
112
109
|
|
|
113
|
-
|
|
110
|
+
function hasTailwindLink(html, appName) {
|
|
114
111
|
return extractHrefs(html).some(url => getTailwindName(url) === appName);
|
|
115
112
|
}
|
|
116
113
|
|
|
117
|
-
|
|
114
|
+
function hasAnyTailwindLink(html) {
|
|
118
115
|
return extractHrefs(html).some(url => getTailwindName(url) !== null);
|
|
119
116
|
}
|
|
120
117
|
|
|
121
|
-
|
|
118
|
+
function replaceTailwindLink(html, newName) {
|
|
122
119
|
return html.replace(
|
|
123
120
|
/(href\s*=\s*["'])([^"']+)(["'])/gi,
|
|
124
121
|
(match, prefix, url, suffix) => {
|
|
@@ -129,3 +126,13 @@ export function replaceTailwindLink(html, newName) {
|
|
|
129
126
|
}
|
|
130
127
|
);
|
|
131
128
|
}
|
|
129
|
+
|
|
130
|
+
module.exports = {
|
|
131
|
+
generateCSS,
|
|
132
|
+
compileTailwind,
|
|
133
|
+
extractCandidates,
|
|
134
|
+
getTailwindCssName,
|
|
135
|
+
hasTailwindLink,
|
|
136
|
+
hasAnyTailwindLink,
|
|
137
|
+
replaceTailwindLink
|
|
138
|
+
};
|
package/package.json
CHANGED
|
@@ -1,12 +1,8 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "tailwind-hyperclay",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.9",
|
|
4
4
|
"description": "On-save Tailwind CSS generator for Hyperclay",
|
|
5
|
-
"type": "module",
|
|
6
5
|
"main": "index.js",
|
|
7
|
-
"exports": {
|
|
8
|
-
".": "./index.js"
|
|
9
|
-
},
|
|
10
6
|
"scripts": {
|
|
11
7
|
"test": "node test/test.js",
|
|
12
8
|
"release": "./scripts/release.sh"
|
package/test/test.js
CHANGED