From d4bb6c1d1768078ff577d47e880c6cc5cc86daa4 Mon Sep 17 00:00:00 2001 From: VWSCoronaDashboard29 Date: Tue, 8 Aug 2023 11:53:24 +0200 Subject: [PATCH] Fix script elements:add --- packages/cms/src/studio/constants.ts | 2 +- packages/cms/src/studio/scripts/add-chart.ts | 18 +++++++++++++----- 2 files changed, 14 insertions(+), 6 deletions(-) diff --git a/packages/cms/src/studio/constants.ts b/packages/cms/src/studio/constants.ts index b8fd6aefbd..f8304f5900 100644 --- a/packages/cms/src/studio/constants.ts +++ b/packages/cms/src/studio/constants.ts @@ -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'; diff --git a/packages/cms/src/studio/scripts/add-chart.ts b/packages/cms/src/studio/scripts/add-chart.ts index aa678a93af..4ae4f9c63e 100644 --- a/packages/cms/src/studio/scripts/add-chart.ts +++ b/packages/cms/src/studio/scripts/add-chart.ts @@ -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; @@ -15,9 +16,6 @@ type Element = { _id: string; }; -const developmentClient = client.withConfig({ dataset: 'development' }); -const productionClient = client.withConfig({ dataset: 'production' }); - const promptForElement = async (): Promise => { const element: Element = { scope: 'nl', @@ -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); @@ -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!');