@sanity/plugin-kit

7.0.28.0.0
dist/init-v15fyisU.js
+dist/init-v15fyisU.jsNew file
+99
Index: package/dist/init-v15fyisU.js
===================================================================
--- package/dist/init-v15fyisU.js
+++ package/dist/init-v15fyisU.js
@@ -0,0 +1,99 @@
+import { t as cliName } from "./constants-BLTUL_Wd.js";
+import { t as log_default } from "./log-DgQL-Rv9.js";
+import { i as presetHelpList, n as initFlags, t as init } from "./init-BDY7XRmJ.js";
+import { F as isEmptyish, N as ensureDir, V as prompt, d as hasSanityJson, u as findStudioV3Config } from "./package-BrKrShA_.js";
+import meow from "meow";
+import path from "path";
+import execa from "execa";
+function npmIsAvailable() {
+	return execa("npm", ["-v"]).then(() => !0).catch(() => !1);
+}
+function yarnIsAvailable() {
+	return execa("yarn", ["-v"]).then(() => !0).catch(() => !1);
+}
+function pnpmAvailable() {
+	return execa("pnpm", ["-v"]).then(() => !0).catch(() => !1);
+}
+async function promptForPackageManager() {
+	let [npm, yarn, pnpm] = await Promise.all([
+		npmIsAvailable(),
+		yarnIsAvailable(),
+		pnpmAvailable()
+	]), choices = [
+		npm && "npm",
+		yarn && "yarn",
+		pnpm && "pnpm"
+	].filter(Boolean);
+	return choices.length < 2 ? choices[0] || "npm" : prompt("Which package manager do you prefer?", {
+		choices: choices.map((value) => ({
+			value,
+			name: value
+		})),
+		default: choices[0]
+	});
+}
+async function installDependencies(pm, { cwd }) {
+	let { exitCode } = await execa(pm, ["install"], {
+		cwd,
+		stdio: "inherit"
+	});
+	return exitCode <= 0;
+}
+const help = `
+Usage
+  $ ${cliName} init [dir] [<args>]
+
+Options
+  --no-oxlint             Disables oxlint config and dependencies from being added
+  --no-oxfmt              Disables oxfmt config and dependencies from being added
+  --no-typescript         Disables typescript config and dependencies from being added
+  --no-license            Disables LICENSE + package.json license field from being added
+  --no-editorconfig       Disables .editorconfig from being added
+  --no-gitignore          Disables .gitignore from being added
+  --no-scripts            Disables scripts from being added to package.json
+  --no-install            Disables automatically running package manager install
+
+  --name [package-name]   Use the provided package-name
+  --author [name]         Use the provided author
+  --repo [url]            Use the provided repo url
+  --license [spdx]        Use the license with the given SPDX identifier
+  --force                 No prompt when overwriting files
+
+  --preset [preset-name]  Adds config and files from a named preset. --preset can be supplied multiple times.
+                          The following presets are available:
+${presetHelpList(30)}
+
+Examples
+  # Initialize a new plugin in the current directory
+  $ ${cliName} init
+
+  # Initialize a plugin in the directory ~/my-plugin
+  $ ${cliName} init ~/my-plugin
+
+  # Don't add oxlint or oxfmt
+  $ ${cliName} init --no-oxlint --no-oxfmt
+`;
+async function run({ argv }) {
+	let cli = meow(help, {
+		flags: initFlags,
+		argv,
+		description: "Initialize a new Sanity plugin"
+	}), basePath = path.resolve(cli.input[0] || process.cwd()), { exists, isRoot } = await hasSanityJson(basePath);
+	if (exists && isRoot) throw Error("sanity.json has a \"root\" property set to true - are you trying to init into a studio instead of a plugin?");
+	let { v3ConfigFile } = await findStudioV3Config(basePath);
+	if (v3ConfigFile) throw Error(`${v3ConfigFile} exists - are you trying to init into a studio instead of a plugin?`);
+	if (log_default.info("Initializing new plugin in \"%s\"", basePath), !cli.flags.force && !await isEmptyish(basePath) && !await prompt("Directory is not empty, proceed?", {
+		type: "confirm",
+		default: !1
+	})) {
+		log_default.error("Directory is not empty. Cancelled.");
+		return;
+	}
+	await ensureDir(basePath), await init({
+		basePath,
+		flags: cli.flags
+	}), cli.flags.install ? await installDependencies(await promptForPackageManager(), { cwd: basePath }) ? log_default.info("Done!") : log_default.error("Failed to install dependencies, try manually running `npm install`") : log_default.info("Dependency installation skipped.");
+}
+export { run as default };
+
+//# sourceMappingURL=init-v15fyisU.js.map
\ No newline at end of file