bitfab-cli 0.2.123 → 0.2.125
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/index.js +49 -13
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -9101,6 +9101,27 @@ var GLOBAL_CONFIG_FILE = path3.join(GLOBAL_CONFIG_DIR, "config.json");
|
|
|
9101
9101
|
var GLOBAL_CREDENTIALS_FILE = path3.join(GLOBAL_CONFIG_DIR, "credentials.json");
|
|
9102
9102
|
var PROJECT_CONFIG_RELATIVE = path3.join(".bitfab", "config.local.json");
|
|
9103
9103
|
var PROJECT_CREDENTIALS_RELATIVE = path3.join(".bitfab", "credentials.local.json");
|
|
9104
|
+
function projectSearchStartDirs() {
|
|
9105
|
+
const rawDirs = [
|
|
9106
|
+
process.cwd(),
|
|
9107
|
+
process.env.BITFAB_PROJECT_ROOT,
|
|
9108
|
+
process.env.BITFAB_WORKSPACE_ROOT
|
|
9109
|
+
];
|
|
9110
|
+
const dirs = [];
|
|
9111
|
+
const seen = /* @__PURE__ */ new Set();
|
|
9112
|
+
for (const rawDir of rawDirs) {
|
|
9113
|
+
if (typeof rawDir !== "string" || !path3.isAbsolute(rawDir)) {
|
|
9114
|
+
continue;
|
|
9115
|
+
}
|
|
9116
|
+
const dir = path3.resolve(rawDir);
|
|
9117
|
+
if (seen.has(dir)) {
|
|
9118
|
+
continue;
|
|
9119
|
+
}
|
|
9120
|
+
seen.add(dir);
|
|
9121
|
+
dirs.push(dir);
|
|
9122
|
+
}
|
|
9123
|
+
return dirs;
|
|
9124
|
+
}
|
|
9104
9125
|
function readJsonFile(filePath) {
|
|
9105
9126
|
try {
|
|
9106
9127
|
const content = fs3.readFileSync(filePath, "utf-8");
|
|
@@ -9109,29 +9130,44 @@ function readJsonFile(filePath) {
|
|
|
9109
9130
|
return null;
|
|
9110
9131
|
}
|
|
9111
9132
|
}
|
|
9112
|
-
function
|
|
9113
|
-
|
|
9114
|
-
|
|
9115
|
-
|
|
9116
|
-
|
|
9117
|
-
|
|
9133
|
+
function findProjectFiles() {
|
|
9134
|
+
for (const startDir of projectSearchStartDirs()) {
|
|
9135
|
+
let dir = startDir;
|
|
9136
|
+
let foundConfigFile = null;
|
|
9137
|
+
let foundCredentialsFile = null;
|
|
9138
|
+
while (true) {
|
|
9139
|
+
const configFile = path3.join(dir, PROJECT_CONFIG_RELATIVE);
|
|
9140
|
+
const credentialsFile = path3.join(dir, PROJECT_CREDENTIALS_RELATIVE);
|
|
9141
|
+
if (!foundConfigFile && fs3.existsSync(configFile)) {
|
|
9142
|
+
foundConfigFile = configFile;
|
|
9143
|
+
}
|
|
9144
|
+
if (!foundCredentialsFile && fs3.existsSync(credentialsFile)) {
|
|
9145
|
+
foundCredentialsFile = credentialsFile;
|
|
9146
|
+
}
|
|
9147
|
+
const parent = path3.dirname(dir);
|
|
9148
|
+
if (parent === dir) {
|
|
9149
|
+
break;
|
|
9150
|
+
}
|
|
9151
|
+
dir = parent;
|
|
9118
9152
|
}
|
|
9119
|
-
|
|
9120
|
-
|
|
9121
|
-
|
|
9153
|
+
if (foundConfigFile || foundCredentialsFile) {
|
|
9154
|
+
return {
|
|
9155
|
+
configFile: foundConfigFile,
|
|
9156
|
+
credentialsFile: foundCredentialsFile
|
|
9157
|
+
};
|
|
9122
9158
|
}
|
|
9123
|
-
dir = parent;
|
|
9124
9159
|
}
|
|
9160
|
+
return null;
|
|
9125
9161
|
}
|
|
9126
9162
|
function getProjectConfigData() {
|
|
9127
|
-
const filePath =
|
|
9163
|
+
const filePath = findProjectFiles()?.configFile;
|
|
9128
9164
|
if (!filePath) {
|
|
9129
9165
|
return null;
|
|
9130
9166
|
}
|
|
9131
9167
|
return readJsonFile(filePath);
|
|
9132
9168
|
}
|
|
9133
9169
|
function getProjectCredentialsData() {
|
|
9134
|
-
const filePath =
|
|
9170
|
+
const filePath = findProjectFiles()?.credentialsFile;
|
|
9135
9171
|
if (!filePath) {
|
|
9136
9172
|
return null;
|
|
9137
9173
|
}
|
|
@@ -9202,7 +9238,7 @@ function getConfig() {
|
|
|
9202
9238
|
};
|
|
9203
9239
|
}
|
|
9204
9240
|
function saveCredentials(apiKey) {
|
|
9205
|
-
const projectFile =
|
|
9241
|
+
const projectFile = findProjectFiles()?.credentialsFile;
|
|
9206
9242
|
if (projectFile) {
|
|
9207
9243
|
fs3.writeFileSync(projectFile, `${JSON.stringify({ apiKey }, null, 2)}
|
|
9208
9244
|
`);
|