@swarm.ing/pieui 2.0.13 → 2.0.15
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/__tests__/step1-local.test.d.cts +2 -0
- package/dist/__tests__/step1-local.test.d.cts.map +1 -0
- package/dist/__tests__/step2-remote.test.d.cts +2 -0
- package/dist/__tests__/step2-remote.test.d.cts.map +1 -0
- package/dist/__tests__/step3-contract.test.d.cts +2 -0
- package/dist/__tests__/step3-contract.test.d.cts.map +1 -0
- package/dist/__tests__/step4-ci.test.d.cts +2 -0
- package/dist/__tests__/step4-ci.test.d.cts.map +1 -0
- package/dist/__tests__/step5-regres.test.d.cts +2 -0
- package/dist/__tests__/step5-regres.test.d.cts.map +1 -0
- package/dist/cli.js +402 -1
- package/dist/code/args.d.ts.map +1 -1
- package/dist/code/commands/createPieApp.d.ts.map +1 -1
- package/dist/code/commands/login.d.ts +13 -0
- package/dist/code/commands/login.d.ts.map +1 -0
- package/package.json +8 -2
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"step1-local.test.d.cts","sourceRoot":"","sources":["../../src/__tests__/step1-local.test.cjs"],"names":[],"mappings":""}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"step2-remote.test.d.cts","sourceRoot":"","sources":["../../src/__tests__/step2-remote.test.cjs"],"names":[],"mappings":""}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"step3-contract.test.d.cts","sourceRoot":"","sources":["../../src/__tests__/step3-contract.test.cjs"],"names":[],"mappings":""}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"step4-ci.test.d.cts","sourceRoot":"","sources":["../../src/__tests__/step4-ci.test.cjs"],"names":[],"mappings":""}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"step5-regres.test.d.cts","sourceRoot":"","sources":["../../src/__tests__/step5-regres.test.cjs"],"names":[],"mappings":""}
|
package/dist/cli.js
CHANGED
|
@@ -193049,7 +193049,7 @@ var parseArgs = (argv) => {
|
|
|
193049
193049
|
if (command === "remove" && argv[1]) {
|
|
193050
193050
|
removeComponentName = argv[1];
|
|
193051
193051
|
}
|
|
193052
|
-
if ((command === "create-pie-app" || command === "create") && argv[1]) {
|
|
193052
|
+
if ((command === "create-pie-app" || command === "create-pieui" || command === "create") && argv[1]) {
|
|
193053
193053
|
createAppName = argv[1];
|
|
193054
193054
|
}
|
|
193055
193055
|
if (command === "list") {
|
|
@@ -193140,6 +193140,8 @@ var printUsage = () => {
|
|
|
193140
193140
|
console.log("Commands:");
|
|
193141
193141
|
console.log(" create <AppName> Create a Next.js app and run pieui init inside it");
|
|
193142
193142
|
console.log(" create-pie-app <AppName> Create a blank Next.js web template for PieUI (bun create next-app under the hood)");
|
|
193143
|
+
console.log(" create-pieui <AppName> Alias for create-pie-app");
|
|
193144
|
+
console.log(" login Sign in to PieUI and save credentials to .pie/config.json");
|
|
193143
193145
|
console.log(" init Initialize piecomponents directory with registry.ts");
|
|
193144
193146
|
console.log(" card add [type] <ComponentName> [--io] [--ajax] Create a new component in piecomponents directory");
|
|
193145
193147
|
console.log(" page add <path> Create app/<path>/page.tsx from the standard Pie page template");
|
|
@@ -193188,9 +193190,11 @@ var printUsage = () => {
|
|
|
193188
193190
|
console.log(" complex-container Container with array content");
|
|
193189
193191
|
console.log("");
|
|
193190
193192
|
console.log("Examples:");
|
|
193193
|
+
console.log(" pieui login");
|
|
193191
193194
|
console.log(" pieui init");
|
|
193192
193195
|
console.log(" pieui create my-pie-app");
|
|
193193
193196
|
console.log(" pieui create-pie-app my-pie-app");
|
|
193197
|
+
console.log(" pieui create-pieui my-pie-app");
|
|
193194
193198
|
console.log(" pieui init --out-dir packages/app");
|
|
193195
193199
|
console.log(" pieui card add MyCustomCard # Creates complex-container by default");
|
|
193196
193200
|
console.log(" pieui card add simple MySimpleCard # Creates simple component");
|
|
@@ -198518,6 +198522,391 @@ var createCommand = (appName) => {
|
|
|
198518
198522
|
runBunCommand(bunBin, ["run", "dev"], appDir);
|
|
198519
198523
|
};
|
|
198520
198524
|
|
|
198525
|
+
// src/code/commands/createPieApp.ts
|
|
198526
|
+
var import_fs13 = __toESM(require("fs"));
|
|
198527
|
+
var import_path15 = __toESM(require("path"));
|
|
198528
|
+
var import_child_process2 = require("child_process");
|
|
198529
|
+
var DEFAULT_TEMPLATE_SPEC2 = "next-app@latest";
|
|
198530
|
+
var SHARED_TEMPLATE_DIR_ENV = "PIEUI_SHARED_TEMPLATE_DIR";
|
|
198531
|
+
var AI_EXCHANGE_BOT_DIR_ENV = "PIEUI_AI_EXCHANGE_BOT_DIR";
|
|
198532
|
+
var DEFAULT_SHARED_SIMPLE_TSX = `"use client";
|
|
198533
|
+
|
|
198534
|
+
import { useEffect, useState } from "react";
|
|
198535
|
+
import { useRouter } from "next/navigation";
|
|
198536
|
+
import { PieTelegramRoot, PieQueryOptions } from "@swarm.ing/pieui";
|
|
198537
|
+
|
|
198538
|
+
import { usePathname, useSearchParams } from "next/navigation";
|
|
198539
|
+
import LoadingScreen from "@/components/LoadingScreen";
|
|
198540
|
+
import { ErrorToast } from "@/components/ErrorToast";
|
|
198541
|
+
import piecache from "@/app/piecache.json";
|
|
198542
|
+
import "@/piecomponents/registry";
|
|
198543
|
+
|
|
198544
|
+
const pieQueryOptions: PieQueryOptions = {
|
|
198545
|
+
staleTime: 0, // always stale - refetch on every mount
|
|
198546
|
+
gcTime: 60 * 1000, // keep cache for 1 minute
|
|
198547
|
+
refetchOnMount: "always" as const,
|
|
198548
|
+
refetchOnWindowFocus: "always" as const,
|
|
198549
|
+
refetchOnReconnect: "always" as const,
|
|
198550
|
+
};
|
|
198551
|
+
|
|
198552
|
+
export default function PiePage({
|
|
198553
|
+
fallback,
|
|
198554
|
+
}: { fallback?: React.ReactNode } = {}) {
|
|
198555
|
+
const router = useRouter();
|
|
198556
|
+
const pathname = usePathname();
|
|
198557
|
+
const searchParams = useSearchParams();
|
|
198558
|
+
const search = searchParams.toString();
|
|
198559
|
+
const [showVpnError, setShowVpnError] = useState(false);
|
|
198560
|
+
|
|
198561
|
+
const handleError = () => {
|
|
198562
|
+
if (showVpnError) {
|
|
198563
|
+
}
|
|
198564
|
+
setShowVpnError(true);
|
|
198565
|
+
setTimeout(() => setShowVpnError(false), 2000);
|
|
198566
|
+
};
|
|
198567
|
+
|
|
198568
|
+
useEffect(() => {
|
|
198569
|
+
const backButton = window.Telegram?.WebApp?.BackButton;
|
|
198570
|
+
if (!backButton) return;
|
|
198571
|
+
|
|
198572
|
+
const slashCount = (pathname.match(/\\//g) || []).length;
|
|
198573
|
+
const historyState = window.history.state as { idx?: number } | null;
|
|
198574
|
+
const hasHistory =
|
|
198575
|
+
typeof historyState?.idx === "number"
|
|
198576
|
+
? historyState.idx > 0
|
|
198577
|
+
: window.history.length > 1;
|
|
198578
|
+
const showBack = slashCount > 1 && hasHistory;
|
|
198579
|
+
|
|
198580
|
+
const handleBack = () => router.back();
|
|
198581
|
+
|
|
198582
|
+
if (showBack) {
|
|
198583
|
+
backButton.onClick(handleBack);
|
|
198584
|
+
backButton.show();
|
|
198585
|
+
} else {
|
|
198586
|
+
backButton.offClick(handleBack);
|
|
198587
|
+
backButton.hide();
|
|
198588
|
+
}
|
|
198589
|
+
|
|
198590
|
+
return () => {
|
|
198591
|
+
backButton.offClick(handleBack);
|
|
198592
|
+
backButton.hide();
|
|
198593
|
+
};
|
|
198594
|
+
}, [router, pathname]);
|
|
198595
|
+
|
|
198596
|
+
useEffect(() => {
|
|
198597
|
+
const webApp = window.Telegram?.WebApp;
|
|
198598
|
+
webApp?.expand();
|
|
198599
|
+
webApp?.disableVerticalSwipes();
|
|
198600
|
+
}, []);
|
|
198601
|
+
|
|
198602
|
+
const Root = PieTelegramRoot;
|
|
198603
|
+
|
|
198604
|
+
return (
|
|
198605
|
+
<>
|
|
198606
|
+
<ErrorToast
|
|
198607
|
+
visible={showVpnError}
|
|
198608
|
+
message="Connection issues. Please check your VPN."
|
|
198609
|
+
/>
|
|
198610
|
+
<Root
|
|
198611
|
+
location={{
|
|
198612
|
+
pathname: pathname,
|
|
198613
|
+
search: search,
|
|
198614
|
+
}}
|
|
198615
|
+
config={{
|
|
198616
|
+
apiServer: process.env.PIE_API_SERVER!,
|
|
198617
|
+
centrifugeServer: process.env.PIE_CENTRIFUGE_SERVER!,
|
|
198618
|
+
enableRenderingLog: true,
|
|
198619
|
+
pageProcessor: "telegram",
|
|
198620
|
+
}}
|
|
198621
|
+
onNavigate={(url) => router.push(url)}
|
|
198622
|
+
fallback={<LoadingScreen />}
|
|
198623
|
+
piecache={piecache as any}
|
|
198624
|
+
queryOptions={pieQueryOptions}
|
|
198625
|
+
onError={handleError}
|
|
198626
|
+
/>
|
|
198627
|
+
</>
|
|
198628
|
+
);
|
|
198629
|
+
}
|
|
198630
|
+
`;
|
|
198631
|
+
var BACKEND_LINK_COMMENT = "// TODO(pie-backend): Link generated Python Unicorn backend routes here once backend template sync is enabled.";
|
|
198632
|
+
var updateNextScriptsToBun = (packageJsonPath) => {
|
|
198633
|
+
if (!import_fs13.default.existsSync(packageJsonPath))
|
|
198634
|
+
return;
|
|
198635
|
+
try {
|
|
198636
|
+
const pkg = JSON.parse(import_fs13.default.readFileSync(packageJsonPath, "utf8"));
|
|
198637
|
+
if (!pkg.scripts)
|
|
198638
|
+
return;
|
|
198639
|
+
const updates = {
|
|
198640
|
+
dev: "bun --bun next dev",
|
|
198641
|
+
build: "bun --bun next build",
|
|
198642
|
+
start: "bun --bun next start"
|
|
198643
|
+
};
|
|
198644
|
+
for (const [scriptName, scriptValue] of Object.entries(updates)) {
|
|
198645
|
+
if (pkg.scripts[scriptName]) {
|
|
198646
|
+
pkg.scripts[scriptName] = scriptValue;
|
|
198647
|
+
}
|
|
198648
|
+
}
|
|
198649
|
+
import_fs13.default.writeFileSync(packageJsonPath, `${JSON.stringify(pkg, null, 2)}
|
|
198650
|
+
`, "utf8");
|
|
198651
|
+
} catch {
|
|
198652
|
+
}
|
|
198653
|
+
};
|
|
198654
|
+
var appendBackendLinkComment = (pagePath) => {
|
|
198655
|
+
if (!import_fs13.default.existsSync(pagePath))
|
|
198656
|
+
return;
|
|
198657
|
+
const page = import_fs13.default.readFileSync(pagePath, "utf8");
|
|
198658
|
+
if (page.includes(BACKEND_LINK_COMMENT))
|
|
198659
|
+
return;
|
|
198660
|
+
import_fs13.default.writeFileSync(pagePath, `${page.trimEnd()}
|
|
198661
|
+
|
|
198662
|
+
${BACKEND_LINK_COMMENT}
|
|
198663
|
+
`, "utf8");
|
|
198664
|
+
};
|
|
198665
|
+
var uniq = (items) => [...new Set(items)];
|
|
198666
|
+
var isDirectory = (target) => {
|
|
198667
|
+
try {
|
|
198668
|
+
return import_fs13.default.statSync(target).isDirectory();
|
|
198669
|
+
} catch {
|
|
198670
|
+
return false;
|
|
198671
|
+
}
|
|
198672
|
+
};
|
|
198673
|
+
var resolveSharedTemplateDir = () => {
|
|
198674
|
+
const explicitSharedDir = process.env[SHARED_TEMPLATE_DIR_ENV];
|
|
198675
|
+
if (explicitSharedDir) {
|
|
198676
|
+
const normalized = import_path15.default.resolve(explicitSharedDir);
|
|
198677
|
+
if (!isDirectory(normalized)) {
|
|
198678
|
+
throw new Error(`${SHARED_TEMPLATE_DIR_ENV} points to a missing directory: ${normalized}`);
|
|
198679
|
+
}
|
|
198680
|
+
return normalized;
|
|
198681
|
+
}
|
|
198682
|
+
const cwd = process.cwd();
|
|
198683
|
+
const baseDirs = [cwd, import_path15.default.resolve(cwd, ".."), import_path15.default.resolve(cwd, "../..")];
|
|
198684
|
+
const explicitRepoDir = process.env[AI_EXCHANGE_BOT_DIR_ENV];
|
|
198685
|
+
if (explicitRepoDir) {
|
|
198686
|
+
baseDirs.unshift(import_path15.default.resolve(explicitRepoDir));
|
|
198687
|
+
}
|
|
198688
|
+
const repoNames = ["ai-exchange-bot", "ai-exchange-web", "a-exchange-web"];
|
|
198689
|
+
const repoCandidates = uniq([
|
|
198690
|
+
...baseDirs,
|
|
198691
|
+
...baseDirs.flatMap((base) => repoNames.map((name) => import_path15.default.join(base, name)))
|
|
198692
|
+
]).filter((candidate) => isDirectory(candidate));
|
|
198693
|
+
const sharedSubpaths = [
|
|
198694
|
+
"_shared",
|
|
198695
|
+
"src/_shared",
|
|
198696
|
+
"app/_shared",
|
|
198697
|
+
"pages/_shared",
|
|
198698
|
+
"pages/components/_shared",
|
|
198699
|
+
"apps/web/_shared",
|
|
198700
|
+
"apps/web/src/_shared"
|
|
198701
|
+
];
|
|
198702
|
+
for (const repoDir of repoCandidates) {
|
|
198703
|
+
for (const subpath of sharedSubpaths) {
|
|
198704
|
+
const candidate = import_path15.default.join(repoDir, subpath);
|
|
198705
|
+
if (isDirectory(candidate)) {
|
|
198706
|
+
return candidate;
|
|
198707
|
+
}
|
|
198708
|
+
}
|
|
198709
|
+
}
|
|
198710
|
+
return null;
|
|
198711
|
+
};
|
|
198712
|
+
var copySharedTemplate = (sharedTemplateDir, appDir) => {
|
|
198713
|
+
const destination = import_path15.default.join(appDir, "_shared");
|
|
198714
|
+
import_fs13.default.cpSync(sharedTemplateDir, destination, { recursive: true, force: true });
|
|
198715
|
+
};
|
|
198716
|
+
var scaffoldFallbackSharedTemplate = (appDir) => {
|
|
198717
|
+
const destination = import_path15.default.join(appDir, "_shared");
|
|
198718
|
+
import_fs13.default.mkdirSync(destination, { recursive: true });
|
|
198719
|
+
import_fs13.default.writeFileSync(import_path15.default.join(destination, "simple.tsx"), DEFAULT_SHARED_SIMPLE_TSX, "utf8");
|
|
198720
|
+
};
|
|
198721
|
+
var createPieAppCommand = (appName) => {
|
|
198722
|
+
const trimmedAppName = appName.trim();
|
|
198723
|
+
if (!trimmedAppName) {
|
|
198724
|
+
console.error("[pieui] Error: App name is required for create-pie-app command");
|
|
198725
|
+
process.exit(1);
|
|
198726
|
+
}
|
|
198727
|
+
const appDir = import_path15.default.resolve(process.cwd(), trimmedAppName);
|
|
198728
|
+
if (import_fs13.default.existsSync(appDir)) {
|
|
198729
|
+
console.error(`[pieui] Error: Target directory already exists: ${trimmedAppName}`);
|
|
198730
|
+
process.exit(1);
|
|
198731
|
+
}
|
|
198732
|
+
const bunBin = process.env.PIEUI_CREATE_BUN_BIN || "bun";
|
|
198733
|
+
const templateSpec = process.env.PIEUI_CREATE_NEXT_APP_SPEC || DEFAULT_TEMPLATE_SPEC2;
|
|
198734
|
+
console.log(`[pieui] Creating blank PieUI web template in "${trimmedAppName}"...`);
|
|
198735
|
+
const args = ["create", templateSpec, trimmedAppName, "--yes"];
|
|
198736
|
+
const result = import_child_process2.spawnSync(bunBin, args, {
|
|
198737
|
+
cwd: process.cwd(),
|
|
198738
|
+
stdio: "inherit",
|
|
198739
|
+
env: process.env
|
|
198740
|
+
});
|
|
198741
|
+
if (result.error) {
|
|
198742
|
+
throw result.error;
|
|
198743
|
+
}
|
|
198744
|
+
if (result.status !== 0) {
|
|
198745
|
+
throw new Error(`create-pie-app failed (exit code ${result.status ?? "unknown"})`);
|
|
198746
|
+
}
|
|
198747
|
+
const sharedTemplateDir = resolveSharedTemplateDir();
|
|
198748
|
+
if (sharedTemplateDir) {
|
|
198749
|
+
copySharedTemplate(sharedTemplateDir, appDir);
|
|
198750
|
+
} else {
|
|
198751
|
+
scaffoldFallbackSharedTemplate(appDir);
|
|
198752
|
+
console.warn([
|
|
198753
|
+
`[pieui] Warning: Could not locate a _shared template directory automatically.`,
|
|
198754
|
+
`Generated fallback "${trimmedAppName}/_shared/simple.tsx".`,
|
|
198755
|
+
`Set ${SHARED_TEMPLATE_DIR_ENV}=/absolute/path/to/_shared`,
|
|
198756
|
+
`or ${AI_EXCHANGE_BOT_DIR_ENV}=/absolute/path/to/ai-exchange-bot to copy a project-standard folder.`
|
|
198757
|
+
].join(" "));
|
|
198758
|
+
}
|
|
198759
|
+
updateNextScriptsToBun(import_path15.default.join(appDir, "package.json"));
|
|
198760
|
+
appendBackendLinkComment(import_path15.default.join(appDir, "app", "page.tsx"));
|
|
198761
|
+
console.log("[pieui] Template created successfully.");
|
|
198762
|
+
if (sharedTemplateDir) {
|
|
198763
|
+
console.log(`[pieui] Copied _shared from: ${sharedTemplateDir}`);
|
|
198764
|
+
} else {
|
|
198765
|
+
console.log(`[pieui] Using fallback _shared scaffold. Update it with your project standards.`);
|
|
198766
|
+
}
|
|
198767
|
+
console.log(`[pieui] Next steps:`);
|
|
198768
|
+
console.log(` 1. cd ${trimmedAppName}`);
|
|
198769
|
+
console.log(` 2. bun install`);
|
|
198770
|
+
console.log(` 3. bun run dev`);
|
|
198771
|
+
};
|
|
198772
|
+
|
|
198773
|
+
// src/code/commands/login.ts
|
|
198774
|
+
var import_node_child_process = require("node:child_process");
|
|
198775
|
+
var import_node_crypto = require("node:crypto");
|
|
198776
|
+
var import_node_fs = __toESM(require("node:fs"));
|
|
198777
|
+
var import_node_path2 = __toESM(require("node:path"));
|
|
198778
|
+
var CONNECT_BASE = "https://pieui.swarm.ing/connect";
|
|
198779
|
+
var CREDENTIALS_API = "https://api-pieui.swarm.ing/api/external/credentials";
|
|
198780
|
+
var CONNECT_BASE_ENV = "PIEUI_LOGIN_CONNECT_BASE";
|
|
198781
|
+
var CREDENTIALS_API_ENV = "PIEUI_LOGIN_CREDENTIALS_API";
|
|
198782
|
+
var CODE_LENGTH = 32;
|
|
198783
|
+
var generateCode = (length = CODE_LENGTH) => {
|
|
198784
|
+
const alphabet = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
|
|
198785
|
+
let out = "";
|
|
198786
|
+
for (let i = 0;i < length; i++) {
|
|
198787
|
+
out += alphabet[import_node_crypto.randomInt(alphabet.length)];
|
|
198788
|
+
}
|
|
198789
|
+
return out;
|
|
198790
|
+
};
|
|
198791
|
+
var tryOpenBrowser = (url) => {
|
|
198792
|
+
try {
|
|
198793
|
+
if (process.platform === "win32") {
|
|
198794
|
+
import_node_child_process.execFile("cmd", ["/c", "start", "", url], () => {
|
|
198795
|
+
});
|
|
198796
|
+
} else if (process.platform === "darwin") {
|
|
198797
|
+
import_node_child_process.execFile("open", [url], () => {
|
|
198798
|
+
});
|
|
198799
|
+
} else {
|
|
198800
|
+
import_node_child_process.execFile("xdg-open", [url], () => {
|
|
198801
|
+
});
|
|
198802
|
+
}
|
|
198803
|
+
} catch {
|
|
198804
|
+
}
|
|
198805
|
+
};
|
|
198806
|
+
var defaultSleep = (ms2) => new Promise((resolve) => setTimeout(resolve, ms2));
|
|
198807
|
+
var PIE_ENV_MAP = [
|
|
198808
|
+
["PIE_USER_ID", "user_id"],
|
|
198809
|
+
["PIE_PROJECT", "project"],
|
|
198810
|
+
["PIE_API_KEY", "api_key"]
|
|
198811
|
+
];
|
|
198812
|
+
var formatEnvValue = (val) => {
|
|
198813
|
+
if (/[\s#'"\\]/.test(val) || val === "") {
|
|
198814
|
+
return `"${val.replace(/\\/g, "\\\\").replace(/"/g, "\\\"")}"`;
|
|
198815
|
+
}
|
|
198816
|
+
return val;
|
|
198817
|
+
};
|
|
198818
|
+
var appendPieCredentialsToEnv = (cwd, config) => {
|
|
198819
|
+
if (typeof config !== "object" || config === null) {
|
|
198820
|
+
return;
|
|
198821
|
+
}
|
|
198822
|
+
const c = config;
|
|
198823
|
+
const entries = {};
|
|
198824
|
+
for (const [envKey, jsonKey] of PIE_ENV_MAP) {
|
|
198825
|
+
const v2 = c[jsonKey];
|
|
198826
|
+
if (v2 !== undefined && v2 !== null) {
|
|
198827
|
+
entries[envKey] = String(v2);
|
|
198828
|
+
}
|
|
198829
|
+
}
|
|
198830
|
+
if (Object.keys(entries).length === 0) {
|
|
198831
|
+
return;
|
|
198832
|
+
}
|
|
198833
|
+
const envPath = import_node_path2.default.join(cwd, ".env");
|
|
198834
|
+
let content = import_node_fs.default.existsSync(envPath) ? import_node_fs.default.readFileSync(envPath, "utf8") : "";
|
|
198835
|
+
if (content.length > 0 && !content.endsWith(`
|
|
198836
|
+
`)) {
|
|
198837
|
+
content += `
|
|
198838
|
+
`;
|
|
198839
|
+
}
|
|
198840
|
+
const additions = PIE_ENV_MAP.filter(([envKey]) => (envKey in entries)).map(([envKey]) => `${envKey}=${formatEnvValue(entries[envKey])}`);
|
|
198841
|
+
content += `${additions.join(`
|
|
198842
|
+
`)}
|
|
198843
|
+
`;
|
|
198844
|
+
import_node_fs.default.writeFileSync(envPath, content, "utf8");
|
|
198845
|
+
console.log(`[pie] Appended credentials to ${envPath}`);
|
|
198846
|
+
};
|
|
198847
|
+
async function loginCommand(options = {}) {
|
|
198848
|
+
const {
|
|
198849
|
+
cwd = process.cwd(),
|
|
198850
|
+
pollIntervalMs = 3000,
|
|
198851
|
+
openBrowser = tryOpenBrowser,
|
|
198852
|
+
fetchImpl = fetch,
|
|
198853
|
+
sleepImpl = defaultSleep
|
|
198854
|
+
} = options;
|
|
198855
|
+
const connectBase = process.env[CONNECT_BASE_ENV] || CONNECT_BASE;
|
|
198856
|
+
const credentialsApi = process.env[CREDENTIALS_API_ENV] || CREDENTIALS_API;
|
|
198857
|
+
const code = generateCode(CODE_LENGTH);
|
|
198858
|
+
const connectUrl = `${connectBase}?${new URLSearchParams({ code }).toString()}`;
|
|
198859
|
+
console.log(`Open link in browser:
|
|
198860
|
+
`);
|
|
198861
|
+
console.log(connectUrl);
|
|
198862
|
+
try {
|
|
198863
|
+
openBrowser(connectUrl);
|
|
198864
|
+
} catch {
|
|
198865
|
+
}
|
|
198866
|
+
const pieDir = import_node_path2.default.join(cwd, ".pie");
|
|
198867
|
+
const configPath = import_node_path2.default.join(pieDir, "config.json");
|
|
198868
|
+
const url = `${credentialsApi}?${new URLSearchParams({ code }).toString()}`;
|
|
198869
|
+
let first = true;
|
|
198870
|
+
while (true) {
|
|
198871
|
+
if (!first) {
|
|
198872
|
+
await sleepImpl(pollIntervalMs);
|
|
198873
|
+
}
|
|
198874
|
+
first = false;
|
|
198875
|
+
const ac = new AbortController;
|
|
198876
|
+
const timer = setTimeout(() => ac.abort(), 30000);
|
|
198877
|
+
let response;
|
|
198878
|
+
try {
|
|
198879
|
+
response = await fetchImpl(url, { signal: ac.signal });
|
|
198880
|
+
} finally {
|
|
198881
|
+
clearTimeout(timer);
|
|
198882
|
+
}
|
|
198883
|
+
if (!response.ok) {
|
|
198884
|
+
throw new Error(`[pieui] Login poll failed: HTTP ${response.status} ${response.statusText}`);
|
|
198885
|
+
}
|
|
198886
|
+
const data = await response.json();
|
|
198887
|
+
if (typeof data !== "object" || data === null || Array.isArray(data)) {
|
|
198888
|
+
continue;
|
|
198889
|
+
}
|
|
198890
|
+
const record = data;
|
|
198891
|
+
const status = record.status;
|
|
198892
|
+
if (status === "error") {
|
|
198893
|
+
const detail = typeof record.message === "string" && record.message || typeof record.error === "string" && record.error || "unknown error";
|
|
198894
|
+
throw new Error(`Login failed: ${detail}`);
|
|
198895
|
+
}
|
|
198896
|
+
if (status === "ok") {
|
|
198897
|
+
if (!("config" in record)) {
|
|
198898
|
+
throw new Error("Login succeeded but response had no 'config' field");
|
|
198899
|
+
}
|
|
198900
|
+
import_node_fs.default.mkdirSync(pieDir, { recursive: true });
|
|
198901
|
+
import_node_fs.default.writeFileSync(configPath, `${JSON.stringify(record.config, null, 2)}
|
|
198902
|
+
`, "utf8");
|
|
198903
|
+
console.log(`[pie] Saved credentials to ${configPath}`);
|
|
198904
|
+
appendPieCredentialsToEnv(cwd, record.config);
|
|
198905
|
+
return;
|
|
198906
|
+
}
|
|
198907
|
+
}
|
|
198908
|
+
}
|
|
198909
|
+
|
|
198521
198910
|
// src/cli.ts
|
|
198522
198911
|
var main = async () => {
|
|
198523
198912
|
const {
|
|
@@ -198550,6 +198939,15 @@ var main = async () => {
|
|
|
198550
198939
|
}
|
|
198551
198940
|
createCommand(createAppName);
|
|
198552
198941
|
return;
|
|
198942
|
+
case "create-pie-app":
|
|
198943
|
+
case "create-pieui":
|
|
198944
|
+
if (!createAppName) {
|
|
198945
|
+
console.error("[pieui] Error: App name is required for create-pie-app command");
|
|
198946
|
+
printUsage();
|
|
198947
|
+
process.exit(1);
|
|
198948
|
+
}
|
|
198949
|
+
createPieAppCommand(createAppName);
|
|
198950
|
+
return;
|
|
198553
198951
|
case "card":
|
|
198554
198952
|
if (cardAction !== "add") {
|
|
198555
198953
|
console.error("[pieui] Error: Supported card subcommands: add");
|
|
@@ -198647,6 +199045,9 @@ var main = async () => {
|
|
|
198647
199045
|
console.log(`[pieui] Append mode: ${append}`);
|
|
198648
199046
|
await postbuildCommand(srcDir, outDir, append);
|
|
198649
199047
|
return;
|
|
199048
|
+
case "login":
|
|
199049
|
+
await loginCommand();
|
|
199050
|
+
return;
|
|
198650
199051
|
default:
|
|
198651
199052
|
printUsage();
|
|
198652
199053
|
process.exit(1);
|
package/dist/code/args.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"args.d.ts","sourceRoot":"","sources":["../../src/code/args.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAKR,UAAU,EACb,MAAM,SAAS,CAAA;AAEhB,eAAO,MAAM,SAAS,GAAI,MAAM,MAAM,EAAE,KAAG,
|
|
1
|
+
{"version":3,"file":"args.d.ts","sourceRoot":"","sources":["../../src/code/args.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAKR,UAAU,EACb,MAAM,SAAS,CAAA;AAEhB,eAAO,MAAM,SAAS,GAAI,MAAM,MAAM,EAAE,KAAG,UA+I1C,CAAA;AAED,eAAO,MAAM,UAAU,YA8JtB,CAAA"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"createPieApp.d.ts","sourceRoot":"","sources":["../../../src/code/commands/createPieApp.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"createPieApp.d.ts","sourceRoot":"","sources":["../../../src/code/commands/createPieApp.ts"],"names":[],"mappings":"AAmOA,eAAO,MAAM,mBAAmB,GAAI,SAAS,MAAM,SAuElD,CAAA"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
export declare const CONNECT_BASE = "https://pieui.swarm.ing/connect";
|
|
2
|
+
export declare const CREDENTIALS_API = "https://api-pieui.swarm.ing/api/external/credentials";
|
|
3
|
+
export declare const CONNECT_BASE_ENV = "PIEUI_LOGIN_CONNECT_BASE";
|
|
4
|
+
export declare const CREDENTIALS_API_ENV = "PIEUI_LOGIN_CREDENTIALS_API";
|
|
5
|
+
export type LoginCommandOptions = {
|
|
6
|
+
cwd?: string;
|
|
7
|
+
pollIntervalMs?: number;
|
|
8
|
+
openBrowser?: (url: string) => void;
|
|
9
|
+
fetchImpl?: typeof fetch;
|
|
10
|
+
sleepImpl?: (ms: number) => Promise<void>;
|
|
11
|
+
};
|
|
12
|
+
export declare function loginCommand(options?: LoginCommandOptions): Promise<void>;
|
|
13
|
+
//# sourceMappingURL=login.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"login.d.ts","sourceRoot":"","sources":["../../../src/code/commands/login.ts"],"names":[],"mappings":"AAKA,eAAO,MAAM,YAAY,oCAAoC,CAAA;AAC7D,eAAO,MAAM,eAAe,yDAC8B,CAAA;AAC1D,eAAO,MAAM,gBAAgB,6BAA6B,CAAA;AAC1D,eAAO,MAAM,mBAAmB,gCAAgC,CAAA;AA2EhE,MAAM,MAAM,mBAAmB,GAAG;IAC9B,GAAG,CAAC,EAAE,MAAM,CAAA;IACZ,cAAc,CAAC,EAAE,MAAM,CAAA;IACvB,WAAW,CAAC,EAAE,CAAC,GAAG,EAAE,MAAM,KAAK,IAAI,CAAA;IACnC,SAAS,CAAC,EAAE,OAAO,KAAK,CAAA;IACxB,SAAS,CAAC,EAAE,CAAC,EAAE,EAAE,MAAM,KAAK,OAAO,CAAC,IAAI,CAAC,CAAA;CAC5C,CAAA;AAED,wBAAsB,YAAY,CAC9B,OAAO,GAAE,mBAAwB,GAClC,OAAO,CAAC,IAAI,CAAC,CAmFf"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@swarm.ing/pieui",
|
|
3
|
-
"version": "2.0.
|
|
3
|
+
"version": "2.0.15",
|
|
4
4
|
"description": "A React component library featuring PieCard component",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -61,7 +61,13 @@
|
|
|
61
61
|
"publish:npm": "npm publish",
|
|
62
62
|
"publish:beta": "npm publish --tag beta",
|
|
63
63
|
"unrelease": "git tag -d v$(node -p \"require('./package.json').version\") && git push origin :refs/tags/v$(node -p \"require('./package.json').version\")",
|
|
64
|
-
"version:current": "node -p \"require('./package.json').version\""
|
|
64
|
+
"version:current": "node -p \"require('./package.json').version\"",
|
|
65
|
+
"test:step1": "bun test src/__tests__/step1-local.test.cjs",
|
|
66
|
+
"test:step2": "bun test src/__tests__/step2-remote.test.cjs",
|
|
67
|
+
"test:step3": "bun test src/__tests__/step3-contract.test.cjs",
|
|
68
|
+
"test:step4": "bun test src/__tests__/step4-ci.test.cjs",
|
|
69
|
+
"test:step5": "bun test src/__tests__/step5-regres.test.cjs",
|
|
70
|
+
"test:steps": "bun test src/__tests__/step1-local.test.cjs src/__tests__/step2-remote.test.cjs src/__tests__/step3-contract.test.cjs src/__tests__/step4-ci.test.cjs src/__tests__/step5-regres.test.cjs"
|
|
65
71
|
},
|
|
66
72
|
"keywords": [
|
|
67
73
|
"react",
|