@tarout/cli 0.2.1 → 0.3.0

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.
@@ -1,3 +1,8 @@
1
+ import {
2
+ getApiUrl,
3
+ getToken,
4
+ isLoggedIn
5
+ } from "./chunk-5DAFGMBH.js";
1
6
  import {
2
7
  ExitCode,
3
8
  error,
@@ -5,135 +10,12 @@ import {
5
10
  isJsonMode,
6
11
  jsonError,
7
12
  outputJson
8
- } from "./chunk-FS74WWHV.js";
13
+ } from "./chunk-KL3JNPAY.js";
9
14
 
10
15
  // src/lib/api.ts
11
16
  import { createTRPCProxyClient, httpBatchLink } from "@trpc/client";
12
17
  import superjson from "superjson";
13
18
 
14
- // src/lib/config.ts
15
- import Conf from "conf";
16
- import {
17
- chmodSync,
18
- existsSync,
19
- mkdirSync,
20
- readFileSync,
21
- rmSync,
22
- writeFileSync
23
- } from "fs";
24
- import { join } from "path";
25
- var config = new Conf({
26
- projectName: "tarout",
27
- configFileMode: 384,
28
- defaults: {
29
- currentProfile: "default",
30
- profiles: {}
31
- }
32
- });
33
- function getConfig() {
34
- return config.store;
35
- }
36
- function getCurrentProfile() {
37
- const cfg = getConfig();
38
- return cfg.profiles[cfg.currentProfile] || null;
39
- }
40
- function setProfile(name, profile) {
41
- config.set(`profiles.${name}`, profile);
42
- }
43
- function setCurrentProfile(name) {
44
- config.set("currentProfile", name);
45
- }
46
- function clearConfig() {
47
- config.clear();
48
- }
49
- function isLoggedIn() {
50
- const profile = getCurrentProfile();
51
- return profile !== null && !!profile.token || !!process.env.TAROUT_TOKEN;
52
- }
53
- function getToken() {
54
- const profile = getCurrentProfile();
55
- return profile?.token || process.env.TAROUT_TOKEN || null;
56
- }
57
- function getApiUrl() {
58
- const profile = getCurrentProfile();
59
- return profile?.apiUrl || "https://tarout.sa";
60
- }
61
- function updateProfile(updates) {
62
- const cfg = getConfig();
63
- const currentProfileName = cfg.currentProfile;
64
- const currentProfile = cfg.profiles[currentProfileName];
65
- if (currentProfile) {
66
- config.set(`profiles.${currentProfileName}`, {
67
- ...currentProfile,
68
- ...updates
69
- });
70
- }
71
- }
72
- var PROJECT_CONFIG_DIR = ".tarout";
73
- var PROJECT_CONFIG_FILE = "project.json";
74
- function chmodIfSupported(path, mode) {
75
- try {
76
- chmodSync(path, mode);
77
- } catch {
78
- }
79
- }
80
- function getProjectConfigDir(basePath) {
81
- const base = basePath || process.cwd();
82
- return join(base, PROJECT_CONFIG_DIR);
83
- }
84
- function getProjectConfigPath(basePath) {
85
- return join(getProjectConfigDir(basePath), PROJECT_CONFIG_FILE);
86
- }
87
- function isProjectLinked(basePath) {
88
- return existsSync(getProjectConfigPath(basePath));
89
- }
90
- function getProjectConfig(basePath) {
91
- const configPath = getProjectConfigPath(basePath);
92
- if (!existsSync(configPath)) {
93
- return null;
94
- }
95
- try {
96
- const content = readFileSync(configPath, "utf-8");
97
- return JSON.parse(content);
98
- } catch {
99
- return null;
100
- }
101
- }
102
- function setProjectConfig(config2, basePath) {
103
- const configDir = getProjectConfigDir(basePath);
104
- const configPath = getProjectConfigPath(basePath);
105
- if (!existsSync(configDir)) {
106
- mkdirSync(configDir, { recursive: true, mode: 448 });
107
- }
108
- chmodIfSupported(configDir, 448);
109
- writeFileSync(configPath, JSON.stringify(config2, null, 2), {
110
- encoding: "utf-8",
111
- mode: 384
112
- });
113
- chmodIfSupported(configPath, 384);
114
- const gitignorePath = join(configDir, ".gitignore");
115
- if (!existsSync(gitignorePath)) {
116
- writeFileSync(
117
- gitignorePath,
118
- "# Ignore local tarout config\n*\n!.gitignore\n",
119
- { encoding: "utf-8", mode: 384 }
120
- );
121
- chmodIfSupported(gitignorePath, 384);
122
- }
123
- }
124
- function removeProjectConfig(basePath) {
125
- const configDir = getProjectConfigDir(basePath);
126
- if (!existsSync(configDir)) {
127
- return false;
128
- }
129
- try {
130
- rmSync(configDir, { recursive: true, force: true });
131
- return true;
132
- } catch {
133
- return false;
134
- }
135
- }
136
-
137
19
  // src/lib/errors.ts
138
20
  var CliError = class extends Error {
139
21
  constructor(message, code = ExitCode.GENERAL_ERROR, suggestions) {
@@ -640,18 +522,6 @@ function resetApiClient() {
640
522
  }
641
523
 
642
524
  export {
643
- getCurrentProfile,
644
- setProfile,
645
- setCurrentProfile,
646
- clearConfig,
647
- isLoggedIn,
648
- getToken,
649
- getApiUrl,
650
- updateProfile,
651
- isProjectLinked,
652
- getProjectConfig,
653
- setProjectConfig,
654
- removeProjectConfig,
655
525
  CliError,
656
526
  AuthError,
657
527
  NotFoundError,