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 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
- 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;
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
- const scopedResult = await postcss([prefixPlugin]).process(
98
- postcssResult.css,
99
- {
100
- from: undefined,
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 plugin JS with StarPro SDK
90
+ // 2. Build JS bundle with StarPro SDK
106
91
  await buildStarProPlugin({
107
92
  entry: "src/plugin-entry.tsx",
108
- out: "public/plugin.js",
93
+ out: outFile,
94
+ env: envMode,
109
95
  });
110
96
 
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
- );
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 terminal:
111
+ Lalu jalankan di package.json ubah script seperti contoh dibawah ini :
147
112
 
148
- ```bash
149
- 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",
150
121
  ```
151
122
 
152
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.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",