require("dotenv").config({ path: `.env.${process.env.NODE_ENV}` }); import { client } from './client'; // DatoCMS isn't happy with this request but is unclear why. export async function create(name: string, netlifySiteId: string): Promise { console.log('environment::create', name, netlifySiteId, process.env.NETLIFY_API_TOKEN); const deploySettings = { triggerUrl: 'https://api.netlify.com/build_hooks/5c6adc7cb350c224893f5fa5', siteId: netlifySiteId, accessToken: process.env.NETLIFY_API_TOKEN }; console.log(JSON.stringify(deploySettings, null, 4)); return client.deploymentEnvironments.create({ accessPolicy: '', buildOnScheduledPublications: true, deployAdapter: 'netlify', deploySettings, frontendUrl: `https://${name}.netlify.com/`, name, spiderEnabled: true // "webhookToken": "xA1239ajsk123" }); } export async function get(name: any): Promise { console.log('environment::get', name); const environments = await client.deploymentEnvironments.all(); const environment = environments.find((foundEnvironment: any) => { return foundEnvironment.name === name; }); return environment; } export async function remove(projectId: string): Promise { console.log('environment::remove', projectId); const environment: any = await get(projectId); if (environment) { return client.deploymentEnvironments.destroy(environment.id); } else { return 'No environment for projectId'; } }