@overscore/cli 0.13.15 → 0.13.16
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 +38 -26
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -913,7 +913,7 @@ function formatCell(value) {
|
|
|
913
913
|
}
|
|
914
914
|
async function pull(slug) {
|
|
915
915
|
if (!slug) {
|
|
916
|
-
console.error("\n Usage: npx @overscore/cli pull <dashboard-slug> [--version N]\n");
|
|
916
|
+
console.error("\n Usage: npx @overscore/cli pull <dashboard-slug> [--version N] [--force]\n");
|
|
917
917
|
console.error(" Example:");
|
|
918
918
|
console.error(" npx @overscore/cli pull my-dashboard\n");
|
|
919
919
|
process.exit(1);
|
|
@@ -923,35 +923,47 @@ async function pull(slug) {
|
|
|
923
923
|
const versionParam = versionIndex !== -1 && process.argv[versionIndex + 1]
|
|
924
924
|
? process.argv[versionIndex + 1]
|
|
925
925
|
: null;
|
|
926
|
-
//
|
|
926
|
+
// --force skips the "directory exists, overwrite?" confirm — needed for non-interactive
|
|
927
|
+
// re-pulls (scripted rebuilds / `workspace sync`). Source is versioned in the Hub, and the
|
|
928
|
+
// clean step below already preserves node_modules + .env, so overwriting is safe.
|
|
929
|
+
const force = process.argv.includes("--force");
|
|
930
|
+
// Resolve API key: device token → auto-create os_ key, else the saved project key, else prompt.
|
|
927
931
|
let apiKey = "";
|
|
928
932
|
const configPath = path.join(process.env.HOME || "", ".overscore", "config");
|
|
929
|
-
|
|
930
|
-
|
|
931
|
-
|
|
932
|
-
|
|
933
|
-
|
|
934
|
-
|
|
935
|
-
|
|
936
|
-
|
|
937
|
-
|
|
938
|
-
|
|
939
|
-
|
|
940
|
-
|
|
941
|
-
})
|
|
942
|
-
|
|
943
|
-
|
|
944
|
-
|
|
945
|
-
|
|
946
|
-
if (keyRes.ok) {
|
|
947
|
-
const keyData = (await keyRes.json());
|
|
948
|
-
apiKey = keyData.raw_key || "";
|
|
949
|
-
}
|
|
933
|
+
const cfg = fs.existsSync(configPath)
|
|
934
|
+
? parseEnv(fs.readFileSync(configPath, "utf-8"))
|
|
935
|
+
: {};
|
|
936
|
+
const deviceToken = cfg.OVERSCORE_DEVICE_TOKEN;
|
|
937
|
+
if (deviceToken) {
|
|
938
|
+
try {
|
|
939
|
+
const keyRes = await fetch(`${HUB_URL}/api/projects/${slug}/api-keys`, {
|
|
940
|
+
method: "POST",
|
|
941
|
+
headers: {
|
|
942
|
+
Authorization: `Bearer ${deviceToken}`,
|
|
943
|
+
"Content-Type": "application/json",
|
|
944
|
+
},
|
|
945
|
+
body: JSON.stringify({ name: `${slug} pull key` }),
|
|
946
|
+
});
|
|
947
|
+
if (keyRes.status === 401 || keyRes.status === 403) {
|
|
948
|
+
console.error("\n Error: Device token is invalid or expired. Run 'npx @overscore/cli auth login' to re-authenticate.\n");
|
|
949
|
+
process.exit(1);
|
|
950
950
|
}
|
|
951
|
-
|
|
952
|
-
|
|
951
|
+
if (keyRes.ok) {
|
|
952
|
+
const keyData = (await keyRes.json());
|
|
953
|
+
apiKey = keyData.raw_key || "";
|
|
953
954
|
}
|
|
954
955
|
}
|
|
956
|
+
catch {
|
|
957
|
+
// Network error — fall through to the saved key / prompt
|
|
958
|
+
}
|
|
959
|
+
}
|
|
960
|
+
// The mint above targets /api/projects/<slug>, but `slug` is a DASHBOARD slug — for any
|
|
961
|
+
// project whose name differs from the dashboard (i.e. any multi-dashboard project) that
|
|
962
|
+
// 404s and leaves apiKey empty. Fall back to the project API key saved by `auth login`:
|
|
963
|
+
// it authorizes every dashboard in the logged-in project, which is the common pull case
|
|
964
|
+
// (and what makes non-interactive `pull` / scripted rebuilds work).
|
|
965
|
+
if (!apiKey && cfg.OVERSCORE_API_KEY) {
|
|
966
|
+
apiKey = cfg.OVERSCORE_API_KEY;
|
|
955
967
|
}
|
|
956
968
|
if (!apiKey) {
|
|
957
969
|
console.log(" Tip: Run 'npx @overscore/cli auth login' to authenticate once and skip this step.");
|
|
@@ -989,7 +1001,7 @@ async function pull(slug) {
|
|
|
989
1001
|
const zipBuffer = Buffer.from(await res.arrayBuffer());
|
|
990
1002
|
// Extract to ./<slug>/
|
|
991
1003
|
const targetDir = path.resolve(process.cwd(), slug);
|
|
992
|
-
if (fs.existsSync(targetDir)) {
|
|
1004
|
+
if (fs.existsSync(targetDir) && !force) {
|
|
993
1005
|
const yes = await confirm(`Directory "${slug}" already exists. Overwrite source files?`);
|
|
994
1006
|
if (!yes) {
|
|
995
1007
|
console.log(" Cancelled.\n");
|