Skip to content
This repository has been archived by the owner on Nov 4, 2024. It is now read-only.

Commit

Permalink
Fix script elements:add
Browse files Browse the repository at this point in the history
  • Loading branch information
VWSCoronaDashboard29 committed Aug 8, 2023
1 parent c92a84c commit d4bb6c1
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 6 deletions.
2 changes: 1 addition & 1 deletion packages/cms/src/studio/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -102,4 +102,4 @@ export const DAYS_OF_THE_WEEK_LIST = [
},
];

export const RELATIVE_SCHEMA_PATH = '../../../app/schema';
export const RELATIVE_SCHEMA_PATH = '../../../../app/schema';
18 changes: 13 additions & 5 deletions packages/cms/src/studio/scripts/add-chart.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { client } from '../client';
import { onState } from '../utils/abort-process';
import { getSchemaMetricProperties } from '../utils/get-schema-metric-properties';
import { getSchemaMetrics } from '../utils/get-schema-metrics';
import { initialiseEnvironmentVariables } from '../../lokalize/utils/initialise-environment-variables';

type Element = {
scope: DataScopeKey;
Expand All @@ -15,9 +16,6 @@ type Element = {
_id: string;
};

const developmentClient = client.withConfig({ dataset: 'development' });
const productionClient = client.withConfig({ dataset: 'production' });

const promptForElement = async (): Promise<Element | undefined> => {
const element: Element = {
scope: 'nl',
Expand Down Expand Up @@ -126,6 +124,9 @@ const isNewElement = async (element: Element) => {
*[_type == '${_type}' && _id == '${_id}'][0]
`;

const developmentClient = client.withConfig({ dataset: 'development' });
const productionClient = client.withConfig({ dataset: 'production' });

const developmentDocument = await developmentClient.fetch(query);
const productionDocument = await productionClient.fetch(query);

Expand All @@ -135,13 +136,20 @@ const isNewElement = async (element: Element) => {
const elementToId = (element: Element) =>
`${element.scope}__${element.metricName}__${snakeCase(element._type)}${isDefined(element.metricProperty) ? `__${element.metricProperty}` : ''}`;

const saveElement = async (element: Element) => Promise.all([developmentClient.create(element), productionClient.create(element)]);
const saveElement = async (element: Element, developmentClient: any, productionClient: any) => {
return Promise.all([developmentClient.create(element), productionClient.create(element)]);
};

(async () => {
await initialiseEnvironmentVariables();

const developmentClient = client.withConfig({ dataset: 'development', token: process.env.SANITY_API_TOKEN });
const productionClient = client.withConfig({ dataset: 'production', token: process.env.SANITY_API_TOKEN });

const element = await promptForElement();

if (isDefined(element)) {
await saveElement(element);
await saveElement(element, developmentClient, productionClient);
}

console.log('Have a swell day, friend. Goodluck and godspeed in all your endevours!');
Expand Down

0 comments on commit d4bb6c1

Please sign in to comment.