css-module-sync 0.1.34 → 1.0.1
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/package.json +1 -9
- package/src/css_formatter.js +1 -1
- package/src/css_sync.js +21 -12
- package/src/default_sort_spec.json +17 -14
package/package.json
CHANGED
|
@@ -1,18 +1,10 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "css-module-sync",
|
|
3
|
-
"version": "0.1
|
|
3
|
+
"version": "1.0.1",
|
|
4
4
|
"description": "Auto sync css module classes with react components",
|
|
5
5
|
"author": "Max Matinpalo",
|
|
6
6
|
"type": "module",
|
|
7
7
|
"license": "MIT",
|
|
8
|
-
"homepage": "https://github.com/max-matinpalo/css-module-sync#readme",
|
|
9
|
-
"repository": {
|
|
10
|
-
"type": "git",
|
|
11
|
-
"url": "https://github.com/max-matinpalo/css-module-sync.git"
|
|
12
|
-
},
|
|
13
|
-
"bugs": {
|
|
14
|
-
"url": "https://github.com/max-matinpalo/css-module-sync/issues"
|
|
15
|
-
},
|
|
16
8
|
"bin": {
|
|
17
9
|
"css-sync": "./src/css_sync.js"
|
|
18
10
|
}
|
package/src/css_formatter.js
CHANGED
package/src/css_sync.js
CHANGED
|
@@ -109,23 +109,32 @@ async function format_css_only(css_path) {
|
|
|
109
109
|
}
|
|
110
110
|
|
|
111
111
|
async function sync_file(tsx_path) {
|
|
112
|
+
let tsx;
|
|
113
|
+
try { tsx = await fs.readFile(tsx_path, "utf-8"); } catch { return; }
|
|
114
|
+
|
|
115
|
+
const used_ordered = extract_classes(tsx);
|
|
116
|
+
const dir = path.dirname(tsx_path);
|
|
117
|
+
const name = path.basename(tsx_path, path.extname(tsx_path));
|
|
118
|
+
const module_path = path.join(dir, `${name}.module.css`);
|
|
119
|
+
const css_exists = existsSync(module_path);
|
|
120
|
+
|
|
121
|
+
if (FLAGS.gen && used_ordered.length === 0 && !css_exists) return;
|
|
122
|
+
|
|
112
123
|
const css_path = await resolve_css_path(tsx_path);
|
|
113
124
|
if (!css_path) return;
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
if (FLAGS.gen) {
|
|
125
|
+
|
|
126
|
+
let css;
|
|
127
|
+
try { css = await fs.readFile(css_path, "utf-8"); } catch { return; }
|
|
128
|
+
|
|
129
|
+
if (FLAGS.gen && used_ordered.length > 0) {
|
|
119
130
|
const target = `import styles from "./${path.basename(css_path)}";`;
|
|
120
|
-
|
|
121
|
-
const
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
});
|
|
125
|
-
const final = found ? next : `${target}\n${next}`;
|
|
131
|
+
const next = tsx.replace(/^import\s+styles\s+from\s+["'][^"']+["'];?\s*\n?/gm, "");
|
|
132
|
+
const m = next.match(/^(\s*(?:(?:\/\*.*?\*\/)\s*|\/\/.*\s*)*)(["']use client["'];?\s*\n)?/s);
|
|
133
|
+
const i = m ? m[0].length : 0;
|
|
134
|
+
const final = `${next.slice(0, i)}${target}\n${next.slice(i)}`;
|
|
126
135
|
if (final !== tsx) await fs.writeFile(tsx_path, tsx = final);
|
|
127
136
|
}
|
|
128
|
-
|
|
137
|
+
|
|
129
138
|
let root;
|
|
130
139
|
try { root = parse(css); } catch { return; }
|
|
131
140
|
const class_to_idxs = new Map();
|
|
@@ -39,38 +39,41 @@
|
|
|
39
39
|
"height",
|
|
40
40
|
"min-height",
|
|
41
41
|
"max-height",
|
|
42
|
-
"aspect-ratio",
|
|
43
42
|
"margin...",
|
|
44
43
|
"padding...",
|
|
45
|
-
"border..."
|
|
44
|
+
"border...",
|
|
45
|
+
"aspect-ratio"
|
|
46
46
|
]
|
|
47
47
|
},
|
|
48
48
|
{
|
|
49
|
-
"category": "
|
|
49
|
+
"category": "SCROLL",
|
|
50
|
+
"keywords": [
|
|
51
|
+
"overflow...",
|
|
52
|
+
"scroll...",
|
|
53
|
+
"scrollbar...",
|
|
54
|
+
"overscroll-behavior...",
|
|
55
|
+
"-webkit-overflow-scrolling"
|
|
56
|
+
]
|
|
57
|
+
},
|
|
58
|
+
{
|
|
59
|
+
"category": "VISUALS",
|
|
50
60
|
"keywords": [
|
|
51
61
|
"color",
|
|
52
62
|
"background...",
|
|
53
63
|
"opacity",
|
|
54
|
-
"box-shadow"
|
|
64
|
+
"box-shadow",
|
|
65
|
+
"backdrop-filter",
|
|
66
|
+
"-webkit-backdrop-filter"
|
|
55
67
|
]
|
|
56
68
|
},
|
|
57
69
|
{
|
|
58
70
|
"category": "TYPO",
|
|
59
71
|
"keywords": [
|
|
60
|
-
"font",
|
|
61
|
-
"font-family",
|
|
62
|
-
"font-size",
|
|
63
|
-
"font-weight",
|
|
64
|
-
"font-style",
|
|
65
72
|
"font...",
|
|
66
|
-
"font-stretch",
|
|
67
73
|
"line-height",
|
|
74
|
+
"text...",
|
|
68
75
|
"letter-spacing",
|
|
69
76
|
"word-spacing",
|
|
70
|
-
"text-align",
|
|
71
|
-
"text-transform",
|
|
72
|
-
"text-decoration....",
|
|
73
|
-
"text-underline-offset",
|
|
74
77
|
"white-space"
|
|
75
78
|
]
|
|
76
79
|
},
|