diff --git a/cmd/project/create.go b/cmd/project/create.go index db397b9f..41013566 100644 --- a/cmd/project/create.go +++ b/cmd/project/create.go @@ -20,7 +20,6 @@ import ( "path/filepath" "strings" - "github.com/slackapi/slack-cli/internal/experiment" "github.com/slackapi/slack-cli/internal/logger" "github.com/slackapi/slack-cli/internal/pkg/create" "github.com/slackapi/slack-cli/internal/shared" @@ -193,9 +192,8 @@ func printCreateSuccess(ctx context.Context, clients *shared.ClientFactory, appP isDenoProject = strings.Contains(strings.ToLower(clients.Runtime.Name()), "deno") } - // Display the original next steps section when the Bolt Experiment is OFF - // or when the Bolt Experiment is ON and a Deno SDK project is created - if !clients.Config.WithExperimentOn(experiment.BoltFrameworks) || isDenoProject { + // Include documentation and information about ROSI for deno apps + if isDenoProject { clients.IO.PrintInfo(ctx, false, style.Sectionf(style.TextSection{ Emoji: "compass", Text: "Explore the documentation to learn more", diff --git a/cmd/project/create_template.go b/cmd/project/create_template.go index f372078f..e889ea84 100644 --- a/cmd/project/create_template.go +++ b/cmd/project/create_template.go @@ -20,7 +20,6 @@ import ( "time" "github.com/slackapi/slack-cli/internal/api" - "github.com/slackapi/slack-cli/internal/experiment" "github.com/slackapi/slack-cli/internal/iostreams" "github.com/slackapi/slack-cli/internal/pkg/create" "github.com/slackapi/slack-cli/internal/shared" @@ -30,88 +29,50 @@ import ( "github.com/spf13/cobra" ) -func getSelectionPrompt(clients *shared.ClientFactory) string { - switch clients.Config.WithExperimentOn(experiment.BoltFrameworks) { - case true: - return "Select a language:" - default: - return "Select a template to build from:" - } -} - -func getSelectionPromptForCategory(clients *shared.ClientFactory) string { - return "Select an app:" -} - func getSelectionOptions(clients *shared.ClientFactory, categoryID string) []promptObject { if strings.TrimSpace(categoryID) == "" { categoryID = "slack-cli#getting-started" } - switch clients.Config.WithExperimentOn(experiment.BoltFrameworks) { - case true: - // App categories and templates - templatePromptObjects := map[string]([]promptObject){ - "slack-cli#getting-started": []promptObject{ - { - Title: fmt.Sprintf("Bolt for JavaScript %s", style.Secondary("Node.js")), - Repository: "slack-samples/bolt-js-starter-template", - }, - { - Title: fmt.Sprintf("Bolt for Python %s", style.Secondary("Python")), - Repository: "slack-samples/bolt-python-starter-template", - }, + // App categories and templates + templatePromptObjects := map[string]([]promptObject){ + "slack-cli#getting-started": []promptObject{ + { + Title: fmt.Sprintf("Bolt for JavaScript %s", style.Secondary("Node.js")), + Repository: "slack-samples/bolt-js-starter-template", }, - "slack-cli#automation-apps": { - { - Title: fmt.Sprintf("Bolt for JavaScript %s", style.Secondary("Node.js")), - Repository: "slack-samples/bolt-js-custom-function-template", - }, - { - Title: fmt.Sprintf("Bolt for Python %s", style.Secondary("Python")), - Repository: "slack-samples/bolt-python-custom-function-template", - }, - { - Title: fmt.Sprintf("Deno Slack SDK %s", style.Secondary("Deno")), - Repository: "slack-samples/deno-starter-template", - }, + { + Title: fmt.Sprintf("Bolt for Python %s", style.Secondary("Python")), + Repository: "slack-samples/bolt-python-starter-template", }, - "slack-cli#ai-apps": { - { - Title: fmt.Sprintf("Bolt for JavaScript %s", style.Secondary("Node.js")), - Repository: "slack-samples/bolt-js-assistant-template", - }, - { - Title: fmt.Sprintf("Bolt for Python %s", style.Secondary("Python")), - Repository: "slack-samples/bolt-python-assistant-template", - }, + }, + "slack-cli#automation-apps": { + { + Title: fmt.Sprintf("Bolt for JavaScript %s", style.Secondary("Node.js")), + Repository: "slack-samples/bolt-js-custom-function-template", }, - } - - return templatePromptObjects[categoryID] - default: - return []promptObject{ { - Title: "Issue submission (default sample)", - Repository: "slack-samples/deno-issue-submission", - Description: "Basic app that demonstrates an issue submission workflow", + Title: fmt.Sprintf("Bolt for Python %s", style.Secondary("Python")), + Repository: "slack-samples/bolt-python-custom-function-template", }, { - Title: "Scaffolded template", - Repository: "slack-samples/deno-starter-template", - Description: "Solid foundation that includes a Slack datastore", + Title: fmt.Sprintf("Deno Slack SDK %s", style.Secondary("Deno")), + Repository: "slack-samples/deno-starter-template", }, + }, + "slack-cli#ai-apps": { { - Title: "Blank template", - Repository: "slack-samples/deno-blank-template", - Description: "A, well.. blank project", + Title: fmt.Sprintf("Bolt for JavaScript %s", style.Secondary("Node.js")), + Repository: "slack-samples/bolt-js-assistant-template", }, { - Title: "View more samples", - Repository: viewMoreSamples, + Title: fmt.Sprintf("Bolt for Python %s", style.Secondary("Python")), + Repository: "slack-samples/bolt-python-assistant-template", }, - } + }, } + + return templatePromptObjects[categoryID] } func getSelectionOptionsForCategory(clients *shared.ClientFactory) []promptObject { @@ -142,34 +103,32 @@ func promptTemplateSelection(cmd *cobra.Command, clients *shared.ClientFactory) var selectedTemplate string // Prompt for the category - if clients.Config.WithExperimentOn(experiment.BoltFrameworks) { - promptForCategory := getSelectionPromptForCategory(clients) - optionsForCategory := getSelectionOptionsForCategory(clients) - titlesForCategory := make([]string, len(optionsForCategory)) - for i, m := range optionsForCategory { - titlesForCategory[i] = m.Title - } - templateForCategory := getSelectionTemplate(clients) + promptForCategory := "Select an app:" + optionsForCategory := getSelectionOptionsForCategory(clients) + titlesForCategory := make([]string, len(optionsForCategory)) + for i, m := range optionsForCategory { + titlesForCategory[i] = m.Title + } + templateForCategory := getSelectionTemplate(clients) - // Print a trace with info about the category title options provided by CLI - clients.IO.PrintTrace(ctx, slacktrace.CreateCategoryOptions, strings.Join(titlesForCategory, ", ")) + // Print a trace with info about the category title options provided by CLI + clients.IO.PrintTrace(ctx, slacktrace.CreateCategoryOptions, strings.Join(titlesForCategory, ", ")) - // Prompt to choose a category - selection, err := clients.IO.SelectPrompt(ctx, promptForCategory, titlesForCategory, iostreams.SelectPromptConfig{ - Description: func(value string, index int) string { - return optionsForCategory[index].Description - }, - Flag: clients.Config.Flags.Lookup("template"), - Required: true, - Template: templateForCategory, - }) - if err != nil { - return create.Template{}, slackerror.ToSlackError(err) - } else if selection.Flag { - selectedTemplate = selection.Option - } else if selection.Prompt { - categoryID = optionsForCategory[selection.Index].Repository - } + // Prompt to choose a category + selection, err := clients.IO.SelectPrompt(ctx, promptForCategory, titlesForCategory, iostreams.SelectPromptConfig{ + Description: func(value string, index int) string { + return optionsForCategory[index].Description + }, + Flag: clients.Config.Flags.Lookup("template"), + Required: true, + Template: templateForCategory, + }) + if err != nil { + return create.Template{}, slackerror.ToSlackError(err) + } else if selection.Flag { + selectedTemplate = selection.Option + } else if selection.Prompt { + categoryID = optionsForCategory[selection.Index].Repository } // Set template to view more samples, so the sample prompt is triggered @@ -179,7 +138,7 @@ func promptTemplateSelection(cmd *cobra.Command, clients *shared.ClientFactory) // Prompt for the template if selectedTemplate == "" { - prompt := getSelectionPrompt(clients) + prompt := "Select a language:" options := getSelectionOptions(clients, categoryID) titles := make([]string, len(options)) for i, m := range options { @@ -276,9 +235,7 @@ func confirmExternalTemplateSelection(cmd *cobra.Command, clients *shared.Client // project template during creation func getSelectionTemplate(clients *shared.ClientFactory) string { samplesURL := style.LinkText("https://docs.slack.dev/samples") - switch clients.Config.WithExperimentOn(experiment.BoltFrameworks) { - case true: - return fmt.Sprintf(` + return fmt.Sprintf(` {{- define "option"}} {{- if eq .SelectedIndex .CurrentIndex }}{{color .Config.Icons.SelectFocus.Format }}{{ .Config.Icons.SelectFocus.Text }} {{else}}{{color "default+hb"}} {{end}} {{- .CurrentOpt.Value}}{{color "reset"}}{{ if ne ($.GetDescription .CurrentOpt) "" }}{{"\n "}}{{color "250"}}{{ $.GetDescription .CurrentOpt }}{{"\n"}}{{end}} @@ -297,27 +254,5 @@ func getSelectionTemplate(clients *shared.ClientFactory) string { {{- "Guided tutorials can be found at %s"}}{{color "reset"}} {{end}} `, - samplesURL) - default: - return fmt.Sprintf(` -{{- define "option"}} -{{- if eq .SelectedIndex .CurrentIndex }}{{color .Config.Icons.SelectFocus.Format }}{{ .Config.Icons.SelectFocus.Text }} {{else}}{{color "default+hb"}} {{end}} -{{- .CurrentOpt.Value}}{{color "reset"}}{{ if ne ($.GetDescription .CurrentOpt) "" }}{{"\n "}}{{color "250"}}{{ $.GetDescription .CurrentOpt }}{{"\n"}}{{end}} -{{- color "reset"}} -{{end}} -{{- if .ShowHelp }}{{- color .Config.Icons.Help.Format }}{{ .Config.Icons.Help.Text }} {{ .Help }}{{color "reset"}}{{"\n"}}{{end}} -{{- color .Config.Icons.Question.Format }}{{ .Config.Icons.Question.Text }} {{color "reset"}} -{{- color "default+hb"}}{{ .Message }}{{color "reset"}} -{{- if .ShowAnswer}}{{color "39+b"}} {{.Answer}}{{color "reset"}} -{{- else}} - {{- " "}}{{- color "39+b"}}[Use arrows to move]{{color "reset"}} - {{- "\n\n"}} - {{- range $ix, $option := .PageEntries}} - {{- template "option" $.IterateOption $ix $option}} - {{- end}} - {{"Guided tutorials can be found at %s"}}{{color "reset"}} -{{end}} -`, - samplesURL) - } + samplesURL) } diff --git a/cmd/project/create_test.go b/cmd/project/create_test.go index d49879f0..726cb961 100644 --- a/cmd/project/create_test.go +++ b/cmd/project/create_test.go @@ -23,9 +23,9 @@ import ( "github.com/slackapi/slack-cli/internal/logger" "github.com/slackapi/slack-cli/internal/pkg/create" "github.com/slackapi/slack-cli/internal/shared" - "github.com/slackapi/slack-cli/internal/slackcontext" "github.com/slackapi/slack-cli/internal/slackerror" "github.com/slackapi/slack-cli/test/testutil" + "github.com/spf13/cobra" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/mock" "github.com/stretchr/testify/require" @@ -41,43 +41,75 @@ func (m *CreateClientMock) Create(ctx context.Context, clients *shared.ClientFac } func TestCreateCommand(t *testing.T) { - // Create mocks - ctx := slackcontext.MockContext(t.Context()) - clientsMock := shared.NewClientsMock() - clientsMock.AddDefaultMocks() - - // Create clients that is mocked for testing - clients := shared.NewClientFactory(clientsMock.MockClientFactory()) - - // Create the command - cmd := NewCreateCommand(clients) - testutil.MockCmdIO(clients.IO, cmd) - - createClientMock := new(CreateClientMock) - - createClientMock.On("Create", mock.Anything, mock.Anything, mock.Anything, mock.Anything).Return("", nil) - clientsMock.IO.On("SelectPrompt", mock.Anything, "Select a template to build from:", mock.Anything, mock.Anything). - Return( - iostreams.SelectPromptResponse{ - Option: "slack-samples/deno-starter-template", - Flag: true, + var createClientMock *CreateClientMock + + testutil.TableTestCommand(t, testutil.CommandTests{ + "creates a bolt application from prompts": { + Setup: func(t *testing.T, ctx context.Context, cm *shared.ClientsMock, cf *shared.ClientFactory) { + cm.IO.On("SelectPrompt", mock.Anything, "Select an app:", mock.Anything, mock.Anything). + Return( + iostreams.SelectPromptResponse{ + Prompt: true, + Index: 0, + }, + nil, + ) + cm.IO.On("SelectPrompt", mock.Anything, "Select a language:", mock.Anything, mock.Anything). + Return( + iostreams.SelectPromptResponse{ + Prompt: true, + Index: 0, + }, + nil, + ) + createClientMock = new(CreateClientMock) + createClientMock.On("Create", mock.Anything, mock.Anything, mock.Anything, mock.Anything).Return("", nil) + CreateFunc = createClientMock.Create }, - nil, - ) - - CreateFunc = createClientMock.Create - - err := cmd.ExecuteContext(ctx) - if err != nil { - assert.Fail(t, "cmd.Execute had unexpected error") - } - - template, err := create.ResolveTemplateURL("slack-samples/deno-starter-template") - require.NoError(t, err) - expected := create.CreateArgs{ - Template: template, - } - createClientMock.AssertCalled(t, "Create", mock.Anything, mock.Anything, mock.Anything, expected) + ExpectedAsserts: func(t *testing.T, ctx context.Context, cm *shared.ClientsMock) { + template, err := create.ResolveTemplateURL("slack-samples/bolt-js-starter-template") + require.NoError(t, err) + expected := create.CreateArgs{ + Template: template, + } + createClientMock.AssertCalled(t, "Create", mock.Anything, mock.Anything, mock.Anything, expected) + }, + }, + "creates a deno application from flags": { + CmdArgs: []string{"--template", "slack-samples/deno-starter-template"}, + Setup: func(t *testing.T, ctx context.Context, cm *shared.ClientsMock, cf *shared.ClientFactory) { + cm.IO.On("SelectPrompt", mock.Anything, "Select an app:", mock.Anything, mock.Anything). + Return( + iostreams.SelectPromptResponse{ + Flag: true, + Option: "slack-samples/deno-starter-template", + }, + nil, + ) + cm.IO.On("SelectPrompt", mock.Anything, "Select a language:", mock.Anything, mock.Anything). + Return( + iostreams.SelectPromptResponse{ + Flag: true, + Option: "slack-samples/deno-starter-template", + }, + nil, + ) + createClientMock = new(CreateClientMock) + createClientMock.On("Create", mock.Anything, mock.Anything, mock.Anything, mock.Anything).Return("", nil) + CreateFunc = createClientMock.Create + }, + ExpectedAsserts: func(t *testing.T, ctx context.Context, cm *shared.ClientsMock) { + template, err := create.ResolveTemplateURL("slack-samples/deno-starter-template") + require.NoError(t, err) + expected := create.CreateArgs{ + Template: template, + } + createClientMock.AssertCalled(t, "Create", mock.Anything, mock.Anything, mock.Anything, expected) + }, + }, + }, func(cf *shared.ClientFactory) *cobra.Command { + return NewCreateCommand(cf) + }) } func TestCreateCommand_confirmExternalTemplateSelection(t *testing.T) { @@ -234,55 +266,3 @@ func TestCreateCommand_confirmExternalTemplateSelection(t *testing.T) { }) } } - -func Test_CreateCommand_BoltExperiment(t *testing.T) { - // Create mocks - ctx := slackcontext.MockContext(t.Context()) - clientsMock := shared.NewClientsMock() - clientsMock.AddDefaultMocks() - - // Create clients that is mocked for testing - clients := shared.NewClientFactory(clientsMock.MockClientFactory()) - - // Set experiment flag - clientsMock.Config.ExperimentsFlag = append(clientsMock.Config.ExperimentsFlag, "bolt") - clientsMock.Config.LoadExperiments(ctx, clientsMock.IO.PrintDebug) - - // Create the command - cmd := NewCreateCommand(clients) - testutil.MockCmdIO(clients.IO, cmd) - - createClientMock := new(CreateClientMock) - - createClientMock.On("Create", mock.Anything, mock.Anything, mock.Anything, mock.Anything).Return("", nil) - clientsMock.IO.On("SelectPrompt", mock.Anything, "Select an app:", mock.Anything, mock.Anything). - Return( - iostreams.SelectPromptResponse{ - Prompt: true, - Index: 0, - }, - nil, - ) - clientsMock.IO.On("SelectPrompt", mock.Anything, "Select a language:", mock.Anything, mock.Anything). - Return( - iostreams.SelectPromptResponse{ - Prompt: true, - Index: 0, - }, - nil, - ) - - CreateFunc = createClientMock.Create - - err := cmd.ExecuteContext(ctx) - if err != nil { - assert.Fail(t, "cmd.Execute had unexpected error") - } - - template, err := create.ResolveTemplateURL("slack-samples/bolt-js-starter-template") - require.NoError(t, err) - expected := create.CreateArgs{ - Template: template, - } - createClientMock.AssertCalled(t, "Create", mock.Anything, mock.Anything, mock.Anything, expected) -} diff --git a/cmd/project/init.go b/cmd/project/init.go index a3817c76..ac24565f 100644 --- a/cmd/project/init.go +++ b/cmd/project/init.go @@ -21,7 +21,6 @@ import ( "github.com/slackapi/slack-cli/cmd/app" "github.com/slackapi/slack-cli/internal/config" - "github.com/slackapi/slack-cli/internal/experiment" "github.com/slackapi/slack-cli/internal/pkg/create" "github.com/slackapi/slack-cli/internal/shared" "github.com/slackapi/slack-cli/internal/shared/types" @@ -82,12 +81,6 @@ func NewInitCommand(clients *shared.ClientFactory) *cobra.Command { // projectInitCommandPreRunE determines if the command is supported for a project // and configures flags func projectInitCommandPreRunE(clients *shared.ClientFactory, cmd *cobra.Command, args []string) error { - // Require the Bolt Framework experiment to run this command - if !clients.Config.WithExperimentOn(experiment.BoltFrameworks) { - return slackerror.New("Command requires the Bolt Framework experiment"). - WithRemediation(`Run the command with the experiment flag "-e %s"`, experiment.BoltFrameworks) - } - clients.Config.SetFlags(cmd) return nil } diff --git a/cmd/project/init_test.go b/cmd/project/init_test.go index 4fcea41c..f2bdc51f 100644 --- a/cmd/project/init_test.go +++ b/cmd/project/init_test.go @@ -53,18 +53,10 @@ var mockLinkSlackAuth2 = types.SlackAuth{ func Test_Project_InitCommand(t *testing.T) { testutil.TableTestCommand(t, testutil.CommandTests{ - "requires bolt experiment": { - CmdArgs: []string{}, - Setup: func(t *testing.T, ctx context.Context, cm *shared.ClientsMock, cf *shared.ClientFactory) { - // Do not set experiment flag - setupProjectInitCommandMocks(t, ctx, cm, cf, false) - }, - ExpectedErrorStrings: []string{"Command requires the Bolt Framework experiment"}, - }, "init a project and do not link an existing app": { CmdArgs: []string{}, Setup: func(t *testing.T, ctx context.Context, cm *shared.ClientsMock, cf *shared.ClientFactory) { - setupProjectInitCommandMocks(t, ctx, cm, cf, true) + setupProjectInitCommandMocks(t, ctx, cm, cf) // Do not link an existing app cm.IO.On("ConfirmPrompt", mock.Anything, app.LinkAppConfirmPromptText, mock.Anything).Return(false, nil) }, @@ -115,7 +107,7 @@ func Test_Project_InitCommand(t *testing.T) { mockLinkSlackAuth1, }, nil) // Default setup - setupProjectInitCommandMocks(t, ctx, cm, cf, true) + setupProjectInitCommandMocks(t, ctx, cm, cf) // Do not link an existing app cm.IO.On("ConfirmPrompt", mock.Anything, app.LinkAppConfirmPromptText, mock.Anything).Return(true, nil) // Mock prompt to link an existing app @@ -222,18 +214,12 @@ func Test_Project_InitCommand(t *testing.T) { } // setupProjectInitCommandMocks prepares common mocks for these tests -func setupProjectInitCommandMocks(t *testing.T, ctx context.Context, cm *shared.ClientsMock, cf *shared.ClientFactory, boltExperimentEnabled bool) { +func setupProjectInitCommandMocks(t *testing.T, ctx context.Context, cm *shared.ClientsMock, cf *shared.ClientFactory) { // Mocks projectDirPath := "/path/to/project-name" cm.Os.On("Getwd").Return(projectDirPath, nil) cm.AddDefaultMocks() - // Set experiment flag - if boltExperimentEnabled { - cm.Config.ExperimentsFlag = append(cm.Config.ExperimentsFlag, "bolt") - cm.Config.LoadExperiments(ctx, cm.IO.PrintDebug) - } - // Create project directory if err := cm.Fs.MkdirAll(filepath.Dir(projectDirPath), 0755); err != nil { require.FailNow(t, fmt.Sprintf("Failed to create the directory %s in the memory-based file system", projectDirPath)) diff --git a/cmd/project/samples_test.go b/cmd/project/samples_test.go index 9682c6e7..8207cf4c 100644 --- a/cmd/project/samples_test.go +++ b/cmd/project/samples_test.go @@ -63,7 +63,7 @@ func TestSamplesCommand(t *testing.T) { }, nil, ) - cm.IO.On("SelectPrompt", mock.Anything, "Select a template to build from:", mock.Anything, mock.Anything). + cm.IO.On("SelectPrompt", mock.Anything, "Select an app:", mock.Anything, mock.Anything). Return( iostreams.SelectPromptResponse{ Option: "slack-samples/deno-starter-template", diff --git a/internal/pkg/create/create.go b/internal/pkg/create/create.go index ffb36dc2..617bba04 100644 --- a/internal/pkg/create/create.go +++ b/internal/pkg/create/create.go @@ -393,56 +393,50 @@ func InstallProjectDependencies( } // Create .slack/.gitignore file - if clients.Config.WithExperimentOn(experiment.BoltFrameworks) { - gitignoreFilePath, err := config.CreateProjectConfigDirDotGitIgnoreFile(clients.Fs, projectDirPath) - dotSlackDirPathRel, _ := filepath.Rel(filepath.Dir(projectDirPath), gitignoreFilePath) - dotSlackDirPathRelStyled := style.Highlight(dotSlackDirPathRel) - - switch { - case os.IsExist(err): - outputs = append(outputs, fmt.Sprintf("Found %s", dotSlackDirPathRelStyled)) - case err != nil: - outputs = append(outputs, fmt.Sprintf("Error adding the file %s: %s", dotSlackDirPathRel, err)) - default: - outputs = append(outputs, fmt.Sprintf("Added %s", dotSlackDirPathRelStyled)) - } + gitignoreFilePath, err := config.CreateProjectConfigDirDotGitIgnoreFile(clients.Fs, projectDirPath) + gitignoreFilePathRel, _ := filepath.Rel(filepath.Dir(projectDirPath), gitignoreFilePath) + gitignoreFilePathRelStyled := style.Highlight(gitignoreFilePathRel) + + switch { + case os.IsExist(err): + outputs = append(outputs, fmt.Sprintf("Found %s", gitignoreFilePathRelStyled)) + case err != nil: + outputs = append(outputs, fmt.Sprintf("Error adding the file %s: %s", gitignoreFilePathRel, err)) + default: + outputs = append(outputs, fmt.Sprintf("Added %s", gitignoreFilePathRelStyled)) } // Create .slack/config.json file - if clients.Config.WithExperimentOn(experiment.BoltFrameworks) { - configJSONFilePath, err := config.CreateProjectConfigJSONFile(clients.Fs, projectDirPath) - configJSONFilePathRel, _ := filepath.Rel(filepath.Dir(projectDirPath), configJSONFilePath) - configJSONFilePathRelStyled := style.Highlight(configJSONFilePathRel) - - switch { - case os.IsExist(err): - outputs = append(outputs, fmt.Sprintf("Found %s", configJSONFilePathRelStyled)) - case err != nil: - outputs = append(outputs, fmt.Sprintf("Error adding the file %s: %s", configJSONFilePathRel, err)) - default: - outputs = append(outputs, fmt.Sprintf("Added %s", configJSONFilePathRelStyled)) - } + configJSONFilePath, err := config.CreateProjectConfigJSONFile(clients.Fs, projectDirPath) + configJSONFilePathRel, _ := filepath.Rel(filepath.Dir(projectDirPath), configJSONFilePath) + configJSONFilePathRelStyled := style.Highlight(configJSONFilePathRel) + + switch { + case os.IsExist(err): + outputs = append(outputs, fmt.Sprintf("Found %s", configJSONFilePathRelStyled)) + case err != nil: + outputs = append(outputs, fmt.Sprintf("Error adding the file %s: %s", configJSONFilePathRel, err)) + default: + outputs = append(outputs, fmt.Sprintf("Added %s", configJSONFilePathRelStyled)) } // Create .slack/hooks.json file - if clients.Config.WithExperimentOn(experiment.BoltFrameworks) { - var hooksJSONTemplate = []byte("{}") - if clients.Runtime != nil { - hooksJSONTemplate = clients.Runtime.HooksJSONTemplate() - } + var hooksJSONTemplate = []byte("{}") + if clients.Runtime != nil { + hooksJSONTemplate = clients.Runtime.HooksJSONTemplate() + } - hooksJSONFilePath, err := config.CreateProjectHooksJSONFile(clients.Fs, projectDirPath, hooksJSONTemplate) - hooksJSONFilePathRel, _ := filepath.Rel(filepath.Dir(projectDirPath), hooksJSONFilePath) - hooksJSONFilePathRelStyled := style.Highlight(hooksJSONFilePathRel) - - switch { - case os.IsExist(err): - outputs = append(outputs, fmt.Sprintf("Found %s", hooksJSONFilePathRelStyled)) - case err != nil: - outputs = append(outputs, fmt.Sprintf("Error adding the file %s: %s", hooksJSONFilePathRel, err)) - default: - outputs = append(outputs, fmt.Sprintf("Added %s", hooksJSONFilePathRelStyled)) - } + hooksJSONFilePath, err := config.CreateProjectHooksJSONFile(clients.Fs, projectDirPath, hooksJSONTemplate) + hooksJSONFilePathRel, _ := filepath.Rel(filepath.Dir(projectDirPath), hooksJSONFilePath) + hooksJSONFilePathRelStyled := style.Highlight(hooksJSONFilePathRel) + + switch { + case os.IsExist(err): + outputs = append(outputs, fmt.Sprintf("Found %s", hooksJSONFilePathRelStyled)) + case err != nil: + outputs = append(outputs, fmt.Sprintf("Error adding the file %s: %s", hooksJSONFilePathRel, err)) + default: + outputs = append(outputs, fmt.Sprintf("Added %s", hooksJSONFilePathRelStyled)) } // Set "project_id" in .slack/config.json diff --git a/internal/pkg/create/create_test.go b/internal/pkg/create/create_test.go index ac67e39c..270acf6b 100644 --- a/internal/pkg/create/create_test.go +++ b/internal/pkg/create/create_test.go @@ -193,40 +193,7 @@ func Test_Create_installProjectDependencies(t *testing.T) { unexpectedOutputs []string expectedVerboseOutputs []string }{ - "When no bolt experiment and hooks.json exists, should output found .slack and caching steps": { - existingFiles: map[string]string{ - ".slack/hooks.json": "{}", // Included with the template - }, - expectedOutputs: []string{ - "Found project-name/.slack", - "Cached dependencies with deno cache import_map.json", - }, - unexpectedOutputs: []string{ - "Found project-name/.slack/hooks.json", // Behind bolt experiment - "project-name/slack.json", // DEPRECATED(semver:major): Now use hooks.json - }, - expectedVerboseOutputs: []string{ - "Detected a project using Deno", - }, - }, - "When no bolt experiment and slack.json exists, should output adding .slack and caching steps": { - existingFiles: map[string]string{ - "slack.json": "{}", // DEPRECATED(semver:major): Included with the template (deprecated path) - }, - expectedOutputs: []string{ - "Added project-name/.slack", - "Cached dependencies with deno cache import_map.json", - }, - unexpectedOutputs: []string{ - "project-name/.slack/hooks.json", // Behind bolt experiment, file doesn't exist - "project-name/slack.json", // Behind bolt experiment, file exists - }, - expectedVerboseOutputs: []string{ - "Detected a project using Deno", - }, - }, - "When bolt experiment, should output added .slack, hooks.json, .gitignore, and caching": { - experiments: []string{"bolt"}, + "Should output added .slack, hooks.json, .gitignore, and caching": { expectedOutputs: []string{ "Added project-name/.slack", "Added project-name/.slack/.gitignore", @@ -237,8 +204,7 @@ func Test_Create_installProjectDependencies(t *testing.T) { "Detected a project using Deno", }, }, - "When bolt experiment and hooks.json exists, should output found .slack and hooks.json": { - experiments: []string{"bolt"}, + "When hooks.json exists, should output found .slack and hooks.json": { existingFiles: map[string]string{ ".slack/hooks.json": "{}", }, @@ -255,8 +221,7 @@ func Test_Create_installProjectDependencies(t *testing.T) { "Detected a project using Deno", }, }, - "When bolt experiment and slack.json exists, should output added .slack": { - experiments: []string{"bolt"}, + "When slack.json exists, should output added .slack": { existingFiles: map[string]string{ "slack.json": "{}", }, @@ -270,26 +235,24 @@ func Test_Create_installProjectDependencies(t *testing.T) { }, }, "When no manifest source, default to project (local)": { - experiments: []string{"bolt"}, expectedOutputs: []string{ `Updated config.json manifest source to "project" (local)`, }, }, "When manifest source is provided, should set it": { - experiments: []string{"bolt"}, manifestSource: config.ManifestSourceRemote, expectedOutputs: []string{ `Updated config.json manifest source to "app settings" (remote)`, }, }, - "When bolt + bolt-install experiment and Deno project, should set manifest source to project (local)": { - experiments: []string{"bolt", "bolt-install"}, + "When bolt-install experiment and Deno project, should set manifest source to project (local)": { + experiments: []string{"bolt-install"}, expectedOutputs: []string{ `Updated config.json manifest source to "project" (local)`, }, }, - "When bolt + bolt-install experiment and non-Deno project, should set manifest source to app settings (remote)": { - experiments: []string{"bolt", "bolt-install"}, + "When bolt-install experiment and non-Deno project, should set manifest source to app settings (remote)": { + experiments: []string{"bolt-install"}, runtime: "node", expectedOutputs: []string{ `Updated config.json manifest source to "app settings" (remote)`,