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

60 lines (59 loc) 3.23 kB
"use strict"; var path = require("path"), chalk = require("chalk"), vite = require("vite"), runtime = require("./runtime.js"), timing = require("./timing.js"), servers = require("./servers.js"); function _interopDefaultCompat(e) { return e && typeof e == "object" && "default" in e ? e : { default: e }; } var path__default = /* @__PURE__ */ _interopDefaultCompat(path), chalk__default = /* @__PURE__ */ _interopDefaultCompat(chalk); async function startDevServer(options) { const { cwd, httpPort, httpHost, basePath, reactStrictMode, vite: extendViteConfig } = options, startTime = Date.now(); runtime.debug("Writing Sanity runtime files"), await runtime.writeSanityRuntime({ cwd, reactStrictMode, watch: !0, basePath }), runtime.debug("Resolving vite config"); const mode = "development"; let viteConfig = await runtime.getViteConfig({ basePath, mode: "development", server: { port: httpPort, host: httpHost }, cwd }); extendViteConfig && (viteConfig = await runtime.extendViteConfigWithUserConfig( { command: "serve", mode }, viteConfig, extendViteConfig )), runtime.debug("Creating vite server"); const server = await vite.createServer(viteConfig), info = server.config.logger.info; runtime.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__default.default.cyan(`vite@${require("vite/package.json").version}`)} ready in ${chalk__default.default.cyan(`${Math.ceil(startupDuration)}ms`)} and running at ${chalk__default.default.cyan(url)}` ), { close: () => server.close() }; } async function startSanityDevServer(args, context) { const timers = timing.getTimer(), flags = args.extOptions, { output, workDir, cliConfig } = context; if (timers.start("checkStudioDependencyVersions"), timing.checkStudioDependencyVersions(workDir), timers.end("checkStudioDependencyVersions"), (await timing.checkRequiredDependencies(context)).didInstall) return; const config = getDevServerConfig({ flags, workDir, cliConfig, output }); try { await startDevServer(config); } catch (err) { servers.gracefulServerDeath("dev", config.httpHost, config.httpPort, err); } } function getDevServerConfig({ flags, workDir, cliConfig, output }) { var _a; const configSpinner = output.spinner("Checking configuration files..."), baseConfig = servers.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__default.default.join(workDir, "static"), reactStrictMode }; } exports.default = startSanityDevServer; //# sourceMappingURL=devAction.js.map