@coraltravelcenter/b2c-landing-builder 2.2.0 → 2.4.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 +5 -2
- package/bin/b2c-landing-vite.mjs +9 -1
- package/package.json +1 -1
- package/src/lib/rewriteImageAssets.mjs +17 -0
- package/src/presets/sunmar.mjs +1 -1
- package/src/update/check-update.mjs +13 -0
package/README.md
CHANGED
|
@@ -33,6 +33,9 @@ b2c-landing-vite update
|
|
|
33
33
|
- `block:rename` атомарно переименовывает все файлы блока и обновляет порядок.
|
|
34
34
|
- `update` проверяет npm registry и показывает команду ручного обновления.
|
|
35
35
|
|
|
36
|
+
После успешного выполнения рабочих команд builder коротко проверяет npm
|
|
37
|
+
registry. Если доступна новая стабильная версия, терминал показывает текущую и
|
|
38
|
+
новую версии и команду ручного обновления. Ошибки сети не влияют на работу CLI.
|
|
36
39
|
Builder никогда не обновляется автоматически:
|
|
37
40
|
|
|
38
41
|
```bash
|
|
@@ -93,8 +96,8 @@ Monkey URL, контейнер и CDN prefix не задаются вручну
|
|
|
93
96
|
- контейнер: `#monkey-app`;
|
|
94
97
|
- CDN prefix: `landing-pages/<project.name>`.
|
|
95
98
|
|
|
96
|
-
|
|
97
|
-
|
|
99
|
+
Для Coral и Sunmar настроены отдельные production CDN. Команда `build`
|
|
100
|
+
автоматически выбирает CDN по `site.preset`.
|
|
98
101
|
|
|
99
102
|
## Структура проекта
|
|
100
103
|
|
package/bin/b2c-landing-vite.mjs
CHANGED
|
@@ -2,7 +2,15 @@
|
|
|
2
2
|
|
|
3
3
|
import {runCli} from "../src/cli/index.mjs";
|
|
4
4
|
|
|
5
|
-
|
|
5
|
+
const args = process.argv.slice(2);
|
|
6
|
+
|
|
7
|
+
runCli(args).then(async () => {
|
|
8
|
+
const command = args[0];
|
|
9
|
+
if (!command || ["help", "--help", "-h", "update"].includes(command)) return;
|
|
10
|
+
|
|
11
|
+
const {printUpdateNotice} = await import("../src/update/check-update.mjs");
|
|
12
|
+
await printUpdateNotice();
|
|
13
|
+
}).catch((error) => {
|
|
6
14
|
console.error(`[b2c-landing-vite] ${error.message}`);
|
|
7
15
|
process.exitCode = 1;
|
|
8
16
|
});
|
package/package.json
CHANGED
|
@@ -51,6 +51,18 @@ export function rewriteCssImageUrls(cssText, options) {
|
|
|
51
51
|
);
|
|
52
52
|
}
|
|
53
53
|
|
|
54
|
+
export function rewriteJsImageUrls(jsText, options) {
|
|
55
|
+
if (!jsText || typeof jsText !== "string") return jsText;
|
|
56
|
+
|
|
57
|
+
return jsText.replace(
|
|
58
|
+
/(['"`])(\/(?!\/)[^'"`\s]+\.(?:avif|gif|jpe?g|png|svg|webp)(?:[?#][^'"`\s]*)?)\1/gi,
|
|
59
|
+
(match, quote, url) => {
|
|
60
|
+
const nextUrl = rewriteImageAssetUrl(url, options);
|
|
61
|
+
return nextUrl === url ? match : `${quote}${nextUrl}${quote}`;
|
|
62
|
+
}
|
|
63
|
+
);
|
|
64
|
+
}
|
|
65
|
+
|
|
54
66
|
export function rewriteHtmlImageAssets(html, options) {
|
|
55
67
|
if (!html || typeof html !== "string") return html;
|
|
56
68
|
|
|
@@ -81,5 +93,10 @@ export function rewriteHtmlImageAssets(html, options) {
|
|
|
81
93
|
return nextCss === css ? match : match.replace(css, nextCss);
|
|
82
94
|
});
|
|
83
95
|
|
|
96
|
+
output = output.replace(/<script\b(?![^>]*\bsrc=)[^>]*>([\s\S]*?)<\/script>/gi, (match, js) => {
|
|
97
|
+
const nextJs = rewriteJsImageUrls(js, options);
|
|
98
|
+
return nextJs === js ? match : match.replace(js, nextJs);
|
|
99
|
+
});
|
|
100
|
+
|
|
84
101
|
return output;
|
|
85
102
|
}
|
package/src/presets/sunmar.mjs
CHANGED
|
@@ -64,3 +64,16 @@ export async function printUpdateStatus(options) {
|
|
|
64
64
|
return null;
|
|
65
65
|
}
|
|
66
66
|
}
|
|
67
|
+
|
|
68
|
+
export async function printUpdateNotice({log = console.warn, timeoutMs = 1000, ...options} = {}) {
|
|
69
|
+
try {
|
|
70
|
+
const status = await checkForUpdate({...options, timeoutMs});
|
|
71
|
+
if (!status.updateAvailable) return status;
|
|
72
|
+
|
|
73
|
+
log(`New ${PACKAGE_NAME} version available: ${status.currentVersion} → ${status.latestVersion}`);
|
|
74
|
+
log(`Update manually: npm install --global ${PACKAGE_NAME}@latest`);
|
|
75
|
+
return status;
|
|
76
|
+
} catch {
|
|
77
|
+
return null;
|
|
78
|
+
}
|
|
79
|
+
}
|