Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: --nodep or similar flag for init CLI command #1196

Closed
ieedan opened this issue Jul 19, 2024 · 5 comments · Fixed by #1199
Closed

feat: --nodep or similar flag for init CLI command #1196

ieedan opened this issue Jul 19, 2024 · 5 comments · Fixed by #1199
Labels
type: feature Introduction of new functionality to the application

Comments

@ieedan
Copy link
Contributor

ieedan commented Jul 19, 2024

Describe the feature

There is already a --nodep flag on the add command which prevents adding and installing dependencies.

In some cases it would be nice to be able to not install dependencies (such as in automated tasks) but while still adding dependencies.

Ideally we could split the flag into --no-install and --no-add or something along those lines that allows users to optionally install dependencies by using the flag.

New Init:

Usage: shadcn-svelte init [options]
 
initialize your project and install dependencies
 
Options:
  -c, --cwd <cwd>            the working directory. defaults to the current directory. (default: the current directory)
  -- new --
  --no-add           disable adding dependencies (advanced) (default: false)
  --no-install       disable installing dependencies (advanced) (default: false)
  -- new --
  --style <name>             the style for the components (choices: "default", "new-york")
  --base-color <name>        the base color for the components (choices: "slate", "gray", "zinc", "neutral", "stone")
  --css <path>               path to the global CSS file
  --tailwind-config <path>   path to the tailwind config file
  --components-alias <path>  import alias for components
  --utils-alias <path>       import alias for utils
  -h, --help                 display help for command

New Add:

Usage: shadcn-svelte add [options] [components...]
 
add components to your project
 
Arguments:
  components         name of components
 
Options:
  -- new --
  --no-add           disable adding dependencies (advanced) (default: false)
  --no-install       disable installing dependencies (advanced) (default: false)
  -- new --
  -a, --all          add all components to your project. (default: false)
  -y, --yes          skip confirmation prompt. (default: false)
  -o, --overwrite    overwrite existing files. (default: false)
  --proxy            fetch components from registry using a proxy.
  -c, --cwd <cwd>    the working directory. (default: the current directory)
  -p, --path <path>  the path to add the component to.
  -h, --help         display help for command

This would require us to add dependencies in a new way something like this could work:

const addDependencies = async (
	dir: string,
	...packages: { name: string; version: string; scope: 'dev' | 'regular' }[]
) => {
	const file = path.join(dir, 'package.json');

	const packageJsonFile = JSON.parse((await fs.readFile(file)).toString());

	for (const pack of packages) {
		if (pack.scope == 'dev') {
			if (!packageJsonFile.devDependencies) {
				packageJsonFile.devDependencies = {};
			}
			packageJsonFile.devDependencies[pack.name] = pack.version;
		} else {
			if (!packageJsonFile.dependencies) {
				packageJsonFile.dependencies = {};
			}
			packageJsonFile.dependencies[pack.name] = pack.version;
		}
	}

	const newFile = JSON.stringify(packageJsonFile, null, 2);

	await fs.writeFile(file, newFile);
};

This would require us to version the dependent packages (which may be nice to do anyways)

If this is something that you'd be open to including I can of course open a PR for it!

@ieedan ieedan added the type: feature Introduction of new functionality to the application label Jul 19, 2024
@AdrianGonz97
Copy link
Collaborator

AdrianGonz97 commented Jul 20, 2024

I'm cool with adding a --nodep flag (we should probably rename it to --no-deps) to init, not so much going beyond that with an --no-install where we'll have to manually maintain the versions of the deps.

Implementing that would make sense if each version of shadcn-svelte had all of the component files embedded in it, but it doesn't. Instead, it fetches the components from our registry api and installs them from there. Perhaps in a future version that could change, but I don't think it makes much sense to do it in it's current state

@ieedan
Copy link
Contributor Author

ieedan commented Jul 20, 2024

That seems like a good compromise the only issue is that users would need to understand what dependencies each component requires since they wouldn't be added with the -nodeps flag enabled. Not sure if that would be worth adding documentation for. Maybe a (next steps) prompt or something could be useful in that case to say install this this and this.

But I also understand that's a pretty narrow use case anyways and it probably isn't too big of a deal to look through the code and find them.

@AdrianGonz97
Copy link
Collaborator

AdrianGonz97 commented Jul 20, 2024

Not sure if that would be worth adding documentation for.

It's actually in the docs and can be found under the Manual Installation section for each component

If you want to access them programmatically, you could always fetch them from this endpoint as well: https://shadcn-svelte.com/registry/index.json

@ieedan
Copy link
Contributor Author

ieedan commented Jul 20, 2024

Oops sorry I didn't know that yeah that would be perfect then we will just need to add a similar section when we add the flag for init

@ieedan
Copy link
Contributor Author

ieedan commented Jul 20, 2024

I can put together a PR for this tomorrow

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: feature Introduction of new functionality to the application
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants