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

140 lines (139 loc) 4.47 kB
import path from "node:path"; import zlib from "node:zlib"; import tar from "tar-fs"; import { getAppId } from "./getAppId.js"; import { shouldAutoUpdate } from "./shouldAutoUpdate.js"; import buildSanityStudio from "./buildAction2.js"; import { deploySchemasAction } from "./deploySchemasAction.js"; import { createManifestExtractor } from "./schemaStoreOutStrings.js"; import { getInstalledSanityVersion, dirIsEmptyOrNonExistent, getOrCreateUserApplicationFromConfig, getOrCreateStudio, debug, checkDir, createDeployment } from "./helpers.js"; async function deployStudioAction(args, context) { const { apiClient, workDir, chalk, output, prompt, cliConfig } = context, flags = { build: !0, ...args.extOptions }, customSourceDir = args.argsWithoutOptions[0], sourceDir = path.resolve(process.cwd(), customSourceDir || path.join(workDir, "dist")), isAutoUpdating = shouldAutoUpdate({ flags, cliConfig, output }), installedSanityVersion = await getInstalledSanityVersion(), client = apiClient({ requireUser: !0, requireProject: !0 }).withConfig({ apiVersion: "v2024-08-01" }); if (customSourceDir === "graphql") throw new Error("Did you mean `sanity graphql deploy`?"); if (customSourceDir) { let relativeOutput = path.relative(process.cwd(), sourceDir); if (relativeOutput[0] !== "." && (relativeOutput = `./${relativeOutput}`), !(await dirIsEmptyOrNonExistent(sourceDir) || await prompt.single({ type: "confirm", message: `"${relativeOutput}" is not empty, do you want to proceed?`, default: !1 }))) { output.print("Cancelled."); return; } output.print(`Building to ${relativeOutput} `); } let spinner = output.spinner("Checking project info").start(); const appId = getAppId({ cliConfig, output }), configStudioHost = cliConfig && "studioHost" in cliConfig ? cliConfig.studioHost : void 0; let userApplication; try { appId || configStudioHost ? userApplication = await getOrCreateUserApplicationFromConfig({ client, context, spinner, ...appId ? { appId, appHost: void 0 } : { appId: void 0, appHost: configStudioHost } }) : userApplication = await getOrCreateStudio({ client, context, spinner }); } catch (err) { if (err.message) { output.error(chalk.red(err.message)); return; } throw debug("Error creating user application", err), err; } const shouldBuild = flags.build; if (shouldBuild) { const buildArgs = { ...args, extOptions: flags, argsWithoutOptions: [customSourceDir].filter(Boolean) }, { didCompile } = await buildSanityStudio(buildArgs, context, { basePath: "/" }); if (!didCompile) return; } await deploySchemasAction({ "extract-manifest": shouldBuild, "manifest-dir": `${sourceDir}/static`, "schema-required": flags["schema-required"], verbose: flags.verbose }, { ...context, manifestExtractor: createManifestExtractor(context) }), spinner = output.spinner("Verifying local content").start(); try { await checkDir(sourceDir), spinner.succeed(); } catch (err) { throw spinner.fail(), debug("Error checking directory", err), err; } const parentDir = path.dirname(sourceDir), base = path.basename(sourceDir), tarball = tar.pack(parentDir, { entries: [base] }).pipe(zlib.createGzip()); spinner = output.spinner("Deploying to sanity.studio").start(); try { const { location } = await createDeployment({ client, applicationId: userApplication.id, version: installedSanityVersion, isAutoUpdating, tarball }); if (spinner.succeed(), output.print(` Success! Studio deployed to ${chalk.cyan(location)}`), !appId) { const example = `Example: export default defineCliConfig({ //\u2026 deployment: { ${chalk.cyan`appId: '${userApplication.id}'`}, }, //\u2026 })`; output.print(` Add ${chalk.cyan(`appId: '${userApplication.id}'`)}`), output.print("to the `deployment` section in sanity.cli.js or sanity.cli.ts"), output.print("to avoid prompting for application id on next deploy."), output.print(` ${example}`); } } catch (err) { throw spinner.fail(), debug("Error deploying studio", err), err; } } export { deployStudioAction as default }; //# sourceMappingURL=deployAction2.js.map