diff --git a/core/app.go b/core/app.go index b454b4e..2dd31c0 100644 --- a/core/app.go +++ b/core/app.go @@ -70,9 +70,10 @@ func (ctx *App) InitAuthor() error { func (ctx *App) UpdateAuthorMetadata(author *models.AuthorFileProps) error { config := GetConfig() - rcFile := filepath.Join(config.HomeDir, ".sublime/rc.json") - _, err := os.ReadFile(rcFile) - if err != nil { + + sublimeDir := filepath.Join(config.HomeDir, ".sublime") + rcFile := filepath.Join(sublimeDir, "rc.json") + if _, err := os.Stat(rcFile); os.IsNotExist(err) { utils.WarningOut(utils.MessageErrorAuthorFileMissing) } @@ -81,7 +82,13 @@ func (ctx *App) UpdateAuthorMetadata(author *models.AuthorFileProps) error { return errors.New(utils.MessageErrorIndentFile) } - err = os.WriteFile(filepath.Join(config.HomeDir, ".sublime/rc.json"), data, 0644) + if _, err := os.Stat(sublimeDir); os.IsNotExist(err) { + if err := os.Mkdir(sublimeDir, 0755); err != nil { + return errors.New(utils.MessageErrorCommandRegisterHomeDir) + } + } + + err = os.WriteFile(rcFile, data, 0644) if err != nil { return errors.New(utils.MessageErrorWriteFile) } diff --git a/utils/constants.go b/utils/constants.go index 340ee23..215f8b0 100644 --- a/utils/constants.go +++ b/utils/constants.go @@ -122,7 +122,7 @@ const ( MessageCommandRootShort string = "CLI tool to manage monorepo packages." MessageCommandRootTokenExpire string = "Your token is expired. Start renew action." - MessageErrorAuthorFileMissing string = "Author file not found. Please register first then login to cloud service." + MessageErrorAuthorFileMissing string = "Author file not found. Please register first or login to cloud service." MessageErrorParseFile string = "Unable to parse file." MessageErrorIndentFile string = "Unable to indent file." MessageErrorWriteFile string = "Unable to write file"