@stackable-labs/cli-app-extension 1.3.0 → 1.4.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.
- package/dist/index.js +56 -41
- package/package.json +2 -3
package/dist/index.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
|
|
3
3
|
// src/index.tsx
|
|
4
|
+
import { createRequire } from "module";
|
|
4
5
|
import { program } from "commander";
|
|
5
6
|
import { render } from "ink";
|
|
6
7
|
|
|
@@ -469,17 +470,22 @@ import Spinner2 from "ink-spinner";
|
|
|
469
470
|
import { useEffect, useState as useState6 } from "react";
|
|
470
471
|
|
|
471
472
|
// src/lib/api.ts
|
|
472
|
-
var DEFAULT_API_URL = "https://api.stackablelabs.io/app-extension/latest";
|
|
473
473
|
var DEFAULT_ADMIN_API_URL = "https://api-use1.stackablelabs.io/admin";
|
|
474
|
-
var getApiBaseUrl = () => process.env.API_BASE_URL ?? DEFAULT_API_URL;
|
|
475
474
|
var getAdminApiBaseUrl = () => process.env.ADMIN_API_BASE_URL ?? DEFAULT_ADMIN_API_URL;
|
|
476
475
|
var fetchApps = async () => {
|
|
477
|
-
const
|
|
478
|
-
const res = await fetch(
|
|
476
|
+
const baseUrl = getAdminApiBaseUrl();
|
|
477
|
+
const res = await fetch(`${baseUrl}/app-extension`);
|
|
479
478
|
if (!res.ok) {
|
|
480
|
-
throw new Error(`Failed to fetch apps: ${res.status} ${res.statusText}`);
|
|
479
|
+
throw new Error(`Failed to fetch apps${baseUrl !== DEFAULT_ADMIN_API_URL ? ` (from ${baseUrl})` : ""}: ${res.status} ${res.statusText}`);
|
|
481
480
|
}
|
|
482
|
-
|
|
481
|
+
const adminApps = await res.json();
|
|
482
|
+
return adminApps.filter((app) => app.enabled).map(({ id, name, targets, iconUrl }) => ({
|
|
483
|
+
id,
|
|
484
|
+
name,
|
|
485
|
+
targets,
|
|
486
|
+
enabled: true,
|
|
487
|
+
iconUrl
|
|
488
|
+
}));
|
|
483
489
|
};
|
|
484
490
|
var createExtensionRemote = async (appId, payload) => {
|
|
485
491
|
const baseUrl = getAdminApiBaseUrl();
|
|
@@ -495,12 +501,24 @@ var createExtensionRemote = async (appId, payload) => {
|
|
|
495
501
|
return res.json();
|
|
496
502
|
};
|
|
497
503
|
var fetchExtensions = async (appId) => {
|
|
498
|
-
const baseUrl =
|
|
499
|
-
const res = await fetch(`${baseUrl}/
|
|
504
|
+
const baseUrl = getAdminApiBaseUrl();
|
|
505
|
+
const res = await fetch(`${baseUrl}/app-extension/${appId}/extensions`);
|
|
500
506
|
if (!res.ok) {
|
|
501
507
|
throw new Error(`Failed to fetch extensions: ${res.status} ${res.statusText}`);
|
|
502
508
|
}
|
|
503
|
-
|
|
509
|
+
const adminExtensions = await res.json();
|
|
510
|
+
return Object.fromEntries(
|
|
511
|
+
adminExtensions.filter((ext) => ext.enabled).map(({ id, manifest, bundleUrl, iconUrl }) => [
|
|
512
|
+
id,
|
|
513
|
+
{
|
|
514
|
+
id,
|
|
515
|
+
manifest,
|
|
516
|
+
bundleUrl,
|
|
517
|
+
enabled: true,
|
|
518
|
+
iconUrl
|
|
519
|
+
}
|
|
520
|
+
])
|
|
521
|
+
);
|
|
504
522
|
};
|
|
505
523
|
|
|
506
524
|
// src/components/Banner.tsx
|
|
@@ -716,6 +734,8 @@ var postScaffold = async (options) => {
|
|
|
716
734
|
import { readFile, readdir, rm, writeFile } from "fs/promises";
|
|
717
735
|
import { join } from "path";
|
|
718
736
|
import { downloadTemplate } from "giget";
|
|
737
|
+
var toKebabCase = (value) => value.trim().toLowerCase().replace(/[^a-z0-9]+/g, "-").replace(/^-+|-+$/g, "");
|
|
738
|
+
var isTextFile = (filePath) => /\.(ts|tsx|js|jsx|json|md|html|yml|yaml|env|gitignore|nvmrc)$/i.test(filePath);
|
|
719
739
|
var normalizeTargets = (targets) => Array.from(new Set(targets));
|
|
720
740
|
var derivePermissions = (targets) => {
|
|
721
741
|
const permissions = /* @__PURE__ */ new Set();
|
|
@@ -731,7 +751,29 @@ var derivePermissions = (targets) => {
|
|
|
731
751
|
}
|
|
732
752
|
return [...permissions];
|
|
733
753
|
};
|
|
734
|
-
var
|
|
754
|
+
var upsertOrRemove = async (filePath, shouldExist, content) => {
|
|
755
|
+
if (shouldExist) {
|
|
756
|
+
await writeFile(filePath, content);
|
|
757
|
+
return;
|
|
758
|
+
}
|
|
759
|
+
await rm(filePath, { force: true });
|
|
760
|
+
};
|
|
761
|
+
var walkFiles = async (rootDir) => {
|
|
762
|
+
const entries = await readdir(rootDir, { withFileTypes: true });
|
|
763
|
+
const files = [];
|
|
764
|
+
for (const entry of entries) {
|
|
765
|
+
if (entry.name === ".git" || entry.name === "node_modules" || entry.name === "dist") {
|
|
766
|
+
continue;
|
|
767
|
+
}
|
|
768
|
+
const fullPath = join(rootDir, entry.name);
|
|
769
|
+
if (entry.isDirectory()) {
|
|
770
|
+
files.push(...await walkFiles(fullPath));
|
|
771
|
+
continue;
|
|
772
|
+
}
|
|
773
|
+
files.push(fullPath);
|
|
774
|
+
}
|
|
775
|
+
return files;
|
|
776
|
+
};
|
|
735
777
|
var replacePlaceholders = async (rootDir, replacements) => {
|
|
736
778
|
const files = await walkFiles(rootDir);
|
|
737
779
|
for (const filePath of files) {
|
|
@@ -960,23 +1002,6 @@ var rewriteTurboJson = async (rootDir) => {
|
|
|
960
1002
|
await writeFile(turboPath, `${JSON.stringify(turbo, null, 2)}
|
|
961
1003
|
`);
|
|
962
1004
|
};
|
|
963
|
-
var walkFiles = async (rootDir) => {
|
|
964
|
-
const entries = await readdir(rootDir, { withFileTypes: true });
|
|
965
|
-
const files = [];
|
|
966
|
-
for (const entry of entries) {
|
|
967
|
-
if (entry.name === ".git" || entry.name === "node_modules" || entry.name === "dist") {
|
|
968
|
-
continue;
|
|
969
|
-
}
|
|
970
|
-
const fullPath = join(rootDir, entry.name);
|
|
971
|
-
if (entry.isDirectory()) {
|
|
972
|
-
files.push(...await walkFiles(fullPath));
|
|
973
|
-
continue;
|
|
974
|
-
}
|
|
975
|
-
files.push(fullPath);
|
|
976
|
-
}
|
|
977
|
-
return files;
|
|
978
|
-
};
|
|
979
|
-
var isTextFile = (filePath) => /\.(ts|tsx|js|jsx|json|md|html|yml|yaml|env|gitignore|nvmrc)$/i.test(filePath);
|
|
980
1005
|
var writeEnvFile = async (dir, extensionPort, previewPort) => {
|
|
981
1006
|
const envPath = join(dir, ".env");
|
|
982
1007
|
const content = `VITE_EXTENSION_PORT=${extensionPort}
|
|
@@ -984,13 +1009,6 @@ VITE_PREVIEW_PORT=${previewPort}
|
|
|
984
1009
|
`;
|
|
985
1010
|
await writeFile(envPath, content);
|
|
986
1011
|
};
|
|
987
|
-
var upsertOrRemove = async (filePath, shouldExist, content) => {
|
|
988
|
-
if (shouldExist) {
|
|
989
|
-
await writeFile(filePath, content);
|
|
990
|
-
return;
|
|
991
|
-
}
|
|
992
|
-
await rm(filePath, { force: true });
|
|
993
|
-
};
|
|
994
1012
|
var scaffold = async (options) => {
|
|
995
1013
|
const { dir } = await downloadTemplate(TEMPLATE_SOURCE, {
|
|
996
1014
|
dir: options.outputDir,
|
|
@@ -1269,16 +1287,13 @@ var App = ({ command, initialName, options }) => {
|
|
|
1269
1287
|
|
|
1270
1288
|
// src/index.tsx
|
|
1271
1289
|
import { jsx as jsx13 } from "react/jsx-runtime";
|
|
1272
|
-
|
|
1290
|
+
var require2 = createRequire(import.meta.url);
|
|
1291
|
+
var { version } = require2("../package.json");
|
|
1292
|
+
program.name("stackable-app-extension").description("Stackable app extension developer CLI").version(version);
|
|
1273
1293
|
program.command("create" /* CREATE */).description("Create a new Extension project").argument("[name]", "Extension project name").option("--extension-port <port>", "Extension dev server port (default: 5173)").option("--preview-port <port>", "Preview host dev server port").option("--skip-install", "Skip package manager install").option("--skip-git", "Skip git initialization").action((name, options) => {
|
|
1274
1294
|
render(/* @__PURE__ */ jsx13(App, { command: "create" /* CREATE */, initialName: name, options }));
|
|
1275
1295
|
});
|
|
1276
1296
|
program.command("scaffold" /* SCAFFOLD */).description("Scaffold a local project from an existing Extension").option("--extension-port <port>", "Extension dev server port (default: 5173)").option("--preview-port <port>", "Preview host dev server port").option("--skip-install", "Skip package manager install").option("--skip-git", "Skip git initialization").action((options) => {
|
|
1277
1297
|
render(/* @__PURE__ */ jsx13(App, { command: "scaffold" /* SCAFFOLD */, options }));
|
|
1278
1298
|
});
|
|
1279
|
-
|
|
1280
|
-
process.stderr.write("\u26A0\uFE0F DEPRECATED: `create-extension` is deprecated and will be removed in v2.0.0. Use `stackable-extension create` instead.\n");
|
|
1281
|
-
program.parse(["node", "stackable-extension", "create", ...process.argv.slice(2).filter((arg) => arg !== "--")]);
|
|
1282
|
-
} else {
|
|
1283
|
-
program.parse(process.argv.filter((arg) => arg !== "--"));
|
|
1284
|
-
}
|
|
1299
|
+
program.parse(process.argv.filter((arg) => arg !== "--"));
|
package/package.json
CHANGED
|
@@ -1,11 +1,10 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@stackable-labs/cli-app-extension",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.4.1",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"private": false,
|
|
6
6
|
"bin": {
|
|
7
|
-
"
|
|
8
|
-
"stackable-extension": "./dist/index.js"
|
|
7
|
+
"stackable-app-extension": "./dist/index.js"
|
|
9
8
|
},
|
|
10
9
|
"files": [
|
|
11
10
|
"dist/",
|