Skip to content
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

fix: errors on build pkgs #5

Merged
merged 11 commits into from
Jun 10, 2022
Merged
Show file tree
Hide file tree
Changes from all 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
13 changes: 13 additions & 0 deletions .github/workflows/go.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,25 @@ jobs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
with:
fetch-depth: 0

- name: Set up Go
uses: actions/setup-go@v3
with:
go-version: 1.18

- name: Set output
id: vars
run: echo ::set-output name=tag::${GITHUB_REF#refs/*/}

- name: Check output
env:
RELEASE_VERSION: ${{ steps.vars.outputs.tag }}
run: |
echo $RELEASE_VERSION
echo ${{ steps.vars.outputs.tag }}

- name: Vendor
run: go mod vendor

Expand Down
11 changes: 10 additions & 1 deletion .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,14 @@ jobs:
goos: windows
steps:
- uses: actions/checkout@v3
with:
fetch-depth: 0

- name: Set APP_VERSION env
run: echo APP_VERSION=$(echo ${GITHUB_REF} | rev | cut -d'/' -f 1 | rev ) >> ${GITHUB_ENV}
- name: Set BUILD_TIME env
run: echo BUILD_TIME=$(date) >> ${GITHUB_ENV}

- uses: wangyoucao577/[email protected]
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
Expand All @@ -28,4 +36,5 @@ jobs:
goversion: "https://go.dev/dl/go1.18.3.linux-amd64.tar.gz"
project_path: "./"
binary_name: "sublime"
extra_files: LICENSE README.md
extra_files: LICENSE README.md
build_command: make build
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ temp/
ui-libs/
ws-libs-ui/
vendor/
out/

*~
*.sw[mnpcod]
Expand Down
18 changes: 18 additions & 0 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,24 @@
"--repo",
"websublime/ws-ui-libs",
]
},
{
"name": "Launch Create",
"type": "go",
"request": "launch",
"mode": "auto",
"program": "${workspaceFolder}",
"args": [
"--root",
"./ui-libs",
"create",
"--name",
"ui-bomb",
"--type",
"pkg",
"--template",
"lit"
]
}
]
}
16 changes: 4 additions & 12 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ YELLOW := $(shell tput -Txterm setaf 3)
WHITE := $(shell tput -Txterm setaf 7)
CYAN := $(shell tput -Txterm setaf 6)
RESET := $(shell tput -Txterm sgr0)
NOW = $(shell date +'%Y-%m-%d_%T')
VERSION = $(shell git describe --tags $(shell git rev-list --tags --max-count=1))

.PHONY: all test build vendor

Expand All @@ -18,7 +20,8 @@ all: help
## Build:
build: ## Build your project and put the output binary in out/bin/
mkdir -p out/bin
GO111MODULE=on $(GOCMD) build -mod vendor -o out/bin/$(BINARY_NAME) .
echo $(VERSION) - $(NOW)
GO111MODULE=on $(GOCMD) build -v -ldflags="-X github.com/websublime/sublime-cli/cmd.Version=${VERSION} -X github.com/websublime/sublime-cli/cmd.BuildTime=${NOW}" -mod vendor -o out/bin/$(BINARY_NAME) .

clean: ## Remove build related file
rm -fr ./bin
Expand All @@ -28,10 +31,6 @@ clean: ## Remove build related file
vendor: ## Copy of all packages needed to support builds and tests in the vendor directory
$(GOCMD) mod vendor

watch: ## Run the code with cosmtrek/air to have automatic reload on changes
$(eval PACKAGE_NAME=$(shell head -n 1 go.mod | cut -d ' ' -f2))
docker run -it --rm -w /go/src/$(PACKAGE_NAME) -v $(shell pwd):/go/src/$(PACKAGE_NAME) -p $(SERVICE_PORT):$(SERVICE_PORT) cosmtrek/air

## Test:
test: ## Run the tests of the project
ifeq ($(EXPORT_RESULT), true)
Expand All @@ -49,13 +48,6 @@ ifeq ($(EXPORT_RESULT), true)
gocov convert profile.cov | gocov-xml > coverage.xml
endif

## Lint:
lint: lint-go ## Run all available linters

lint-go: ## Use golintci-lint on your project
$(eval OUTPUT_OPTIONS = $(shell [ "${EXPORT_RESULT}" == "true" ] && echo "--out-format checkstyle ./... | tee /dev/tty > checkstyle-report.xml" || echo "" ))
docker run --rm -v $(shell pwd):/app -w /app golangci/golangci-lint:latest-alpine golangci-lint run --deadline=65s $(OUTPUT_OPTIONS)

