weifuwu 0.27.7 → 0.27.8
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/dist/cli.js +17 -14
- package/dist/index.js +26 -4
- package/package.json +1 -1
package/dist/cli.js
CHANGED
|
@@ -120,7 +120,10 @@ async function generateFull(targetDir, name, version, skipInstall) {
|
|
|
120
120
|
`import { html, raw, assetScripts } from 'weifuwu'`,
|
|
121
121
|
``,
|
|
122
122
|
`export default function(body: string, ctx: any) {`,
|
|
123
|
-
` // Theme:
|
|
123
|
+
` // Theme: read from ctx at server, resolve system on client`,
|
|
124
|
+
` const themeVal = ctx.theme?.value || 'system'`,
|
|
125
|
+
` const isDark = themeVal === 'dark' || (themeVal === 'system' && false)`,
|
|
126
|
+
` const htmlClass = isDark ? 'dark' : ''`,
|
|
124
127
|
` const themeScript = raw(\`<script>`,
|
|
125
128
|
`!function(){`,
|
|
126
129
|
`var t=(document.cookie.match(/(?:^|;\\s*)theme=([^;]+)/)||[])[1]||'system';`,
|
|
@@ -138,7 +141,7 @@ async function generateFull(targetDir, name, version, skipInstall) {
|
|
|
138
141
|
` : ''`,
|
|
139
142
|
``,
|
|
140
143
|
` return html\`<!DOCTYPE html>`,
|
|
141
|
-
`<html lang="\${lang}">`,
|
|
144
|
+
`<html lang="\${lang}" class="\${htmlClass}">`,
|
|
142
145
|
`<head>`,
|
|
143
146
|
` <meta charset="utf-8" />`,
|
|
144
147
|
` <meta name="viewport" content="width=device-width, initial-scale=1" />`,
|
|
@@ -188,7 +191,7 @@ async function generateFull(targetDir, name, version, skipInstall) {
|
|
|
188
191
|
``,
|
|
189
192
|
` <!-- Hero -->`,
|
|
190
193
|
` <section class="max-w-3xl mx-auto px-4 py-16 text-center">`,
|
|
191
|
-
` <h1 class="text-4xl font-bold tracking-tight mb-3">\${t('
|
|
194
|
+
` <h1 class="text-4xl font-bold tracking-tight mb-3">\${t('title')}</h1>`,
|
|
192
195
|
` <p class="text-gray-500 dark:text-gray-400 text-lg mb-8">`,
|
|
193
196
|
` Pure Node.js, no build step`,
|
|
194
197
|
` </p>`,
|
|
@@ -197,19 +200,19 @@ async function generateFull(targetDir, name, version, skipInstall) {
|
|
|
197
200
|
` <button @click="open = !open"`,
|
|
198
201
|
` class="rounded-md bg-gray-900 px-4 py-2 text-sm font-medium text-white`,
|
|
199
202
|
` hover:bg-gray-700 dark:bg-gray-100 dark:text-gray-900 dark:hover:bg-gray-300">`,
|
|
200
|
-
` \${t('
|
|
203
|
+
` \${t('cta')}`,
|
|
201
204
|
` </button>`,
|
|
202
205
|
` <a href="/docs"`,
|
|
203
206
|
` class="rounded-md border border-gray-300 px-4 py-2 text-sm font-medium`,
|
|
204
207
|
` hover:bg-gray-100 dark:border-gray-600 dark:hover:bg-gray-800">`,
|
|
205
|
-
` \${t('
|
|
208
|
+
` \${t('docs')}`,
|
|
206
209
|
` </a>`,
|
|
207
210
|
` </div>`,
|
|
208
211
|
``,
|
|
209
212
|
` <!-- Alpine demo: click to reveal -->`,
|
|
210
213
|
` <div x-show="open" x-cloak`,
|
|
211
214
|
` class="mt-6 p-4 bg-gray-100 dark:bg-gray-800 rounded-lg text-sm text-left">`,
|
|
212
|
-
` \${t('demo
|
|
215
|
+
` \${t('demo')}`,
|
|
213
216
|
` </div>`,
|
|
214
217
|
` </section>`,
|
|
215
218
|
` </div>\``,
|
|
@@ -234,10 +237,10 @@ async function generateFull(targetDir, name, version, skipInstall) {
|
|
|
234
237
|
join(targetDir, "locales", "en.json"),
|
|
235
238
|
JSON.stringify(
|
|
236
239
|
{
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
240
|
+
title: "Build APIs & UI, Zero Build Step",
|
|
241
|
+
cta: "Try Alpine",
|
|
242
|
+
docs: "Documentation",
|
|
243
|
+
demo: "This is Alpine.js in action \u2014 click-toggled content, zero JavaScript written."
|
|
241
244
|
},
|
|
242
245
|
null,
|
|
243
246
|
2
|
|
@@ -247,10 +250,10 @@ async function generateFull(targetDir, name, version, skipInstall) {
|
|
|
247
250
|
join(targetDir, "locales", "zh-CN.json"),
|
|
248
251
|
JSON.stringify(
|
|
249
252
|
{
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
253
|
+
title: "\u96F6\u7F16\u8BD1\u6784\u5EFA API \u548C UI",
|
|
254
|
+
cta: "\u4F53\u9A8C Alpine",
|
|
255
|
+
docs: "\u6587\u6863",
|
|
256
|
+
demo: "\u8FD9\u662F Alpine.js \u7684\u6F14\u793A\u2014\u2014\u70B9\u51FB\u5207\u6362\u5185\u5BB9\uFF0C\u4E0D\u9700\u8981\u5199 JavaScript\u3002"
|
|
254
257
|
},
|
|
255
258
|
null,
|
|
256
259
|
2
|
package/dist/index.js
CHANGED
|
@@ -2460,8 +2460,8 @@ function postgres(opts) {
|
|
|
2460
2460
|
const stmtTimeout = options.statementTimeout ?? 3e4;
|
|
2461
2461
|
let connStr = typeof connection === "string" ? connection : "";
|
|
2462
2462
|
if (stmtTimeout > 0 && typeof connection === "string") {
|
|
2463
|
-
const
|
|
2464
|
-
connStr = `${connStr}${
|
|
2463
|
+
const sep3 = connStr.includes("?") ? "&" : "?";
|
|
2464
|
+
connStr = `${connStr}${sep3}options=-c%20statement_timeout%3D${stmtTimeout}`;
|
|
2465
2465
|
}
|
|
2466
2466
|
const sql = postgresFactory(connStr, {
|
|
2467
2467
|
max: options.max,
|
|
@@ -3592,15 +3592,37 @@ function view(path, options) {
|
|
|
3592
3592
|
// ssr/css.ts
|
|
3593
3593
|
import { createHash } from "node:crypto";
|
|
3594
3594
|
import { existsSync, readFileSync as readFileSync2 } from "node:fs";
|
|
3595
|
-
import { join as join3, resolve as resolve6 } from "node:path";
|
|
3595
|
+
import { join as join3, resolve as resolve6, sep as sep2 } from "node:path";
|
|
3596
3596
|
import tailwindPlugin from "@tailwindcss/postcss";
|
|
3597
3597
|
import postcss from "postcss";
|
|
3598
3598
|
var cssCache = /* @__PURE__ */ new Map();
|
|
3599
|
+
function findTailwindDir() {
|
|
3600
|
+
const hoisted = resolve6(process.cwd(), "node_modules", "tailwindcss");
|
|
3601
|
+
if (existsSync(hoisted)) return hoisted;
|
|
3602
|
+
let dir = process.cwd();
|
|
3603
|
+
const root = sep2 === "/" ? "/" : "";
|
|
3604
|
+
while (dir !== root) {
|
|
3605
|
+
const wfwDir = resolve6(dir, "node_modules", "weifuwu");
|
|
3606
|
+
if (existsSync(wfwDir)) {
|
|
3607
|
+
const nested = resolve6(wfwDir, "node_modules", "tailwindcss");
|
|
3608
|
+
if (existsSync(nested)) return nested;
|
|
3609
|
+
const parent = resolve6(dir, "..", "node_modules", "tailwindcss");
|
|
3610
|
+
if (existsSync(parent)) return parent;
|
|
3611
|
+
}
|
|
3612
|
+
dir = resolve6(dir, "..");
|
|
3613
|
+
}
|
|
3614
|
+
return null;
|
|
3615
|
+
}
|
|
3599
3616
|
async function compileCSS(cssPath, sourceDir) {
|
|
3600
3617
|
if (!existsSync(cssPath)) {
|
|
3601
3618
|
return { css: "", hash: "empty", url: "" };
|
|
3602
3619
|
}
|
|
3603
|
-
|
|
3620
|
+
let raw2 = readFileSync2(cssPath, "utf-8");
|
|
3621
|
+
const tailwindDir = findTailwindDir();
|
|
3622
|
+
if (tailwindDir && raw2.includes('@import "tailwindcss"')) {
|
|
3623
|
+
const tailwindCss = readFileSync2(join3(tailwindDir, "index.css"), "utf-8");
|
|
3624
|
+
raw2 = raw2.replace('@import "tailwindcss"', tailwindCss);
|
|
3625
|
+
}
|
|
3604
3626
|
const src = `@source "${sourceDir}";
|
|
3605
3627
|
${raw2}`;
|
|
3606
3628
|
const result = await postcss([tailwindPlugin()]).process(src, { from: cssPath });
|