starpro-plugin-sdk 1.2.0 → 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 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
- defaultRoute: "/dashboard", // Rute awal yang dibuka saat plugin dimuat
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
@@ -48,18 +48,76 @@ Simpan file `build-plugin.js` di root folder proyek web Anda:
48
48
 
49
49
  ```javascript
50
50
  // build-plugin.js
51
+ const fs = require("fs");
52
+ const path = require("path");
53
+ const postcss = require("postcss");
54
+ const tailwind = require("@tailwindcss/postcss");
51
55
  const { buildStarProPlugin } = require("starpro-plugin-sdk/build");
52
56
 
53
- buildStarProPlugin({
54
- entry: "src/plugin-entry.tsx",
55
- out: "public/plugin.js",
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
+ };
73
+
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 },
88
+ );
89
+
90
+ // 2. Build JS bundle with StarPro SDK
91
+ await buildStarProPlugin({
92
+ entry: "src/plugin-entry.tsx",
93
+ out: outFile,
94
+ env: envMode,
95
+ });
96
+
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!");
103
+ }
104
+
105
+ build().catch((err) => {
106
+ console.error("❌ Build error:", err);
107
+ process.exit(1);
56
108
  });
57
109
  ```
58
110
 
59
- Lalu jalankan di terminal:
111
+ Lalu jalankan di package.json ubah script seperti contoh dibawah ini :
60
112
 
61
- ```bash
62
- node build-plugin.js
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",
63
121
  ```
64
122
 
65
123
  File `public/plugin.js` siap disajikan dan ditempelkan ke StarPro!
@@ -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 { src, alt, ...rest } = props;
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
- return React.createElement('img', { ...rest, src: targetSrc, alt: alt || '' });
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 || "production";
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;
@@ -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 { src, alt, ...rest } = props;
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
- return React.createElement('img', { ...rest, src: targetSrc, alt: alt || '' });
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 || "production";
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.2.0",
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",