## Help:
help: ## Show this help.
@echo ''
Expand Down
117 changes: 12 additions & 105 deletions cmd/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,118 +92,23 @@ func NewCreateCmd(cmdCreate *CreateCommand) *cobra.Command {
Use: "create",
Short: "Create libs or packages from lit, solid, vue or react",
Run: func(cmd *cobra.Command, args []string) {
if cmdCreate.Type == "lib" {
cmdCreate.Library(cmd)
}

if cmdCreate.Type == "pkg" {
cmdCreate.Package((cmd))
}

cmdCreate.CreatPackage((cmd))
cmdCreate.YarnLink()
},
}
}

func (ctx *CreateCommand) Library(cmd *cobra.Command) {
func (ctx *CreateCommand) CreatPackage(cmd *cobra.Command) {
sublime := core.GetSublime()
var libType = "libs"

libNamespace := strings.Join([]string{sublime.Scope, slug.Make(ctx.Name)}, "/")
libDirectory := filepath.Join(sublime.Root, "libs", slug.Make(ctx.Name))

var template = ""
var link = ""
for i := range ctx.Templates {
if ctx.Templates[i].Type == ctx.Template {
template = ctx.Templates[i].Type
link = ctx.Templates[i].Link
break
}
}

if link == "" {
color.Error.Println("Unable to determine template. Valid types are: lit, solid, vue or react")
cobra.CheckErr("Template error")
}

gitCmd := exec.Command("git", "clone", link, libDirectory)
_, err := gitCmd.Output()
if err != nil {
color.Error.Println("Unable to clone: ", template, " template type")
cobra.CheckErr(err)
if ctx.Type == "pkg" {
libType = "packages"
}

color.Info.Println("🛢 Template: ", template, "cloned. Initializing config files")

packageJson, _ := FileTemplates.ReadFile("templates/lib-package.json")
apiExtractorJson, _ := FileTemplates.ReadFile("templates/api-extractor-lib.json")
tsConfigJson, _ := FileTemplates.ReadFile("templates/tsconfig-lib.json")
viteConfigJson, _ := FileTemplates.ReadFile("templates/vite-config-lit.json")

pkgJsonFile, _ := os.Create(filepath.Join(libDirectory, "package.json"))
pkgJsonFile.WriteString(utils.ProcessString(string(packageJson), &utils.PackageJsonVars{
Namespace: libNamespace,
Repo: sublime.Repo,
Name: slug.Make(ctx.Name),
Scope: sublime.Scope,
}, "{{", "}}"))

color.Info.Println("❤️‍🔥 Package json created and configured!")

apiExtractorFile, _ := os.Create(filepath.Join(libDirectory, "api-extractor.json"))
apiExtractorFile.WriteString(utils.ProcessString(string(apiExtractorJson), &utils.ApiExtractorJsonVars{
Name: slug.Make(ctx.Name),
}, "{{", "}}"))

color.Info.Println("❤️‍🔥 Api extractor created and configured!")

tsConfigFile, _ := os.Create(filepath.Join(libDirectory, "tsconfig.json"))
tsConfigFile.WriteString(utils.ProcessString(string(tsConfigJson), &utils.TsConfigJsonVars{
Namespace: libNamespace,
}, "{{", "}}"))

color.Info.Println("❤️‍🔥 Tsconfig created and configured!")

viteConfigFile, _ := os.Create(filepath.Join(libDirectory, "vite.config.js"))
viteConfigFile.WriteString(utils.ProcessString(string(viteConfigJson), &utils.ViteJsonVars{
Scope: sublime.Scope,
Name: slug.Make(ctx.Name),
}, "{{", "}}"))

color.Info.Println("❤️‍🔥 Vite config created and configured!")

sublime.Packages = append(sublime.Packages, core.Packages{
Name: slug.Make(ctx.Name),
Scope: sublime.Scope,
Type: "lib",
})

data, _ := json.MarshalIndent(sublime, "", " ")

os.WriteFile(filepath.Join(sublime.Root, ".sublime.json"), data, 0644)

color.Info.Println("❤️‍🔥 Sublime json updated!")

tsConfigBase := sublime.GetTsconfig()

tsConfigBase.References = append(tsConfigBase.References, core.TsConfigReferences{
Path: filepath.Join("./libs", slug.Make(ctx.Name)),
Name: filepath.Join(sublime.Scope, slug.Make(ctx.Name)),
})

tsconfig, _ := json.MarshalIndent(tsConfigBase, "", " ")
os.WriteFile(filepath.Join(sublime.Root, "tsconfig.base.json"), tsconfig, 0644)

color.Info.Println("❤️‍🔥 Tsconfig base updated!")

os.RemoveAll(filepath.Join(libDirectory, ".git"))
}

func (ctx *CreateCommand) Package(cmd *cobra.Command) {
sublime := core.GetSublime()

libNamespace := strings.Join([]string{sublime.Scope, slug.Make(ctx.Name)}, "/")
libDirectory := filepath.Join(sublime.Root, "packages", slug.Make(ctx.Name))
libDirectory := filepath.Join(sublime.Root, libType, slug.Make(ctx.Name))
viteRel, _ := filepath.Rel(libDirectory, filepath.Join(sublime.Root, "libs/vite"))

var template = ""
var link = ""
Expand All @@ -216,7 +121,7 @@ func (ctx *CreateCommand) Package(cmd *cobra.Command) {
}

if link == "" {
color.Error.Println("Unable to determine template. Valid types are: lit, solid, vue or react")
color.Error.Println("Unable to determine template. Valid types are: lit, solid, vue, react or typescript")
cobra.CheckErr("Template error")
}

Expand All @@ -239,6 +144,7 @@ func (ctx *CreateCommand) Package(cmd *cobra.Command) {
Namespace: libNamespace,
Repo: sublime.Repo,
Name: slug.Make(ctx.Name),
Scope: sublime.Scope,
}, "{{", "}}"))

color.Info.Println("❤️‍🔥 Package json created and configured!")
Expand All @@ -253,6 +159,7 @@ func (ctx *CreateCommand) Package(cmd *cobra.Command) {
tsConfigFile, _ := os.Create(filepath.Join(libDirectory, "tsconfig.json"))
tsConfigFile.WriteString(utils.ProcessString(string(tsConfigJson), &utils.TsConfigJsonVars{
Namespace: libNamespace,
Vite: viteRel,
}, "{{", "}}"))

color.Info.Println("❤️‍🔥 Tsconfig created and configured!")
Expand All @@ -268,7 +175,7 @@ func (ctx *CreateCommand) Package(cmd *cobra.Command) {
sublime.Packages = append(sublime.Packages, core.Packages{
Name: slug.Make(ctx.Name),
Scope: sublime.Scope,
Type: "pkg",
Type: core.PackageType(ctx.Type),
})

data, _ := json.MarshalIndent(sublime, "", " ")
Expand All @@ -280,7 +187,7 @@ func (ctx *CreateCommand) Package(cmd *cobra.Command) {
tsConfigBase := sublime.GetTsconfig()

tsConfigBase.References = append(tsConfigBase.References, core.TsConfigReferences{
Path: filepath.Join("./packages", slug.Make(ctx.Name)),
Path: filepath.Join("./", libType, slug.Make(ctx.Name)),
Name: filepath.Join(sublime.Scope, slug.Make(ctx.Name)),
})

Expand Down
2 changes: 1 addition & 1 deletion cmd/templates/tsconfig-lib.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
"extends": "../../tsconfig.base.json",
"references": [
{
"path": "../vite"
"path": "{{ .Vite }}"
}
]
}
4 changes: 2 additions & 2 deletions cmd/templates/workflow-artifact.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ jobs:
STORAGE_URL: ${{ secrets.STORAGE_URL }}
STORAGE_KEY: ${{ secrets.STORAGE_KEY }}
run: |
wget https://github.com/websublime/sublime-cli/releases/download/v0.0.6/sublime-v0.0.6-linux-amd64.tar.gz
tar -xf sublime-v0.0.6-linux-amd64.tar.gz sublime
wget https://github.com/websublime/sublime-cli/releases/download/[[ .Version ]]/sublime-[[ .Version ]]-linux-amd64.tar.gz
tar -xf sublime-[[ .Version ]]-linux-amd64.tar.gz sublime
chmod +x sublime
./sublime action --kind tag --bucket "$BUCKET" --url "$STORAGE_URL" --key "$STORAGE_KEY" --env "$NODE_ENV"
4 changes: 2 additions & 2 deletions cmd/templates/workflow-feature.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ jobs:
STORAGE_URL: ${{ secrets.STORAGE_URL }}
STORAGE_KEY: ${{ secrets.STORAGE_KEY }}
run: |
wget https://github.com/websublime/sublime-cli/releases/download/v0.0.6/sublime-v0.0.6-linux-amd64.tar.gz
tar -xf sublime-v0.0.6-linux-amd64.tar.gz sublime
wget https://github.com/websublime/sublime-cli/releases/download/[[ .Version ]]/sublime-[[ .Version ]]-linux-amd64.tar.gz
tar -xf sublime-[[ .Version ]]-linux-amd64.tar.gz sublime
chmod +x sublime
./sublime action --kind branch --bucket "$BUCKET" --url "$STORAGE_URL" --key "$STORAGE_KEY" --env "$NODE_ENV"
7 changes: 6 additions & 1 deletion cmd/version.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,11 @@ import (
"github.com/spf13/cobra"
)

var (
Version string = "v0.0.1"
BuildTime string = ""
)

func init() {
rootCmd.AddCommand(versionCmd)
}
Expand All @@ -36,6 +41,6 @@ var versionCmd = &cobra.Command{
Short: "Print the version number of sublime",
Long: `All software has versions. This is Sublime's`,
Run: func(cmd *cobra.Command, args []string) {
fmt.Println("Sublime CLI v0.0.1 -- HEAD")
fmt.Println("Sublime CLI", Version)
},
}
8 changes: 6 additions & 2 deletions cmd/workspace.go
Original file line number Diff line number Diff line change
Expand Up @@ -163,12 +163,16 @@ func (ctx *WorkSpaceCommand) Workflows() {
color.Info.Println("❤️‍🔥 Github action release created!")

featureYamlFile, _ := os.Create(filepath.Join(workspaceDir, ".github/workflows/feature.yaml"))
featureYamlFile.WriteString(utils.ProcessString(string(featureYaml), &utils.EmptyVars{}, "[[", "]]"))
featureYamlFile.WriteString(utils.ProcessString(string(featureYaml), &utils.ArtifactsVars{
Version: Version,
}, "[[", "]]"))

color.Info.Println("❤️‍🔥 Github action feature created!")

artifactYamlFile, _ := os.Create(filepath.Join(workspaceDir, ".github/workflows/artifact.yaml"))
artifactYamlFile.WriteString(utils.ProcessString(string(artifactYaml), &utils.EmptyVars{}, "[[", "]]"))
artifactYamlFile.WriteString(utils.ProcessString(string(artifactYaml), &utils.ArtifactsVars{
Version: Version,
}, "[[", "]]"))

color.Info.Println("❤️‍🔥 Github action artifact created!")
}
Expand Down
12 changes: 7 additions & 5 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,15 @@ module github.com/websublime/sublime-cli

go 1.18

require (
github.com/gookit/color v1.5.0
github.com/gosimple/slug v1.12.0
github.com/spf13/cobra v1.4.0
github.com/spf13/viper v1.12.0
)

require (
github.com/fsnotify/fsnotify v1.5.4 // indirect
github.com/gookit/color v1.5.0 // indirect
github.com/gosimple/slug v1.12.0 // indirect
github.com/gosimple/unidecode v1.0.1 // indirect
github.com/hashicorp/hcl v1.0.0 // indirect
github.com/inconshreveable/mousetrap v1.0.0 // indirect
Expand All @@ -15,13 +20,10 @@ require (
github.com/pelletier/go-toml/v2 v2.0.1 // indirect
github.com/spf13/afero v1.8.2 // indirect
github.com/spf13/cast v1.5.0 // indirect
github.com/spf13/cobra v1.4.0 // indirect
github.com/spf13/jwalterweatherman v1.1.0 // indirect
github.com/spf13/pflag v1.0.5 // indirect
github.com/spf13/viper v1.12.0 // indirect
github.com/subosito/gotenv v1.3.0 // indirect
github.com/xo/terminfo v0.0.0-20210125001918-ca9a967f8778 // indirect
golang.org/x/net v0.0.0-20220520000938-2e3eb7b945c2 // indirect
golang.org/x/sys v0.0.0-20220520151302-bc2c85ada10a // indirect
golang.org/x/text v0.3.7 // indirect
gopkg.in/ini.v1 v1.66.4 // indirect
Expand Down
Loading