sv 0.12.7 → 0.12.8

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/bin.mjs CHANGED
@@ -1,6 +1,6 @@
1
1
  #!/usr/bin/env node
2
2
  import { f as program, l as from, r as detectPackageManager, u as Command } from "./package-manager-BYzDyeam.mjs";
3
- import { a as helpConfig, i as forwardExitCode, n as add, o as name, r as create, s as version } from "./engine-v9g2eGJ2.mjs";
3
+ import { a as helpConfig, i as forwardExitCode, n as add, o as name, r as create, s as version } from "./engine-DUNH7ELq.mjs";
4
4
  import { color, resolveCommand } from "@sveltejs/sv-utils";
5
5
  import process from "node:process";
6
6
  import { execSync } from "node:child_process";
@@ -60,6 +60,7 @@ async function runMigrate(cwd$1, args) {
60
60
  console.log();
61
61
  program.name(name).version(version, "-v, --version").configureHelp(helpConfig);
62
62
  program.addCommand(create).addCommand(add).addCommand(migrate).addCommand(check);
63
+ if (process.argv.includes("--help") || process.argv.includes("-h")) program.addHelpText("after", () => "\n" + create.helpInformation());
63
64
  program.parse();
64
65
 
65
66
  //#endregion
@@ -2742,7 +2742,7 @@ function getAddonDetails(id) {
2742
2742
  //#endregion
2743
2743
  //#region package.json
2744
2744
  var name = "sv";
2745
- var version = "0.12.7";
2745
+ var version = "0.12.8";
2746
2746
 
2747
2747
  //#endregion
2748
2748
  //#region src/core/errors.ts
@@ -2796,8 +2796,57 @@ function formatDescription(arg) {
2796
2796
  if (arg.argChoices !== void 0 && String(arg.argChoices)) output += color.dim(` (choices: ${arg.argChoices.join(", ")})`);
2797
2797
  return output;
2798
2798
  }
2799
+ /**
2800
+ * Returns standard help sections and a formatItem helper.
2801
+ * Used by `add` and `create` custom `formatHelp` to avoid duplicating boilerplate.
2802
+ */
2803
+ function getHelpSections(cmd, helper) {
2804
+ const termWidth = helper.padWidth(cmd, helper);
2805
+ const helpWidth = helper.helpWidth ?? 80;
2806
+ function formatItem(term, description$1) {
2807
+ return helper.formatItem(term, termWidth, description$1, helper);
2808
+ }
2809
+ const usage = [`${helper.styleTitle("Usage:")} ${helper.styleUsage(helper.commandUsage(cmd))}`, ""];
2810
+ const descText = helper.commandDescription(cmd);
2811
+ const description = descText.length > 0 ? [helper.boxWrap(helper.styleCommandDescription(descText), helpWidth), ""] : [];
2812
+ const argItems = helper.visibleArguments(cmd).map((argument) => formatItem(helper.styleArgumentTerm(helper.argumentTerm(argument)), helper.styleArgumentDescription(helper.argumentDescription(argument))));
2813
+ const arguments_ = argItems.length > 0 ? [
2814
+ helper.styleTitle("Arguments:"),
2815
+ ...argItems,
2816
+ ""
2817
+ ] : [];
2818
+ const optItems = helper.visibleOptions(cmd).map((option) => formatItem(helper.styleOptionTerm(helper.optionTerm(option)), helper.styleOptionDescription(helper.optionDescription(option))));
2819
+ const options$8 = optItems.length > 0 ? [
2820
+ helper.styleTitle("Options:"),
2821
+ ...optItems,
2822
+ ""
2823
+ ] : [];
2824
+ const globalOptItems = helper.showGlobalOptions ? helper.visibleGlobalOptions(cmd).map((option) => formatItem(helper.styleOptionTerm(helper.optionTerm(option)), helper.styleOptionDescription(helper.optionDescription(option)))) : [];
2825
+ const globalOptions = globalOptItems.length > 0 ? [
2826
+ helper.styleTitle("Global Options:"),
2827
+ ...globalOptItems,
2828
+ ""
2829
+ ] : [];
2830
+ const cmdItems = helper.visibleCommands(cmd).map((sub) => formatItem(helper.styleSubcommandTerm(helper.subcommandTerm(sub)), helper.styleSubcommandDescription(helper.subcommandDescription(sub))));
2831
+ const commands = cmdItems.length > 0 ? [
2832
+ helper.styleTitle("Commands:"),
2833
+ ...cmdItems,
2834
+ ""
2835
+ ] : [];
2836
+ return {
2837
+ formatItem,
2838
+ styleTitle: helper.styleTitle.bind(helper),
2839
+ usage,
2840
+ description,
2841
+ arguments: arguments_,
2842
+ options: options$8,
2843
+ globalOptions,
2844
+ commands
2845
+ };
2846
+ }
2799
2847
  async function runCommand(action) {
2800
2848
  try {
2849
+ console.log(color.hidden("HINT: Run \"sv --help\" to get the full list of commands, add-ons, and examples to one-shot and skip interactive prompts."));
2801
2850
  Nt(`Welcome to the Svelte CLI! ${color.optional(`(v${version})`)}`);
2802
2851
  const minimumVersion = "18.3.0";
2803
2852
  if (isVersionUnsupportedBelow(process$1.versions.node, minimumVersion)) R.warn(`You are using Node.js ${color.error(process$1.versions.node)}, please upgrade to Node.js ${color.success(minimumVersion)} or higher.`);
@@ -5918,7 +5967,7 @@ const templateChoices = templates.map((t) => t.name);
5918
5967
  const langOption = new Option("--types <lang>", "add type checking").choices(langs);
5919
5968
  const templateOption = new Option("--template <type>", "template to scaffold").choices(templateChoices);
5920
5969
  const noAddonsOption = new Option("--no-add-ons", "do not prompt to add add-ons").conflicts("add");
5921
- const addOption = new Option("--add <addon...>", "add-on to include").default([]);
5970
+ const addOption = new Option("--add <addon...>", "add-ons to include (see Add-Ons section below)").default([]);
5922
5971
  const noDownloadCheckOption = new Option("--no-download-check", "skip all download confirmation prompts");
5923
5972
  const noInstallOption = new Option("--no-install", "skip installing dependencies");
5924
5973
  const ProjectPathSchema = optional(string());
@@ -5932,7 +5981,32 @@ const OptionsSchema$1 = strictObject({
5932
5981
  dirCheck: boolean(),
5933
5982
  downloadCheck: boolean()
5934
5983
  });
5935
- const create = new Command("create").description("scaffolds a new SvelteKit project").argument("[path]", "where the project will be created").addOption(templateOption).addOption(langOption).option("--no-types").addOption(noAddonsOption).addOption(addOption).addOption(noInstallOption).option("--from-playground <url>", "create a project from the svelte playground").option("--no-dir-check", "even if the folder is not empty, no prompt will be shown").addOption(noDownloadCheckOption).addOption(installOption).configureHelp(helpConfig).action((projectPath, opts) => {
5984
+ const create = new Command("create").description("Scaffold a new project (--add to include add-ons)").argument("[path]", "where the project will be created").addOption(templateOption).addOption(langOption).option("--no-types").addOption(noAddonsOption).addOption(addOption).addOption(noInstallOption).option("--from-playground <url>", "create a project from the svelte playground").option("--no-dir-check", "even if the folder is not empty, no prompt will be shown").addOption(noDownloadCheckOption).addOption(installOption).configureHelp({
5985
+ ...helpConfig,
5986
+ formatHelp(cmd, helper) {
5987
+ const s = getHelpSections(cmd, helper);
5988
+ const addonSection = formatAddonHelpSection({
5989
+ styleTitle: s.styleTitle,
5990
+ formatItem: (term, desc) => s.formatItem(helper.styleArgumentTerm(term), helper.styleArgumentDescription(desc))
5991
+ });
5992
+ return [
5993
+ ...s.usage,
5994
+ ...s.description,
5995
+ ...s.arguments,
5996
+ ...s.options,
5997
+ ...addonSection,
5998
+ s.styleTitle("Non-interactive usage:"),
5999
+ " Provide --template, --types, --add, and --install (or --no-install) to skip prompts entirely.",
6000
+ " Note: --add and --no-add-ons cannot be used together.",
6001
+ "",
6002
+ s.styleTitle("Examples:"),
6003
+ " sv create my-app --template minimal --types ts --add prettier eslint --install pnpm",
6004
+ " sv create my-app --template minimal --types ts --add prettier vitest=\"usages:unit\" tailwindcss=\"plugins:none\" --install pnpm",
6005
+ " sv create my-app --template minimal --types ts --add drizzle=\"database:postgresql+client:postgres.js\" --no-install",
6006
+ ""
6007
+ ].join("\n");
6008
+ }
6009
+ }).action((projectPath, opts) => {
5936
6010
  const cwd$1 = parse$1(ProjectPathSchema, projectPath);
5937
6011
  const options$8 = parse$1(OptionsSchema$1, opts);
5938
6012
  if (options$8.fromPlayground && !validatePlaygroundUrl(options$8.fromPlayground)) {
@@ -6270,58 +6344,25 @@ const defaultCwd = defaultPkgPath ? path.dirname(defaultPkgPath) : void 0;
6270
6344
  const add$1 = new Command("add").description("applies specified add-ons into a project").argument("[add-on...]", `add-ons to install`, (value, previous = []) => addonArgsHandler(previous, value)).option("-C, --cwd <path>", "path to working directory", defaultCwd).option("--no-git-check", "even if some files are dirty, no prompt will be shown").addOption(noDownloadCheckOption).addOption(noInstallOption).addOption(installOption).configureHelp({
6271
6345
  ...helpConfig,
6272
6346
  formatHelp(cmd, helper) {
6273
- const termWidth = helper.padWidth(cmd, helper);
6274
- const helpWidth = helper.helpWidth ?? 80;
6275
- function callFormatItem(term, description) {
6276
- return helper.formatItem(term, termWidth, description, helper);
6277
- }
6278
- let output = [`${helper.styleTitle("Usage:")} ${helper.styleUsage(helper.commandUsage(cmd))}`, ""];
6279
- const commandDescription = helper.commandDescription(cmd);
6280
- if (commandDescription.length > 0) output = output.concat([helper.boxWrap(helper.styleCommandDescription(commandDescription), helpWidth), ""]);
6281
- const argumentList = helper.visibleArguments(cmd).map((argument) => {
6282
- return callFormatItem(helper.styleArgumentTerm(helper.argumentTerm(argument)), helper.styleArgumentDescription(helper.argumentDescription(argument)));
6283
- });
6284
- if (argumentList.length > 0) output = output.concat([
6285
- helper.styleTitle("Arguments:"),
6286
- ...argumentList,
6287
- ""
6288
- ]);
6289
- const addonList = addonOptions.map((option) => {
6290
- const description = option.choices;
6291
- return callFormatItem(helper.styleArgumentTerm(option.id), helper.styleArgumentDescription(description));
6347
+ const s = getHelpSections(cmd, helper);
6348
+ const addonSection = formatAddonHelpSection({
6349
+ styleTitle: s.styleTitle,
6350
+ formatItem: (term, desc) => s.formatItem(helper.styleArgumentTerm(term), helper.styleArgumentDescription(desc))
6292
6351
  });
6293
- if (addonList.length > 0) output = output.concat([
6294
- helper.styleTitle("Add-On Options:"),
6295
- ...addonList,
6352
+ return [
6353
+ ...s.usage,
6354
+ ...s.description,
6355
+ ...s.arguments,
6356
+ ...addonSection,
6357
+ ...s.options,
6358
+ ...s.globalOptions,
6359
+ ...s.commands,
6360
+ s.styleTitle("Examples:"),
6361
+ " sv add prettier eslint",
6362
+ " sv add vitest=\"usages:unit\" tailwindcss=\"plugins:none\"",
6363
+ " sv add drizzle=\"database:postgresql+client:postgres.js+docker:yes\"",
6296
6364
  ""
6297
- ]);
6298
- const optionList = helper.visibleOptions(cmd).map((option) => {
6299
- return callFormatItem(helper.styleOptionTerm(helper.optionTerm(option)), helper.styleOptionDescription(helper.optionDescription(option)));
6300
- });
6301
- if (optionList.length > 0) output = output.concat([
6302
- helper.styleTitle("Options:"),
6303
- ...optionList,
6304
- ""
6305
- ]);
6306
- if (helper.showGlobalOptions) {
6307
- const globalOptionList = helper.visibleGlobalOptions(cmd).map((option) => {
6308
- return callFormatItem(helper.styleOptionTerm(helper.optionTerm(option)), helper.styleOptionDescription(helper.optionDescription(option)));
6309
- });
6310
- if (globalOptionList.length > 0) output = output.concat([
6311
- helper.styleTitle("Global Options:"),
6312
- ...globalOptionList,
6313
- ""
6314
- ]);
6315
- }
6316
- const commandList = helper.visibleCommands(cmd).map((cmd$1) => {
6317
- return callFormatItem(helper.styleSubcommandTerm(helper.subcommandTerm(cmd$1)), helper.styleSubcommandDescription(helper.subcommandDescription(cmd$1)));
6318
- });
6319
- if (commandList.length > 0) output = output.concat([
6320
- helper.styleTitle("Commands:"),
6321
- ...commandList,
6322
- ""
6323
- ]);
6324
- return output.join("\n");
6365
+ ].join("\n");
6325
6366
  }
6326
6367
  }).action(async (addonInputs, opts) => {
6327
6368
  if (opts.cwd === void 0) errorAndExit("Invalid workspace: Please verify that you are inside of a Svelte project. You can also specify the working directory with `--cwd <path>`");
@@ -6691,68 +6732,92 @@ function addonArgsHandler(acc, current) {
6691
6732
  }
6692
6733
  return acc;
6693
6734
  }
6735
+ function getOfficialAddonIds() {
6736
+ return officialAddons.map((a) => a.id);
6737
+ }
6694
6738
  function getAddonOptionFlags() {
6695
6739
  const options$8 = [];
6696
6740
  for (const addon of officialAddons) {
6697
6741
  const id = addon.id;
6698
6742
  const details = getAddonDetails(id);
6699
6743
  if (Object.values(details.options).length === 0) continue;
6700
- const { defaults, groups } = getOptionChoices(details);
6701
- const choices = Object.entries(groups).map(([group, choices$1]) => `${color.optional(`${group}:`)} ${color.dim(choices$1.join(", "))}`).join("\n");
6702
- const preset = defaults.join(", ") || "none";
6744
+ const { groups, groupDefaults } = getOptionChoices(details);
6745
+ const choices = Object.entries(groups).map(([group, choices$1]) => {
6746
+ const defaults = groupDefaults[group];
6747
+ const defaultStr = defaults === void 0 ? "" : defaults.length > 0 ? ` (default: ${defaults.join(", ")})` : " (default: none)";
6748
+ return `${color.optional(`${group}:`)} ${color.dim(choices$1.join(", "))}${defaultStr}`;
6749
+ }).join("\n");
6703
6750
  options$8.push({
6704
6751
  id,
6705
- choices,
6706
- preset
6752
+ choices
6707
6753
  });
6708
6754
  }
6709
6755
  return options$8;
6710
6756
  }
6757
+ /**
6758
+ * Shared addon help section used by `add --help`, `create --help`, and `sv --help`.
6759
+ * Returns formatted lines showing all addons, their options, and syntax examples.
6760
+ */
6761
+ function formatAddonHelpSection(opts) {
6762
+ const { styleTitle, formatItem } = opts;
6763
+ const output = [];
6764
+ const allIds = getOfficialAddonIds();
6765
+ const withOptionsMap = new Map(addonOptions.map((o) => [o.id, o]));
6766
+ const addonList = allIds.map((id) => {
6767
+ const option = withOptionsMap.get(id);
6768
+ if (!option) return formatItem(id, "(no options)");
6769
+ return formatItem(id, option.choices);
6770
+ });
6771
+ if (addonList.length > 0) output.push(styleTitle("Add-Ons:"), ...addonList, "");
6772
+ output.push(styleTitle("Add-On Syntax:"), " <addon> add with defaults (may still prompt)", " <addon>=<opt>:<val> set a single option", " <addon>=<opt1>:<val1>+<opt2>:<val2> set multiple options", " <addon>=<opt>:none explicitly set no value (for multiselect)", " To skip prompts, explicitly set ALL options (use defaults shown above).", "");
6773
+ return output;
6774
+ }
6711
6775
  function getOptionChoices(details) {
6712
6776
  const choices = [];
6713
- const defaults = [];
6714
6777
  const groups = {};
6778
+ const groupDefaults = {};
6715
6779
  const options$8 = {};
6716
6780
  for (const [id, question] of Object.entries(details.options)) {
6717
6781
  let values = [];
6718
6782
  const applyDefault = question.condition?.(options$8) !== false;
6783
+ const groupId = question.group ?? id;
6784
+ groupDefaults[groupId] ??= [];
6719
6785
  if (question.type === "boolean") {
6720
6786
  values = ["yes", `no`];
6721
6787
  if (applyDefault) {
6722
6788
  options$8[id] = question.default;
6723
- defaults.push(question.default ? values[0] : values[1]);
6789
+ groupDefaults[groupId].push(question.default ? values[0] : values[1]);
6724
6790
  }
6725
6791
  }
6726
6792
  if (question.type === "select") {
6727
6793
  values = question.options.map((o) => o.value);
6728
6794
  if (applyDefault) {
6729
6795
  options$8[id] = question.default;
6730
- defaults.push(question.default);
6796
+ groupDefaults[groupId].push(question.default);
6731
6797
  }
6732
6798
  }
6733
6799
  if (question.type === "multiselect") {
6734
6800
  values = question.options.map((o) => o.value);
6735
6801
  if (applyDefault) {
6736
6802
  options$8[id] = question.default;
6737
- defaults.push(...question.default);
6803
+ groupDefaults[groupId].push(...question.default);
6738
6804
  }
6739
6805
  }
6740
6806
  if (question.type === "string" || question.type === "number") {
6741
6807
  values = ["<user-input>"];
6742
6808
  if (applyDefault && question.default !== void 0) {
6743
6809
  options$8[id] = question.default;
6744
- defaults.push(question.default.toString());
6810
+ groupDefaults[groupId].push(question.default.toString());
6745
6811
  }
6746
6812
  }
6747
6813
  choices.push(...values);
6748
- const groupId = question.group ?? id;
6749
6814
  groups[groupId] ??= [];
6750
6815
  groups[groupId].push(...values);
6751
6816
  }
6752
6817
  return {
6753
6818
  choices,
6754
- defaults,
6755
- groups
6819
+ groups,
6820
+ groupDefaults
6756
6821
  };
6757
6822
  }
6758
6823
  async function resolveNonOfficialAddons(refs, downloadCheck) {
@@ -1,4 +1,4 @@
1
1
  import { p as create } from "../package-manager-BYzDyeam.mjs";
2
- import { c as officialAddons, l as defineAddon, t as add, u as defineAddonOptions } from "../engine-v9g2eGJ2.mjs";
2
+ import { c as officialAddons, l as defineAddon, t as add, u as defineAddonOptions } from "../engine-DUNH7ELq.mjs";
3
3
 
4
4
  export { add, create, defineAddon, defineAddonOptions, officialAddons };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "sv",
3
- "version": "0.12.7",
3
+ "version": "0.12.8",
4
4
  "type": "module",
5
5
  "description": "A command line interface (CLI) for creating and maintaining Svelte applications",
6
6
  "license": "MIT",
@@ -25,7 +25,7 @@
25
25
  }
26
26
  },
27
27
  "dependencies": {
28
- "@sveltejs/sv-utils": "0.0.2"
28
+ "@sveltejs/sv-utils": "0.0.3"
29
29
  },
30
30
  "devDependencies": {
31
31
  "@clack/prompts": "1.0.0",