Compare commits
258 Commits
Port-Init
...
91-create-
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
8432f725a9 | ||
|
|
7015b80888 | ||
|
|
1ac16d1933 | ||
|
|
0f36a88f0e | ||
|
|
b30031d025 | ||
|
|
cd152f0cd7 | ||
|
|
12280b51b9 | ||
|
|
29256c5766 | ||
|
|
8b13c0b197 | ||
|
|
50e2037fba | ||
|
|
f86c10af02 | ||
|
|
00e165b139 | ||
|
|
02199bbe9d | ||
|
|
d591a55140 | ||
|
|
508295b558 | ||
|
|
bdc33e1430 | ||
|
|
d55dcb2dfb | ||
|
|
79ac4c1d45 | ||
|
|
c6bfa85a1a | ||
|
|
82289714ba | ||
|
|
77142bd99e | ||
|
|
538f5c6501 | ||
|
|
3ff02fb183 | ||
|
|
30298b4237 | ||
|
|
9f2c9a989f | ||
|
|
146147bed8 | ||
|
|
76499b20c4 | ||
|
|
b21e79daf5 | ||
|
|
71194108de | ||
|
|
11fd50f78d | ||
|
|
c08d1d7b3c | ||
|
|
2febf5a97a | ||
|
|
cea7b1e494 | ||
|
|
25962e2e53 | ||
|
|
43f9b141fe | ||
|
|
e1b729ea96 | ||
|
|
f9a18817b7 | ||
|
|
23cb97d314 | ||
|
|
32e085b609 | ||
|
|
389dee8db9 | ||
|
|
dba6fdf7e4 | ||
|
|
cc45dcf91e | ||
|
|
4aeb554f1b | ||
|
|
3d2268420b | ||
|
|
ca388be121 | ||
|
|
f9ca13ff30 | ||
|
|
319dbcdc49 | ||
|
|
bffbbd59ce | ||
|
|
8bd1d0ec92 | ||
|
|
0daec29fab | ||
|
|
bb3dbe0510 | ||
|
|
2fa9e3b0ee | ||
|
|
40d1750345 | ||
|
|
d2d4ea3033 | ||
|
|
ff55170002 | ||
|
|
444db6a560 | ||
|
|
b015f27e14 | ||
|
|
67a1f23b13 | ||
|
|
9c98a7a9e3 | ||
|
|
5aa5ad8ad3 | ||
|
|
ac203ec931 | ||
|
|
3fd73186f4 | ||
|
|
46307469e5 | ||
|
|
31a67f3aed | ||
|
|
44919d2750 | ||
|
|
cff87c641b | ||
|
|
abbd71d057 | ||
|
|
aacfe8386a | ||
|
|
97944d771a | ||
|
|
3f1b616a5e | ||
|
|
fdcc2fd2e5 | ||
|
|
855032ed1e | ||
|
|
760e109aab | ||
|
|
4c799bca8f | ||
|
|
2d08ebc054 | ||
|
|
91ab2c2b31 | ||
|
|
13ad57d49f | ||
|
|
a109e3078d | ||
|
|
2e61a3c309 | ||
|
|
0373bea4e5 | ||
|
|
2d5825d73d | ||
|
|
c4a042cb1d | ||
|
|
205f9476fa | ||
|
|
a1230fcbb6 | ||
|
|
ba5c32a4a1 | ||
|
|
58eee64326 | ||
|
|
41d786a13c | ||
|
|
a2b7906c89 | ||
|
|
eeb6fa4677 | ||
|
|
6a36d75774 | ||
|
|
6078f3c780 | ||
|
|
fc11197725 | ||
|
|
8c40b99194 | ||
|
|
de53fc6510 | ||
|
|
d4f4feb429 | ||
|
|
02973c49ff | ||
|
|
01dce9f139 | ||
|
|
6c0906e87d | ||
|
|
d7cfc4c71a | ||
|
|
fec3e7eac5 | ||
|
|
9f5e2c7dd4 | ||
|
|
c5276cca6c | ||
|
|
74dbbbed8a | ||
|
|
629ac4b93c | ||
|
|
5ece7e84b3 | ||
|
|
eaba857676 | ||
|
|
db489a3cae | ||
|
|
4821ab8597 | ||
|
|
670b769f82 | ||
|
|
eb53399824 | ||
|
|
24e4fbfb68 | ||
|
|
7f54ca4ac3 | ||
|
|
b224803e4d | ||
|
|
28b2025aaa | ||
|
|
77e85705d1 | ||
|
|
9fd24595c7 | ||
|
|
69067e85f5 | ||
|
|
c8db58e00e | ||
|
|
e96e0e0999 | ||
|
|
2da21ec528 | ||
|
|
cda0b40414 | ||
|
|
7f4229dd6b | ||
|
|
68651b77f4 | ||
|
|
bf001f5ad2 | ||
|
|
d1907b4ce5 | ||
|
|
56363d193d | ||
|
|
8553f43080 | ||
|
|
587681bb8d | ||
|
|
afbf80ea4a | ||
|
|
c180d7dccb | ||
|
|
c20aabc8f8 | ||
|
|
4cccb628c9 | ||
|
|
5d487347d4 | ||
|
|
fe8b7ac5c9 | ||
|
|
732c70777b | ||
|
|
753c5fd337 | ||
|
|
2dad29673d | ||
|
|
5e466893cf | ||
|
|
c15fd822c1 | ||
|
|
42b1c0befa | ||
|
|
6ef8744e02 | ||
|
|
cf916c8e8b | ||
|
|
cdc1d4be3e | ||
|
|
1c5284db3e | ||
|
|
073cdc3a55 | ||
|
|
fd9363e842 | ||
|
|
3051628fa2 | ||
|
|
cac97e8652 | ||
|
|
2ccabc772b | ||
|
|
ff91241592 | ||
|
|
2257b1cab1 | ||
|
|
bdcf98fc15 | ||
|
|
3025a94a77 | ||
|
|
d971495ad3 | ||
|
|
a4b1f469e9 | ||
|
|
b18f04b30d | ||
|
|
94e9447e1c | ||
|
|
03c479c890 | ||
|
|
c95a3a795e | ||
|
|
1d8e99d846 | ||
|
|
8e909fc9f4 | ||
|
|
3bc86a4f50 | ||
|
|
2c7913c202 | ||
|
|
d1c57ddb5f | ||
|
|
9ffb517183 | ||
|
|
27f852ac6a | ||
|
|
20c0b48634 | ||
|
|
6cf01b4239 | ||
|
|
3ae88f8822 | ||
|
|
5994eb605f | ||
|
|
9694dc57aa | ||
|
|
b5b78fddee | ||
|
|
c905185467 | ||
|
|
47ca7879cd | ||
|
|
6202b3bf3e | ||
|
|
ea94c2de1f | ||
|
|
eb0d4bc42f | ||
|
|
b323c3db20 | ||
|
|
1670ac6567 | ||
|
|
c941176018 | ||
|
|
a060d9dcc0 | ||
|
|
ba208dce44 | ||
|
|
9bbac46b3f | ||
|
|
d8c591e64c | ||
|
|
2c28a8f550 | ||
|
|
d6c5586159 | ||
|
|
08a7893b1d | ||
|
|
fa6cf17079 | ||
|
|
fe2a20f92a | ||
|
|
b713d57168 | ||
|
|
17ca06693e | ||
|
|
243d738d64 | ||
|
|
3f50b95f26 | ||
|
|
f0d8ce99a1 | ||
|
|
259eec97d6 | ||
|
|
8b2168abe7 | ||
|
|
a51e127309 | ||
|
|
c5cee79ff7 | ||
|
|
9393b08c3f | ||
|
|
0ca039e914 | ||
|
|
cd8b4f088f | ||
|
|
847842504b | ||
|
|
8ab91d31fe | ||
|
|
bb4d891549 | ||
|
|
4a316a76fa | ||
|
|
529e4cc07e | ||
|
|
579747d0f7 | ||
|
|
6880c53082 | ||
|
|
6e011e75c3 | ||
|
|
683ba7dc59 | ||
|
|
717e598330 | ||
|
|
a6489a1044 | ||
|
|
df911adcae | ||
|
|
d7c0b1ec58 | ||
|
|
7135d4fa27 | ||
|
|
83e063bf2b | ||
|
|
6e0773b355 | ||
|
|
60f34223b0 | ||
|
|
539be2ce84 | ||
|
|
561198b81b | ||
|
|
c823215eb6 | ||
|
|
93f890f6d9 | ||
|
|
8a3aec6866 | ||
|
|
1ef8ed73ab | ||
|
|
9004c3955e | ||
|
|
4c98ce7da1 | ||
|
|
0ae5381203 | ||
|
|
3f2f1b45f6 | ||
|
|
e6bec8f7cc | ||
|
|
f1f15fc1c5 | ||
|
|
bcca09563c | ||
|
|
ee355659ce | ||
|
|
a660e4a9da | ||
|
|
a44fd57e98 | ||
|
|
85de0bbf8a | ||
|
|
7274b6d19c | ||
|
|
c0371f141a | ||
|
|
5c96264234 | ||
|
|
a3c41d1740 | ||
|
|
7c15b780e2 | ||
|
|
fb081b4876 | ||
|
|
a28315f38b | ||
|
|
49e4f00b62 | ||
|
|
9167063976 | ||
|
|
aaa425724c | ||
|
|
ffdbb0af64 | ||
|
|
12dec650de | ||
|
|
d4b2563e9b | ||
|
|
55817b65b5 | ||
|
|
ab6e7531b4 | ||
|
|
1e4cf9b0ad | ||
|
|
13efa58c9a | ||
|
|
88b9b40bfe | ||
|
|
0011e39c55 | ||
|
|
aa6b67734b | ||
|
|
733258cc83 | ||
|
|
4742fd7ed2 | ||
|
|
96996431b4 |
42
.chglog/CHANGELOG.tpl.md
Executable file
@@ -0,0 +1,42 @@
|
||||
{{ if .Versions -}}
|
||||
<a name="unreleased"></a>
|
||||
## [Unreleased]
|
||||
|
||||
{{ if .Unreleased.CommitGroups -}}
|
||||
{{ range .Unreleased.CommitGroups -}}
|
||||
### {{ .Title }}
|
||||
{{ range .Commits -}}
|
||||
- {{ if .Scope }}**{{ .Scope }}:** {{ end }}{{ .Subject }}
|
||||
{{ end }}
|
||||
{{ end -}}
|
||||
{{ end -}}
|
||||
{{ end -}}
|
||||
|
||||
{{ range .Versions }}
|
||||
<a name="{{ .Tag.Name }}"></a>
|
||||
## {{ if .Tag.Previous }}[{{ .Tag.Name }}]{{ else }}{{ .Tag.Name }}{{ end }} - {{ datetime "2006-01-02" .Tag.Date }}
|
||||
{{ range .CommitGroups -}}
|
||||
### {{ .Title }}
|
||||
{{ range .Commits -}}
|
||||
- {{ if .Scope }}**{{ .Scope }}:** {{ end }}{{ .Subject }}
|
||||
{{ end }}
|
||||
{{ end -}}
|
||||
|
||||
{{- if .NoteGroups -}}
|
||||
{{ range .NoteGroups -}}
|
||||
### {{ .Title }}
|
||||
{{ range .Notes }}
|
||||
{{ .Body }}
|
||||
{{ end }}
|
||||
{{ end -}}
|
||||
{{ end -}}
|
||||
{{ end -}}
|
||||
|
||||
{{- if .Versions }}
|
||||
[Unreleased]: {{ .Info.RepositoryURL }}/compare/{{ $latest := index .Versions 0 }}{{ $latest.Tag.Name }}...HEAD
|
||||
{{ range .Versions -}}
|
||||
{{ if .Tag.Previous -}}
|
||||
[{{ .Tag.Name }}]: {{ $.Info.RepositoryURL }}/compare/{{ .Tag.Previous.Name }}...{{ .Tag.Name }}
|
||||
{{ end -}}
|
||||
{{ end -}}
|
||||
{{ end -}}
|
||||
27
.chglog/config.yml
Executable file
@@ -0,0 +1,27 @@
|
||||
style: github
|
||||
template: CHANGELOG.tpl.md
|
||||
info:
|
||||
title: CHANGELOG
|
||||
repository_url: https://github.com/wailsapp/wails
|
||||
options:
|
||||
commits:
|
||||
# filters:
|
||||
# Type:
|
||||
# - feat
|
||||
# - fix
|
||||
# - perf
|
||||
# - refactor
|
||||
commit_groups:
|
||||
# title_maps:
|
||||
# feat: Features
|
||||
# fix: Bug Fixes
|
||||
# perf: Performance Improvements
|
||||
# refactor: Code Refactoring
|
||||
header:
|
||||
pattern: "^(\\w*)\\:\\s(.*)$"
|
||||
pattern_maps:
|
||||
- Type
|
||||
- Subject
|
||||
notes:
|
||||
keywords:
|
||||
- BREAKING CHANGE
|
||||
30
.github/ISSUE_TEMPLATE/bug_report.md
vendored
Normal file
@@ -0,0 +1,30 @@
|
||||
---
|
||||
name: Bug report
|
||||
about: Create a report to help us improve
|
||||
title: ''
|
||||
labels: bug
|
||||
assignees: ''
|
||||
|
||||
---
|
||||
|
||||
**Description**
|
||||
A clear and concise description of what the bug is.
|
||||
|
||||
**To Reproduce**
|
||||
Steps to reproduce the behaviour:
|
||||
1. Go to '...'
|
||||
2. Click on '....'
|
||||
3. Scroll down to '....'
|
||||
4. See error
|
||||
|
||||
**Expected behaviour**
|
||||
A clear and concise description of what you expected to happen.
|
||||
|
||||
**Screenshots**
|
||||
If applicable, add screenshots to help explain your problem.
|
||||
|
||||
**System Details**
|
||||
Please paste the output of `wails report` here.
|
||||
|
||||
**Additional context**
|
||||
Add any other context about the problem here.
|
||||
7
.gitignore
vendored
@@ -10,3 +10,10 @@
|
||||
|
||||
# Output of the go coverage tool, specifically when used with LiteIDE
|
||||
*.out
|
||||
|
||||
examples/**/example*
|
||||
!examples/**/*.*
|
||||
cmd/wails/wails
|
||||
.DS_Store
|
||||
tmp
|
||||
dist
|
||||
34
.goreleaser.yml
Normal file
@@ -0,0 +1,34 @@
|
||||
# This is an example goreleaser.yaml file with some sane defaults.
|
||||
# Make sure to check the documentation at http://goreleaser.com
|
||||
|
||||
builds:
|
||||
- env:
|
||||
- CGO_ENABLED=0
|
||||
goos:
|
||||
- windows
|
||||
- linux
|
||||
- darwin
|
||||
goarch:
|
||||
- 386
|
||||
- amd64
|
||||
ignore:
|
||||
- goos: darwin
|
||||
goarch: 386
|
||||
main: ./cmd/wails/main.go
|
||||
archive:
|
||||
replacements:
|
||||
darwin: Darwin
|
||||
linux: Linux
|
||||
windows: Windows
|
||||
386: i386
|
||||
amd64: x86_64
|
||||
checksum:
|
||||
name_template: 'checksums.txt'
|
||||
snapshot:
|
||||
name_template: "{{ .Tag }}-next"
|
||||
changelog:
|
||||
sort: asc
|
||||
filters:
|
||||
exclude:
|
||||
- '^docs:'
|
||||
- '^test:'
|
||||
26
.vscode/launch.json
vendored
@@ -5,14 +5,36 @@
|
||||
"version": "0.2.0",
|
||||
"configurations": [
|
||||
{
|
||||
"name": "Launch",
|
||||
"name": "Wails Init",
|
||||
"type": "go",
|
||||
"request": "launch",
|
||||
"mode": "auto",
|
||||
"program": "${workspaceFolder}/cmd/wails/main.go",
|
||||
"env": {},
|
||||
"cwd": "/tmp",
|
||||
"args": [
|
||||
"setup"
|
||||
"init",
|
||||
"-name",
|
||||
"runtime",
|
||||
"-dir",
|
||||
"runtime",
|
||||
"-output",
|
||||
"runtime",
|
||||
"-template",
|
||||
"vuebasic"
|
||||
]
|
||||
},
|
||||
{
|
||||
"name": "Wails Update Pre",
|
||||
"type": "go",
|
||||
"request": "launch",
|
||||
"mode": "auto",
|
||||
"program": "${workspaceFolder}/cmd/wails/main.go",
|
||||
"env": {},
|
||||
"cwd": "/tmp",
|
||||
"args": [
|
||||
"update",
|
||||
"-pre"
|
||||
]
|
||||
}
|
||||
]
|
||||
|
||||
3
.vscode/settings.json
vendored
Normal file
@@ -0,0 +1,3 @@
|
||||
{
|
||||
"go.formatTool": "goimports"
|
||||
}
|
||||
19
CHANGELOG.md
Normal file
@@ -0,0 +1,19 @@
|
||||
|
||||
<a name="v0.13.0"></a>
|
||||
## [v0.13.0] - 2019-05-12
|
||||
|
||||
### Feat
|
||||
- revamped 'update' system
|
||||
- no need for explicit GO111MODULE=on
|
||||
|
||||
### Fix
|
||||
- documentation typo fixes
|
||||
- windows init project
|
||||
- windows 10 colour
|
||||
- leave windows assets on -p flag
|
||||
- show prerequisite errors
|
||||
|
||||
### Docs
|
||||
- updated contributors
|
||||
- added awesomego logo
|
||||
- added Redhat distro
|
||||
12
CONTRIBUTORS.md
Normal file
@@ -0,0 +1,12 @@
|
||||
# Contributors
|
||||
|
||||
Wails is what it is because of the time and effort given by these great people. A huge thank you to each and every one!
|
||||
|
||||
* [Dustin Krysak](https://wiki.ubuntu.com/bashfulrobot)
|
||||
* [Qais Patankar](https://github.com/qaisjp)
|
||||
* [Anthony Lee](https://github.com/alee792)
|
||||
* [Adrian Lanzafame](https://github.com/lanzafame)
|
||||
* [0xflotus](https://github.com/0xflotus)
|
||||
* [Michael D Henderson](https://github.com/mdhender)
|
||||
* [fred2104] (https://github.com/fishfishfish2104)
|
||||
* [intelwalk] (https://github.com/intelwalk)
|
||||
2
LICENSE
@@ -1,6 +1,6 @@
|
||||
MIT License
|
||||
|
||||
Copyright (c) 2018 wailsapp
|
||||
Copyright (c) 2018-Present Lea Anthony
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
|
||||
121
README.md
@@ -1 +1,120 @@
|
||||
# Coming Soon
|
||||
<p align="center" style="text-align: center">
|
||||
<img src="https://github.com/wailsapp/docs/raw/master/.vuepress/public/media/logo_cropped.png" width="40%"><br/>
|
||||
</p>
|
||||
<p align="center">
|
||||
A framework for building desktop applications using Go & Web Technologies.<br/><br/>
|
||||
<a href="https://github.com/wailsapp/wails/blob/master/LICENSE"><img src="https://img.shields.io/badge/License-MIT-blue.svg"></a>
|
||||
<a href="https://goreportcard.com/report/github.com/wailsapp/wails"><img src="https://goreportcard.com/badge/github.com/wailsapp/wails"/></a>
|
||||
<a href="http://godoc.org/github.com/wailsapp/wails"><img src="https://img.shields.io/badge/godoc-reference-blue.svg"/></a>
|
||||
<a href="https://www.codefactor.io/repository/github/wailsapp/wails"><img src="https://www.codefactor.io/repository/github/wailsapp/wails/badge" alt="CodeFactor" /></a>
|
||||
<a href="https://github.com/wailsapp/wails/issues"><img src="https://img.shields.io/badge/contributions-welcome-brightgreen.svg?style=flat" alt="CodeFactor" /></a>
|
||||
<a href="https://houndci.com"><img src="https://img.shields.io/badge/Reviewed_by-Hound-8E64B0.svg"/></a>
|
||||
<a href="https://github.com/sindresorhus/awesome" rel="nofollow"><img src="https://cdn.rawgit.com/sindresorhus/awesome/d7305f38d29fed78fa85652e3a63e154dd8e8829/media/badge.svg" alt="Awesome"></a>-
|
||||
</p>
|
||||
|
||||
The traditional method of providing web interfaces to Go programs is via a built-in web server. Wails offers a different approach: it provides the ability to wrap both Go code and a web frontend into a single binary. Tools are provided to make this easy for you by handling project creation, compilation and bundling. All you have to do is get creative!
|
||||
|
||||
## Features
|
||||
|
||||
- Use standard Go libraries/frameworks for the backend
|
||||
- Use any frontend technology to build your UI
|
||||
- Expose Go methods/functions to the frontend via a single bind command
|
||||
- Uses native rendering engines - no embedded browser
|
||||
- Shared events system
|
||||
- Native file dialogs
|
||||
- Powerful cli tool
|
||||
- Multiplatform
|
||||
|
||||
## Project Status
|
||||
|
||||
Wails is currently in Beta. Please make sure you read the [Project Status](https://wails.app/project_status.html) if you are interested in using this project.
|
||||
|
||||
## Installation
|
||||
|
||||
Wails uses cgo to bind to the native rendering engines so a number of platform dependent libraries are needed as well as an installation of Go. The basic requirements are:
|
||||
|
||||
- Go 1.11 or above
|
||||
- npm
|
||||
|
||||
### MacOS
|
||||
|
||||
Make sure you have the xcode command line tools installed. This can be done by running:
|
||||
|
||||
`xcode-select --install`
|
||||
|
||||
### Linux
|
||||
|
||||
#### Ubuntu 18.04
|
||||
|
||||
`sudo apt install pkg-config build-essential libgtk-3-dev libwebkit2gtk-4.0-dev`
|
||||
|
||||
#### Arch Linux
|
||||
|
||||
`sudo pacman -S webkit2gtk gtk3`
|
||||
|
||||
#### Red Hat Based Distros
|
||||
|
||||
`sudo yum install webkit2gtk-devel gtk3-devel`
|
||||
|
||||
Note: If you have successfully installed these dependencies on a different flavour of Linux, please consider submitting a PR.
|
||||
|
||||
### Windows
|
||||
|
||||
Windows requires gcc and related tooling. The recommended download is from [http://tdm-gcc.tdragon.net/download](http://tdm-gcc.tdragon.net/download). Once this is installed, you are good to go.
|
||||
|
||||
## Installation
|
||||
|
||||
Installation is as simple as running the following command:
|
||||
|
||||
<pre style='color:white'>
|
||||
go get github.com/wailsapp/wails/cmd/wails
|
||||
</pre>
|
||||
|
||||
## Next Steps
|
||||
|
||||
It is recommended at this stage to read the comprehensive documentation at [https://wails.app](https://wails.app).
|
||||
|
||||
## FAQ
|
||||
|
||||
* Is this an alternative to Electron?
|
||||
|
||||
Depends on your requirements. It's designed to make it easy for Go programmers to make lightweight desktop applications or add a frontend to their existing applications. Whilst Wails does not currently offer hooks into native elements such as menus, this may change in the future.
|
||||
|
||||
* Who is this project aimed at?
|
||||
|
||||
Go programmers who want to bundle an HTML/JS/CSS frontend with their applications, without resorting to creating a server and opening a browser to view it.
|
||||
|
||||
* What's with the name?
|
||||
|
||||
When I saw WebView, I thought "What I really want is tooling around building a WebView app, a bit like Rails is to Ruby". So initially it was a play on words (Webview on Rails). It just so happened to also be a homophone of the English name for the [Country](https://en.wikipedia.org/wiki/Wales) I am from. So it stuck.
|
||||
|
||||
## Shoulders of Giants
|
||||
|
||||
Without the following people, this project would never have existed:
|
||||
|
||||
* [Dustin Krysak](https://wiki.ubuntu.com/bashfulrobot) - His support and feedback has been immense. More patience than you can throw a stick at (Not long now Dustin!).
|
||||
* [Serge Zaitsev](https://github.com/zserge) - Creator of [Webview](https://github.com/zserge/webview) which Wails uses for the windowing.
|
||||
|
||||
And without [these people](CONTRIBUTORS.md), it wouldn't be what it is today.
|
||||
|
||||
Special Mentions:
|
||||
|
||||
* [Bill Kennedy](https://twitter.com/goinggodotnet) - Go guru, encourager and all-round nice guy, whose infectious energy and inspiration powered me on when I had none left.
|
||||
* [Mark Bates](https://github.com/markbates) - Creator of [Packr](https://github.com/gobuffalo/packr), inspiration for packing strategies which fed into some of the tooling.
|
||||
|
||||
This project was mainly coded to the following albums:
|
||||
|
||||
* [Manic Street Preachers - Resistance Is Futile](https://open.spotify.com/album/1R2rsEUqXjIvAbzM0yHrxA)
|
||||
* [Manic Street Preachers - This Is My Truth, Tell Me Yours](https://open.spotify.com/album/4VzCL9kjhgGQeKCiojK1YN)
|
||||
* [The Midnight - Endless Summer](https://open.spotify.com/album/4Krg8zvprquh7TVn9OxZn8)
|
||||
* [Gary Newman - Savage (Songs from a Broken World)](https://open.spotify.com/album/3kMfsD07Q32HRWKRrpcexr)
|
||||
* [Steve Vai - Passion & Warfare](https://open.spotify.com/album/0oL0OhrE2rYVns4IGj8h2m)
|
||||
* [Ben Howard - Every Kingdom](https://open.spotify.com/album/1nJsbWm3Yy2DW1KIc1OKle)
|
||||
* [Ben Howard - Noonday Dream](https://open.spotify.com/album/6astw05cTiXEc2OvyByaPs)
|
||||
* [Adwaith - Melyn](https://open.spotify.com/album/2vBE40Rp60tl7rNqIZjaXM)
|
||||
* [Gwidaith Hen Fran - Cedors Hen Wrach](https://open.spotify.com/album/3v2hrfNGINPLuDP0YDTOjm)
|
||||
* [Metallica - Metallica](https://open.spotify.com/album/2Kh43m04B1UkVcpcRa1Zug)
|
||||
* [Bloc Party - Silent Alarm](https://open.spotify.com/album/6SsIdN05HQg2GwYLfXuzLB)
|
||||
* [Maxthor - Another World](https://open.spotify.com/album/3tklE2Fgw1hCIUstIwPBJF)
|
||||
* [Alun Tan Lan - Y Distawrwydd](https://open.spotify.com/album/0c32OywcLpdJCWWMC6vB8v)
|
||||
|
||||
|
||||
140
app.go
Normal file
@@ -0,0 +1,140 @@
|
||||
package wails
|
||||
|
||||
import (
|
||||
"github.com/wailsapp/wails/cmd"
|
||||
)
|
||||
|
||||
// -------------------------------- Compile time Flags ------------------------------
|
||||
|
||||
// BuildMode indicates what mode we are in
|
||||
var BuildMode = cmd.BuildModeProd
|
||||
|
||||
// ----------------------------------------------------------------------------------
|
||||
|
||||
// App defines the main application struct
|
||||
type App struct {
|
||||
config *AppConfig // The Application configuration object
|
||||
cli *cmd.Cli // In debug mode, we have a cli
|
||||
renderer Renderer // The renderer is what we will render the app to
|
||||
logLevel string // The log level of the app
|
||||
ipc *ipcManager // Handles the IPC calls
|
||||
log *CustomLogger // Logger
|
||||
bindingManager *bindingManager // Handles binding of Go code to renderer
|
||||
eventManager *eventManager // Handles all the events
|
||||
runtime *Runtime // The runtime object for registered structs
|
||||
|
||||
// This is a list of all the JS/CSS that needs injecting
|
||||
// It will get injected in order
|
||||
jsCache []string
|
||||
cssCache []string
|
||||
}
|
||||
|
||||
// CreateApp creates the application window with the given configuration
|
||||
// If none given, the defaults are used
|
||||
func CreateApp(optionalConfig ...*AppConfig) *App {
|
||||
var userConfig *AppConfig
|
||||
if len(optionalConfig) > 0 {
|
||||
userConfig = optionalConfig[0]
|
||||
}
|
||||
|
||||
result := &App{
|
||||
logLevel: "info",
|
||||
renderer: &webViewRenderer{},
|
||||
ipc: newIPCManager(),
|
||||
bindingManager: newBindingManager(),
|
||||
eventManager: newEventManager(),
|
||||
log: newCustomLogger("App"),
|
||||
}
|
||||
|
||||
appconfig, err := newAppConfig(userConfig)
|
||||
if err != nil {
|
||||
result.log.Fatalf("Cannot use custom HTML: %s", err.Error())
|
||||
}
|
||||
result.config = appconfig
|
||||
|
||||
// Set up the CLI if not in release mode
|
||||
if BuildMode != cmd.BuildModeProd {
|
||||
result.cli = result.setupCli()
|
||||
} else {
|
||||
// Disable Inspector in release mode
|
||||
result.config.DisableInspector = true
|
||||
}
|
||||
|
||||
return result
|
||||
}
|
||||
|
||||
// Run the app
|
||||
func (a *App) Run() error {
|
||||
if BuildMode != cmd.BuildModeProd {
|
||||
return a.cli.Run()
|
||||
}
|
||||
|
||||
a.logLevel = "error"
|
||||
err := a.start()
|
||||
if err != nil {
|
||||
a.log.Error(err.Error())
|
||||
}
|
||||
return err
|
||||
}
|
||||
|
||||
func (a *App) start() error {
|
||||
|
||||
// Set the log level
|
||||
setLogLevel(a.logLevel)
|
||||
|
||||
// Log starup
|
||||
a.log.Info("Starting")
|
||||
|
||||
// Check if we are to run in headless mode
|
||||
if BuildMode == cmd.BuildModeBridge {
|
||||
a.renderer = &Headless{}
|
||||
}
|
||||
|
||||
// Initialise the renderer
|
||||
err := a.renderer.Initialise(a.config, a.ipc, a.eventManager)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
// Start event manager and give it our renderer
|
||||
a.eventManager.start(a.renderer)
|
||||
|
||||
// Start the IPC Manager and give it the event manager and binding manager
|
||||
a.ipc.start(a.eventManager, a.bindingManager)
|
||||
|
||||
// Create the runtime
|
||||
a.runtime = newRuntime(a.eventManager, a.renderer)
|
||||
|
||||
// Start binding manager and give it our renderer
|
||||
err = a.bindingManager.start(a.renderer, a.runtime)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
// Inject CSS
|
||||
a.renderer.AddCSSList(a.cssCache)
|
||||
|
||||
// Inject JS
|
||||
a.renderer.AddJSList(a.jsCache)
|
||||
|
||||
// Run the renderer
|
||||
return a.renderer.Run()
|
||||
}
|
||||
|
||||
// Bind allows the user to bind the given object
|
||||
// with the application
|
||||
func (a *App) Bind(object interface{}) {
|
||||
a.bindingManager.bind(object)
|
||||
}
|
||||
|
||||
// AddJS adds a piece of Javascript to a cache that
|
||||
// gets injected at runtime
|
||||
func (a *App) AddJS(js string) {
|
||||
a.jsCache = append(a.jsCache, js)
|
||||
}
|
||||
|
||||
// AddCSS adds a CSS string to a cache that
|
||||
// gets injected at runtime
|
||||
func (a *App) AddCSS(js string) {
|
||||
a.cssCache = append(a.cssCache, js)
|
||||
}
|
||||
28
app_cli.go
Normal file
@@ -0,0 +1,28 @@
|
||||
package wails
|
||||
|
||||
import (
|
||||
"github.com/wailsapp/wails/cmd"
|
||||
)
|
||||
|
||||
// setupCli creates a new cli handler for the application
|
||||
func (app *App) setupCli() *cmd.Cli {
|
||||
|
||||
// Create a new cli
|
||||
result := cmd.NewCli(app.config.Title, "Debug build")
|
||||
result.Version(cmd.Version)
|
||||
|
||||
// Setup cli to handle loglevel and headless flags
|
||||
result.
|
||||
StringFlag("loglevel", "Sets the log level [debug|info|error|panic|fatal]. Default debug", &app.logLevel).
|
||||
// BoolFlag("headless", "Runs the app in headless mode", &app.headless).
|
||||
Action(app.start)
|
||||
|
||||
// Banner
|
||||
result.PreRun(func(cli *cmd.Cli) error {
|
||||
log := cmd.NewLogger()
|
||||
log.YellowUnderline(app.config.Title + " - Debug Build")
|
||||
return nil
|
||||
})
|
||||
|
||||
return result
|
||||
}
|
||||
97
app_config.go
Normal file
@@ -0,0 +1,97 @@
|
||||
package wails
|
||||
|
||||
import (
|
||||
"strings"
|
||||
|
||||
"github.com/dchest/htmlmin"
|
||||
"github.com/leaanthony/mewn"
|
||||
)
|
||||
|
||||
// AppConfig is the configuration structure used when creating a Wails App object
|
||||
type AppConfig struct {
|
||||
Width, Height int
|
||||
Title string
|
||||
defaultHTML string
|
||||
HTML string
|
||||
JS string
|
||||
CSS string
|
||||
Colour string
|
||||
Resizable bool
|
||||
DisableInspector bool
|
||||
isHTMLFragment bool
|
||||
}
|
||||
|
||||
func (a *AppConfig) merge(in *AppConfig) error {
|
||||
if in.CSS != "" {
|
||||
a.CSS = in.CSS
|
||||
}
|
||||
if in.Title != "" {
|
||||
a.Title = in.Title
|
||||
}
|
||||
if in.HTML != "" {
|
||||
minified, err := htmlmin.Minify([]byte(in.HTML), &htmlmin.Options{
|
||||
MinifyScripts: true,
|
||||
})
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
inlineHTML := string(minified)
|
||||
inlineHTML = strings.Replace(inlineHTML, "'", "\\'", -1)
|
||||
inlineHTML = strings.Replace(inlineHTML, "\n", " ", -1)
|
||||
a.HTML = strings.TrimSpace(inlineHTML)
|
||||
|
||||
// Deduce whether this is a full html page or a fragment
|
||||
// The document is determined to be a fragment if an HTML
|
||||
// tag exists and is located before the first div tag
|
||||
HTMLTagIndex := strings.Index(a.HTML, "<html")
|
||||
DivTagIndex := strings.Index(a.HTML, "<div")
|
||||
|
||||
if HTMLTagIndex == -1 {
|
||||
a.isHTMLFragment = true
|
||||
} else {
|
||||
if DivTagIndex < HTMLTagIndex {
|
||||
a.isHTMLFragment = true
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if in.Colour != "" {
|
||||
a.Colour = in.Colour
|
||||
}
|
||||
|
||||
if in.JS != "" {
|
||||
a.JS = in.JS
|
||||
}
|
||||
|
||||
if in.Width != 0 {
|
||||
a.Width = in.Width
|
||||
}
|
||||
if in.Height != 0 {
|
||||
a.Height = in.Height
|
||||
}
|
||||
a.Resizable = in.Resizable
|
||||
a.DisableInspector = in.DisableInspector
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// Creates the default configuration
|
||||
func newAppConfig(userConfig *AppConfig) (*AppConfig, error) {
|
||||
result := &AppConfig{
|
||||
Width: 800,
|
||||
Height: 600,
|
||||
Resizable: true,
|
||||
Title: "My Wails App",
|
||||
Colour: "#FFF", // White by default
|
||||
HTML: mewn.String("./wailsruntimeassets/default/default.html"),
|
||||
}
|
||||
|
||||
if userConfig != nil {
|
||||
err := result.merge(userConfig)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
|
||||
return result, nil
|
||||
}
|
||||
163
binding_function.go
Normal file
@@ -0,0 +1,163 @@
|
||||
package wails
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"reflect"
|
||||
"runtime"
|
||||
)
|
||||
|
||||
type boundFunction struct {
|
||||
fullName string
|
||||
function reflect.Value
|
||||
functionType reflect.Type
|
||||
inputs []reflect.Type
|
||||
returnTypes []reflect.Type
|
||||
log *CustomLogger
|
||||
hasErrorReturnType bool
|
||||
}
|
||||
|
||||
// Creates a new bound function based on the given method + type
|
||||
func newBoundFunction(object interface{}) (*boundFunction, error) {
|
||||
|
||||
objectValue := reflect.ValueOf(object)
|
||||
objectType := reflect.TypeOf(object)
|
||||
|
||||
name := runtime.FuncForPC(objectValue.Pointer()).Name()
|
||||
|
||||
result := &boundFunction{
|
||||
fullName: name,
|
||||
function: objectValue,
|
||||
functionType: objectType,
|
||||
log: newCustomLogger(name),
|
||||
}
|
||||
|
||||
err := result.processParameters()
|
||||
|
||||
return result, err
|
||||
}
|
||||
|
||||
func (b *boundFunction) processParameters() error {
|
||||
|
||||
// Param processing
|
||||
functionType := b.functionType
|
||||
|
||||
// Input parameters
|
||||
inputParamCount := functionType.NumIn()
|
||||
if inputParamCount > 0 {
|
||||
b.inputs = make([]reflect.Type, inputParamCount)
|
||||
// We start at 1 as the first param is the struct
|
||||
for index := 0; index < inputParamCount; index++ {
|
||||
param := functionType.In(index)
|
||||
name := param.Name()
|
||||
kind := param.Kind()
|
||||
b.inputs[index] = param
|
||||
typ := param
|
||||
index := index
|
||||
b.log.DebugFields("Input param", Fields{
|
||||
"index": index,
|
||||
"name": name,
|
||||
"kind": kind,
|
||||
"typ": typ,
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
// Process return/output declarations
|
||||
returnParamsCount := functionType.NumOut()
|
||||
// Guard against bad number of return types
|
||||
switch returnParamsCount {
|
||||
case 0:
|
||||
case 1:
|
||||
// Check if it's an error type
|
||||
param := functionType.Out(0)
|
||||
paramName := param.Name()
|
||||
if paramName == "error" {
|
||||
b.hasErrorReturnType = true
|
||||
}
|
||||
// Save return type
|
||||
b.returnTypes = append(b.returnTypes, param)
|
||||
case 2:
|
||||
// Check the second return type is an error
|
||||
secondParam := functionType.Out(1)
|
||||
secondParamName := secondParam.Name()
|
||||
if secondParamName != "error" {
|
||||
return fmt.Errorf("last return type of method '%s' must be an error (got %s)", b.fullName, secondParamName)
|
||||
}
|
||||
|
||||
// Check the second return type is an error
|
||||
firstParam := functionType.Out(0)
|
||||
firstParamName := firstParam.Name()
|
||||
if firstParamName == "error" {
|
||||
return fmt.Errorf("first return type of method '%s' must not be an error", b.fullName)
|
||||
}
|
||||
b.hasErrorReturnType = true
|
||||
|
||||
// Save return types
|
||||
b.returnTypes = append(b.returnTypes, firstParam)
|
||||
b.returnTypes = append(b.returnTypes, secondParam)
|
||||
|
||||
default:
|
||||
return fmt.Errorf("cannot register method '%s' with %d return parameters. Please use up to 2", b.fullName, returnParamsCount)
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// call the method with the given data
|
||||
func (b *boundFunction) call(data string) ([]reflect.Value, error) {
|
||||
|
||||
// The data will be an array of values so we will decode the
|
||||
// input data into
|
||||
var jsArgs []interface{}
|
||||
d := json.NewDecoder(bytes.NewBufferString(data))
|
||||
// d.UseNumber()
|
||||
err := d.Decode(&jsArgs)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("Invalid data passed to method call: %s", err.Error())
|
||||
}
|
||||
|
||||
// Check correct number of inputs
|
||||
if len(jsArgs) != len(b.inputs) {
|
||||
return nil, fmt.Errorf("Invalid number of parameters given to %s. Expected %d but got %d", b.fullName, len(b.inputs), len(jsArgs))
|
||||
}
|
||||
|
||||
// Set up call
|
||||
args := make([]reflect.Value, len(b.inputs))
|
||||
for index := 0; index < len(b.inputs); index++ {
|
||||
|
||||
// Set the input values
|
||||
value, err := b.setInputValue(index, b.inputs[index], jsArgs[index])
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
args[index] = value
|
||||
}
|
||||
b.log.Debugf("Unmarshalled Args: %+v\n", jsArgs)
|
||||
b.log.Debugf("Converted Args: %+v\n", args)
|
||||
results := b.function.Call(args)
|
||||
|
||||
b.log.Debugf("results = %+v", results)
|
||||
return results, nil
|
||||
}
|
||||
|
||||
// Attempts to set the method input <typ> for parameter <index> with the given value <val>
|
||||
func (b *boundFunction) setInputValue(index int, typ reflect.Type, val interface{}) (result reflect.Value, err error) {
|
||||
|
||||
// Catch type conversion panics thrown by convert
|
||||
defer func() {
|
||||
if r := recover(); r != nil {
|
||||
// Modify error
|
||||
err = fmt.Errorf("%s for parameter %d of function %s", r.(string)[23:], index+1, b.fullName)
|
||||
}
|
||||
}()
|
||||
|
||||
// Translate javascript null values
|
||||
if val == nil {
|
||||
result = reflect.Zero(typ)
|
||||
} else {
|
||||
result = reflect.ValueOf(val).Convert(typ)
|
||||
}
|
||||
return result, err
|
||||
}
|
||||
282
binding_manager.go
Normal file
@@ -0,0 +1,282 @@
|
||||
package wails
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"reflect"
|
||||
"unicode"
|
||||
)
|
||||
|
||||
/**
|
||||
|
||||
binding:
|
||||
Name() // Full name (package+name)
|
||||
Call(params)
|
||||
|
||||
**/
|
||||
|
||||
type bindingManager struct {
|
||||
methods map[string]*boundMethod
|
||||
functions map[string]*boundFunction
|
||||
initMethods []*boundMethod
|
||||
log *CustomLogger
|
||||
renderer Renderer
|
||||
runtime *Runtime // The runtime object to pass to bound structs
|
||||
objectsToBind []interface{}
|
||||
bindPackageNames bool // Package name should be considered when binding
|
||||
}
|
||||
|
||||
func newBindingManager() *bindingManager {
|
||||
result := &bindingManager{
|
||||
methods: make(map[string]*boundMethod),
|
||||
functions: make(map[string]*boundFunction),
|
||||
log: newCustomLogger("Bind"),
|
||||
}
|
||||
return result
|
||||
}
|
||||
|
||||
// Sets flag to indicate package names should be considered when binding
|
||||
func (b *bindingManager) BindPackageNames() {
|
||||
b.bindPackageNames = true
|
||||
}
|
||||
|
||||
func (b *bindingManager) start(renderer Renderer, runtime *Runtime) error {
|
||||
b.log.Info("Starting")
|
||||
b.renderer = renderer
|
||||
b.runtime = runtime
|
||||
err := b.initialise()
|
||||
if err != nil {
|
||||
b.log.Errorf("Binding error: %s", err.Error())
|
||||
return err
|
||||
}
|
||||
err = b.callWailsInitMethods()
|
||||
return err
|
||||
}
|
||||
|
||||
func (b *bindingManager) initialise() error {
|
||||
|
||||
var err error
|
||||
// var binding *boundMethod
|
||||
|
||||
b.log.Info("Binding Go Functions/Methods")
|
||||
|
||||
// Create bindings for objects
|
||||
for _, object := range b.objectsToBind {
|
||||
|
||||
// Safeguard against nils
|
||||
if object == nil {
|
||||
return fmt.Errorf("attempted to bind nil object")
|
||||
}
|
||||
|
||||
// Determine kind of object
|
||||
objectType := reflect.TypeOf(object)
|
||||
objectKind := objectType.Kind()
|
||||
|
||||
switch objectKind {
|
||||
case reflect.Ptr:
|
||||
err = b.bindMethod(object)
|
||||
case reflect.Func:
|
||||
// spew.Dump(result.objectType.String())
|
||||
err = b.bindFunction(object)
|
||||
default:
|
||||
err = fmt.Errorf("cannot bind object of type '%s'", objectKind.String())
|
||||
}
|
||||
|
||||
// Return error if set
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// bind the given struct method
|
||||
func (b *bindingManager) bindMethod(object interface{}) error {
|
||||
|
||||
objectType := reflect.TypeOf(object)
|
||||
baseName := objectType.String()
|
||||
|
||||
// Strip pointer if there
|
||||
if baseName[0] == '*' {
|
||||
baseName = baseName[1:]
|
||||
}
|
||||
|
||||
b.log.Debugf("Processing struct: %s", baseName)
|
||||
|
||||
// Iterate over method definitions
|
||||
for i := 0; i < objectType.NumMethod(); i++ {
|
||||
|
||||
// Get method definition
|
||||
methodDef := objectType.Method(i)
|
||||
methodName := methodDef.Name
|
||||
fullMethodName := baseName + "." + methodName
|
||||
method := reflect.ValueOf(object).MethodByName(methodName)
|
||||
|
||||
// Skip unexported methods
|
||||
if !unicode.IsUpper([]rune(methodName)[0]) {
|
||||
continue
|
||||
}
|
||||
|
||||
// Create a new boundMethod
|
||||
newMethod, err := newBoundMethod(methodName, fullMethodName, method, objectType)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
// Check if it's a wails init function
|
||||
if newMethod.isWailsInit {
|
||||
b.log.Debugf("Detected WailsInit function: %s", fullMethodName)
|
||||
b.initMethods = append(b.initMethods, newMethod)
|
||||
} else {
|
||||
// Save boundMethod
|
||||
b.log.Infof("Bound Method: %s()", fullMethodName)
|
||||
b.methods[fullMethodName] = newMethod
|
||||
|
||||
// Inform renderer of new binding
|
||||
b.renderer.NewBinding(fullMethodName)
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// bind the given function object
|
||||
func (b *bindingManager) bindFunction(object interface{}) error {
|
||||
|
||||
newFunction, err := newBoundFunction(object)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
// Save method
|
||||
b.log.Infof("Bound Function: %s()", newFunction.fullName)
|
||||
b.functions[newFunction.fullName] = newFunction
|
||||
|
||||
// Register with Renderer
|
||||
b.renderer.NewBinding(newFunction.fullName)
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// Save the given object to be bound at start time
|
||||
func (b *bindingManager) bind(object interface{}) {
|
||||
// Store binding
|
||||
b.objectsToBind = append(b.objectsToBind, object)
|
||||
}
|
||||
|
||||
func (b *bindingManager) processFunctionCall(callData *callData) (interface{}, error) {
|
||||
// Return values
|
||||
var result []reflect.Value
|
||||
var err error
|
||||
|
||||
function := b.functions[callData.BindingName]
|
||||
if function == nil {
|
||||
return nil, fmt.Errorf("Invalid function name '%s'", callData.BindingName)
|
||||
}
|
||||
result, err = function.call(callData.Data)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
// Do we have an error return type?
|
||||
if function.hasErrorReturnType {
|
||||
// We do - last result is an error type
|
||||
// Check if the last result was nil
|
||||
b.log.Debugf("# of return types: %d", len(function.returnTypes))
|
||||
b.log.Debugf("# of results: %d", len(result))
|
||||
errorResult := result[len(function.returnTypes)-1]
|
||||
if !errorResult.IsNil() {
|
||||
// It wasn't - we have an error
|
||||
return nil, errorResult.Interface().(error)
|
||||
}
|
||||
}
|
||||
return result[0].Interface(), nil
|
||||
}
|
||||
|
||||
func (b *bindingManager) processMethodCall(callData *callData) (interface{}, error) {
|
||||
// Return values
|
||||
var result []reflect.Value
|
||||
var err error
|
||||
|
||||
// do we have this method?
|
||||
method := b.methods[callData.BindingName]
|
||||
if method == nil {
|
||||
return nil, fmt.Errorf("Invalid method name '%s'", callData.BindingName)
|
||||
}
|
||||
|
||||
result, err = method.call(callData.Data)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
// Do we have an error return type?
|
||||
if method.hasErrorReturnType {
|
||||
// We do - last result is an error type
|
||||
// Check if the last result was nil
|
||||
b.log.Debugf("# of return types: %d", len(method.returnTypes))
|
||||
b.log.Debugf("# of results: %d", len(result))
|
||||
errorResult := result[len(method.returnTypes)-1]
|
||||
if !errorResult.IsNil() {
|
||||
// It wasn't - we have an error
|
||||
return nil, errorResult.Interface().(error)
|
||||
}
|
||||
}
|
||||
if result != nil {
|
||||
return result[0].Interface(), nil
|
||||
}
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
// process an incoming call request
|
||||
func (b *bindingManager) processCall(callData *callData) (result interface{}, err error) {
|
||||
b.log.Debugf("Wanting to call %s", callData.BindingName)
|
||||
|
||||
// Determine if this is function call or method call by the number of
|
||||
// dots in the binding name
|
||||
dotCount := 0
|
||||
for _, character := range callData.BindingName {
|
||||
if character == '.' {
|
||||
dotCount++
|
||||
}
|
||||
}
|
||||
|
||||
// We need to catch reflect related panics and return
|
||||
// a decent error message
|
||||
// TODO: DEBUG THIS!
|
||||
|
||||
defer func() {
|
||||
if r := recover(); r != nil {
|
||||
err = fmt.Errorf("%s", r.(string))
|
||||
}
|
||||
}()
|
||||
|
||||
switch dotCount {
|
||||
case 1:
|
||||
result, err = b.processFunctionCall(callData)
|
||||
case 2:
|
||||
result, err = b.processMethodCall(callData)
|
||||
default:
|
||||
result = nil
|
||||
err = fmt.Errorf("Invalid binding name '%s'", callData.BindingName)
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
// callWailsInitMethods calls all of the WailsInit methods that were
|
||||
// registered with the runtime object
|
||||
func (b *bindingManager) callWailsInitMethods() error {
|
||||
// Create reflect value for runtime object
|
||||
runtimeValue := reflect.ValueOf(b.runtime)
|
||||
params := []reflect.Value{runtimeValue}
|
||||
|
||||
// Iterate initMethods
|
||||
for _, initMethod := range b.initMethods {
|
||||
// Call
|
||||
result := initMethod.method.Call(params)
|
||||
// Check errors
|
||||
err := result[0].Interface()
|
||||
if err != nil {
|
||||
return err.(error)
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
211
binding_method.go
Normal file
@@ -0,0 +1,211 @@
|
||||
package wails
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"reflect"
|
||||
)
|
||||
|
||||
type boundMethod struct {
|
||||
Name string
|
||||
fullName string
|
||||
method reflect.Value
|
||||
inputs []reflect.Type
|
||||
returnTypes []reflect.Type
|
||||
log *CustomLogger
|
||||
hasErrorReturnType bool // Indicates if there is an error return type
|
||||
isWailsInit bool
|
||||
}
|
||||
|
||||
// Creates a new bound method based on the given method + type
|
||||
func newBoundMethod(name string, fullName string, method reflect.Value, objectType reflect.Type) (*boundMethod, error) {
|
||||
result := &boundMethod{
|
||||
Name: name,
|
||||
method: method,
|
||||
fullName: fullName,
|
||||
}
|
||||
|
||||
// Setup logger
|
||||
result.log = newCustomLogger(result.fullName)
|
||||
|
||||
// Check if Parameters are valid
|
||||
err := result.processParameters()
|
||||
|
||||
// Are we a WailsInit method?
|
||||
if result.Name == "WailsInit" {
|
||||
err = result.processWailsInit()
|
||||
}
|
||||
|
||||
return result, err
|
||||
}
|
||||
|
||||
func (b *boundMethod) processParameters() error {
|
||||
|
||||
// Param processing
|
||||
methodType := b.method.Type()
|
||||
|
||||
// Input parameters
|
||||
inputParamCount := methodType.NumIn()
|
||||
if inputParamCount > 0 {
|
||||
b.inputs = make([]reflect.Type, inputParamCount)
|
||||
// We start at 1 as the first param is the struct
|
||||
for index := 0; index < inputParamCount; index++ {
|
||||
param := methodType.In(index)
|
||||
name := param.Name()
|
||||
kind := param.Kind()
|
||||
b.inputs[index] = param
|
||||
typ := param
|
||||
index := index
|
||||
b.log.DebugFields("Input param", Fields{
|
||||
"index": index,
|
||||
"name": name,
|
||||
"kind": kind,
|
||||
"typ": typ,
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
// Process return/output declarations
|
||||
returnParamsCount := methodType.NumOut()
|
||||
// Guard against bad number of return types
|
||||
switch returnParamsCount {
|
||||
case 0:
|
||||
case 1:
|
||||
// Check if it's an error type
|
||||
param := methodType.Out(0)
|
||||
paramName := param.Name()
|
||||
if paramName == "error" {
|
||||
b.hasErrorReturnType = true
|
||||
}
|
||||
// Save return type
|
||||
b.returnTypes = append(b.returnTypes, param)
|
||||
case 2:
|
||||
// Check the second return type is an error
|
||||
secondParam := methodType.Out(1)
|
||||
secondParamName := secondParam.Name()
|
||||
if secondParamName != "error" {
|
||||
return fmt.Errorf("last return type of method '%s' must be an error (got %s)", b.Name, secondParamName)
|
||||
}
|
||||
|
||||
// Check the second return type is an error
|
||||
firstParam := methodType.Out(0)
|
||||
firstParamName := firstParam.Name()
|
||||
if firstParamName == "error" {
|
||||
return fmt.Errorf("first return type of method '%s' must not be an error", b.Name)
|
||||
}
|
||||
b.hasErrorReturnType = true
|
||||
|
||||
// Save return types
|
||||
b.returnTypes = append(b.returnTypes, firstParam)
|
||||
b.returnTypes = append(b.returnTypes, secondParam)
|
||||
|
||||
default:
|
||||
return fmt.Errorf("cannot register method '%s' with %d return parameters. Please use up to 2", b.Name, returnParamsCount)
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// call the method with the given data
|
||||
func (b *boundMethod) call(data string) ([]reflect.Value, error) {
|
||||
|
||||
// The data will be an array of values so we will decode the
|
||||
// input data into
|
||||
var jsArgs []interface{}
|
||||
d := json.NewDecoder(bytes.NewBufferString(data))
|
||||
// d.UseNumber()
|
||||
err := d.Decode(&jsArgs)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("Invalid data passed to method call: %s", err.Error())
|
||||
}
|
||||
|
||||
// Check correct number of inputs
|
||||
if len(jsArgs) != len(b.inputs) {
|
||||
return nil, fmt.Errorf("Invalid number of parameters given to %s. Expected %d but got %d", b.fullName, len(b.inputs), len(jsArgs))
|
||||
}
|
||||
|
||||
// Set up call
|
||||
args := make([]reflect.Value, len(b.inputs))
|
||||
for index := 0; index < len(b.inputs); index++ {
|
||||
|
||||
// Set the input values
|
||||
value, err := b.setInputValue(index, b.inputs[index], jsArgs[index])
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
args[index] = value
|
||||
}
|
||||
b.log.Debugf("Unmarshalled Args: %+v\n", jsArgs)
|
||||
b.log.Debugf("Converted Args: %+v\n", args)
|
||||
results := b.method.Call(args)
|
||||
|
||||
b.log.Debugf("results = %+v", results)
|
||||
return results, nil
|
||||
}
|
||||
|
||||
// Attempts to set the method input <typ> for parameter <index> with the given value <val>
|
||||
func (b *boundMethod) setInputValue(index int, typ reflect.Type, val interface{}) (result reflect.Value, err error) {
|
||||
|
||||
// Catch type conversion panics thrown by convert
|
||||
defer func() {
|
||||
if r := recover(); r != nil {
|
||||
// Modify error
|
||||
fmt.Printf("Recovery message: %+v\n", r)
|
||||
err = fmt.Errorf("%s for parameter %d of method %s", r.(string)[23:], index+1, b.fullName)
|
||||
}
|
||||
}()
|
||||
|
||||
// Do the conversion
|
||||
// Handle nil values
|
||||
if val == nil {
|
||||
switch typ.Kind() {
|
||||
case reflect.Chan,
|
||||
reflect.Func,
|
||||
reflect.Interface,
|
||||
reflect.Map,
|
||||
reflect.Ptr,
|
||||
reflect.Slice:
|
||||
logger.Debug("Converting nil to type")
|
||||
result = reflect.ValueOf(val).Convert(typ)
|
||||
default:
|
||||
logger.Debug("Cannot convert nil to type, returning error")
|
||||
return reflect.Zero(typ), fmt.Errorf("Unable to use null value for parameter %d of method %s", index+1, b.fullName)
|
||||
}
|
||||
} else {
|
||||
result = reflect.ValueOf(val).Convert(typ)
|
||||
}
|
||||
|
||||
return result, err
|
||||
}
|
||||
|
||||
func (b *boundMethod) processWailsInit() error {
|
||||
// We must have only 1 input, it must be *wails.Runtime
|
||||
if len(b.inputs) != 1 {
|
||||
return fmt.Errorf("Invalid WailsInit() definition. Expected 1 input, but got %d", len(b.inputs))
|
||||
}
|
||||
|
||||
// It must be *wails.Runtime
|
||||
inputName := b.inputs[0].String()
|
||||
b.log.Debugf("WailsInit input type: %s", inputName)
|
||||
if inputName != "*wails.Runtime" {
|
||||
return fmt.Errorf("Invalid WailsInit() definition. Expected input to be wails.Runtime, but got %s", inputName)
|
||||
}
|
||||
|
||||
// We must have only 1 output, it must be error
|
||||
if len(b.returnTypes) != 1 {
|
||||
return fmt.Errorf("Invalid WailsInit() definition. Expected 1 return type, but got %d", len(b.returnTypes))
|
||||
}
|
||||
|
||||
// It must be *wails.Runtime
|
||||
outputName := b.returnTypes[0].String()
|
||||
b.log.Debugf("WailsInit output type: %s", outputName)
|
||||
if outputName != "error" {
|
||||
return fmt.Errorf("Invalid WailsInit() definition. Expected input to be error, but got %s", outputName)
|
||||
}
|
||||
|
||||
// We are indeed a wails Init method
|
||||
b.isWailsInit = true
|
||||
|
||||
return nil
|
||||
}
|
||||
10
cmd/build.go
Normal file
@@ -0,0 +1,10 @@
|
||||
package cmd
|
||||
|
||||
const (
|
||||
// BuildModeProd indicates we are building for prod mode
|
||||
BuildModeProd = "prod"
|
||||
// BuildModeDebug indicates we are building for debug mode
|
||||
BuildModeDebug = "debug"
|
||||
// BuildModeBridge indicates we are building for bridge mode
|
||||
BuildModeBridge = "bridge"
|
||||
)
|
||||
26
cmd/cli.go
@@ -96,6 +96,7 @@ type Command struct {
|
||||
flagCount int
|
||||
log *Logger
|
||||
helpFlag bool
|
||||
hidden bool
|
||||
}
|
||||
|
||||
// NewCommand creates a new Command
|
||||
@@ -105,6 +106,8 @@ func NewCommand(name string, description string, app *Cli, parentCommandPath str
|
||||
Shortdescription: description,
|
||||
SubCommandsMap: make(map[string]*Command),
|
||||
App: app,
|
||||
log: NewLogger(),
|
||||
hidden: false,
|
||||
}
|
||||
|
||||
// Set up command path
|
||||
@@ -181,6 +184,7 @@ func (c *Command) Run(args []string) error {
|
||||
|
||||
// Nothing left we can do
|
||||
c.PrintHelp()
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -192,10 +196,8 @@ func (c *Command) Action(callback Action) *Command {
|
||||
|
||||
// PrintHelp - Output the help text for this command
|
||||
func (c *Command) PrintHelp() {
|
||||
versionString := c.AppVersion
|
||||
if versionString != "" {
|
||||
versionString = " " + versionString
|
||||
}
|
||||
c.log.PrintBanner()
|
||||
|
||||
commandTitle := c.CommandPath
|
||||
if c.Shortdescription != "" {
|
||||
commandTitle += " - " + c.Shortdescription
|
||||
@@ -209,10 +211,12 @@ func (c *Command) PrintHelp() {
|
||||
fmt.Println(c.Longdescription + "\n")
|
||||
}
|
||||
if len(c.SubCommands) > 0 {
|
||||
fmt.Println("")
|
||||
c.log.White("Available commands:")
|
||||
fmt.Println("")
|
||||
for _, subcommand := range c.SubCommands {
|
||||
if subcommand.isHidden() {
|
||||
continue
|
||||
}
|
||||
spacer := strings.Repeat(" ", 3+c.longestSubcommand-len(subcommand.Name))
|
||||
isDefault := ""
|
||||
if subcommand.isDefaultCommand() {
|
||||
@@ -220,9 +224,9 @@ func (c *Command) PrintHelp() {
|
||||
}
|
||||
fmt.Printf(" %s%s%s %s\n", subcommand.Name, spacer, subcommand.Shortdescription, isDefault)
|
||||
}
|
||||
fmt.Println("")
|
||||
}
|
||||
if c.flagCount > 0 {
|
||||
fmt.Println("")
|
||||
c.log.White("Flags:")
|
||||
fmt.Println()
|
||||
c.Flags.SetOutput(os.Stdout)
|
||||
@@ -238,6 +242,16 @@ func (c *Command) isDefaultCommand() bool {
|
||||
return c.App.defaultCommand == c
|
||||
}
|
||||
|
||||
// isHidden returns true if the command is a hidden command
|
||||
func (c *Command) isHidden() bool {
|
||||
return c.hidden
|
||||
}
|
||||
|
||||
// Hidden hides the command from the Help system
|
||||
func (c *Command) Hidden() {
|
||||
c.hidden = true
|
||||
}
|
||||
|
||||
// Command - Defines a subcommand
|
||||
func (c *Command) Command(name, description string) *Command {
|
||||
result := NewCommand(name, description, c.App, c.CommandPath)
|
||||
|
||||
@@ -1,69 +0,0 @@
|
||||
package cmd
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"io/ioutil"
|
||||
"path"
|
||||
"path/filepath"
|
||||
"runtime"
|
||||
)
|
||||
|
||||
// FrameworkMetadata contains information about a given framework
|
||||
type FrameworkMetadata struct {
|
||||
Name string `json:"name"`
|
||||
BuildTag string `json:"buildtag"`
|
||||
Description string `json:"description"`
|
||||
}
|
||||
|
||||
// Utility function for creating new FrameworkMetadata structs
|
||||
func loadFrameworkMetadata(pathToMetadataJSON string) (*FrameworkMetadata, error) {
|
||||
result := &FrameworkMetadata{}
|
||||
configData, err := ioutil.ReadFile(pathToMetadataJSON)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
// Load and unmarshall!
|
||||
err = json.Unmarshal(configData, result)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return result, nil
|
||||
}
|
||||
|
||||
// GetFrameworks returns information about all the available frameworks
|
||||
func GetFrameworks() ([]*FrameworkMetadata, error) {
|
||||
|
||||
var err error
|
||||
|
||||
// Calculate framework base dir
|
||||
_, filename, _, _ := runtime.Caller(1)
|
||||
frameworksBaseDir := filepath.Join(path.Dir(filename), "frameworks")
|
||||
|
||||
// Get the subdirectories
|
||||
fs := NewFSHelper()
|
||||
frameworkDirs, err := fs.GetSubdirs(frameworksBaseDir)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
// Prepare result
|
||||
result := []*FrameworkMetadata{}
|
||||
|
||||
// Iterate framework directories, looking for metadata.json files
|
||||
for _, frameworkDir := range frameworkDirs {
|
||||
var frameworkMetadata FrameworkMetadata
|
||||
metadataFile := filepath.Join(frameworkDir, "metadata.json")
|
||||
jsonData, err := ioutil.ReadFile(metadataFile)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
err = json.Unmarshal(jsonData, &frameworkMetadata)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
result = append(result, &frameworkMetadata)
|
||||
}
|
||||
|
||||
// Read in framework metadata
|
||||
return result, nil
|
||||
}
|
||||
@@ -1,16 +0,0 @@
|
||||
// +build frameworkbootstrap4
|
||||
|
||||
package frameworks
|
||||
|
||||
import (
|
||||
"github.com/gobuffalo/packr"
|
||||
)
|
||||
|
||||
func init() {
|
||||
assets := packr.NewBox("./bootstrap4default/assets")
|
||||
FrameworkToUse = &Framework{
|
||||
Name: "Bootstrap 4",
|
||||
JS: assets.String("bootstrap.bundle.min.js"),
|
||||
CSS: assets.String("bootstrap.min.css"),
|
||||
}
|
||||
}
|
||||
@@ -1,17 +0,0 @@
|
||||
// +build frameworkbootstrap4
|
||||
|
||||
package bootstrap4
|
||||
|
||||
import (
|
||||
"github.com/gobuffalo/packr"
|
||||
"github.com/wailsapp/wails/frameworks"
|
||||
)
|
||||
|
||||
func init() {
|
||||
assets := packr.NewBox("./assets")
|
||||
frameworks.FrameworkToUse = &frameworks.Framework{
|
||||
Name: "Bootstrap 4",
|
||||
JS: assets.String("bootstrap.bundle.min.js"),
|
||||
CSS: assets.String("bootstrap.min.css"),
|
||||
}
|
||||
}
|
||||
@@ -1,5 +0,0 @@
|
||||
{
|
||||
"Name": "Bootstrap 4",
|
||||
"Description": "Standard Bootstrap 4 with default theme",
|
||||
"BuildTag": "frameworkbootstrap4"
|
||||
}
|
||||
@@ -1,16 +0,0 @@
|
||||
// +build frameworkbootstrap4lux
|
||||
|
||||
package frameworks
|
||||
|
||||
import (
|
||||
"github.com/gobuffalo/packr"
|
||||
)
|
||||
|
||||
func init() {
|
||||
assets := packr.NewBox("./bootstrap4lux/assets")
|
||||
FrameworkToUse = &Framework{
|
||||
Name: "Bootstrap 4 (Lux)",
|
||||
JS: assets.String("bootstrap.bundle.min.js"),
|
||||
CSS: assets.String("bootstrap.min.css"),
|
||||
}
|
||||
}
|
||||
@@ -1,17 +0,0 @@
|
||||
// +build frameworkbootstrap4lux
|
||||
|
||||
package bootstrap4
|
||||
|
||||
import (
|
||||
"github.com/gobuffalo/packr"
|
||||
"github.com/wailsapp/wails/frameworks"
|
||||
)
|
||||
|
||||
func init() {
|
||||
assets := packr.NewBox("./assets")
|
||||
frameworks.FrameworkToUse = &frameworks.Framework{
|
||||
Name: "Bootstrap 4 (Lux)",
|
||||
JS: assets.String("bootstrap.bundle.min.js"),
|
||||
CSS: assets.String("bootstrap.min.css"),
|
||||
}
|
||||
}
|
||||
@@ -1,5 +0,0 @@
|
||||
{
|
||||
"Name": "Bootstrap 4 (Lux)",
|
||||
"Description": "Bootstrap with Lux theme",
|
||||
"BuildTag": "frameworkbootstrap4lux"
|
||||
}
|
||||
@@ -1,13 +0,0 @@
|
||||
package frameworks
|
||||
|
||||
// Framework has details about a specific framework
|
||||
type Framework struct {
|
||||
Name string
|
||||
JS string
|
||||
CSS string
|
||||
Options string
|
||||
}
|
||||
|
||||
// FrameworkToUse is the framework we will use when building
|
||||
// Set by `wails init`, used by `wails build`
|
||||
var FrameworkToUse *Framework
|
||||
97
cmd/fs.go
@@ -1,13 +1,19 @@
|
||||
package cmd
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"crypto/md5"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"io"
|
||||
"io/ioutil"
|
||||
"log"
|
||||
"os"
|
||||
"path"
|
||||
"path/filepath"
|
||||
"runtime"
|
||||
|
||||
"github.com/leaanthony/slicer"
|
||||
)
|
||||
|
||||
// FSHelper - Wrapper struct for File System utility commands
|
||||
@@ -41,6 +47,14 @@ func (fs *FSHelper) FileExists(path string) bool {
|
||||
return fi.Mode().IsRegular()
|
||||
}
|
||||
|
||||
// CreateFile creates a file at the given filename location with the contents
|
||||
// set to the given data. It will create intermediary directories if needed.
|
||||
func (fs *FSHelper) CreateFile(filename string, data []byte) error {
|
||||
// Ensure directory exists
|
||||
fs.MkDirs(filepath.Dir(filename))
|
||||
return ioutil.WriteFile(filename, data, 0644)
|
||||
}
|
||||
|
||||
// MkDirs creates the given nested directories.
|
||||
// Returns error on failure
|
||||
func (fs *FSHelper) MkDirs(fullPath string, mode ...os.FileMode) error {
|
||||
@@ -80,11 +94,46 @@ func (fs *FSHelper) Cwd() string {
|
||||
return cwd
|
||||
}
|
||||
|
||||
// RemoveFile removes the given filename
|
||||
func (fs *FSHelper) RemoveFile(filename string) error {
|
||||
return os.Remove(filename)
|
||||
}
|
||||
|
||||
// RemoveFiles removes the given filenames
|
||||
func (fs *FSHelper) RemoveFiles(files []string) error {
|
||||
for _, filename := range files {
|
||||
err := os.Remove(filename)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
type Dir struct {
|
||||
localPath string
|
||||
fullPath string
|
||||
}
|
||||
|
||||
func (fs *FSHelper) Dir(dir string) (*Dir, error) {
|
||||
fullPath, err := filepath.Abs(dir)
|
||||
return &Dir{fullPath: fullPath}, err
|
||||
}
|
||||
|
||||
func (fs *FSHelper) LocalDir(dir string) (*Dir, error) {
|
||||
_, filename, _, _ := runtime.Caller(1)
|
||||
fullPath, err := filepath.Abs(filepath.Join(path.Dir(filename), dir))
|
||||
return &Dir{
|
||||
localPath: dir,
|
||||
fullPath: fullPath,
|
||||
}, err
|
||||
}
|
||||
|
||||
// GetSubdirs will return a list of FQPs to subdirectories in the given directory
|
||||
func (fs *FSHelper) GetSubdirs(dir string) (map[string]string, error) {
|
||||
func (d *Dir) GetSubdirs() (map[string]string, error) {
|
||||
|
||||
// Read in the directory information
|
||||
fileInfo, err := ioutil.ReadDir(dir)
|
||||
fileInfo, err := ioutil.ReadDir(d.fullPath)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -96,25 +145,65 @@ func (fs *FSHelper) GetSubdirs(dir string) (map[string]string, error) {
|
||||
// map["directoryName"] = "path/to/directoryName"
|
||||
for _, file := range fileInfo {
|
||||
if file.IsDir() {
|
||||
subdirs[file.Name()] = filepath.Join(dir, file.Name())
|
||||
subdirs[file.Name()] = filepath.Join(d.fullPath, file.Name())
|
||||
}
|
||||
}
|
||||
return subdirs, nil
|
||||
}
|
||||
|
||||
// GetAllFilenames returns all filename in and below this directory
|
||||
func (d *Dir) GetAllFilenames() (*slicer.StringSlicer, error) {
|
||||
result := slicer.String()
|
||||
err := filepath.Walk(d.fullPath, func(dir string, info os.FileInfo, err error) error {
|
||||
if dir == d.fullPath {
|
||||
return nil
|
||||
}
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
// Don't copy template metadata
|
||||
result.Add(dir)
|
||||
|
||||
return nil
|
||||
})
|
||||
return result, err
|
||||
}
|
||||
|
||||
// MkDir creates the given directory.
|
||||
// Returns error on failure
|
||||
func (fs *FSHelper) MkDir(dir string) error {
|
||||
return os.Mkdir(dir, 0700)
|
||||
}
|
||||
|
||||
// SaveAsJSON saves the JSON representation of the given data to the given filename
|
||||
func (fs *FSHelper) SaveAsJSON(data interface{}, filename string) error {
|
||||
|
||||
var buf bytes.Buffer
|
||||
e := json.NewEncoder(&buf)
|
||||
e.SetEscapeHTML(false)
|
||||
e.SetIndent("", " ")
|
||||
e.Encode(data)
|
||||
|
||||
err := ioutil.WriteFile(filename, buf.Bytes(), 0755)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// LoadAsString will attempt to load the given file and return
|
||||
// its contents as a string
|
||||
func (fs *FSHelper) LoadAsString(filename string) (string, error) {
|
||||
bytes, err := ioutil.ReadFile(filename)
|
||||
bytes, err := fs.LoadAsBytes(filename)
|
||||
return string(bytes), err
|
||||
}
|
||||
|
||||
// LoadAsBytes returns the contents of the file as a byte slice
|
||||
func (fs *FSHelper) LoadAsBytes(filename string) ([]byte, error) {
|
||||
return ioutil.ReadFile(filename)
|
||||
}
|
||||
|
||||
// FileMD5 returns the md5sum of the given file
|
||||
func (fs *FSHelper) FileMD5(filename string) (string, error) {
|
||||
f, err := os.Open(filename)
|
||||
|
||||
108
cmd/github.go
Normal file
@@ -0,0 +1,108 @@
|
||||
package cmd
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"net/http"
|
||||
"sort"
|
||||
)
|
||||
|
||||
// GitHubHelper is a utility class for interacting with GitHub
|
||||
type GitHubHelper struct {
|
||||
}
|
||||
|
||||
// NewGitHubHelper returns a new GitHub Helper
|
||||
func NewGitHubHelper() *GitHubHelper {
|
||||
return &GitHubHelper{}
|
||||
}
|
||||
|
||||
// GetVersionTags gets the list of tags on the Wails repo
|
||||
// It retuns a list of sorted tags in descending order
|
||||
func (g *GitHubHelper) GetVersionTags() ([]*SemanticVersion, error) {
|
||||
|
||||
result := []*SemanticVersion{}
|
||||
var err error
|
||||
|
||||
resp, err := http.Get("https://api.github.com/repos/wailsapp/wails/tags")
|
||||
if err != nil {
|
||||
return result, err
|
||||
}
|
||||
body, err := ioutil.ReadAll(resp.Body)
|
||||
if err != nil {
|
||||
return result, err
|
||||
}
|
||||
|
||||
data := []map[string]interface{}{}
|
||||
err = json.Unmarshal(body, &data)
|
||||
if err != nil {
|
||||
return result, err
|
||||
}
|
||||
|
||||
// Convert tag data to Version structs
|
||||
for _, tag := range data {
|
||||
version := tag["name"].(string)
|
||||
semver, err := NewSemanticVersion(version)
|
||||
if err != nil {
|
||||
return result, err
|
||||
}
|
||||
result = append(result, semver)
|
||||
}
|
||||
|
||||
// Reverse Sort
|
||||
sort.Sort(sort.Reverse(SemverCollection(result)))
|
||||
|
||||
return result, err
|
||||
}
|
||||
|
||||
// GetLatestStableRelease gets the latest stable release on GitHub
|
||||
func (g *GitHubHelper) GetLatestStableRelease() (result *SemanticVersion, err error) {
|
||||
|
||||
tags, err := g.GetVersionTags()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
for _, tag := range tags {
|
||||
if tag.IsRelease() {
|
||||
return tag, nil
|
||||
}
|
||||
}
|
||||
|
||||
return nil, fmt.Errorf("no release tag found")
|
||||
}
|
||||
|
||||
// GetLatestPreRelease gets the latest prerelease on GitHub
|
||||
func (g *GitHubHelper) GetLatestPreRelease() (result *SemanticVersion, err error) {
|
||||
|
||||
tags, err := g.GetVersionTags()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
for _, tag := range tags {
|
||||
if tag.IsPreRelease() {
|
||||
return tag, nil
|
||||
}
|
||||
}
|
||||
|
||||
return nil, fmt.Errorf("no prerelease tag found")
|
||||
}
|
||||
|
||||
// IsValidTag returns true if the given string is a valid tag
|
||||
func (g *GitHubHelper) IsValidTag(tagVersion string) (bool, error) {
|
||||
if tagVersion[0] == 'v' {
|
||||
tagVersion = tagVersion[1:]
|
||||
}
|
||||
tags, err := g.GetVersionTags()
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
|
||||
for _, tag := range tags {
|
||||
if tag.String() == tagVersion {
|
||||
return true, nil
|
||||
}
|
||||
}
|
||||
return false, nil
|
||||
}
|
||||
306
cmd/helpers.go
Normal file
@@ -0,0 +1,306 @@
|
||||
package cmd
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"os/exec"
|
||||
"path/filepath"
|
||||
"runtime"
|
||||
"time"
|
||||
|
||||
mewn "github.com/leaanthony/mewn"
|
||||
"github.com/leaanthony/slicer"
|
||||
"github.com/leaanthony/spinner"
|
||||
)
|
||||
|
||||
var fs = NewFSHelper()
|
||||
|
||||
// ValidateFrontendConfig checks if the frontend config is valid
|
||||
func ValidateFrontendConfig(projectOptions *ProjectOptions) error {
|
||||
if projectOptions.FrontEnd.Dir == "" {
|
||||
return fmt.Errorf("Frontend directory not set in project.json")
|
||||
}
|
||||
if projectOptions.FrontEnd.Build == "" {
|
||||
return fmt.Errorf("Frontend build command not set in project.json")
|
||||
}
|
||||
if projectOptions.FrontEnd.Install == "" {
|
||||
return fmt.Errorf("Frontend install command not set in project.json")
|
||||
}
|
||||
if projectOptions.FrontEnd.Bridge == "" {
|
||||
return fmt.Errorf("Frontend bridge config not set in project.json")
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// InstallGoDependencies will run go get in the current directory
|
||||
func InstallGoDependencies() error {
|
||||
depSpinner := spinner.New("Ensuring Dependencies are up to date...")
|
||||
depSpinner.SetSpinSpeed(50)
|
||||
depSpinner.Start()
|
||||
err := NewProgramHelper().RunCommand("go get")
|
||||
if err != nil {
|
||||
depSpinner.Error()
|
||||
return err
|
||||
}
|
||||
depSpinner.Success()
|
||||
return nil
|
||||
}
|
||||
|
||||
// BuildApplication will attempt to build the project based on the given inputs
|
||||
func BuildApplication(binaryName string, forceRebuild bool, buildMode string, packageApp bool, projectOptions *ProjectOptions) error {
|
||||
|
||||
// Generate Windows assets if needed
|
||||
if runtime.GOOS == "windows" {
|
||||
cleanUp := !packageApp
|
||||
err := NewPackageHelper().PackageWindows(projectOptions, cleanUp)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
// Check Mewn is installed
|
||||
err := CheckMewn()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
compileMessage := "Packing + Compiling project"
|
||||
|
||||
if buildMode == BuildModeDebug {
|
||||
compileMessage += " (Debug Mode)"
|
||||
}
|
||||
|
||||
packSpinner := spinner.New(compileMessage + "...")
|
||||
packSpinner.SetSpinSpeed(50)
|
||||
packSpinner.Start()
|
||||
|
||||
buildCommand := slicer.String()
|
||||
buildCommand.Add("mewn")
|
||||
|
||||
if buildMode == BuildModeBridge {
|
||||
// Ignore errors
|
||||
buildCommand.Add("-i")
|
||||
}
|
||||
|
||||
buildCommand.Add("build")
|
||||
|
||||
if binaryName != "" {
|
||||
buildCommand.Add("-o")
|
||||
buildCommand.Add(binaryName)
|
||||
}
|
||||
|
||||
// If we are forcing a rebuild
|
||||
if forceRebuild {
|
||||
buildCommand.Add("-a")
|
||||
}
|
||||
|
||||
// Setup ld flags
|
||||
ldflags := "-w -s "
|
||||
if buildMode == BuildModeDebug {
|
||||
ldflags = ""
|
||||
}
|
||||
|
||||
// Add windows flags
|
||||
if runtime.GOOS == "windows" {
|
||||
ldflags += "-H windowsgui "
|
||||
}
|
||||
|
||||
ldflags += "-X github.com/wailsapp/wails.BuildMode=" + buildMode
|
||||
|
||||
buildCommand.AddSlice([]string{"-ldflags", ldflags})
|
||||
err = NewProgramHelper().RunCommandArray(buildCommand.AsSlice())
|
||||
if err != nil {
|
||||
packSpinner.Error()
|
||||
return err
|
||||
}
|
||||
packSpinner.Success()
|
||||
|
||||
// packageApp
|
||||
if packageApp {
|
||||
err = PackageApplication(projectOptions)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// PackageApplication will attempt to package the application in a platform dependent way
|
||||
func PackageApplication(projectOptions *ProjectOptions) error {
|
||||
// Package app
|
||||
message := "Generating .app"
|
||||
if runtime.GOOS == "windows" {
|
||||
err := CheckWindres()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
message = "Generating resource bundle"
|
||||
}
|
||||
packageSpinner := spinner.New(message)
|
||||
packageSpinner.SetSpinSpeed(50)
|
||||
packageSpinner.Start()
|
||||
err := NewPackageHelper().Package(projectOptions)
|
||||
if err != nil {
|
||||
packageSpinner.Error()
|
||||
return err
|
||||
}
|
||||
packageSpinner.Success()
|
||||
return nil
|
||||
}
|
||||
|
||||
// BuildFrontend runs the given build command
|
||||
func BuildFrontend(buildCommand string) error {
|
||||
buildFESpinner := spinner.New("Building frontend...")
|
||||
buildFESpinner.SetSpinSpeed(50)
|
||||
buildFESpinner.Start()
|
||||
err := NewProgramHelper().RunCommand(buildCommand)
|
||||
if err != nil {
|
||||
buildFESpinner.Error()
|
||||
return err
|
||||
}
|
||||
buildFESpinner.Success()
|
||||
return nil
|
||||
}
|
||||
|
||||
// CheckMewn checks if mewn is installed and if not, attempts to fetch it
|
||||
func CheckMewn() (err error) {
|
||||
programHelper := NewProgramHelper()
|
||||
if !programHelper.IsInstalled("mewn") {
|
||||
buildSpinner := spinner.New()
|
||||
buildSpinner.SetSpinSpeed(50)
|
||||
buildSpinner.Start("Installing Mewn asset packer...")
|
||||
err := programHelper.InstallGoPackage("github.com/leaanthony/mewn/cmd/mewn")
|
||||
if err != nil {
|
||||
buildSpinner.Error()
|
||||
return err
|
||||
}
|
||||
buildSpinner.Success()
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// CheckWindres checks if Windres is installed and if not, aborts
|
||||
func CheckWindres() (err error) {
|
||||
if runtime.GOOS != "windows" {
|
||||
return nil
|
||||
}
|
||||
programHelper := NewProgramHelper()
|
||||
if !programHelper.IsInstalled("windres") {
|
||||
return fmt.Errorf("windres not installed. It comes by default with mingw. Ensure you have installed mingw correctly")
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// InstallFrontendDeps attempts to install the frontend dependencies based on the given options
|
||||
func InstallFrontendDeps(projectDir string, projectOptions *ProjectOptions, forceRebuild bool, caller string) error {
|
||||
|
||||
// Install frontend deps
|
||||
err := os.Chdir(projectOptions.FrontEnd.Dir)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
// Check if frontend deps have been updated
|
||||
feSpinner := spinner.New("Ensuring frontend dependencies are up to date (This may take a while)")
|
||||
feSpinner.SetSpinSpeed(50)
|
||||
feSpinner.Start()
|
||||
|
||||
requiresNPMInstall := true
|
||||
|
||||
// Read in package.json MD5
|
||||
fs := NewFSHelper()
|
||||
packageJSONMD5, err := fs.FileMD5("package.json")
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
const md5sumFile = "package.json.md5"
|
||||
|
||||
// If we aren't forcing the install and the md5sum file exists
|
||||
if !forceRebuild && fs.FileExists(md5sumFile) {
|
||||
// Yes - read contents
|
||||
savedMD5sum, err := fs.LoadAsString(md5sumFile)
|
||||
// File exists
|
||||
if err == nil {
|
||||
// Compare md5
|
||||
if savedMD5sum == packageJSONMD5 {
|
||||
// Same - no need for reinstall
|
||||
requiresNPMInstall = false
|
||||
feSpinner.Success("Skipped frontend dependencies (-f to force rebuild)")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Md5 sum package.json
|
||||
// Different? Build
|
||||
if requiresNPMInstall || forceRebuild {
|
||||
// Install dependencies
|
||||
err = NewProgramHelper().RunCommand(projectOptions.FrontEnd.Install)
|
||||
if err != nil {
|
||||
feSpinner.Error()
|
||||
return err
|
||||
}
|
||||
feSpinner.Success()
|
||||
|
||||
// Update md5sum file
|
||||
ioutil.WriteFile(md5sumFile, []byte(packageJSONMD5), 0644)
|
||||
}
|
||||
|
||||
// Install the bridge library
|
||||
err = InstallBridge(caller, projectDir, projectOptions)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
// Build frontend
|
||||
err = BuildFrontend(projectOptions.FrontEnd.Build)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// InstallBridge installs the relevant bridge javascript library
|
||||
func InstallBridge(caller string, projectDir string, projectOptions *ProjectOptions) error {
|
||||
bridgeFile := "wailsbridge.prod.js"
|
||||
if caller == "serve" {
|
||||
bridgeFile = "wailsbridge.js"
|
||||
}
|
||||
|
||||
// Copy bridge to project
|
||||
bridgeAssets := mewn.Group("../wailsruntimeassets/bridge/")
|
||||
bridgeFileData := bridgeAssets.Bytes(bridgeFile)
|
||||
bridgeFileTarget := filepath.Join(projectDir, projectOptions.FrontEnd.Dir, projectOptions.FrontEnd.Bridge, "wailsbridge.js")
|
||||
err := fs.CreateFile(bridgeFileTarget, bridgeFileData)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// ServeProject attempts to serve up the current project so that it may be connected to
|
||||
// via the Wails bridge
|
||||
func ServeProject(projectOptions *ProjectOptions, logger *Logger) error {
|
||||
go func() {
|
||||
time.Sleep(2 * time.Second)
|
||||
logger.Green(">>>>> To connect, you will need to run '" + projectOptions.FrontEnd.Serve + "' in the '" + projectOptions.FrontEnd.Dir + "' directory <<<<<")
|
||||
}()
|
||||
location, err := filepath.Abs(projectOptions.BinaryName)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
logger.Yellow("Serving Application: " + location)
|
||||
cmd := exec.Command(location)
|
||||
cmd.Stdout = os.Stdout
|
||||
cmd.Stderr = os.Stderr
|
||||
err = cmd.Run()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
53
cmd/linux.go
@@ -2,6 +2,9 @@ package cmd
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"regexp"
|
||||
"strings"
|
||||
)
|
||||
|
||||
@@ -10,9 +13,13 @@ type LinuxDistribution int
|
||||
|
||||
const (
|
||||
// Unknown is the catch-all distro
|
||||
Unknown LinuxDistribution = 0
|
||||
Unknown LinuxDistribution = iota
|
||||
// Ubuntu distribution
|
||||
Ubuntu LinuxDistribution = 1
|
||||
Ubuntu
|
||||
// Arch linux distribution
|
||||
Arch
|
||||
// RedHat linux distribution
|
||||
RedHat
|
||||
)
|
||||
|
||||
// DistroInfo contains all the information relating to a linux distribution
|
||||
@@ -49,6 +56,8 @@ func GetLinuxDistroInfo() *DistroInfo {
|
||||
switch value {
|
||||
case "Ubuntu":
|
||||
result.Distribution = Ubuntu
|
||||
case "Arch", "ManjaroLinux":
|
||||
result.Distribution = Arch
|
||||
}
|
||||
case "Description":
|
||||
result.Description = value
|
||||
@@ -60,20 +69,52 @@ func GetLinuxDistroInfo() *DistroInfo {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// check if /etc/os-release exists
|
||||
} else if _, err := os.Stat("/etc/os-release"); !os.IsNotExist(err) {
|
||||
// read /etc/os-release
|
||||
osRelease, _ := ioutil.ReadFile("/etc/os-release")
|
||||
// compile a regex to find NAME=distro
|
||||
re := regexp.MustCompile(`^NAME=(.*)\n`)
|
||||
// extract the distro name
|
||||
osName := string(re.FindSubmatch(osRelease)[1])
|
||||
// Check distro name against list of RedHat distros
|
||||
if osName == "Fedora" || osName == "CentOS" {
|
||||
//if it matches set result.Distribution to RedHat
|
||||
result.Distribution = RedHat
|
||||
}
|
||||
}
|
||||
return result
|
||||
}
|
||||
|
||||
// DpkgInstalled uses dpkg to see if a package is installed
|
||||
func DpkgInstalled(packageName string) (bool, error) {
|
||||
result := false
|
||||
program := NewProgramHelper()
|
||||
dpkg := program.FindProgram("dpkg")
|
||||
if dpkg == nil {
|
||||
return false, fmt.Errorf("cannot check dependencies: dpkg not found")
|
||||
}
|
||||
_, _, exitCode, _ := dpkg.Run("-L", packageName)
|
||||
result = exitCode == 0
|
||||
return result, nil
|
||||
return exitCode == 0, nil
|
||||
}
|
||||
|
||||
// PacmanInstalled uses pacman to see if a package is installed.
|
||||
func PacmanInstalled(packageName string) (bool, error) {
|
||||
program := NewProgramHelper()
|
||||
pacman := program.FindProgram("pacman")
|
||||
if pacman == nil {
|
||||
return false, fmt.Errorf("cannot check dependencies: pacman not found")
|
||||
}
|
||||
_, _, exitCode, _ := pacman.Run("-Qs", packageName)
|
||||
return exitCode == 0, nil
|
||||
}
|
||||
|
||||
// RpmInstalled uses rpm to see if a package is installed
|
||||
func RpmInstalled(packageName string) (bool, error) {
|
||||
program := NewProgramHelper()
|
||||
rpm := program.FindProgram("rpm")
|
||||
if rpm == nil {
|
||||
return false, fmt.Errorf("cannot check dependencies: rpm not found")
|
||||
}
|
||||
_, _, exitCode, _ := rpm.Run("--query", packageName)
|
||||
return exitCode == 0, nil
|
||||
}
|
||||
|
||||
50
cmd/log.go
@@ -9,52 +9,89 @@ import (
|
||||
|
||||
// Logger struct
|
||||
type Logger struct {
|
||||
errorOnly bool
|
||||
}
|
||||
|
||||
// NewLogger creates a new logger!
|
||||
func NewLogger() *Logger {
|
||||
return &Logger{}
|
||||
return &Logger{errorOnly: false}
|
||||
}
|
||||
|
||||
// SetErrorOnly ensures that only errors are logged out
|
||||
func (l *Logger) SetErrorOnly(errorOnly bool) {
|
||||
l.errorOnly = errorOnly
|
||||
}
|
||||
|
||||
// Yellow - Outputs yellow text
|
||||
func (l *Logger) Yellow(format string, a ...interface{}) {
|
||||
if l.errorOnly {
|
||||
return
|
||||
}
|
||||
color.New(color.FgHiYellow).PrintfFunc()(format+"\n", a...)
|
||||
}
|
||||
|
||||
// Yellowf - Outputs yellow text without the newline
|
||||
func (l *Logger) Yellowf(format string, a ...interface{}) {
|
||||
if l.errorOnly {
|
||||
return
|
||||
}
|
||||
|
||||
color.New(color.FgHiYellow).PrintfFunc()(format, a...)
|
||||
}
|
||||
|
||||
// Green - Outputs Green text
|
||||
func (l *Logger) Green(format string, a ...interface{}) {
|
||||
if l.errorOnly {
|
||||
return
|
||||
}
|
||||
|
||||
color.New(color.FgHiGreen).PrintfFunc()(format+"\n", a...)
|
||||
}
|
||||
|
||||
// White - Outputs White text
|
||||
func (l *Logger) White(format string, a ...interface{}) {
|
||||
if l.errorOnly {
|
||||
return
|
||||
}
|
||||
|
||||
color.New(color.FgHiWhite).PrintfFunc()(format+"\n", a...)
|
||||
}
|
||||
|
||||
// WhiteUnderline - Outputs White text with underline
|
||||
func (l *Logger) WhiteUnderline(format string, a ...interface{}) {
|
||||
if l.errorOnly {
|
||||
return
|
||||
}
|
||||
|
||||
l.White(format, a...)
|
||||
l.White(l.underline(format))
|
||||
}
|
||||
|
||||
// YellowUnderline - Outputs Yellow text with underline
|
||||
func (l *Logger) YellowUnderline(format string, a ...interface{}) {
|
||||
if l.errorOnly {
|
||||
return
|
||||
}
|
||||
|
||||
l.Yellow(format, a...)
|
||||
l.Yellow(l.underline(format))
|
||||
}
|
||||
|
||||
// underline returns a string of a line, the length of the message given to it
|
||||
func (l *Logger) underline(message string) string {
|
||||
if l.errorOnly {
|
||||
return ""
|
||||
}
|
||||
|
||||
return strings.Repeat("-", len(message))
|
||||
}
|
||||
|
||||
// Red - Outputs Red text
|
||||
func (l *Logger) Red(format string, a ...interface{}) {
|
||||
if l.errorOnly {
|
||||
return
|
||||
}
|
||||
|
||||
color.New(color.FgHiRed).PrintfFunc()(format+"\n", a...)
|
||||
}
|
||||
|
||||
@@ -63,6 +100,17 @@ func (l *Logger) Error(format string, a ...interface{}) {
|
||||
color.New(color.FgHiRed).PrintfFunc()("Error: "+format+"\n", a...)
|
||||
}
|
||||
|
||||
// PrintSmallBanner prints a condensed banner
|
||||
func (l *Logger) PrintSmallBanner(message ...string) {
|
||||
yellow := color.New(color.FgYellow).SprintFunc()
|
||||
red := color.New(color.FgRed).SprintFunc()
|
||||
msg := ""
|
||||
if len(message) > 0 {
|
||||
msg = " - " + message[0]
|
||||
}
|
||||
fmt.Printf("%s %s%s\n", yellow("Wails"), red(Version), msg)
|
||||
}
|
||||
|
||||
// PrintBanner prints the Wails banner before running commands
|
||||
func (l *Logger) PrintBanner() error {
|
||||
banner1 := ` _ __ _ __
|
||||
|
||||
259
cmd/package.go
Normal file
@@ -0,0 +1,259 @@
|
||||
package cmd
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"fmt"
|
||||
"image"
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"path"
|
||||
"path/filepath"
|
||||
"runtime"
|
||||
"strings"
|
||||
"text/template"
|
||||
"time"
|
||||
|
||||
"github.com/jackmordaunt/icns"
|
||||
)
|
||||
|
||||
// PackageHelper helps with the 'wails package' command
|
||||
type PackageHelper struct {
|
||||
fs *FSHelper
|
||||
log *Logger
|
||||
system *SystemHelper
|
||||
}
|
||||
|
||||
// NewPackageHelper creates a new PackageHelper!
|
||||
func NewPackageHelper() *PackageHelper {
|
||||
return &PackageHelper{
|
||||
fs: NewFSHelper(),
|
||||
log: NewLogger(),
|
||||
system: NewSystemHelper(),
|
||||
}
|
||||
}
|
||||
|
||||
type plistData struct {
|
||||
Title string
|
||||
Exe string
|
||||
PackageID string
|
||||
Version string
|
||||
Author string
|
||||
Date string
|
||||
}
|
||||
|
||||
func newPlistData(title, exe, packageID, version, author string) *plistData {
|
||||
now := time.Now().Format(time.RFC822)
|
||||
return &plistData{
|
||||
Title: title,
|
||||
Exe: exe,
|
||||
Version: version,
|
||||
PackageID: packageID,
|
||||
Author: author,
|
||||
Date: now,
|
||||
}
|
||||
}
|
||||
|
||||
func defaultString(val string, defaultVal string) string {
|
||||
if val != "" {
|
||||
return val
|
||||
}
|
||||
return defaultVal
|
||||
}
|
||||
|
||||
func (b *PackageHelper) getPackageFileBaseDir() string {
|
||||
// Calculate template base dir
|
||||
_, filename, _, _ := runtime.Caller(1)
|
||||
return filepath.Join(path.Dir(filename), "packages", runtime.GOOS)
|
||||
}
|
||||
|
||||
// Package the application into a platform specific package
|
||||
func (b *PackageHelper) Package(po *ProjectOptions) error {
|
||||
switch runtime.GOOS {
|
||||
case "darwin":
|
||||
// Check we have the exe
|
||||
if !b.fs.FileExists(po.BinaryName) {
|
||||
return fmt.Errorf("cannot bundle non-existent binary file '%s'. Please build with 'wails build' first", po.BinaryName)
|
||||
}
|
||||
return b.packageOSX(po)
|
||||
case "windows":
|
||||
return b.PackageWindows(po, false)
|
||||
case "linux":
|
||||
return fmt.Errorf("linux is not supported at this time. Please see https://github.com/wailsapp/wails/issues/2")
|
||||
default:
|
||||
return fmt.Errorf("platform '%s' not supported for bundling yet", runtime.GOOS)
|
||||
}
|
||||
}
|
||||
|
||||
// Package the application for OSX
|
||||
func (b *PackageHelper) packageOSX(po *ProjectOptions) error {
|
||||
|
||||
system := NewSystemHelper()
|
||||
config, err := system.LoadConfig()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
name := defaultString(po.Name, "WailsTest")
|
||||
exe := defaultString(po.BinaryName, name)
|
||||
version := defaultString(po.Version, "0.1.0")
|
||||
author := defaultString(config.Name, "Anonymous")
|
||||
packageID := strings.Join([]string{"wails", name, version}, ".")
|
||||
plistData := newPlistData(name, exe, packageID, version, author)
|
||||
appname := po.Name + ".app"
|
||||
|
||||
// Check binary exists
|
||||
source := path.Join(b.fs.Cwd(), exe)
|
||||
if !b.fs.FileExists(source) {
|
||||
// We need to build!
|
||||
return fmt.Errorf("Target '%s' not available. Has it been compiled yet?", exe)
|
||||
}
|
||||
|
||||
// Remove the existing package
|
||||
os.RemoveAll(appname)
|
||||
|
||||
exeDir := path.Join(b.fs.Cwd(), appname, "/Contents/MacOS")
|
||||
b.fs.MkDirs(exeDir, 0755)
|
||||
resourceDir := path.Join(b.fs.Cwd(), appname, "/Contents/Resources")
|
||||
b.fs.MkDirs(resourceDir, 0755)
|
||||
tmpl := template.New("infoPlist")
|
||||
plistFile := filepath.Join(b.getPackageFileBaseDir(), "info.plist")
|
||||
infoPlist, err := ioutil.ReadFile(plistFile)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
tmpl.Parse(string(infoPlist))
|
||||
|
||||
// Write the template to a buffer
|
||||
var tpl bytes.Buffer
|
||||
err = tmpl.Execute(&tpl, plistData)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
filename := path.Join(b.fs.Cwd(), appname, "Contents", "Info.plist")
|
||||
err = ioutil.WriteFile(filename, tpl.Bytes(), 0644)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
// Copy executable
|
||||
target := path.Join(exeDir, exe)
|
||||
err = b.fs.CopyFile(source, target)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
err = os.Chmod(target, 0755)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
err = b.packageIconOSX(resourceDir)
|
||||
return err
|
||||
}
|
||||
|
||||
// PackageWindows packages the application for windows platforms
|
||||
func (b *PackageHelper) PackageWindows(po *ProjectOptions, cleanUp bool) error {
|
||||
basename := strings.TrimSuffix(po.BinaryName, ".exe")
|
||||
|
||||
// Copy icon
|
||||
tgtIconFile := filepath.Join(b.fs.Cwd(), basename+".ico")
|
||||
if !b.fs.FileExists(tgtIconFile) {
|
||||
srcIconfile := filepath.Join(b.getPackageFileBaseDir(), "wails.ico")
|
||||
err := b.fs.CopyFile(srcIconfile, tgtIconFile)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
// Copy manifest
|
||||
tgtManifestFile := filepath.Join(b.fs.Cwd(), basename+".exe.manifest")
|
||||
if !b.fs.FileExists(tgtManifestFile) {
|
||||
srcManifestfile := filepath.Join(b.getPackageFileBaseDir(), "wails.exe.manifest")
|
||||
err := b.fs.CopyFile(srcManifestfile, tgtManifestFile)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
// Copy rc file
|
||||
tgtRCFile := filepath.Join(b.fs.Cwd(), basename+".rc")
|
||||
if !b.fs.FileExists(tgtRCFile) {
|
||||
srcRCfile := filepath.Join(b.getPackageFileBaseDir(), "wails.rc")
|
||||
rcfilebytes, err := ioutil.ReadFile(srcRCfile)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
rcfiledata := strings.Replace(string(rcfilebytes), "$NAME$", basename, -1)
|
||||
err = ioutil.WriteFile(tgtRCFile, []byte(rcfiledata), 0755)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
// Build syso
|
||||
sysofile := filepath.Join(b.fs.Cwd(), basename+"-res.syso")
|
||||
windresCommand := []string{"windres", "-o", sysofile, tgtRCFile}
|
||||
err := NewProgramHelper().RunCommandArray(windresCommand)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
// clean up
|
||||
if cleanUp {
|
||||
filesToDelete := []string{tgtIconFile, tgtManifestFile, tgtRCFile, sysofile}
|
||||
err := b.fs.RemoveFiles(filesToDelete)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (b *PackageHelper) copyIcon(resourceDir string) (string, error) {
|
||||
|
||||
// TODO: Read this from project.json
|
||||
const appIconFilename = "appicon.png"
|
||||
srcIcon := path.Join(b.fs.Cwd(), appIconFilename)
|
||||
|
||||
// Check if appicon.png exists
|
||||
if !b.fs.FileExists(srcIcon) {
|
||||
|
||||
// Install default icon
|
||||
iconfile := filepath.Join(b.getPackageFileBaseDir(), "icon.png")
|
||||
iconData, err := ioutil.ReadFile(iconfile)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
err = ioutil.WriteFile(srcIcon, iconData, 0644)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
}
|
||||
return srcIcon, nil
|
||||
}
|
||||
|
||||
func (b *PackageHelper) packageIconOSX(resourceDir string) error {
|
||||
|
||||
srcIcon, err := b.copyIcon(resourceDir)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
tgtBundle := path.Join(resourceDir, "iconfile.icns")
|
||||
imageFile, err := os.Open(srcIcon)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
defer imageFile.Close()
|
||||
srcImg, _, err := image.Decode(imageFile)
|
||||
if err != nil {
|
||||
return err
|
||||
|
||||
}
|
||||
dest, err := os.Create(tgtBundle)
|
||||
if err != nil {
|
||||
return err
|
||||
|
||||
}
|
||||
defer dest.Close()
|
||||
return icns.Encode(dest, srcImg)
|
||||
}
|
||||
BIN
cmd/packages/darwin/icon.png
Normal file
|
After Width: | Height: | Size: 106 KiB |
11
cmd/packages/darwin/info.plist
Normal file
@@ -0,0 +1,11 @@
|
||||
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
|
||||
<plist version="1.0"><dict>
|
||||
<key>CFBundleName</key><string>{{.Title}}</string>
|
||||
<key>CFBundleExecutable</key><string>{{.Exe}}</string>
|
||||
<key>CFBundleIdentifier</key><string>{{.PackageID}}</string>
|
||||
<key>CFBundleVersion</key><string>{{.Version}}</string>
|
||||
<key>CFBundleGetInfoString</key><string>Built by {{.Author}} at {{.Date}} using Wails (https://wails.app)</string>
|
||||
<key>CFBundleShortVersionString</key><string>{{.Version}}</string>
|
||||
<key>CFBundleIconFile</key><string>iconfile</string>
|
||||
<key>NSHighResolutionCapable</key><string>true</string>
|
||||
</dict></plist>
|
||||
BIN
cmd/packages/windows/icon.png
Normal file
|
After Width: | Height: | Size: 106 KiB |
12
cmd/packages/windows/wails.exe.manifest
Normal file
@@ -0,0 +1,12 @@
|
||||
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
|
||||
<assembly manifestVersion="1.0" xmlns="urn:schemas-microsoft-com:asm.v1" xmlns:asmv3="urn:schemas-microsoft-com:asm.v3">
|
||||
<assemblyIdentity type="win32" name="MyApplication" version="1.0.0.0" processorArchitecture="amd64"/>
|
||||
|
||||
<asmv3:application>
|
||||
<asmv3:windowsSettings>
|
||||
<dpiAware xmlns="http://schemas.microsoft.com/SMI/2005/WindowsSettings">true/pm</dpiAware> <!-- fallback for Windows 7 and 8 -->
|
||||
<dpiAwareness xmlns="http://schemas.microsoft.com/SMI/2016/WindowsSettings">permonitorv2,permonitor</dpiAwareness> <!-- falls back to per-monitor if per-monitor v2 is not supported -->
|
||||
<gdiScaling xmlns="http://schemas.microsoft.com/SMI/2017/WindowsSettings">true</gdiScaling> <!-- enables GDI DPI scaling -->
|
||||
</asmv3:windowsSettings>
|
||||
</asmv3:application>
|
||||
</assembly>
|
||||
BIN
cmd/packages/windows/wails.ico
Normal file
|
After Width: | Height: | Size: 315 KiB |
2
cmd/packages/windows/wails.rc
Normal file
@@ -0,0 +1,2 @@
|
||||
100 ICON "$NAME$.ico"
|
||||
100 24 "$NAME$.exe.manifest"
|
||||
@@ -97,6 +97,12 @@ func getRequiredLibrariesLinux() (*Prerequisites, error) {
|
||||
case Ubuntu:
|
||||
result.Add(newPrerequisite("libgtk-3-dev", "Please install with `sudo apt install libgtk-3-dev` and try again"))
|
||||
result.Add(newPrerequisite("libwebkit2gtk-4.0-dev", "Please install with `sudo apt install libwebkit2gtk-4.0-dev` and try again"))
|
||||
case Arch:
|
||||
result.Add(newPrerequisite("gtk3", "Please install with `sudo pacman -S gtk3` and try again"))
|
||||
result.Add(newPrerequisite("webkit2gtk", "Please install with `sudo pacman -S webkit2gtk` and try again"))
|
||||
case RedHat:
|
||||
result.Add(newPrerequisite("gtk3-devel", "Please install with `sudo yum install gtk3-devel` and try again"))
|
||||
result.Add(newPrerequisite("webkit2gtk3-devel", "Please install with `sudo yum install webkit2gtk3-devel` and try again"))
|
||||
default:
|
||||
result.Add(newPrerequisite("libgtk-3-dev", "Please install with your system package manager and try again"))
|
||||
result.Add(newPrerequisite("libwebkit2gtk-4.0-dev", "Please install with your system package manager and try again"))
|
||||
|
||||
@@ -2,17 +2,23 @@ package cmd
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"fmt"
|
||||
"os/exec"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
"syscall"
|
||||
)
|
||||
|
||||
// ProgramHelper - Utility functions around installed applications
|
||||
type ProgramHelper struct{}
|
||||
type ProgramHelper struct {
|
||||
shell *ShellHelper
|
||||
}
|
||||
|
||||
// NewProgramHelper - Creates a new ProgramHelper
|
||||
func NewProgramHelper() *ProgramHelper {
|
||||
return &ProgramHelper{}
|
||||
return &ProgramHelper{
|
||||
shell: NewShellHelper(),
|
||||
}
|
||||
}
|
||||
|
||||
// IsInstalled tries to determine if the given binary name is installed
|
||||
@@ -50,7 +56,7 @@ func (p *Program) GetFullPathToBinary() (string, error) {
|
||||
}
|
||||
|
||||
// Run will execute the program with the given parameters
|
||||
// Returns stdout + stderr as strings and an error if one occured
|
||||
// Returns stdout + stderr as strings and an error if one occurred
|
||||
func (p *Program) Run(vars ...string) (stdout, stderr string, exitCode int, err error) {
|
||||
command, err := p.GetFullPathToBinary()
|
||||
if err != nil {
|
||||
@@ -83,3 +89,42 @@ func (p *Program) Run(vars ...string) (stdout, stderr string, exitCode int, err
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
// InstallGoPackage installs the given Go package
|
||||
func (p *ProgramHelper) InstallGoPackage(packageName string) error {
|
||||
args := strings.Split("get "+packageName, " ")
|
||||
_, stderr, err := p.shell.Run("go", args...)
|
||||
if err != nil {
|
||||
fmt.Println(stderr)
|
||||
}
|
||||
return err
|
||||
}
|
||||
|
||||
// RunCommand runs the given command
|
||||
func (p *ProgramHelper) RunCommand(command string) error {
|
||||
args := strings.Split(command, " ")
|
||||
return p.RunCommandArray(args)
|
||||
}
|
||||
|
||||
// RunCommandArray runs the command specified in the array
|
||||
func (p *ProgramHelper) RunCommandArray(args []string, dir ...string) error {
|
||||
program := args[0]
|
||||
// TODO: Run FindProgram here and get the full path to the exe
|
||||
program, err := exec.LookPath(program)
|
||||
if err != nil {
|
||||
fmt.Printf("ERROR: Looks like '%s' isn't installed. Please install and try again.", program)
|
||||
return err
|
||||
}
|
||||
args = args[1:]
|
||||
var stderr string
|
||||
// fmt.Printf("RunCommandArray = %s %+v\n", program, args)
|
||||
if len(dir) > 0 {
|
||||
_, stderr, err = p.shell.RunInDirectory(dir[0], program, args...)
|
||||
} else {
|
||||
_, stderr, err = p.shell.Run(program, args...)
|
||||
}
|
||||
if err != nil {
|
||||
fmt.Println(stderr)
|
||||
}
|
||||
return err
|
||||
}
|
||||
|
||||
351
cmd/project.go
@@ -4,10 +4,12 @@ import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"runtime"
|
||||
"strings"
|
||||
|
||||
"github.com/AlecAivazis/survey"
|
||||
"github.com/leaanthony/slicer"
|
||||
)
|
||||
|
||||
type author struct {
|
||||
@@ -19,6 +21,8 @@ type frontend struct {
|
||||
Dir string `json:"dir"`
|
||||
Install string `json:"install"`
|
||||
Build string `json:"build"`
|
||||
Bridge string `json:"bridge"`
|
||||
Serve string `json:"serve"`
|
||||
}
|
||||
|
||||
type framework struct {
|
||||
@@ -46,22 +50,14 @@ func NewProjectHelper() *ProjectHelper {
|
||||
// GenerateProject generates a new project using the options given
|
||||
func (ph *ProjectHelper) GenerateProject(projectOptions *ProjectOptions) error {
|
||||
|
||||
fs := NewFSHelper()
|
||||
exists, err := ph.templates.TemplateExists(projectOptions.Template)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if !exists {
|
||||
return fmt.Errorf("template '%s' is invalid", projectOptions.Template)
|
||||
}
|
||||
|
||||
// Calculate project path
|
||||
projectPath, err := filepath.Abs(projectOptions.OutputDirectory)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
_ = projectPath
|
||||
|
||||
if fs.DirExists(projectPath) {
|
||||
return fmt.Errorf("directory '%s' already exists", projectPath)
|
||||
}
|
||||
@@ -82,11 +78,27 @@ func (ph *ProjectHelper) GenerateProject(projectOptions *ProjectOptions) error {
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
// // If we are on windows, dump a windows_resource.json
|
||||
// if runtime.GOOS == "windows" {
|
||||
// ph.GenerateWindowsResourceConfig(projectOptions)
|
||||
// }
|
||||
|
||||
ph.log.Yellow("Project '%s' generated in directory '%s'!", projectOptions.Name, projectOptions.OutputDirectory)
|
||||
ph.log.Yellow("To compile the project, run 'wails build' in the project directory.")
|
||||
return nil
|
||||
}
|
||||
|
||||
// // GenerateWindowsResourceConfig generates the default windows resource file
|
||||
// func (ph *ProjectHelper) GenerateWindowsResourceConfig(po *ProjectOptions) {
|
||||
|
||||
// fmt.Println(buffer.String())
|
||||
|
||||
// // vi.Build()
|
||||
// // vi.Walk()
|
||||
// // err := vi.WriteSyso(outPath, runtime.GOARCH)
|
||||
// }
|
||||
|
||||
// LoadProjectConfig loads the project config from the given directory
|
||||
func (ph *ProjectHelper) LoadProjectConfig(dir string) (*ProjectOptions, error) {
|
||||
po := ph.NewProjectOptions()
|
||||
@@ -97,15 +109,14 @@ func (ph *ProjectHelper) LoadProjectConfig(dir string) (*ProjectOptions, error)
|
||||
// NewProjectOptions creates a new default set of project options
|
||||
func (ph *ProjectHelper) NewProjectOptions() *ProjectOptions {
|
||||
result := ProjectOptions{
|
||||
Name: "",
|
||||
Description: "Enter your project description",
|
||||
Version: "0.1.0",
|
||||
BinaryName: "",
|
||||
system: NewSystemHelper(),
|
||||
log: NewLogger(),
|
||||
templates: NewTemplateHelper(),
|
||||
templateNameMap: make(map[string]string),
|
||||
Author: &author{},
|
||||
Name: "",
|
||||
Description: "Enter your project description",
|
||||
Version: "0.1.0",
|
||||
BinaryName: "",
|
||||
system: NewSystemHelper(),
|
||||
log: NewLogger(),
|
||||
templates: NewTemplateHelper(),
|
||||
Author: &author{},
|
||||
}
|
||||
|
||||
// Populate system config
|
||||
@@ -118,193 +129,94 @@ func (ph *ProjectHelper) NewProjectOptions() *ProjectOptions {
|
||||
return &result
|
||||
}
|
||||
|
||||
// SelectQuestion creates a new select type question for Survey
|
||||
func SelectQuestion(name, message string, options []string, defaultValue string, required bool) *survey.Question {
|
||||
result := survey.Question{
|
||||
Name: name,
|
||||
Prompt: &survey.Select{
|
||||
Message: message,
|
||||
Options: options,
|
||||
Default: defaultValue,
|
||||
},
|
||||
}
|
||||
if required {
|
||||
result.Validate = survey.Required
|
||||
}
|
||||
return &result
|
||||
}
|
||||
|
||||
// InputQuestion creates a new input type question for Survey
|
||||
func InputQuestion(name, message string, defaultValue string, required bool) *survey.Question {
|
||||
result := survey.Question{
|
||||
Name: name,
|
||||
Prompt: &survey.Input{
|
||||
Message: message + ":",
|
||||
Default: defaultValue,
|
||||
},
|
||||
}
|
||||
if required {
|
||||
result.Validate = survey.Required
|
||||
}
|
||||
return &result
|
||||
}
|
||||
|
||||
// ProjectOptions holds all the options available for a project
|
||||
type ProjectOptions struct {
|
||||
Name string `json:"name"`
|
||||
Description string `json:"description"`
|
||||
Author *author `json:"author,omitempty"`
|
||||
Version string `json:"version"`
|
||||
OutputDirectory string `json:"-"`
|
||||
UseDefaults bool `json:"-"`
|
||||
Template string `json:"-"`
|
||||
BinaryName string `json:"binaryname"`
|
||||
FrontEnd *frontend `json:"frontend,omitempty"`
|
||||
NPMProjectName string `json:"-"`
|
||||
Framework *framework `json:"framework,omitempty"`
|
||||
system *SystemHelper
|
||||
log *Logger
|
||||
templates *TemplateHelper
|
||||
templateNameMap map[string]string // Converts template prompt text to template name
|
||||
Name string `json:"name"`
|
||||
Description string `json:"description"`
|
||||
Author *author `json:"author,omitempty"`
|
||||
Version string `json:"version"`
|
||||
OutputDirectory string `json:"-"`
|
||||
UseDefaults bool `json:"-"`
|
||||
Template string `json:"-"`
|
||||
BinaryName string `json:"binaryname"`
|
||||
FrontEnd *frontend `json:"frontend,omitempty"`
|
||||
NPMProjectName string `json:"-"`
|
||||
system *SystemHelper
|
||||
log *Logger
|
||||
templates *TemplateHelper
|
||||
selectedTemplate *TemplateDetails
|
||||
}
|
||||
|
||||
// Defaults sets the default project template
|
||||
func (po *ProjectOptions) Defaults() {
|
||||
po.Template = "basic"
|
||||
po.Template = "vuebasic"
|
||||
}
|
||||
|
||||
// PromptForInputs asks the user to input project details
|
||||
func (po *ProjectOptions) PromptForInputs() error {
|
||||
|
||||
var questions []*survey.Question
|
||||
fs := NewFSHelper()
|
||||
processProjectName(po)
|
||||
|
||||
if po.Name == "" {
|
||||
questions = append(questions, InputQuestion("Name", "The name of the project", "My Project", true))
|
||||
} else {
|
||||
fmt.Println("Project Name: " + po.Name)
|
||||
}
|
||||
|
||||
if po.BinaryName == "" {
|
||||
var binaryNameComputed string
|
||||
if po.Name != "" {
|
||||
binaryNameComputed = strings.ToLower(po.Name)
|
||||
binaryNameComputed = strings.Replace(binaryNameComputed, " ", "-", -1)
|
||||
binaryNameComputed = strings.Replace(binaryNameComputed, string(filepath.Separator), "-", -1)
|
||||
binaryNameComputed = strings.Replace(binaryNameComputed, ":", "-", -1)
|
||||
}
|
||||
questions = append(questions, InputQuestion("BinaryName", "The output binary name", binaryNameComputed, true))
|
||||
} else {
|
||||
fmt.Println("Output binary Name: " + po.BinaryName)
|
||||
}
|
||||
|
||||
if po.OutputDirectory != "" {
|
||||
projectPath, err := filepath.Abs(po.OutputDirectory)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if fs.DirExists(projectPath) {
|
||||
return fmt.Errorf("directory '%s' already exists", projectPath)
|
||||
}
|
||||
|
||||
fmt.Println("Project Directory: " + po.OutputDirectory)
|
||||
} else {
|
||||
questions = append(questions, InputQuestion("OutputDirectory", "Project directory name", "", true))
|
||||
processBinaryName(po)
|
||||
|
||||
err := processOutputDirectory(po)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
// Process Templates
|
||||
templateList := slicer.Interface()
|
||||
options := slicer.String()
|
||||
templateDetails, err := po.templates.GetTemplateDetails()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
templates := []string{}
|
||||
// Add a Custom Template
|
||||
// templates = append(templates, "Custom - Choose your own CSS framework")
|
||||
for templateName, templateDetails := range templateDetails {
|
||||
templateText := templateName
|
||||
// Check if metadata json exists
|
||||
if templateDetails.Metadata != nil {
|
||||
shortdescription := templateDetails.Metadata["shortdescription"]
|
||||
if shortdescription != "" {
|
||||
templateText += " - " + shortdescription.(string)
|
||||
}
|
||||
}
|
||||
templates = append(templates, templateText)
|
||||
po.templateNameMap[templateText] = templateName
|
||||
}
|
||||
|
||||
if po.Template != "" {
|
||||
if _, ok := templateDetails[po.Template]; !ok {
|
||||
po.log.Error("Template '%s' invalid.", po.Template)
|
||||
questions = append(questions, SelectQuestion("Template", "Select template", templates, templates[0], true))
|
||||
// Check template is valid if given
|
||||
if templateDetails[po.Template] == nil {
|
||||
keys := make([]string, 0, len(templateDetails))
|
||||
for k := range templateDetails {
|
||||
keys = append(keys, k)
|
||||
}
|
||||
return fmt.Errorf("invalid template name '%s'. Valid options: %s", po.Template, strings.Join(keys, ", "))
|
||||
}
|
||||
po.selectedTemplate = templateDetails[po.Template]
|
||||
} else {
|
||||
questions = append(questions, SelectQuestion("Template", "Select template", templates, templates[0], true))
|
||||
|
||||
for _, templateDetail := range templateDetails {
|
||||
templateList.Add(templateDetail)
|
||||
options.Add(fmt.Sprintf("%s - %s", templateDetail.Metadata.Name, templateDetail.Metadata.ShortDescription))
|
||||
}
|
||||
|
||||
templateIndex := 0
|
||||
|
||||
if len(options.AsSlice()) > 1 {
|
||||
templateIndex = PromptSelection("Please select a template", options.AsSlice(), 0)
|
||||
}
|
||||
|
||||
if len(templateList.AsSlice()) == 0 {
|
||||
return fmt.Errorf("aborting: no templates found")
|
||||
}
|
||||
|
||||
// After selection do this....
|
||||
po.selectedTemplate = templateList.AsSlice()[templateIndex].(*TemplateDetails)
|
||||
}
|
||||
|
||||
err = survey.Ask(questions, po)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
fmt.Println("Template: " + po.selectedTemplate.Metadata.Name)
|
||||
|
||||
// Setup NPM Project name
|
||||
po.NPMProjectName = strings.Replace(po.Name, " ", "_", -1)
|
||||
|
||||
// If we selected custom, prompt for framework
|
||||
if po.Template == "custom - Choose your own CSS Framework" {
|
||||
// Ask for the framework
|
||||
var frameworkName string
|
||||
frameworks, err := GetFrameworks()
|
||||
frameworkNames := []string{}
|
||||
metadataMap := make(map[string]*FrameworkMetadata)
|
||||
for _, frameworkMetadata := range frameworks {
|
||||
frameworkDetails := fmt.Sprintf("%s - %s", frameworkMetadata.Name, frameworkMetadata.Description)
|
||||
metadataMap[frameworkDetails] = frameworkMetadata
|
||||
frameworkNames = append(frameworkNames, frameworkDetails)
|
||||
}
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
var frameworkQuestion []*survey.Question
|
||||
frameworkQuestion = append(frameworkQuestion, SelectQuestion("Framework", "Select framework", frameworkNames, frameworkNames[0], true))
|
||||
err = survey.Ask(frameworkQuestion, &frameworkName)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
// Get metadata
|
||||
metadata := metadataMap[frameworkName]
|
||||
|
||||
// Add to project config
|
||||
po.Framework = &framework{
|
||||
Name: metadata.Name,
|
||||
BuildTag: metadata.BuildTag,
|
||||
}
|
||||
|
||||
}
|
||||
po.NPMProjectName = strings.ToLower(strings.Replace(po.Name, " ", "_", -1))
|
||||
|
||||
// Fix template name
|
||||
if po.templateNameMap[po.Template] != "" {
|
||||
po.Template = po.templateNameMap[po.Template]
|
||||
}
|
||||
po.Template = strings.Split(po.selectedTemplate.Path, string(os.PathSeparator))[0]
|
||||
|
||||
// Populate template details
|
||||
templateMetadata := templateDetails[po.Template].Metadata
|
||||
if templateMetadata["frontenddir"] != nil {
|
||||
po.FrontEnd = &frontend{}
|
||||
po.FrontEnd.Dir = templateMetadata["frontenddir"].(string)
|
||||
}
|
||||
if templateMetadata["install"] != nil {
|
||||
if po.FrontEnd == nil {
|
||||
return fmt.Errorf("install set in template metadata but not frontenddir")
|
||||
}
|
||||
po.FrontEnd.Install = templateMetadata["install"].(string)
|
||||
}
|
||||
if templateMetadata["build"] != nil {
|
||||
if po.FrontEnd == nil {
|
||||
return fmt.Errorf("build set in template metadata but not frontenddir")
|
||||
}
|
||||
po.FrontEnd.Build = templateMetadata["build"].(string)
|
||||
// // Populate template details
|
||||
templateMetadata := po.selectedTemplate.Metadata
|
||||
|
||||
err = processTemplateMetadata(templateMetadata, po)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return nil
|
||||
@@ -337,3 +249,86 @@ func (po *ProjectOptions) LoadConfig(projectDir string) error {
|
||||
}
|
||||
return json.Unmarshal(rawBytes, po)
|
||||
}
|
||||
|
||||
func computeBinaryName(projectName string) string {
|
||||
if projectName == "" {
|
||||
return ""
|
||||
}
|
||||
var binaryNameComputed = strings.ToLower(projectName)
|
||||
binaryNameComputed = strings.Replace(binaryNameComputed, " ", "-", -1)
|
||||
binaryNameComputed = strings.Replace(binaryNameComputed, string(filepath.Separator), "-", -1)
|
||||
binaryNameComputed = strings.Replace(binaryNameComputed, ":", "-", -1)
|
||||
return binaryNameComputed
|
||||
}
|
||||
|
||||
func processOutputDirectory(po *ProjectOptions) error {
|
||||
// po.OutputDirectory
|
||||
if po.OutputDirectory == "" {
|
||||
po.OutputDirectory = PromptRequired("Project directory name", computeBinaryName(po.Name))
|
||||
}
|
||||
projectPath, err := filepath.Abs(po.OutputDirectory)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if NewFSHelper().DirExists(projectPath) {
|
||||
return fmt.Errorf("directory '%s' already exists", projectPath)
|
||||
}
|
||||
|
||||
fmt.Println("Project Directory: " + po.OutputDirectory)
|
||||
return nil
|
||||
}
|
||||
|
||||
func processProjectName(po *ProjectOptions) {
|
||||
if po.Name == "" {
|
||||
po.Name = Prompt("The name of the project", "My Project")
|
||||
}
|
||||
fmt.Println("Project Name: " + po.Name)
|
||||
}
|
||||
|
||||
func processBinaryName(po *ProjectOptions) {
|
||||
if po.BinaryName == "" {
|
||||
var binaryNameComputed = computeBinaryName(po.Name)
|
||||
po.BinaryName = Prompt("The output binary name", binaryNameComputed)
|
||||
if runtime.GOOS == "windows" {
|
||||
if !strings.HasSuffix(po.BinaryName, ".exe") {
|
||||
po.BinaryName += ".exe"
|
||||
}
|
||||
}
|
||||
}
|
||||
fmt.Println("Output binary Name: " + po.BinaryName)
|
||||
}
|
||||
|
||||
func processTemplateMetadata(templateMetadata *TemplateMetadata, po *ProjectOptions) error {
|
||||
if templateMetadata.FrontendDir != "" {
|
||||
po.FrontEnd = &frontend{}
|
||||
po.FrontEnd.Dir = templateMetadata.FrontendDir
|
||||
}
|
||||
if templateMetadata.Install != "" {
|
||||
if po.FrontEnd == nil {
|
||||
return fmt.Errorf("install set in template metadata but not frontenddir")
|
||||
}
|
||||
po.FrontEnd.Install = templateMetadata.Install
|
||||
}
|
||||
if templateMetadata.Build != "" {
|
||||
if po.FrontEnd == nil {
|
||||
return fmt.Errorf("build set in template metadata but not frontenddir")
|
||||
}
|
||||
po.FrontEnd.Build = templateMetadata.Build
|
||||
}
|
||||
|
||||
if templateMetadata.Bridge != "" {
|
||||
if po.FrontEnd == nil {
|
||||
return fmt.Errorf("bridge set in template metadata but not frontenddir")
|
||||
}
|
||||
po.FrontEnd.Bridge = templateMetadata.Bridge
|
||||
}
|
||||
|
||||
if templateMetadata.Serve != "" {
|
||||
if po.FrontEnd == nil {
|
||||
return fmt.Errorf("serve set in template metadata but not frontenddir")
|
||||
}
|
||||
po.FrontEnd.Serve = templateMetadata.Serve
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
85
cmd/prompt.go
Normal file
@@ -0,0 +1,85 @@
|
||||
package cmd
|
||||
|
||||
import (
|
||||
"bufio"
|
||||
"fmt"
|
||||
"os"
|
||||
"runtime"
|
||||
"strconv"
|
||||
"strings"
|
||||
)
|
||||
|
||||
// Prompt asks the user for a value
|
||||
func Prompt(question string, defaultValue ...string) string {
|
||||
var answer string
|
||||
|
||||
if len(defaultValue) > 0 {
|
||||
answer = defaultValue[0]
|
||||
question = fmt.Sprintf("%s (%s)", question, answer)
|
||||
}
|
||||
fmt.Printf(question + ": ")
|
||||
reader := bufio.NewReader(os.Stdin)
|
||||
input, _ := reader.ReadString('\n')
|
||||
EOL := "\n"
|
||||
if runtime.GOOS == "windows" {
|
||||
EOL = "\r\n"
|
||||
}
|
||||
input = strings.Replace(input, EOL, "", -1)
|
||||
|
||||
if input != "" {
|
||||
answer = input
|
||||
}
|
||||
|
||||
return answer
|
||||
}
|
||||
|
||||
// PromptRequired calls Prompt repeatedly until a value is given
|
||||
func PromptRequired(question string, defaultValue ...string) string {
|
||||
for {
|
||||
result := Prompt(question, defaultValue...)
|
||||
if result != "" {
|
||||
return result
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// PromptSelection asks the user to choose an option
|
||||
func PromptSelection(question string, options []string, optionalDefaultValue ...int) int {
|
||||
|
||||
defaultValue := -1
|
||||
message := "Please choose an option"
|
||||
fmt.Println(question + ":")
|
||||
|
||||
if len(optionalDefaultValue) > 0 {
|
||||
defaultValue = optionalDefaultValue[0] + 1
|
||||
message = fmt.Sprintf("%s [%d]", message, defaultValue)
|
||||
}
|
||||
|
||||
for index, option := range options {
|
||||
fmt.Printf(" %d: %s\n", index+1, option)
|
||||
}
|
||||
|
||||
selectedValue := -1
|
||||
|
||||
for {
|
||||
choice := Prompt(message)
|
||||
if choice == "" && defaultValue > -1 {
|
||||
selectedValue = defaultValue - 1
|
||||
break
|
||||
}
|
||||
|
||||
// index
|
||||
number, err := strconv.Atoi(choice)
|
||||
if err == nil {
|
||||
if number > 0 && number <= len(options) {
|
||||
selectedValue = number - 1
|
||||
break
|
||||
} else {
|
||||
continue
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return selectedValue
|
||||
}
|
||||
98
cmd/semver.go
Normal file
@@ -0,0 +1,98 @@
|
||||
package cmd
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"github.com/masterminds/semver"
|
||||
)
|
||||
|
||||
// SemanticVersion is a struct containing a semantic version
|
||||
type SemanticVersion struct {
|
||||
Version *semver.Version
|
||||
}
|
||||
|
||||
// NewSemanticVersion creates a new SemanticVersion object with the given version string
|
||||
func NewSemanticVersion(version string) (*SemanticVersion, error) {
|
||||
semverVersion, err := semver.NewVersion(version)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &SemanticVersion{
|
||||
Version: semverVersion,
|
||||
}, nil
|
||||
}
|
||||
|
||||
// IsRelease returns true if it's a release version
|
||||
func (s *SemanticVersion) IsRelease() bool {
|
||||
return len(s.Version.Prerelease()) == 0 && len(s.Version.Metadata()) == 0
|
||||
}
|
||||
|
||||
// IsPreRelease returns true if it's a prerelease version
|
||||
func (s *SemanticVersion) IsPreRelease() bool {
|
||||
return len(s.Version.Prerelease()) > 0
|
||||
}
|
||||
|
||||
func (s *SemanticVersion) String() string {
|
||||
return s.Version.String()
|
||||
}
|
||||
|
||||
// IsGreaterThan returns true if this version is greater than the given version
|
||||
func (s *SemanticVersion) IsGreaterThan(version *SemanticVersion) (bool, error) {
|
||||
// Set up new constraint
|
||||
constraint, err := semver.NewConstraint("> " + version.Version.String())
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
|
||||
// Check if the desired one is greater than the requested on
|
||||
success, msgs := constraint.Validate(s.Version)
|
||||
if !success {
|
||||
return false, msgs[0]
|
||||
}
|
||||
return true, nil
|
||||
}
|
||||
|
||||
// IsGreaterThanOrEqual returns true if this version is greater than or equal the given version
|
||||
func (s *SemanticVersion) IsGreaterThanOrEqual(version *SemanticVersion) (bool, error) {
|
||||
// Set up new constraint
|
||||
constraint, err := semver.NewConstraint(">= " + version.Version.String())
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
|
||||
// Check if the desired one is greater than the requested on
|
||||
success, msgs := constraint.Validate(s.Version)
|
||||
if !success {
|
||||
return false, msgs[0]
|
||||
}
|
||||
return true, nil
|
||||
}
|
||||
|
||||
// MainVersion returns the main version of any version+prerelease+metadata
|
||||
// EG: MainVersion("1.2.3-pre") => "1.2.3"
|
||||
func (s *SemanticVersion) MainVersion() *SemanticVersion {
|
||||
mainVersion := fmt.Sprintf("%d.%d.%d", s.Version.Major(), s.Version.Minor(), s.Version.Patch())
|
||||
result, _ := NewSemanticVersion(mainVersion)
|
||||
return result
|
||||
}
|
||||
|
||||
// SemverCollection is a collection of SemanticVersion objects
|
||||
type SemverCollection []*SemanticVersion
|
||||
|
||||
// Len returns the length of a collection. The number of Version instances
|
||||
// on the slice.
|
||||
func (c SemverCollection) Len() int {
|
||||
return len(c)
|
||||
}
|
||||
|
||||
// Less is needed for the sort interface to compare two Version objects on the
|
||||
// slice. If checks if one is less than the other.
|
||||
func (c SemverCollection) Less(i, j int) bool {
|
||||
return c[i].Version.LessThan(c[j].Version)
|
||||
}
|
||||
|
||||
// Swap is needed for the sort interface to replace the Version objects
|
||||
// at two different positions in the slice.
|
||||
func (c SemverCollection) Swap(i, j int) {
|
||||
c[i], c[j] = c[j], c[i]
|
||||
}
|
||||
@@ -1 +0,0 @@
|
||||
package cmd
|
||||
43
cmd/shell.go
Normal file
@@ -0,0 +1,43 @@
|
||||
package cmd
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"os"
|
||||
"os/exec"
|
||||
)
|
||||
|
||||
// ShellHelper helps with Shell commands
|
||||
type ShellHelper struct {
|
||||
}
|
||||
|
||||
// NewShellHelper creates a new ShellHelper!
|
||||
func NewShellHelper() *ShellHelper {
|
||||
return &ShellHelper{}
|
||||
}
|
||||
|
||||
// Run the given command
|
||||
func (sh *ShellHelper) Run(command string, vars ...string) (stdout, stderr string, err error) {
|
||||
cmd := exec.Command(command, vars...)
|
||||
cmd.Env = append(os.Environ(), "GO111MODULE=on")
|
||||
var stdo, stde bytes.Buffer
|
||||
cmd.Stdout = &stdo
|
||||
cmd.Stderr = &stde
|
||||
err = cmd.Run()
|
||||
stdout = string(stdo.Bytes())
|
||||
stderr = string(stde.Bytes())
|
||||
return
|
||||
}
|
||||
|
||||
// RunInDirectory runs the given command in the given directory
|
||||
func (sh *ShellHelper) RunInDirectory(dir string, command string, vars ...string) (stdout, stderr string, err error) {
|
||||
cmd := exec.Command(command, vars...)
|
||||
cmd.Dir = dir
|
||||
cmd.Env = append(os.Environ(), "GO111MODULE=on")
|
||||
var stdo, stde bytes.Buffer
|
||||
cmd.Stdout = &stdo
|
||||
cmd.Stderr = &stde
|
||||
err = cmd.Run()
|
||||
stdout = string(stdo.Bytes())
|
||||
stderr = string(stde.Bytes())
|
||||
return
|
||||
}
|
||||
105
cmd/system.go
@@ -10,7 +10,6 @@ import (
|
||||
"strconv"
|
||||
"time"
|
||||
|
||||
"github.com/AlecAivazis/survey"
|
||||
homedir "github.com/mitchellh/go-homedir"
|
||||
)
|
||||
|
||||
@@ -69,6 +68,17 @@ func (s *SystemHelper) ConfigFileIsValid() bool {
|
||||
return err == nil
|
||||
}
|
||||
|
||||
// GetAuthor returns a formatted string of the user's name and email
|
||||
func (s *SystemHelper) GetAuthor() (string, error) {
|
||||
var config *SystemConfig
|
||||
config, err := s.LoadConfig()
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
|
||||
return fmt.Sprintf("%s <%s>", config.Name, config.Email), nil
|
||||
}
|
||||
|
||||
// BackupConfig attempts to backup the system config file
|
||||
func (s *SystemHelper) BackupConfig() (string, error) {
|
||||
now := strconv.FormatInt(time.Now().UTC().UnixNano(), 10)
|
||||
@@ -82,55 +92,43 @@ func (s *SystemHelper) BackupConfig() (string, error) {
|
||||
|
||||
func (s *SystemHelper) setup() error {
|
||||
|
||||
// Answers. We all need them.
|
||||
answers := &SystemConfig{}
|
||||
systemConfig := make(map[string]string)
|
||||
|
||||
// Try to load current values - ignore errors
|
||||
config, err := s.LoadConfig()
|
||||
defaultName := ""
|
||||
defaultEmail := ""
|
||||
if config != nil {
|
||||
defaultName = config.Name
|
||||
defaultEmail = config.Email
|
||||
}
|
||||
// Questions
|
||||
var simpleQs = []*survey.Question{
|
||||
{
|
||||
Name: "Name",
|
||||
Prompt: &survey.Input{
|
||||
Message: "What is your name:",
|
||||
Default: defaultName,
|
||||
},
|
||||
Validate: survey.Required,
|
||||
},
|
||||
{
|
||||
Name: "Email",
|
||||
Prompt: &survey.Input{
|
||||
Message: "What is your email address:",
|
||||
Default: defaultEmail,
|
||||
},
|
||||
Validate: survey.Required,
|
||||
},
|
||||
}
|
||||
config, _ := s.LoadConfig()
|
||||
|
||||
// ask the questions
|
||||
err = survey.Ask(simpleQs, answers)
|
||||
if err != nil {
|
||||
return err
|
||||
if config.Name != "" {
|
||||
systemConfig["name"] = PromptRequired("What is your name", config.Name)
|
||||
} else {
|
||||
systemConfig["name"] = PromptRequired("What is your name")
|
||||
}
|
||||
if config.Email != "" {
|
||||
systemConfig["email"] = PromptRequired("What is your email address", config.Email)
|
||||
} else {
|
||||
systemConfig["email"] = PromptRequired("What is your email address")
|
||||
}
|
||||
|
||||
// Create the directory
|
||||
err = s.fs.MkDirs(s.wailsSystemDir)
|
||||
err := s.fs.MkDirs(s.wailsSystemDir)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
// Save
|
||||
configData, err := json.Marshal(&systemConfig)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
err = ioutil.WriteFile(s.wailsSystemConfig, configData, 0755)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
fmt.Println()
|
||||
s.log.White("Wails config saved to: " + s.wailsSystemConfig)
|
||||
s.log.White("Feel free to customise these settings.")
|
||||
fmt.Println()
|
||||
|
||||
return answers.Save(s.wailsSystemConfig)
|
||||
return nil
|
||||
}
|
||||
|
||||
const introText = `
|
||||
@@ -220,6 +218,15 @@ func (sc *SystemConfig) load(filename string) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
// CheckDependenciesSilent checks for dependencies but
|
||||
// only outputs if there's an error
|
||||
func CheckDependenciesSilent(logger *Logger) (bool, error) {
|
||||
logger.SetErrorOnly(true)
|
||||
result, err := CheckDependencies(logger)
|
||||
logger.SetErrorOnly(false)
|
||||
return result, err
|
||||
}
|
||||
|
||||
// CheckDependencies will look for Wails dependencies on the system
|
||||
// Errors are reported in error and the bool return value is whether
|
||||
// the dependencies are all installed.
|
||||
@@ -249,7 +256,7 @@ func CheckDependencies(logger *Logger) (bool, error) {
|
||||
bin := programHelper.FindProgram(program.Name)
|
||||
if bin == nil {
|
||||
errors = true
|
||||
logger.Red("Program '%s' not found. %s", program.Name, program.Help)
|
||||
logger.Error("Program '%s' not found. %s", program.Name, program.Help)
|
||||
} else {
|
||||
logger.Green("Program '%s' found: %s", program.Name, bin.Path)
|
||||
}
|
||||
@@ -272,7 +279,30 @@ func CheckDependencies(logger *Logger) (bool, error) {
|
||||
}
|
||||
if !installed {
|
||||
errors = true
|
||||
logger.Red("Library '%s' not found. %s", library.Name, library.Help)
|
||||
logger.Error("Library '%s' not found. %s", library.Name, library.Help)
|
||||
} else {
|
||||
logger.Green("Library '%s' installed.", library.Name)
|
||||
}
|
||||
case Arch:
|
||||
installed, err := PacmanInstalled(library.Name)
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
if !installed {
|
||||
errors = true
|
||||
logger.Error("Library '%s' not found. %s", library.Name, library.Help)
|
||||
} else {
|
||||
logger.Green("Library '%s' installed.", library.Name)
|
||||
}
|
||||
case RedHat:
|
||||
|
||||
installed, err := RpmInstalled(library.Name)
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
if !installed {
|
||||
errors = true
|
||||
logger.Error("Library '%s' not found. %s", library.Name, library.Help)
|
||||
} else {
|
||||
logger.Green("Library '%s' installed.", library.Name)
|
||||
}
|
||||
@@ -281,6 +311,7 @@ func CheckDependencies(logger *Logger) (bool, error) {
|
||||
}
|
||||
}
|
||||
}
|
||||
logger.White("")
|
||||
|
||||
return !errors, err
|
||||
}
|
||||
|
||||
347
cmd/templates.go
@@ -5,85 +5,94 @@ import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"path"
|
||||
"log"
|
||||
"path/filepath"
|
||||
"runtime"
|
||||
"strings"
|
||||
"text/template"
|
||||
|
||||
"github.com/alecthomas/template"
|
||||
"github.com/kennygrant/sanitize"
|
||||
"github.com/leaanthony/slicer"
|
||||
)
|
||||
|
||||
const templateSuffix = ".template"
|
||||
// TemplateMetadata holds all the metadata for a Wails template
|
||||
type TemplateMetadata struct {
|
||||
Name string `json:"name"`
|
||||
Version string `json:"version"`
|
||||
ShortDescription string `json:"shortdescription"`
|
||||
Description string `json:"description"`
|
||||
Install string `json:"install"`
|
||||
Build string `json:"build"`
|
||||
Author string `json:"author"`
|
||||
Created string `json:"created"`
|
||||
FrontendDir string `json:"frontenddir"`
|
||||
Serve string `json:"serve"`
|
||||
Bridge string `json:"bridge"`
|
||||
WailsDir string `json:"wailsdir"`
|
||||
}
|
||||
|
||||
// TemplateDetails holds information about a specific template
|
||||
type TemplateDetails struct {
|
||||
Name string
|
||||
Path string
|
||||
Metadata *TemplateMetadata
|
||||
fs *FSHelper
|
||||
}
|
||||
|
||||
// TemplateHelper is a utility object to help with processing templates
|
||||
type TemplateHelper struct {
|
||||
system *SystemHelper
|
||||
fs *FSHelper
|
||||
templateDir string
|
||||
// templates map[string]string
|
||||
templateSuffix string
|
||||
templateDir *Dir
|
||||
fs *FSHelper
|
||||
metadataFilename string
|
||||
}
|
||||
|
||||
type Template struct {
|
||||
Name string
|
||||
Dir string
|
||||
Metadata map[string]interface{}
|
||||
}
|
||||
|
||||
// NewTemplateHelper creates a new template helper
|
||||
func NewTemplateHelper() *TemplateHelper {
|
||||
result := TemplateHelper{
|
||||
system: NewSystemHelper(),
|
||||
fs: NewFSHelper(),
|
||||
templateSuffix: ".template",
|
||||
|
||||
templateDir, err := fs.LocalDir("./templates")
|
||||
if err != nil {
|
||||
log.Fatal("Unable to find the template directory. Please reinstall Wails.")
|
||||
}
|
||||
|
||||
return &TemplateHelper{
|
||||
templateDir: templateDir,
|
||||
metadataFilename: "template.json",
|
||||
}
|
||||
// Calculate template base dir
|
||||
_, filename, _, _ := runtime.Caller(1)
|
||||
result.templateDir = filepath.Join(path.Dir(filename), "templates")
|
||||
// result.templateDir = filepath.Join(result.system.homeDir, "go", "src", "github.com", "wailsapp", "wails", "cmd", "templates")
|
||||
return &result
|
||||
}
|
||||
|
||||
func (t *TemplateHelper) GetTemplateNames() (map[string]string, error) {
|
||||
templateDirs, err := t.fs.GetSubdirs(t.templateDir)
|
||||
// IsValidTemplate returns true if the given tempalte name resides on disk
|
||||
func (t *TemplateHelper) IsValidTemplate(templateName string) bool {
|
||||
pathToTemplate := filepath.Join(t.templateDir.fullPath, templateName)
|
||||
return t.fs.DirExists(pathToTemplate)
|
||||
}
|
||||
|
||||
// SanitizeFilename sanitizes the given string to make a valid filename
|
||||
func (t *TemplateHelper) SanitizeFilename(name string) string {
|
||||
return sanitize.Name(name)
|
||||
}
|
||||
|
||||
// CreateNewTemplate creates a new template based on the given directory name and string
|
||||
func (t *TemplateHelper) CreateNewTemplate(dirname string, details *TemplateMetadata) (string, error) {
|
||||
|
||||
// Check if this template has already been created
|
||||
if t.IsValidTemplate(dirname) {
|
||||
return "", fmt.Errorf("cannot create template in directory '%s' - already exists", dirname)
|
||||
}
|
||||
|
||||
targetDir := filepath.Join(t.templateDir.fullPath, dirname)
|
||||
err := t.fs.MkDir(targetDir)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
return "", err
|
||||
}
|
||||
return templateDirs, nil
|
||||
targetMetadata := filepath.Join(targetDir, t.metadataFilename)
|
||||
err = t.fs.SaveAsJSON(details, targetMetadata)
|
||||
|
||||
return targetDir, err
|
||||
}
|
||||
|
||||
func (t *TemplateHelper) GetTemplateDetails() (map[string]*Template, error) {
|
||||
templateDirs, err := t.fs.GetSubdirs(t.templateDir)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
result := make(map[string]*Template)
|
||||
|
||||
for name, dir := range templateDirs {
|
||||
result[name] = &Template{
|
||||
Dir: dir,
|
||||
}
|
||||
metadata, err := t.LoadMetadata(dir)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
result[name].Metadata = metadata
|
||||
if metadata["name"] != nil {
|
||||
result[name].Name = metadata["name"].(string)
|
||||
} else {
|
||||
// Ignore bad templates?
|
||||
result[name] = nil
|
||||
}
|
||||
}
|
||||
|
||||
return result, nil
|
||||
}
|
||||
|
||||
func (t *TemplateHelper) LoadMetadata(dir string) (map[string]interface{}, error) {
|
||||
// LoadMetadata loads the template's 'metadata.json' file
|
||||
func (t *TemplateHelper) LoadMetadata(dir string) (*TemplateMetadata, error) {
|
||||
templateFile := filepath.Join(dir, t.metadataFilename)
|
||||
result := make(map[string]interface{})
|
||||
result := &TemplateMetadata{}
|
||||
if !t.fs.FileExists(templateFile) {
|
||||
return nil, nil
|
||||
}
|
||||
@@ -95,173 +104,109 @@ func (t *TemplateHelper) LoadMetadata(dir string) (map[string]interface{}, error
|
||||
return result, err
|
||||
}
|
||||
|
||||
func (t *TemplateHelper) TemplateExists(templateName string) (bool, error) {
|
||||
templates, err := t.GetTemplateNames()
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
_, exists := templates[templateName]
|
||||
return exists, nil
|
||||
}
|
||||
// GetTemplateDetails returns a map of Template structs containing details
|
||||
// of the found templates
|
||||
func (t *TemplateHelper) GetTemplateDetails() (map[string]*TemplateDetails, error) {
|
||||
|
||||
func (t *TemplateHelper) InstallTemplate(projectPath string, projectOptions *ProjectOptions) error {
|
||||
|
||||
// Get template files
|
||||
template, err := t.getTemplateFiles(projectOptions.Template)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
// Copy files to target
|
||||
err = template.Install(projectPath, projectOptions)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// templateFiles categorises files found in a template
|
||||
type templateFiles struct {
|
||||
BaseDir string
|
||||
StandardFiles []string
|
||||
Templates []string
|
||||
Dirs []string
|
||||
}
|
||||
|
||||
// newTemplateFiles returns a new TemplateFiles struct
|
||||
func (t *TemplateHelper) newTemplateFiles(dir string) *templateFiles {
|
||||
pathsep := string(os.PathSeparator)
|
||||
// Ensure base directory has trailing slash
|
||||
if !strings.HasSuffix(dir, pathsep) {
|
||||
dir = dir + pathsep
|
||||
}
|
||||
return &templateFiles{
|
||||
BaseDir: dir,
|
||||
}
|
||||
}
|
||||
|
||||
// AddStandardFile adds the given file to the list of standard files
|
||||
func (t *templateFiles) AddStandardFile(filename string) {
|
||||
localPath := strings.TrimPrefix(filename, t.BaseDir)
|
||||
t.StandardFiles = append(t.StandardFiles, localPath)
|
||||
}
|
||||
|
||||
// AddTemplate adds the given file to the list of template files
|
||||
func (t *templateFiles) AddTemplate(filename string) {
|
||||
localPath := strings.TrimPrefix(filename, t.BaseDir)
|
||||
t.Templates = append(t.Templates, localPath)
|
||||
}
|
||||
|
||||
// AddDir adds the given directory to the list of template dirs
|
||||
func (t *templateFiles) AddDir(dir string) {
|
||||
localPath := strings.TrimPrefix(dir, t.BaseDir)
|
||||
t.Dirs = append(t.Dirs, localPath)
|
||||
}
|
||||
|
||||
// getTemplateFiles returns a struct categorising files in
|
||||
// the template directory
|
||||
func (t *TemplateHelper) getTemplateFiles(templateName string) (*templateFiles, error) {
|
||||
|
||||
templates, err := t.GetTemplateNames()
|
||||
// Get the subdirectory details
|
||||
templateDirs, err := t.templateDir.GetSubdirs()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
templateDir := templates[templateName]
|
||||
result := t.newTemplateFiles(templateDir)
|
||||
var localPath string
|
||||
err = filepath.Walk(templateDir, func(dir string, info os.FileInfo, err error) error {
|
||||
if dir == templateDir {
|
||||
return nil
|
||||
|
||||
result := make(map[string]*TemplateDetails)
|
||||
|
||||
for name, dir := range templateDirs {
|
||||
result[name] = &TemplateDetails{
|
||||
Path: dir,
|
||||
}
|
||||
_ = &TemplateMetadata{}
|
||||
metadata, err := t.LoadMetadata(dir)
|
||||
if err != nil {
|
||||
return err
|
||||
return nil, err
|
||||
}
|
||||
|
||||
// Don't copy template metadata
|
||||
localPath = strings.TrimPrefix(dir, templateDir+string(filepath.Separator))
|
||||
if localPath == t.metadataFilename {
|
||||
return nil
|
||||
result[name].Metadata = metadata
|
||||
if metadata.Name != "" {
|
||||
result[name].Name = metadata.Name
|
||||
} else {
|
||||
// Ignore bad templates?
|
||||
result[name] = nil
|
||||
}
|
||||
|
||||
// Categorise the file
|
||||
switch {
|
||||
case info.IsDir():
|
||||
result.AddDir(dir)
|
||||
case strings.HasSuffix(info.Name(), templateSuffix):
|
||||
result.AddTemplate(dir)
|
||||
default:
|
||||
result.AddStandardFile(dir)
|
||||
}
|
||||
return nil
|
||||
})
|
||||
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("error processing template '%s' in path '%q': %v", templateName, templateDir, err)
|
||||
}
|
||||
return result, err
|
||||
|
||||
return result, nil
|
||||
}
|
||||
|
||||
// Install the template files into the given project path
|
||||
func (t *templateFiles) Install(projectPath string, projectOptions *ProjectOptions) error {
|
||||
// GetTemplateFilenames returns all the filenames of the given template
|
||||
func (t *TemplateHelper) GetTemplateFilenames(template *TemplateDetails) (*slicer.StringSlicer, error) {
|
||||
|
||||
fs := NewFSHelper()
|
||||
// Get the subdirectory details
|
||||
templateDir, err := t.fs.Dir(template.Path)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return templateDir.GetAllFilenames()
|
||||
}
|
||||
|
||||
// Create directories
|
||||
var targetDir string
|
||||
for _, dirname := range t.Dirs {
|
||||
targetDir = filepath.Join(projectPath, dirname)
|
||||
fs.MkDir(targetDir)
|
||||
// InstallTemplate installs the template given in the project options to the
|
||||
// project path given
|
||||
func (t *TemplateHelper) InstallTemplate(projectPath string, projectOptions *ProjectOptions) error {
|
||||
|
||||
// Get template files
|
||||
templateFilenames, err := t.GetTemplateFilenames(projectOptions.selectedTemplate)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
// Copy standard files
|
||||
var targetFile, sourceFile string
|
||||
var err error
|
||||
for _, filename := range t.StandardFiles {
|
||||
sourceFile = filepath.Join(t.BaseDir, filename)
|
||||
targetFile = filepath.Join(projectPath, filename)
|
||||
templatePath := projectOptions.selectedTemplate.Path
|
||||
|
||||
err = fs.CopyFile(sourceFile, targetFile)
|
||||
templateJSONFilename := filepath.Join(templatePath, t.metadataFilename)
|
||||
|
||||
templateFiles := templateFilenames.Filter(func(filename string) bool {
|
||||
filename = filepath.FromSlash(filename)
|
||||
return strings.HasPrefix(filename, templatePath) && filename != templateJSONFilename
|
||||
})
|
||||
|
||||
templateFiles.Each(func(templateFile string) {
|
||||
|
||||
// Setup filenames
|
||||
relativeFilename := strings.TrimPrefix(templateFile, templatePath)[1:]
|
||||
targetFilename, err := filepath.Abs(filepath.Join(projectOptions.OutputDirectory, relativeFilename))
|
||||
if err != nil {
|
||||
return err
|
||||
return
|
||||
}
|
||||
filedata, err := t.fs.LoadAsBytes(templateFile)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
// Do we have template files?
|
||||
if len(t.Templates) > 0 {
|
||||
|
||||
// Iterate over the templates
|
||||
var templateFile string
|
||||
var tmpl *template.Template
|
||||
for _, filename := range t.Templates {
|
||||
|
||||
// Load template text
|
||||
templateFile = filepath.Join(t.BaseDir, filename)
|
||||
templateText, err := fs.LoadAsString(templateFile)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
// Apply template
|
||||
tmpl = template.New(templateFile)
|
||||
tmpl.Parse(templateText)
|
||||
|
||||
// Write the template to a buffer
|
||||
// If file is a template, process it
|
||||
if strings.HasSuffix(templateFile, ".template") {
|
||||
templateData := string(filedata)
|
||||
tmpl := template.New(templateFile)
|
||||
tmpl.Parse(templateData)
|
||||
var tpl bytes.Buffer
|
||||
err = tmpl.Execute(&tpl, projectOptions)
|
||||
if err != nil {
|
||||
fmt.Println("ERROR!!! " + err.Error())
|
||||
return err
|
||||
return
|
||||
}
|
||||
|
||||
// Save buffer to disk
|
||||
targetFilename := strings.TrimSuffix(filename, templateSuffix)
|
||||
targetFile = filepath.Join(projectPath, targetFilename)
|
||||
err = ioutil.WriteFile(targetFile, tpl.Bytes(), 0644)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
// Remove template suffix
|
||||
targetFilename = strings.TrimSuffix(targetFilename, ".template")
|
||||
|
||||
// Set the filedata to the template result
|
||||
filedata = tpl.Bytes()
|
||||
}
|
||||
|
||||
// Normal file, just copy it
|
||||
err = fs.CreateFile(targetFilename, filedata)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
})
|
||||
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return nil
|
||||
|
||||
@@ -1,19 +0,0 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
wails "github.com/wailsapp/wails"
|
||||
)
|
||||
|
||||
var html = `<h1> Basic Template </h1>`
|
||||
|
||||
func main() {
|
||||
|
||||
// Initialise the app
|
||||
app := wails.CreateApp(&wails.AppConfig{
|
||||
Width: 1024,
|
||||
Height: 768,
|
||||
Title: "My Project",
|
||||
HTML: html,
|
||||
})
|
||||
app.Run()
|
||||
}
|
||||
@@ -1,7 +0,0 @@
|
||||
{
|
||||
"name": "Basic",
|
||||
"shortdescription": "A basic template",
|
||||
"description": "A basic template using vanilla JS",
|
||||
"author": "Lea Anthony<lea.anthony@gmail.com>",
|
||||
"created": "2018-10-18"
|
||||
}
|
||||
@@ -1,19 +0,0 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
wails "github.com/wailsapp/wails"
|
||||
)
|
||||
|
||||
var html = `<h1> Custom Project </h1>`
|
||||
|
||||
func main() {
|
||||
|
||||
// Initialise the app
|
||||
app := wails.CreateApp(&wails.AppConfig{
|
||||
Width: 800,
|
||||
Height: 600,
|
||||
Title: "My Project",
|
||||
HTML: html,
|
||||
})
|
||||
app.Run()
|
||||
}
|
||||
@@ -1,7 +0,0 @@
|
||||
{
|
||||
"name": "Custom",
|
||||
"shortdescription": "Choose your own CSS Framework",
|
||||
"description": "A basic template allowing use of CSS Frameworks",
|
||||
"author": "Lea Anthony<lea.anthony@gmail.com>",
|
||||
"created": "2018-10-22"
|
||||
}
|
||||
@@ -1,29 +1,35 @@
|
||||
# frontend
|
||||
# vue basic
|
||||
|
||||
## Project setup
|
||||
|
||||
```
|
||||
npm install
|
||||
```
|
||||
|
||||
### Compiles and hot-reloads for development
|
||||
|
||||
```
|
||||
npm run serve
|
||||
```
|
||||
|
||||
### Compiles and minifies for production
|
||||
|
||||
```
|
||||
npm run build
|
||||
```
|
||||
|
||||
### Run your tests
|
||||
|
||||
```
|
||||
npm run test
|
||||
```
|
||||
|
||||
### Lints and fixes files
|
||||
|
||||
```
|
||||
npm run lint
|
||||
```
|
||||
|
||||
### Customize configuration
|
||||
|
||||
See [Configuration Reference](https://cli.vuejs.org/config/).
|
||||
11109
cmd/templates/vuebasic/frontend/package-lock.json
generated
Normal file
49
cmd/templates/vuebasic/frontend/package.json.template
Normal file
@@ -0,0 +1,49 @@
|
||||
{
|
||||
"name": "{{.NPMProjectName}}",
|
||||
"author": "{{.Author.Name}}<{{.Author.Email}}>",
|
||||
"private": true,
|
||||
"scripts": {
|
||||
"serve": "vue-cli-service serve",
|
||||
"build": "vue-cli-service build",
|
||||
"lint": "vue-cli-service lint"
|
||||
},
|
||||
"dependencies": {
|
||||
"core-js": "^2.6.4",
|
||||
"vue": "^2.5.22"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@vue/cli-plugin-babel": "^3.4.0",
|
||||
"@vue/cli-plugin-eslint": "^3.4.0",
|
||||
"@vue/cli-service": "^3.4.0",
|
||||
"babel-eslint": "^10.0.1",
|
||||
"eslint": "^5.8.0",
|
||||
"eslint-plugin-vue": "^5.0.0",
|
||||
"eventsource-polyfill": "^0.9.6",
|
||||
"vue-template-compiler": "^2.5.21",
|
||||
"webpack-hot-middleware": "^2.24.3"
|
||||
},
|
||||
"eslintConfig": {
|
||||
"root": true,
|
||||
"env": {
|
||||
"node": true
|
||||
},
|
||||
"extends": [
|
||||
"plugin:vue/essential",
|
||||
"eslint:recommended"
|
||||
],
|
||||
"rules": {},
|
||||
"parserOptions": {
|
||||
"parser": "babel-eslint"
|
||||
}
|
||||
},
|
||||
"postcss": {
|
||||
"plugins": {
|
||||
"autoprefixer": {}
|
||||
}
|
||||
},
|
||||
"browserslist": [
|
||||
"> 1%",
|
||||
"last 2 versions",
|
||||
"not ie <= 8"
|
||||
]
|
||||
}
|
||||
@@ -1,22 +1,18 @@
|
||||
<template>
|
||||
<div id="app">
|
||||
<img alt="Wails logo" src="./assets/images/logo.png" class="logo zoomIn">
|
||||
<HelloWorld msg="Welcome to Your Wails App!"/>
|
||||
<Quote/>
|
||||
<HelloWorld/>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script>
|
||||
import HelloWorld from "./components/HelloWorld.vue";
|
||||
import Quote from "./components/Quote.vue";
|
||||
import "./assets/css/main.css";
|
||||
|
||||
export default {
|
||||
name: "app",
|
||||
components: {
|
||||
HelloWorld,
|
||||
Quote
|
||||
HelloWorld
|
||||
}
|
||||
};
|
||||
</script>
|
||||
|
||||
@@ -10,21 +10,6 @@
|
||||
html {
|
||||
height: 100%;
|
||||
overflow: hidden;
|
||||
/* https://leaverou.github.io/css3patterns/#carbon */
|
||||
background: linear-gradient(27deg, #151515 5px, transparent 5px) 0 5px,
|
||||
linear-gradient(207deg, #151515 5px, transparent 5px) 10px 0px,
|
||||
linear-gradient(27deg, #222 5px, transparent 5px) 0px 10px,
|
||||
linear-gradient(207deg, #222 5px, transparent 5px) 10px 5px,
|
||||
linear-gradient(90deg, #1b1b1b 10px, transparent 10px),
|
||||
linear-gradient(
|
||||
#1d1d1d 25%,
|
||||
#1a1a1a 25%,
|
||||
#1a1a1a 50%,
|
||||
transparent 50%,
|
||||
transparent 75%,
|
||||
#242424 75%,
|
||||
#242424
|
||||
);
|
||||
background-color: #131313;
|
||||
background-size: 20px 20px;
|
||||
}
|
||||
@@ -46,10 +31,8 @@ html {
|
||||
format("woff2"),
|
||||
/* Super Modern Browsers */
|
||||
url("../fonts/roboto/roboto-v18-latin-regular.woff") format("woff"),
|
||||
/* Modern Browsers */
|
||||
url("../fonts/roboto/roboto-v18-latin-regular.ttf")
|
||||
/* Modern Browsers */ url("../fonts/roboto/roboto-v18-latin-regular.ttf")
|
||||
format("truetype"),
|
||||
/* Safari, Android, iOS */
|
||||
url("../fonts/roboto/roboto-v18-latin-regular.svg#Roboto")
|
||||
format("svg"); /* Legacy iOS */
|
||||
}
|
||||
url("../fonts/roboto/roboto-v18-latin-regular.svg#Roboto") format("svg"); /* Legacy iOS */
|
||||
}
|
||||
|
Before Width: | Height: | Size: 48 KiB After Width: | Height: | Size: 48 KiB |
|
Before Width: | Height: | Size: 301 KiB After Width: | Height: | Size: 301 KiB |
@@ -0,0 +1,55 @@
|
||||
<template>
|
||||
<div class="container">
|
||||
<h1>{{message}}</h1>
|
||||
<a @click="getMessage">Press Me!</a>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script>
|
||||
export default {
|
||||
data() {
|
||||
return {
|
||||
message: " "
|
||||
};
|
||||
},
|
||||
methods: {
|
||||
getMessage: function() {
|
||||
var self = this;
|
||||
window.backend.basic().then(result => {
|
||||
self.message = result;
|
||||
});
|
||||
}
|
||||
}
|
||||
};
|
||||
</script>
|
||||
|
||||
<!-- Add "scoped" attribute to limit CSS to this component only -->
|
||||
<style scoped>
|
||||
h1 {
|
||||
margin-top: 2em;
|
||||
position: relative;
|
||||
min-height: 5rem;
|
||||
width: 100%;
|
||||
}
|
||||
a:hover {
|
||||
font-size: 1.7em;
|
||||
border-color: blue;
|
||||
background-color: blue;
|
||||
color: white;
|
||||
border: 3px solid white;
|
||||
border-radius: 10px;
|
||||
padding: 9px;
|
||||
cursor: pointer;
|
||||
transition: 500ms;
|
||||
}
|
||||
a {
|
||||
font-size: 1.7em;
|
||||
border-color: white;
|
||||
background-color: #121212;
|
||||
color: white;
|
||||
border: 3px solid white;
|
||||
border-radius: 10px;
|
||||
padding: 9px;
|
||||
cursor: pointer;
|
||||
}
|
||||
</style>
|
||||
13
cmd/templates/vuebasic/frontend/src/main.js
Normal file
@@ -0,0 +1,13 @@
|
||||
import Vue from "vue";
|
||||
import App from "./App.vue";
|
||||
|
||||
Vue.config.productionTip = false;
|
||||
Vue.config.devtools = true;
|
||||
|
||||
import Bridge from "./wailsbridge";
|
||||
|
||||
Bridge.Start(() => {
|
||||
new Vue({
|
||||
render: h => h(App)
|
||||
}).$mount("#app");
|
||||
});
|
||||
17
cmd/templates/vuebasic/frontend/src/wailsbridge.js
Normal file
@@ -0,0 +1,17 @@
|
||||
/*
|
||||
Wails Bridge (c) 2019-present Lea Anthony
|
||||
|
||||
This prod version is to get around having to rewrite your code
|
||||
for production. When doing a release build, this file will be used
|
||||
instead of the full version.
|
||||
*/
|
||||
|
||||
export default {
|
||||
// The main function
|
||||
// Passes the main Wails object to the callback if given.
|
||||
Start: function(callback) {
|
||||
if (callback) {
|
||||
window.wails.events.on("wails:ready", callback);
|
||||
}
|
||||
}
|
||||
};
|
||||
43
cmd/templates/vuebasic/frontend/vue.config.js
Normal file
@@ -0,0 +1,43 @@
|
||||
let cssConfig = {};
|
||||
|
||||
if (process.env.NODE_ENV == "production") {
|
||||
cssConfig = {
|
||||
extract: {
|
||||
filename: "[name].css",
|
||||
chunkFilename: "[name].css"
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
chainWebpack: config => {
|
||||
let limit = 9999999999999999;
|
||||
config.module
|
||||
.rule("images")
|
||||
.test(/\.(png|gif|jpg)(\?.*)?$/i)
|
||||
.use("url-loader")
|
||||
.loader("url-loader")
|
||||
.tap(options => Object.assign(options, { limit: limit }));
|
||||
config.module
|
||||
.rule("fonts")
|
||||
.test(/\.(woff2?|eot|ttf|otf|svg)(\?.*)?$/i)
|
||||
.use("url-loader")
|
||||
.loader("url-loader")
|
||||
.options({
|
||||
limit: limit
|
||||
});
|
||||
},
|
||||
css: cssConfig,
|
||||
configureWebpack: {
|
||||
output: {
|
||||
filename: "[name].js"
|
||||
},
|
||||
optimization: {
|
||||
splitChunks: false
|
||||
}
|
||||
},
|
||||
devServer: {
|
||||
disableHostCheck: true,
|
||||
host: "localhost"
|
||||
}
|
||||
};
|
||||
1
cmd/templates/vuebasic/go.mod.template
Normal file
@@ -0,0 +1 @@
|
||||
module {{.BinaryName}}
|
||||
27
cmd/templates/vuebasic/main.go.template
Normal file
@@ -0,0 +1,27 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"github.com/leaanthony/mewn"
|
||||
"github.com/wailsapp/wails"
|
||||
)
|
||||
|
||||
func basic() string {
|
||||
return "Hello World!"
|
||||
}
|
||||
|
||||
func main() {
|
||||
|
||||
js := mewn.String("./frontend/dist/app.js")
|
||||
css := mewn.String("./frontend/dist/app.css")
|
||||
|
||||
app := wails.CreateApp(&wails.AppConfig{
|
||||
Width: 1024,
|
||||
Height: 768,
|
||||
Title: "{{.Name}}",
|
||||
JS: js,
|
||||
CSS: css,
|
||||
Colour: "#131313",
|
||||
})
|
||||
app.Bind(basic)
|
||||
app.Run()
|
||||
}
|
||||
@@ -1,10 +1,12 @@
|
||||
{
|
||||
"name": "Vue2/Webpack",
|
||||
"name": "Vue2/Webpack Basic",
|
||||
"shortdescription": "A basic Vue2/WebPack4 template",
|
||||
"description": "A basic template using Vue 2 and bundled using Webpack 4",
|
||||
"author": "Lea Anthony<lea.anthony@gmail.com>",
|
||||
"created": "2018-12-01",
|
||||
"frontenddir": "frontend",
|
||||
"install": "npm install",
|
||||
"build": "npm run build"
|
||||
}
|
||||
"build": "npm run build",
|
||||
"serve": "npm run serve",
|
||||
"bridge": "src"
|
||||
}
|
||||
@@ -1,3 +0,0 @@
|
||||
> 1%
|
||||
last 2 versions
|
||||
not ie <= 8
|
||||
@@ -1,17 +0,0 @@
|
||||
{
|
||||
"name": "frontend",
|
||||
"version": "0.1.0",
|
||||
"private": true,
|
||||
"scripts": {
|
||||
"serve": "vue-cli-service serve",
|
||||
"build": "vue-cli-service build"
|
||||
},
|
||||
"dependencies": {
|
||||
"vue": "^2.5.17"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@vue/cli-plugin-babel": "^3.1.1",
|
||||
"@vue/cli-service": "^3.1.4",
|
||||
"vue-template-compiler": "^2.5.17"
|
||||
}
|
||||
}
|
||||
@@ -1,5 +0,0 @@
|
||||
module.exports = {
|
||||
plugins: {
|
||||
autoprefixer: {}
|
||||
}
|
||||
}
|
||||
|
Before Width: | Height: | Size: 1.1 KiB |
@@ -1,17 +0,0 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<meta http-equiv="X-UA-Compatible" content="IE=edge">
|
||||
<meta name="viewport" content="width=device-width,initial-scale=1.0">
|
||||
<link rel="icon" href="<%= BASE_URL %>favicon.ico">
|
||||
<title>frontend</title>
|
||||
</head>
|
||||
<body>
|
||||
<noscript>
|
||||
<strong>We're sorry but frontend doesn't work properly without JavaScript enabled. Please enable it to continue.</strong>
|
||||
</noscript>
|
||||
<div id="app"></div>
|
||||
<!-- built files will be auto injected -->
|
||||
</body>
|
||||
</html>
|
||||
@@ -1,75 +0,0 @@
|
||||
/**
|
||||
Credit: https://codepen.io/harmputman/pen/IpAnb
|
||||
**/
|
||||
|
||||
body {
|
||||
font: normal 300 1em/1.5em sans-serif;
|
||||
}
|
||||
|
||||
.container {
|
||||
background: #fff;
|
||||
width: 100%;
|
||||
max-width: 480px;
|
||||
min-width: 320px;
|
||||
margin: 2em auto 0;
|
||||
padding: 1.5em;
|
||||
opacity: 0.8;
|
||||
border-radius: 1em;
|
||||
border-color: #117;
|
||||
}
|
||||
|
||||
p { margin-bottom: 1.5em; }
|
||||
p:last-child { margin-bottom: 0; }
|
||||
|
||||
blockquote {
|
||||
display: block;
|
||||
border-width: 2px 0;
|
||||
border-style: solid;
|
||||
border-color: #eee;
|
||||
padding: 1.5em 0 0.5em;
|
||||
margin: 1.5em 0;
|
||||
position: relative;
|
||||
color: #117;
|
||||
}
|
||||
blockquote:before {
|
||||
content: '\201C';
|
||||
position: absolute;
|
||||
top: 0em;
|
||||
left: 50%;
|
||||
transform: translate(-50%, -50%);
|
||||
background: #fff;
|
||||
width: 3rem;
|
||||
height: 2rem;
|
||||
font: 6em/1.08em sans-serif;
|
||||
color: #666;
|
||||
text-align: center;
|
||||
}
|
||||
blockquote:after {
|
||||
content: "\2013 \2003" attr(cite);
|
||||
display: block;
|
||||
text-align: right;
|
||||
font-size: 0.875em;
|
||||
color: #e70000;
|
||||
}
|
||||
|
||||
/* https://fdossena.com/?p=html5cool/buttons/i.frag */
|
||||
button {
|
||||
display:inline-block;
|
||||
padding:0.35em 1.2em;
|
||||
border:0.1em solid #000;
|
||||
margin:0 0.3em 0.3em 0;
|
||||
border-radius:0.12em;
|
||||
box-sizing: border-box;
|
||||
text-decoration:none;
|
||||
font-family:'Roboto',sans-serif;
|
||||
font-weight:300;
|
||||
font-size: 1em;
|
||||
color:#000;
|
||||
text-align:center;
|
||||
transition: all 0.2s;
|
||||
}
|
||||
button:hover{
|
||||
color:#FFF;
|
||||
background-color:#000;
|
||||
cursor: pointer;
|
||||
}
|
||||
@@ -1,38 +0,0 @@
|
||||
<template>
|
||||
<div class="hello">
|
||||
<h1>{{ msg }}</h1>
|
||||
<p></p>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script>
|
||||
export default {
|
||||
name: "HelloWorld",
|
||||
props: {
|
||||
msg: String
|
||||
}
|
||||
};
|
||||
</script>
|
||||
|
||||
<!-- Add "scoped" attribute to limit CSS to this component only -->
|
||||
<style scoped>
|
||||
.hello {
|
||||
margin-top: 2em;
|
||||
position: relative;
|
||||
width: 100%;
|
||||
}
|
||||
h3 {
|
||||
margin: 40px 0 0;
|
||||
}
|
||||
ul {
|
||||
list-style-type: none;
|
||||
padding: 0;
|
||||
}
|
||||
li {
|
||||
display: inline-block;
|
||||
margin: 0 10px;
|
||||
}
|
||||
a {
|
||||
color: gold;
|
||||
}
|
||||
</style>
|
||||
@@ -1,54 +0,0 @@
|
||||
<template>
|
||||
<div class="container">
|
||||
<blockquote v-if="quote != null" :cite="quote.person">{{ quote.text }}</blockquote>
|
||||
<p></p>
|
||||
<button @click="getNewQuote()">Get new Quote</button>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script>
|
||||
import "../assets/css/quote.css";
|
||||
|
||||
export default {
|
||||
data() {
|
||||
return {
|
||||
quote: null
|
||||
};
|
||||
},
|
||||
methods: {
|
||||
getNewQuote: function() {
|
||||
var self = this;
|
||||
wails.$.main.QuotesCollection.GetQuote().then(result => {
|
||||
console.log(result);
|
||||
self.quote = result;
|
||||
});
|
||||
}
|
||||
},
|
||||
created() {
|
||||
this.getNewQuote();
|
||||
}
|
||||
};
|
||||
</script>
|
||||
|
||||
<!-- Add "scoped" attribute to limit CSS to this component only -->
|
||||
<style scoped>
|
||||
.hello {
|
||||
margin-top: 2em;
|
||||
position: relative;
|
||||
width: 100%;
|
||||
}
|
||||
h3 {
|
||||
margin: 40px 0 0;
|
||||
}
|
||||
ul {
|
||||
list-style-type: none;
|
||||
padding: 0;
|
||||
}
|
||||
li {
|
||||
display: inline-block;
|
||||
margin: 0 10px;
|
||||
}
|
||||
a {
|
||||
color: gold;
|
||||
}
|
||||
</style>
|
||||
@@ -1,8 +0,0 @@
|
||||
import Vue from 'vue'
|
||||
import App from './App.vue'
|
||||
|
||||
Vue.config.productionTip = false
|
||||
|
||||
new Vue({
|
||||
render: h => h(App),
|
||||
}).$mount('#app')
|
||||
@@ -1,35 +0,0 @@
|
||||
|
||||
module.exports = {
|
||||
chainWebpack: (config) => {
|
||||
let limit = 9999999999999999;
|
||||
config.module
|
||||
.rule('images')
|
||||
.test(/\.(png|gif|jpg)(\?.*)?$/i)
|
||||
.use('url-loader')
|
||||
.loader('url-loader')
|
||||
.tap(options => Object.assign(options, { limit: limit }));
|
||||
config.module
|
||||
.rule('fonts')
|
||||
.test(/\.(woff2?|eot|ttf|otf|svg)(\?.*)?$/i)
|
||||
.use('url-loader')
|
||||
.loader('url-loader')
|
||||
.options({
|
||||
limit: limit,
|
||||
})
|
||||
},
|
||||
css: {
|
||||
extract: {
|
||||
filename: '[name].css',
|
||||
chunkFilename: '[name].css',
|
||||
}
|
||||
},
|
||||
configureWebpack: {
|
||||
output: {
|
||||
filename: '[name].js',
|
||||
},
|
||||
optimization: {
|
||||
splitChunks: false
|
||||
}
|
||||
},
|
||||
|
||||
}
|
||||
@@ -1,21 +0,0 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"github.com/gobuffalo/packr"
|
||||
"github.com/wailsapp/wails"
|
||||
)
|
||||
|
||||
func main() {
|
||||
|
||||
assets := packr.NewBox("./frontend/dist")
|
||||
|
||||
app := wails.CreateApp(&wails.AppConfig{
|
||||
Width: 1024,
|
||||
Height: 768,
|
||||
Title: "Vue Simple",
|
||||
JS: assets.String("app.js"),
|
||||
CSS: assets.String("app.css"),
|
||||
})
|
||||
app.Bind(newQuotesCollection())
|
||||
app.Run()
|
||||
}
|
||||
@@ -1,61 +0,0 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"math/rand"
|
||||
"time"
|
||||
)
|
||||
|
||||
// Quote holds a single quote and the person who said it
|
||||
type Quote struct {
|
||||
Text string `json:"text"`
|
||||
Person string `json:"person"`
|
||||
}
|
||||
|
||||
// QuotesCollection holds a collection of quotes!
|
||||
type QuotesCollection struct {
|
||||
quotes []*Quote
|
||||
}
|
||||
|
||||
// AddQuote creates a Quote object with the given inputs and
|
||||
// adds it to the Quotes collection
|
||||
func (Q *QuotesCollection) AddQuote(text, person string) {
|
||||
Q.quotes = append(Q.quotes, &Quote{Text: text, Person: person})
|
||||
}
|
||||
|
||||
// GetQuote returns a random Quote object from the Quotes collection
|
||||
func (Q *QuotesCollection) GetQuote() *Quote {
|
||||
return Q.quotes[rand.Intn(len(Q.quotes))]
|
||||
}
|
||||
|
||||
// newQuotesCollection creates a new QuotesCollection
|
||||
func newQuotesCollection() *QuotesCollection {
|
||||
result := &QuotesCollection{}
|
||||
rand.Seed(time.Now().Unix())
|
||||
result.AddQuote("Age is an issue of mind over matter. If you don't mind, it doesn't matter", "Mark Twain")
|
||||
result.AddQuote("Anyone who stops learning is old, whether at twenty or eighty. Anyone who keeps learning stays young. The greatest thing in life is to keep your mind young", "Henry Ford")
|
||||
result.AddQuote("Wrinkles should merely indicate where smiles have been", "Mark Twain")
|
||||
result.AddQuote("True terror is to wake up one morning and discover that your high school class is running the country", "Kurt Vonnegut")
|
||||
result.AddQuote("A diplomat is a man who always remembers a woman's birthday but never remembers her age", "Robert Frost")
|
||||
result.AddQuote("As I grow older, I pay less attention to what men say. I just watch what they do", "Andrew Carnegie")
|
||||
result.AddQuote("How incessant and great are the ills with which a prolonged old age is replete", "C. S. Lewis")
|
||||
result.AddQuote("Old age, believe me, is a good and pleasant thing. It is true you are gently shouldered off the stage, but then you are given such a comfortable front stall as spectator", "Confucius")
|
||||
result.AddQuote("Old age has deformities enough of its own. It should never add to them the deformity of vice", "Eleanor Roosevelt")
|
||||
result.AddQuote("Nobody grows old merely by living a number of years. We grow old by deserting our ideals. Years may wrinkle the skin, but to give up enthusiasm wrinkles the soul", "Samuel Ullman")
|
||||
result.AddQuote("An archaeologist is the best husband a woman can have. The older she gets the more interested he is in her", "Agatha Christie")
|
||||
result.AddQuote("All diseases run into one, old age", "Ralph Waldo Emerson")
|
||||
result.AddQuote("Bashfulness is an ornament to youth, but a reproach to old age", "Aristotle")
|
||||
result.AddQuote("Like everyone else who makes the mistake of getting older, I begin each day with coffee and obituaries", "Bill Cosby")
|
||||
result.AddQuote("Age appears to be best in four things old wood best to burn, old wine to drink, old friends to trust, and old authors to read", "Francis Bacon")
|
||||
result.AddQuote("None are so old as those who have outlived enthusiasm", "Henry David Thoreau")
|
||||
result.AddQuote("Every man over forty is a scoundrel", "George Bernard Shaw")
|
||||
result.AddQuote("Forty is the old age of youth fifty the youth of old age", "Victor Hugo")
|
||||
result.AddQuote("You can't help getting older, but you don't have to get old", "George Burns")
|
||||
result.AddQuote("Alas, after a certain age every man is responsible for his face", "Albert Camus")
|
||||
result.AddQuote("Youth is when you're allowed to stay up late on New Year's Eve. Middle age is when you're forced to", "Bill Vaughan")
|
||||
result.AddQuote("Old age is like everything else. To make a success of it, you've got to start young", "Theodore Roosevelt")
|
||||
result.AddQuote("A comfortable old age is the reward of a well-spent youth. Instead of its bringing sad and melancholy prospects of decay, it would give us hopes of eternal youth in a better world", "Maurice Chevalier")
|
||||
result.AddQuote("A man growing old becomes a child again", "Sophocles")
|
||||
result.AddQuote("I will never be an old man. To me, old age is always 15 years older than I am", "Francis Bacon")
|
||||
result.AddQuote("Age considers youth ventures", "Rabindranath Tagore")
|
||||
return result
|
||||
}
|
||||
@@ -1,5 +1,4 @@
|
||||
package cmd
|
||||
|
||||
// Version - Wails version
|
||||
// ...oO(There must be a better way)
|
||||
const Version = "v0.5.0"
|
||||
const Version = "v0.14.4-pre"
|
||||
|
||||
@@ -18,9 +18,13 @@ func init() {
|
||||
|
||||
setupCommand.Action(func() error {
|
||||
|
||||
logger.PrintBanner()
|
||||
|
||||
var err error
|
||||
|
||||
system := cmd.NewSystemHelper()
|
||||
err := system.Initialise()
|
||||
if err != nil {
|
||||
err = system.Initialise()
|
||||
if err == nil {
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -29,65 +33,37 @@ Create your first project by running 'wails init'.`
|
||||
if runtime.GOOS != "windows" {
|
||||
successMessage = "🚀 " + successMessage
|
||||
}
|
||||
switch runtime.GOOS {
|
||||
case "darwin":
|
||||
logger.Yellow("Detected Platform: OSX")
|
||||
case "windows":
|
||||
logger.Yellow("Detected Platform: Windows")
|
||||
case "linux":
|
||||
logger.Yellow("Detected Platform: Linux")
|
||||
default:
|
||||
return fmt.Errorf("Platform %s is currently not supported", runtime.GOOS)
|
||||
}
|
||||
|
||||
logger.Yellow("Checking for prerequisites...")
|
||||
// Check we have a cgo capable environment
|
||||
|
||||
requiredPrograms, err := cmd.GetRequiredPrograms()
|
||||
// Platform check
|
||||
err = platformCheck()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
errors := false
|
||||
programHelper := cmd.NewProgramHelper()
|
||||
for _, program := range *requiredPrograms {
|
||||
bin := programHelper.FindProgram(program.Name)
|
||||
if bin == nil {
|
||||
errors = true
|
||||
logger.Red("Program '%s' not found. %s", program.Name, program.Help)
|
||||
} else {
|
||||
logger.Green("Program '%s' found: %s", program.Name, bin.Path)
|
||||
}
|
||||
|
||||
// Check we have a cgo capable environment
|
||||
logger.Yellow("Checking for prerequisites...")
|
||||
var requiredProgramErrors bool
|
||||
requiredProgramErrors, err = checkRequiredPrograms()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
// Linux has library deps
|
||||
if runtime.GOOS == "linux" {
|
||||
// Check library prerequisites
|
||||
requiredLibraries, err := cmd.GetRequiredLibraries()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
distroInfo := cmd.GetLinuxDistroInfo()
|
||||
for _, library := range *requiredLibraries {
|
||||
switch distroInfo.Distribution {
|
||||
case cmd.Ubuntu:
|
||||
installed, err := cmd.DpkgInstalled(library.Name)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if !installed {
|
||||
errors = true
|
||||
logger.Red("Library '%s' not found. %s", library.Name, library.Help)
|
||||
} else {
|
||||
logger.Green("Library '%s' installed.", library.Name)
|
||||
}
|
||||
default:
|
||||
return fmt.Errorf("unable to check libraries on distribution '%s'. Please ensure that the '%s' equivalent is installed", distroInfo.DistributorID, library.Name)
|
||||
}
|
||||
}
|
||||
var libraryErrors bool
|
||||
libraryErrors, err = checkLibraries()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
// Check Mewn
|
||||
err = cmd.CheckMewn()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
logger.White("")
|
||||
|
||||
// Check for errors
|
||||
var errors = libraryErrors || requiredProgramErrors
|
||||
if !errors {
|
||||
logger.Yellow(successMessage)
|
||||
}
|
||||
@@ -95,3 +71,65 @@ Create your first project by running 'wails init'.`
|
||||
return err
|
||||
})
|
||||
}
|
||||
|
||||
func platformCheck() error {
|
||||
switch runtime.GOOS {
|
||||
case "darwin":
|
||||
logger.Yellow("Detected Platform: OSX")
|
||||
case "windows":
|
||||
logger.Yellow("Detected Platform: Windows")
|
||||
case "linux":
|
||||
logger.Yellow("Detected Platform: Linux")
|
||||
default:
|
||||
return fmt.Errorf("Platform %s is currently not supported", runtime.GOOS)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func checkLibraries() (errors bool, err error) {
|
||||
if runtime.GOOS == "linux" {
|
||||
// Check library prerequisites
|
||||
requiredLibraries, err := cmd.GetRequiredLibraries()
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
distroInfo := cmd.GetLinuxDistroInfo()
|
||||
for _, library := range *requiredLibraries {
|
||||
switch distroInfo.Distribution {
|
||||
case cmd.Ubuntu:
|
||||
installed, err := cmd.DpkgInstalled(library.Name)
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
if !installed {
|
||||
errors = true
|
||||
logger.Red("Library '%s' not found. %s", library.Name, library.Help)
|
||||
} else {
|
||||
logger.Green("Library '%s' installed.", library.Name)
|
||||
}
|
||||
default:
|
||||
return false, fmt.Errorf("unable to check libraries on distribution '%s'. Please ensure that the '%s' equivalent is installed", distroInfo.DistributorID, library.Name)
|
||||
}
|
||||
}
|
||||
}
|
||||
return false, nil
|
||||
}
|
||||
|
||||
func checkRequiredPrograms() (errors bool, err error) {
|
||||
requiredPrograms, err := cmd.GetRequiredPrograms()
|
||||
if err != nil {
|
||||
return true, err
|
||||
}
|
||||
errors = false
|
||||
programHelper := cmd.NewProgramHelper()
|
||||
for _, program := range *requiredPrograms {
|
||||
bin := programHelper.FindProgram(program.Name)
|
||||
if bin == nil {
|
||||
errors = true
|
||||
logger.Red("Program '%s' not found. %s", program.Name, program.Help)
|
||||
} else {
|
||||
logger.Green("Program '%s' found: %s", program.Name, bin.Path)
|
||||
}
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
121
cmd/wails/10.1_dev_newtemplate.go
Normal file
@@ -0,0 +1,121 @@
|
||||
// +build dev
|
||||
|
||||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"time"
|
||||
|
||||
"github.com/wailsapp/wails/cmd"
|
||||
"gopkg.in/AlecAivazis/survey.v1"
|
||||
)
|
||||
|
||||
var templateHelper = cmd.NewTemplateHelper()
|
||||
|
||||
var qs = []*survey.Question{
|
||||
{
|
||||
Name: "Name",
|
||||
Prompt: &survey.Input{Message: "Please enter the name of your template (eg: React/Webpack Basic):"},
|
||||
Validate: survey.Required,
|
||||
},
|
||||
{
|
||||
Name: "ShortDescription",
|
||||
Prompt: &survey.Input{Message: "Please enter a short description for the template (eg: React with Webpack 4):"},
|
||||
Validate: survey.Required,
|
||||
},
|
||||
{
|
||||
Name: "Description",
|
||||
Prompt: &survey.Input{Message: "Please enter a long description:"},
|
||||
Validate: survey.Required,
|
||||
},
|
||||
{
|
||||
Name: "FrontendDir",
|
||||
Prompt: &survey.Input{Message: "Please enter the name of the directory the frontend code resides (eg: frontend):"},
|
||||
Validate: survey.Required,
|
||||
},
|
||||
{
|
||||
Name: "Install",
|
||||
Prompt: &survey.Input{Message: "Please enter the install command (eg: npm install):"},
|
||||
Validate: survey.Required,
|
||||
},
|
||||
{
|
||||
Name: "Build",
|
||||
Prompt: &survey.Input{Message: "Please enter the build command (eg: npm run build):"},
|
||||
Validate: survey.Required,
|
||||
},
|
||||
{
|
||||
Name: "Serve",
|
||||
Prompt: &survey.Input{Message: "Please enter the serve command (eg: npm run serve):"},
|
||||
Validate: survey.Required,
|
||||
},
|
||||
{
|
||||
Name: "Bridge",
|
||||
Prompt: &survey.Input{Message: "Please enter the name of the directory to copy the wails bridge runtime (eg: src):"},
|
||||
Validate: survey.Required,
|
||||
},
|
||||
}
|
||||
|
||||
func newTemplate(devCommand *cmd.Command) {
|
||||
|
||||
commandDescription := `This command scaffolds everything needed to develop a new template.`
|
||||
newTemplate := devCommand.Command("newtemplate", "Generate a new template").
|
||||
LongDescription(commandDescription)
|
||||
|
||||
newTemplate.Action(func() error {
|
||||
logger.PrintSmallBanner("Generating new project template")
|
||||
fmt.Println()
|
||||
|
||||
var answers cmd.TemplateMetadata
|
||||
|
||||
// perform the questions
|
||||
err := survey.Ask(qs, &answers)
|
||||
if err != nil {
|
||||
fmt.Println(err.Error())
|
||||
return err
|
||||
}
|
||||
|
||||
dirname := templateHelper.SanitizeFilename(answers.Name)
|
||||
prompt := []*survey.Question{{
|
||||
Prompt: &survey.Input{
|
||||
Message: "Please enter a directory name for the template:",
|
||||
Default: dirname,
|
||||
},
|
||||
Validate: func(val interface{}) error {
|
||||
err := survey.Required(val)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if templateHelper.IsValidTemplate(val.(string)) {
|
||||
return fmt.Errorf("template directory already exists")
|
||||
}
|
||||
if templateHelper.SanitizeFilename(val.(string)) != val.(string) {
|
||||
return fmt.Errorf("invalid directory name '%s'", val.(string))
|
||||
}
|
||||
return nil
|
||||
},
|
||||
}}
|
||||
err = survey.Ask(prompt, &dirname)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
answers.Version = "1.0.0"
|
||||
answers.Created = time.Now().String()
|
||||
|
||||
// Get Author info from system info
|
||||
system := cmd.NewSystemHelper()
|
||||
author, err := system.GetAuthor()
|
||||
if err == nil {
|
||||
answers.Author = author
|
||||
}
|
||||
|
||||
templateDirectory, err := templateHelper.CreateNewTemplate(dirname, &answers)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
logger.Green("Created new template '%s' in directory '%s'", answers.Name, templateDirectory)
|
||||
|
||||
return nil
|
||||
})
|
||||
}
|
||||
18
cmd/wails/10_dev.go
Normal file
@@ -0,0 +1,18 @@
|
||||
// +build dev
|
||||
|
||||
package main
|
||||
|
||||
func init() {
|
||||
|
||||
commandDescription := `This command provides access to developer tooling.`
|
||||
devCommand := app.Command("dev", "A selection of developer tools").
|
||||
LongDescription(commandDescription)
|
||||
|
||||
// Add subcommands
|
||||
newTemplate(devCommand)
|
||||
|
||||
devCommand.Action(func() error {
|
||||
devCommand.PrintHelp()
|
||||
return nil
|
||||
})
|
||||
}
|
||||
@@ -24,7 +24,7 @@ Any flags that are required and not given will be prompted for.`
|
||||
|
||||
initCommand.Action(func() error {
|
||||
|
||||
logger.WhiteUnderline("Initialising project")
|
||||
logger.PrintSmallBanner("Initialising project")
|
||||
fmt.Println()
|
||||
|
||||
// Check if the system is initialised
|
||||
@@ -34,13 +34,11 @@ Any flags that are required and not given will be prompted for.`
|
||||
return err
|
||||
}
|
||||
|
||||
success, err := cmd.CheckDependencies(logger)
|
||||
success, err := cmd.CheckDependenciesSilent(logger)
|
||||
if !success {
|
||||
return err
|
||||
}
|
||||
|
||||
logger.White("")
|
||||
|
||||
// Do we want to just force defaults?
|
||||
if projectOptions.UseDefaults {
|
||||
// Use defaults
|
||||
105
cmd/wails/4_build.go
Normal file
@@ -0,0 +1,105 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"os"
|
||||
|
||||
"github.com/leaanthony/spinner"
|
||||
"github.com/wailsapp/wails/cmd"
|
||||
)
|
||||
|
||||
func init() {
|
||||
|
||||
var packageApp = false
|
||||
var forceRebuild = false
|
||||
var debugMode = false
|
||||
buildSpinner := spinner.NewSpinner()
|
||||
buildSpinner.SetSpinSpeed(50)
|
||||
|
||||
commandDescription := `This command will check to ensure all pre-requistes are installed prior to building. If not, it will attempt to install them. Building comprises of a number of steps: install frontend dependencies, build frontend, pack frontend, compile main application.`
|
||||
initCmd := app.Command("build", "Builds your Wails project").
|
||||
LongDescription(commandDescription).
|
||||
BoolFlag("p", "Package application on successful build", &packageApp).
|
||||
BoolFlag("f", "Force rebuild of application components", &forceRebuild).
|
||||
BoolFlag("d", "Build in Debug mode", &debugMode)
|
||||
|
||||
initCmd.Action(func() error {
|
||||
|
||||
message := "Building Application"
|
||||
if packageApp {
|
||||
message = "Packaging Application"
|
||||
}
|
||||
if forceRebuild {
|
||||
message += " (force rebuild)"
|
||||
}
|
||||
logger.PrintSmallBanner(message)
|
||||
fmt.Println()
|
||||
|
||||
// Project options
|
||||
projectOptions := &cmd.ProjectOptions{}
|
||||
|
||||
// Check we are in project directory
|
||||
// Check project.json loads correctly
|
||||
fs := cmd.NewFSHelper()
|
||||
err := projectOptions.LoadConfig(fs.Cwd())
|
||||
if err != nil {
|
||||
return fmt.Errorf("Unable to find 'project.json'. Please check you are in a Wails project directory")
|
||||
}
|
||||
|
||||
// Validate config
|
||||
// Check if we have a frontend
|
||||
err = cmd.ValidateFrontendConfig(projectOptions)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
// Program checker
|
||||
program := cmd.NewProgramHelper()
|
||||
|
||||
if projectOptions.FrontEnd != nil {
|
||||
// npm
|
||||
if !program.IsInstalled("npm") {
|
||||
return fmt.Errorf("it appears npm is not installed. Please install and run again")
|
||||
}
|
||||
}
|
||||
|
||||
// Save project directory
|
||||
projectDir := fs.Cwd()
|
||||
|
||||
// Install deps
|
||||
if projectOptions.FrontEnd != nil {
|
||||
err = cmd.InstallFrontendDeps(projectDir, projectOptions, forceRebuild, "build")
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
// Move to project directory
|
||||
err = os.Chdir(projectDir)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
// Install dependencies
|
||||
err = cmd.InstallGoDependencies()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
// Build application
|
||||
buildMode := cmd.BuildModeProd
|
||||
if debugMode {
|
||||
buildMode = cmd.BuildModeDebug
|
||||
}
|
||||
|
||||
err = cmd.BuildApplication(projectOptions.BinaryName, forceRebuild, buildMode, packageApp, projectOptions)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
logger.Yellow("Awesome! Project '%s' built!", projectOptions.Name)
|
||||
|
||||
return nil
|
||||
|
||||
})
|
||||
}
|
||||
68
cmd/wails/6_serve.go
Normal file
@@ -0,0 +1,68 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"github.com/leaanthony/spinner"
|
||||
"github.com/wailsapp/wails/cmd"
|
||||
)
|
||||
|
||||
func init() {
|
||||
|
||||
var forceRebuild = false
|
||||
buildSpinner := spinner.NewSpinner()
|
||||
buildSpinner.SetSpinSpeed(50)
|
||||
|
||||
commandDescription := `This command builds then serves your application in bridge mode. Useful for developing your app in a browser.`
|
||||
initCmd := app.Command("serve", "Run your Wails project in bridge mode").
|
||||
LongDescription(commandDescription).
|
||||
BoolFlag("f", "Force rebuild of application components", &forceRebuild)
|
||||
|
||||
initCmd.Action(func() error {
|
||||
|
||||
message := "Serving Application"
|
||||
logger.PrintSmallBanner(message)
|
||||
fmt.Println()
|
||||
|
||||
// Check Mewn is installed
|
||||
err := cmd.CheckMewn()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
// Project options
|
||||
projectOptions := &cmd.ProjectOptions{}
|
||||
|
||||
// Check we are in project directory
|
||||
// Check project.json loads correctly
|
||||
fs := cmd.NewFSHelper()
|
||||
err = projectOptions.LoadConfig(fs.Cwd())
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
// Save project directory
|
||||
projectDir := fs.Cwd()
|
||||
|
||||
// Install the bridge library
|
||||
err = cmd.InstallBridge("serve", projectDir, projectOptions)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
// Install dependencies
|
||||
err = cmd.InstallGoDependencies()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
buildMode := cmd.BuildModeBridge
|
||||
err = cmd.BuildApplication(projectOptions.BinaryName, forceRebuild, buildMode, false, projectOptions)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
logger.Yellow("Awesome! Project '%s' built!", projectOptions.Name)
|
||||
return cmd.ServeProject(projectOptions, logger)
|
||||
})
|
||||
}
|
||||
164
cmd/wails/8_update.go
Normal file
@@ -0,0 +1,164 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"log"
|
||||
|
||||
"github.com/leaanthony/spinner"
|
||||
"github.com/mitchellh/go-homedir"
|
||||
"github.com/wailsapp/wails/cmd"
|
||||
)
|
||||
|
||||
func init() {
|
||||
|
||||
var prereleaseRequired bool
|
||||
var specificVersion string
|
||||
|
||||
// var forceRebuild = false
|
||||
checkSpinner := spinner.NewSpinner()
|
||||
checkSpinner.SetSpinSpeed(50)
|
||||
|
||||
commandDescription := `This command allows you to update your version of Wails.`
|
||||
updateCmd := app.Command("update", "Update to newer [pre]releases or specific versions").
|
||||
LongDescription(commandDescription).
|
||||
BoolFlag("pre", "Update to latest Prerelease", &prereleaseRequired).
|
||||
StringFlag("version", "Install a specific version (Overrides other flags)", &specificVersion)
|
||||
|
||||
updateCmd.Action(func() error {
|
||||
|
||||
message := "Checking for updates..."
|
||||
logger.PrintSmallBanner(message)
|
||||
fmt.Println()
|
||||
|
||||
// Get versions
|
||||
checkSpinner.Start(message)
|
||||
|
||||
github := cmd.NewGitHubHelper()
|
||||
var desiredVersion *cmd.SemanticVersion
|
||||
var err error
|
||||
var valid bool
|
||||
|
||||
if len(specificVersion) > 0 {
|
||||
// Check if this is a valid version
|
||||
valid, err = github.IsValidTag(specificVersion)
|
||||
if err == nil {
|
||||
if !valid {
|
||||
err = fmt.Errorf("version '%s' is invalid", specificVersion)
|
||||
} else {
|
||||
desiredVersion, err = cmd.NewSemanticVersion(specificVersion)
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if prereleaseRequired {
|
||||
desiredVersion, err = github.GetLatestPreRelease()
|
||||
} else {
|
||||
desiredVersion, err = github.GetLatestStableRelease()
|
||||
}
|
||||
}
|
||||
if err != nil {
|
||||
checkSpinner.Error(err.Error())
|
||||
return err
|
||||
}
|
||||
checkSpinner.Success()
|
||||
fmt.Println()
|
||||
|
||||
fmt.Println(" Current Version : " + cmd.Version)
|
||||
|
||||
if len(specificVersion) > 0 {
|
||||
fmt.Printf(" Desired Version : v%s\n", desiredVersion)
|
||||
} else {
|
||||
if prereleaseRequired {
|
||||
fmt.Printf(" Latest Prerelease : v%s\n", desiredVersion)
|
||||
} else {
|
||||
fmt.Printf(" Latest Release : v%s\n", desiredVersion)
|
||||
}
|
||||
}
|
||||
|
||||
return updateToVersion(desiredVersion, len(specificVersion) > 0)
|
||||
})
|
||||
}
|
||||
|
||||
func updateToVersion(targetVersion *cmd.SemanticVersion, force bool) error {
|
||||
|
||||
var targetVersionString = "v" + targetVersion.String()
|
||||
|
||||
// Early exit
|
||||
if targetVersionString == cmd.Version {
|
||||
logger.Green("Looks like you're up to date!")
|
||||
return nil
|
||||
}
|
||||
|
||||
var desiredVersion string
|
||||
|
||||
if !force {
|
||||
|
||||
compareVersion := cmd.Version
|
||||
|
||||
currentVersion, err := cmd.NewSemanticVersion(compareVersion)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
var success bool
|
||||
|
||||
// Release -> Pre-Release = Massage current version to prerelease format
|
||||
if targetVersion.IsPreRelease() && currentVersion.IsRelease() {
|
||||
testVersion, err := cmd.NewSemanticVersion(compareVersion + "-0")
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
success, _ = targetVersion.IsGreaterThan(testVersion)
|
||||
}
|
||||
// Pre-Release -> Release = Massage target version to prerelease format
|
||||
if targetVersion.IsRelease() && currentVersion.IsPreRelease() {
|
||||
// We are ok with greater than or equal
|
||||
mainversion := currentVersion.MainVersion()
|
||||
targetVersion, err = cmd.NewSemanticVersion(targetVersion.String())
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
success, _ = targetVersion.IsGreaterThanOrEqual(mainversion)
|
||||
}
|
||||
|
||||
// Release -> Release = Standard check
|
||||
if (targetVersion.IsRelease() && currentVersion.IsRelease()) ||
|
||||
(targetVersion.IsPreRelease() && currentVersion.IsPreRelease()) {
|
||||
|
||||
success, _ = targetVersion.IsGreaterThan(currentVersion)
|
||||
}
|
||||
|
||||
// Compare
|
||||
if !success {
|
||||
logger.Red("The requested version is lower than the current version.")
|
||||
logger.Red("If this is what you really want to do, use `wails update -version %s`", targetVersionString)
|
||||
return nil
|
||||
}
|
||||
|
||||
desiredVersion = "v" + targetVersion.String()
|
||||
|
||||
} else {
|
||||
desiredVersion = "v" + targetVersion.String()
|
||||
}
|
||||
|
||||
fmt.Println()
|
||||
updateSpinner := spinner.NewSpinner()
|
||||
updateSpinner.SetSpinSpeed(40)
|
||||
updateSpinner.Start("Installing Wails " + desiredVersion)
|
||||
|
||||
// Run command in non module directory
|
||||
homeDir, err := homedir.Dir()
|
||||
if err != nil {
|
||||
log.Fatal("Cannot find home directory! Please file a bug report!")
|
||||
}
|
||||
|
||||
err = cmd.NewProgramHelper().RunCommandArray([]string{"go", "get", "github.com/wailsapp/wails/cmd/wails@" + desiredVersion}, homeDir)
|
||||
if err != nil {
|
||||
updateSpinner.Error(err.Error())
|
||||
return err
|
||||
}
|
||||
updateSpinner.Success()
|
||||
fmt.Println()
|
||||
logger.Green("Wails updated to " + desiredVersion)
|
||||
|
||||
return nil
|
||||
}
|
||||