@ptkl/toolkit 0.10.0 → 0.10.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.
@@ -5,7 +5,7 @@ import { Writable } from "stream";
5
5
  import { writeFileSync, readFileSync, rmSync, existsSync } from "fs";
6
6
  import axios from 'axios';
7
7
  import Util from "../lib/util.js";
8
- import { join } from 'path';
8
+ import { extname, isAbsolute, join } from 'path';
9
9
  import { forgeDevKernelPlugin } from '../lib/forgeDevKernelPlugin.js';
10
10
  function formatBuildError(reason) {
11
11
  const lines = [];
@@ -30,6 +30,36 @@ function formatBuildError(reason) {
30
30
  }
31
31
  return lines.join('\n') || String(reason);
32
32
  }
33
+ function iconMimeType(iconPath) {
34
+ const extension = extname(iconPath).toLowerCase();
35
+ if (extension === '.png')
36
+ return 'image/png';
37
+ if (extension === '.jpg' || extension === '.jpeg')
38
+ return 'image/jpeg';
39
+ if (extension === '.svg')
40
+ return 'image/svg+xml';
41
+ if (extension === '.gif')
42
+ return 'image/gif';
43
+ if (extension === '.webp')
44
+ return 'image/webp';
45
+ if (extension === '.ico')
46
+ return 'image/x-icon';
47
+ return 'application/octet-stream';
48
+ }
49
+ function encodeIcon(icon, appPath) {
50
+ if (!icon) {
51
+ return icon;
52
+ }
53
+ if (icon.startsWith('data:')) {
54
+ return icon;
55
+ }
56
+ const iconPath = isAbsolute(icon) ? icon : join(appPath, icon);
57
+ if (!existsSync(iconPath)) {
58
+ throw new Error(`Icon file not found: ${iconPath}`);
59
+ }
60
+ const iconBuffer = readFileSync(iconPath);
61
+ return `data:${iconMimeType(iconPath)};base64,${iconBuffer.toString('base64')}`;
62
+ }
33
63
  class ForgeCommand {
34
64
  register() {
35
65
  return new Command("forge")
@@ -75,6 +105,7 @@ class ForgeCommand {
75
105
  process.chdir(path);
76
106
  const module = await import(`${path}/ptkl.config.js`);
77
107
  const { views, name, version, distPath, icon, type, label, permissions, install_permissions, runtime_permissions, entitlements, requires, scripts, ssrRenderer, } = module.default ?? {};
108
+ const iconBase64 = encodeIcon(icon, path);
78
109
  // Clean dist folder before building to remove stale files
79
110
  if (existsSync(distPath)) {
80
111
  rmSync(distPath, { recursive: true, force: true });
@@ -91,7 +122,7 @@ class ForgeCommand {
91
122
  version,
92
123
  views: {},
93
124
  label,
94
- icon,
125
+ icon: iconBase64,
95
126
  permissions,
96
127
  install_permissions: install_permissions ?? [],
97
128
  runtime_permissions: runtime_permissions ?? [],
@@ -107,7 +138,6 @@ class ForgeCommand {
107
138
  // Different build approach for public vs platform apps
108
139
  if (type === 'public') {
109
140
  // Public apps: standard SPA build with index.html
110
- manifest.icon = icon;
111
141
  console.log("Building public app...");
112
142
  try {
113
143
  await build({
@@ -165,7 +195,6 @@ class ForgeCommand {
165
195
  else {
166
196
  // Platform apps: custom bundle format with views and scripts
167
197
  const base = `${baseUrl}/luma/appservice/v1/forge/static/bundle/${name}/${version}/`;
168
- manifest.icon = `${base}${icon}`;
169
198
  const buildViews = Object.keys(views).map(async (view) => {
170
199
  manifest.views[view] = `${view}.bundle.js`;
171
200
  try {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ptkl/toolkit",
3
- "version": "0.10.0",
3
+ "version": "0.10.1",
4
4
  "description": "A command-line toolkit for managing Protokol platform applications, profiles, functions, and components",
5
5
  "keywords": [
6
6
  "protokol",