Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 8 additions & 4 deletions cmd/dev/headers/license.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (
"strings"
"time"

goGitIgnore "github.com/sabhiram/go-gitignore"
ignore "github.com/sabhiram/go-gitignore"
"github.com/spf13/cobra"

"github.com/ory/cli/cmd/dev/headers/comments"
Expand All @@ -30,7 +30,8 @@ var defaultExcludedFolders = []string{"dist", "node_modules", "vendor"}
// AddLicenses adds or updates the Ory license header in all applicable files within the given directory.
func AddLicenses(dir string, year int, exclude []string) error {
licenseText := fmt.Sprintf(LICENSE_TEMPLATE, year)
gitIgnore, _ := goGitIgnore.CompileIgnoreFile(filepath.Join(dir, ".gitignore"))
gitIgnore, _ := ignore.CompileIgnoreFile(filepath.Join(dir, ".gitignore"))
prettierIgnore, _ := ignore.CompileIgnoreFile(filepath.Join(dir, ".prettierignore"))
return filepath.Walk(dir, func(path string, info fs.FileInfo, err error) error {
if err != nil {
return fmt.Errorf("cannot read directory %q: %w", path, err)
Expand All @@ -41,6 +42,9 @@ func AddLicenses(dir string, year int, exclude []string) error {
if gitIgnore != nil && gitIgnore.MatchesPath(info.Name()) {
return nil
}
if prettierIgnore != nil && prettierIgnore.MatchesPath(info.Name()) {
return nil
}
if !comments.SupportsFile(path) {
return nil
}
Expand Down Expand Up @@ -79,9 +83,9 @@ func fileTypeIsLicensed(path string) bool {
var copyright = &cobra.Command{
Use: "license",
Short: "Adds the license header to all known files in the current directory",
Long: `Adds the license header to all known files in the current directory.
Long: `Adds the license header to all files that need one in the current directory.

Does not add the license header to git-ignored files.`,
Does not add the license header to files listed in .gitignore and .prettierignore.`,
RunE: func(cmd *cobra.Command, args []string) error {
year, _, _ := time.Now().Date()
return AddLicenses(".", year, exclude)
Expand Down