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
98 lines (97 loc) • 3.75 kB
JavaScript
;
var path = require("node:path"), zlib = require("node:zlib"), tar = require("tar-fs"), shouldAutoUpdate = require("./shouldAutoUpdate.js"), helpers = require("./helpers.js"), buildAction = require("./buildAction.js");
function _interopDefaultCompat(e) {
return e && typeof e == "object" && "default" in e ? e : { default: e };
}
var path__default = /* @__PURE__ */ _interopDefaultCompat(path), zlib__default = /* @__PURE__ */ _interopDefaultCompat(zlib), tar__default = /* @__PURE__ */ _interopDefaultCompat(tar);
async function deployAppAction(args, context) {
const {
apiClient,
workDir,
chalk,
output,
prompt,
cliConfig
} = context, flags = {
build: !0,
...args.extOptions
}, customSourceDir = args.argsWithoutOptions[0], sourceDir = path__default.default.resolve(process.cwd(), customSourceDir || path__default.default.join(workDir, "dist")), isAutoUpdating = shouldAutoUpdate.shouldAutoUpdate({
flags,
cliConfig
}), installedSanityVersion = await helpers.getInstalledSanityVersion(), appId = cliConfig && "app" in cliConfig && cliConfig.app?.id, client = apiClient({
requireUser: !0,
requireProject: !1
// custom apps are not project-specific
}).withConfig({
apiVersion: "v2024-08-01"
});
if (customSourceDir) {
let relativeOutput = path__default.default.relative(process.cwd(), sourceDir);
if (relativeOutput[0] !== "." && (relativeOutput = `./${relativeOutput}`), !(await helpers.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 application info").start(), userApplication;
try {
const configParams = {
client,
context,
spinner
};
appId ? userApplication = await helpers.getOrCreateUserApplicationFromConfig({
...configParams,
appId
}) : userApplication = await helpers.getOrCreateApplication(configParams);
} catch (err) {
if (err.message) {
output.error(chalk.red(err.message));
return;
}
throw helpers.debug("Error creating user application", err), err;
}
if (flags.build) {
const buildArgs = {
extOptions: flags,
argsWithoutOptions: [customSourceDir].filter(Boolean)
}, {
didCompile
} = await buildAction.default(buildArgs, context, {
basePath: "/"
});
if (!didCompile)
return;
}
spinner = output.spinner("Verifying local content").start();
try {
await helpers.checkDir(sourceDir), spinner.succeed();
} catch (err) {
throw spinner.fail(), helpers.debug("Error checking directory", err), err;
}
const parentDir = path__default.default.dirname(sourceDir), base = path__default.default.basename(sourceDir), tarball = tar__default.default.pack(parentDir, {
entries: [base]
}).pipe(zlib__default.default.createGzip());
spinner = output.spinner("Deploying...").start();
try {
await helpers.createDeployment({
client,
applicationId: userApplication.id,
version: installedSanityVersion,
isAutoUpdating,
tarball,
isApp: !0
}), spinner.succeed(), output.print(`
Success! Application deployed`), appId || (output.print(`
Add ${chalk.cyan(`id: '${userApplication.id}'`)}`), output.print("to `app` in sanity.cli.js or sanity.cli.ts"), output.print("to avoid prompting on next deploy."));
} catch (err) {
throw spinner.fail(), helpers.debug("Error deploying application", err), err;
}
}
exports.default = deployAppAction;
//# sourceMappingURL=deployAction.js.map