Skip to content

Commit

Permalink
breaking: prepare command renamed as install
Browse files Browse the repository at this point in the history
With [#4182](sveltejs/kit#4182), SvelteKit added support for a new CLI command called `sync` wrapped as `prepare` script in `package.json` file
  • Loading branch information
indaco committed Mar 7, 2022
1 parent 902574a commit 3c57136
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 1 deletion.
52 changes: 52 additions & 0 deletions cmd/install.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
/**
* Copyright © 2021 Mirco Veltri <github@mircoveltri.me>
*
* 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)
}
2 changes: 1 addition & 1 deletion cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
}
}

0 comments on commit 3c57136

Please sign in to comment.