Skip to content

chore: add icons.json file #10085

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Oct 6, 2023
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ site/e2e/test-results/*
site/e2e/states/*.json
site/e2e/.auth.json
site/playwright-report/*
site/static/icons.json
site/.swc

# Make target for updating golden files (any dir).
Expand Down
1 change: 1 addition & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ site/e2e/test-results/*
site/e2e/states/*.json
site/e2e/.auth.json
site/playwright-report/*
site/static/icons.json
site/.swc

# Make target for updating golden files (any dir).
Expand Down
7 changes: 6 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -472,6 +472,7 @@ gen: \
site/.prettierignore \
site/.eslintignore \
site/e2e/provisionerGenerated.ts \
site/static/icons.json \
examples/examples.gen.json
.PHONY: gen

Expand All @@ -495,6 +496,7 @@ gen/mark-fresh:
site/.prettierignore \
site/.eslintignore \
site/e2e/provisionerGenerated.ts \
site/static/icons.json \
examples/examples.gen.json \
"
for file in $$files; do
Expand Down Expand Up @@ -538,7 +540,7 @@ provisionerd/proto/provisionerd.pb.go: provisionerd/proto/provisionerd.proto
./provisionerd/proto/provisionerd.proto

site/src/api/typesGenerated.ts: scripts/apitypings/main.go $(shell find ./codersdk $(FIND_EXCLUSIONS) -type f -name '*.go')
go run scripts/apitypings/main.go > site/src/api/typesGenerated.ts
go run ./scripts/apitypings/ > site/src/api/typesGenerated.ts
cd site
pnpm run format:types ./src/api/typesGenerated.ts

Expand All @@ -547,6 +549,9 @@ site/e2e/provisionerGenerated.ts: provisionerd/proto/provisionerd.pb.go provisio
../scripts/pnpm_install.sh
pnpm run gen:provisioner

site/static/icons.json: $(wildcard site/static/icon/*)
go run ./scripts/sitestatic/

examples/examples.gen.json: scripts/examplegen/main.go examples/examples.go $(shell find ./examples/templates)
go run ./scripts/examplegen/main.go > examples/examples.gen.json

Expand Down
54 changes: 54 additions & 0 deletions scripts/sitestatic/generateIconList.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
package main

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

func generateIconList() int {
files, err := os.ReadDir("site/static/icon")
if err != nil {
_, _ = fmt.Println("failed to read icon/ directory")
_, _ = fmt.Println("err:", err.Error())
return 71 // OSERR
}

icons := make([]string, len(files))
i := 0
for _, file := range files {
if !file.Type().IsRegular() {
continue
}

icons[i] = file.Name()
i++
}
icons = icons[:i]

outputFile, err := os.Create("./site/static/icons.json")
if err != nil {
_, _ = fmt.Println("failed to create file")
_, _ = fmt.Println("err:", err.Error())
return 73 // CANTCREAT
}
defer outputFile.Close()

iconsJSON, err := json.Marshal(icons)
if err != nil {
_, _ = fmt.Println("failed to serialize JSON")
_, _ = fmt.Println("err:", err.Error())
return 70 // SOFTWARE
}

written, err := outputFile.Write(iconsJSON)
if err != nil || written != len(iconsJSON) {
_, _ = fmt.Println("failed to write JSON")
if err != nil {
_, _ = fmt.Println("err:", err.Error())
}
return 74 // IOERR
}

return 0
}
8 changes: 8 additions & 0 deletions scripts/sitestatic/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package main

import "os"

func main() {
status := generateIconList()
os.Exit(status)
}
1 change: 1 addition & 0 deletions site/.eslintignore
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ e2e/test-results/*
e2e/states/*.json
e2e/.auth.json
playwright-report/*
static/icons.json
.swc

# Make target for updating golden files (any dir).
Expand Down
1 change: 1 addition & 0 deletions site/.prettierignore
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ e2e/test-results/*
e2e/states/*.json
e2e/.auth.json
playwright-report/*
static/icons.json
.swc

# Make target for updating golden files (any dir).
Expand Down