@swarm.ing/pieui 2.0.22 → 2.0.24

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.
Files changed (33) hide show
  1. package/dist/cli.js +992 -400
  2. package/dist/code/args.d.ts +3 -1
  3. package/dist/code/args.d.ts.map +1 -1
  4. package/dist/code/commands/add.d.ts.map +1 -1
  5. package/dist/code/commands/addEvent.d.ts.map +1 -1
  6. package/dist/code/commands/cardPull.d.ts +2 -0
  7. package/dist/code/commands/cardPull.d.ts.map +1 -0
  8. package/dist/code/commands/cardView.d.ts +2 -0
  9. package/dist/code/commands/cardView.d.ts.map +1 -0
  10. package/dist/code/commands/create.d.ts +1 -1
  11. package/dist/code/commands/create.d.ts.map +1 -1
  12. package/dist/code/commands/init.d.ts +1 -1
  13. package/dist/code/commands/init.d.ts.map +1 -1
  14. package/dist/code/commands/list.d.ts.map +1 -1
  15. package/dist/code/commands/pageAdd.d.ts.map +1 -1
  16. package/dist/code/commands/pageAjax.d.ts +3 -0
  17. package/dist/code/commands/pageAjax.d.ts.map +1 -0
  18. package/dist/code/commands/pageView.d.ts +2 -0
  19. package/dist/code/commands/pageView.d.ts.map +1 -0
  20. package/dist/code/commands/selfUpgrade.d.ts +2 -0
  21. package/dist/code/commands/selfUpgrade.d.ts.map +1 -0
  22. package/dist/code/scan.d.ts.map +1 -1
  23. package/dist/code/types.d.ts +8 -3
  24. package/dist/code/types.d.ts.map +1 -1
  25. package/dist/components/PieCard/index.d.ts +1 -1
  26. package/dist/components/PieCard/index.d.ts.map +1 -1
  27. package/dist/components/PieCard/types/index.d.ts +6 -0
  28. package/dist/components/PieCard/types/index.d.ts.map +1 -1
  29. package/dist/components/index.esm.js +1 -1
  30. package/dist/components/index.js +1 -1
  31. package/dist/index.esm.js +2 -2
  32. package/dist/index.js +2 -2
  33. package/package.json +1 -1
package/dist/cli.js CHANGED
@@ -883,9 +883,9 @@ globstar while`, t, d, e, u, m), this.matchOne(t.slice(d), e.slice(u), s))
883
883
  Wt2.LRUCache = undefined;
884
884
  var er = typeof performance == "object" && performance && typeof performance.now == "function" ? performance : Date, as2 = new Set, ge2 = typeof process == "object" && process ? process : {}, ls2 = (n7, t, e, s) => {
885
885
  typeof ge2.emitWarning == "function" ? ge2.emitWarning(n7, t, e, s) : console.error(`[${e}] ${t}: ${n7}`);
886
- }, Lt2 = globalThis.AbortController, os2 = globalThis.AbortSignal;
886
+ }, Lt2 = globalThis.AbortController, os3 = globalThis.AbortSignal;
887
887
  if (typeof Lt2 > "u") {
888
- os2 = class {
888
+ os3 = class {
889
889
  onabort;
890
890
  _onabort = [];
891
891
  reason;
@@ -897,7 +897,7 @@ globstar while`, t, d, e, u, m), this.matchOne(t.slice(d), e.slice(u), s))
897
897
  constructor() {
898
898
  t();
899
899
  }
