@tscircuit/cli 0.0.16 → 0.0.18

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/cli.js CHANGED
@@ -215,6 +215,7 @@ var configRevealLocation = async (ctx, args2) => {
215
215
  import {z} from "zod";
216
216
  var configSetRegistry = async (ctx, args2) => {
217
217
  const params = z.object({ server: z.string().url() }).parse(args2);
218
+ ctx.profile_config.clear();
218
219
  ctx.profile_config.set("registry_url", params.server);
219
220
  };
220
221
  // lib/cmd-fns/config-set-session.ts
@@ -1526,6 +1527,10 @@ var devServerUpload = async (ctx, args2) => {
1526
1527
  const watcher = await startWatcher({ cwd: params.dir, devServerAxios });
1527
1528
  }
1528
1529
  };
1530
+ // lib/cmd-fns/config-clear.ts
1531
+ var configClear = async (ctx, args2) => {
1532
+ ctx.global_config.clear();
1533
+ };
1529
1534
  // lib/cmd-fns/open.ts
1530
1535
  import {existsSync as existsSync4, readFileSync as readFileSync6} from "fs";
1531
1536
  import kleur16 from "kleur";
@@ -1545,7 +1550,7 @@ var openCmd = async (ctx, args2) => {
1545
1550
  // package.json
1546
1551
  var package_default = {
1547
1552
  name: "@tscircuit/cli",
1548
- version: "0.0.15",
1553
+ version: "0.0.17",
1549
1554
  private: false,
1550
1555
  type: "module",
1551
1556
  description: "Command line tool for developing, publishing and installing tscircuit circuits",
@@ -1638,6 +1643,7 @@ var getProgram = (ctx) => {
1638
1643
  configCmd.command("set-session").requiredOption("--session-token <session_token>", "Session Token").action((args2) => configSetSession(ctx, args2));
1639
1644
  configCmd.command("set-log-requests").requiredOption("--log-requests", "Should log requests to registry").action((args2) => configSetLogRequests(ctx, args2));
1640
1645
  configCmd.command("print-config").action((args2) => configPrintConfig(ctx, args2));
1646
+ configCmd.command("clear").action((args2) => configClear(ctx, args2));
1641
1647
  const authSessionsCmd = authCmd.command("sessions");
1642
1648
  authSessionsCmd.command("create").action((args2) => authSessionsCreate(ctx, args2));
1643
1649
  authSessionsCmd.command("list").action((args2) => authSessionsList(ctx, args2));
@@ -1889,11 +1895,36 @@ var interactForPackageName = async ({
1889
1895
  return selectedPackage;
1890
1896
  };
1891
1897
 
1898
+ // lib/param-handlers/interact-for-registry-url.ts
1899
+ var interactForRegistryUrl = async (params) => {
1900
+ const { prompts: prompts3, ctx } = params;
1901
+ const { registry_url } = await prompts3({
1902
+ type: "select",
1903
+ name: "registry_url",
1904
+ message: "Select a package example",
1905
+ choices: [
1906
+ "https://registry.tscircuit.com",
1907
+ "http://localhost:3100",
1908
+ "other"
1909
+ ].map((a) => ({ title: a, value: a }))
1910
+ });
1911
+ if (registry_url === "other") {
1912
+ const { registry_url: registry_url2 } = await prompts3({
1913
+ type: "text",
1914
+ name: "registry_url",
1915
+ message: "Enter the registry url"
1916
+ });
1917
+ return registry_url2;
1918
+ }
1919
+ return registry_url;
1920
+ };
1921
+
1892
1922
  // lib/param-handlers/index.ts
1893
1923
  var PARAM_HANDLERS_BY_PARAM_NAME = {
1894
1924
  file: interactForLocalFile,
1895
1925
  cwd: interactForLocalDirectory,
1896
1926
  dir: interactForLocalDirectory,
1927
+ registry_url: interactForRegistryUrl,
1897
1928
  package_release_id: interactForPackageReleaseId,
1898
1929
  package_name: interactForPackageName,
1899
1930
  package_name_with_version: interactForPackageNameWithVersion,
@@ -1909,7 +1940,14 @@ var createConfigHandler = ({
1909
1940
  const current_profile = profile ?? global_config.get("current_profile") ?? "default";
1910
1941
  const profile_config = {
1911
1942
  get: (key) => global_config.get(`profiles.${current_profile}.${key}`),
1912
- set: (key, value) => global_config.set(`profiles.${current_profile}.${key}`, value)
1943
+ set: (key, value) => global_config.set(`profiles.${current_profile}.${key}`, value),
1944
+ clear: () => {
1945
+ for (const key of Object.keys(global_config.all)) {
1946
+ if (key.startsWith(`profiles.${current_profile}`)) {
1947
+ global_config.delete(key);
1948
+ }
1949
+ }
1950
+ }
1913
1951
  };
1914
1952
  return { profile_config, global_config, current_profile };
1915
1953
  };
@@ -1979,7 +2017,10 @@ var createContextAndRunProgram = async (process_args) => {
1979
2017
  }
1980
2018
  await perfectCli(getProgram(ctx), args_without_globals, {
1981
2019
  async customParamHandler({ commandPath, optionName }, { prompts: prompts3 }) {
1982
- const optionNameHandler = PARAM_HANDLERS_BY_PARAM_NAME[_.snakeCase(optionName)];
2020
+ let optionNameHandler = PARAM_HANDLERS_BY_PARAM_NAME[_.snakeCase(optionName)];
2021
+ if (commandPath.join(" ") === "config set-registry" && optionName === "server") {
2022
+ optionNameHandler = PARAM_HANDLERS_BY_PARAM_NAME["registry_url"];
2023
+ }
1983
2024
  if (optionNameHandler) {
1984
2025
  return optionNameHandler({ prompts: prompts3, ctx });
1985
2026
  }
@@ -3,5 +3,7 @@ import { z } from "zod"
3
3
 
4
4
  export const configSetRegistry = async (ctx: AppContext, args: any) => {
5
5
  const params = z.object({ server: z.string().url() }).parse(args)
6
+ // don't want to re-use auth token
7
+ ctx.profile_config.clear()
6
8
  ctx.profile_config.set("registry_url", params.server)
7
9
  }
@@ -83,6 +83,13 @@ export const createConfigHandler = ({
83
83
  (global_config as any).get(`profiles.${current_profile}.${key}`),
84
84
  set: (key: string, value: any) =>
85
85
  (global_config as any).set(`profiles.${current_profile}.${key}`, value),
86
+ clear: () => {
87
+ for (const key of Object.keys(global_config.all)) {
88
+ if (key.startsWith(`profiles.${current_profile}`)) {
89
+ global_config.delete(key as any)
90
+ }
91
+ }
92
+ },
86
93
  } as any
87
94
 
88
95
  return { profile_config, global_config, current_profile }
@@ -47,6 +47,7 @@ export const getProgram = (ctx: AppContext) => {
47
47
  configCmd
48
48
  .command("print-config")
49
49
  .action((args) => CMDFN.configPrintConfig(ctx, args))
50
+ configCmd.command("clear").action((args) => CMDFN.configClear(ctx, args))
50
51
 
51
52
  const authSessionsCmd = authCmd.command("sessions")
52
53
 
@@ -4,12 +4,14 @@ import { interactForPackageExampleId } from "./interact-for-package-example-id"
4
4
  import { interactForPackageName } from "./interact-for-package-name"
5
5
  import { interactForPackageNameWithVersion } from "./interact-for-package-name-with-version"
6
6
  import { interactForPackageReleaseId } from "./interact-for-package-release-id"
7
+ import { interactForRegistryUrl } from "./interact-for-registry-url"
7
8
  import { ParamHandler } from "./param-handler-type"
8
9
 
9
10
  export const PARAM_HANDLERS_BY_PARAM_NAME: Record<string, ParamHandler> = {
10
11
  file: interactForLocalFile,
11
12
  cwd: interactForLocalDirectory,
12
13
  dir: interactForLocalDirectory,
14
+ registry_url: interactForRegistryUrl,
13
15
  package_release_id: interactForPackageReleaseId,
14
16
  package_name: interactForPackageName,
15
17
  package_name_with_version: interactForPackageNameWithVersion,
@@ -0,0 +1,28 @@
1
+ import { interactForPackageReleaseId } from "./interact-for-package-release-id"
2
+ import { ParamHandler } from "./param-handler-type"
3
+
4
+ export const interactForRegistryUrl: ParamHandler = async (params) => {
5
+ const { prompts, ctx } = params
6
+
7
+ const { registry_url } = await prompts({
8
+ type: "select",
9
+ name: "registry_url",
10
+ message: "Select a package example",
11
+ choices: [
12
+ "https://registry.tscircuit.com",
13
+ "http://localhost:3100",
14
+ "other",
15
+ ].map((a) => ({ title: a, value: a })),
16
+ })
17
+
18
+ if (registry_url === "other") {
19
+ const { registry_url } = await prompts({
20
+ type: "text",
21
+ name: "registry_url",
22
+ message: "Enter the registry url",
23
+ })
24
+ return registry_url
25
+ }
26
+
27
+ return registry_url
28
+ }
@@ -123,9 +123,16 @@ export const createContextAndRunProgram = async (process_args: any) => {
123
123
 
124
124
  await perfectCli(getProgram(ctx), args_without_globals, {
125
125
  async customParamHandler({ commandPath, optionName }, { prompts }) {
126
- const optionNameHandler =
126
+ let optionNameHandler =
127
127
  PARAM_HANDLERS_BY_PARAM_NAME[_.snakeCase(optionName)]
128
128
 
129
+ if (
130
+ commandPath.join(" ") === "config set-registry" &&
131
+ optionName === "server"
132
+ ) {
133
+ optionNameHandler = PARAM_HANDLERS_BY_PARAM_NAME["registry_url"]
134
+ }
135
+
129
136
  if (optionNameHandler) {
130
137
  return optionNameHandler({ prompts, ctx })
131
138
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tscircuit/cli",
3
- "version": "0.0.16",
3
+ "version": "0.0.18",
4
4
  "private": false,
5
5
  "type": "module",
6
6
  "description": "Command line tool for developing, publishing and installing tscircuit circuits",