Compare commits
300 Commits
Port-Build
...
123-Unify-
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
801465ac51 | ||
|
|
36e575e0a2 | ||
|
|
d3cd3d43bd | ||
|
|
9116f0d06c | ||
|
|
2c91e26add | ||
|
|
f1647443dc | ||
|
|
b6b6ce2d4a | ||
|
|
abcc869537 | ||
|
|
3e02e1676a | ||
|
|
5c8a4de446 | ||
|
|
7cabef946e | ||
|
|
f2519e5af2 | ||
|
|
5b002e88b7 | ||
|
|
3723e70e6f | ||
|
|
7c08ddbb07 | ||
|
|
c8027f5b81 | ||
|
|
393e418e68 | ||
|
|
dcc3e5fa79 | ||
|
|
f4e6c407ba | ||
|
|
e718a56ed9 | ||
|
|
068443f3fd | ||
|
|
1efc8cb934 | ||
|
|
1ce0620620 | ||
|
|
249a35f90f | ||
|
|
d003de3270 | ||
|
|
9cb2ed10b5 | ||
|
|
4a376f1b67 | ||
|
|
c540f3902c | ||
|
|
accc04ef90 | ||
|
|
d54bd3dc54 | ||
|
|
a54bbb4e14 | ||
|
|
6b1b999546 | ||
|
|
a5aeafc4bc | ||
|
|
39ea5cc456 | ||
|
|
a225b8d50a | ||
|
|
e0036b1cbb | ||
|
|
9a5833f7c9 | ||
|
|
06a1372e80 | ||
|
|
7a16cf74f0 | ||
|
|
4239c89b76 | ||
|
|
29ea5cc74d | ||
|
|
fa27be083d | ||
|
|
9be56c47e4 | ||
|
|
249720b0cc | ||
|
|
3553cb6694 | ||
|
|
3c0fa4c55e | ||
|
|
c07a4b6c16 | ||
|
|
8175eb4446 | ||
|
|
eeab418c90 | ||
|
|
0eb59d823e | ||
|
|
f07705268d | ||
|
|
63fef39854 | ||
|
|
3ea45da2c8 | ||
|
|
eb0d9f3ba4 | ||
|
|
8432f725a9 | ||
|
|
7015b80888 | ||
|
|
ddcc103f37 | ||
|
|
1ac16d1933 | ||
|
|
0f36a88f0e | ||
|
|
b30031d025 | ||
|
|
b849964562 | ||
|
|
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 | ||
|
|
c0371f141a | ||
|
|
a3c41d1740 | ||
|
|
fb081b4876 | ||
|
|
9167063976 | ||
|
|
ffdbb0af64 | ||
|
|
d4b2563e9b | ||
|
|
ab6e7531b4 | ||
|
|
13efa58c9a | ||
|
|
0011e39c55 | ||
|
|
733258cc83 |
17
.1.gitignore
@@ -1,17 +0,0 @@
|
||||
lib/project/templates/vue
|
||||
lib/project/templates/blank
|
||||
tools
|
||||
test
|
||||
.vscode/
|
||||
tmp
|
||||
examples/**/example*
|
||||
!examples/**/*.*
|
||||
node_modules
|
||||
cmd.old
|
||||
lib.old
|
||||
cmd/wails/wails
|
||||
.DS_Store
|
||||
rewrite
|
||||
.rewrite
|
||||
examples/WIP/*
|
||||
docs
|
||||
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
|
||||
35
.github/ISSUE_TEMPLATE/bug_report.md
vendored
Normal file
@@ -0,0 +1,35 @@
|
||||
---
|
||||
name: Bug report
|
||||
about: Create a report to help us improve
|
||||
title: ''
|
||||
labels: bug
|
||||
assignees: ''
|
||||
|
||||
---
|
||||
|
||||
#####################################################
|
||||
If you have a technical issue, please do not open a bug this way!
|
||||
Please use the `wails issue` command!
|
||||
#####################################################
|
||||
|
||||
**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 provide your platform, GO version and variables, etc
|
||||
|
||||
**Additional context**
|
||||
Add any other context about the problem here.
|
||||
4
.gitignore
vendored
@@ -14,4 +14,6 @@
|
||||
examples/**/example*
|
||||
!examples/**/*.*
|
||||
cmd/wails/wails
|
||||
.DS_Store
|
||||
.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"
|
||||
}
|
||||
28
CHANGELOG.md
Normal file
@@ -0,0 +1,28 @@
|
||||
2019-06-18 **v0.16.0**
|
||||
* React template FTW! - Thanks [admin_3.exe](https://github.com/bh90210)!
|
||||
* Updated contributors
|
||||
* Arch Linux detection without lsb-release
|
||||
* Removed deprecated methods for dealing with JS/CSS in the backend
|
||||
|
||||
2019-05-29 **v0.14.11-pre**
|
||||
* Windows fix for spinner
|
||||
|
||||
2019-05-29 **v0.14.10-pre**
|
||||
* Windows fix for Vuetify
|
||||
|
||||
2019-05-29 **v0.14.9-pre**
|
||||
* Vuetify project template 🎉
|
||||
|
||||
2019-05-29 **v0.14.8-pre**
|
||||
* Updated Ubuntu npm install command
|
||||
|
||||
2019-05-22 **v0.14.7-pre**
|
||||
* New projects are built automatically when initialised
|
||||
* Go 1.12 is now a minimum requirement
|
||||
|
||||
2019-05-21 **v0.14.6-pre**
|
||||
* Hotfix for module dependency issue
|
||||
|
||||
2019-05-20 **v0.14.5-pre**
|
||||
* Added developer tooling - New Template Generator
|
||||
* Documentation fixes - Thanks [admin_3.exe](https://github.com/bh90210)!
|
||||
14
CONTRIBUTORS.md
Normal file
@@ -0,0 +1,14 @@
|
||||
# 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)
|
||||
* [Mark Stenglein](https://github.com/ocelotsloth)
|
||||
* [admin_3.exe](https://github.com/bh90210)
|
||||
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
|
||||
|
||||
125
README.md
@@ -1 +1,124 @@
|
||||
# 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/avelino/awesome-go" rel="nofollow"><img src="https://cdn.rawgit.com/sindresorhus/awesome/d7305f38d29fed78fa85652e3a63e154dd8e8829/media/badge.svg" alt="Awesome"></a>
|
||||
<a href="https://dashboard.guardrails.io/default/gh/wailsapp/wails"><img src="https://badges.guardrails.io/wailsapp/wails.svg?token=53657bc22ec360d7673c894fdd70568e918ec581d10d84427ed4de5fe1eeff1a"></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
|
||||
- Quickly create Vue, Vuetify or React frontends for your Go programs
|
||||
- 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.12
|
||||
- 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
|
||||
|
||||
**Ensure Go modules are enabled: GO111MODULE=on and go/bin is in your PATH variable.**
|
||||
|
||||
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. A huge thank you to each and every one of you!
|
||||
|
||||
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)
|
||||
|
||||
|
||||
54
app.go
@@ -2,13 +2,12 @@ package wails
|
||||
|
||||
import (
|
||||
"github.com/wailsapp/wails/cmd"
|
||||
"github.com/wailsapp/wails/cmd/frameworks"
|
||||
)
|
||||
|
||||
// -------------------------------- Compile time Flags ------------------------------
|
||||
|
||||
// DebugMode indicates if we are in debug Mode
|
||||
var DebugMode = "true"
|
||||
// BuildMode indicates what mode we are in
|
||||
var BuildMode = cmd.BuildModeProd
|
||||
|
||||
// ----------------------------------------------------------------------------------
|
||||
|
||||
@@ -18,17 +17,11 @@ type App struct {
|
||||
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
|
||||
headless bool // Indicates if the app should be started in headless mode
|
||||
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
|
||||
@@ -55,7 +48,7 @@ func CreateApp(optionalConfig ...*AppConfig) *App {
|
||||
result.config = appconfig
|
||||
|
||||
// Set up the CLI if not in release mode
|
||||
if DebugMode == "true" {
|
||||
if BuildMode != cmd.BuildModeProd {
|
||||
result.cli = result.setupCli()
|
||||
} else {
|
||||
// Disable Inspector in release mode
|
||||
@@ -67,12 +60,16 @@ func CreateApp(optionalConfig ...*AppConfig) *App {
|
||||
|
||||
// Run the app
|
||||
func (a *App) Run() error {
|
||||
if DebugMode == "true" {
|
||||
if BuildMode != cmd.BuildModeProd {
|
||||
return a.cli.Run()
|
||||
} else {
|
||||
a.logLevel = "error"
|
||||
return a.start()
|
||||
}
|
||||
|
||||
a.logLevel = "error"
|
||||
err := a.start()
|
||||
if err != nil {
|
||||
a.log.Error(err.Error())
|
||||
}
|
||||
return err
|
||||
}
|
||||
|
||||
func (a *App) start() error {
|
||||
@@ -84,7 +81,7 @@ func (a *App) start() error {
|
||||
a.log.Info("Starting")
|
||||
|
||||
// Check if we are to run in headless mode
|
||||
if a.headless {
|
||||
if BuildMode == cmd.BuildModeBridge {
|
||||
a.renderer = &Headless{}
|
||||
}
|
||||
|
||||
@@ -109,21 +106,8 @@ func (a *App) start() error {
|
||||
return err
|
||||
}
|
||||
|
||||
// Inject framework, if specified
|
||||
if frameworks.FrameworkToUse != nil {
|
||||
a.renderer.InjectFramework(frameworks.FrameworkToUse.JS, frameworks.FrameworkToUse.CSS)
|
||||
}
|
||||
|
||||
// Inject CSS
|
||||
a.renderer.AddCSSList(a.cssCache)
|
||||
|
||||
// Inject JS
|
||||
a.renderer.AddJSList(a.jsCache)
|
||||
|
||||
// Run the renderer
|
||||
a.renderer.Run()
|
||||
|
||||
return nil
|
||||
return a.renderer.Run()
|
||||
}
|
||||
|
||||
// Bind allows the user to bind the given object
|
||||
@@ -131,15 +115,3 @@ func (a *App) start() error {
|
||||
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)
|
||||
}
|
||||
|
||||
@@ -1,8 +1,6 @@
|
||||
package wails
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"github.com/wailsapp/wails/cmd"
|
||||
)
|
||||
|
||||
@@ -11,18 +9,17 @@ 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).
|
||||
// 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.PrintBanner()
|
||||
fmt.Println()
|
||||
log.YellowUnderline(app.config.Title + " - Debug Build")
|
||||
return nil
|
||||
})
|
||||
|
||||
@@ -4,11 +4,9 @@ import (
|
||||
"strings"
|
||||
|
||||
"github.com/dchest/htmlmin"
|
||||
"github.com/gobuffalo/packr"
|
||||
"github.com/leaanthony/mewn"
|
||||
)
|
||||
|
||||
var assets = packr.NewBox("./assets/default")
|
||||
|
||||
// AppConfig is the configuration structure used when creating a Wails App object
|
||||
type AppConfig struct {
|
||||
Width, Height int
|
||||
@@ -43,7 +41,7 @@ func (a *AppConfig) merge(in *AppConfig) error {
|
||||
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 HMTL
|
||||
// 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")
|
||||
@@ -85,7 +83,7 @@ func newAppConfig(userConfig *AppConfig) (*AppConfig, error) {
|
||||
Resizable: true,
|
||||
Title: "My Wails App",
|
||||
Colour: "#FFF", // White by default
|
||||
HTML: BoxString(&defaultAssets, "default.html"),
|
||||
HTML: mewn.String("./wailsruntimeassets/default/default.html"),
|
||||
}
|
||||
|
||||
if userConfig != nil {
|
||||
|
||||
@@ -1 +0,0 @@
|
||||
<div id="app"></div>
|
||||
2
assets/default/jquery.3.3.1.min.js
vendored
@@ -1,179 +0,0 @@
|
||||
<html>
|
||||
|
||||
<head>
|
||||
<title>Wails Headless</title>
|
||||
<style>
|
||||
.wails-reconnect-overlay {
|
||||
position: fixed;
|
||||
top: 0;
|
||||
left: 0;
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
background: rgba(0, 0, 0, 0.6);
|
||||
font-family: sans-serif;
|
||||
display: none;
|
||||
z-index: 999999;
|
||||
}
|
||||
|
||||
.wails-reconnect-overlay-content {
|
||||
padding: 20px 30px;
|
||||
text-align: center;
|
||||
width: 20em;
|
||||
position: relative;
|
||||
height: 17em;
|
||||
border-radius: 1em;
|
||||
margin: 5% auto 0;
|
||||
background-color: white;
|
||||
box-shadow: 1px 1px 20px 3px;
|
||||
background-image: url("data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAC8AAAAuCAMAAACPpbA7AAAAqFBMVEUAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAEBAQAAAAAAAAEBAQAAAAAAAAAAAAEBAQEBAQDAwMBAQEAAAABAQEAAAAAAAAAAAABAQEAAAAAAAACAgICAgIBAQEAAAAAAAAAAAAAAAAAAAAAAAABAQEAAAACAgIAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAFBQWKCj6oAAAAN3RSTlMALiIqDhkGBAswJjP0GxP6NR4W9/ztjRDMhWU50G9g5eHXvbZ9XEI9xZTcqZl2aldKo55QwoCvZUgzhAAAAs9JREFUSMeNleeWqjAUhU0BCaH3Itiw9zKT93+zG02QK1hm/5HF+jzZJ6fQe6cyXE+jg9X7o9wxuylIIf4Tv2V3+bOrEXnf8dwQ/KQIGDN2/S+4OmVCVXL/ScBnfibxURqIByP/hONE8r8T+bDMlQ98KSl7Y8hzjpS8v1qtDh8u5f8KQpGpfnPPhqG8JeogN37Hq9eaN2xRhIwAaGnvws8F1ShxqK5ob2twYi1FAMD4rXsYtnC/JEiRbl4cUrCWhnMCLRFemXezXbb59QK4WASOsm6n2W1+4CBT2JmtzQ6fsrbGubR/NFbd2g5Y179+5w/GEHaKsHjYCet7CgrXU3txarNC7YxOVJtIj4/ERzMdZfzc31hp+8cD6eGILgarZY9uZ12hAs03vfBD9C171gS5Omz7OcvxALQIn4u8RRBBBcsi9WW2woO9ipLgfzpYlggg3ZRdROUC8KT7QLqq3W9KB5BbdFVg4929kdwp6+qaZnMCCNBdj+NyN1W885Ry/AL3D4AQbsVV4noCiM/C83kyYq80XlDAYQtralOiDzoRAHlotWl8q2tjvYlOgcg1A8jEApZa+C06TBdAz2Qv0wu11I/zZOyJQ6EwGez2P2b8PIQr1hwwnAZsAxwA4UAYOyXUxM/xp6tHAn4GUmPGM9R28oVxgC0e/zQJJI6DyhyZ1r7uzRQhpcW7x7vTaWSzKSG6aep77kroTEl3U81uSVaUTtgEINfC8epx+Q4F9SpplHG84Ek6m4RAq9/TLkOBrxyeuddZhHvGIp1XXfFy3Z3vtwNblKGiDn+J+92vwwABHghj7HnzlS1H5kB49AZvdGCFgiBPq69qfXPr3y++yilF0ON4R8eR7spAsLpZ95NqAW5tab1c4vkZm6aleajchMwYTdILQQTwE2OV411ZM9WztDjPql12caBi6gDpUKmDd4U1XNdQxZ4LIXQ5/Tr4P7I9tYcFrDK3AAAAAElFTkSuQmCC");
|
||||
background-repeat: no-repeat;
|
||||
background-position: center;
|
||||
}
|
||||
|
||||
.wails-reconnect-overlay-title {
|
||||
font-size: 2em;
|
||||
}
|
||||
|
||||
.wails-reconnect-overlay-message {
|
||||
font-size: 1.3em;
|
||||
}
|
||||
|
||||
/* https://codepen.io/EastingAndNorthing/pen/aNWrZz - Cheers Mark! */
|
||||
|
||||
.wails-reconnect-overlay-loadingspinner {
|
||||
pointer-events: none;
|
||||
width: 2.5em;
|
||||
height: 2.5em;
|
||||
border: 0.4em solid transparent;
|
||||
border-color: #eee;
|
||||
border-top-color: #3E67EC;
|
||||
border-radius: 50%;
|
||||
animation: loadingspin 1s linear infinite;
|
||||
margin: auto;
|
||||
padding: 2.5em;
|
||||
}
|
||||
|
||||
@keyframes loadingspin {
|
||||
100% {
|
||||
transform: rotate(360deg)
|
||||
}
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
|
||||
<body>
|
||||
<div class="wails-reconnect-overlay">
|
||||
<div class="wails-reconnect-overlay-content">
|
||||
<div class="wails-reconnect-overlay-title">Disconnected</div><br>
|
||||
<div class="wails-reconnect-overlay-loadingspinner"></div><br>
|
||||
<div class="wails-reconnect-overlay-message">Waiting for backend</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div id="app"></div>
|
||||
|
||||
<script id="wails-headless-runtime">
|
||||
(function () {
|
||||
|
||||
var websocket = null;
|
||||
var connectTimer = null;
|
||||
var reconnectOverlay = document.querySelector(".wails-reconnect-overlay");
|
||||
var connectionState = "disconnected";
|
||||
|
||||
function showReconnectOverlay() {
|
||||
reconnectOverlay.style.display = 'block';
|
||||
}
|
||||
|
||||
function hideReconnectOverlay() {
|
||||
reconnectOverlay.style.display = 'none';
|
||||
}
|
||||
|
||||
window.external = {
|
||||
invoke: function (msg) {
|
||||
websocket.send(msg);
|
||||
}
|
||||
};
|
||||
|
||||
function addScript(script, id) {
|
||||
var s = document.createElement("script")
|
||||
if (id) {
|
||||
s.id = id;
|
||||
}
|
||||
s.textContent = script;
|
||||
document.head.appendChild(s)
|
||||
}
|
||||
|
||||
function handleConnect() {
|
||||
console.log("[Wails] Connected to backend");
|
||||
addKeyListener();
|
||||
hideReconnectOverlay();
|
||||
clearInterval(connectTimer);
|
||||
websocket.onclose = handleDisconnect;
|
||||
websocket.onmessage = handleMessage;
|
||||
connectionState = "connected";
|
||||
// websocket.onerror = function () { }
|
||||
}
|
||||
|
||||
function handleDisconnect() {
|
||||
console.log("[Wails] Disconnected from backend");
|
||||
websocket = null;
|
||||
removeKeyListener();
|
||||
connectionState = "disconnected";
|
||||
showReconnectOverlay();
|
||||
connect();
|
||||
}
|
||||
|
||||
function connect() {
|
||||
connectTimer = setInterval(function () {
|
||||
if (websocket == null) {
|
||||
websocket = new WebSocket("ws://localhost:34115/ws")
|
||||
websocket.onopen = handleConnect;
|
||||
websocket.onerror = function (e) {
|
||||
e.stopImmediatePropagation();
|
||||
e.stopPropagation();
|
||||
e.preventDefault();
|
||||
websocket = null;
|
||||
return false
|
||||
}
|
||||
}
|
||||
}, 300);
|
||||
}
|
||||
|
||||
function handleMessage(e) {
|
||||
addScript(e.data);
|
||||
}
|
||||
|
||||
// Key listener
|
||||
var delta = 300;
|
||||
var lastKeypressTime = 0;
|
||||
function KeyHandler(event) {
|
||||
if (event.key === "`") {
|
||||
var thisKeypressTime = new Date();
|
||||
if (thisKeypressTime - lastKeypressTime <= delta) {
|
||||
console.log("Double tap!")
|
||||
// optional - if we'd rather not detect a triple-press
|
||||
// as a second double-press, reset the timestamp
|
||||
thisKeypressTime = 0;
|
||||
}
|
||||
lastKeypressTime = thisKeypressTime;
|
||||
}
|
||||
}
|
||||
|
||||
function addKeyListener() {
|
||||
document.body.addEventListener('keydown', KeyHandler);
|
||||
}
|
||||
|
||||
function removeKeyListener() {
|
||||
document.body.removeEventListener('keydown', KeyHandler);
|
||||
}
|
||||
|
||||
connect();
|
||||
|
||||
|
||||
}());
|
||||
|
||||
</script>
|
||||
|
||||
</body>
|
||||
|
||||
</html>
|
||||
@@ -153,8 +153,11 @@ func (b *boundFunction) setInputValue(index int, typ reflect.Type, val interface
|
||||
}
|
||||
}()
|
||||
|
||||
// Do the conversion
|
||||
result = reflect.ValueOf(val).Convert(typ)
|
||||
|
||||
// Translate javascript null values
|
||||
if val == nil {
|
||||
result = reflect.Zero(typ)
|
||||
} else {
|
||||
result = reflect.ValueOf(val).Convert(typ)
|
||||
}
|
||||
return result, err
|
||||
}
|
||||
|
||||
65
binding_internal.go
Normal file
@@ -0,0 +1,65 @@
|
||||
package wails
|
||||
|
||||
import "strings"
|
||||
import "fmt"
|
||||
|
||||
type internalMethods struct{
|
||||
log *CustomLogger
|
||||
browser *RuntimeBrowser
|
||||
}
|
||||
|
||||
func newInternalMethods() *internalMethods {
|
||||
return &internalMethods{
|
||||
log: newCustomLogger("InternalCall"),
|
||||
browser: newRuntimeBrowser(),
|
||||
}
|
||||
}
|
||||
|
||||
func (i *internalMethods) processCall(callData *callData) (interface{}, error) {
|
||||
if !strings.HasPrefix(callData.BindingName, ".wails.") {
|
||||
return nil, fmt.Errorf("Invalid call signature '%s'", callData.BindingName)
|
||||
}
|
||||
|
||||
// Strip prefix
|
||||
var splitCall = strings.Split(callData.BindingName,".")[2:]
|
||||
if len(splitCall) != 2 {
|
||||
return nil, fmt.Errorf("Invalid call signature '%s'", callData.BindingName)
|
||||
}
|
||||
|
||||
group := splitCall[0]
|
||||
switch group {
|
||||
case "Browser":
|
||||
return i.processBrowserCommand(splitCall[1], callData.Data)
|
||||
default:
|
||||
return nil, fmt.Errorf("Unknown internal command group '%s'", group)
|
||||
}
|
||||
}
|
||||
|
||||
func (i *internalMethods) processBrowserCommand(command string, data interface{}) (interface{}, error) {
|
||||
switch command {
|
||||
case "OpenURL":
|
||||
url := data.(string)
|
||||
// Strip string quotes. Credit: https://stackoverflow.com/a/44222648
|
||||
if url[0] == '"' {
|
||||
url = url[1:]
|
||||
}
|
||||
if i := len(url)-1; url[i] == '"' {
|
||||
url = url[:i]
|
||||
}
|
||||
i.log.Debugf("Calling Browser.OpenURL with '%s'", url)
|
||||
return nil, i.browser.OpenURL(url)
|
||||
case "OpenFile":
|
||||
filename := data.(string)
|
||||
// Strip string quotes. Credit: https://stackoverflow.com/a/44222648
|
||||
if filename[0] == '"' {
|
||||
filename = filename[1:]
|
||||
}
|
||||
if i := len(filename)-1; filename[i] == '"' {
|
||||
filename = filename[:i]
|
||||
}
|
||||
i.log.Debugf("Calling Browser.OpenFile with '%s'", filename)
|
||||
return nil, i.browser.OpenFile(filename)
|
||||
default:
|
||||
return nil, fmt.Errorf("Unknown Browser command '%s'", command)
|
||||
}
|
||||
}
|
||||
@@ -17,6 +17,7 @@ binding:
|
||||
type bindingManager struct {
|
||||
methods map[string]*boundMethod
|
||||
functions map[string]*boundFunction
|
||||
internalMethods *internalMethods
|
||||
initMethods []*boundMethod
|
||||
log *CustomLogger
|
||||
renderer Renderer
|
||||
@@ -27,9 +28,10 @@ type bindingManager struct {
|
||||
|
||||
func newBindingManager() *bindingManager {
|
||||
result := &bindingManager{
|
||||
methods: make(map[string]*boundMethod),
|
||||
functions: make(map[string]*boundFunction),
|
||||
log: newCustomLogger("Bind"),
|
||||
methods: make(map[string]*boundMethod),
|
||||
functions: make(map[string]*boundFunction),
|
||||
log: newCustomLogger("Bind"),
|
||||
internalMethods: newInternalMethods(),
|
||||
}
|
||||
return result
|
||||
}
|
||||
@@ -163,8 +165,76 @@ func (b *bindingManager) bind(object interface{}) {
|
||||
b.objectsToBind = append(b.objectsToBind, object)
|
||||
}
|
||||
|
||||
func (b *bindingManager) processInternalCall(callData *callData) (interface{}, error) {
|
||||
// Strip prefix
|
||||
return b.internalMethods.processCall(callData)
|
||||
}
|
||||
|
||||
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) (interface{}, error) {
|
||||
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
|
||||
@@ -176,13 +246,10 @@ func (b *bindingManager) processCall(callData *callData) (interface{}, error) {
|
||||
}
|
||||
}
|
||||
|
||||
// Return values
|
||||
var result []reflect.Value
|
||||
var err error
|
||||
|
||||
// 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))
|
||||
@@ -191,59 +258,16 @@ func (b *bindingManager) processCall(callData *callData) (interface{}, error) {
|
||||
|
||||
switch dotCount {
|
||||
case 1:
|
||||
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
|
||||
result, err = b.processFunctionCall(callData)
|
||||
case 2:
|
||||
// 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
|
||||
|
||||
result, err = b.processMethodCall(callData)
|
||||
case 3:
|
||||
result, err = b.processInternalCall(callData)
|
||||
default:
|
||||
return nil, fmt.Errorf("Invalid binding name '%s'", callData.BindingName)
|
||||
result = nil
|
||||
err = fmt.Errorf("Invalid binding name '%s'", callData.BindingName)
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
// callWailsInitMethods calls all of the WailsInit methods that were
|
||||
|
||||
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"
|
||||
)
|
||||
191
cmd/bundle.go
@@ -1,191 +0,0 @@
|
||||
package cmd
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"fmt"
|
||||
"image"
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"path"
|
||||
"path/filepath"
|
||||
"runtime"
|
||||
"strings"
|
||||
"text/template"
|
||||
"time"
|
||||
|
||||
"github.com/jackmordaunt/icns"
|
||||
)
|
||||
|
||||
// BundleHelper helps with the 'wails bundle' command
|
||||
type BundleHelper struct {
|
||||
fs *FSHelper
|
||||
log *Logger
|
||||
system *SystemHelper
|
||||
}
|
||||
|
||||
// NewBundleHelper creates a new BundleHelper!
|
||||
func NewBundleHelper() *BundleHelper {
|
||||
return &BundleHelper{
|
||||
fs: NewFSHelper(),
|
||||
log: NewLogger(),
|
||||
system: NewSystemHelper(),
|
||||
}
|
||||
}
|
||||
|
||||
type plistData struct {
|
||||
Title string
|
||||
Exe string
|
||||
BundleID string
|
||||
Version string
|
||||
Author string
|
||||
Date string
|
||||
}
|
||||
|
||||
func newPlistData(title, exe, bundleID, version, author string) *plistData {
|
||||
now := time.Now().Format(time.RFC822)
|
||||
return &plistData{
|
||||
Title: title,
|
||||
Exe: exe,
|
||||
Version: version,
|
||||
BundleID: bundleID,
|
||||
Author: author,
|
||||
Date: now,
|
||||
}
|
||||
}
|
||||
|
||||
func defaultString(val string, defaultVal string) string {
|
||||
if val != "" {
|
||||
return val
|
||||
}
|
||||
return defaultVal
|
||||
}
|
||||
|
||||
func (b *BundleHelper) getBundleFileBaseDir() string {
|
||||
return filepath.Join(b.system.homeDir, "go", "src", "github.com", "wailsapp", "wails", "cmd", "bundle", runtime.GOOS)
|
||||
}
|
||||
|
||||
// Bundle the application into a platform specific package
|
||||
func (b *BundleHelper) Bundle(po *ProjectOptions) error {
|
||||
// Check we have the exe
|
||||
if !b.fs.FileExists(po.BinaryName) {
|
||||
return fmt.Errorf("cannot bundle non-existant binary file '%s'. Please build with 'wails build' first", po.BinaryName)
|
||||
}
|
||||
switch runtime.GOOS {
|
||||
case "darwin":
|
||||
return b.bundleOSX(po)
|
||||
default:
|
||||
return fmt.Errorf("platform '%s' not supported for bundling yet", runtime.GOOS)
|
||||
}
|
||||
}
|
||||
|
||||
// Bundle the application
|
||||
func (b *BundleHelper) bundleOSX(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")
|
||||
bundleID := strings.Join([]string{"wails", name, version}, ".")
|
||||
plistData := newPlistData(name, exe, bundleID, 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 bundle
|
||||
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.getBundleFileBaseDir(), "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.bundleIcon(resourceDir)
|
||||
return err
|
||||
}
|
||||
|
||||
func (b *BundleHelper) bundleIcon(resourceDir 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.getBundleFileBaseDir(), "icon.png")
|
||||
iconData, err := ioutil.ReadFile(iconfile)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
err = ioutil.WriteFile(srcIcon, iconData, 0644)
|
||||
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()
|
||||
if err := icns.Encode(dest, srcImg); err != nil {
|
||||
return err
|
||||
|
||||
}
|
||||
return nil
|
||||
}
|
||||
24
cmd/cli.go
@@ -96,6 +96,7 @@ type Command struct {
|
||||
flagCount int
|
||||
log *Logger
|
||||
helpFlag bool
|
||||
hidden bool
|
||||
}
|
||||
|
||||
// NewCommand creates a new Command
|
||||
@@ -106,6 +107,7 @@ func NewCommand(name string, description string, app *Cli, parentCommandPath str
|
||||
SubCommandsMap: make(map[string]*Command),
|
||||
App: app,
|
||||
log: NewLogger(),
|
||||
hidden: false,
|
||||
}
|
||||
|
||||
// Set up command path
|
||||
@@ -194,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
|
||||
@@ -211,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() {
|
||||
@@ -222,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)
|
||||
@@ -240,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)
|
||||
|
||||
10
cmd/cmd-mewn.go
Normal file
@@ -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: BoxString(&assets, "bootstrap.bundle.min.js"),
|
||||
CSS: BoxString(&assets, "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: BoxString(&assets, "bootstrap.bundle.min.js"),
|
||||
CSS: BoxString(&assets, "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: BoxString(&assets, "bootstrap.bundle.min.js"),
|
||||
CSS: BoxString(&assets, "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: BoxString(&assets, "bootstrap.bundle.min.js"),
|
||||
CSS: BoxString(&assets, "bootstrap.min.css"),
|
||||
}
|
||||
}
|
||||
@@ -1,5 +0,0 @@
|
||||
{
|
||||
"Name": "Bootstrap 4 (Lux)",
|
||||
"Description": "Bootstrap with Lux theme",
|
||||
"BuildTag": "frameworkbootstrap4lux"
|
||||
}
|
||||
@@ -1,28 +0,0 @@
|
||||
package frameworks
|
||||
|
||||
import (
|
||||
"log"
|
||||
|
||||
"github.com/gobuffalo/packr"
|
||||
)
|
||||
|
||||
// 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
|
||||
|
||||
// BoxString extracts a string from a packr box
|
||||
func BoxString(box *packr.Box, filename string) string {
|
||||
result, err := box.FindString(filename)
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
return result
|
||||
}
|
||||
100
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,49 @@ 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
|
||||
}
|
||||
|
||||
// Dir holds information about a directory
|
||||
type Dir struct {
|
||||
localPath string
|
||||
fullPath string
|
||||
}
|
||||
|
||||
// Directory creates a new Dir struct with the given directory path
|
||||
func (fs *FSHelper) Directory(dir string) (*Dir, error) {
|
||||
fullPath, err := filepath.Abs(dir)
|
||||
return &Dir{fullPath: fullPath}, err
|
||||
}
|
||||
|
||||
// LocalDir creates a new Dir struct based on a path relative to the caller
|
||||
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 +148,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
|
||||
}
|
||||
59
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,58 @@ 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])
|
||||
// strip quotations
|
||||
osName = strings.Trim(osName, "\"")
|
||||
// Check distro name against list of distros
|
||||
switch osName {
|
||||
case "Fedora":
|
||||
result.Distribution = RedHat
|
||||
case "CentOS":
|
||||
result.Distribution = RedHat
|
||||
case "Arch Linux":
|
||||
result.Distribution = Arch
|
||||
}
|
||||
}
|
||||
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
|
||||
}
|
||||
|
||||
12
cmd/log.go
@@ -17,6 +17,7 @@ func NewLogger() *Logger {
|
||||
return &Logger{errorOnly: false}
|
||||
}
|
||||
|
||||
// SetErrorOnly ensures that only errors are logged out
|
||||
func (l *Logger) SetErrorOnly(errorOnly bool) {
|
||||
l.errorOnly = errorOnly
|
||||
}
|
||||
@@ -99,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"
|
||||
@@ -52,7 +52,7 @@ func getRequiredProgramsLinux() *Prerequisites {
|
||||
case Ubuntu:
|
||||
result.Add(newPrerequisite("gcc", "Please install with `sudo apt install build-essentials` and try again"))
|
||||
result.Add(newPrerequisite("pkg-config", "Please install with `sudo apt install pkg-config` and try again"))
|
||||
result.Add(newPrerequisite("npm", "Please install with `sudo apt install npm` and try again"))
|
||||
result.Add(newPrerequisite("npm", "Please install with `sudo snap install node --channel=12/stable --classic` and try again"))
|
||||
|
||||
default:
|
||||
result.Add(newPrerequisite("gcc", "Please install with your system package manager and try again"))
|
||||
@@ -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"))
|
||||
|
||||
@@ -56,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 {
|
||||
@@ -92,7 +92,7 @@ func (p *Program) Run(vars ...string) (stdout, stderr string, exitCode int, err
|
||||
|
||||
// InstallGoPackage installs the given Go package
|
||||
func (p *ProgramHelper) InstallGoPackage(packageName string) error {
|
||||
args := strings.Split("get -u "+packageName, " ")
|
||||
args := strings.Split("get "+packageName, " ")
|
||||
_, stderr, err := p.shell.Run("go", args...)
|
||||
if err != nil {
|
||||
fmt.Println(stderr)
|
||||
@@ -107,7 +107,7 @@ func (p *ProgramHelper) RunCommand(command string) error {
|
||||
}
|
||||
|
||||
// RunCommandArray runs the command specified in the array
|
||||
func (p *ProgramHelper) RunCommandArray(args []string) error {
|
||||
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)
|
||||
@@ -116,7 +116,13 @@ func (p *ProgramHelper) RunCommandArray(args []string) error {
|
||||
return err
|
||||
}
|
||||
args = args[1:]
|
||||
_, stderr, err := p.shell.Run(program, args...)
|
||||
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)
|
||||
}
|
||||
|
||||
353
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,25 @@ func (ph *ProjectHelper) GenerateProject(projectOptions *ProjectOptions) error {
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
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.")
|
||||
|
||||
// // If we are on windows, dump a windows_resource.json
|
||||
// if runtime.GOOS == "windows" {
|
||||
// ph.GenerateWindowsResourceConfig(projectOptions)
|
||||
// }
|
||||
|
||||
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 +107,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 +127,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 +247,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
|
||||
16
cmd/shell.go
@@ -2,6 +2,7 @@ package cmd
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"os"
|
||||
"os/exec"
|
||||
)
|
||||
|
||||
@@ -17,6 +18,21 @@ func NewShellHelper() *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
|
||||
|
||||
@@ -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 = `
|
||||
@@ -258,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)
|
||||
}
|
||||
@@ -281,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)
|
||||
}
|
||||
|
||||
342
cmd/templates.go
@@ -5,91 +5,94 @@ import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"path"
|
||||
"log"
|
||||
"path/filepath"
|
||||
"runtime"
|
||||
"strings"
|
||||
"text/template"
|
||||
|
||||
"github.com/kennygrant/sanitize"
|
||||
"github.com/leaanthony/slicer"
|
||||
)
|
||||
|
||||
const templateSuffix = ".template"
|
||||
|
||||
// TemplateHelper helps with creating projects
|
||||
type TemplateHelper struct {
|
||||
system *SystemHelper
|
||||
fs *FSHelper
|
||||
templateDir string
|
||||
// templates map[string]string
|
||||
templateSuffix string
|
||||
metadataFilename string
|
||||
// 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"`
|
||||
}
|
||||
|
||||
// Template defines a single template
|
||||
type Template struct {
|
||||
// TemplateDetails holds information about a specific template
|
||||
type TemplateDetails struct {
|
||||
Name string
|
||||
Dir string
|
||||
Metadata map[string]interface{}
|
||||
Path string
|
||||
Metadata *TemplateMetadata
|
||||
fs *FSHelper
|
||||
}
|
||||
|
||||
// TemplateHelper is a utility object to help with processing templates
|
||||
type TemplateHelper struct {
|
||||
templateDir *Dir
|
||||
fs *FSHelper
|
||||
metadataFilename string
|
||||
}
|
||||
|
||||
// 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
|
||||
}
|
||||
|
||||
// GetTemplateNames returns a map of all available templates
|
||||
func (t *TemplateHelper) GetTemplateNames() (map[string]string, error) {
|
||||
templateDirs, err := t.fs.GetSubdirs(t.templateDir)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return templateDirs, nil
|
||||
// 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)
|
||||
}
|
||||
|
||||
// GetTemplateDetails returns a map of Template structs containing details
|
||||
// of the found templates
|
||||
func (t *TemplateHelper) GetTemplateDetails() (map[string]*Template, error) {
|
||||
templateDirs, err := t.fs.GetSubdirs(t.templateDir)
|
||||
// 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
|
||||
}
|
||||
targetMetadata := filepath.Join(targetDir, t.metadataFilename)
|
||||
err = t.fs.SaveAsJSON(details, targetMetadata)
|
||||
|
||||
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
|
||||
return targetDir, err
|
||||
}
|
||||
|
||||
// LoadMetadata loads the template's 'metadata.json' file
|
||||
func (t *TemplateHelper) LoadMetadata(dir string) (map[string]interface{}, error) {
|
||||
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
|
||||
}
|
||||
@@ -101,14 +104,48 @@ func (t *TemplateHelper) LoadMetadata(dir string) (map[string]interface{}, error
|
||||
return result, err
|
||||
}
|
||||
|
||||
// TemplateExists returns true if the given template name exists
|
||||
func (t *TemplateHelper) TemplateExists(templateName string) (bool, error) {
|
||||
templates, err := t.GetTemplateNames()
|
||||
// GetTemplateDetails returns a map of Template structs containing details
|
||||
// of the found templates
|
||||
func (t *TemplateHelper) GetTemplateDetails() (map[string]*TemplateDetails, error) {
|
||||
|
||||
// Get the subdirectory details
|
||||
templateDirs, err := t.templateDir.GetSubdirs()
|
||||
if err != nil {
|
||||
return false, err
|
||||
return nil, err
|
||||
}
|
||||
_, exists := templates[templateName]
|
||||
return exists, 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 nil, err
|
||||
}
|
||||
result[name].Metadata = metadata
|
||||
if metadata.Name != "" {
|
||||
result[name].Name = metadata.Name
|
||||
} else {
|
||||
// Ignore bad templates?
|
||||
result[name] = nil
|
||||
}
|
||||
}
|
||||
|
||||
return result, nil
|
||||
}
|
||||
|
||||
// GetTemplateFilenames returns all the filenames of the given template
|
||||
func (t *TemplateHelper) GetTemplateFilenames(template *TemplateDetails) (*slicer.StringSlicer, error) {
|
||||
|
||||
// Get the subdirectory details
|
||||
templateDir, err := t.fs.Directory(template.Path)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return templateDir.GetAllFilenames()
|
||||
}
|
||||
|
||||
// InstallTemplate installs the template given in the project options to the
|
||||
@@ -116,161 +153,60 @@ func (t *TemplateHelper) TemplateExists(templateName string) (bool, error) {
|
||||
func (t *TemplateHelper) InstallTemplate(projectPath string, projectOptions *ProjectOptions) error {
|
||||
|
||||
// Get template files
|
||||
template, err := t.getTemplateFiles(projectOptions.Template)
|
||||
templateFilenames, err := t.GetTemplateFilenames(projectOptions.selectedTemplate)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
// Copy files to target
|
||||
err = template.Install(projectPath, projectOptions)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
templatePath := projectOptions.selectedTemplate.Path
|
||||
|
||||
return nil
|
||||
}
|
||||
templateJSONFilename := filepath.Join(templatePath, t.metadataFilename)
|
||||
|
||||
// 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()
|
||||
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
|
||||
}
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
// Don't copy template metadata
|
||||
localPath = strings.TrimPrefix(dir, templateDir+string(filepath.Separator))
|
||||
if localPath == t.metadataFilename {
|
||||
return 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
|
||||
templateFiles := templateFilenames.Filter(func(filename string) bool {
|
||||
filename = filepath.FromSlash(filename)
|
||||
return strings.HasPrefix(filename, templatePath) && filename != templateJSONFilename
|
||||
})
|
||||
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("error processing template '%s' in path '%q': %v", templateName, templateDir, err)
|
||||
}
|
||||
return result, err
|
||||
}
|
||||
templateFiles.Each(func(templateFile string) {
|
||||
|
||||
// Install the template files into the given project path
|
||||
func (t *templateFiles) Install(projectPath string, projectOptions *ProjectOptions) error {
|
||||
|
||||
fs := NewFSHelper()
|
||||
|
||||
// Create directories
|
||||
var targetDir string
|
||||
for _, dirname := range t.Dirs {
|
||||
targetDir = filepath.Join(projectPath, dirname)
|
||||
fs.MkDir(targetDir)
|
||||
}
|
||||
|
||||
// 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)
|
||||
|
||||
err = fs.CopyFile(sourceFile, targetFile)
|
||||
// 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,24 +0,0 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
wails "github.com/wailsapp/wails"
|
||||
)
|
||||
|
||||
var html = `
|
||||
<div style='text-align:center'>
|
||||
<h1> Basic Template </h1>
|
||||
Welcome to your basic Wails app!
|
||||
</div>
|
||||
`
|
||||
|
||||
func main() {
|
||||
|
||||
// Initialise the app
|
||||
app := wails.CreateApp(&wails.AppConfig{
|
||||
Width: 1024,
|
||||
Height: 768,
|
||||
Title: "{{.Name}}",
|
||||
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"
|
||||
}
|
||||
23
cmd/templates/create-react-app/frontend/.gitignore
vendored
Normal file
@@ -0,0 +1,23 @@
|
||||
# See https://help.github.com/articles/ignoring-files/ for more about ignoring files.
|
||||
|
||||
# dependencies
|
||||
/node_modules
|
||||
/.pnp
|
||||
.pnp.js
|
||||
|
||||
# testing
|
||||
/coverage
|
||||
|
||||
# production
|
||||
/build
|
||||
|
||||
# misc
|
||||
.DS_Store
|
||||
.env.local
|
||||
.env.development.local
|
||||
.env.test.local
|
||||
.env.production.local
|
||||
|
||||
npm-debug.log*
|
||||
yarn-debug.log*
|
||||
yarn-error.log*
|
||||
68
cmd/templates/create-react-app/frontend/README.md
Normal file
@@ -0,0 +1,68 @@
|
||||
This project was bootstrapped with [Create React App](https://github.com/facebook/create-react-app).
|
||||
|
||||
## Available Scripts
|
||||
|
||||
In the project directory, you can run:
|
||||
|
||||
### `npm start`
|
||||
|
||||
Runs the app in the development mode.<br>
|
||||
Open [http://localhost:3000](http://localhost:3000) to view it in the browser.
|
||||
|
||||
The page will reload if you make edits.<br>
|
||||
You will also see any lint errors in the console.
|
||||
|
||||
### `npm test`
|
||||
|
||||
Launches the test runner in the interactive watch mode.<br>
|
||||
See the section about [running tests](https://facebook.github.io/create-react-app/docs/running-tests) for more information.
|
||||
|
||||
### `npm run build`
|
||||
|
||||
Builds the app for production to the `build` folder.<br>
|
||||
It correctly bundles React in production mode and optimizes the build for the best performance.
|
||||
|
||||
The build is minified and the filenames include the hashes.<br>
|
||||
Your app is ready to be deployed!
|
||||
|
||||
See the section about [deployment](https://facebook.github.io/create-react-app/docs/deployment) for more information.
|
||||
|
||||
### `npm run eject`
|
||||
|
||||
**Note: this is a one-way operation. Once you `eject`, you can’t go back!**
|
||||
|
||||
If you aren’t satisfied with the build tool and configuration choices, you can `eject` at any time. This command will remove the single build dependency from your project.
|
||||
|
||||
Instead, it will copy all the configuration files and the transitive dependencies (Webpack, Babel, ESLint, etc) right into your project so you have full control over them. All of the commands except `eject` will still work, but they will point to the copied scripts so you can tweak them. At this point you’re on your own.
|
||||
|
||||
You don’t have to ever use `eject`. The curated feature set is suitable for small and middle deployments, and you shouldn’t feel obligated to use this feature. However we understand that this tool wouldn’t be useful if you couldn’t customize it when you are ready for it.
|
||||
|
||||
## Learn More
|
||||
|
||||
You can learn more in the [Create React App documentation](https://facebook.github.io/create-react-app/docs/getting-started).
|
||||
|
||||
To learn React, check out the [React documentation](https://reactjs.org/).
|
||||
|
||||
### Code Splitting
|
||||
|
||||
This section has moved here: https://facebook.github.io/create-react-app/docs/code-splitting
|
||||
|
||||
### Analyzing the Bundle Size
|
||||
|
||||
This section has moved here: https://facebook.github.io/create-react-app/docs/analyzing-the-bundle-size
|
||||
|
||||
### Making a Progressive Web App
|
||||
|
||||
This section has moved here: https://facebook.github.io/create-react-app/docs/making-a-progressive-web-app
|
||||
|
||||
### Advanced Configuration
|
||||
|
||||
This section has moved here: https://facebook.github.io/create-react-app/docs/advanced-configuration
|
||||
|
||||
### Deployment
|
||||
|
||||
This section has moved here: https://facebook.github.io/create-react-app/docs/deployment
|
||||
|
||||
### `npm run build` fails to minify
|
||||
|
||||
This section has moved here: https://facebook.github.io/create-react-app/docs/troubleshooting#npm-run-build-fails-to-minify
|
||||
@@ -0,0 +1,29 @@
|
||||
{
|
||||
"name": "{{.NPMProjectName}}",
|
||||
"author": "{{.Author.Name}}<{{.Author.Email}}>",
|
||||
"version": "0.1.0",
|
||||
"private": true,
|
||||
"dependencies": {
|
||||
"react": "^16.8.6",
|
||||
"react-dom": "^16.8.6",
|
||||
"wails-react-scripts": "3.0.1-2",
|
||||
"react-modal": "3.8.1"
|
||||
},
|
||||
"scripts": {
|
||||
"start": "react-scripts start",
|
||||
"build": "react-scripts build",
|
||||
"test": "react-scripts test",
|
||||
"eject": "react-scripts eject"
|
||||
},
|
||||
"eslintConfig": {
|
||||
"extends": "react-app"
|
||||
},
|
||||
"browserslist": {
|
||||
"production": [],
|
||||
"development": [
|
||||
"last 1 chrome version",
|
||||
"last 1 firefox version",
|
||||
"last 1 safari version"
|
||||
]
|
||||
}
|
||||
}
|
||||
BIN
cmd/templates/create-react-app/frontend/public/favicon.ico
Normal file
|
After Width: | Height: | Size: 3.8 KiB |
38
cmd/templates/create-react-app/frontend/public/index.html
Normal file
@@ -0,0 +1,38 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="utf-8" />
|
||||
<link rel="shortcut icon" href="%PUBLIC_URL%/favicon.ico" />
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1" />
|
||||
<meta name="theme-color" content="#000000" />
|
||||
<!--
|
||||
manifest.json provides metadata used when your web app is installed on a
|
||||
user's mobile device or desktop. See https://developers.google.com/web/fundamentals/web-app-manifest/
|
||||
-->
|
||||
<link rel="manifest" href="%PUBLIC_URL%/manifest.json" />
|
||||
<!--
|
||||
Notice the use of %PUBLIC_URL% in the tags above.
|
||||
It will be replaced with the URL of the `public` folder during the build.
|
||||
Only files inside the `public` folder can be referenced from the HTML.
|
||||
|
||||
Unlike "/favicon.ico" or "favicon.ico", "%PUBLIC_URL%/favicon.ico" will
|
||||
work correctly both with client-side routing and a non-root public URL.
|
||||
Learn how to configure a non-root public URL by running `npm run build`.
|
||||
-->
|
||||
<title>React App</title>
|
||||
</head>
|
||||
<body>
|
||||
<noscript>You need to enable JavaScript to run this app.</noscript>
|
||||
<div id="app"></div>
|
||||
<!--
|
||||
This HTML file is a template.
|
||||
If you open it directly in the browser, you will see an empty page.
|
||||
|
||||
You can add webfonts, meta tags, or analytics to this file.
|
||||
The build step will place the bundled scripts into the <body> tag.
|
||||
|
||||
To begin the development, run `npm start` or `yarn start`.
|
||||
To create a production bundle, use `npm run build` or `yarn build`.
|
||||
-->
|
||||
</body>
|
||||
</html>
|
||||
15
cmd/templates/create-react-app/frontend/public/manifest.json
Normal file
@@ -0,0 +1,15 @@
|
||||
{
|
||||
"short_name": "React App",
|
||||
"name": "Create React App Sample",
|
||||
"icons": [
|
||||
{
|
||||
"src": "favicon.ico",
|
||||
"sizes": "64x64 32x32 24x24 16x16",
|
||||
"type": "image/x-icon"
|
||||
}
|
||||
],
|
||||
"start_url": ".",
|
||||
"display": "standalone",
|
||||
"theme_color": "#000000",
|
||||
"background_color": "#ffffff"
|
||||
}
|
||||
33
cmd/templates/create-react-app/frontend/src/App.css
Normal file
@@ -0,0 +1,33 @@
|
||||
.App {
|
||||
text-align: center;
|
||||
}
|
||||
|
||||
.App-logo {
|
||||
animation: App-logo-spin infinite 20s linear;
|
||||
height: 40vmin;
|
||||
pointer-events: none;
|
||||
}
|
||||
|
||||
.App-header {
|
||||
background-color: #282c34;
|
||||
min-height: 100vh;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
font-size: calc(10px + 2vmin);
|
||||
color: white;
|
||||
}
|
||||
|
||||
.App-link {
|
||||
color: #61dafb;
|
||||
}
|
||||
|
||||
@keyframes App-logo-spin {
|
||||
from {
|
||||
transform: rotate(0deg);
|
||||
}
|
||||
to {
|
||||
transform: rotate(360deg);
|
||||
}
|
||||
}
|
||||
21
cmd/templates/create-react-app/frontend/src/App.js
Normal file
@@ -0,0 +1,21 @@
|
||||
import React from 'react';
|
||||
import logo from './logo.png';
|
||||
import './App.css';
|
||||
import HelloWorld from './components/HelloWorld';
|
||||
|
||||
function App() {
|
||||
return (
|
||||
<div id="app" className="App">
|
||||
<header className="App-header">
|
||||
<img src={logo} className="App-logo" alt="logo" />
|
||||
<p>
|
||||
Welcome to your new <code>wails/react</code> project.
|
||||
</p>
|
||||
|
||||
<HelloWorld />
|
||||
</header>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
export default App;
|
||||
9
cmd/templates/create-react-app/frontend/src/App.test.js
Normal file
@@ -0,0 +1,9 @@
|
||||
import React from 'react';
|
||||
import ReactDOM from 'react-dom';
|
||||
import App from './App';
|
||||
|
||||
it('renders without crashing', () => {
|
||||
const div = document.createElement('div');
|
||||
ReactDOM.render(<App />, div);
|
||||
ReactDOM.unmountComponentAtNode(div);
|
||||
});
|
||||
@@ -0,0 +1,62 @@
|
||||
import React from 'react';
|
||||
import Modal from 'react-modal';
|
||||
|
||||
class HelloWorld extends React.Component {
|
||||
constructor(props, context) {
|
||||
super();
|
||||
this.state = {
|
||||
showModal: false
|
||||
};
|
||||
|
||||
this.handleOpenModal = this.handleOpenModal.bind(this);
|
||||
this.handleCloseModal = this.handleCloseModal.bind(this);
|
||||
}
|
||||
|
||||
handleOpenModal () {
|
||||
this.setState({ showModal: true });
|
||||
|
||||
window.backend.basic().then(result =>
|
||||
this.setState({
|
||||
result
|
||||
})
|
||||
);
|
||||
}
|
||||
|
||||
handleCloseModal () {
|
||||
this.setState({ showModal: false });
|
||||
}
|
||||
|
||||
|
||||
startAsync() {
|
||||
this.setState({
|
||||
loading: true
|
||||
});
|
||||
|
||||
window.backend.basic().then(result =>
|
||||
this.setState({
|
||||
loading: false,
|
||||
result
|
||||
})
|
||||
);
|
||||
}
|
||||
|
||||
render() {
|
||||
const { loading, result } = this.state;
|
||||
return (
|
||||
<div className="App">
|
||||
<button onClick={this.handleOpenModal} type="button">
|
||||
Hello
|
||||
</button>
|
||||
<Modal
|
||||
isOpen={this.state.showModal}
|
||||
contentLabel="Minimal Modal Example"
|
||||
>
|
||||
<p>{result}</p>
|
||||
<button onClick={this.handleCloseModal}>Close Modal</button>
|
||||
</Modal>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
export default HelloWorld;
|
||||
13
cmd/templates/create-react-app/frontend/src/index.css
Normal file
@@ -0,0 +1,13 @@
|
||||
body {
|
||||
margin: 0;
|
||||
font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Roboto", "Oxygen",
|
||||
"Ubuntu", "Cantarell", "Fira Sans", "Droid Sans", "Helvetica Neue",
|
||||
sans-serif;
|
||||
-webkit-font-smoothing: antialiased;
|
||||
-moz-osx-font-smoothing: grayscale;
|
||||
}
|
||||
|
||||
code {
|
||||
font-family: source-code-pro, Menlo, Monaco, Consolas, "Courier New",
|
||||
monospace;
|
||||
}
|
||||
10
cmd/templates/create-react-app/frontend/src/index.js
Normal file
@@ -0,0 +1,10 @@
|
||||
import React from 'react';
|
||||
import ReactDOM from 'react-dom';
|
||||
import './index.css';
|
||||
import App from './App';
|
||||
|
||||
import Bridge from "./wailsbridge";
|
||||
|
||||
Bridge.Start(() => {
|
||||
ReactDOM.render(<App />, document.getElementById('app'));
|
||||
});
|
||||
|
Before Width: | Height: | Size: 301 KiB After Width: | Height: | Size: 301 KiB |
135
cmd/templates/create-react-app/frontend/src/serviceWorker.js
Normal file
@@ -0,0 +1,135 @@
|
||||
// This optional code is used to register a service worker.
|
||||
// register() is not called by default.
|
||||
|
||||
// This lets the app load faster on subsequent visits in production, and gives
|
||||
// it offline capabilities. However, it also means that developers (and users)
|
||||
// will only see deployed updates on subsequent visits to a page, after all the
|
||||
// existing tabs open on the page have been closed, since previously cached
|
||||
// resources are updated in the background.
|
||||
|
||||
// To learn more about the benefits of this model and instructions on how to
|
||||
// opt-in, read https://bit.ly/CRA-PWA
|
||||
|
||||
const isLocalhost = Boolean(
|
||||
window.location.hostname === 'localhost' ||
|
||||
// [::1] is the IPv6 localhost address.
|
||||
window.location.hostname === '[::1]' ||
|
||||
// 127.0.0.1/8 is considered localhost for IPv4.
|
||||
window.location.hostname.match(
|
||||
/^127(?:\.(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)){3}$/
|
||||
)
|
||||
);
|
||||
|
||||
export function register(config) {
|
||||
if (process.env.NODE_ENV === 'production' && 'serviceWorker' in navigator) {
|
||||
// The URL constructor is available in all browsers that support SW.
|
||||
const publicUrl = new URL(process.env.PUBLIC_URL, window.location.href);
|
||||
if (publicUrl.origin !== window.location.origin) {
|
||||
// Our service worker won't work if PUBLIC_URL is on a different origin
|
||||
// from what our page is served on. This might happen if a CDN is used to
|
||||
// serve assets; see https://github.com/facebook/create-react-app/issues/2374
|
||||
return;
|
||||
}
|
||||
|
||||
window.addEventListener('load', () => {
|
||||
const swUrl = `${process.env.PUBLIC_URL}/service-worker.js`;
|
||||
|
||||
if (isLocalhost) {
|
||||
// This is running on localhost. Let's check if a service worker still exists or not.
|
||||
checkValidServiceWorker(swUrl, config);
|
||||
|
||||
// Add some additional logging to localhost, pointing developers to the
|
||||
// service worker/PWA documentation.
|
||||
navigator.serviceWorker.ready.then(() => {
|
||||
console.log(
|
||||
'This web app is being served cache-first by a service ' +
|
||||
'worker. To learn more, visit https://bit.ly/CRA-PWA'
|
||||
);
|
||||
});
|
||||
} else {
|
||||
// Is not localhost. Just register service worker
|
||||
registerValidSW(swUrl, config);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
function registerValidSW(swUrl, config) {
|
||||
navigator.serviceWorker
|
||||
.register(swUrl)
|
||||
.then(registration => {
|
||||
registration.onupdatefound = () => {
|
||||
const installingWorker = registration.installing;
|
||||
if (installingWorker == null) {
|
||||
return;
|
||||
}
|
||||
installingWorker.onstatechange = () => {
|
||||
if (installingWorker.state === 'installed') {
|
||||
if (navigator.serviceWorker.controller) {
|
||||
// At this point, the updated precached content has been fetched,
|
||||
// but the previous service worker will still serve the older
|
||||
// content until all client tabs are closed.
|
||||
console.log(
|
||||
'New content is available and will be used when all ' +
|
||||
'tabs for this page are closed. See https://bit.ly/CRA-PWA.'
|
||||
);
|
||||
|
||||
// Execute callback
|
||||
if (config && config.onUpdate) {
|
||||
config.onUpdate(registration);
|
||||
}
|
||||
} else {
|
||||
// At this point, everything has been precached.
|
||||
// It's the perfect time to display a
|
||||
// "Content is cached for offline use." message.
|
||||
console.log('Content is cached for offline use.');
|
||||
|
||||
// Execute callback
|
||||
if (config && config.onSuccess) {
|
||||
config.onSuccess(registration);
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
};
|
||||
})
|
||||
.catch(error => {
|
||||
console.error('Error during service worker registration:', error);
|
||||
});
|
||||
}
|
||||
|
||||
function checkValidServiceWorker(swUrl, config) {
|
||||
// Check if the service worker can be found. If it can't reload the page.
|
||||
fetch(swUrl)
|
||||
.then(response => {
|
||||
// Ensure service worker exists, and that we really are getting a JS file.
|
||||
const contentType = response.headers.get('content-type');
|
||||
if (
|
||||
response.status === 404 ||
|
||||
(contentType != null && contentType.indexOf('javascript') === -1)
|
||||
) {
|
||||
// No service worker found. Probably a different app. Reload the page.
|
||||
navigator.serviceWorker.ready.then(registration => {
|
||||
registration.unregister().then(() => {
|
||||
window.location.reload();
|
||||
});
|
||||
});
|
||||
} else {
|
||||
// Service worker found. Proceed as normal.
|
||||
registerValidSW(swUrl, config);
|
||||
}
|
||||
})
|
||||
.catch(() => {
|
||||
console.log(
|
||||
'No internet connection found. App is running in offline mode.'
|
||||
);
|
||||
});
|
||||
}
|
||||
|
||||
export function unregister() {
|
||||
if ('serviceWorker' in navigator) {
|
||||
navigator.serviceWorker.ready.then(registration => {
|
||||
registration.unregister();
|
||||
});
|
||||
}
|
||||
}
|
||||
17
cmd/templates/create-react-app/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);
|
||||
}
|
||||
}
|
||||
};
|
||||
27
cmd/templates/create-react-app/main.go.template
Normal file
@@ -0,0 +1,27 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"github.com/leaanthony/mewn"
|
||||
"github.com/wailsapp/wails"
|
||||
)
|
||||
|
||||
func basic() string {
|
||||
return "World!"
|
||||
}
|
||||
|
||||
func main() {
|
||||
|
||||
js := mewn.String("./frontend/build/static/js/main.js")
|
||||
css := mewn.String("./frontend/build/static/css/main.css")
|
||||
|
||||
app := wails.CreateApp(&wails.AppConfig{
|
||||
Width: 1024,
|
||||
Height: 768,
|
||||
Title: "{{.Name}}",
|
||||
JS: js,
|
||||
CSS: css,
|
||||
Colour: "#131313",
|
||||
})
|
||||
app.Bind(basic)
|
||||
app.Run()
|
||||
}
|
||||
14
cmd/templates/create-react-app/template.json
Executable file
@@ -0,0 +1,14 @@
|
||||
{
|
||||
"name": "React JS",
|
||||
"version": "1.0.0",
|
||||
"shortdescription": "Create React App v3 template",
|
||||
"description": "Create React App v3 standar tooling",
|
||||
"install": "npm install",
|
||||
"build": "npm run build",
|
||||
"author": "bh90210 <ktc@pm.me>",
|
||||
"created": "2019-06-07 18:23:48.666414555 +0300 EEST m=+223.934866008",
|
||||
"frontenddir": "frontend",
|
||||
"serve": "npm run start",
|
||||
"bridge": "src",
|
||||
"wailsdir": ""
|
||||
}
|
||||
@@ -1,24 +0,0 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
wails "github.com/wailsapp/wails"
|
||||
)
|
||||
|
||||
var html = `
|
||||
<div style='text-align:center'>
|
||||
<h1> Custom </h1>
|
||||
Welcome to your basic Wails app with added CSS!
|
||||
</div>
|
||||
`
|
||||
|
||||
func main() {
|
||||
|
||||
// Initialise the app
|
||||
app := wails.CreateApp(&wails.AppConfig{
|
||||
Width: 800,
|
||||
Height: 600,
|
||||
Title: "{{.Name}}",
|
||||
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/).
|
||||
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 |
BIN
cmd/templates/vuebasic/frontend/src/assets/images/logo.png
Normal file
|
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);
|
||||
}
|
||||
}
|
||||
};
|
||||