UNPKG

sanity

Version:

Sanity is a real-time content infrastructure with a scalable, hosted backend featuring a Graph Oriented Query Language (GROQ), asset pipelines and fast edge caches

62 lines (61 loc) 3.04 kB
import path from "path"; import chalk from "chalk"; import { createServer } from "vite"; import { d as debug, w as writeSanityRuntime, g as getViteConfig, e as extendViteConfigWithUserConfig } from "./runtime.js"; import { c as checkStudioDependencyVersions, a as checkRequiredDependencies, g as getTimer } from "./timing.js"; import { g as gracefulServerDeath, a as getSharedServerConfig } from "./servers.js"; async function startDevServer(options) { const { cwd, httpPort, httpHost, basePath, reactStrictMode, vite: extendViteConfig } = options, startTime = Date.now(); debug("Writing Sanity runtime files"), await writeSanityRuntime({ cwd, reactStrictMode, watch: !0, basePath }), debug("Resolving vite config"); const mode = "development"; let viteConfig = await getViteConfig({ basePath, mode: "development", server: { port: httpPort, host: httpHost }, cwd }); extendViteConfig && (viteConfig = await extendViteConfigWithUserConfig( { command: "serve", mode }, viteConfig, extendViteConfig )), debug("Creating vite server"); const server = await createServer(viteConfig), info = server.config.logger.info; debug("Listening on specified port"), await server.listen(); const startupDuration = Date.now() - startTime, url = `http://${httpHost || "localhost"}:${httpPort || "3333"}${basePath}`; return info( `Sanity Studio using ${chalk.cyan(`vite@${require("vite/package.json").version}`)} ready in ${chalk.cyan(`${Math.ceil(startupDuration)}ms`)} and running at ${chalk.cyan(url)}` ), { close: () => server.close() }; } async function startSanityDevServer(args, context) { const timers = getTimer(), flags = args.extOptions, { output, workDir, cliConfig } = context; if (timers.start("checkStudioDependencyVersions"), checkStudioDependencyVersions(workDir), timers.end("checkStudioDependencyVersions"), (await checkRequiredDependencies(context)).didInstall) return; const config = getDevServerConfig({ flags, workDir, cliConfig, output }); try { await startDevServer(config); } catch (err) { gracefulServerDeath("dev", config.httpHost, config.httpPort, err); } } function getDevServerConfig({ flags, workDir, cliConfig, output }) { var _a; const configSpinner = output.spinner("Checking configuration files..."), baseConfig = getSharedServerConfig({ flags, workDir, cliConfig }); configSpinner.succeed(); const env = process.env, reactStrictMode = env.SANITY_STUDIO_REACT_STRICT_MODE ? env.SANITY_STUDIO_REACT_STRICT_MODE === "true" : !!(cliConfig != null && cliConfig.reactStrictMode); return env.SANITY_STUDIO_BASEPATH && (_a = cliConfig == null ? void 0 : cliConfig.project) != null && _a.basePath && output.warn( `Overriding configured base path (${cliConfig.project.basePath}) with value from environment variable (${env.SANITY_STUDIO_BASEPATH})` ), { ...baseConfig, staticPath: path.join(workDir, "static"), reactStrictMode }; } export { startSanityDevServer as default }; //# sourceMappingURL=devAction.js.map