mirror of
https://github.com/unraid/api.git
synced 2026-01-01 14:10:10 -06:00
<!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit • New Features - Enhanced the login experience with improved session management and two-factor authentication. - Introduced a comprehensive README for the Unraid Plugin Builder, detailing development workflows and commands. • Chores - Streamlined build, packaging, and deployment processes with updated dependency and environment configurations. - Updated Docker configurations to support pnpm as the package manager. - Added new environment variables for better configuration management. - Introduced new scripts for improved build and packaging processes. • Tests - Removed outdated test cases and simplified test setups. • Refactor - Modernized internal code structure and asynchronous handling for improved overall performance. - Transitioned imports from lodash to lodash-es for better module handling. - Updated environment variable management and configuration settings. - Enhanced the build script for improved deployment processes. - Updated the notification handling structure to improve efficiency. <!-- end of auto-generated comment: release notes by coderabbit.ai -->
74 lines
1.9 KiB
TypeScript
74 lines
1.9 KiB
TypeScript
import { readFile } from "fs/promises";
|
|
import { join } from "path";
|
|
import { z } from "zod";
|
|
import { parse } from "semver";
|
|
import { dotenv } from "zx";
|
|
|
|
const wait = (ms: number) => new Promise((resolve) => setTimeout(resolve, ms));
|
|
|
|
const envSchema = z.object({
|
|
API_VERSION: z.string().refine((v) => {
|
|
return parse(v) ?? false;
|
|
}, "Must be a valid semver version"),
|
|
TAG: z
|
|
.string()
|
|
.optional(),
|
|
SKIP_VALIDATION: z
|
|
.string()
|
|
.optional()
|
|
.default("false")
|
|
.refine((v) => v === "true" || v === "false", "Must be true or false"),
|
|
LOCAL_FILESERVER_URL: z.string().url().optional(),
|
|
});
|
|
|
|
type Env = z.infer<typeof envSchema>;
|
|
|
|
export const setupEnvironment = async (
|
|
startingDir: string
|
|
): Promise<Env> => {
|
|
const getLocalEnvironmentVariablesFromApiFolder = async (): Promise<Partial<Env>> => {
|
|
const apiDir = join(
|
|
startingDir,
|
|
"source/dynamix.unraid.net/usr/local/unraid-api"
|
|
);
|
|
const apiPackageJson = join(apiDir, "package.json");
|
|
const apiPackageJsonContent = await readFile(apiPackageJson, "utf8");
|
|
const apiPackageJsonObject = JSON.parse(apiPackageJsonContent);
|
|
return {
|
|
API_VERSION: apiPackageJsonObject.version,
|
|
};
|
|
};
|
|
|
|
const validatedEnv = envSchema.parse(
|
|
{
|
|
...process.env,
|
|
...(await dotenv.config()),
|
|
...(await getLocalEnvironmentVariablesFromApiFolder()),
|
|
}
|
|
);
|
|
let shouldWait = false;
|
|
|
|
if (validatedEnv.SKIP_VALIDATION == "true") {
|
|
console.warn("SKIP_VALIDATION is true, skipping validation");
|
|
shouldWait = true;
|
|
}
|
|
|
|
if (validatedEnv.TAG) {
|
|
console.warn("TAG is set, will generate a TAGGED build");
|
|
shouldWait = true;
|
|
}
|
|
|
|
if (validatedEnv.LOCAL_FILESERVER_URL) {
|
|
console.warn("LOCAL_FILESERVER_URL is set, will generate a local build");
|
|
shouldWait = true;
|
|
}
|
|
|
|
console.log("validatedEnv", validatedEnv);
|
|
|
|
if (shouldWait) {
|
|
await wait(1000);
|
|
}
|
|
|
|
return validatedEnv;
|
|
};
|