@cloudparse/up-miniapps-sdk 0.5.6 → 0.6.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/bin/up-sdk.cjs +99 -0
- package/dist/index.browser.min.js +21 -21
- package/dist/index.browser.min.js.map +1 -1
- package/dist/index.cjs +111 -5
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +61 -1
- package/dist/index.d.ts +61 -1
- package/dist/index.js +110 -5
- package/dist/index.js.map +1 -1
- package/dist/style.css +0 -12
- package/package.json +15 -8
package/bin/up-sdk.cjs
ADDED
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
"use strict";
|
|
3
|
+
|
|
4
|
+
const { execFileSync } = require("node:child_process");
|
|
5
|
+
const fs = require("node:fs");
|
|
6
|
+
const path = require("node:path");
|
|
7
|
+
const zlib = require("node:zlib");
|
|
8
|
+
|
|
9
|
+
const CWD = process.cwd();
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* `up-sdk build` — standardizes the build pipeline every mini-app repo used
|
|
13
|
+
* to duplicate by hand: `tsc && vite build`, then a post-build step baking
|
|
14
|
+
* the single-file HTML output into base64 (+gzipped) plus a small
|
|
15
|
+
* `<AppName>.ts` helper module the shell imports for native WebView
|
|
16
|
+
* injection. Only the post-build step actually differed per app before
|
|
17
|
+
* (the exported function/file name) — everything else was copy-pasted
|
|
18
|
+
* verbatim across repos. This is now one shared implementation instead of
|
|
19
|
+
* N near-identical `scripts/post-build.cjs` files that could individually
|
|
20
|
+
* drift.
|
|
21
|
+
*/
|
|
22
|
+
function run(cmd, args) {
|
|
23
|
+
console.log(`$ ${cmd} ${args.join(" ")}`);
|
|
24
|
+
execFileSync(cmd, args, { cwd: CWD, stdio: "inherit" });
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
function readAppName() {
|
|
28
|
+
const pkgPath = path.join(CWD, "package.json");
|
|
29
|
+
if (!fs.existsSync(pkgPath)) {
|
|
30
|
+
console.error("❌ No package.json found in", CWD);
|
|
31
|
+
process.exit(1);
|
|
32
|
+
}
|
|
33
|
+
const pkg = JSON.parse(fs.readFileSync(pkgPath, "utf-8"));
|
|
34
|
+
// "@cloudparse/up-miniapps-split" -> "split", "@cloudparse/up-miniapps-by-night" -> "by-night"
|
|
35
|
+
const match = /up-miniapps-(.+)$/.exec(pkg.name || "");
|
|
36
|
+
if (!match) {
|
|
37
|
+
console.error(
|
|
38
|
+
`❌ Could not derive app name from package.json "name" (${pkg.name}). Expected it to match "*up-miniapps-<app-name>".`,
|
|
39
|
+
);
|
|
40
|
+
process.exit(1);
|
|
41
|
+
}
|
|
42
|
+
return match[1];
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
function pascalCase(kebab) {
|
|
46
|
+
return kebab
|
|
47
|
+
.split("-")
|
|
48
|
+
.map((part) => part.charAt(0).toUpperCase() + part.slice(1))
|
|
49
|
+
.join("");
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
function postBuild(appName) {
|
|
53
|
+
const distDir = path.join(CWD, "dist");
|
|
54
|
+
const indexPath = path.join(distDir, "index.html");
|
|
55
|
+
|
|
56
|
+
if (!fs.existsSync(indexPath)) {
|
|
57
|
+
console.error("❌ dist/index.html not found. Did the build step fail?");
|
|
58
|
+
process.exit(1);
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
const htmlContent = fs.readFileSync(indexPath);
|
|
62
|
+
const base64Content = htmlContent.toString("base64");
|
|
63
|
+
|
|
64
|
+
fs.writeFileSync(path.join(distDir, "index.base64"), base64Content);
|
|
65
|
+
console.log("✅ Generated dist/index.base64");
|
|
66
|
+
|
|
67
|
+
const gzipped = zlib.gzipSync(base64Content);
|
|
68
|
+
fs.writeFileSync(path.join(distDir, "index.base64.gz"), gzipped);
|
|
69
|
+
console.log("✅ Generated dist/index.base64.gz");
|
|
70
|
+
|
|
71
|
+
const pascalName = pascalCase(appName);
|
|
72
|
+
const outFile = `${appName}.ts`;
|
|
73
|
+
const tsContent = `export function build${pascalName}HTML(): string {
|
|
74
|
+
const base64 = '${base64Content}';
|
|
75
|
+
if (typeof atob === 'function') return atob(base64);
|
|
76
|
+
return Buffer.from(base64, 'base64').toString('utf-8');
|
|
77
|
+
}
|
|
78
|
+
`;
|
|
79
|
+
fs.writeFileSync(path.join(distDir, outFile), tsContent);
|
|
80
|
+
console.log(`✅ Generated dist/${outFile}`);
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
function build() {
|
|
84
|
+
const appName = readAppName();
|
|
85
|
+
run("npx", ["tsc"]);
|
|
86
|
+
run("npx", ["vite", "build"]);
|
|
87
|
+
postBuild(appName);
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
const [, , command] = process.argv;
|
|
91
|
+
|
|
92
|
+
switch (command) {
|
|
93
|
+
case "build":
|
|
94
|
+
build();
|
|
95
|
+
break;
|
|
96
|
+
default:
|
|
97
|
+
console.error(`Unknown command: ${command || "(none)"}\n\nUsage: up-sdk build`);
|
|
98
|
+
process.exit(1);
|
|
99
|
+
}
|