starpro-plugin-sdk 1.2.1 → 1.3.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 +49 -78
- package/dist/build/index.js +21 -3
- package/dist/build/index.mjs +21 -3
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -48,93 +48,58 @@ Simpan file `build-plugin.js` di root folder proyek web Anda:
|
|
|
48
48
|
|
|
49
49
|
```javascript
|
|
50
50
|
// build-plugin.js
|
|
51
|
-
const { buildStarProPlugin } = require("starpro-plugin-sdk/build");
|
|
52
51
|
const fs = require("fs");
|
|
53
52
|
const path = require("path");
|
|
54
53
|
const postcss = require("postcss");
|
|
55
54
|
const tailwind = require("@tailwindcss/postcss");
|
|
55
|
+
const { buildStarProPlugin } = require("starpro-plugin-sdk/build");
|
|
56
56
|
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
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;
|
|
57
|
+
// Prefix all CSS rules to .starpro-plugin-root so styles don't leak into StarPro host
|
|
58
|
+
const prefixPlugin = {
|
|
59
|
+
postcssPlugin: "prefix-starpro",
|
|
60
|
+
Rule(rule) {
|
|
61
|
+
if (
|
|
62
|
+
rule.parent?.type === "atrule" &&
|
|
63
|
+
["keyframes", "property"].includes(rule.parent.name)
|
|
64
|
+
)
|
|
65
|
+
return;
|
|
66
|
+
rule.selectors = rule.selectors.map((s) =>
|
|
67
|
+
/^(:root|:host|html|body)\b/.test(s.trim())
|
|
68
|
+
? s.trim().replace(/^(:root|:host|html|body)/, ".starpro-plugin-root")
|
|
69
|
+
: `.starpro-plugin-root ${s.trim()}`,
|
|
70
|
+
);
|
|
71
|
+
},
|
|
72
|
+
};
|
|
96
73
|
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
74
|
+
async function build() {
|
|
75
|
+
const cssFile = path.resolve(__dirname, "src/app/globals.css");
|
|
76
|
+
const outFile = path.resolve(__dirname, "public/plugin.js");
|
|
77
|
+
const envMode =
|
|
78
|
+
process.argv.find((a) => a.startsWith("--env="))?.split("=")[1] ||
|
|
79
|
+
process.env.BUILD_ENV ||
|
|
80
|
+
process.env.NODE_ENV ||
|
|
81
|
+
"development";
|
|
82
|
+
|
|
83
|
+
// 1. Compile Tailwind CSS & scope selectors in a single pass
|
|
84
|
+
console.log(`🎨 Compiling scoped Tailwind CSS (${envMode})...`);
|
|
85
|
+
const { css } = await postcss([tailwind(), prefixPlugin]).process(
|
|
86
|
+
fs.readFileSync(cssFile, "utf-8"),
|
|
87
|
+
{ from: cssFile },
|
|
102
88
|
);
|
|
103
|
-
const compiledCss = scopedResult.css;
|
|
104
89
|
|
|
105
|
-
// 2. Build
|
|
90
|
+
// 2. Build JS bundle with StarPro SDK
|
|
106
91
|
await buildStarProPlugin({
|
|
107
92
|
entry: "src/plugin-entry.tsx",
|
|
108
|
-
out:
|
|
93
|
+
out: outFile,
|
|
94
|
+
env: envMode,
|
|
109
95
|
});
|
|
110
96
|
|
|
111
|
-
// 3. Inject CSS loader into
|
|
112
|
-
const
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
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
|
-
);
|
|
97
|
+
// 3. Inject CSS loader into plugin.js
|
|
98
|
+
const js = fs.readFileSync(outFile, "utf-8");
|
|
99
|
+
const injector = `(function(){if(typeof document!=="undefined"&&!document.getElementById("starpro-tenant-access-styles")){var s=document.createElement("style");s.id="starpro-tenant-access-styles";s.setAttribute("data-plugin-id","star-tenant-access");s.textContent=${JSON.stringify(css)};document.head.appendChild(s);}})();\n`;
|
|
100
|
+
fs.writeFileSync(outFile, injector + js, "utf-8");
|
|
101
|
+
|
|
102
|
+
console.log("✨ Successfully built public/plugin.js with scoped styles!");
|
|
138
103
|
}
|
|
139
104
|
|
|
140
105
|
build().catch((err) => {
|
|
@@ -143,10 +108,16 @@ build().catch((err) => {
|
|
|
143
108
|
});
|
|
144
109
|
```
|
|
145
110
|
|
|
146
|
-
Lalu jalankan di
|
|
111
|
+
Lalu jalankan di package.json ubah script seperti contoh dibawah ini :
|
|
147
112
|
|
|
148
|
-
```
|
|
149
|
-
|
|
113
|
+
```
|
|
114
|
+
"dev": "npm run build:plugin -- --env=development && next dev",
|
|
115
|
+
"build:plugin": "node build-plugin.js", //tambahkan script build-plugin.js di package.json
|
|
116
|
+
"dev:staging": "npm run build:plugin -- --env=staging && dotenv -e .env.staging -- next dev",
|
|
117
|
+
"build": "npm run build:plugin -- --env=production && dotenv -e .env.production -- next build",
|
|
118
|
+
"start": "dotenv -e .env.production -- next start",
|
|
119
|
+
"build:staging": "npm run build:plugin -- --env=staging && dotenv -e .env.staging -- next build",
|
|
120
|
+
"build:production": "npm run build:plugin -- --env=production && dotenv -e .env.production -- next build",
|
|
150
121
|
```
|
|
151
122
|
|
|
152
123
|
File `public/plugin.js` siap disajikan dan ditempelkan ke StarPro!
|
package/dist/build/index.js
CHANGED
|
@@ -267,9 +267,27 @@ function starproEsbuildPlugin(options = {}) {
|
|
|
267
267
|
contents: `
|
|
268
268
|
import React from 'react';
|
|
269
269
|
export default function Image(props) {
|
|
270
|
-
const {
|
|
270
|
+
const {
|
|
271
|
+
src,
|
|
272
|
+
alt,
|
|
273
|
+
priority,
|
|
274
|
+
quality,
|
|
275
|
+
fill,
|
|
276
|
+
placeholder,
|
|
277
|
+
blurDataURL,
|
|
278
|
+
unoptimized,
|
|
279
|
+
loader,
|
|
280
|
+
fetchPriority,
|
|
281
|
+
...rest
|
|
282
|
+
} = props;
|
|
271
283
|
const targetSrc = typeof src === 'object' && src !== null ? (src.src || '') : src;
|
|
272
|
-
|
|
284
|
+
const computedFetchPriority = fetchPriority || (priority ? 'high' : undefined);
|
|
285
|
+
return React.createElement('img', {
|
|
286
|
+
...rest,
|
|
287
|
+
src: targetSrc,
|
|
288
|
+
alt: alt || '',
|
|
289
|
+
fetchPriority: computedFetchPriority,
|
|
290
|
+
});
|
|
273
291
|
}
|
|
274
292
|
`,
|
|
275
293
|
loader: "tsx",
|
|
@@ -338,7 +356,7 @@ function loadProjectEnv(cwd, mode) {
|
|
|
338
356
|
}
|
|
339
357
|
async function buildStarProPlugin(options = {}) {
|
|
340
358
|
const cwd = options.cwd || process.cwd();
|
|
341
|
-
const envMode = options.env || process.env.NODE_ENV || "
|
|
359
|
+
const envMode = options.env || process.env.BUILD_ENV || process.env.NODE_ENV || "development";
|
|
342
360
|
const entry = options.entry || (fs.existsSync(path.join(cwd, "src/plugin-entry.tsx")) ? "src/plugin-entry.tsx" : "src/plugin-entry.ts");
|
|
343
361
|
const outFile = options.out || "public/plugin.js";
|
|
344
362
|
const minify = options.minify !== false;
|
package/dist/build/index.mjs
CHANGED
|
@@ -235,9 +235,27 @@ function starproEsbuildPlugin(options = {}) {
|
|
|
235
235
|
contents: `
|
|
236
236
|
import React from 'react';
|
|
237
237
|
export default function Image(props) {
|
|
238
|
-
const {
|
|
238
|
+
const {
|
|
239
|
+
src,
|
|
240
|
+
alt,
|
|
241
|
+
priority,
|
|
242
|
+
quality,
|
|
243
|
+
fill,
|
|
244
|
+
placeholder,
|
|
245
|
+
blurDataURL,
|
|
246
|
+
unoptimized,
|
|
247
|
+
loader,
|
|
248
|
+
fetchPriority,
|
|
249
|
+
...rest
|
|
250
|
+
} = props;
|
|
239
251
|
const targetSrc = typeof src === 'object' && src !== null ? (src.src || '') : src;
|
|
240
|
-
|
|
252
|
+
const computedFetchPriority = fetchPriority || (priority ? 'high' : undefined);
|
|
253
|
+
return React.createElement('img', {
|
|
254
|
+
...rest,
|
|
255
|
+
src: targetSrc,
|
|
256
|
+
alt: alt || '',
|
|
257
|
+
fetchPriority: computedFetchPriority,
|
|
258
|
+
});
|
|
241
259
|
}
|
|
242
260
|
`,
|
|
243
261
|
loader: "tsx",
|
|
@@ -306,7 +324,7 @@ function loadProjectEnv(cwd, mode) {
|
|
|
306
324
|
}
|
|
307
325
|
async function buildStarProPlugin(options = {}) {
|
|
308
326
|
const cwd = options.cwd || process.cwd();
|
|
309
|
-
const envMode = options.env || process.env.NODE_ENV || "
|
|
327
|
+
const envMode = options.env || process.env.BUILD_ENV || process.env.NODE_ENV || "development";
|
|
310
328
|
const entry = options.entry || (fs.existsSync(path.join(cwd, "src/plugin-entry.tsx")) ? "src/plugin-entry.tsx" : "src/plugin-entry.ts");
|
|
311
329
|
const outFile = options.out || "public/plugin.js";
|
|
312
330
|
const minify = options.minify !== false;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "starpro-plugin-sdk",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.3.0",
|
|
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",
|