AssessSetup inspects .codemap/config.json and reports whether it should be initialized or tuned before deeper Codemap analysis.
(root string)
| 222 | // AssessSetup inspects .codemap/config.json and reports whether it should be |
| 223 | // initialized or tuned before deeper Codemap analysis. |
| 224 | func AssessSetup(root string) SetupAssessment { |
| 225 | data, err := os.ReadFile(ConfigPath(root)) |
| 226 | if err != nil { |
| 227 | if os.IsNotExist(err) { |
| 228 | return SetupAssessment{ |
| 229 | State: SetupStateMissing, |
| 230 | Reasons: []string{"No .codemap/config.json is present yet."}, |
| 231 | } |
| 232 | } |
| 233 | return SetupAssessment{ |
| 234 | State: SetupStateMalformed, |
| 235 | Reasons: []string{fmt.Sprintf("Codemap could not read the config file: %v", err)}, |
| 236 | } |
| 237 | } |
| 238 | |
| 239 | if strings.TrimSpace(string(data)) == "" { |
| 240 | return SetupAssessment{ |
| 241 | State: SetupStateEmpty, |
| 242 | Reasons: []string{"The config file is blank and does not shape Codemap output yet."}, |
| 243 | } |
| 244 | } |
| 245 | |
| 246 | var cfg ProjectConfig |
| 247 | if err := json.Unmarshal(data, &cfg); err != nil { |
| 248 | return SetupAssessment{ |
| 249 | State: SetupStateMalformed, |
| 250 | Reasons: []string{"The existing .codemap/config.json is malformed JSON."}, |
| 251 | } |
| 252 | } |
| 253 | |
| 254 | if cfg.IsZero() { |
| 255 | return SetupAssessment{ |
| 256 | State: SetupStateEmpty, |
| 257 | Reasons: []string{"The config exists but does not shape Codemap output yet."}, |
| 258 | } |
| 259 | } |
| 260 | |
| 261 | if cfg.LooksBoilerplate() { |
| 262 | return SetupAssessment{ |
| 263 | State: SetupStateBoilerplate, |
| 264 | Reasons: []string{"The config only contains generic bootstrap filters and should be tuned for this repo."}, |
| 265 | } |
| 266 | } |
| 267 | |
| 268 | return SetupAssessment{State: SetupStateReady} |
| 269 | } |