@tscircuit/cli 0.1.222 → 0.1.224

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 +69 -11
  2. package/package.json +1 -1
package/dist/main.js CHANGED
@@ -63256,7 +63256,7 @@ var getGlobalDepsInstallCommand = (packageManager, deps) => {
63256
63256
  import { execSync as execSync2 } from "node:child_process";
63257
63257
  var import_semver2 = __toESM2(require_semver2(), 1);
63258
63258
  // package.json
63259
- var version = "0.1.221";
63259
+ var version = "0.1.223";
63260
63260
  var package_default = {
63261
63261
  name: "@tscircuit/cli",
63262
63262
  version,
@@ -67867,6 +67867,7 @@ async function addPackage(componentPath, projectDir = process.cwd()) {
67867
67867
  // cli/dev/DevServer.ts
67868
67868
  import Debug2 from "debug";
67869
67869
  var debug2 = Debug2("tscircuit:devserver");
67870
+ var BINARY_FILE_EXTENSIONS = new Set([".glb", ".png", ".jpeg", ".jpg"]);
67870
67871
 
67871
67872
  class DevServer {
67872
67873
  port;
@@ -67928,7 +67929,12 @@ class DevServer {
67928
67929
  if (!fs18.existsSync(dirPath)) {
67929
67930
  fs18.mkdirSync(dirPath, { recursive: true });
67930
67931
  }
67931
- 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
+ }
67932
67938
  }
67933
67939
  async handleFileChangedOnFilesystem(absoluteFilePath) {
67934
67940
  const relativeFilePath = path18.relative(this.projectDir, absoluteFilePath);
@@ -67937,12 +67943,13 @@ class DevServer {
67937
67943
  if (shouldIgnorePath(relativeFilePath, this.ignoredFiles))
67938
67944
  return;
67939
67945
  await this.typesHandler?.handleFileTypeDependencies(absoluteFilePath);
67946
+ const filePayload = this.createFileUploadPayload(absoluteFilePath, relativeFilePath);
67940
67947
  console.log(kleur_default.green(`Saving: ${relativeFilePath}`));
67941
67948
  await this.fsKy.post("api/files/upsert", {
67942
67949
  json: {
67943
67950
  file_path: relativeFilePath,
67944
- text_content: fs18.readFileSync(absoluteFilePath, "utf-8"),
67945
- initiator: "filesystem_change"
67951
+ initiator: "filesystem_change",
67952
+ ...filePayload
67946
67953
  }
67947
67954
  }).json();
67948
67955
  }
@@ -67990,12 +67997,12 @@ class DevServer {
67990
67997
  if (shouldIgnorePath(oldRelativePath, this.ignoredFiles) || shouldIgnorePath(newRelativePath, this.ignoredFiles))
67991
67998
  return;
67992
67999
  await this.handleFileRemovedFromFilesystem(oldPath);
67993
- const fileContent = fs18.readFileSync(newPath, "utf-8");
68000
+ const filePayload = this.createFileUploadPayload(newPath, newRelativePath);
67994
68001
  await this.fsKy.post("api/files/upsert", {
67995
68002
  json: {
67996
68003
  file_path: newRelativePath,
67997
- text_content: fileContent,
67998
- initiator: "filesystem_change"
68004
+ initiator: "filesystem_change",
68005
+ ...filePayload
67999
68006
  }
68000
68007
  });
68001
68008
  debug2(`File renamed from ${oldRelativePath} to ${newRelativePath}`);
@@ -68003,12 +68010,13 @@ class DevServer {
68003
68010
  async upsertInitialFiles() {
68004
68011
  const filePaths = getPackageFilePaths(this.projectDir, this.ignoredFiles);
68005
68012
  for (const filePath of filePaths) {
68006
- const fileContent = fs18.readFileSync(filePath, "utf-8");
68013
+ const relativeFilePath = path18.relative(this.projectDir, filePath);
68014
+ const filePayload = this.createFileUploadPayload(filePath, relativeFilePath);
68007
68015
  await this.fsKy.post("api/files/upsert", {
68008
68016
  json: {
68009
- file_path: path18.relative(this.projectDir, filePath),
68010
- text_content: fileContent,
68011
- initiator: "filesystem_change"
68017
+ file_path: relativeFilePath,
68018
+ initiator: "filesystem_change",
68019
+ ...filePayload
68012
68020
  }
68013
68021
  });
68014
68022
  }
@@ -68035,6 +68043,14 @@ class DevServer {
68035
68043
  this.eventsWatcher?.stop();
68036
68044
  await this.filesystemWatcher?.close();
68037
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
+ }
68038
68054
  async handleInstallPackage(full_package_name) {
68039
68055
  const postEvent = async (event, message) => {
68040
68056
  await this.fsKy.post("api/events/create", {
@@ -72341,6 +72357,47 @@ var registerAuthSetToken = (program3) => {
72341
72357
  });
72342
72358
  };
72343
72359
 
72360
+ // cli/auth/whoami/register.ts
72361
+ var registerAuthWhoami = (program3) => {
72362
+ program3.commands.find((c) => c.name() === "auth").command("whoami").description("Show information about the current authenticated user").action(async () => {
72363
+ const sessionToken = getSessionToken();
72364
+ if (!sessionToken) {
72365
+ console.log("You need to log in to access this.");
72366
+ return;
72367
+ }
72368
+ const ky2 = getRegistryApiKy({ sessionToken });
72369
+ const githubUsernameFromConfig = cliConfig.get("githubUsername");
72370
+ const accountIdFromConfig = cliConfig.get("accountId");
72371
+ let account;
72372
+ if (githubUsernameFromConfig && !accountIdFromConfig) {
72373
+ const tryFetchAccount = async (username) => {
72374
+ try {
72375
+ const { account: account2 } = await ky2.post("accounts/get", {
72376
+ json: { github_username: username }
72377
+ }).json();
72378
+ return account2;
72379
+ } catch {
72380
+ return;
72381
+ }
72382
+ };
72383
+ account = await tryFetchAccount(githubUsernameFromConfig);
72384
+ if (!account && process.env.TSCI_TEST_MODE === "true") {
72385
+ const sanitized = githubUsernameFromConfig.replace(/[^a-zA-Z0-9]/g, "");
72386
+ if (sanitized && sanitized !== githubUsernameFromConfig) {
72387
+ account = await tryFetchAccount(sanitized);
72388
+ }
72389
+ }
72390
+ }
72391
+ const githubUsername = account?.github_username ?? githubUsernameFromConfig ?? "(unknown)";
72392
+ const accountId = account?.account_id ?? accountIdFromConfig ?? "(unknown)";
72393
+ console.log("Currently logged in user:");
72394
+ console.log(` GitHub Username: ${githubUsername}`);
72395
+ console.log(` Account ID: ${accountId}`);
72396
+ const sessionId = cliConfig.get("sessionId");
72397
+ console.log(` Session ID: ${sessionId ?? "(unknown)"}`);
72398
+ });
72399
+ };
72400
+
72344
72401
  // cli/push/register.ts
72345
72402
  var registerPush = (program3) => {
72346
72403
  program3.command("push").description("Save snippet code to Registry API").argument("[file]", "Path to the snippet file").option("--private", "Make the snippet private").action(async (filePath, options = {}) => {
@@ -179724,6 +179781,7 @@ registerAuthLogin(program2);
179724
179781
  registerAuthLogout(program2);
179725
179782
  registerAuthPrintToken(program2);
179726
179783
  registerAuthSetToken(program2);
179784
+ registerAuthWhoami(program2);
179727
179785
  registerConfig(program2);
179728
179786
  registerConfigPrint(program2);
179729
179787
  registerConfigSet(program2);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tscircuit/cli",
3
- "version": "0.1.222",
3
+ "version": "0.1.224",
4
4
  "main": "dist/main.js",
5
5
  "devDependencies": {
6
6
  "@babel/standalone": "^7.26.9",