Skip to content

Commit

Permalink
add minify option to deploy
Browse files Browse the repository at this point in the history
  • Loading branch information
treblereel authored and Dmitrii Tikhomirov committed Nov 1, 2024
1 parent 2d0b903 commit 2ce72fd
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 7 deletions.
6 changes: 6 additions & 0 deletions packages/kn-plugin-workflow/pkg/command/deploy.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,11 @@ func NewDeployCommand() *cobra.Command {
cmd.Flags().StringP("specs-dir", "p", "", "Specify a custom specs files directory")
cmd.Flags().StringP("subflows-dir", "s", "", "Specify a custom subflows files directory")
cmd.Flags().StringP("schemas-dir", "t", "", "Specify a custom schemas files directory")
cmd.Flags().BoolP("minify", "f", true, "Minify the OpenAPI specs files before deploying")

if err := viper.BindPFlag("minify", cmd.Flags().Lookup("minify")); err != nil {
fmt.Println("❌ ERROR: failed to bind minify flag")
}

cmd.SetHelpFunc(common.DefaultTemplatedHelp)

Expand Down Expand Up @@ -159,6 +164,7 @@ func runDeployCmdConfig(cmd *cobra.Command) (cfg DeployUndeployCmdConfig, err er
SpecsDir: viper.GetString("specs-dir"),
SchemasDir: viper.GetString("schemas-dir"),
SubflowsDir: viper.GetString("subflows-dir"),
Minify: viper.GetBool("minify"),
}

if len(cfg.SubflowsDir) == 0 {
Expand Down
27 changes: 20 additions & 7 deletions packages/kn-plugin-workflow/pkg/command/deploy_undeploy_common.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ type DeployUndeployCmdConfig struct {
SpecsFilesPath map[string]string
SubFlowsFilesPath []string
DashboardsPath []string
Minify bool
}

func checkEnvironment(cfg *DeployUndeployCmdConfig) error {
Expand Down Expand Up @@ -123,14 +124,26 @@ func generateManifests(cfg *DeployUndeployCmdConfig) error {
supportFileExtensions := []string{metadata.JSONExtension, metadata.YAMLExtension, metadata.YMLExtension}

fmt.Println("πŸ” Looking for specs files...")
minifiedfiles, err := specs.NewMinifier(&specs.OpenApiMinifierOpts{
SpecsDir: cfg.SpecsDir,
SubflowsDir: cfg.SubflowsDir,
}).Minify()
if err != nil {
return fmt.Errorf("❌ ERROR: failed to minify specs files: %w", err)
if cfg.Minify {
minifiedfiles, err := specs.NewMinifier(&specs.OpenApiMinifierOpts{
SpecsDir: cfg.SpecsDir,
SubflowsDir: cfg.SubflowsDir,
}).Minify()
if err != nil {
return fmt.Errorf("❌ ERROR: failed to minify specs files: %w", err)
}
cfg.SpecsFilesPath = minifiedfiles
} else {
files, err = common.FindFilesWithExtensions(cfg.SpecsDir, supportFileExtensions)
if err != nil {
return fmt.Errorf("❌ ERROR: failed to get supportFiles directory: %w", err)
}
cfg.SpecsFilesPath = map[string]string{}
for _, file := range files {
cfg.SpecsFilesPath[file] = file
fmt.Printf(" - βœ… Specs file found: %s\n", file)
}
}
cfg.SpecsFilesPath = minifiedfiles

fmt.Println("πŸ” Looking for schema files...")
files, err = common.FindFilesWithExtensions(cfg.SchemasDir, supportFileExtensions)
Expand Down

0 comments on commit 2ce72fd

Please sign in to comment.