diff --git a/cmd/install.go b/cmd/install.go new file mode 100644 index 00000000..793dee50 --- /dev/null +++ b/cmd/install.go @@ -0,0 +1,52 @@ +/** + * Copyright © 2021 Mirco Veltri + * + * Use of this source code is governed by Apache 2.0 license + * that can be found in the LICENSE file. + */ + +// Package cmd ... +package cmd + +import ( + "path/filepath" + + "github.com/spf13/cobra" + "github.com/sveltinio/sveltin/helpers" + "github.com/sveltinio/sveltin/resources" + "github.com/sveltinio/sveltin/sveltinlib/logger" + "github.com/sveltinio/sveltin/utils" +) + +//============================================================================= + +var installCmd = &cobra.Command{ + Use: "install", + Aliases: []string{"i", "init"}, + Short: "Get all the dependencies from the `package.json` file", + Long: resources.GetAsciiArt() + ` +Initialize the Sveltin project getting all dependencies from the package.json file. + +It wraps (npm|pnpm|yarn) install. +`, + Run: RunInstallCmd, +} + +// RunInstallCmd is the actual work function. +func RunInstallCmd(cmd *cobra.Command, args []string) { + listLogger := log.WithList() + listLogger.Append(logger.LevelInfo, "Getting dependencies") + listLogger.Info("Prepare Sveltin project") + + pathToPkgFile := filepath.Join(pathMaker.GetRootFolder(), "package.json") + npmClient, err := utils.RetrievePackageManagerFromPkgJson(AppFs, pathToPkgFile) + utils.ExitIfError(err) + + err = helpers.RunPMCommand(npmClient.Name, "install", "", nil, false) + utils.ExitIfError(err) + log.Success("Done") +} + +func init() { + rootCmd.AddCommand(installCmd) +} diff --git a/cmd/root.go b/cmd/root.go index c333c833..23b20c9c 100644 --- a/cmd/root.go +++ b/cmd/root.go @@ -152,6 +152,6 @@ func loadEnvFile(filename string) (config config.ProjectConfig, err error) { // GetSveltinCommands returns an array of pointers to the implemented cobra.Command func GetSveltinCommands() []*cobra.Command { return []*cobra.Command{ - newCmd, generateCmd, prepareCmd, updateCmd, serverCmd, buildCmd, previewCmd, + newCmd, generateCmd, installCmd, updateCmd, serverCmd, buildCmd, previewCmd, deployCmd, } }