Skip to content

Commit

Permalink
Add app detection package (#2647)
Browse files Browse the repository at this point in the history
Add `appdetect`, a package that detects application projects on the filesystem by scanning files and applying heuristics. This involves only static analysis of files. 

This will be used to analyze emitted metadata about the projects to feed `azure.yaml` and infra generation.

Closes #2615
  • Loading branch information
weikanglim authored Aug 28, 2023
1 parent e2fbcfe commit 91f74f0
Show file tree
Hide file tree
Showing 26 changed files with 1,271 additions and 0 deletions.
1 change: 1 addition & 0 deletions .vscode/cspell-github-user-aliases.txt
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,5 @@ pbnj
sethvargo
stretchr
theckman
bmatcuk
tonybaloney
10 changes: 10 additions & 0 deletions cli/azd/.vscode/cspell-azd-dictionary.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,13 @@ alphafeatures
apimanagement
apims
appconfiguration
appdetect
appinsights
appinsightsexporter
appinsightsstorage
appplatform
appservice
arget
armapimanagement
armappconfiguration
armappplatform
Expand Down Expand Up @@ -58,6 +60,7 @@ devel
discarder
docf
dockerproject
doublestar
dskip
eastus
endregion
Expand All @@ -81,6 +84,7 @@ hotspot
iidfile
ineffassign
javac
jquery
jmes
keychain
LASTEXITCODE
Expand All @@ -92,6 +96,8 @@ microsoftonline
mockarmresources
mockazcli
mvnw
mysqldb
mysqlclient
nobanner
nodeapp
nolint
Expand All @@ -110,8 +116,10 @@ otlptracehttp
pflag
preinit
proxying
psycopg
pulumi
pyapp
pyproject
pyvenv
reauthentication
relogin
Expand All @@ -126,6 +134,7 @@ servicebus
setenvs
snapshotter
springapp
sqlserver
sstore
staticcheck
staticwebapp
Expand All @@ -147,6 +156,7 @@ unmarshalling
unsetenvs
unsets
utsname
vuejs
westus2
wireinject
yacspin
Expand Down
1 change: 1 addition & 0 deletions cli/azd/appdetect/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
appdetect
55 changes: 55 additions & 0 deletions cli/azd/appdetect/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
package main

import (
"encoding/json"
"flag"
"fmt"
"os"

"github.com/azure/azure-dev/cli/azd/internal/appdetect"
)

var directory string
var projectDirectory string

func init() {
flag.StringVar(&directory, "dir", "", "Directory containing projects to detect")
flag.StringVar(&projectDirectory, "proj", "", "Specific project directory to detect")
}

func main() {
flag.Parse()

if directory == "" && projectDirectory == "" {
fmt.Println("must set one of 'proj', or 'dir'")
os.Exit(1)
}

var projects []appdetect.Project
var err error

if directory != "" {
projects, err = appdetect.Detect(directory)
}

if projectDirectory != "" {
var project *appdetect.Project
project, err = appdetect.DetectDirectory(projectDirectory)

if err == nil && project != nil {
projects = append(projects, *project)
}
}

if err != nil {
fmt.Println(err)
os.Exit(1)
}

fmt.Println("Projects detected:")
content, err := json.Marshal(projects)
if err != nil {
panic(err)
}
fmt.Printf("%v\n", string(content))
}
Loading

0 comments on commit 91f74f0

Please sign in to comment.