@tscircuit/cli 0.1.221 → 0.1.223

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 (2) hide show
  1. package/dist/main.js +94 -37
  2. package/package.json +2 -2
package/dist/main.js CHANGED
@@ -58032,7 +58032,39 @@ var require_dist7 = __commonJS((exports2, module2) => {
58032
58032
  return figureOutCommandPath(program3, commandPath.concat([nextCommandName]));
58033
58033
  });
58034
58034
  var import_prompts22 = __toESM3(require_prompts3());
58035
- var stringifyOptions = (options) => Object.entries(options).filter((opt) => opt[0] !== "_").map(([key, value]) => `--${key} ${value}`).join(" ");
58035
+ var camelToKebab = (str) => str.replace(/([A-Z])/g, "-$1").toLowerCase().replace(/^-/, "");
58036
+ var findOptionByKey = (command, key) => {
58037
+ var _a;
58038
+ return (_a = command == null ? undefined : command.options) == null ? undefined : _a.find((o) => {
58039
+ var _a2, _b;
58040
+ const longFlag = (_a2 = o.long) == null ? undefined : _a2.replace(/^--/, "");
58041
+ const shortFlag = (_b = o.short) == null ? undefined : _b.replace(/^-/, "");
58042
+ if (longFlag === key || shortFlag === key) {
58043
+ return true;
58044
+ }
58045
+ if (longFlag === camelToKebab(key)) {
58046
+ return true;
58047
+ }
58048
+ return false;
58049
+ });
58050
+ };
58051
+ var getOptionFlagName = (command, key) => {
58052
+ var _a, _b;
58053
+ const option = findOptionByKey(command, key);
58054
+ if (option) {
58055
+ return ((_a = option.long) == null ? undefined : _a.replace(/^--/, "")) || ((_b = option.short) == null ? undefined : _b.replace(/^-/, "")) || "";
58056
+ }
58057
+ return camelToKebab(key);
58058
+ };
58059
+ var stringifyOptions = (options, command) => Object.entries(options).filter((opt) => opt[0] !== "_").map(([key, value]) => {
58060
+ var _a;
58061
+ const option = findOptionByKey(command, key);
58062
+ const flagName = getOptionFlagName(command, key);
58063
+ if ((_a = option == null ? undefined : option.isBoolean) == null ? undefined : _a.call(option)) {
58064
+ return value ? `--${flagName}` : "";
58065
+ }
58066
+ return `--${flagName} ${value}`;
58067
+ }).filter(Boolean).join(" ");
58036
58068
  var getOptionKey = (o) => {
58037
58069
  var _a;
58038
58070
  return ((_a = o.long) != null ? _a : o.short).replace(/^--/, "");
@@ -58057,8 +58089,8 @@ var require_dist7 = __commonJS((exports2, module2) => {
58057
58089
  if (command.options.length === 0) {
58058
58090
  return options;
58059
58091
  }
58060
- console.log(`> ${[program3.name(), ...commandPath].filter(Boolean).join(" ")} ${stringifyOptions(options)}`);
58061
- const hasRequiredOptions = command.options.filter((o) => o.mandatory).every((o) => options[getOptionKey(o)]);
58092
+ console.log(`> ${[program3.name(), ...commandPath].filter(Boolean).join(" ")} ${stringifyOptions(options, command)}`);
58093
+ const hasRequiredOptions = command.options.filter((o) => o.mandatory).every((o) => (getOptionKey(o) in options));
58062
58094
  const { optionToEdit } = yield (0, import_prompts22.default)({
58063
58095
  type: "autocomplete",
58064
58096
  name: "optionToEdit",
@@ -58077,7 +58109,7 @@ var require_dist7 = __commonJS((exports2, module2) => {
58077
58109
  return {
58078
58110
  title: `${o.long}${o.mandatory ? "*" : ""}`,
58079
58111
  value: optionName,
58080
- description: options[optionName] ? `[${options[optionName]}]` : o.description
58112
+ description: optionName in options ? `[${options[optionName]}]` : o.description
58081
58113
  };
58082
58114
  })
58083
58115
  ].filter((elm) => Boolean(elm))
@@ -58116,7 +58148,7 @@ var require_dist7 = __commonJS((exports2, module2) => {
58116
58148
  var stringifyCommandWithOptions = (program3, commandPath, options) => {
58117
58149
  var _a, _b;
58118
58150
  const command = getCommandFromPath(program3, commandPath);
58119
- return `${[program3.name(), ...commandPath].filter(Boolean).join(" ")}${((_a = options == null ? undefined : options._) == null ? undefined : _a.length) > 0 ? ` ${(_b = options == null ? undefined : options._) == null ? undefined : _b.join(" ")}` : ""} ${stringifyOptions(options)}`;
58151
+ return `${[program3.name(), ...commandPath].filter(Boolean).join(" ")}${((_a = options == null ? undefined : options._) == null ? undefined : _a.length) > 0 ? ` ${(_b = options == null ? undefined : options._) == null ? undefined : _b.join(" ")}` : ""} ${stringifyOptions(options, command)}`;
58120
58152
  };
58121
58153
  var doesProgramHaveAllRequiredArgs = (program3, _, passedArgs) => {
58122
58154
  const command = getCommandFromPath(program3, _);
@@ -58181,10 +58213,19 @@ var require_dist7 = __commonJS((exports2, module2) => {
58181
58213
  const fullCommandString = stringifyCommandWithOptions(program3, commandPath, options);
58182
58214
  console.log(`> ${fullCommandString}`);
58183
58215
  const strictCommandPath = getStrictCommandPath(program3, commandPath);
58216
+ const optionArgs = Object.entries(options).filter((opt) => opt[0] !== "_").flatMap(([optKey, optVal]) => {
58217
+ var _a2;
58218
+ const option = findOptionByKey(command, optKey);
58219
+ const flagName = getOptionFlagName(command, optKey);
58220
+ if ((_a2 = option == null ? undefined : option.isBoolean) == null ? undefined : _a2.call(option)) {
58221
+ return optVal ? [`--${flagName}`] : [];
58222
+ }
58223
+ return [`--${flagName}`, optVal];
58224
+ });
58184
58225
  yield program3.parseAsync([
58185
58226
  ...process.argv.slice(0, 2),
58186
58227
  ...strictCommandPath.concat((_b = options._) != null ? _b : []),
58187
- ...Object.entries(options).filter((opt) => opt[0] !== "_").flatMap(([optKey, optVal]) => [`--${optKey}`, optVal])
58228
+ ...optionArgs
58188
58229
  ]);
58189
58230
  });
58190
58231
  });
@@ -63215,7 +63256,7 @@ var getGlobalDepsInstallCommand = (packageManager, deps) => {
63215
63256
  import { execSync as execSync2 } from "node:child_process";
63216
63257
  var import_semver2 = __toESM2(require_semver2(), 1);
63217
63258
  // package.json
63218
- var version = "0.1.220";
63259
+ var version = "0.1.222";
63219
63260
  var package_default = {
63220
63261
  name: "@tscircuit/cli",
63221
63262
  version,
@@ -63262,7 +63303,7 @@ var package_default = {
63262
63303
  ky: "^1.7.4",
63263
63304
  "looks-same": "^9.0.1",
63264
63305
  "make-vfs": "^1.0.15",
63265
- "perfect-cli": "^1.0.20",
63306
+ "perfect-cli": "^1.0.21",
63266
63307
  prompts: "^2.4.2",
63267
63308
  redaxios: "^0.5.1",
63268
63309
  semver: "^7.6.3",
@@ -67826,6 +67867,7 @@ async function addPackage(componentPath, projectDir = process.cwd()) {
67826
67867
  // cli/dev/DevServer.ts
67827
67868
  import Debug2 from "debug";
67828
67869
  var debug2 = Debug2("tscircuit:devserver");
67870
+ var BINARY_FILE_EXTENSIONS = new Set([".glb", ".png", ".jpeg", ".jpg"]);
67829
67871
 
67830
67872
  class DevServer {
67831
67873
  port;
@@ -67887,7 +67929,12 @@ class DevServer {
67887
67929
  if (!fs18.existsSync(dirPath)) {
67888
67930
  fs18.mkdirSync(dirPath, { recursive: true });
67889
67931
  }
67890
- fs18.writeFileSync(fullPath, file.text_content);
67932
+ if (file.binary_content_b64) {
67933
+ const decodedContent = Buffer.from(file.binary_content_b64, "base64");
67934
+ fs18.writeFileSync(fullPath, decodedContent);
67935
+ } else {
67936
+ fs18.writeFileSync(fullPath, file.text_content ?? "", "utf-8");
67937
+ }
67891
67938
  }
67892
67939
  async handleFileChangedOnFilesystem(absoluteFilePath) {
67893
67940
  const relativeFilePath = path18.relative(this.projectDir, absoluteFilePath);
@@ -67896,12 +67943,13 @@ class DevServer {
67896
67943
  if (shouldIgnorePath(relativeFilePath, this.ignoredFiles))
67897
67944
  return;
67898
67945
  await this.typesHandler?.handleFileTypeDependencies(absoluteFilePath);
67946
+ const filePayload = this.createFileUploadPayload(absoluteFilePath, relativeFilePath);
67899
67947
  console.log(kleur_default.green(`Saving: ${relativeFilePath}`));
67900
67948
  await this.fsKy.post("api/files/upsert", {
67901
67949
  json: {
67902
67950
  file_path: relativeFilePath,
67903
- text_content: fs18.readFileSync(absoluteFilePath, "utf-8"),
67904
- initiator: "filesystem_change"
67951
+ initiator: "filesystem_change",
67952
+ ...filePayload
67905
67953
  }
67906
67954
  }).json();
67907
67955
  }
@@ -67949,12 +67997,12 @@ class DevServer {
67949
67997
  if (shouldIgnorePath(oldRelativePath, this.ignoredFiles) || shouldIgnorePath(newRelativePath, this.ignoredFiles))
67950
67998
  return;
67951
67999
  await this.handleFileRemovedFromFilesystem(oldPath);
67952
- const fileContent = fs18.readFileSync(newPath, "utf-8");
68000
+ const filePayload = this.createFileUploadPayload(newPath, newRelativePath);
67953
68001
  await this.fsKy.post("api/files/upsert", {
67954
68002
  json: {
67955
68003
  file_path: newRelativePath,
67956
- text_content: fileContent,
67957
- initiator: "filesystem_change"
68004
+ initiator: "filesystem_change",
68005
+ ...filePayload
67958
68006
  }
67959
68007
  });
67960
68008
  debug2(`File renamed from ${oldRelativePath} to ${newRelativePath}`);
@@ -67962,12 +68010,13 @@ class DevServer {
67962
68010
  async upsertInitialFiles() {
67963
68011
  const filePaths = getPackageFilePaths(this.projectDir, this.ignoredFiles);
67964
68012
  for (const filePath of filePaths) {
67965
- const fileContent = fs18.readFileSync(filePath, "utf-8");
68013
+ const relativeFilePath = path18.relative(this.projectDir, filePath);
68014
+ const filePayload = this.createFileUploadPayload(filePath, relativeFilePath);
67966
68015
  await this.fsKy.post("api/files/upsert", {
67967
68016
  json: {
67968
- file_path: path18.relative(this.projectDir, filePath),
67969
- text_content: fileContent,
67970
- initiator: "filesystem_change"
68017
+ file_path: relativeFilePath,
68018
+ initiator: "filesystem_change",
68019
+ ...filePayload
67971
68020
  }
67972
68021
  });
67973
68022
  }
@@ -67994,6 +68043,14 @@ class DevServer {
67994
68043
  this.eventsWatcher?.stop();
67995
68044
  await this.filesystemWatcher?.close();
67996
68045
  }
68046
+ createFileUploadPayload(absoluteFilePath, relativeFilePath) {
68047
+ const ext = path18.extname(relativeFilePath).toLowerCase();
68048
+ if (BINARY_FILE_EXTENSIONS.has(ext)) {
68049
+ const fileBuffer = fs18.readFileSync(absoluteFilePath);
68050
+ return { binary_content_b64: fileBuffer.toString("base64") };
68051
+ }
68052
+ return { text_content: fs18.readFileSync(absoluteFilePath, "utf-8") };
68053
+ }
67997
68054
  async handleInstallPackage(full_package_name) {
67998
68055
  const postEvent = async (event, message) => {
67999
68056
  await this.fsKy.post("api/events/create", {
@@ -68242,25 +68299,6 @@ var registerClone = (program3) => {
68242
68299
  throw new Error("No valid match found");
68243
68300
  const [, author, packageName] = match;
68244
68301
  console.log(`Cloning ${author}/${packageName}...`);
68245
- const ky2 = getRegistryApiKy();
68246
- let packageFileList = {
68247
- package_files: []
68248
- };
68249
- try {
68250
- packageFileList = await ky2.post("package_files/list", {
68251
- json: {
68252
- package_name: `${author}/${packageName}`,
68253
- use_latest_version: true
68254
- }
68255
- }).json();
68256
- } catch (error) {
68257
- if (typeof error === "object" && error !== null && "response" in error && typeof error.response === "object" && error.response?.status === 404) {
68258
- console.error(`Package "${author}/${packageName}" not found. Please check the name and try again.`);
68259
- process.exit(1);
68260
- }
68261
- console.error("Failed to fetch package files:", error instanceof Error ? error.message : error);
68262
- process.exit(1);
68263
- }
68264
68302
  const userSettingToIncludeAuthor = options.includeAuthor || cliConfig.get("alwaysCloneWithAuthorName");
68265
68303
  const dirPath = userSettingToIncludeAuthor ? path20.resolve(`${author}.${packageName}`) : path20.resolve(packageName);
68266
68304
  if (fs20.existsSync(dirPath)) {
@@ -68289,6 +68327,25 @@ var registerClone = (program3) => {
68289
68327
  console.log(`Merging files into existing directory: ${dirPath}`);
68290
68328
  }
68291
68329
  }
68330
+ const ky2 = getRegistryApiKy();
68331
+ let packageFileList = {
68332
+ package_files: []
68333
+ };
68334
+ try {
68335
+ packageFileList = await ky2.post("package_files/list", {
68336
+ json: {
68337
+ package_name: `${author}/${packageName}`,
68338
+ use_latest_version: true
68339
+ }
68340
+ }).json();
68341
+ } catch (error) {
68342
+ if (typeof error === "object" && error !== null && "response" in error && typeof error.response === "object" && error.response?.status === 404) {
68343
+ console.error(`Package "${author}/${packageName}" not found. Please check the name and try again.`);
68344
+ process.exit(1);
68345
+ }
68346
+ console.error("Failed to fetch package files:", error instanceof Error ? error.message : error);
68347
+ process.exit(1);
68348
+ }
68292
68349
  fs20.mkdirSync(dirPath, { recursive: true });
68293
68350
  for (const fileInfo of packageFileList.package_files) {
68294
68351
  const filePath = fileInfo.file_path.replace(/^\/|dist\//g, "");
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tscircuit/cli",
3
- "version": "0.1.221",
3
+ "version": "0.1.223",
4
4
  "main": "dist/main.js",
5
5
  "devDependencies": {
6
6
  "@babel/standalone": "^7.26.9",
@@ -44,7 +44,7 @@
44
44
  "ky": "^1.7.4",
45
45
  "looks-same": "^9.0.1",
46
46
  "make-vfs": "^1.0.15",
47
- "perfect-cli": "^1.0.20",
47
+ "perfect-cli": "^1.0.21",
48
48
  "prompts": "^2.4.2",
49
49
  "redaxios": "^0.5.1",
50
50
  "semver": "^7.6.3",