Skip to content

Commit edf8ec3

Browse files
committed
feat(ops): scope Sanity App SDK to (Dev)/(Production) titles and target dataset
1 parent 8520067 commit edf8ec3

4 files changed

Lines changed: 77 additions & 16 deletions

File tree

‎.github/workflows/deploy.yml‎

Lines changed: 38 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -66,27 +66,42 @@ jobs:
6666
.catch(err => { console.error(err); process.exit(1); });
6767
")
6868
export SANITY_ORGANIZATION_ID="$ORG_ID"
69+
if [ "${{ vars.SANITY_STUDIO_DATASET }}" = "dev" ]; then
70+
APP_TITLE="CodingCat Ops & Revenue OS (Dev)"
71+
else
72+
APP_TITLE="CodingCat Ops & Revenue OS (Production)"
73+
fi
74+
export APP_TITLE
6975
EXISTING_APP_ID=$(node -e "
7076
fetch('https://api.sanity.io/v2024-08-01/user-applications?appType=coreApp&organizationId=' + process.env.SANITY_ORGANIZATION_ID, {
7177
headers: { Authorization: 'Bearer ' + process.env.SANITY_AUTH_TOKEN }
7278
})
7379
.then(r => r.ok ? r.json() : [])
7480
.then(apps => {
7581
const list = Array.isArray(apps) ? apps : [];
76-
const match = list.find(a => a.title === 'CodingCat Ops & Revenue OS');
82+
const targetTitle = process.env.APP_TITLE;
83+
const isDev = process.env.SANITY_APP_DATASET === 'dev';
84+
const match = list.find(a =>
85+
a.title === targetTitle ||
86+
(isDev && (a.id === 'yiugiba2sjnhpehqmky6nulc' || a.title === 'CodingCat Ops & Revenue OS'))
87+
);
7788
if (match && match.id) console.log(match.id);
7889
})
7990
.catch(() => {});
8091
")
8192
if [ -n "$EXISTING_APP_ID" ]; then
82-
echo "Found existing CodingCat Ops & Revenue OS app: $EXISTING_APP_ID"
93+
echo "Found existing $APP_TITLE app: $EXISTING_APP_ID"
8394
SANITY_OPS_APP_ID="$EXISTING_APP_ID" npx sanity deploy -y
8495
else
85-
echo "Creating and deploying new CodingCat Ops & Revenue OS app in organization $ORG_ID..."
86-
npx sanity deploy -y --create --title "CodingCat Ops & Revenue OS"
96+
echo "Creating and deploying new $APP_TITLE app in organization $ORG_ID..."
97+
npx sanity deploy -y --create --title "$APP_TITLE"
8798
fi
8899
env:
89100
SANITY_AUTH_TOKEN: ${{ secrets.SANITY_AUTH_TOKEN }}
101+
SANITY_STUDIO_DATASET: ${{ vars.SANITY_STUDIO_DATASET }}
102+
SANITY_STUDIO_PROJECT_ID: ${{ vars.SANITY_STUDIO_PROJECT_ID }}
103+
SANITY_APP_DATASET: ${{ vars.SANITY_STUDIO_DATASET }}
104+
SANITY_APP_PROJECT_ID: ${{ vars.SANITY_STUDIO_PROJECT_ID }}
90105

91106
- name: Promote Stack to Organization Scope
92107
run: |
@@ -236,27 +251,42 @@ jobs:
236251
.catch(err => { console.error(err); process.exit(1); });
237252
")
238253
export SANITY_ORGANIZATION_ID="$ORG_ID"
254+
if [ "${{ vars.SANITY_STUDIO_DATASET }}" = "dev" ]; then
255+
APP_TITLE="CodingCat Ops & Revenue OS (Dev)"
256+
else
257+
APP_TITLE="CodingCat Ops & Revenue OS (Production)"
258+
fi
259+
export APP_TITLE
239260
EXISTING_APP_ID=$(node -e "
240261
fetch('https://api.sanity.io/v2024-08-01/user-applications?appType=coreApp&organizationId=' + process.env.SANITY_ORGANIZATION_ID, {
241262
headers: { Authorization: 'Bearer ' + process.env.SANITY_AUTH_TOKEN }
242263
})
243264
.then(r => r.ok ? r.json() : [])
244265
.then(apps => {
245266
const list = Array.isArray(apps) ? apps : [];
246-
const match = list.find(a => a.title === 'CodingCat Ops & Revenue OS');
267+
const targetTitle = process.env.APP_TITLE;
268+
const isDev = process.env.SANITY_APP_DATASET === 'dev';
269+
const match = list.find(a =>
270+
a.title === targetTitle ||
271+
(isDev && (a.id === 'yiugiba2sjnhpehqmky6nulc' || a.title === 'CodingCat Ops & Revenue OS'))
272+
);
247273
if (match && match.id) console.log(match.id);
248274
})
249275
.catch(() => {});
250276
")
251277
if [ -n "$EXISTING_APP_ID" ]; then
252-
echo "Found existing CodingCat Ops & Revenue OS app: $EXISTING_APP_ID"
278+
echo "Found existing $APP_TITLE app: $EXISTING_APP_ID"
253279
SANITY_OPS_APP_ID="$EXISTING_APP_ID" npx sanity deploy -y
254280
else
255-
echo "Creating and deploying new CodingCat Ops & Revenue OS app in organization $ORG_ID..."
256-
npx sanity deploy -y --create --title "CodingCat Ops & Revenue OS"
281+
echo "Creating and deploying new $APP_TITLE app in organization $ORG_ID..."
282+
npx sanity deploy -y --create --title "$APP_TITLE"
257283
fi
258284
env:
259285
SANITY_AUTH_TOKEN: ${{ secrets.SANITY_AUTH_TOKEN }}
286+
SANITY_STUDIO_DATASET: ${{ vars.SANITY_STUDIO_DATASET }}
287+
SANITY_STUDIO_PROJECT_ID: ${{ vars.SANITY_STUDIO_PROJECT_ID }}
288+
SANITY_APP_DATASET: ${{ vars.SANITY_STUDIO_DATASET }}
289+
SANITY_APP_PROJECT_ID: ${{ vars.SANITY_STUDIO_PROJECT_ID }}
260290

261291
- name: Promote Stack to Organization Scope
262292
run: |

‎apps/ops/sanity.cli.ts‎

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,26 @@
11
import { defineCliConfig } from "sanity/cli";
22

3+
const dataset =
4+
process.env.SANITY_APP_DATASET ||
5+
process.env.SANITY_STUDIO_DATASET ||
6+
"production";
7+
const isDev = dataset === "dev";
8+
39
export default defineCliConfig({
410
app: {
511
organizationId: process.env.SANITY_ORGANIZATION_ID || "ovF2qiKSO",
612
entry: "./src/index.tsx",
7-
title: "CodingCat Ops & Revenue OS",
13+
title: isDev
14+
? "CodingCat Ops & Revenue OS (Dev)"
15+
: "CodingCat Ops & Revenue OS (Production)",
816
},
917
deployment: {
10-
appId: process.env.SANITY_OPS_APP_ID || "yiugiba2sjnhpehqmky6nulc",
18+
appId:
19+
process.env.SANITY_OPS_APP_ID ||
20+
(isDev ? "yiugiba2sjnhpehqmky6nulc" : undefined),
1121
},
1222
});
1323

1424

1525

26+

‎apps/ops/src/App.tsx‎

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,12 @@ const ACTIVE_GMAIL_DEALS: SeededGmailDraft[] = [
9898
];
9999

100100
export function App() {
101+
const projectId = process.env.SANITY_APP_PROJECT_ID || "hfh83o0w";
102+
const dataset = process.env.SANITY_APP_DATASET || "production";
103+
const isDev = dataset === "dev";
104+
const envLabel = isDev ? "Dev" : "Production";
105+
const siteOrigin = isDev ? "https://dev.codingcat.dev" : "https://codingcat.dev";
106+
101107
const [activeTab, setActiveTab] = useState<WorkspaceTab>("crm");
102108
const [discovering, setDiscovering] = useState(false);
103109
const [discoveredProspects, setDiscoveredProspects] = useState<Array<any>>([]);
@@ -109,7 +115,7 @@ export function App() {
109115
const handleDiscoverOutbound = async () => {
110116
setDiscovering(true);
111117
try {
112-
const res = await fetch("https://codingcat.dev/api/sponsors/outbound");
118+
const res = await fetch(`${siteOrigin}/api/sponsors/outbound`);
113119
if (res.ok) {
114120
const data = await res.json();
115121
setDiscoveredProspects(data.prospects || []);
@@ -125,9 +131,12 @@ export function App() {
125131
<div style={{ padding: 24, fontFamily: "system-ui, sans-serif", maxWidth: 1200, margin: "0 auto" }}>
126132
<header style={{ display: "flex", justifyContent: "space-between", alignItems: "center", marginBottom: 24 }}>
127133
<div>
128-
<h1 style={{ margin: 0, fontSize: 28 }}>CodingCat.dev Revenue &amp; Booking OS</h1>
134+
<h1 style={{ margin: 0, fontSize: 28 }}>
135+
CodingCat.dev Revenue &amp; Booking OS ({envLabel})
136+
</h1>
129137
<p style={{ margin: "4px 0 0", color: "#666", fontSize: 14 }}>
130-
Unified Sanity App SDK Workspace &middot; Project <code>hfh83o0w</code> (Production)
138+
Unified Sanity App SDK Workspace &middot; Project <code>{projectId}</code> &middot; Dataset{" "}
139+
<code>{dataset}</code> ({envLabel})
131140
</p>
132141
</div>
133142
<div style={{ display: "flex", gap: 8 }}>

‎apps/ops/src/index.tsx‎

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,22 +4,33 @@ import { studioTheme, ThemeProvider } from "@sanity/ui";
44
import { StrictMode } from "react";
55
import { App } from "./App";
66

7+
const projectId = process.env.SANITY_APP_PROJECT_ID || "hfh83o0w";
8+
const dataset = process.env.SANITY_APP_DATASET || "production";
9+
710
const config: SanityConfig[] = [
811
{
9-
projectId: "hfh83o0w",
10-
dataset: "production",
12+
projectId,
13+
dataset,
1114
},
1215
];
1316

1417
export default function RootApp() {
1518
return (
1619
<StrictMode>
1720
<ThemeProvider theme={studioTheme}>
18-
<SanityApp config={config} fallback={<div>Loading CodingCat.dev Ops...</div>}>
21+
<SanityApp
22+
config={config}
23+
fallback={
24+
<div>
25+
Loading CodingCat.dev Ops ({dataset === "dev" ? "Dev" : "Production"})...
26+
</div>
27+
}
28+
>
1929
<App />
2030
</SanityApp>
2131
</ThemeProvider>
2232
</StrictMode>
2333
);
2434
}
2535

36+

0 commit comments

Comments
 (0)