900
- signal = new os2;
900
+ signal = new os3;
901
901
  abort(e) {
902
902
  if (!this.signal.aborted) {
903
903
  this.signal.reason = e, this.signal.aborted = true;
@@ -172964,7 +172964,7 @@ var require_v8_compile_cache = __commonJS((exports2, module2) => {
172964
172964
  var fs6 = require("fs");
172965
172965
  var path5 = require("path");
172966
172966
  var vm = require("vm");
172967
- var os2 = require("os");
172967
+ var os3 = require("os");
172968
172968
  var hasOwnProperty = Object.prototype.hasOwnProperty;
172969
172969
 
172970
172970
  class FileSystemBlobStore {
@@ -173208,7 +173208,7 @@ var require_v8_compile_cache = __commonJS((exports2, module2) => {
173208
173208
  }
173209
173209
  const dirname = typeof process.getuid === "function" ? "v8-compile-cache-" + process.getuid() : "v8-compile-cache";
173210
173210
  const version = typeof process.versions.v8 === "string" ? process.versions.v8 : typeof process.versions.chakracore === "string" ? "chakracore-" + process.versions.chakracore : "node-" + process.version;
173211
- const cacheDir = path5.join(os2.tmpdir(), dirname, version);
173211
+ const cacheDir = path5.join(os3.tmpdir(), dirname, version);
173212
173212
  return cacheDir;
173213
173213
  }
173214
173214
  function getMainName() {
@@ -188195,10 +188195,125 @@ var require_typescript_json_schema = __commonJS((exports2) => {
188195
188195
  }
188196
188196
  });
188197
188197
 
188198
+ // src/cli.ts
188199
+ var import_node_path10 = __toESM(require("node:path"));
188200
+
188198
188201
  // src/code/args.ts
188202
+ var VALID_CARD_ACTIONS = [
188203
+ "add",
188204
+ "list",
188205
+ "pull",
188206
+ "view",
188207
+ "remove",
188208
+ "list-events",
188209
+ "add-event",
188210
+ "remote"
188211
+ ];
188212
+ var VALID_CARD_REMOTE_ACTIONS = [
188213
+ "push",
188214
+ "pull",
188215
+ "list",
188216
+ "remove",
188217
+ "history",
188218
+ "public",
188219
+ "private"
188220
+ ];
188221
+ var VALID_PAGE_ACTIONS = ["add", "view", "ajax"];
188222
+ var VALID_PAGE_AJAX_ACTIONS = ["add", "remove"];
188223
+ var VALID_COMPONENT_TYPES = [
188224
+ "simple",
188225
+ "complex",
188226
+ "simple-container",
188227
+ "complex-container"
188228
+ ];
188229
+ var VALID_LIST_FILTERS = [
188230
+ "all",
188231
+ "simple",
188232
+ "complex",
188233
+ "simple-container",
188234
+ "complex-container"
188235
+ ];
188236
+ var parseIntFlag = (name, raw) => {
188237
+ if (!/^-?\d+$/.test(raw)) {
188238
+ throw new Error(`${name} must be an integer, got ${JSON.stringify(raw)}`);
188239
+ }
188240
+ return Number(raw);
188241
+ };
188242
+ var consumeFlags = (tokens) => {
188243
+ const flags = {};
188244
+ const positionals = [];
188245
+ let ajax = false;
188246
+ let io = false;
188247
+ for (let i = 0;i < tokens.length; i++) {
188248
+ const tok = tokens[i];
188249
+ if (tok === "--ajax") {
188250
+ ajax = true;
188251
+ continue;
188252
+ }
188253
+ if (tok === "--io") {
188254
+ io = true;
188255
+ continue;
188256
+ }
188257
+ if (tok === "--user" && tokens[i + 1]) {
188258
+ flags.remoteUserId = tokens[i + 1];
188259
+ i++;
188260
+ continue;
188261
+ }
188262
+ if (tok === "--project" && tokens[i + 1]) {
188263
+ flags.remoteProject = tokens[i + 1];
188264
+ i++;
188265
+ continue;
188266
+ }
188267
+ if (tok === "--page" && tokens[i + 1]) {
188268
+ flags.historyPage = parseIntFlag("--page", tokens[i + 1]);
188269
+ i++;
188270
+ continue;
188271
+ }
188272
+ if (tok === "--per-page" && tokens[i + 1]) {
188273
+ flags.historyPerPage = parseIntFlag("--per-page", tokens[i + 1]);
188274
+ i++;
188275
+ continue;
188276
+ }
188277
+ if (tok === "--from" && tokens[i + 1]) {
188278
+ flags.historyFrom = parseIntFlag("--from", tokens[i + 1]);
188279
+ i++;
188280
+ continue;
188281
+ }
188282
+ if (tok === "--to" && tokens[i + 1]) {
188283
+ flags.historyTo = parseIntFlag("--to", tokens[i + 1]);
188284
+ i++;
188285
+ continue;
188286
+ }
188287
+ if (tok.startsWith("--user=")) {
188288
+ flags.remoteUserId = tok.slice("--user=".length);
188289
+ continue;
188290
+ }
188291
+ if (tok.startsWith("--project=")) {
188292
+ flags.remoteProject = tok.slice("--project=".length);
188293
+ continue;
188294
+ }
188295
+ if (tok.startsWith("--page=")) {
188296
+ flags.historyPage = parseIntFlag("--page", tok.slice("--page=".length));
188297
+ continue;
188298
+ }
188299
+ if (tok.startsWith("--per-page=")) {
188300
+ flags.historyPerPage = parseIntFlag("--per-page", tok.slice("--per-page=".length));
188301
+ continue;
188302
+ }
188303
+ if (tok.startsWith("--from=")) {
188304
+ flags.historyFrom = parseIntFlag("--from", tok.slice("--from=".length));
188305
+ continue;
188306
+ }
188307
+ if (tok.startsWith("--to=")) {
188308
+ flags.historyTo = parseIntFlag("--to", tok.slice("--to=".length));
188309
+ continue;
188310
+ }
188311
+ positionals.push(tok);
188312
+ }
188313
+ return { positionals, flags, boolFlags: { ajax, io } };
188314
+ };
188199
188315
  var parseArgs = (argv) => {
188200
188316
  const [command = ""] = argv;
188201
- const cardFlagSet = new Set(["--io", "--ajax"]);
188202
188317
  const outDirFlag = argv.find((arg) => arg.startsWith("--out-dir="));
188203
188318
  const srcDirFlag = argv.find((arg) => arg.startsWith("--src-dir="));
188204
188319
  const outDirIndex = argv.findIndex((arg) => arg === "--out-dir" || arg === "-o");
@@ -188206,159 +188321,6 @@ var parseArgs = (argv) => {
188206
188321
  const appendFlag = argv.includes("--append");
188207
188322
  let outDir = command === "postbuild" ? "public" : ".";
188208
188323
  let srcDir = ".";
188209
- let componentType;
188210
- let componentName;
188211
- let createAppName;
188212
- let eventName;
188213
- let cardAction;
188214
- let cardAjax = false;
188215
- let cardIo = false;
188216
- let cardRemoteAction;
188217
- let remoteUserId;
188218
- let remoteProject;
188219
- let pageAction;
188220
- let pagePath;
188221
- let removeComponentName;
188222
- let listFilter;
188223
- if (command === "remove" && argv[1]) {
188224
- removeComponentName = argv[1];
188225
- }
188226
- if ((command === "create-pie-app" || command === "create-pieui" || command === "create") && argv[1]) {
188227
- createAppName = argv[1];
188228
- }
188229
- if (command === "list") {
188230
- const validFilters = [
188231
- "all",
188232
- "simple",
188233
- "complex",
188234
- "simple-container",
188235
- "complex-container"
188236
- ];
188237
- const filterArg = argv[1];
188238
- listFilter = filterArg && validFilters.includes(filterArg) ? filterArg : "all";
188239
- }
188240
- if (command === "card" && argv[1]) {
188241
- const validActions = ["add", "remote"];
188242
- if (validActions.includes(argv[1])) {
188243
- cardAction = argv[1];
188244
- }
188245
- }
188246
- if ((command === "card" && cardAction === "add" || command === "add") && argv[1]) {
188247
- const offset = command === "card" ? 2 : 1;
188248
- const cardArgv = argv.slice(offset);
188249
- const positionalArgs = cardArgv.filter((arg) => !cardFlagSet.has(arg));
188250
- cardIo = cardArgv.includes("--io");
188251
- cardAjax = cardArgv.includes("--ajax");
188252
- const validTypes = [
188253
- "simple",
188254
- "complex",
188255
- "simple-container",
188256
- "complex-container"
188257
- ];
188258
- if (validTypes.includes(positionalArgs[0])) {
188259
- componentType = positionalArgs[0];
188260
- componentName = positionalArgs[1];
188261
- } else {
188262
- componentType = "complex-container";
188263
- componentName = positionalArgs[0];
188264
- }
188265
- }
188266
- let historyPage;
188267
- let historyPerPage;
188268
- let historyFrom;
188269
- let historyTo;
188270
- if (command === "card" && cardAction === "remote" && argv[2]) {
188271
- const validRemoteActions = [
188272
- "push",
188273
- "pull",
188274
- "list",
188275
- "remove",
188276
- "history",
188277
- "public",
188278
- "private"
188279
- ];
188280
- const action = argv[2];
188281
- if (validRemoteActions.includes(action)) {
188282
- cardRemoteAction = action;
188283
- const rest = argv.slice(3);
188284
- const flagIndexes = new Set;
188285
- const parseIntFlag = (name, raw) => {
188286
- if (!/^-?\d+$/.test(raw)) {
188287
- throw new Error(`${name} must be an integer, got ${JSON.stringify(raw)}`);
188288
- }
188289
- return Number(raw);
188290
- };
188291
- for (let i = 0;i < rest.length; i++) {
188292
- const tok = rest[i];
188293
- if (tok === "--user" && rest[i + 1]) {
188294
- remoteUserId = rest[i + 1];
188295
- flagIndexes.add(i);
188296
- flagIndexes.add(i + 1);
188297
- i++;
188298
- } else if (tok === "--project" && rest[i + 1]) {
188299
- remoteProject = rest[i + 1];
188300
- flagIndexes.add(i);
188301
- flagIndexes.add(i + 1);
188302
- i++;
188303
- } else if (tok === "--page" && rest[i + 1]) {
188304
- historyPage = parseIntFlag("--page", rest[i + 1]);
188305
- flagIndexes.add(i);
188306
- flagIndexes.add(i + 1);
188307
- i++;
188308
- } else if (tok === "--per-page" && rest[i + 1]) {
188309
- historyPerPage = parseIntFlag("--per-page", rest[i + 1]);
188310
- flagIndexes.add(i);
188311
- flagIndexes.add(i + 1);
188312
- i++;
188313
- } else if (tok === "--from" && rest[i + 1]) {
188314
- historyFrom = parseIntFlag("--from", rest[i + 1]);
188315
- flagIndexes.add(i);
188316
- flagIndexes.add(i + 1);
188317
- i++;
188318
- } else if (tok === "--to" && rest[i + 1]) {
188319
- historyTo = parseIntFlag("--to", rest[i + 1]);
188320
- flagIndexes.add(i);
188321
- flagIndexes.add(i + 1);
188322
- i++;
188323
- } else if (tok?.startsWith("--user=")) {
188324
- remoteUserId = tok.slice("--user=".length);
188325
- flagIndexes.add(i);
188326
- } else if (tok?.startsWith("--project=")) {
188327
- remoteProject = tok.slice("--project=".length);
188328
- flagIndexes.add(i);
188329
- } else if (tok?.startsWith("--page=")) {
188330
- historyPage = parseIntFlag("--page", tok.slice("--page=".length));
188331
- flagIndexes.add(i);
188332
- } else if (tok?.startsWith("--per-page=")) {
188333
- historyPerPage = parseIntFlag("--per-page", tok.slice("--per-page=".length));
188334
- flagIndexes.add(i);
188335
- } else if (tok?.startsWith("--from=")) {
188336
- historyFrom = parseIntFlag("--from", tok.slice("--from=".length));
188337
- flagIndexes.add(i);
188338
- } else if (tok?.startsWith("--to=")) {
188339
- historyTo = parseIntFlag("--to", tok.slice("--to=".length));
188340
- flagIndexes.add(i);
188341
- }
188342
- }
188343
- const positionals = rest.filter((_, i) => !flagIndexes.has(i));
188344
- if (positionals[0])
188345
- componentName = positionals[0];
188346
- }
188347
- }
188348
- if (command === "page" && argv[1]) {
188349
- const validActions = ["add"];
188350
- if (validActions.includes(argv[1])) {
188351
- pageAction = argv[1];
188352
- pagePath = argv[2];
188353
- }
188354
- }
188355
- if (command === "list-events" && argv[1]) {
188356
- componentName = argv[1];
188357
- }
188358
- if (command === "add-event" && argv[1] && argv[2]) {
188359
- componentName = argv[1];
188360
- eventName = argv[2];
188361
- }
188362
188324
  if (outDirFlag) {
188363
188325
  outDir = outDirFlag.split("=")[1] || outDir;
188364
188326
  } else if (outDirIndex !== -1 && argv[outDirIndex + 1]) {
@@ -188369,127 +188331,323 @@ var parseArgs = (argv) => {
188369
188331
  } else if (srcDirIndex !== -1 && argv[srcDirIndex + 1]) {
188370
188332
  srcDir = argv[srcDirIndex + 1];
188371
188333
  }
188372
- return {
188334
+ const result = {
188373
188335
  command,
188374
188336
  outDir,
188375
188337
  srcDir,
188376
- append: appendFlag,
188377
- componentName,
188378
- createAppName,
188379
- componentType,
188380
- eventName,
188381
- removeComponentName,
188382
- listFilter,
188383
- cardAction,
188384
- cardAjax,
188385
- cardIo,
188386
- cardRemoteAction,
188387
- remoteUserId,
188388
- remoteProject,
188389
- pageAction,
188390
- pagePath,
188391
- historyPage,
188392
- historyPerPage,
188393
- historyFrom,
188394
- historyTo
188338
+ append: appendFlag
188395
188339
  };
188340
+ if (command === "self-upgrade") {
188341
+ const pmFlag = argv.find((arg) => arg.startsWith("--pm="));
188342
+ const pmIndex = argv.findIndex((arg) => arg === "--pm");
188343
+ if (pmFlag) {
188344
+ result.selfUpgradePm = pmFlag.split("=")[1];
188345
+ } else if (pmIndex !== -1 && argv[pmIndex + 1]) {
188346
+ result.selfUpgradePm = argv[pmIndex + 1];
188347
+ }
188348
+ }
188349
+ if ((command === "create-pie-app" || command === "create-pieui" || command === "create") && argv[1]) {
188350
+ result.createAppName = argv[1];
188351
+ }
188352
+ if (command === "card" && argv[1]) {
188353
+ const action = argv[1];
188354
+ if (!VALID_CARD_ACTIONS.includes(action)) {
188355
+ return result;
188356
+ }
188357
+ result.cardAction = action;
188358
+ const tail = argv.slice(2);
188359
+ const { positionals, flags, boolFlags } = consumeFlags(tail);
188360
+ if (action === "add") {
188361
+ result.cardAjax = boolFlags.ajax;
188362
+ result.cardIo = boolFlags.io;
188363
+ if (positionals[0] && VALID_COMPONENT_TYPES.includes(positionals[0])) {
188364
+ result.componentType = positionals[0];
188365
+ result.componentName = positionals[1];
188366
+ } else {
188367
+ result.componentType = "complex-container";
188368
+ result.componentName = positionals[0];
188369
+ }
188370
+ } else if (action === "list") {
188371
+ const filter = positionals[0];
188372
+ result.listFilter = filter && VALID_LIST_FILTERS.includes(filter) ? filter : "all";
188373
+ } else if (action === "pull") {
188374
+ result.cardPullRef = positionals[0];
188375
+ } else if (action === "view") {
188376
+ result.componentName = positionals[0];
188377
+ } else if (action === "remove") {
188378
+ result.componentName = positionals[0];
188379
+ } else if (action === "list-events") {
188380
+ result.componentName = positionals[0];
188381
+ } else if (action === "add-event") {
188382
+ result.componentName = positionals[0];
188383
+ result.eventName = positionals[1];
188384
+ } else if (action === "remote") {
188385
+ const sub = positionals[0];
188386
+ if (sub && VALID_CARD_REMOTE_ACTIONS.includes(sub)) {
188387
+ result.cardRemoteAction = sub;
188388
+ if (positionals[1])
188389
+ result.componentName = positionals[1];
188390
+ result.remoteUserId = flags.remoteUserId;
188391
+ result.remoteProject = flags.remoteProject;
188392
+ result.historyPage = flags.historyPage;
188393
+ result.historyPerPage = flags.historyPerPage;
188394
+ result.historyFrom = flags.historyFrom;
188395
+ result.historyTo = flags.historyTo;
188396
+ }
188397
+ }
188398
+ }
188399
+ if (command === "page" && argv[1]) {
188400
+ const action = argv[1];
188401
+ if (!VALID_PAGE_ACTIONS.includes(action)) {
188402
+ return result;
188403
+ }
188404
+ result.pageAction = action;
188405
+ if (action === "add") {
188406
+ result.pagePath = argv[2];
188407
+ } else if (action === "view") {
188408
+ result.pageName = argv[2];
188409
+ } else if (action === "ajax") {
188410
+ result.pageName = argv[2];
188411
+ const sub = argv[3];
188412
+ if (sub && VALID_PAGE_AJAX_ACTIONS.includes(sub)) {
188413
+ result.pageAjaxAction = sub;
188414
+ }
188415
+ result.pageAjaxHandler = argv[4];
188416
+ }
188417
+ }
188418
+ return result;
188396
188419
  };
188397
- var printUsage = () => {
188398
- console.log("Usage: pieui <command> [options]");
188399
- console.log("");
188400
- console.log("Commands:");
188401
- console.log(" create <AppName> Create a Next.js app and run pieui init inside it");
188402
- console.log(" create-pie-app <AppName> Create a blank Next.js web template for PieUI (bun create next-app under the hood)");
188403
- console.log(" create-pieui <AppName> Alias for create-pie-app");
188404
- console.log(" login Sign in to PieUI and save credentials to .pie/config.json");
188405
- console.log(" init Initialize piecomponents directory with registry.ts");
188406
- console.log(" card add [type] <ComponentName> [--io] [--ajax] Create a new component in piecomponents directory");
188407
- console.log(" page add <path> Create app/<path>/page.tsx from the standard Pie page template");
188408
- console.log(" card remote push <ComponentName> Upload piecomponents/<Name>/ to PieUI storage (prints new revision)");
188409
- console.log(" card remote pull <ComponentName>[@rev] Download component from current project (optional @<revision>)");
188410
- console.log(" card remote pull <project>/<ComponentName>[@rev] Pull from a different project of the current user");
188411
- console.log(" card remote pull r/<user>/<ComponentName> Pull a public component by another user");
188412
- console.log(" card remote list [--user U] [--project S] List remote components for the configured or specified user/project");
188413
- console.log(" card remote remove <ComponentName> Delete component from PieUI storage");
188414
- console.log(" card remote history <ComponentName> [--page N] [--per-page N] [--from R] [--to R] Show revision history with per-file diff stats");
188415
- console.log(" card remote public <ComponentName> Mark a component public (readable without API key as r/<user>/<Name>)");
188416
- console.log(" card remote private <ComponentName> Make a public component private again");
188417
- console.log(' list-events <ComponentName> List registered methods keys for <PieCard card="ComponentName" ... methods={...} />');
188418
- console.log(' add-event <ComponentName> <event> Add a new methods key with a default handler to <PieCard card="ComponentName" ... methods={...} />');
188419
- console.log(" remove <ComponentName> Remove a component from piecomponents directory");
188420
- console.log(" postbuild Scan for components and generate manifest");
188421
- console.log(" list [filter] List registered components in a table");
188422
- console.log("");
188423
- console.log("Component types for card add command:");
188424
- console.log(" simple Simple component (only data prop)");
188425
- console.log(" complex Complex component (data + children props)");
188426
- console.log(" simple-container Container with single content (data + content)");
188427
- console.log(" complex-container Container with array content (data + content[])");
188428
- console.log(" (default if type not specified)");
188429
- console.log("");
188430
- console.log("Options for card add:");
188431
- console.log(" --io Add realtime support fields to the generated data interface");
188432
- console.log(" --ajax Add AJAX request fields to the generated data interface");
188433
- console.log("");
188434
- console.log("Options for init:");
188435
- console.log(" --out-dir <dir>, -o <dir> Base directory for piecomponents (default: .)");
188436
- console.log("");
188437
- console.log("Options for postbuild:");
188438
- console.log(" --out-dir <dir>, -o <dir> Output directory (default: public)");
188439
- console.log(" --src-dir <dir>, -s <dir> Source directory (default: src)");
188440
- console.log(" --append Include built-in pieui components in the manifest");
188441
- console.log("");
188442
- console.log("Options for list:");
188443
- console.log(" --src-dir <dir>, -s <dir> Source directory (default: src)");
188444
- console.log("");
188445
- console.log("Options for list-events:");
188446
- console.log(" --src-dir <dir>, -s <dir> Source directory to scan (default: .)");
188447
- console.log("");
188448
- console.log("Options for add-event:");
188449
- console.log(" --src-dir <dir>, -s <dir> Source directory to modify (default: .)");
188450
- console.log("");
188451
- console.log("Filters for list:");
188452
- console.log(" all All components (default)");
188453
- console.log(" simple Simple components (only data prop)");
188454
- console.log(" complex Complex components (data + children props)");
188455
- console.log(" simple-container Container with single content");
188456
- console.log(" complex-container Container with array content");
188457
- console.log("");
188458
- console.log("Examples:");
188459
- console.log(" pieui login");
188460
- console.log(" pieui init");
188461
- console.log(" pieui create my-pie-app");
188462
- console.log(" pieui create-pie-app my-pie-app");
188463
- console.log(" pieui create-pieui my-pie-app");
188464
- console.log(" pieui init --out-dir packages/app");
188465
- console.log(" pieui card add MyCustomCard # Creates complex-container by default");
188466
- console.log(" pieui card add simple MySimpleCard # Creates simple component");
188467
- console.log(" pieui card add complex-container MyContainerCard # Creates complex container");
188468
- console.log(" pieui card add simple LiveCard --io --ajax # Adds realtime and AJAX fields");
188469
- console.log(" pieui page add chat # Creates app/chat/page.tsx");
188470
- console.log(" pieui postbuild --append --out-dir dist");
188471
- console.log(" pieui list # List all components");
188472
- console.log(" pieui list simple # List only simple components");
188473
- console.log(" pieui list complex-container --src-dir app # List complex containers in app/");
188474
- console.log(" pieui list-events ExchangeAlertsCard # Print methods table for that PieCard usage");
188475
- console.log(" pieui add-event ExchangeAlertsCard alert # Add methods.alert with default handler");
188476
- console.log(" pieui card remote push ExchangeAlertsCard # Upload component directory (server assigns new revision)");
188477
- console.log(" pieui card remote pull ExchangeAlertsCard # Download latest revision from current project");
188478
- console.log(" pieui card remote pull ExchangeAlertsCard@7 # Download revision 7 snapshot");
188479
- console.log(" pieui card remote pull other-proj/AlertsCard # Pull from another of your projects");
188480
- console.log(" pieui card remote pull r/delta37/YetAnotherCard # Pull a public component by user delta37");
188481
- console.log(" pieui card remote list # List remote components");
188482
- console.log(" pieui card remote remove ExchangeAlertsCard # Delete remote component");
188483
- console.log(" pieui card remote history ExchangeAlertsCard # Full history (newest first)");
188484
- console.log(" pieui card remote history ExchangeAlertsCard --page 1 --per-page 5 # Paginate");
188485
- console.log(" pieui card remote history ExchangeAlertsCard --from 12 --to 14 # Revision range");
188486
- console.log(" pieui card remote public ExchangeAlertsCard # Make this component public");
188487
- console.log(" pieui card remote private ExchangeAlertsCard # Revert to private");
188420
+ var detectHelpScope = (argv) => {
188421
+ if (!argv.includes("--help") && !argv.includes("-h"))
188422
+ return null;
188423
+ const [c0, c1] = argv;
188424
+ if (!c0 || c0 === "--help" || c0 === "-h")
188425
+ return "all";
188426
+ if (c0 === "card" && c1 === "remote")
188427
+ return "card-remote";
188428
+ if (c0 === "card")
188429
+ return "card";
188430
+ if (c0 === "page")
188431
+ return "page";
188432
+ if (c0 === "init")
188433
+ return "init";
188434
+ if (c0 === "postbuild")
188435
+ return "postbuild";
188436
+ if (c0 === "login")
188437
+ return "login";
188438
+ if (c0 === "self-upgrade")
188439
+ return "self-upgrade";
188440
+ if (c0 === "create" || c0 === "create-pie-app" || c0 === "create-pieui") {
188441
+ return "create";
188442
+ }
188443
+ return "all";
188444
+ };
188445
+ var ALL_LINES = [
188446
+ "Usage: pieui <command> [options]",
188447
+ "",
188448
+ "Commands:",
188449
+ " login Sign in to PieUI and save credentials to .pie/config.json",
188450
+ " create <AppName> Create a Next.js app and run pieui init inside it",
188451
+ " create-pie-app <AppName> Create a blank Next.js web template for PieUI",
188452
+ " create-pieui <AppName> Alias for create-pie-app",
188453
+ " init Initialize piecomponents dir, registry.ts, tailwind & next.config; prompt for backend dirs",
188454
+ " postbuild Scan for components and generate manifest",
188455
+ " self-upgrade [--pm bun|npm|pnpm|yarn] Upgrade the globally installed pieui CLI to the latest published version",
188456
+ "",
188457
+ "Card management (mirrors `pie card ...`):",
188458
+ " card add [type] <Name> [--io] [--ajax] Create a new component in piecomponents/",
188459
+ " card list [filter] List registered components",
188460
+ " card pull <ref> Pull a card by Name, project/Name, or r/user/Name (public alias)",
188461
+ " card view <Name> Print card name, props, ajax, IO, and events",
188462
+ " card remove <Name> Remove a component from piecomponents/",
188463
+ " card list-events <Name> List methods keys on the registered PieCard",
188464
+ " card add-event <Name> <event> Add a new methods key with a default handler",
188465
+ " card remote list [--user U] [--project S] List remote components",
188466
+ " card remote push <Name> Upload piecomponents/<Name>/ to PieUI storage",
188467
+ " card remote pull <Name>[@rev] Download component from PieUI storage",
188468
+ " card remote remove <Name> Delete component from PieUI storage",
188469
+ " card remote history <Name> [--page N] [--per-page N] [--from R] [--to R]",
188470
+ " Show revision history with per-file diff stats",
188471
+ " card remote public <Name> Mark component public (readable as r/<user>/<Name>)",
188472
+ " card remote private <Name> Make a public component private again",
188473
+ "",
188474
+ "Page management (mirrors `pie page ...`):",
188475
+ " page add <path> Create app/<path>/page.tsx from the standard Pie page template",
188476
+ " page view <path> Print app/<path>/page.tsx source",
188477
+ " page ajax <path> <add|remove> <handler> Add or remove an AJAX handler in app/<path>/page.tsx",
188478
+ "",
188479
+ "Component types for `card add`:",
188480
+ " simple Simple component (only data prop)",
188481
+ " complex Complex component (data + children props)",
188482
+ " simple-container Container with single content (data + content)",
188483
+ " complex-container Container with array content (data + content[]) [default]",
188484
+ "",
188485
+ "Options for `card add`:",
188486
+ " --io Add realtime support fields to the generated data interface",
188487
+ " --ajax Add AJAX request fields to the generated data interface",
188488
+ "",
188489
+ "Options for init:",
188490
+ " --out-dir <dir>, -o <dir> Base directory for piecomponents (default: .)",
188491
+ "",
188492
+ "Options for postbuild:",
188493
+ " --out-dir <dir>, -o <dir> Output directory (default: public)",
188494
+ " --src-dir <dir>, -s <dir> Source directory (default: src)",
188495
+ " --append Include built-in pieui components in the manifest",
188496
+ "",
188497
+ "Options for `card list` / `card list-events` / `card add-event`:",
188498
+ " --src-dir <dir>, -s <dir> Source directory (default: .)",
188499
+ "",
188500
+ "Examples:",
188501
+ " pieui login",
188502
+ " pieui self-upgrade",
188503
+ " pieui init",
188504
+ " pieui create my-pie-app",
188505
+ " pieui card add MyCustomCard",
188506
+ " pieui card add simple MySimpleCard",
188507
+ " pieui card list complex-container",
188508
+ " pieui card view MyCustomCard",
188509
+ " pieui card pull r/alice/HeroCard",
188510
+ " pieui card remote push MyCustomCard",
188511
+ " pieui page add dashboard",
188512
+ " pieui page view dashboard",
188513
+ " pieui page ajax dashboard add refresh"
188514
+ ];
188515
+ var CARD_LINES = [
188516
+ "Usage: pieui card <subcommand> [options]",
188517
+ "",
188518
+ "Subcommands:",
188519
+ " add [type] <Name> [--io] [--ajax] Create a new component in piecomponents/",
188520
+ " list [filter] List registered components",
188521
+ " pull <ref> Pull a card by Name, project/Name, or r/user/Name (public alias)",
188522
+ " view <Name> Print card name, props, ajax, IO, and events",
188523
+ " remove <Name> Remove a component from piecomponents/",
188524
+ " list-events <Name> List methods keys on the registered PieCard",
188525
+ " add-event <Name> <event> Add a new methods key with a default handler",
188526
+ " remote ... Remote storage operations (see `pieui card remote --help`)",
188527
+ "",
188528
+ "Component types for `card add`:",
188529
+ " simple Simple component (only data prop)",
188530
+ " complex Complex component (data + children props)",
188531
+ " simple-container Container with single content (data + content)",
188532
+ " complex-container Container with array content (data + content[]) [default]",
188533
+ "",
188534
+ "Options for `card add`:",
188535
+ " --io Add realtime support fields to the generated data interface",
188536
+ " --ajax Add AJAX request fields to the generated data interface",
188537
+ "",
188538
+ "Options for `card list` / `card list-events` / `card add-event`:",
188539
+ " --src-dir <dir>, -s <dir> Source directory (default: .)",
188540
+ "",
188541
+ "Examples:",
188542
+ " pieui card add MyCustomCard",
188543
+ " pieui card add simple MySimpleCard",
188544
+ " pieui card list complex-container",
188545
+ " pieui card view MyCustomCard",
188546
+ " pieui card pull r/alice/HeroCard"
188547
+ ];
188548
+ var CARD_REMOTE_LINES = [
188549
+ "Usage: pieui card remote <subcommand> [options]",
188550
+ "",
188551
+ "Subcommands:",
188552
+ " list [--user U] [--project S] List remote components",
188553
+ " push <Name> Upload piecomponents/<Name>/ to PieUI storage",
188554
+ " pull <Name>[@rev] Download component from PieUI storage",
188555
+ " remove <Name> Delete component from PieUI storage",
188556
+ " history <Name> [--page N] [--per-page N] [--from R] [--to R]",
188557
+ " Show revision history with per-file diff stats",
188558
+ " public <Name> Mark component public (readable as r/<user>/<Name>)",
188559
+ " private <Name> Make a public component private again",
188560
+ "",
188561
+ "Examples:",
188562
+ " pieui card remote push MyCustomCard",
188563
+ " pieui card remote pull MyCustomCard",
188564
+ " pieui card remote list --user alice --project demo",
188565
+ " pieui card remote history MyCustomCard --page 2"
188566
+ ];
188567
+ var PAGE_LINES = [
188568
+ "Usage: pieui page <subcommand> [options]",
188569
+ "",
188570
+ "Subcommands:",
188571
+ " add <path> Create app/<path>/page.tsx from the standard Pie page template",
188572
+ " view <path> Print app/<path>/page.tsx source",
188573
+ " ajax <path> <add|remove> <handler> Add or remove an AJAX handler in app/<path>/page.tsx",
188574
+ "",
188575
+ "Examples:",
188576
+ " pieui page add dashboard",
188577
+ " pieui page view dashboard",
188578
+ " pieui page ajax dashboard add refresh"
188579
+ ];
188580
+ var INIT_LINES = [
188581
+ "Usage: pieui init [options]",
188582
+ "",
188583
+ "Initialize piecomponents dir, registry.ts, tailwind & next.config; prompt for backend dirs.",
188584
+ "",
188585
+ "Options:",
188586
+ " --out-dir <dir>, -o <dir> Base directory for piecomponents (default: .)"
188587
+ ];
188588
+ var POSTBUILD_LINES = [
188589
+ "Usage: pieui postbuild [options]",
188590
+ "",
188591
+ "Scan for components and generate manifest.",
188592
+ "",
188593
+ "Options:",
188594
+ " --out-dir <dir>, -o <dir> Output directory (default: public)",
188595
+ " --src-dir <dir>, -s <dir> Source directory (default: src)",
188596
+ " --append Include built-in pieui components in the manifest"
188597
+ ];
188598
+ var LOGIN_LINES = [
188599
+ "Usage: pieui login",
188600
+ "",
188601
+ "Sign in to PieUI and save credentials to .pie/config.json."
188602
+ ];
188603
+ var SELF_UPGRADE_LINES = [
188604
+ "Usage: pieui self-upgrade [--pm bun|npm|pnpm|yarn]",
188605
+ "",
188606
+ "Upgrade the globally installed @swarm.ing/pieui CLI to the latest published version.",
188607
+ "",
188608
+ "Options:",
188609
+ " --pm <manager> Force package manager (default: auto-detect — prefers bun, then pnpm, yarn, npm)"
188610
+ ];
188611
+ var CREATE_LINES = [
188612
+ "Usage: pieui create <AppName>",
188613
+ " pieui create-pie-app <AppName>",
188614
+ " pieui create-pieui <AppName>",
188615
+ "",
188616
+ "`create` creates a Next.js app and runs `pieui init` inside it.",
188617
+ "`create-pie-app` (alias `create-pieui`) creates a blank Next.js web template for PieUI."
188618
+ ];
188619
+ var printUsage = (scope = "all") => {
188620
+ const lines = (() => {
188621
+ switch (scope) {
188622
+ case "card":
188623
+ return CARD_LINES;
188624
+ case "card-remote":
188625
+ return CARD_REMOTE_LINES;
188626
+ case "page":
188627
+ return PAGE_LINES;
188628
+ case "init":
188629
+ return INIT_LINES;
188630
+ case "postbuild":
188631
+ return POSTBUILD_LINES;
188632
+ case "login":
188633
+ return LOGIN_LINES;
188634
+ case "self-upgrade":
188635
+ return SELF_UPGRADE_LINES;
188636
+ case "create":
188637
+ return CREATE_LINES;
188638
+ default:
188639
+ return ALL_LINES;
188640
+ }
188641
+ })();
188642
+ for (const line of lines)
188643
+ console.log(line);
188488
188644
  };
188489
188645
 
188490
188646
  // src/code/commands/init.ts
188491
188647
  var import_fs = __toESM(require("fs"));
188648
+ var import_os = __toESM(require("os"));
188492
188649
  var import_path = __toESM(require("path"));
188650
+ var readline = __toESM(require("readline/promises"));
188493
188651
 
188494
188652
  // src/code/templates/componentIndex.ts
188495
188653
  var componentIndexTemplate = (componentName) => `import { registerPieComponent } from "@swarm.ing/pieui";
@@ -188837,15 +188995,15 @@ var componentTemplateFor = (componentType, componentName, options = {}) => {
188837
188995
  };
188838
188996
 
188839
188997
  // src/code/commands/init.ts
188840
- var initCommand = (outDir) => {
188998
+ var initCommand = async (outDir) => {
188841
188999
  const resolvedOutDir = import_path.default.resolve(process.cwd(), outDir);
188842
189000
  console.log(`[pieui] Initializing piecomponents directory in ${resolvedOutDir}...`);
188843
189001
  const pieComponentsDir = import_path.default.join(resolvedOutDir, "piecomponents");
188844
189002
  if (!import_fs.default.existsSync(pieComponentsDir)) {
188845
189003
  import_fs.default.mkdirSync(pieComponentsDir, { recursive: true });
188846
- console.log("[pieui] Created piecomponents directory");
189004
+ console.log(`[pieui] Created piecomponents directory: ${pieComponentsDir}`);
188847
189005
  } else {
188848
- console.log("[pieui] piecomponents directory already exists");
189006
+ console.log(`[pieui] piecomponents directory already exists: ${pieComponentsDir}`);
188849
189007
  }
188850
189008
  const registryPath = import_path.default.join(pieComponentsDir, "registry.ts");
188851
189009
  const registryContent = `"use client";
@@ -188856,9 +189014,9 @@ var initCommand = (outDir) => {
188856
189014
  `;
188857
189015
  if (!import_fs.default.existsSync(registryPath)) {
188858
189016
  import_fs.default.writeFileSync(registryPath, registryContent, "utf8");
188859
- console.log("[pieui] Created registry.ts");
189017
+ console.log(`[pieui] Created registry.ts: ${registryPath}`);
188860
189018
  } else {
188861
- console.log("[pieui] registry.ts already exists");
189019
+ console.log(`[pieui] registry.ts already exists: ${registryPath}`);
188862
189020
  }
188863
189021
  const tailwindConfigPath = import_path.default.join(resolvedOutDir, "tailwind.config.js");
188864
189022
  const tailwindConfigTsPath = import_path.default.join(resolvedOutDir, "tailwind.config.ts");
@@ -188902,11 +189060,156 @@ var initCommand = (outDir) => {
188902
189060
  console.log(`[pieui] "${pieuiContentPath}"`);
188903
189061
  }
188904
189062
  ensureNextConfig(resolvedOutDir);
189063
+ await ensureBackendPaths(resolvedOutDir);
188905
189064
  console.log("[pieui] Initialization complete!");
188906
189065
  console.log("[pieui] Next steps:");
188907
189066
  console.log(' 1. Import "./piecomponents/registry" in your app entry point');
188908
189067
  console.log(' 2. Use "pieui card add <ComponentName>" to create new components');
188909
189068
  };
189069
+ var PIE_CONFIG_DIR = ".pie";
189070
+ var PIE_CONFIG_FILE = "config.json";
189071
+ var MAX_HOMEDIR_SCAN_DEPTH = 2;
189072
+ var ensureBackendPaths = async (resolvedOutDir) => {
189073
+ const existing = readPieConfig(resolvedOutDir);
189074
+ if (existing.backendPagesDir && existing.backendComponentsDir) {
189075
+ console.log(`[pieui] Backend dirs already configured in .pie/${PIE_CONFIG_FILE}:`);
189076
+ console.log(`[pieui] pages: ${existing.backendPagesDir}`);
189077
+ console.log(`[pieui] components: ${existing.backendComponentsDir}`);
189078
+ return;
189079
+ }
189080
+ if (!process.stdin.isTTY) {
189081
+ console.log("[pieui] Non-interactive shell — skipping backend pages/components prompt.");
189082
+ console.log(`[pieui] To configure, add "backendPagesDir" and "backendComponentsDir" to ${import_path.default.join(resolvedOutDir, PIE_CONFIG_DIR, PIE_CONFIG_FILE)}`);
189083
+ return;
189084
+ }
189085
+ const home = import_os.default.homedir();
189086
+ console.log(`[pieui] Searching ${home} for backend projects with pages/ and components/ directories...`);
189087
+ const candidates = findBackendCandidates(home, MAX_HOMEDIR_SCAN_DEPTH);
189088
+ const rl = readline.createInterface({
189089
+ input: process.stdin,
189090
+ output: process.stdout
189091
+ });
189092
+ try {
189093
+ let pagesDir = existing.backendPagesDir;
189094
+ let componentsDir = existing.backendComponentsDir;
189095
+ if (!pagesDir || !componentsDir) {
189096
+ const picked = await pickBackendPair(rl, candidates, home);
189097
+ if (picked) {
189098
+ pagesDir = pagesDir || picked.pages;
189099
+ componentsDir = componentsDir || picked.components;
189100
+ }
189101
+ }
189102
+ if (!pagesDir) {
189103
+ pagesDir = await promptAbsoluteDir(rl, "Path to backend pages directory", home);
189104
+ }
189105
+ if (!componentsDir) {
189106
+ componentsDir = await promptAbsoluteDir(rl, "Path to backend components directory", home);
189107
+ }
189108
+ if (!pagesDir || !componentsDir) {
189109
+ console.log("[pieui] Skipped backend paths — neither directory was provided.");
189110
+ return;
189111
+ }
189112
+ writePieConfig(resolvedOutDir, {
189113
+ ...existing,
189114
+ backendPagesDir: pagesDir,
189115
+ backendComponentsDir: componentsDir
189116
+ });
189117
+ const configPath = import_path.default.join(resolvedOutDir, PIE_CONFIG_DIR, PIE_CONFIG_FILE);
189118
+ console.log(`[pieui] Saved backend paths to ${configPath}`);
189119
+ console.log(`[pieui] pages: ${pagesDir}`);
189120
+ console.log(`[pieui] components: ${componentsDir}`);
189121
+ } finally {
189122
+ rl.close();
189123
+ }
189124
+ };
189125
+ var findBackendCandidates = (home, maxDepth) => {
189126
+ const found = [];
189127
+ const visit = (dir, depth) => {
189128
+ if (depth > maxDepth)
189129
+ return;
189130
+ let entries;
189131
+ try {
189132
+ entries = import_fs.default.readdirSync(dir, { withFileTypes: true });
189133
+ } catch {
189134
+ return;
189135
+ }
189136
+ const subdirs = entries.filter((e) => e.isDirectory() && !e.name.startsWith("."));
189137
+ const subdirNames = new Set(subdirs.map((e) => e.name));
189138
+ if (subdirNames.has("pages") && subdirNames.has("components")) {
189139
+ found.push({
189140
+ project: dir,
189141
+ pages: import_path.default.join(dir, "pages"),
189142
+ components: import_path.default.join(dir, "components")
189143
+ });
189144
+ }
189145
+ for (const sub of subdirs) {
189146
+ if (sub.name === "node_modules" || sub.name === ".git")
189147
+ continue;
189148
+ visit(import_path.default.join(dir, sub.name), depth + 1);
189149
+ }
189150
+ };
189151
+ visit(home, 0);
189152
+ return found;
189153
+ };
189154
+ var pickBackendPair = async (rl, candidates, home) => {
189155
+ if (candidates.length === 0) {
189156
+ console.log("[pieui] No matching backend projects found under home directory.");
189157
+ return null;
189158
+ }
189159
+ console.log("[pieui] Found backend candidates:");
189160
+ candidates.forEach((c, i) => {
189161
+ const rel = import_path.default.relative(home, c.project) || ".";
189162
+ console.log(` ${i + 1}. ~/${rel}`);
189163
+ });
189164
+ const answer = (await rl.question(`[pieui] Pick a candidate [1-${candidates.length}] or press Enter to type paths manually: `)).trim();
189165
+ if (!answer)
189166
+ return null;
189167
+ const idx = Number.parseInt(answer, 10);
189168
+ if (Number.isNaN(idx) || idx < 1 || idx > candidates.length) {
189169
+ console.log("[pieui] Invalid selection — falling back to manual input.");
189170
+ return null;
189171
+ }
189172
+ return candidates[idx - 1];
189173
+ };
189174
+ var promptAbsoluteDir = async (rl, label, home) => {
189175
+ while (true) {
189176
+ const raw = (await rl.question(`[pieui] ${label} (absolute or ~/...): `)).trim();
189177
+ if (!raw)
189178
+ return;
189179
+ const expanded = raw.startsWith("~") ? import_path.default.join(home, raw.slice(1).replace(/^[\\/]/, "")) : raw;
189180
+ const absolute = import_path.default.resolve(expanded);
189181
+ if (!absolute.startsWith(home + import_path.default.sep) && absolute !== home) {
189182
+ console.log(`[pieui] Warning: ${absolute} is outside ${home}. Continuing anyway.`);
189183
+ }
189184
+ if (!import_fs.default.existsSync(absolute) || !import_fs.default.statSync(absolute).isDirectory()) {
189185
+ console.log(`[pieui] Not a directory: ${absolute}. Try again.`);
189186
+ continue;
189187
+ }
189188
+ return absolute;
189189
+ }
189190
+ };
189191
+ var readPieConfig = (resolvedOutDir) => {
189192
+ const configPath = import_path.default.join(resolvedOutDir, PIE_CONFIG_DIR, PIE_CONFIG_FILE);
189193
+ if (!import_fs.default.existsSync(configPath))
189194
+ return {};
189195
+ try {
189196
+ const parsed = JSON.parse(import_fs.default.readFileSync(configPath, "utf8"));
189197
+ if (typeof parsed !== "object" || parsed === null || Array.isArray(parsed))
189198
+ return {};
189199
+ return parsed;
189200
+ } catch {
189201
+ return {};
189202
+ }
189203
+ };
189204
+ var writePieConfig = (resolvedOutDir, config) => {
189205
+ const pieDir = import_path.default.join(resolvedOutDir, PIE_CONFIG_DIR);
189206
+ if (!import_fs.default.existsSync(pieDir)) {
189207
+ import_fs.default.mkdirSync(pieDir, { recursive: true });
189208
+ }
189209
+ const configPath = import_path.default.join(pieDir, PIE_CONFIG_FILE);
189210
+ import_fs.default.writeFileSync(configPath, `${JSON.stringify(config, null, 2)}
189211
+ `, "utf8");
189212
+ };
188910
189213
  var ensureNextConfig = (resolvedOutDir) => {
188911
189214
  const candidates = [
188912
189215
  "next.config.ts",
@@ -189075,10 +189378,10 @@ var addCommand = (componentName, componentType = "complex-container", options =
189075
189378
  }
189076
189379
  console.log(`[pieui] Component ${componentName} (${componentType}) created successfully!`);
189077
189380
  console.log(`[pieui] Files created:`);
189078
- console.log(` - piecomponents/${componentName}/index.ts`);
189079
- console.log(` - piecomponents/${componentName}/types/index.ts`);
189080
- console.log(` - piecomponents/${componentName}/ui/${componentName}.tsx`);
189081
- console.log(`[pieui] Updated registry.ts with new component`);
189381
+ console.log(` - ${import_path3.default.join(componentDir, "index.ts")}`);
189382
+ console.log(` - ${import_path3.default.join(componentDir, "types", "index.ts")}`);
189383
+ console.log(` - ${import_path3.default.join(componentDir, "ui", `${componentName}.tsx`)}`);
189384
+ console.log(`[pieui] Updated registry: ${resolveRegistryPath(pieComponentsDir)}`);
189082
189385
  console.log("");
189083
189386
  console.log(`[pieui] Component type: ${componentType}`);
189084
189387
  console.log(`[pieui] IO fields: ${options.io ? "enabled" : "disabled"}`);
@@ -189113,12 +189416,12 @@ var removeCommand = (componentName) => {
189113
189416
  console.error("[pieui] Error: piecomponents directory not found. Nothing to remove.");
189114
189417
  process.exit(1);
189115
189418
  }
189116
- const componentDir = import_path4.default.join(pieComponentsDir, componentName);
189419
+ const componentDir = import_path4.default.resolve(pieComponentsDir, componentName);
189117
189420
  if (import_fs4.default.existsSync(componentDir)) {
189118
189421
  import_fs4.default.rmSync(componentDir, { recursive: true, force: true });
189119
- console.log(`[pieui] Removed directory: piecomponents/${componentName}`);
189422
+ console.log(`[pieui] Removed directory: ${componentDir}`);
189120
189423
  } else {
189121
- console.log(`[pieui] Warning: Component directory piecomponents/${componentName} not found`);
189424
+ console.log(`[pieui] Warning: Component directory not found: ${componentDir}`);
189122
189425
  }
189123
189426
  const registryPath = resolveRegistryPath(pieComponentsDir);
189124
189427
  if (import_fs4.default.existsSync(registryPath)) {
@@ -189131,9 +189434,9 @@ var removeCommand = (componentName) => {
189131
189434
  `);
189132
189435
  if (registryContent !== originalContent) {
189133
189436
  import_fs4.default.writeFileSync(registryPath, registryContent, "utf8");
189134
- console.log(`[pieui] Cleaned up registry.ts`);
189437
+ console.log(`[pieui] Cleaned up registry: ${registryPath}`);
189135
189438
  } else {
189136
- console.log(`[pieui] Warning: ${componentName} not found in registry.ts`);
189439
+ console.log(`[pieui] Warning: ${componentName} not found in ${registryPath}`);
189137
189440
  }
189138
189441
  }
189139
189442
  console.log(`[pieui] Component ${componentName} removed successfully!`);
@@ -189187,7 +189490,7 @@ var pe = "\x00PERIOD" + Math.random() + "\x00";
189187
189490
  var is = new RegExp(fe, "g");
189188
189491
  var rs = new RegExp(ue, "g");
189189
189492
  var ns = new RegExp(qt, "g");
189190
- var os = new RegExp(de, "g");
189493
+ var os2 = new RegExp(de, "g");
189191
189494
  var hs = new RegExp(pe, "g");
189192
189495
  var as = /\\\\/g;
189193
189496
  var ls = /\\{/g;
@@ -189202,7 +189505,7 @@ function ps(n) {
189202
189505
  return n.replace(as, fe).replace(ls, ue).replace(cs, qt).replace(fs5, de).replace(us, pe);
189203
189506
  }
189204
189507
  function ms(n) {
189205
- return n.replace(is, "\\").replace(rs, "{").replace(ns, "}").replace(os, ",").replace(hs, ".");
189508
+ return n.replace(is, "\\").replace(rs, "{").replace(ns, "}").replace(os2, ",").replace(hs, ".");
189206
189509
  }
189207
189510
  function me(n) {
189208
189511
  if (!n)
@@ -192462,7 +192765,7 @@ var defaultCompilerOptions = () => ({
192462
192765
  skipLibCheck: true
192463
192766
  });
192464
192767
  var findComponentRegistrations = (srcDir) => {
192465
- console.log(`[pieui] Searching for components in: ${srcDir}`);
192768
+ console.log(`[pieui] Searching for components in: ${import_path5.default.resolve(process.cwd(), srcDir)}`);
192466
192769
  const files = Ze.sync(`${srcDir}/**/*.{ts,tsx}`, {
192467
192770
  ignore: ["**/*.d.ts", "**/dist/**", "**/node_modules/**"]
192468
192771
  });
@@ -192602,7 +192905,8 @@ var detectComponentType = (propsType, checker) => {
192602
192905
 
192603
192906
  // src/code/commands/list.ts
192604
192907
  var listCommand = (srcDir, filter) => {
192605
- console.log(`[pieui] Scanning components in: ${srcDir}`);
192908
+ const resolvedSrcDir = import_path6.default.resolve(process.cwd(), srcDir);
192909
+ console.log(`[pieui] Scanning components in: ${resolvedSrcDir}`);
192606
192910
  const files = Ze.sync(`${srcDir}/**/*.{ts,tsx}`, {
192607
192911
  ignore: [
192608
192912
  "**/*.d.ts",
@@ -192698,7 +193002,7 @@ var listCommand = (srcDir, filter) => {
192698
193002
  components.push({
192699
193003
  name: componentName,
192700
193004
  type: compType,
192701
- file: import_path6.default.relative(process.cwd(), componentFile),
193005
+ file: import_path6.default.resolve(componentFile),
192702
193006
  dataType: dataTypeName,
192703
193007
  lazy: hasLoader && !componentRef
192704
193008
  });
@@ -192919,7 +193223,7 @@ var listEventsCommand = (srcDir, componentName) => {
192919
193223
  entries.push({
192920
193224
  event: f.event,
192921
193225
  handler: f.handler,
192922
- file: import_path7.default.relative(process.cwd(), sourceFile.fileName),
193226
+ file: import_path7.default.resolve(sourceFile.fileName),
192923
193227
  line: f.line
192924
193228
  });
192925
193229
  }
@@ -192951,7 +193255,7 @@ var listEventsCommand = (srcDir, componentName) => {
192951
193255
  entries.push({
192952
193256
  event: f.event,
192953
193257
  handler: f.handler,
192954
- file: import_path7.default.relative(process.cwd(), sourceFile.fileName),
193258
+ file: import_path7.default.resolve(sourceFile.fileName),
192955
193259
  line: f.line
192956
193260
  });
192957
193261
  }
@@ -193134,7 +193438,7 @@ var addEventCommand = (srcDir, componentName, eventName) => {
193134
193438
  const methodsObj = target.methodsObj;
193135
193439
  const existingKeys = getPropertyKeys(methodsObj);
193136
193440
  if (existingKeys.has(eventName)) {
193137
- console.log(`[pieui] methods.${eventName} already exists in ${import_path8.default.relative(process.cwd(), filePath)}`);
193441
+ console.log(`[pieui] methods.${eventName} already exists in ${import_path8.default.resolve(filePath)}`);
193138
193442
  return;
193139
193443
  }
193140
193444
  const { propIndent, closingIndent } = computeIndentFromExistingProp(sourceText, target.sourceFile, methodsObj);
@@ -193150,7 +193454,7 @@ ${propIndent}${eventName}: ${handler}
193150
193454
  ${closingIndent}`;
193151
193455
  const updated = sourceText.slice(0, insertAt) + insertion + sourceText.slice(insertAt);
193152
193456
  import_fs6.default.writeFileSync(filePath, updated, "utf8");
193153
- console.log(`[pieui] Updated: ${import_path8.default.relative(process.cwd(), filePath)} (added "${eventName}")`);
193457
+ console.log(`[pieui] Updated: ${import_path8.default.resolve(filePath)} (added "${eventName}")`);
193154
193458
  };
193155
193459
 
193156
193460
  // src/code/commands/postbuild.ts
@@ -194286,6 +194590,115 @@ var cardRemotePrivateCommand = async (componentName) => {
194286
194590
  console.log(`[pieui] is_public: ${state.isPublic}`);
194287
194591
  };
194288
194592
 
194593
+ // src/code/commands/cardPull.ts
194594
+ var cardPullCommand = async (cardRef) => {
194595
+ await cardRemotePullCommand(cardRef);
194596
+ };
194597
+
194598
+ // src/code/commands/cardView.ts
194599
+ var import_node_fs4 = __toESM(require("node:fs"));
194600
+ var import_node_path5 = __toESM(require("node:path"));
194601
+ var AJAX_FIELD_NAMES2 = new Set(["pathname", "deps_names", "kwargs"]);
194602
+ var IO_FIELD_RE = /\buse_[A-Za-z0-9_]+_support\b/g;
194603
+ var extractInterfaceBody = (source, interfaceName) => {
194604
+ const idx = source.indexOf(`interface ${interfaceName}`);
194605
+ if (idx === -1)
194606
+ return null;
194607
+ const braceStart = source.indexOf("{", idx);
194608
+ if (braceStart === -1)
194609
+ return null;
194610
+ let depth = 0;
194611
+ for (let i = braceStart;i < source.length; i++) {
194612
+ const ch = source[i];
194613
+ if (ch === "{")
194614
+ depth++;
194615
+ else if (ch === "}") {
194616
+ depth--;
194617
+ if (depth === 0)
194618
+ return source.slice(braceStart + 1, i);
194619
+ }
194620
+ }
194621
+ return null;
194622
+ };
194623
+ var parseProps = (body) => {
194624
+ const props = [];
194625
+ const lineRe = /^[ \t]*([A-Za-z_][A-Za-z0-9_]*)(\?)?\s*:\s*([^;\n]+?)\s*;?\s*$/gm;
194626
+ let match;
194627
+ while ((match = lineRe.exec(body)) !== null) {
194628
+ const [, name, optional, typeRaw] = match;
194629
+ props.push({
194630
+ name,
194631
+ type: typeRaw.trim(),
194632
+ default: optional ? "(optional)" : "(required)"
194633
+ });
194634
+ }
194635
+ return props;
194636
+ };
194637
+ var formatTable = (headers, rows) => {
194638
+ const data = [headers, ...rows];
194639
+ const widths = headers.map((_2, c) => Math.max(...data.map((row) => (row[c] ?? "").length)));
194640
+ const hline = `+${widths.map((w) => "-".repeat(w + 2)).join("+")}+`;
194641
+ const fmtRow = (cells) => `|${cells.map((cell, i) => ` ${(cell ?? "").padEnd(widths[i])} `).join("|")}|`;
194642
+ return [hline, fmtRow(headers), hline, ...rows.map(fmtRow), hline].join(`
194643
+ `);
194644
+ };
194645
+ var cardViewCommand = (componentName) => {
194646
+ const settings = loadSettings();
194647
+ const componentDir = import_node_path5.default.join(settings.componentsDir, componentName);
194648
+ if (!import_node_fs4.default.existsSync(componentDir)) {
194649
+ throw new Error(`Component directory not found: ${componentDir}`);
194650
+ }
194651
+ const typesPath = import_node_path5.default.join(componentDir, "types.ts");
194652
+ const indexPath = import_node_path5.default.join(componentDir, "index.tsx");
194653
+ const indexPathTs = import_node_path5.default.join(componentDir, "index.ts");
194654
+ const typesSource = import_node_fs4.default.existsSync(typesPath) ? import_node_fs4.default.readFileSync(typesPath, "utf8") : "";
194655
+ const indexSource = import_node_fs4.default.existsSync(indexPath) ? import_node_fs4.default.readFileSync(indexPath, "utf8") : import_node_fs4.default.existsSync(indexPathTs) ? import_node_fs4.default.readFileSync(indexPathTs, "utf8") : "";
194656
+ const dataInterface = extractInterfaceBody(typesSource, `${componentName}Data`) ?? "";
194657
+ const props = parseProps(dataInterface);
194658
+ const hasAjax = props.some((p) => AJAX_FIELD_NAMES2.has(p.name));
194659
+ const ioFields2 = props.map((p) => p.name).filter((name) => IO_FIELD_RE.test(name));
194660
+ IO_FIELD_RE.lastIndex = 0;
194661
+ const events = [];
194662
+ const eventRe = /\b(?:on|create)([A-Z][A-Za-z0-9]*)Event\b|methods\s*=\s*\{([\s\S]*?)\}/g;
194663
+ const methodsMatch = indexSource.match(/methods\s*=\s*\{([\s\S]*?)\}/);
194664
+ if (methodsMatch) {
194665
+ const inner = methodsMatch[1];
194666
+ const keyRe = /([A-Za-z_][A-Za-z0-9_]*)\s*:/g;
194667
+ let m;
194668
+ while ((m = keyRe.exec(inner)) !== null)
194669
+ events.push(m[1]);
194670
+ }
194671
+ console.log("Name:");
194672
+ console.log(componentName);
194673
+ console.log("");
194674
+ console.log("File:");
194675
+ console.log(import_node_path5.default.resolve(componentDir));
194676
+ console.log("");
194677
+ console.log("Props:");
194678
+ if (props.length === 0) {
194679
+ console.log("(none)");
194680
+ } else {
194681
+ console.log(formatTable(["Name", "Type", "Default"], props.map((p) => [p.name, p.type, p.default])));
194682
+ }
194683
+ console.log("");
194684
+ console.log("Ajax:");
194685
+ console.log(hasAjax ? "yes" : "no");
194686
+ console.log("");
194687
+ console.log("IO:");
194688
+ if (ioFields2.length === 0) {
194689
+ console.log("no");
194690
+ } else {
194691
+ console.log(formatTable(["name"], ioFields2.map((n7) => [n7])));
194692
+ }
194693
+ console.log("");
194694
+ console.log("Events:");
194695
+ if (events.length === 0) {
194696
+ console.log("no (run `pieui card list-events " + componentName + "`)");
194697
+ } else {
194698
+ console.log(formatTable(["event"], events.map((e) => [e])));
194699
+ }
194700
+ };
194701
+
194289
194702
  // src/code/commands/pageAdd.ts
194290
194703
  var import_fs8 = __toESM(require("fs"));
194291
194704
  var import_path10 = __toESM(require("path"));
@@ -194325,12 +194738,93 @@ var pageAddCommand = (pagePath) => {
194325
194738
  throw new Error("Page path must stay inside the app directory");
194326
194739
  }
194327
194740
  if (import_fs8.default.existsSync(targetFile)) {
194328
- console.error(`[pieui] Error: Page already exists at app/${normalizedPath}/page.tsx`);
194741
+ console.error(`[pieui] Error: Page already exists at ${targetFile}`);
194329
194742
  process.exit(1);
194330
194743
  }
194331
194744
  import_fs8.default.mkdirSync(import_path10.default.dirname(targetFile), { recursive: true });
194332
194745
  import_fs8.default.writeFileSync(targetFile, pageTemplate(pageComponentName), "utf8");
194333
- console.log(`[pieui] Page created successfully at app/${normalizedPath}/page.tsx`);
194746
+ console.log(`[pieui] Page created successfully at ${targetFile}`);
194747
+ };
194748
+
194749
+ // src/code/commands/pageView.ts
194750
+ var import_node_fs5 = __toESM(require("node:fs"));
194751
+ var import_node_path6 = __toESM(require("node:path"));
194752
+ var normalizePagePath2 = (pagePath) => {
194753
+ const trimmed = pagePath.trim();
194754
+ if (!trimmed)
194755
+ throw new Error("Path is required for page view command");
194756
+ const slashed = trimmed.replace(/\\/g, "/");
194757
+ const noRel = slashed.replace(/^\.\/+/, "");
194758
+ const noApp = noRel.replace(/^app\//, "");
194759
+ const noEdge = noApp.replace(/^\/+|\/+$/g, "");
194760
+ const normalized = import_node_path6.default.posix.normalize(noEdge);
194761
+ if (!normalized || normalized === ".") {
194762
+ throw new Error("Path is required for page view command");
194763
+ }
194764
+ if (normalized === ".." || normalized.startsWith("../") || normalized.includes("/../")) {
194765
+ throw new Error("Page path must stay inside the app directory");
194766
+ }
194767
+ return normalized;
194768
+ };
194769
+ var pageViewCommand = (pagePath) => {
194770
+ const normalized = normalizePagePath2(pagePath);
194771
+ const target = import_node_path6.default.join(process.cwd(), "app", normalized, "page.tsx");
194772
+ if (!import_node_fs5.default.existsSync(target)) {
194773
+ throw new Error(`Page file not found: ${target}`);
194774
+ }
194775
+ const source = import_node_fs5.default.readFileSync(target, "utf8");
194776
+ console.log(`[pieui] Path: ${target}`);
194777
+ console.log("");
194778
+ process.stdout.write(source);
194779
+ if (!source.endsWith(`
194780
+ `))
194781
+ console.log("");
194782
+ };
194783
+
194784
+ // src/code/commands/pageAjax.ts
194785
+ var import_node_fs6 = __toESM(require("node:fs"));
194786
+ var import_node_path7 = __toESM(require("node:path"));
194787
+ var import_node_child_process = require("node:child_process");
194788
+ var PIE_CONFIG_PATH = ".pie/config.json";
194789
+ var readBackendRoot = () => {
194790
+ const configPath = import_node_path7.default.join(process.cwd(), PIE_CONFIG_PATH);
194791
+ if (!import_node_fs6.default.existsSync(configPath))
194792
+ return;
194793
+ try {
194794
+ const parsed = JSON.parse(import_node_fs6.default.readFileSync(configPath, "utf8"));
194795
+ if (typeof parsed !== "object" || parsed === null)
194796
+ return;
194797
+ const config = parsed;
194798
+ if (!config.backendPagesDir)
194799
+ return;
194800
+ const pages = import_node_path7.default.resolve(config.backendPagesDir);
194801
+ if (!import_node_fs6.default.existsSync(pages) || !import_node_fs6.default.statSync(pages).isDirectory()) {
194802
+ return;
194803
+ }
194804
+ return import_node_path7.default.dirname(pages);
194805
+ } catch {
194806
+ return;
194807
+ }
194808
+ };
194809
+ var pageAjaxCommand = (pageName, action, handlerName) => {
194810
+ if (!pageName)
194811
+ throw new Error("Page name is required for page ajax command");
194812
+ if (!handlerName) {
194813
+ throw new Error("Handler name is required for page ajax command");
194814
+ }
194815
+ const backendRoot = readBackendRoot();
194816
+ if (!backendRoot) {
194817
+ throw new Error("Backend project not configured. Run `pieui init` to link a backend project (saves backendPagesDir/.backendComponentsDir to .pie/config.json).");
194818
+ }
194819
+ console.log(`[pieui] Delegating to backend: ${backendRoot}`);
194820
+ console.log(`[pieui] pie page ajax ${pageName} ${action} ${handlerName}`);
194821
+ const result = import_node_child_process.spawnSync("pie", ["page", "ajax", pageName, action, handlerName], { cwd: backendRoot, stdio: "inherit", env: process.env });
194822
+ if (result.error) {
194823
+ throw new Error(`Failed to invoke \`pie\` in ${backendRoot}: ${result.error.message}`);
194824
+ }
194825
+ if (typeof result.status === "number" && result.status !== 0) {
194826
+ process.exit(result.status);
194827
+ }
194334
194828
  };
194335
194829
 
194336
194830
  // src/code/commands/create.ts
@@ -194338,6 +194832,7 @@ var import_fs9 = __toESM(require("fs"));
194338
194832
  var import_path11 = __toESM(require("path"));
194339
194833
  var import_child_process = require("child_process");
194340
194834
  var DEFAULT_TEMPLATE_SPEC = "next-app@latest";
194835
+ var DEFAULT_PIEUI_PACKAGE_SPEC = "@swarm.ing/pieui";
194341
194836
  var clearDirectory = (targetDir) => {
194342
194837
  if (!import_fs9.default.existsSync(targetDir))
194343
194838
  return;
@@ -194395,7 +194890,7 @@ var runBunCommand = (bunBin, args, cwd) => {
194395
194890
  throw new Error(`${args.join(" ")} failed (exit code ${result.status ?? "unknown"})`);
194396
194891
  }
194397
194892
  };
194398
- var createCommand = (appName) => {
194893
+ var createCommand = async (appName) => {
194399
194894
  const trimmedAppName = appName.trim();
194400
194895
  if (!trimmedAppName) {
194401
194896
  console.error("[pieui] Error: App name is required for create command");
@@ -194408,6 +194903,7 @@ var createCommand = (appName) => {
194408
194903
  }
194409
194904
  const bunBin = process.env.PIEUI_CREATE_BUN_BIN || "bun";
194410
194905
  const templateSpec = process.env.PIEUI_CREATE_NEXT_APP_SPEC || DEFAULT_TEMPLATE_SPEC;
194906
+ const pieuiPackageSpec = process.env.PIEUI_CREATE_PACKAGE_SPEC || DEFAULT_PIEUI_PACKAGE_SPEC;
194411
194907
  console.log(`[pieui] Creating Next.js app in "${trimmedAppName}"...`);
194412
194908
  const result = import_child_process.spawnSync(bunBin, ["create", templateSpec, trimmedAppName, "--yes"], {
194413
194909
  cwd: process.cwd(),
@@ -194421,9 +194917,9 @@ var createCommand = (appName) => {
194421
194917
  throw new Error(`create failed (exit code ${result.status ?? "unknown"})`);
194422
194918
  }
194423
194919
  scaffoldCreateAppFiles(appDir);
194424
- initCommand(trimmedAppName);
194425
194920
  writeFile(import_path11.default.join(appDir, ".env"), envTemplate());
194426
- runBunCommand(bunBin, ["install"], appDir);
194921
+ runBunCommand(bunBin, ["add", pieuiPackageSpec], appDir);
194922
+ await initCommand(trimmedAppName);
194427
194923
  runBunCommand(bunBin, ["run", "dev"], appDir);
194428
194924
  };
194429
194925
 
@@ -194676,10 +195172,10 @@ var createPieAppCommand = (appName) => {
194676
195172
  };
194677
195173
 
194678
195174
  // src/code/commands/login.ts
194679
- var import_node_child_process = require("node:child_process");
195175
+ var import_node_child_process2 = require("node:child_process");
194680
195176
  var import_node_crypto = require("node:crypto");
194681
- var import_node_fs4 = __toESM(require("node:fs"));
194682
- var import_node_path5 = __toESM(require("node:path"));
195177
+ var import_node_fs7 = __toESM(require("node:fs"));
195178
+ var import_node_path8 = __toESM(require("node:path"));
194683
195179
  var CONNECT_BASE = "https://pieui.swarm.ing/connect";
194684
195180
  var CREDENTIALS_API = "https://api-pieui.swarm.ing/api/external/credentials";
194685
195181
  var CONNECT_BASE_ENV = "PIEUI_LOGIN_CONNECT_BASE";
@@ -194696,13 +195192,13 @@ var generateCode = (length = CODE_LENGTH) => {
194696
195192
  var tryOpenBrowser = (url) => {
194697
195193
  try {
194698
195194
  if (process.platform === "win32") {
194699
- import_node_child_process.execFile("cmd", ["/c", "start", "", url], () => {
195195
+ import_node_child_process2.execFile("cmd", ["/c", "start", "", url], () => {
194700
195196
  });
194701
195197
  } else if (process.platform === "darwin") {
194702
- import_node_child_process.execFile("open", [url], () => {
195198
+ import_node_child_process2.execFile("open", [url], () => {
194703
195199
  });
194704
195200
  } else {
194705
- import_node_child_process.execFile("xdg-open", [url], () => {
195201
+ import_node_child_process2.execFile("xdg-open", [url], () => {
194706
195202
  });
194707
195203
  }
194708
195204
  } catch {
@@ -194735,8 +195231,8 @@ var appendPieCredentialsToEnv = (cwd, config) => {
194735
195231
  if (Object.keys(entries).length === 0) {
194736
195232
  return;
194737
195233
  }
194738
- const envPath = import_node_path5.default.join(cwd, ".env");
194739
- let content = import_node_fs4.default.existsSync(envPath) ? import_node_fs4.default.readFileSync(envPath, "utf8") : "";
195234
+ const envPath = import_node_path8.default.join(cwd, ".env");
195235
+ let content = import_node_fs7.default.existsSync(envPath) ? import_node_fs7.default.readFileSync(envPath, "utf8") : "";
194740
195236
  if (content.length > 0 && !content.endsWith(`
194741
195237
  `)) {
194742
195238
  content += `
@@ -194746,7 +195242,7 @@ var appendPieCredentialsToEnv = (cwd, config) => {
194746
195242
  content += `${additions.join(`
194747
195243
  `)}
194748
195244
  `;
194749
- import_node_fs4.default.writeFileSync(envPath, content, "utf8");
195245
+ import_node_fs7.default.writeFileSync(envPath, content, "utf8");
194750
195246
  console.log(`[pie] Appended credentials to ${envPath}`);
194751
195247
  };
194752
195248
  async function loginCommand(options = {}) {
@@ -194768,8 +195264,8 @@ async function loginCommand(options = {}) {
194768
195264
  openBrowser(connectUrl);
194769
195265
  } catch {
194770
195266
  }
194771
- const pieDir = import_node_path5.default.join(cwd, ".pie");
194772
- const configPath = import_node_path5.default.join(pieDir, "config.json");
195267
+ const pieDir = import_node_path8.default.join(cwd, ".pie");
195268
+ const configPath = import_node_path8.default.join(pieDir, "config.json");
194773
195269
  const url = `${credentialsApi}?${new URLSearchParams({ code }).toString()}`;
194774
195270
  let first = true;
194775
195271
  while (true) {
@@ -194802,8 +195298,8 @@ async function loginCommand(options = {}) {
194802
195298
  if (!("config" in record)) {
194803
195299
  throw new Error("Login succeeded but response had no 'config' field");
194804
195300
  }
194805
- import_node_fs4.default.mkdirSync(pieDir, { recursive: true });
194806
- import_node_fs4.default.writeFileSync(configPath, `${JSON.stringify(record.config, null, 2)}
195301
+ import_node_fs7.default.mkdirSync(pieDir, { recursive: true });
195302
+ import_node_fs7.default.writeFileSync(configPath, `${JSON.stringify(record.config, null, 2)}
194807
195303
  `, "utf8");
194808
195304
  console.log(`[pie] Saved credentials to ${configPath}`);
194809
195305
  appendPieCredentialsToEnv(cwd, record.config);
@@ -194812,8 +195308,96 @@ async function loginCommand(options = {}) {
194812
195308
  }
194813
195309
  }
194814
195310
 
195311
+ // src/code/commands/selfUpgrade.ts
195312
+ var import_node_child_process3 = require("node:child_process");
195313
+ var import_node_fs8 = __toESM(require("node:fs"));
195314
+ var import_node_path9 = __toESM(require("node:path"));
195315
+ var __dirname = "/home/runner/work/pieui/pieui/src/code/commands";
195316
+ var PACKAGE_NAME = "@swarm.ing/pieui";
195317
+ var INSTALL_ARGS = {
195318
+ bun: ["add", "-g", `${PACKAGE_NAME}@latest`],
195319
+ npm: ["install", "-g", `${PACKAGE_NAME}@latest`],
195320
+ pnpm: ["add", "-g", `${PACKAGE_NAME}@latest`],
195321
+ yarn: ["global", "add", `${PACKAGE_NAME}@latest`]
195322
+ };
195323
+ var isPackageManager = (value2) => value2 === "bun" || value2 === "npm" || value2 === "pnpm" || value2 === "yarn";
195324
+ var hasBinary = (bin) => {
195325
+ const result = import_node_child_process3.spawnSync("which", [bin], { stdio: "ignore" });
195326
+ return result.status === 0;
195327
+ };
195328
+ var detectPackageManager = () => {
195329
+ const order = ["bun", "pnpm", "yarn", "npm"];
195330
+ for (const pm of order) {
195331
+ if (hasBinary(pm))
195332
+ return pm;
195333
+ }
195334
+ return "npm";
195335
+ };
195336
+ var readInstalledVersion = () => {
195337
+ const candidates = [
195338
+ import_node_path9.default.resolve(__dirname, "..", "package.json"),
195339
+ import_node_path9.default.resolve(__dirname, "..", "..", "package.json"),
195340
+ import_node_path9.default.resolve(__dirname, "..", "..", "..", "package.json")
195341
+ ];
195342
+ for (const file of candidates) {
195343
+ try {
195344
+ const raw = import_node_fs8.default.readFileSync(file, "utf8");
195345
+ const parsed = JSON.parse(raw);
195346
+ if (parsed.name === PACKAGE_NAME && parsed.version) {
195347
+ return parsed.version;
195348
+ }
195349
+ } catch {
195350
+ }
195351
+ }
195352
+ return null;
195353
+ };
195354
+ var selfUpgradeCommand = async (override) => {
195355
+ const before = readInstalledVersion();
195356
+ console.log(`[pieui] Current version: ${before ?? "unknown (running from source or dev build)"}`);
195357
+ let pm;
195358
+ if (override) {
195359
+ if (!isPackageManager(override)) {
195360
+ console.error(`[pieui] Error: --pm must be one of: bun, npm, pnpm, yarn`);
195361
+ process.exit(1);
195362
+ }
195363
+ pm = override;
195364
+ } else {
195365
+ pm = detectPackageManager();
195366
+ }
195367
+ const args = INSTALL_ARGS[pm];
195368
+ console.log(`[pieui] Upgrading via ${pm}: ${pm} ${args.join(" ")}`);
195369
+ const result = import_node_child_process3.spawnSync(pm, args, {
195370
+ stdio: "inherit",
195371
+ env: process.env
195372
+ });
195373
+ if (result.error) {
195374
+ console.error(`[pieui] Failed to run ${pm}: ${result.error.message}`);
195375
+ process.exit(1);
195376
+ }
195377
+ if (result.status !== 0) {
195378
+ console.error(`[pieui] Upgrade failed (exit code ${result.status ?? "unknown"})`);
195379
+ process.exit(result.status ?? 1);
195380
+ }
195381
+ console.log(`[pieui] Upgrade complete. Run \`pieui --help\` to verify.`);
195382
+ };
195383
+
194815
195384
  // src/cli.ts
195385
+ var requireName = (value2, label) => {
195386
+ if (!value2) {
195387
+ console.error(`[pieui] Error: ${label} is required`);
195388
+ printUsage();
195389
+ process.exit(1);
195390
+ }
195391
+ return value2;
195392
+ };
194816
195393
  var main = async () => {
195394
+ const rawArgs = process.argv.slice(2);
195395
+ const helpScope = detectHelpScope(rawArgs);
195396
+ if (helpScope) {
195397
+ printUsage(helpScope);
195398
+ return;
195399
+ }
195400
+ const args = parseArgs(rawArgs);
194817
195401
  const {
194818
195402
  command,
194819
195403
  outDir,
@@ -194822,57 +195406,101 @@ var main = async () => {
194822
195406
  componentName,
194823
195407
  createAppName,
194824
195408
  componentType,
194825
- removeComponentName,
194826
195409
  listFilter,
194827
195410
  eventName,
194828
195411
  cardAction,
194829
195412
  cardAjax,
194830
195413
  cardIo,
194831
195414
  cardRemoteAction,
195415
+ cardPullRef,
194832
195416
  remoteUserId,
194833
195417
  remoteProject,
194834
195418
  pageAction,
194835
195419
  pagePath,
195420
+ pageName,
195421
+ pageAjaxAction,
195422
+ pageAjaxHandler,
194836
195423
  historyPage,
194837
195424
  historyPerPage,
194838
195425
  historyFrom,
194839
195426
  historyTo
194840
- } = parseArgs(process.argv.slice(2));
195427
+ } = args;
194841
195428
  console.log(`[pieui] CLI started with command: "${command}"`);
194842
195429
  switch (command) {
194843
195430
  case "init":
194844
- initCommand(outDir);
195431
+ await initCommand(outDir);
194845
195432
  return;
194846
- case "create":
194847
- if (!createAppName) {
194848
- console.error("[pieui] Error: App name is required for create command");
194849
- printUsage();
194850
- process.exit(1);
194851
- }
194852
- createCommand(createAppName);
195433
+ case "create": {
195434
+ const name = requireName(createAppName, "App name");
195435
+ await createCommand(name);
194853
195436
  return;
195437
+ }
194854
195438
  case "create-pie-app":
194855
- case "create-pieui":
194856
- if (!createAppName) {
194857
- console.error("[pieui] Error: App name is required for create-pie-app command");
195439
+ case "create-pieui": {
195440
+ const name = requireName(createAppName, "App name");
195441
+ createPieAppCommand(name);
195442
+ return;
195443
+ }
195444
+ case "login":
195445
+ await loginCommand();
195446
+ return;
195447
+ case "self-upgrade":
195448
+ await selfUpgradeCommand(args.selfUpgradePm);
195449
+ return;
195450
+ case "postbuild":
195451
+ console.log(`[pieui] Source directory: ${import_node_path10.default.resolve(process.cwd(), srcDir)}`);
195452
+ console.log(`[pieui] Output directory: ${import_node_path10.default.resolve(process.cwd(), outDir)}`);
195453
+ console.log(`[pieui] Append mode: ${append}`);
195454
+ await postbuildCommand(srcDir, outDir, append);
195455
+ return;
195456
+ case "card": {
195457
+ if (!cardAction) {
195458
+ console.error("[pieui] Error: Supported card subcommands: add, list, pull, view, remove, list-events, add-event, remote");
194858
195459
  printUsage();
194859
195460
  process.exit(1);
194860
195461
  }
194861
- createPieAppCommand(createAppName);
194862
- return;
194863
- case "card":
194864
195462
  if (cardAction === "add") {
194865
- if (!componentName) {
194866
- console.error("[pieui] Error: Component name is required for card add command");
194867
- printUsage();
194868
- process.exit(1);
194869
- }
194870
- addCommand(componentName, componentType, {
195463
+ const name = requireName(componentName, "Component name");
195464
+ addCommand(name, componentType, {
194871
195465
  ajax: cardAjax,
194872
195466
  io: cardIo
194873
195467
  });
194874
195468
  return;
194875
195469
  }
195470
+ if (cardAction === "list") {
195471
+ listCommand(srcDir, listFilter || "all");
195472
+ return;
195473
+ }
195474
+ if (cardAction === "pull") {
195475
+ const ref = requireName(cardPullRef, "Card reference");
195476
+ await cardPullCommand(ref);
195477
+ return;
195478
+ }
195479
+ if (cardAction === "view") {
195480
+ const name = requireName(componentName, "Component name");
195481
+ cardViewCommand(name);
195482
+ return;
195483
+ }
195484
+ if (cardAction === "remove") {
195485
+ const name = requireName(componentName, "Component name");
195486
+ removeCommand(name);
195487
+ return;
195488
+ }
195489
+ if (cardAction === "list-events") {
195490
+ const name = requireName(componentName, "Component name");
195491
+ listEventsCommand(srcDir, name);
195492
+ return;
195493
+ }
195494
+ if (cardAction === "add-event") {
195495
+ const name = requireName(componentName, "Component name");
195496
+ if (!eventName) {
195497
+ console.error("[pieui] Error: Event name is required");
195498
+ printUsage();
195499
+ process.exit(1);
195500
+ }
195501
+ addEventCommand(srcDir, name, eventName);
195502
+ return;
195503
+ }
194876
195504
  if (cardAction === "remote") {
194877
195505
  if (cardRemoteAction === "list") {
194878
195506
  await cardRemoteListCommand({
@@ -194881,26 +195509,22 @@ var main = async () => {
194881
195509
  });
194882
195510
  return;
194883
195511
  }
194884
- if (!componentName) {
194885
- console.error(`[pieui] Error: Component name is required for card remote ${cardRemoteAction ?? ""} command`);
194886
- printUsage();
194887
- process.exit(1);
194888
- }
195512
+ const name = requireName(componentName, "Component name");
194889
195513
  if (cardRemoteAction === "push") {
194890
- await cardRemotePushCommand(componentName);
195514
+ await cardRemotePushCommand(name);
194891
195515
  return;
194892
195516
  }
194893
195517
  if (cardRemoteAction === "pull") {
194894
- await cardRemotePullCommand(componentName);
195518
+ await cardRemotePullCommand(name);
194895
195519
  return;
194896
195520
  }
194897
195521
  if (cardRemoteAction === "remove") {
194898
- await cardRemoteRemoveCommand(componentName);
195522
+ await cardRemoteRemoveCommand(name);
194899
195523
  return;
194900
195524
  }
194901
195525
  if (cardRemoteAction === "history") {
194902
195526
  await cardRemoteHistoryCommand({
194903
- componentName,
195527
+ componentName: name,
194904
195528
  page: historyPage,
194905
195529
  perPage: historyPerPage,
194906
195530
  from: historyFrom,
@@ -194909,80 +195533,48 @@ var main = async () => {
194909
195533
  return;
194910
195534
  }
194911
195535
  if (cardRemoteAction === "public") {
194912
- await cardRemotePublicCommand(componentName);
195536
+ await cardRemotePublicCommand(name);
194913
195537
  return;
194914
195538
  }
194915
195539
  if (cardRemoteAction === "private") {
194916
- await cardRemotePrivateCommand(componentName);
195540
+ await cardRemotePrivateCommand(name);
194917
195541
  return;
194918
195542
  }
194919
- console.error("[pieui] Error: Supported card remote subcommands: push, pull, list, remove, history, public, private");
195543
+ console.error("[pieui] Error: Supported card remote subcommands: list, push, pull, remove, history, public, private");
194920
195544
  printUsage();
194921
195545
  process.exit(1);
194922
195546
  }
194923
- console.error("[pieui] Error: Supported card subcommands: add, remote");
194924
- printUsage();
194925
- process.exit(1);
194926
- case "add":
194927
- if (!componentName) {
194928
- console.error("[pieui] Error: Component name is required for card add command");
194929
- printUsage();
194930
- process.exit(1);
194931
- }
194932
- addCommand(componentName, componentType, {
194933
- ajax: cardAjax,
194934
- io: cardIo
194935
- });
194936
195547
  return;
194937
- case "page":
194938
- if (pageAction !== "add") {
194939
- console.error("[pieui] Error: Supported page subcommands: add");
194940
- printUsage();
194941
- process.exit(1);
194942
- }
194943
- if (!pagePath) {
194944
- console.error("[pieui] Error: Path is required for page add command");
195548
+ }
195549
+ case "page": {
195550
+ if (!pageAction) {
195551
+ console.error("[pieui] Error: Supported page subcommands: add, view, ajax");
194945
195552
  printUsage();
194946
195553
  process.exit(1);
194947
195554
  }
194948
- pageAddCommand(pagePath);
194949
- return;
194950
- case "remove":
194951
- if (!removeComponentName) {
194952
- console.error("[pieui] Error: Component name is required for remove command");
194953
- printUsage();
194954
- process.exit(1);
195555
+ if (pageAction === "add") {
195556
+ const p = requireName(pagePath, "Path");
195557
+ pageAddCommand(p);
195558
+ return;
194955
195559
  }
194956
- removeCommand(removeComponentName);
194957
- return;
194958
- case "list":
194959
- listCommand(srcDir, listFilter || "all");
194960
- return;
194961
- case "list-events":
194962
- if (!componentName) {
194963
- console.error("[pieui] Error: Component name is required for list-events command");
194964
- printUsage();
194965
- process.exit(1);
195560
+ if (pageAction === "view") {
195561
+ const name = requireName(pageName, "Path");
195562
+ pageViewCommand(name);
195563
+ return;
194966
195564
  }
194967
- listEventsCommand(srcDir, componentName);
194968
- return;
194969
- case "add-event":
194970
- if (!componentName || !eventName) {
194971
- console.error("[pieui] Error: Component name and event name are required for add-event command");
194972
- printUsage();
194973
- process.exit(1);
195565
+ if (pageAction === "ajax") {
195566
+ const name = requireName(pageName, "Page name");
195567
+ if (!pageAjaxAction) {
195568
+ console.error("[pieui] Error: page ajax action must be `add` or `remove`");
195569
+ printUsage();
195570
+ process.exit(1);
195571
+ }
195572
+ const handler = requireName(pageAjaxHandler, "Handler name");
195573
+ pageAjaxCommand(name, pageAjaxAction, handler);
195574
+ return;
194974
195575
  }
194975
- addEventCommand(srcDir, componentName, eventName);
194976
- return;
194977
- case "postbuild":
194978
- console.log(`[pieui] Source directory: ${srcDir}`);
194979
- console.log(`[pieui] Output directory: ${outDir}`);
194980
- console.log(`[pieui] Append mode: ${append}`);
194981
- await postbuildCommand(srcDir, outDir, append);
194982
- return;
194983
- case "login":
194984
- await loginCommand();
194985
195576
  return;
195577
+ }
194986
195578
  default:
194987
195579
  printUsage();
194988
195580
  process.exit(1);