@skyvexsoftware/stratos-sdk 0.1.11 → 0.1.12

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.
@@ -0,0 +1,13 @@
1
+ #!/usr/bin/env node
2
+ /**
3
+ * stratos-deploy — Bundle and upload a Stratos plugin.
4
+ *
5
+ * Zips dist/ into bundle.zip. If SKYVEX_API_TOKEN is set, uploads to the
6
+ * Skyvex API. Otherwise outputs the zip path for manual upload.
7
+ *
8
+ * Usage:
9
+ * stratos-deploy # from plugin root after pnpm build
10
+ * pnpm bundle # if package.json has "bundle": "pnpm build && stratos-deploy"
11
+ */
12
+ export {};
13
+ //# sourceMappingURL=deploy.d.ts.map
@@ -0,0 +1,154 @@
1
+ #!/usr/bin/env node
2
+ /**
3
+ * stratos-deploy — Bundle and upload a Stratos plugin.
4
+ *
5
+ * Zips dist/ into bundle.zip. If SKYVEX_API_TOKEN is set, uploads to the
6
+ * Skyvex API. Otherwise outputs the zip path for manual upload.
7
+ *
8
+ * Usage:
9
+ * stratos-deploy # from plugin root after pnpm build
10
+ * pnpm bundle # if package.json has "bundle": "pnpm build && stratos-deploy"
11
+ */
12
+ import * as fs from "fs";
13
+ import * as path from "path";
14
+ import { execSync } from "child_process";
15
+ import * as https from "https";
16
+ import * as http from "http";
17
+ const API_BASE = "https://skyvexsoftware.com/api/stratos";
18
+ // ── Helpers ──────────────────────────────────────────────────────────
19
+ function fatal(message) {
20
+ console.error(`\n Error: ${message}\n`);
21
+ process.exit(1);
22
+ }
23
+ function formatSize(bytes) {
24
+ if (bytes < 1024)
25
+ return `${bytes} B`;
26
+ if (bytes < 1024 * 1024)
27
+ return `${(bytes / 1024).toFixed(1)} kB`;
28
+ return `${(bytes / (1024 * 1024)).toFixed(1)} MB`;
29
+ }
30
+ // ── Validation ───────────────────────────────────────────────────────
31
+ function validateBuild(cwd) {
32
+ const distDir = path.join(cwd, "dist");
33
+ const manifestPath = path.join(distDir, "plugin.json");
34
+ if (!fs.existsSync(manifestPath)) {
35
+ fatal("No built plugin found. Run pnpm build first.");
36
+ }
37
+ const uiEntry = path.join(distDir, "ui", "index.js");
38
+ if (!fs.existsSync(uiEntry)) {
39
+ fatal("Build output incomplete — missing ui/index.js");
40
+ }
41
+ const manifest = JSON.parse(fs.readFileSync(manifestPath, "utf-8"));
42
+ if (!manifest.id || !manifest.version) {
43
+ fatal("plugin.json missing required fields: id, version");
44
+ }
45
+ return {
46
+ id: manifest.id,
47
+ version: manifest.version,
48
+ name: manifest.name ?? manifest.id,
49
+ };
50
+ }
51
+ // ── Zip ──────────────────────────────────────────────────────────────
52
+ function createBundle(cwd) {
53
+ const bundlePath = path.join(cwd, "bundle.zip");
54
+ // Remove stale bundle
55
+ if (fs.existsSync(bundlePath)) {
56
+ fs.unlinkSync(bundlePath);
57
+ }
58
+ try {
59
+ execSync("zip -r ../bundle.zip .", {
60
+ cwd: path.join(cwd, "dist"),
61
+ stdio: "pipe",
62
+ });
63
+ }
64
+ catch {
65
+ fatal("Failed to create bundle.zip. Ensure 'zip' is installed.");
66
+ }
67
+ return bundlePath;
68
+ }
69
+ // ── Upload ───────────────────────────────────────────────────────────
70
+ function upload(pluginId, version, bundlePath, token) {
71
+ return new Promise((resolve) => {
72
+ const boundary = `----StratosDeploy${Date.now()}`;
73
+ const fileContent = fs.readFileSync(bundlePath);
74
+ const parts = [];
75
+ // Version field
76
+ parts.push(Buffer.from(`--${boundary}\r\nContent-Disposition: form-data; name="version"\r\n\r\n${version}\r\n`));
77
+ // File field
78
+ parts.push(Buffer.from(`--${boundary}\r\nContent-Disposition: form-data; name="file"; filename="bundle.zip"\r\nContent-Type: application/zip\r\n\r\n`));
79
+ parts.push(fileContent);
80
+ parts.push(Buffer.from(`\r\n--${boundary}--\r\n`));
81
+ const body = Buffer.concat(parts);
82
+ const url = new URL(`${API_BASE}/plugins/${pluginId}/versions`);
83
+ const options = {
84
+ hostname: url.hostname,
85
+ port: url.port || 443,
86
+ path: url.pathname,
87
+ method: "POST",
88
+ headers: {
89
+ Authorization: `Bearer ${token}`,
90
+ "Content-Type": `multipart/form-data; boundary=${boundary}`,
91
+ "Content-Length": body.length,
92
+ Accept: "application/json",
93
+ },
94
+ };
95
+ const transport = url.protocol === "https:" ? https : http;
96
+ const req = transport.request(options, (res) => {
97
+ let data = "";
98
+ res.on("data", (chunk) => (data += chunk.toString()));
99
+ res.on("end", () => resolve({
100
+ ok: res.statusCode === 201,
101
+ status: res.statusCode ?? 0,
102
+ body: data,
103
+ }));
104
+ });
105
+ req.on("error", (err) => resolve({ ok: false, status: 0, body: err.message }));
106
+ req.write(body);
107
+ req.end();
108
+ });
109
+ }
110
+ // ── Main ─────────────────────────────────────────────────────────────
111
+ async function main() {
112
+ const cwd = process.cwd();
113
+ const { id, version, name } = validateBuild(cwd);
114
+ const bundlePath = createBundle(cwd);
115
+ const bundleSize = fs.statSync(bundlePath).size;
116
+ console.log(`\n ${name} v${version} — bundle.zip (${formatSize(bundleSize)})`);
117
+ const token = process.env.SKYVEX_API_TOKEN;
118
+ if (token) {
119
+ console.log(" Uploading to Skyvex...");
120
+ const result = await upload(id, version, bundlePath, token);
121
+ if (result.ok) {
122
+ console.log(" Published! Server is signing and publishing to CDN.\n");
123
+ fs.unlinkSync(bundlePath);
124
+ }
125
+ else if (result.status === 422) {
126
+ try {
127
+ const errors = JSON.parse(result.body);
128
+ const messages = errors.errors
129
+ ? Object.values(errors.errors).flat().join(", ")
130
+ : (errors.message ?? result.body);
131
+ fatal(`Validation failed: ${messages}`);
132
+ }
133
+ catch {
134
+ fatal(`Validation failed (${result.status}): ${result.body}`);
135
+ }
136
+ }
137
+ else if (result.status === 401) {
138
+ fatal("Authentication failed. Check your SKYVEX_API_TOKEN.");
139
+ }
140
+ else if (result.status === 403) {
141
+ fatal("Permission denied. You do not own this plugin.");
142
+ }
143
+ else {
144
+ fatal(`Upload failed (${result.status}): ${result.body}`);
145
+ }
146
+ }
147
+ else {
148
+ console.log(" No SKYVEX_API_TOKEN found.");
149
+ console.log(" Upload manually at https://skyvexsoftware.com");
150
+ console.log(" Or set SKYVEX_API_TOKEN to deploy from the CLI\n");
151
+ }
152
+ }
153
+ main();
154
+ //# sourceMappingURL=deploy.js.map
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@skyvexsoftware/stratos-sdk",
3
- "version": "0.1.11",
3
+ "version": "0.1.12",
4
4
  "description": "Plugin SDK for Stratos — types, hooks, and UI components",
5
5
  "author": {
6
6
  "name": "Skyvex Software",
@@ -45,6 +45,9 @@
45
45
  "import": "./dist/vite/plugin-config.js"
46
46
  }
47
47
  },
48
+ "bin": {
49
+ "stratos-deploy": "./dist/bin/deploy.js"
50
+ },
48
51
  "files": [
49
52
  "dist",
50
53
  "!dist/**/*.map"