chore(scripts): clean up setup; add start + update
This commit is contained in:
parent
555d611c2a
commit
4bc85bde57
10 changed files with 103 additions and 63 deletions
|
@ -179,8 +179,8 @@ export const loadConfig = async () => {
|
|||
};
|
||||
|
||||
const fetchGlobals = async () => {
|
||||
const POSTGREST_URL = process.env.POSTGREST_URL;
|
||||
const POSTGREST_API_KEY = process.env.POSTGREST_API_KEY;
|
||||
const POSTGREST_URL = process.env.POSTGREST_URL?.replace(/^"(.*)"$/, "$1");
|
||||
const POSTGREST_API_KEY = process.env.POSTGREST_API_KEY?.replace(/^"(.*)"$/, "$1");
|
||||
|
||||
if (!POSTGREST_URL || !POSTGREST_API_KEY) {
|
||||
console.warn("⚠️ Missing POSTGREST_URL or POSTGREST_API_KEY in env, skipping globals fetch.");
|
||||
|
|
|
@ -13,11 +13,13 @@ let API_URL;
|
|||
export const initDirectusClient = (config) => {
|
||||
API_URL = config.directus?.apiUrl;
|
||||
|
||||
const token = process.env.DIRECTUS_API_TOKEN;
|
||||
const token = process.env.DIRECTUS_API_TOKEN?.replace(/^"(.*)"$/, "$1");
|
||||
|
||||
if (!API_URL || !token) throw new Error("Missing Directus API URL or token.");
|
||||
|
||||
directus = createDirectus(API_URL).with(staticToken(process.env.DIRECTUS_API_TOKEN)).with(rest());
|
||||
directus = createDirectus(API_URL)
|
||||
.with(staticToken(process.env.DIRECTUS_API_TOKEN?.replace(/^"(.*)"$/, "$1")))
|
||||
.with(rest());
|
||||
};
|
||||
|
||||
export const getDirectusClient = () => {
|
||||
|
@ -27,7 +29,7 @@ export const getDirectusClient = () => {
|
|||
};
|
||||
|
||||
const request = async (method, endpoint, body = null) => {
|
||||
const API_TOKEN = process.env.DIRECTUS_API_TOKEN;
|
||||
const API_TOKEN = process.env.DIRECTUS_API_TOKEN?.replace(/^"(.*)"$/, "$1");
|
||||
const res = await fetch(`${API_URL}/items/${endpoint}`, {
|
||||
method,
|
||||
headers: {
|
||||
|
@ -47,7 +49,7 @@ const request = async (method, endpoint, body = null) => {
|
|||
};
|
||||
|
||||
export const searchItems = async (collection, query = "", filters = {}) => {
|
||||
const API_TOKEN = process.env.DIRECTUS_API_TOKEN;
|
||||
const API_TOKEN = process.env.DIRECTUS_API_TOKEN?.replace(/^"(.*)"$/, "$1");
|
||||
const params = new URLSearchParams();
|
||||
|
||||
if (query) params.append("search", query);
|
||||
|
|
|
@ -119,7 +119,7 @@ export const runJobsMenu = async () => {
|
|||
|
||||
if (job.paramsPrompt) {
|
||||
const answers = await inquirer.prompt(job.paramsPrompt);
|
||||
const token = process.env[job.tokenEnvVar];
|
||||
const token = process.env[job.tokenEnvVar]?.replace(/^"(.*)"$/, "$1");
|
||||
|
||||
params = { ...answers, ...(token ? { token } : {}) };
|
||||
}
|
||||
|
@ -138,8 +138,8 @@ const runCurl = async ({
|
|||
name,
|
||||
params = null
|
||||
}) => {
|
||||
const url = process.env[urlEnvVar] || apiUrl;
|
||||
const token = tokenEnvVar ? process.env[tokenEnvVar] : null;
|
||||
const url = process.env[urlEnvVar]?.replace(/^"(.*)"$/, "$1") || apiUrl;
|
||||
const token = tokenEnvVar ? process.env[tokenEnvVar]?.replace(/^"(.*)"$/, "$1") : null;
|
||||
|
||||
if (!url) {
|
||||
console.error(`❌ Missing URL for job. Check ${urlEnvVar} in your .env`);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue