Skip to content
Draft
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
3 changes: 2 additions & 1 deletion v3/UNRELEASED_CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Unreleased Changes

<!--
<!--
This file is used to collect changelog entries for the next v3-alpha release.
Add your changes under the appropriate sections below.

Expand All @@ -23,6 +23,7 @@ After processing, the content will be moved to the main changelog and this file

## Fixed
<!-- Bug fixes -->
- Fix reference to javascript bindings in templates when using -git cli option

## Deprecated
<!-- Soon-to-be removed features -->
Expand Down
6 changes: 4 additions & 2 deletions v3/internal/buildinfo/buildinfo.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"fmt"
"runtime/debug"
"slices"
"testing"

"github.com/samber/lo"
)
Expand All @@ -21,18 +22,19 @@ func Get() (*Info, error) {

// BuildInfo contains the build info for the application
var BuildInfo *debug.BuildInfo

var ok bool
BuildInfo, ok = debug.ReadBuildInfo()
if !ok {
return nil, fmt.Errorf("could not read build info from binary")
}

result.BuildSettings = lo.Associate(BuildInfo.Settings, func(setting debug.BuildSetting) (string, string) {
return setting.Key, setting.Value
})
result.Version = BuildInfo.Main.Version

result.Development = -1 != slices.IndexFunc(BuildInfo.Settings, func(setting debug.BuildSetting) bool {
return setting.Key == "vcs" && setting.Value == "git"
return testing.Testing() || setting.Key == "vcs" && setting.Value == "git"
})

return &result, nil
Expand Down
59 changes: 3 additions & 56 deletions v3/internal/commands/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,14 @@ package commands

import (
"fmt"
"github.com/go-git/go-git/v5/config"
"github.com/wailsapp/wails/v3/internal/term"
"os"
"path/filepath"
"regexp"
"strings"

"github.com/go-git/go-git/v5/config"
"github.com/wailsapp/wails/v3/internal/term"

"github.com/go-git/go-git/v5"
"github.com/pterm/pterm"
"github.com/wailsapp/wails/v3/internal/flags"
Expand All @@ -17,38 +18,6 @@ import (

var DisableFooter bool

// GitURLToModuleName converts a git URL to a Go module name by removing common prefixes
// and suffixes. It handles HTTPS, SSH, Git protocol, and filesystem URLs.
func GitURLToModuleName(gitURL string) string {
moduleName := gitURL
if strings.HasSuffix(moduleName, ".git") {
moduleName = moduleName[:len(moduleName)-4]
}
// Handle various URL schemes
for _, prefix := range []string{
"https://",
"http://",
"git://",
"ssh://",
"file://",
} {
if strings.HasPrefix(moduleName, prefix) {
moduleName = moduleName[len(prefix):]
break
}
}
// Handle SSH URLs ([email protected]:username/project.git)
if strings.HasPrefix(moduleName, "git@") {
// Remove the 'git@' prefix
moduleName = moduleName[4:]
// Replace ':' with '/' for proper module path
moduleName = strings.Replace(moduleName, ":", "/", 1)
}
// Remove leading forward slash for file system paths
moduleName = strings.TrimPrefix(moduleName, "/")
return moduleName
}

func initGitRepository(projectDir string, gitURL string) error {
// Initialize repository
repo, err := git.PlainInit(projectDir, false)
Expand All @@ -65,28 +34,6 @@ func initGitRepository(projectDir string, gitURL string) error {
return fmt.Errorf("failed to create git remote: %w", err)
}

// Update go.mod with the module name
moduleName := GitURLToModuleName(gitURL)

goModPath := filepath.Join(projectDir, "go.mod")
content, err := os.ReadFile(goModPath)
if err != nil {
return fmt.Errorf("failed to read go.mod: %w", err)
}

// Replace module name
lines := strings.Split(string(content), "\n")
if len(lines) == 0 {
return fmt.Errorf("go.mod is empty")
}
lines[0] = fmt.Sprintf("module %s", moduleName)
newContent := strings.Join(lines, "\n")

err = os.WriteFile(goModPath, []byte(newContent), 0644)
if err != nil {
return fmt.Errorf("failed to write go.mod: %w", err)
}

// Stage all files
worktree, err := repo.Worktree()
if err != nil {
Expand Down
2 changes: 1 addition & 1 deletion v3/internal/templates/_common/go.mod.tmpl
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
module changeme
module {{.GoModule}}

go 1.24

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {GreetService} from "./bindings/changeme";
import {GreetService} from "./bindings/{{.GoModule}}";
import {Events} from "@wailsio/runtime";

const resultElement = document.getElementById('result');
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import {css, html, LitElement} from 'lit'
import {customElement, property} from 'lit/decorators.js'
import {GreetService} from '../bindings/changeme';
import {GreetService} from '../bindings/{{.GoModule}}';
import {Events} from "@wailsio/runtime";

/**
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import {css, html, LitElement} from 'lit'
import {GreetService} from "../bindings/changeme";
import {GreetService} from "../bindings/{{.GoModule}}";
import {Events} from "@wailsio/runtime";

export class MyElement extends LitElement {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import {useEffect, useState} from 'preact/hooks'
import {GreetService} from "../bindings/changeme";
import {GreetService} from "../bindings/{{.GoModule}}";
import {Events} from "@wailsio/runtime";

export function App() {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { useState, useEffect } from 'preact/hooks'
import {GreetService} from "../bindings/changeme";
import {GreetService} from "../bindings/{{.GoModule}}";
import {Events} from "@wailsio/runtime";

export function App() {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { component$, useSignal, useVisibleTask$ } from '@builder.io/qwik'
import {GreetService} from "../bindings/changeme";
import {GreetService} from "../bindings/{{.GoModule}}";
import {Events, WML} from "@wailsio/runtime";

export const App = component$(() => {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { component$, useSignal, useVisibleTask$ } from '@builder.io/qwik'
import {GreetService} from "../bindings/changeme";
import {GreetService} from "../bindings/{{.GoModule}}";
import {Events, WML} from "@wailsio/runtime";

export const App = component$(() => {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { useState, useEffect } from 'react'
import {GreetService} from "../bindings/changeme";
import {GreetService} from "../bindings/{{.GoModule}}";
import {Events, WML} from "@wailsio/runtime";

function App() {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { useState, useEffect } from 'react'
import {GreetService} from "../bindings/changeme";
import {GreetService} from "../bindings/{{.GoModule}}";
import {Events, WML} from "@wailsio/runtime";

function App() {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { useState, useEffect } from 'react'
import {GreetService} from "../bindings/changeme";
import {GreetService} from "../bindings/{{.GoModule}}";
import {Events, WML} from "@wailsio/runtime";

function App() {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { useState, useEffect } from 'react'
import {GreetService} from "../bindings/changeme";
import {GreetService} from "../bindings/{{.GoModule}}";
import {Events, WML} from "@wailsio/runtime";

function App() {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { createSignal, onMount } from 'solid-js'
import {GreetService} from "../bindings/changeme";
import {GreetService} from "../bindings/{{.GoModule}}";
import {Events} from "@wailsio/runtime";

function App() {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { createSignal, onMount } from 'solid-js'
import {GreetService} from "../bindings/changeme";
import {GreetService} from "../bindings/{{.GoModule}}";
import {Events} from "@wailsio/runtime";

function App() {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<script lang="ts">
import {GreetService} from "../bindings/changeme";
import {GreetService} from "../bindings/{{.GoModule}}";
import {Events} from "@wailsio/runtime";

let name: string = '';
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<script>
import {GreetService} from "../bindings/changeme";
import {GreetService} from "../bindings/{{.GoModule}}";
import {Events} from "@wailsio/runtime";

let name = '';
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<script>
import {GreetService} from "../../bindings/changeme";
import {GreetService} from "../../bindings/{{.GoModule}}";
import {Events} from "@wailsio/runtime";

let name = '';
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<script>
import {GreetService} from "../../bindings/changeme";
import {GreetService} from "../../bindings/{{.GoModule}}";
import {Events} from "@wailsio/runtime";

let name = '';
Expand Down
39 changes: 39 additions & 0 deletions v3/internal/templates/templates.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ func GetDefaultTemplates() []TemplateData {

type TemplateOptions struct {
*flags.Init
GoModule string
LocalModulePath string
UseTypescript bool
WailsVersion string
Expand Down Expand Up @@ -258,8 +259,14 @@ func Install(options *flags.Init) error {
}
UseTypescript := strings.HasSuffix(options.TemplateName, "-ts")

gomodule := gitURLToModuleName(options.Git)
if gomodule == "" {
gomodule = options.ProjectName
}

templateData := TemplateOptions{
Init: options,
GoModule: gomodule,
LocalModulePath: localModulePath,
UseTypescript: UseTypescript,
WailsVersion: version.String(),
Expand Down Expand Up @@ -481,3 +488,35 @@ func goModTidy(projectDir string) error {
}
return nil
}

// gitURLToModuleName converts a git URL to a Go module name by removing common prefixes
// and suffixes. It handles HTTPS, SSH, Git protocol, and filesystem URLs.
func gitURLToModuleName(gitURL string) string {
moduleName := gitURL
if strings.HasSuffix(moduleName, ".git") {
moduleName = moduleName[:len(moduleName)-4]
}
// Handle various URL schemes
for _, prefix := range []string{
"https://",
"http://",
"git://",
"ssh://",
"file://",
} {
if strings.HasPrefix(moduleName, prefix) {
moduleName = moduleName[len(prefix):]
break
}
}
// Handle SSH URLs ([email protected]:username/project.git)
if strings.HasPrefix(moduleName, "git@") {
// Remove the 'git@' prefix
moduleName = moduleName[4:]
// Replace ':' with '/' for proper module path
moduleName = strings.Replace(moduleName, ":", "/", 1)
}
// Remove leading forward slash for file system paths
moduleName = strings.TrimPrefix(moduleName, "/")
return moduleName
}
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package commands
package templates

import "testing"

func Test_GitURLToModuleName(t *testing.T) {
func Test_gitURLToModuleName(t *testing.T) {
tests := []struct {
name string
gitURL string
Expand Down Expand Up @@ -106,8 +106,8 @@ func Test_GitURLToModuleName(t *testing.T) {
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
if got := GitURLToModuleName(tt.gitURL); got != tt.want {
t.Errorf("GitURLToModuleName() = %v, want %v", got, tt.want)
if got := gitURLToModuleName(tt.gitURL); got != tt.want {
t.Errorf("gitURLToModuleName() = %v, want %v", got, tt.want)
}
})
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {GreetService} from "../bindings/changeme";
import {GreetService} from "../bindings/{{.GoModule}}";
import {Events} from "@wailsio/runtime";

const greetButton = document.getElementById('greet')! as HTMLButtonElement;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {GreetService} from "./bindings/changeme";
import {GreetService} from "./bindings/{{.GoModule}}";
import {Events} from "@wailsio/runtime";

const resultElement = document.getElementById('result');
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<script setup lang="ts">
import { ref, onMounted } from 'vue'
import {GreetService} from "../../bindings/changeme";
import {GreetService} from "../../bindings/{{.GoModule}}";
import {Events} from "@wailsio/runtime";

defineProps<{ msg: string }>()
Expand Down Expand Up @@ -30,9 +30,9 @@ onMounted(() => {
</script>

<template>
<h1>{{ msg }}</h1>
<h1>{{"{{"}} msg {{"}}"}}</h1>

<div class="result">{{ result }}</div>
<div class="result">{{"{{"}} result {{"}}"}}</div>
<div class="card">
<div class="input-box">
<input class="input" v-model="name" type="text" autocomplete="off"/>
Expand All @@ -42,6 +42,6 @@ onMounted(() => {

<div class="footer">
<div><p>Click on the Wails logo to learn more</p></div>
<div><p>{{ time }}</p></div>
<div><p>{{"{{"}} time {{"}}"}}</p></div>
</div>
</template>
Loading