task runner

This commit is contained in:
maddalax 2024-09-13 14:54:19 -05:00
parent 4130d7fab5
commit b0ff36d34e
14 changed files with 229 additions and 3607 deletions

View file

@ -12,5 +12,6 @@
<option name="myCustomValuesEnabled" value="true" />
</inspection_tool>
<inspection_tool class="XmlUnboundNsPrefix" enabled="true" level="INFORMATION" enabled_by_default="true" />
<inspection_tool class="YAMLSchemaValidation" enabled="true" level="INFORMATION" enabled_by_default="true" />
</profile>
</component>

View file

@ -1,23 +0,0 @@
version: '3'
interval: 500ms
tasks:
ast:
dir: '{{.USER_WORKING_DIR}}'
desc: Generate AST from source code
generates:
- '**/generated.go'
cmds:
- go run github.com/maddalax/mhtml/framework/tooling/astgen
ast-watch:
dir: '{{.USER_WORKING_DIR}}'
desc: Generate AST from source code and watch for changes
watch: true
generates:
- '**/generated.go'
sources:
- '**/*.go'
cmds:
- go run github.com/maddalax/mhtml/framework/tooling/astgen

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View file

@ -2,14 +2,14 @@ import { defineConfig } from "tsup";
export default defineConfig({
format: ["esm"],
entry: ["mhtml.ts", "./scripts/*.ts"],
entry: ["mhtml.ts"],
outDir: "./../dist",
dts: false,
shims: true,
skipNodeModulesBundle: true,
clean: false,
target: "esnext",
treeshake: false,
treeshake: true,
platform: "browser",
outExtension: () => {
return {
@ -18,6 +18,7 @@ export default defineConfig({
},
minify: false,
bundle: true,
splitting: true,
// https://github.com/egoist/tsup/issues/619
noExternal: [/(.*)/],
});

View file

@ -0,0 +1,8 @@
// Package pages THIS FILE IS GENERATED. DO NOT EDIT.
package pages
import "github.com/gofiber/fiber/v2"
import "github.com/maddalax/mhtml/framework/h"
func RegisterPages(f *fiber.App) {
}

View file

@ -344,6 +344,7 @@ func GetModuleName() string {
}
func main() {
fmt.Println("Generating partials...")
writePartialsFile()
writePagesFile()
}

View file

@ -1,48 +0,0 @@
package main
import (
"fmt"
"golang.org/x/mod/modfile"
"log"
"os"
)
func getModuleVersion(modulePath string) (string, error) {
// Read the go.mod file
data, err := os.ReadFile("go.mod")
if err != nil {
return "", fmt.Errorf("error reading go.mod: %v", err)
}
// Parse the go.mod file
modFile, err := modfile.Parse("go.mod", data, nil)
if err != nil {
return "", fmt.Errorf("error parsing go.mod: %v", err)
}
// Find the module version
for _, req := range modFile.Require {
if req.Mod.Path == modulePath {
return req.Mod.Version, nil
}
}
return "", fmt.Errorf("module %s not found in go.mod", modulePath)
}
func main() {
modulePath := "github.com/maddalax/mhtml/framework"
version, err := getModuleVersion(modulePath)
if err != nil {
log.Fatalf("Error: %v", err)
}
dirname, err := os.UserHomeDir()
if err != nil {
log.Fatal(err)
}
assetDir := fmt.Sprintf("%s/go/pkg/mod/%s@%s/assets", dirname, modulePath, version)
files, _ := os.ReadDir(assetDir)
for _, file := range files {
fmt.Println(file.Name())
}
}

View file

@ -0,0 +1,112 @@
package main
import (
"fmt"
"golang.org/x/mod/modfile"
"io"
"log"
"os"
"path/filepath"
)
func getModuleVersion(modulePath string) (string, error) {
// Read the go.mod file
data, err := os.ReadFile("go.mod")
if err != nil {
return "", fmt.Errorf("error reading go.mod: %v", err)
}
// Parse the go.mod file
modFile, err := modfile.Parse("go.mod", data, nil)
if err != nil {
return "", fmt.Errorf("error parsing go.mod: %v", err)
}
// Find the module version
for _, req := range modFile.Require {
if req.Mod.Path == modulePath {
return req.Mod.Version, nil
}
}
return "", fmt.Errorf("module %s not found in go.mod", modulePath)
}
func copyFile(src, dst string) error {
// Open the source file for reading.
srcFile, err := os.Open(src)
if err != nil {
return fmt.Errorf("failed to open source file: %v", err)
}
defer srcFile.Close()
// Create the destination file.
dstFile, err := os.Create(dst)
if err != nil {
return fmt.Errorf("failed to create destination file: %v", err)
}
defer dstFile.Close()
// Copy the content from srcFile to dstFile.
_, err = io.Copy(dstFile, srcFile)
if err != nil {
return fmt.Errorf("failed to copy file contents: %v", err)
}
return nil
}
// copyDir copies a directory recursively from src to dst.
func copyDir(srcDir, dstDir string) error {
// Walk the source directory tree.
return filepath.Walk(srcDir, func(srcPath string, info os.FileInfo, err error) error {
if err != nil {
return err
}
// Construct the corresponding destination path.
relPath, err := filepath.Rel(srcDir, srcPath)
if err != nil {
return err
}
dstPath := filepath.Join(dstDir, relPath)
if info.IsDir() {
// If it's a directory, create the corresponding directory in the destination.
err := os.MkdirAll(dstPath, 0700)
if err != nil {
return fmt.Errorf("failed to create directory: %v", err)
}
} else {
// If it's a file, copy the file.
err := copyFile(srcPath, dstPath)
if err != nil {
return err
}
}
return nil
})
}
func main() {
modulePath := "github.com/maddalax/mhtml/framework"
version, err := getModuleVersion(modulePath)
if err != nil {
log.Fatalf("Error: %v", err)
}
dirname, err := os.UserHomeDir()
if err != nil {
log.Fatal(err)
}
assetDir := fmt.Sprintf("%s/go/pkg/mod/%s@%s/assets/dist", dirname, modulePath, version)
cwd, err := os.Getwd()
if err != nil {
log.Fatal("failed to get cwd")
}
destDir := fmt.Sprintf("%s/assets/dist", cwd)
err = copyDir(assetDir, destDir)
if err != nil {
log.Fatal(err.Error())
}
fmt.Printf("successfully copied assets to %s\n", destDir)
}

View file

@ -0,0 +1,57 @@
version: '3'
interval: 500ms
tasks:
setup:
deps: [copy-framework-assets, ast]
dir: '{{.USER_WORKING_DIR}}'
desc: Setup the project
cmds:
- go mod download
- go mod tidy
run:
dir: '{{.USER_WORKING_DIR}}'
desc: Run the project
cmds:
- task: setup
dir: '{{.USER_WORKING_DIR}}'
- go run .
build:
deps: [setup]
dir: '{{.USER_WORKING_DIR}}'
desc: Build the project
cmds:
- rm -rf ./dist
- mkdir -p ./dist/assets
- cp -r ./assets ./dist/assets
- go build -o "./dist" .
- echo "Build successful"
copy-framework-assets:
dir: '{{.USER_WORKING_DIR}}'
desc: Copy framework assets
cmds:
- go run github.com/maddalax/mhtml/framework/tooling/copyassets
ast:
dir: '{{.USER_WORKING_DIR}}'
desc: Generate AST from source code
generates:
- '**/generated.go'
cmds:
- go run github.com/maddalax/mhtml/framework/tooling/astgen
ast-watch:
dir: '{{.USER_WORKING_DIR}}'
desc: Generate AST from source code and watch for changes
watch: true
generates:
- '**/generated.go'
sources:
- '**/*.go'
cmds:
- go run github.com/maddalax/mhtml/framework/tooling/astgen

View file

@ -0,0 +1,46 @@
package main
import (
_ "embed"
"flag"
"fmt"
"os"
"os/exec"
)
//go:embed Taskfile.yml
var taskFile string
func main() {
taskFlag := flag.String("task", "", "Specify the task to run (e.g., build, clean, deploy)")
// Parse the command-line flags
flag.Parse()
temp, err := os.CreateTemp("", "Taskfile.yml")
if err != nil {
fmt.Printf("Error creating temporary file: %v\n", err)
return
}
os.WriteFile(temp.Name(), []byte(taskFile), 0644)
if *taskFlag == "" {
fmt.Println("Please specify a task to run using the -task flag")
return
}
// Define the command and arguments
cmd := exec.Command("task", "-t", temp.Name(), *taskFlag)
// Set the standard output and error to be the same as the Go program
cmd.Stdout = os.Stdout
cmd.Stderr = os.Stderr
// Run the command
err = cmd.Run()
if err != nil {
fmt.Printf("Error running task command: %v\n", err)
return
}
fmt.Println("Task executed successfully!")
}

View file

@ -5,7 +5,7 @@ go 1.23.0
require (
github.com/gofiber/fiber/v2 v2.52.5
github.com/google/uuid v1.6.0
github.com/maddalax/mhtml/framework v0.0.0-20240913182902-723438a677ae
github.com/maddalax/mhtml/framework v0.0.0-20240913185752-4130d7fab5eb
github.com/maddalax/mhtml/framework-ui v0.0.0-20240913172832-ad335247426d
github.com/redis/go-redis/v9 v9.6.1
)