@allior/wmake-cli 0.0.2 → 0.0.4
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/base64.d.ts +11 -0
- package/dist/base64.d.ts.map +1 -0
- package/dist/bin.d.ts +3 -0
- package/dist/bin.d.ts.map +1 -0
- package/dist/bin.js +76 -0
- package/dist/extract-test-data.d.ts +7 -0
- package/dist/extract-test-data.d.ts.map +1 -0
- package/dist/generate-fields-from-module-runner.d.ts +2 -0
- package/dist/generate-fields-from-module-runner.d.ts.map +1 -0
- package/dist/generate-fields.d.ts +18 -0
- package/dist/generate-fields.d.ts.map +1 -0
- package/dist/index.d.ts +9 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +8 -76
- package/dist/vite-config.d.ts +22 -0
- package/dist/vite-config.d.ts.map +1 -0
- package/dist/vite-config.js +127 -0
- package/dist/widget.d.ts +4 -0
- package/dist/widget.d.ts.map +1 -0
- package/dist/widget.js +11 -1
- package/package.json +15 -11
- package/src/bin.ts +82 -0
- package/src/index.ts +4 -96
- package/src/vite-config.ts +141 -0
- package/src/widget.ts +9 -1
- package/tsconfig.json +2 -0
package/dist/base64.d.ts
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
export interface FileInfo {
|
|
2
|
+
filename: string;
|
|
3
|
+
base64: string;
|
|
4
|
+
mimeType: string;
|
|
5
|
+
size: number;
|
|
6
|
+
}
|
|
7
|
+
export declare function isSupportedFile(filePath: string): boolean;
|
|
8
|
+
export declare function fileToBase64(filePath: string): Promise<FileInfo>;
|
|
9
|
+
export declare function getOutputPath(output: string, originalFilename: string): string;
|
|
10
|
+
export declare function processPath(inputPath: string, output: string | null, full: boolean): Promise<void>;
|
|
11
|
+
//# sourceMappingURL=base64.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"base64.d.ts","sourceRoot":"","sources":["../src/base64.ts"],"names":[],"mappings":"AAIA,MAAM,WAAW,QAAQ;IACvB,QAAQ,EAAE,MAAM,CAAC;IACjB,MAAM,EAAE,MAAM,CAAC;IACf,QAAQ,EAAE,MAAM,CAAC;IACjB,IAAI,EAAE,MAAM,CAAC;CACd;AAMD,wBAAgB,eAAe,CAAC,QAAQ,EAAE,MAAM,GAAG,OAAO,CAGzD;AAED,wBAAgB,YAAY,CAAC,QAAQ,EAAE,MAAM,GAAG,OAAO,CAAC,QAAQ,CAAC,CAkChE;AAED,wBAAgB,aAAa,CAAC,MAAM,EAAE,MAAM,EAAE,gBAAgB,EAAE,MAAM,GAAG,MAAM,CAM9E;AAED,wBAAsB,WAAW,CAC/B,SAAS,EAAE,MAAM,EACjB,MAAM,EAAE,MAAM,GAAG,IAAI,EACrB,IAAI,EAAE,OAAO,GACZ,OAAO,CAAC,IAAI,CAAC,CA4Bf"}
|
package/dist/bin.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"bin.d.ts","sourceRoot":"","sources":["../src/bin.ts"],"names":[],"mappings":""}
|
package/dist/bin.js
ADDED
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import path from "node:path";
|
|
3
|
+
import fs from "node:fs";
|
|
4
|
+
import { Command } from "commander";
|
|
5
|
+
import { processPath } from "./base64.js";
|
|
6
|
+
import { buildWidget } from "./widget.js";
|
|
7
|
+
import { runGenerateFields } from "./generate-fields.js";
|
|
8
|
+
import { runExtractTestData } from "./extract-test-data.js";
|
|
9
|
+
const program = new Command();
|
|
10
|
+
program.name("wmake").description("CLI for streamiby / wmake").version("1.0.0");
|
|
11
|
+
program
|
|
12
|
+
.command("widget")
|
|
13
|
+
.description("Build chat-demo into widget files and zip in examples/chat-demo/dist")
|
|
14
|
+
.option("--full", "Full bundle (no CDN external), like the old build")
|
|
15
|
+
.action(async (opts) => {
|
|
16
|
+
try {
|
|
17
|
+
await buildWidget({ full: opts.full });
|
|
18
|
+
}
|
|
19
|
+
catch (e) {
|
|
20
|
+
console.error(e.message);
|
|
21
|
+
process.exit(1);
|
|
22
|
+
}
|
|
23
|
+
});
|
|
24
|
+
program
|
|
25
|
+
.command("generate-fields")
|
|
26
|
+
.description("Generate fields.json from fields.base.json and test data objects (WMAKE_FIELDS_DIR)")
|
|
27
|
+
.action(async () => {
|
|
28
|
+
try {
|
|
29
|
+
const fieldsDir = process.env.WMAKE_FIELDS_DIR;
|
|
30
|
+
if (!fieldsDir?.trim()) {
|
|
31
|
+
throw new Error("WMAKE_FIELDS_DIR must be set.");
|
|
32
|
+
}
|
|
33
|
+
const mod = (await import("@allior/wmake-streamelements-events"));
|
|
34
|
+
runGenerateFields({
|
|
35
|
+
fieldsDir: path.resolve(fieldsDir),
|
|
36
|
+
testMessages: mod.testMessages,
|
|
37
|
+
testAlerts: mod.testAlerts,
|
|
38
|
+
});
|
|
39
|
+
}
|
|
40
|
+
catch (e) {
|
|
41
|
+
console.error(e.message);
|
|
42
|
+
process.exit(1);
|
|
43
|
+
}
|
|
44
|
+
});
|
|
45
|
+
program
|
|
46
|
+
.command("extract-test-data")
|
|
47
|
+
.description("No-op: test data lives in streamelements/src/assets as TS objects")
|
|
48
|
+
.action(async () => {
|
|
49
|
+
try {
|
|
50
|
+
await runExtractTestData();
|
|
51
|
+
}
|
|
52
|
+
catch (e) {
|
|
53
|
+
console.error(e.message);
|
|
54
|
+
process.exit(1);
|
|
55
|
+
}
|
|
56
|
+
});
|
|
57
|
+
program
|
|
58
|
+
.command("base64")
|
|
59
|
+
.description("Convert images, videos, SVG to base64 for browsers")
|
|
60
|
+
.argument("<path>", "File or directory path")
|
|
61
|
+
.option("-o, --output <path>", "Output file or directory")
|
|
62
|
+
.option("-f, --full", "Output with additional info")
|
|
63
|
+
.action(async (inputPath, options) => {
|
|
64
|
+
if (!fs.existsSync(inputPath)) {
|
|
65
|
+
console.error("Error: Path does not exist");
|
|
66
|
+
process.exit(1);
|
|
67
|
+
}
|
|
68
|
+
try {
|
|
69
|
+
await processPath(inputPath, options.output ?? null, options.full ?? false);
|
|
70
|
+
}
|
|
71
|
+
catch (e) {
|
|
72
|
+
console.error("Error:", e.message);
|
|
73
|
+
process.exit(1);
|
|
74
|
+
}
|
|
75
|
+
});
|
|
76
|
+
program.parse();
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Раньше создавал test-messages.json и test-alerts.json в streamelements/src/assets.
|
|
3
|
+
* Теперь тестовые данные — объекты в скриптах: streamelements/src/assets/test-messages.ts и test-alerts.ts.
|
|
4
|
+
* Команда оставлена для совместимости (no-op).
|
|
5
|
+
*/
|
|
6
|
+
export declare function runExtractTestData(): Promise<void>;
|
|
7
|
+
//# sourceMappingURL=extract-test-data.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"extract-test-data.d.ts","sourceRoot":"","sources":["../src/extract-test-data.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,wBAAsB,kBAAkB,IAAI,OAAO,CAAC,IAAI,CAAC,CAIxD"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"generate-fields-from-module-runner.d.ts","sourceRoot":"","sources":["../src/generate-fields-from-module-runner.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Генерирует fields.json из fields.base.json и ключей из объектов testMessages / testAlerts.
|
|
3
|
+
* Путь к каталогу с fields.base.json задаётся WMAKE_FIELDS_DIR.
|
|
4
|
+
* Данные сообщений и алертов передаются объектами (из скриптов streamelements).
|
|
5
|
+
*/
|
|
6
|
+
export type MessagesRecord = Record<string, unknown>;
|
|
7
|
+
export type AlertsRecord = Record<string, unknown>;
|
|
8
|
+
export declare function runGenerateFields(options: {
|
|
9
|
+
fieldsDir: string;
|
|
10
|
+
testMessages: MessagesRecord;
|
|
11
|
+
testAlerts: AlertsRecord;
|
|
12
|
+
}): void;
|
|
13
|
+
/**
|
|
14
|
+
* Генерирует fields.json из TS/JS модуля, экспортирующего default AdvancedField[].
|
|
15
|
+
* Использует tsx для загрузки .ts файлов.
|
|
16
|
+
*/
|
|
17
|
+
export declare function runGenerateFieldsFromModule(fieldsModulePath: string): void;
|
|
18
|
+
//# sourceMappingURL=generate-fields.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"generate-fields.d.ts","sourceRoot":"","sources":["../src/generate-fields.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAgCH,MAAM,MAAM,cAAc,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;AACrD,MAAM,MAAM,YAAY,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;AAEnD,wBAAgB,iBAAiB,CAAC,OAAO,EAAE;IACzC,SAAS,EAAE,MAAM,CAAC;IAClB,YAAY,EAAE,cAAc,CAAC;IAC7B,UAAU,EAAE,YAAY,CAAC;CAC1B,GAAG,IAAI,CAkDP;AAED;;;GAGG;AACH,wBAAgB,2BAA2B,CAAC,gBAAgB,EAAE,MAAM,GAAG,IAAI,CAiB1E"}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Библиотека экспортов для использования в других пакетах (например, в Vite конфигах).
|
|
3
|
+
* ВАЖНО: Не запускает CLI автоматически при импорте.
|
|
4
|
+
*/
|
|
5
|
+
export * from "./vite-config.js";
|
|
6
|
+
export { buildWidget } from "./widget.js";
|
|
7
|
+
export { runGenerateFields } from "./generate-fields.js";
|
|
8
|
+
export { runExtractTestData } from "./extract-test-data.js";
|
|
9
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,cAAc,kBAAkB,CAAC;AACjC,OAAO,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAC1C,OAAO,EAAE,iBAAiB,EAAE,MAAM,sBAAsB,CAAC;AACzD,OAAO,EAAE,kBAAkB,EAAE,MAAM,wBAAwB,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -1,76 +1,8 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
const program = new Command();
|
|
10
|
-
program.name("wmake").description("CLI for streamiby / wmake").version("1.0.0");
|
|
11
|
-
program
|
|
12
|
-
.command("widget")
|
|
13
|
-
.description("Build chat-demo into widget files and zip in examples/chat-demo/dist")
|
|
14
|
-
.option("--full", "Full bundle (no CDN external), like the old build")
|
|
15
|
-
.action(async (opts) => {
|
|
16
|
-
try {
|
|
17
|
-
await buildWidget({ full: opts.full });
|
|
18
|
-
}
|
|
19
|
-
catch (e) {
|
|
20
|
-
console.error(e.message);
|
|
21
|
-
process.exit(1);
|
|
22
|
-
}
|
|
23
|
-
});
|
|
24
|
-
program
|
|
25
|
-
.command("generate-fields")
|
|
26
|
-
.description("Generate fields.json from fields.base.json and test data objects (WMAKE_FIELDS_DIR)")
|
|
27
|
-
.action(async () => {
|
|
28
|
-
try {
|
|
29
|
-
const fieldsDir = process.env.WMAKE_FIELDS_DIR;
|
|
30
|
-
if (!fieldsDir?.trim()) {
|
|
31
|
-
throw new Error("WMAKE_FIELDS_DIR must be set.");
|
|
32
|
-
}
|
|
33
|
-
const mod = (await import("@allior/wmake-streamelements-events"));
|
|
34
|
-
runGenerateFields({
|
|
35
|
-
fieldsDir: path.resolve(fieldsDir),
|
|
36
|
-
testMessages: mod.testMessages,
|
|
37
|
-
testAlerts: mod.testAlerts,
|
|
38
|
-
});
|
|
39
|
-
}
|
|
40
|
-
catch (e) {
|
|
41
|
-
console.error(e.message);
|
|
42
|
-
process.exit(1);
|
|
43
|
-
}
|
|
44
|
-
});
|
|
45
|
-
program
|
|
46
|
-
.command("extract-test-data")
|
|
47
|
-
.description("No-op: test data lives in streamelements/src/assets as TS objects")
|
|
48
|
-
.action(async () => {
|
|
49
|
-
try {
|
|
50
|
-
await runExtractTestData();
|
|
51
|
-
}
|
|
52
|
-
catch (e) {
|
|
53
|
-
console.error(e.message);
|
|
54
|
-
process.exit(1);
|
|
55
|
-
}
|
|
56
|
-
});
|
|
57
|
-
program
|
|
58
|
-
.command("base64")
|
|
59
|
-
.description("Convert images, videos, SVG to base64 for browsers")
|
|
60
|
-
.argument("<path>", "File or directory path")
|
|
61
|
-
.option("-o, --output <path>", "Output file or directory")
|
|
62
|
-
.option("-f, --full", "Output with additional info")
|
|
63
|
-
.action(async (inputPath, options) => {
|
|
64
|
-
if (!fs.existsSync(inputPath)) {
|
|
65
|
-
console.error("Error: Path does not exist");
|
|
66
|
-
process.exit(1);
|
|
67
|
-
}
|
|
68
|
-
try {
|
|
69
|
-
await processPath(inputPath, options.output ?? null, options.full ?? false);
|
|
70
|
-
}
|
|
71
|
-
catch (e) {
|
|
72
|
-
console.error("Error:", e.message);
|
|
73
|
-
process.exit(1);
|
|
74
|
-
}
|
|
75
|
-
});
|
|
76
|
-
program.parse();
|
|
1
|
+
/**
|
|
2
|
+
* Библиотека экспортов для использования в других пакетах (например, в Vite конфигах).
|
|
3
|
+
* ВАЖНО: Не запускает CLI автоматически при импорте.
|
|
4
|
+
*/
|
|
5
|
+
export * from "./vite-config.js";
|
|
6
|
+
export { buildWidget } from "./widget.js";
|
|
7
|
+
export { runGenerateFields } from "./generate-fields.js";
|
|
8
|
+
export { runExtractTestData } from "./extract-test-data.js";
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { PluginOption } from "vite";
|
|
2
|
+
export declare const CDN_BASE = "https://cdn.jsdelivr.net/npm";
|
|
3
|
+
export declare const REACT_VER = "19.0.0";
|
|
4
|
+
export declare const WMAKE_VER = "1.0.0";
|
|
5
|
+
export declare const EXTERNAL_FOR_CDN: Set<string>;
|
|
6
|
+
export declare function wmakeImportMapPlugin(): PluginOption;
|
|
7
|
+
export declare function getWmakeAliases(root: string): {
|
|
8
|
+
"@allior/wmake-streamelements-events/react": string;
|
|
9
|
+
"@allior/wmake-streamelements-events": string;
|
|
10
|
+
"@allior/wmake-utils/react": string;
|
|
11
|
+
"@allior/wmake-utils": string;
|
|
12
|
+
"@allior/wmake-emotes/react": string;
|
|
13
|
+
"@allior/wmake-emotes/7tv": string;
|
|
14
|
+
"@allior/wmake-emotes": string;
|
|
15
|
+
"@allior/wmake-streamelements/react": string;
|
|
16
|
+
"@allior/wmake-streamelements/fields": string;
|
|
17
|
+
"@allior/wmake-streamelements": string;
|
|
18
|
+
};
|
|
19
|
+
export declare function getWmakeOptimizeDeps(): {
|
|
20
|
+
include: string[];
|
|
21
|
+
};
|
|
22
|
+
//# sourceMappingURL=vite-config.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"vite-config.d.ts","sourceRoot":"","sources":["../src/vite-config.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,YAAY,EAAE,MAAM,MAAM,CAAC;AAEpC,eAAO,MAAM,QAAQ,iCAAiC,CAAC;AACvD,eAAO,MAAM,SAAS,WAAW,CAAC;AAClC,eAAO,MAAM,SAAS,UAAU,CAAC;AAEjC,eAAO,MAAM,gBAAgB,aAW3B,CAAC;AA4CH,wBAAgB,oBAAoB,IAAI,YAAY,CAmDnD;AAED,wBAAgB,eAAe,CAAC,IAAI,EAAE,MAAM;;;;;;;;;;;EAa3C;AAED,wBAAgB,oBAAoB;;EASnC"}
|
|
@@ -0,0 +1,127 @@
|
|
|
1
|
+
import path from "node:path";
|
|
2
|
+
import fs from "node:fs";
|
|
3
|
+
export const CDN_BASE = "https://cdn.jsdelivr.net/npm";
|
|
4
|
+
export const REACT_VER = "19.0.0";
|
|
5
|
+
export const WMAKE_VER = "1.0.0";
|
|
6
|
+
export const EXTERNAL_FOR_CDN = new Set([
|
|
7
|
+
"react",
|
|
8
|
+
"react/jsx-runtime",
|
|
9
|
+
"react-dom",
|
|
10
|
+
"react-dom/client",
|
|
11
|
+
"@allior/wmake-utils",
|
|
12
|
+
"@allior/wmake-utils/react",
|
|
13
|
+
"@allior/wmake-streamelements-events",
|
|
14
|
+
"@allior/wmake-streamelements-events/react",
|
|
15
|
+
"@allior/wmake-emotes/7tv",
|
|
16
|
+
"@allior/wmake-streamelements",
|
|
17
|
+
]);
|
|
18
|
+
const BOOTSTRAP_PLACEHOLDER_SRC = "__MAIN_SCRIPT_SRC__";
|
|
19
|
+
const BOOTSTRAP_PLACEHOLDER_VER = "__DEFAULT_WMAKE_VER__";
|
|
20
|
+
const bootstrapScript = `
|
|
21
|
+
(function(){
|
|
22
|
+
var CDN_BASE='${CDN_BASE}';
|
|
23
|
+
var REACT_VER='${REACT_VER}';
|
|
24
|
+
var defaultVer='${BOOTSTRAP_PLACEHOLDER_VER}';
|
|
25
|
+
var mainScriptSrc='${BOOTSTRAP_PLACEHOLDER_SRC}';
|
|
26
|
+
function run(ver){
|
|
27
|
+
var v=ver||defaultVer;
|
|
28
|
+
var map={imports:{
|
|
29
|
+
'react':CDN_BASE+'/react@'+REACT_VER+'/+esm',
|
|
30
|
+
'react/jsx-runtime':CDN_BASE+'/react@'+REACT_VER+'/jsx-runtime.js',
|
|
31
|
+
'react-dom':CDN_BASE+'/react-dom@'+REACT_VER+'/+esm',
|
|
32
|
+
'react-dom/client':CDN_BASE+'/react-dom@'+REACT_VER+'/client.js',
|
|
33
|
+
'@allior/wmake-utils':CDN_BASE+'/@allior/wmake-utils@'+v+'/dist/root/index.js',
|
|
34
|
+
'@allior/wmake-utils/react':CDN_BASE+'/@allior/wmake-utils@'+v+'/dist/react/index.js',
|
|
35
|
+
'@allior/wmake-streamelements-events':CDN_BASE+'/@allior/wmake-streamelements-events@'+v+'/dist/root/index.js',
|
|
36
|
+
'@allior/wmake-streamelements-events/react':CDN_BASE+'/@allior/wmake-streamelements-events@'+v+'/dist/react/index.js',
|
|
37
|
+
'@allior/wmake-emotes/7tv':CDN_BASE+'/@allior/wmake-emotes@'+v+'/dist/7tv/index.js',
|
|
38
|
+
'@allior/wmake-streamelements':CDN_BASE+'/@allior/wmake-streamelements@'+v+'/dist/root/index.js'
|
|
39
|
+
}};
|
|
40
|
+
var s=document.createElement('script');
|
|
41
|
+
s.type='importmap';
|
|
42
|
+
s.textContent=JSON.stringify(map);
|
|
43
|
+
document.head.appendChild(s);
|
|
44
|
+
var m=document.createElement('script');
|
|
45
|
+
m.type='module';
|
|
46
|
+
m.src=mainScriptSrc;
|
|
47
|
+
document.body.appendChild(m);
|
|
48
|
+
}
|
|
49
|
+
if(typeof window.addEventListener==='function'){
|
|
50
|
+
window.addEventListener('onWidgetLoad',function(obj){
|
|
51
|
+
var fd=obj.detail&&obj.detail.fieldData;
|
|
52
|
+
run(fd&&fd.wmakeVersion);
|
|
53
|
+
});
|
|
54
|
+
setTimeout(function(){if(!document.querySelector('script[type="importmap"]'))run(defaultVer);},100);
|
|
55
|
+
}else{run(defaultVer);}
|
|
56
|
+
})();
|
|
57
|
+
`;
|
|
58
|
+
export function wmakeImportMapPlugin() {
|
|
59
|
+
const imports = {
|
|
60
|
+
react: `${CDN_BASE}/react@${REACT_VER}/+esm`,
|
|
61
|
+
"react/jsx-runtime": `${CDN_BASE}/react@${REACT_VER}/jsx-runtime.js`,
|
|
62
|
+
"react-dom": `${CDN_BASE}/react-dom@${REACT_VER}/+esm`,
|
|
63
|
+
"react-dom/client": `${CDN_BASE}/react-dom@${REACT_VER}/client.js`,
|
|
64
|
+
"@allior/wmake-utils": `${CDN_BASE}/@allior/wmake-utils@${WMAKE_VER}/dist/root/index.js`,
|
|
65
|
+
"@allior/wmake-utils/react": `${CDN_BASE}/@allior/wmake-utils@${WMAKE_VER}/dist/react/index.js`,
|
|
66
|
+
"@allior/wmake-streamelements-events": `${CDN_BASE}/@allior/wmake-streamelements-events@${WMAKE_VER}/dist/root/index.js`,
|
|
67
|
+
"@allior/wmake-streamelements-events/react": `${CDN_BASE}/@allior/wmake-streamelements-events@${WMAKE_VER}/dist/react/index.js`,
|
|
68
|
+
"@allior/wmake-emotes/7tv": `${CDN_BASE}/@allior/wmake-emotes@${WMAKE_VER}/dist/7tv/index.js`,
|
|
69
|
+
"@allior/wmake-streamelements": `${CDN_BASE}/@allior/wmake-streamelements@${WMAKE_VER}/dist/root/index.js`,
|
|
70
|
+
};
|
|
71
|
+
const importMap = { imports };
|
|
72
|
+
const staticImportMapScript = `<script type="importmap">${JSON.stringify(importMap)}</script>`;
|
|
73
|
+
return {
|
|
74
|
+
name: "importmap-cdn",
|
|
75
|
+
transformIndexHtml: {
|
|
76
|
+
order: "post",
|
|
77
|
+
handler(html, ctx) {
|
|
78
|
+
const isBuild = !ctx.server;
|
|
79
|
+
if (isBuild) {
|
|
80
|
+
const script = "<script>\n" + bootstrapScript.trim() + "\n</script>";
|
|
81
|
+
return html.replace(/(<head[^>]*>)/i, "$1\n" + script);
|
|
82
|
+
}
|
|
83
|
+
return staticImportMapScript + "\n" + html;
|
|
84
|
+
},
|
|
85
|
+
},
|
|
86
|
+
writeBundle(options) {
|
|
87
|
+
const outDir = options.dir ?? "dist";
|
|
88
|
+
const htmlPath = path.join(outDir, "index.html");
|
|
89
|
+
if (!fs.existsSync(htmlPath))
|
|
90
|
+
return;
|
|
91
|
+
let html = fs.readFileSync(htmlPath, "utf-8");
|
|
92
|
+
const scriptTagMatch = html.match(/<script(?=[^>]*type=["']module["'])(?=[^>]*src=)[^>]*src=["']([^"']+)["'][^>]*>\s*<\/script>/);
|
|
93
|
+
if (!scriptTagMatch)
|
|
94
|
+
return;
|
|
95
|
+
const mainScriptSrc = scriptTagMatch[1];
|
|
96
|
+
html = html
|
|
97
|
+
.replace(BOOTSTRAP_PLACEHOLDER_VER, WMAKE_VER)
|
|
98
|
+
.replace(BOOTSTRAP_PLACEHOLDER_SRC, mainScriptSrc)
|
|
99
|
+
.replace(scriptTagMatch[0], "");
|
|
100
|
+
fs.writeFileSync(htmlPath, html);
|
|
101
|
+
},
|
|
102
|
+
};
|
|
103
|
+
}
|
|
104
|
+
export function getWmakeAliases(root) {
|
|
105
|
+
return {
|
|
106
|
+
"@allior/wmake-streamelements-events/react": path.join(root, "streamelements-events/dist/react/index.js"),
|
|
107
|
+
"@allior/wmake-streamelements-events": path.join(root, "streamelements-events/dist/root/index.js"),
|
|
108
|
+
"@allior/wmake-utils/react": path.join(root, "utils/dist/react/index.js"),
|
|
109
|
+
"@allior/wmake-utils": path.join(root, "utils/dist/root/index.js"),
|
|
110
|
+
"@allior/wmake-emotes/react": path.join(root, "emotes/dist/react/index.js"),
|
|
111
|
+
"@allior/wmake-emotes/7tv": path.join(root, "emotes/dist/7tv/index.js"),
|
|
112
|
+
"@allior/wmake-emotes": path.join(root, "emotes/dist/root/index.js"),
|
|
113
|
+
"@allior/wmake-streamelements/react": path.join(root, "streamelements/dist/react/index.js"),
|
|
114
|
+
"@allior/wmake-streamelements/fields": path.join(root, "streamelements/dist/fields/index.js"),
|
|
115
|
+
"@allior/wmake-streamelements": path.join(root, "streamelements/dist/root/index.js"),
|
|
116
|
+
};
|
|
117
|
+
}
|
|
118
|
+
export function getWmakeOptimizeDeps() {
|
|
119
|
+
return {
|
|
120
|
+
include: [
|
|
121
|
+
"@allior/wmake-streamelements-events",
|
|
122
|
+
"@allior/wmake-utils",
|
|
123
|
+
"@allior/wmake-emotes/7tv",
|
|
124
|
+
"@allior/wmake-streamelements",
|
|
125
|
+
],
|
|
126
|
+
};
|
|
127
|
+
}
|
package/dist/widget.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"widget.d.ts","sourceRoot":"","sources":["../src/widget.ts"],"names":[],"mappings":"AAwCA,wBAAsB,WAAW,CAAC,OAAO,EAAE;IAAE,IAAI,CAAC,EAAE,OAAO,CAAA;CAAE,GAAG,OAAO,CAAC,IAAI,CAAC,CA0I5E"}
|
package/dist/widget.js
CHANGED
|
@@ -19,6 +19,16 @@ function run(cmd, args, cwd, env) {
|
|
|
19
19
|
});
|
|
20
20
|
return r.status === 0;
|
|
21
21
|
}
|
|
22
|
+
function getPackageManager() {
|
|
23
|
+
const userAgent = process.env.npm_config_user_agent || "";
|
|
24
|
+
if (userAgent.includes("bun"))
|
|
25
|
+
return "bun";
|
|
26
|
+
if (userAgent.includes("pnpm"))
|
|
27
|
+
return "pnpm";
|
|
28
|
+
if (userAgent.includes("yarn"))
|
|
29
|
+
return "yarn";
|
|
30
|
+
return "npm";
|
|
31
|
+
}
|
|
22
32
|
export async function buildWidget(options) {
|
|
23
33
|
const projectDir = getProjectDir();
|
|
24
34
|
const distDir = path.join(projectDir, "dist");
|
|
@@ -43,7 +53,7 @@ export async function buildWidget(options) {
|
|
|
43
53
|
}
|
|
44
54
|
console.log("Building...");
|
|
45
55
|
const buildEnv = options.full ? { BUILD_FULL: "1" } : {};
|
|
46
|
-
if (!run(
|
|
56
|
+
if (!run(getPackageManager(), ["run", "build"], projectDir, buildEnv)) {
|
|
47
57
|
throw new Error("Build failed.");
|
|
48
58
|
}
|
|
49
59
|
if (!fs.existsSync(distDir)) {
|
package/package.json
CHANGED
|
@@ -1,27 +1,31 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@allior/wmake-cli",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.4",
|
|
4
4
|
"description": "Streamiby/wmake CLI: build widgets, base64 encode assets, generate fields",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "dist/index.js",
|
|
7
7
|
"bin": {
|
|
8
|
-
"wmake-cli": "dist/
|
|
9
|
-
"@allior/wmake-cli": "dist/
|
|
8
|
+
"wmake-cli": "dist/bin.js",
|
|
9
|
+
"@allior/wmake-cli": "dist/bin.js"
|
|
10
|
+
},
|
|
11
|
+
"scripts": {
|
|
12
|
+
"pub": "npm publish --access public",
|
|
13
|
+
"build": "tsc",
|
|
14
|
+
"start": "node dist/index.js",
|
|
15
|
+
"dev": "tsx src/index.ts"
|
|
10
16
|
},
|
|
11
17
|
"dependencies": {
|
|
18
|
+
"@allior/wmake-streamelements-events": "^0.0.3",
|
|
19
|
+
"@vitejs/plugin-react": "^6.0.1",
|
|
20
|
+
"adm-zip": "^0.5.16",
|
|
12
21
|
"commander": "^11.1.0",
|
|
13
22
|
"mime-types": "^2.1.35",
|
|
14
|
-
"
|
|
15
|
-
"@allior/wmake-streamelements-events": "^0.0.3"
|
|
23
|
+
"vite": "^6.4.1"
|
|
16
24
|
},
|
|
17
25
|
"devDependencies": {
|
|
26
|
+
"@types/adm-zip": "^0.5.8",
|
|
18
27
|
"@types/mime-types": "^2.1.4",
|
|
19
28
|
"ts-node": "^10.9.0",
|
|
20
29
|
"tsx": "^4.20.6"
|
|
21
|
-
},
|
|
22
|
-
"scripts": {
|
|
23
|
-
"build": "tsc",
|
|
24
|
-
"start": "node dist/index.js",
|
|
25
|
-
"dev": "tsx src/index.ts"
|
|
26
30
|
}
|
|
27
|
-
}
|
|
31
|
+
}
|
package/src/bin.ts
ADDED
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import path from "node:path";
|
|
3
|
+
import fs from "node:fs";
|
|
4
|
+
import { Command } from "commander";
|
|
5
|
+
import { processPath } from "./base64.js";
|
|
6
|
+
import { buildWidget } from "./widget.js";
|
|
7
|
+
import { runGenerateFields } from "./generate-fields.js";
|
|
8
|
+
import { runExtractTestData } from "./extract-test-data.js";
|
|
9
|
+
|
|
10
|
+
const program = new Command();
|
|
11
|
+
|
|
12
|
+
program.name("wmake").description("CLI for streamiby / wmake").version("1.0.0");
|
|
13
|
+
|
|
14
|
+
program
|
|
15
|
+
.command("widget")
|
|
16
|
+
.description("Build chat-demo into widget files and zip in examples/chat-demo/dist")
|
|
17
|
+
.option("--full", "Full bundle (no CDN external), like the old build")
|
|
18
|
+
.action(async (opts: { full?: boolean }) => {
|
|
19
|
+
try {
|
|
20
|
+
await buildWidget({ full: opts.full });
|
|
21
|
+
} catch (e) {
|
|
22
|
+
console.error((e as Error).message);
|
|
23
|
+
process.exit(1);
|
|
24
|
+
}
|
|
25
|
+
});
|
|
26
|
+
|
|
27
|
+
program
|
|
28
|
+
.command("generate-fields")
|
|
29
|
+
.description("Generate fields.json from fields.base.json and test data objects (WMAKE_FIELDS_DIR)")
|
|
30
|
+
.action(async () => {
|
|
31
|
+
try {
|
|
32
|
+
const fieldsDir = process.env.WMAKE_FIELDS_DIR;
|
|
33
|
+
if (!fieldsDir?.trim()) {
|
|
34
|
+
throw new Error("WMAKE_FIELDS_DIR must be set.");
|
|
35
|
+
}
|
|
36
|
+
const mod = (await import("@allior/wmake-streamelements-events")) as unknown as {
|
|
37
|
+
testMessages: Record<string, unknown>;
|
|
38
|
+
testAlerts: Record<string, unknown>;
|
|
39
|
+
};
|
|
40
|
+
runGenerateFields({
|
|
41
|
+
fieldsDir: path.resolve(fieldsDir),
|
|
42
|
+
testMessages: mod.testMessages,
|
|
43
|
+
testAlerts: mod.testAlerts,
|
|
44
|
+
});
|
|
45
|
+
} catch (e) {
|
|
46
|
+
console.error((e as Error).message);
|
|
47
|
+
process.exit(1);
|
|
48
|
+
}
|
|
49
|
+
});
|
|
50
|
+
|
|
51
|
+
program
|
|
52
|
+
.command("extract-test-data")
|
|
53
|
+
.description("No-op: test data lives in streamelements/src/assets as TS objects")
|
|
54
|
+
.action(async () => {
|
|
55
|
+
try {
|
|
56
|
+
await runExtractTestData();
|
|
57
|
+
} catch (e) {
|
|
58
|
+
console.error((e as Error).message);
|
|
59
|
+
process.exit(1);
|
|
60
|
+
}
|
|
61
|
+
});
|
|
62
|
+
|
|
63
|
+
program
|
|
64
|
+
.command("base64")
|
|
65
|
+
.description("Convert images, videos, SVG to base64 for browsers")
|
|
66
|
+
.argument("<path>", "File or directory path")
|
|
67
|
+
.option("-o, --output <path>", "Output file or directory")
|
|
68
|
+
.option("-f, --full", "Output with additional info")
|
|
69
|
+
.action(async (inputPath: string, options: { output?: string; full?: boolean }) => {
|
|
70
|
+
if (!fs.existsSync(inputPath)) {
|
|
71
|
+
console.error("Error: Path does not exist");
|
|
72
|
+
process.exit(1);
|
|
73
|
+
}
|
|
74
|
+
try {
|
|
75
|
+
await processPath(inputPath, options.output ?? null, options.full ?? false);
|
|
76
|
+
} catch (e) {
|
|
77
|
+
console.error("Error:", (e as Error).message);
|
|
78
|
+
process.exit(1);
|
|
79
|
+
}
|
|
80
|
+
});
|
|
81
|
+
|
|
82
|
+
program.parse();
|
package/src/index.ts
CHANGED
|
@@ -1,96 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
import * as fs from "fs";
|
|
6
|
-
import { processPath } from "./base64.js";
|
|
7
|
-
import { buildWidget } from "./widget.js";
|
|
8
|
-
import { runGenerateFields } from "./generate-fields.js";
|
|
9
|
-
import { runExtractTestData } from "./extract-test-data.js";
|
|
10
|
-
|
|
11
|
-
const program = new Command();
|
|
12
|
-
|
|
13
|
-
program.name("wmake").description("CLI for streamiby / wmake").version("1.0.0");
|
|
14
|
-
|
|
15
|
-
program
|
|
16
|
-
.command("widget")
|
|
17
|
-
.description(
|
|
18
|
-
"Build chat-demo into widget files and zip in examples/chat-demo/dist",
|
|
19
|
-
)
|
|
20
|
-
.option("--full", "Full bundle (no CDN external), like the old build")
|
|
21
|
-
.action(async (opts: { full?: boolean }) => {
|
|
22
|
-
try {
|
|
23
|
-
await buildWidget({ full: opts.full });
|
|
24
|
-
} catch (e) {
|
|
25
|
-
console.error((e as Error).message);
|
|
26
|
-
process.exit(1);
|
|
27
|
-
}
|
|
28
|
-
});
|
|
29
|
-
|
|
30
|
-
program
|
|
31
|
-
.command("generate-fields")
|
|
32
|
-
.description(
|
|
33
|
-
"Generate fields.json from fields.base.json and test data objects (WMAKE_FIELDS_DIR)",
|
|
34
|
-
)
|
|
35
|
-
.action(async () => {
|
|
36
|
-
try {
|
|
37
|
-
const fieldsDir = process.env.WMAKE_FIELDS_DIR;
|
|
38
|
-
if (!fieldsDir?.trim()) {
|
|
39
|
-
throw new Error("WMAKE_FIELDS_DIR must be set.");
|
|
40
|
-
}
|
|
41
|
-
const mod =
|
|
42
|
-
(await import("@allior/wmake-streamelements-events")) as unknown as {
|
|
43
|
-
testMessages: Record<string, unknown>;
|
|
44
|
-
testAlerts: Record<string, unknown>;
|
|
45
|
-
};
|
|
46
|
-
runGenerateFields({
|
|
47
|
-
fieldsDir: path.resolve(fieldsDir),
|
|
48
|
-
testMessages: mod.testMessages,
|
|
49
|
-
testAlerts: mod.testAlerts,
|
|
50
|
-
});
|
|
51
|
-
} catch (e) {
|
|
52
|
-
console.error((e as Error).message);
|
|
53
|
-
process.exit(1);
|
|
54
|
-
}
|
|
55
|
-
});
|
|
56
|
-
|
|
57
|
-
program
|
|
58
|
-
.command("extract-test-data")
|
|
59
|
-
.description(
|
|
60
|
-
"No-op: test data lives in streamelements/src/assets as TS objects",
|
|
61
|
-
)
|
|
62
|
-
.action(async () => {
|
|
63
|
-
try {
|
|
64
|
-
await runExtractTestData();
|
|
65
|
-
} catch (e) {
|
|
66
|
-
console.error((e as Error).message);
|
|
67
|
-
process.exit(1);
|
|
68
|
-
}
|
|
69
|
-
});
|
|
70
|
-
|
|
71
|
-
program
|
|
72
|
-
.command("base64")
|
|
73
|
-
.description("Convert images, videos, SVG to base64 for browsers")
|
|
74
|
-
.argument("<path>", "File or directory path")
|
|
75
|
-
.option("-o, --output <path>", "Output file or directory")
|
|
76
|
-
.option("-f, --full", "Output with additional info")
|
|
77
|
-
.action(
|
|
78
|
-
async (inputPath: string, options: { output?: string; full?: boolean }) => {
|
|
79
|
-
if (!fs.existsSync(inputPath)) {
|
|
80
|
-
console.error("Error: Path does not exist");
|
|
81
|
-
process.exit(1);
|
|
82
|
-
}
|
|
83
|
-
try {
|
|
84
|
-
await processPath(
|
|
85
|
-
inputPath,
|
|
86
|
-
options.output ?? null,
|
|
87
|
-
options.full ?? false,
|
|
88
|
-
);
|
|
89
|
-
} catch (e) {
|
|
90
|
-
console.error("Error:", (e as Error).message);
|
|
91
|
-
process.exit(1);
|
|
92
|
-
}
|
|
93
|
-
},
|
|
94
|
-
);
|
|
95
|
-
|
|
96
|
-
program.parse();
|
|
1
|
+
export * from "./vite-config.js";
|
|
2
|
+
export { buildWidget } from "./widget.js";
|
|
3
|
+
export { runGenerateFields } from "./generate-fields.js";
|
|
4
|
+
export { runExtractTestData } from "./extract-test-data.js";
|
|
@@ -0,0 +1,141 @@
|
|
|
1
|
+
import path from "node:path";
|
|
2
|
+
import fs from "node:fs";
|
|
3
|
+
import { PluginOption } from "vite";
|
|
4
|
+
|
|
5
|
+
export const CDN_BASE = "https://cdn.jsdelivr.net/npm";
|
|
6
|
+
export const REACT_VER = "19.0.0";
|
|
7
|
+
export const WMAKE_VER = "1.0.0";
|
|
8
|
+
|
|
9
|
+
export const EXTERNAL_FOR_CDN = new Set([
|
|
10
|
+
"react",
|
|
11
|
+
"react/jsx-runtime",
|
|
12
|
+
"react-dom",
|
|
13
|
+
"react-dom/client",
|
|
14
|
+
"@allior/wmake-utils",
|
|
15
|
+
"@allior/wmake-utils/react",
|
|
16
|
+
"@allior/wmake-streamelements-events",
|
|
17
|
+
"@allior/wmake-streamelements-events/react",
|
|
18
|
+
"@allior/wmake-emotes/7tv",
|
|
19
|
+
"@allior/wmake-streamelements",
|
|
20
|
+
]);
|
|
21
|
+
|
|
22
|
+
const BOOTSTRAP_PLACEHOLDER_SRC = "__MAIN_SCRIPT_SRC__";
|
|
23
|
+
const BOOTSTRAP_PLACEHOLDER_VER = "__DEFAULT_WMAKE_VER__";
|
|
24
|
+
|
|
25
|
+
const bootstrapScript = `
|
|
26
|
+
(function(){
|
|
27
|
+
var CDN_BASE='${CDN_BASE}';
|
|
28
|
+
var REACT_VER='${REACT_VER}';
|
|
29
|
+
var defaultVer='${BOOTSTRAP_PLACEHOLDER_VER}';
|
|
30
|
+
var mainScriptSrc='${BOOTSTRAP_PLACEHOLDER_SRC}';
|
|
31
|
+
function run(ver){
|
|
32
|
+
var v=ver||defaultVer;
|
|
33
|
+
var map={imports:{
|
|
34
|
+
'react':CDN_BASE+'/react@'+REACT_VER+'/+esm',
|
|
35
|
+
'react/jsx-runtime':CDN_BASE+'/react@'+REACT_VER+'/jsx-runtime.js',
|
|
36
|
+
'react-dom':CDN_BASE+'/react-dom@'+REACT_VER+'/+esm',
|
|
37
|
+
'react-dom/client':CDN_BASE+'/react-dom@'+REACT_VER+'/client.js',
|
|
38
|
+
'@allior/wmake-utils':CDN_BASE+'/@allior/wmake-utils@'+v+'/dist/root/index.js',
|
|
39
|
+
'@allior/wmake-utils/react':CDN_BASE+'/@allior/wmake-utils@'+v+'/dist/react/index.js',
|
|
40
|
+
'@allior/wmake-streamelements-events':CDN_BASE+'/@allior/wmake-streamelements-events@'+v+'/dist/root/index.js',
|
|
41
|
+
'@allior/wmake-streamelements-events/react':CDN_BASE+'/@allior/wmake-streamelements-events@'+v+'/dist/react/index.js',
|
|
42
|
+
'@allior/wmake-emotes/7tv':CDN_BASE+'/@allior/wmake-emotes@'+v+'/dist/7tv/index.js',
|
|
43
|
+
'@allior/wmake-streamelements':CDN_BASE+'/@allior/wmake-streamelements@'+v+'/dist/root/index.js'
|
|
44
|
+
}};
|
|
45
|
+
var s=document.createElement('script');
|
|
46
|
+
s.type='importmap';
|
|
47
|
+
s.textContent=JSON.stringify(map);
|
|
48
|
+
document.head.appendChild(s);
|
|
49
|
+
var m=document.createElement('script');
|
|
50
|
+
m.type='module';
|
|
51
|
+
m.src=mainScriptSrc;
|
|
52
|
+
document.body.appendChild(m);
|
|
53
|
+
}
|
|
54
|
+
if(typeof window.addEventListener==='function'){
|
|
55
|
+
window.addEventListener('onWidgetLoad',function(obj){
|
|
56
|
+
var fd=obj.detail&&obj.detail.fieldData;
|
|
57
|
+
run(fd&&fd.wmakeVersion);
|
|
58
|
+
});
|
|
59
|
+
setTimeout(function(){if(!document.querySelector('script[type="importmap"]'))run(defaultVer);},100);
|
|
60
|
+
}else{run(defaultVer);}
|
|
61
|
+
})();
|
|
62
|
+
`;
|
|
63
|
+
|
|
64
|
+
export function wmakeImportMapPlugin(): PluginOption {
|
|
65
|
+
const imports: Record<string, string> = {
|
|
66
|
+
react: `${CDN_BASE}/react@${REACT_VER}/+esm`,
|
|
67
|
+
"react/jsx-runtime": `${CDN_BASE}/react@${REACT_VER}/jsx-runtime.js`,
|
|
68
|
+
"react-dom": `${CDN_BASE}/react-dom@${REACT_VER}/+esm`,
|
|
69
|
+
"react-dom/client": `${CDN_BASE}/react-dom@${REACT_VER}/client.js`,
|
|
70
|
+
"@allior/wmake-utils": `${CDN_BASE}/@allior/wmake-utils@${WMAKE_VER}/dist/root/index.js`,
|
|
71
|
+
"@allior/wmake-utils/react": `${CDN_BASE}/@allior/wmake-utils@${WMAKE_VER}/dist/react/index.js`,
|
|
72
|
+
"@allior/wmake-streamelements-events": `${CDN_BASE}/@allior/wmake-streamelements-events@${WMAKE_VER}/dist/root/index.js`,
|
|
73
|
+
"@allior/wmake-streamelements-events/react": `${CDN_BASE}/@allior/wmake-streamelements-events@${WMAKE_VER}/dist/react/index.js`,
|
|
74
|
+
"@allior/wmake-emotes/7tv": `${CDN_BASE}/@allior/wmake-emotes@${WMAKE_VER}/dist/7tv/index.js`,
|
|
75
|
+
"@allior/wmake-streamelements": `${CDN_BASE}/@allior/wmake-streamelements@${WMAKE_VER}/dist/root/index.js`,
|
|
76
|
+
};
|
|
77
|
+
|
|
78
|
+
const importMap = { imports };
|
|
79
|
+
const staticImportMapScript = `<script type="importmap">${JSON.stringify(importMap)}</script>`;
|
|
80
|
+
|
|
81
|
+
return {
|
|
82
|
+
name: "importmap-cdn",
|
|
83
|
+
transformIndexHtml: {
|
|
84
|
+
order: "post" as const,
|
|
85
|
+
handler(html: string, ctx: { server?: unknown }) {
|
|
86
|
+
const isBuild = !ctx.server;
|
|
87
|
+
if (isBuild) {
|
|
88
|
+
const script = "<script>\n" + bootstrapScript.trim() + "\n</script>";
|
|
89
|
+
return html.replace(/(<head[^>]*>)/i, "$1\n" + script);
|
|
90
|
+
}
|
|
91
|
+
return staticImportMapScript + "\n" + html;
|
|
92
|
+
},
|
|
93
|
+
},
|
|
94
|
+
writeBundle(options: { dir?: string }) {
|
|
95
|
+
const outDir = options.dir ?? "dist";
|
|
96
|
+
const htmlPath = path.join(outDir, "index.html");
|
|
97
|
+
if (!fs.existsSync(htmlPath)) return;
|
|
98
|
+
|
|
99
|
+
let html = fs.readFileSync(htmlPath, "utf-8");
|
|
100
|
+
const scriptTagMatch = html.match(
|
|
101
|
+
/<script(?=[^>]*type=["']module["'])(?=[^>]*src=)[^>]*src=["']([^"']+)["'][^>]*>\s*<\/script>/,
|
|
102
|
+
);
|
|
103
|
+
|
|
104
|
+
if (!scriptTagMatch) return;
|
|
105
|
+
const mainScriptSrc = scriptTagMatch[1];
|
|
106
|
+
|
|
107
|
+
html = html
|
|
108
|
+
.replace(BOOTSTRAP_PLACEHOLDER_VER, WMAKE_VER)
|
|
109
|
+
.replace(BOOTSTRAP_PLACEHOLDER_SRC, mainScriptSrc)
|
|
110
|
+
.replace(scriptTagMatch[0], "");
|
|
111
|
+
|
|
112
|
+
fs.writeFileSync(htmlPath, html);
|
|
113
|
+
},
|
|
114
|
+
};
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
export function getWmakeAliases(root: string) {
|
|
118
|
+
return {
|
|
119
|
+
"@allior/wmake-streamelements-events/react": path.join(root, "streamelements-events/dist/react/index.js"),
|
|
120
|
+
"@allior/wmake-streamelements-events": path.join(root, "streamelements-events/dist/root/index.js"),
|
|
121
|
+
"@allior/wmake-utils/react": path.join(root, "utils/dist/react/index.js"),
|
|
122
|
+
"@allior/wmake-utils": path.join(root, "utils/dist/root/index.js"),
|
|
123
|
+
"@allior/wmake-emotes/react": path.join(root, "emotes/dist/react/index.js"),
|
|
124
|
+
"@allior/wmake-emotes/7tv": path.join(root, "emotes/dist/7tv/index.js"),
|
|
125
|
+
"@allior/wmake-emotes": path.join(root, "emotes/dist/root/index.js"),
|
|
126
|
+
"@allior/wmake-streamelements/react": path.join(root, "streamelements/dist/react/index.js"),
|
|
127
|
+
"@allior/wmake-streamelements/fields": path.join(root, "streamelements/dist/fields/index.js"),
|
|
128
|
+
"@allior/wmake-streamelements": path.join(root, "streamelements/dist/root/index.js"),
|
|
129
|
+
};
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
export function getWmakeOptimizeDeps() {
|
|
133
|
+
return {
|
|
134
|
+
include: [
|
|
135
|
+
"@allior/wmake-streamelements-events",
|
|
136
|
+
"@allior/wmake-utils",
|
|
137
|
+
"@allior/wmake-emotes/7tv",
|
|
138
|
+
"@allior/wmake-streamelements",
|
|
139
|
+
],
|
|
140
|
+
};
|
|
141
|
+
}
|
package/src/widget.ts
CHANGED
|
@@ -30,6 +30,14 @@ function run(
|
|
|
30
30
|
return r.status === 0;
|
|
31
31
|
}
|
|
32
32
|
|
|
33
|
+
function getPackageManager(): string {
|
|
34
|
+
const userAgent = process.env.npm_config_user_agent || "";
|
|
35
|
+
if (userAgent.includes("bun")) return "bun";
|
|
36
|
+
if (userAgent.includes("pnpm")) return "pnpm";
|
|
37
|
+
if (userAgent.includes("yarn")) return "yarn";
|
|
38
|
+
return "npm";
|
|
39
|
+
}
|
|
40
|
+
|
|
33
41
|
export async function buildWidget(options: { full?: boolean }): Promise<void> {
|
|
34
42
|
const projectDir = getProjectDir();
|
|
35
43
|
const distDir = path.join(projectDir, "dist");
|
|
@@ -59,7 +67,7 @@ export async function buildWidget(options: { full?: boolean }): Promise<void> {
|
|
|
59
67
|
}
|
|
60
68
|
console.log("Building...");
|
|
61
69
|
const buildEnv = options.full ? { BUILD_FULL: "1" } : {};
|
|
62
|
-
if (!run(
|
|
70
|
+
if (!run(getPackageManager(), ["run", "build"], projectDir, buildEnv)) {
|
|
63
71
|
throw new Error("Build failed.");
|
|
64
72
|
}
|
|
65
73
|
|