dsh-taiwind 0.2.0 → 0.3.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/README.md +16 -12
- package/dist/index.js +10 -35
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -56,15 +56,24 @@ pnpm add dsh-taiwind
|
|
|
56
56
|
name: dsh-taiwind
|
|
57
57
|
```
|
|
58
58
|
|
|
59
|
-
用户启用业务插件时,`dsh-taiwind`
|
|
59
|
+
用户启用业务插件时,`dsh-taiwind` 将随行一起启用。
|
|
60
60
|
|
|
61
|
-
-
|
|
62
|
-
- 宿主半要求 `clientModules`、`webServer`、`connection` 三件服务齐备。
|
|
61
|
+
- 它没有界面和工具,唯一产物是共享样式接口 `plugins/taiwind.css` 和页面上的 `<style data-plugin="dsh-taiwind">`。
|
|
63
62
|
- 扫描范围是当前客户端图里所有插件的构建产物,插件图变化会自动触发重新编译。
|
|
64
63
|
|
|
65
|
-
### 2.
|
|
64
|
+
### 2. 声明样式入口
|
|
66
65
|
|
|
67
|
-
|
|
66
|
+
在插件包的 `package.json` 里显式声明未编译的 CSS 入口(相对包根,必须位于包内):
|
|
67
|
+
|
|
68
|
+
```json
|
|
69
|
+
{
|
|
70
|
+
"dsh": {
|
|
71
|
+
"taiwind": "src/main.css"
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
```
|
|
75
|
+
|
|
76
|
+
`main.css` 保留未编译的 CSS-first 写法:
|
|
68
77
|
|
|
69
78
|
```css
|
|
70
79
|
@import "tailwindcss";
|
|
@@ -81,16 +90,11 @@ pnpm add dsh-taiwind
|
|
|
81
90
|
|
|
82
91
|
🚀 客户端直接使用 taiwind 类名,例如 `bg-notes-accent w-notes-panel notes-compact` 即可。
|
|
83
92
|
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
1. 包根目录的 `main.css`
|
|
87
|
-
2. 客户端入口同目录的 `main.css`(如 `client/main.css`)
|
|
88
|
-
3. 以上都没有时,在包内查找 `main.css`;
|
|
89
|
-
4. 找到多个会明确报错,不任意选择
|
|
93
|
+
没有声明 `dsh.taiwind` 的包不参与样式编译;声明了但路径不是相对 `.css`、文件不存在或指向包外都会明确报错,不会去猜别的 `main.css`。
|
|
90
94
|
|
|
91
95
|
### 3. 发布时携带样式文件
|
|
92
96
|
|
|
93
|
-
在 `package.json` 中添加 `files`
|
|
97
|
+
在 `package.json` 中添加 `files` 字段,发布时需要携带入口 CSS 及它引用的相对 CSS:
|
|
94
98
|
|
|
95
99
|
```json
|
|
96
100
|
{
|
package/dist/index.js
CHANGED
|
@@ -138,41 +138,16 @@ async function bundles(directory) {
|
|
|
138
138
|
}
|
|
139
139
|
return files;
|
|
140
140
|
}
|
|
141
|
-
async function
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
if (error.code === "ENOENT") return false;
|
|
147
|
-
throw error;
|
|
148
|
-
}
|
|
149
|
-
}
|
|
150
|
-
async function cssEntry(root, clientDirectory) {
|
|
151
|
-
for (const directory of /* @__PURE__ */ new Set([root, clientDirectory])) {
|
|
152
|
-
const entry = (await readdir(directory, { withFileTypes: true })).find((item) => item.name === "main.css");
|
|
153
|
-
if (entry) {
|
|
154
|
-
if (!entry.isFile()) throw new Error(`${directory}: main.css must be a regular file`);
|
|
155
|
-
return join(directory, entry.name);
|
|
156
|
-
}
|
|
141
|
+
async function cssEntry(root, owner) {
|
|
142
|
+
const entry = JSON.parse(await readFile(join(root, "package.json"), "utf8")).dsh?.taiwind;
|
|
143
|
+
if (entry === void 0) {
|
|
144
|
+
if (await stat(join(root, "main.css")).then((info) => info.isFile(), () => false)) throw new Error(`${owner}: main.css is not discovered automatically anymore; declare "dsh": { "taiwind": "main.css" } in package.json`);
|
|
145
|
+
return;
|
|
157
146
|
}
|
|
158
|
-
|
|
159
|
-
const
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
"node_modules",
|
|
163
|
-
"archive",
|
|
164
|
-
".git"
|
|
165
|
-
].includes(item.name) || item.isSymbolicLink()) continue;
|
|
166
|
-
const path = join(directory, item.name);
|
|
167
|
-
if (item.isDirectory()) {
|
|
168
|
-
if (await nestedPackage(path)) continue;
|
|
169
|
-
await visit(path);
|
|
170
|
-
} else if (item.isFile() && item.name === "main.css") found.push(path);
|
|
171
|
-
}
|
|
172
|
-
};
|
|
173
|
-
await visit(root);
|
|
174
|
-
if (found.length > 1) throw new Error(`${root}: multiple main.css entries found: ${found.sort().join(", ")}`);
|
|
175
|
-
return found[0];
|
|
147
|
+
if (typeof entry !== "string" || !entry.trim() || extname(entry) !== ".css") throw new Error(`${owner}: dsh.taiwind must be a relative .css path`);
|
|
148
|
+
const path = resolve(root, entry);
|
|
149
|
+
if (!await stat(path).then((info) => info.isFile(), () => false)) throw new Error(`${owner}: dsh.taiwind entry not found: ${entry}`);
|
|
150
|
+
return path;
|
|
176
151
|
}
|
|
177
152
|
async function compilePlugins(entries) {
|
|
178
153
|
const hash = createHash("sha256");
|
|
@@ -301,7 +276,7 @@ async function compilePlugins(entries) {
|
|
|
301
276
|
]));
|
|
302
277
|
bundleFiles.push(file);
|
|
303
278
|
}
|
|
304
|
-
const stylesheet = await cssEntry(root,
|
|
279
|
+
const stylesheet = await cssEntry(root, entry.id);
|
|
305
280
|
if (stylesheet) {
|
|
306
281
|
cssImports.push(await loadCss(stylesheet, root, entry.id));
|
|
307
282
|
continue;
|
package/package.json
CHANGED