starpro-plugin-sdk 1.2.0 → 1.2.1
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 +91 -4
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -31,7 +31,7 @@ import { defineStarProApp } from "starpro-plugin-sdk";
|
|
|
31
31
|
|
|
32
32
|
defineStarProApp({
|
|
33
33
|
pluginId: "star-tenant-access", // UUID Plugin (bebas apa saja asal tidak ada yg sama)
|
|
34
|
-
|
|
34
|
+
layout: ApplicationLayout, // Component Layout untuk memuat halaman/view
|
|
35
35
|
title: "Tenant Access", // Judul Plugin
|
|
36
36
|
badge: "STA", // Singkatan Plugin
|
|
37
37
|
themeColor: "#059669", // Warna Theme Plugin
|
|
@@ -49,10 +49,97 @@ Simpan file `build-plugin.js` di root folder proyek web Anda:
|
|
|
49
49
|
```javascript
|
|
50
50
|
// build-plugin.js
|
|
51
51
|
const { buildStarProPlugin } = require("starpro-plugin-sdk/build");
|
|
52
|
+
const fs = require("fs");
|
|
53
|
+
const path = require("path");
|
|
54
|
+
const postcss = require("postcss");
|
|
55
|
+
const tailwind = require("@tailwindcss/postcss");
|
|
56
|
+
|
|
57
|
+
async function build() {
|
|
58
|
+
// 1. Compile Tailwind CSS and scope all rules to .starpro-plugin-root
|
|
59
|
+
console.log(
|
|
60
|
+
"🎨 Compiling and scoping Tailwind CSS from src/app/globals.css...",
|
|
61
|
+
);
|
|
62
|
+
const cssInput = fs.readFileSync(
|
|
63
|
+
path.resolve(__dirname, "src/app/globals.css"),
|
|
64
|
+
"utf-8",
|
|
65
|
+
);
|
|
66
|
+
const postcssResult = await postcss([tailwind()]).process(cssInput, {
|
|
67
|
+
from: path.resolve(__dirname, "src/app/globals.css"),
|
|
68
|
+
});
|
|
69
|
+
|
|
70
|
+
// Prefix all selectors so plugin styles NEVER pollute StarPro's header, sidebar, or host dropdowns
|
|
71
|
+
const prefixPlugin = () => ({
|
|
72
|
+
postcssPlugin: "prefix-starpro",
|
|
73
|
+
Rule(rule) {
|
|
74
|
+
if (
|
|
75
|
+
rule.parent &&
|
|
76
|
+
rule.parent.type === "atrule" &&
|
|
77
|
+
(rule.parent.name === "keyframes" || rule.parent.name === "property")
|
|
78
|
+
) {
|
|
79
|
+
return;
|
|
80
|
+
}
|
|
81
|
+
rule.selectors = rule.selectors.map((selector) => {
|
|
82
|
+
const s = selector.trim();
|
|
83
|
+
if (
|
|
84
|
+
s.startsWith(":root") ||
|
|
85
|
+
s.startsWith(":host") ||
|
|
86
|
+
s === "html" ||
|
|
87
|
+
s === "body"
|
|
88
|
+
) {
|
|
89
|
+
return s.replace(/^(:root|:host|html|body)/, ".starpro-plugin-root");
|
|
90
|
+
}
|
|
91
|
+
return ".starpro-plugin-root " + s;
|
|
92
|
+
});
|
|
93
|
+
},
|
|
94
|
+
});
|
|
95
|
+
prefixPlugin.postcss = true;
|
|
96
|
+
|
|
97
|
+
const scopedResult = await postcss([prefixPlugin]).process(
|
|
98
|
+
postcssResult.css,
|
|
99
|
+
{
|
|
100
|
+
from: undefined,
|
|
101
|
+
},
|
|
102
|
+
);
|
|
103
|
+
const compiledCss = scopedResult.css;
|
|
104
|
+
|
|
105
|
+
// 2. Build plugin JS with StarPro SDK
|
|
106
|
+
await buildStarProPlugin({
|
|
107
|
+
entry: "src/plugin-entry.tsx",
|
|
108
|
+
out: "public/plugin.js",
|
|
109
|
+
});
|
|
110
|
+
|
|
111
|
+
// 3. Inject CSS loader into public/plugin.js so styles work 100% in StarPro
|
|
112
|
+
const jsContent = fs.readFileSync(
|
|
113
|
+
path.resolve(__dirname, "public/plugin.js"),
|
|
114
|
+
"utf-8",
|
|
115
|
+
);
|
|
116
|
+
const cssInjector = `
|
|
117
|
+
(function() {
|
|
118
|
+
if (typeof document !== "undefined") {
|
|
119
|
+
var existing = document.getElementById("starpro-tenant-access-styles");
|
|
120
|
+
if (!existing) {
|
|
121
|
+
var style = document.createElement("style");
|
|
122
|
+
style.id = "starpro-tenant-access-styles";
|
|
123
|
+
style.setAttribute("data-plugin-id", "star-tenant-access");
|
|
124
|
+
style.textContent = ${JSON.stringify(compiledCss)};
|
|
125
|
+
document.head.appendChild(style);
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
})();
|
|
129
|
+
`;
|
|
130
|
+
fs.writeFileSync(
|
|
131
|
+
path.resolve(__dirname, "public/plugin.js"),
|
|
132
|
+
cssInjector + "\n" + jsContent,
|
|
133
|
+
"utf-8",
|
|
134
|
+
);
|
|
135
|
+
console.log(
|
|
136
|
+
"✨ Successfully bundled and injected Tailwind CSS into public/plugin.js!",
|
|
137
|
+
);
|
|
138
|
+
}
|
|
52
139
|
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
140
|
+
build().catch((err) => {
|
|
141
|
+
console.error("❌ Build error:", err);
|
|
142
|
+
process.exit(1);
|
|
56
143
|
});
|
|
57
144
|
```
|
|
58
145
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "starpro-plugin-sdk",
|
|
3
|
-
"version": "1.2.
|
|
3
|
+
"version": "1.2.1",
|
|
4
4
|
"description": "Universal SDK to turn any React, Next.js, Vue, or JavaScript web app into a native StarPro plugin with automatic authentication & login bypass.",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"module": "dist/index.mjs",
|