Skip to content
This repository has been archived by the owner on Jan 19, 2024. It is now read-only.

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
dzc0d3r committed Nov 21, 2021
1 parent d6ff078 commit 14a6f6d
Show file tree
Hide file tree
Showing 34 changed files with 609 additions and 170 deletions.
45 changes: 23 additions & 22 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,23 +1,24 @@
# See https://help.github.com/articles/ignoring-files/ for more about ignoring files.

# dependencies
/node_modules
/.pnp
.pnp.js

# testing
/coverage

# production
/build

# misc
*.pyc
*.sh
setup.cfg
pywebview.egg-info
MANIFEST
build
dist
.cache
.idea
.vs
bin
obj
node_modules
dist
gui
.DS_Store
.env.local
.env.development.local
.env.test.local
.env.production.local

npm-debug.log*
yarn-debug.log*
yarn-error.log*
venv*
.vscode
.pytest_cache
__pycache__
src/__pycache__
.eggs
yarn-error.log
yarn.lock
29 changes: 29 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
BSD 3-Clause License

Copyright (c) 2020, Roman
All rights reserved.

Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:

1. Redistributions of source code must retain the above copyright notice, this
list of conditions and the following disclaimer.

2. Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.

3. Neither the name of the copyright holder nor the names of its
contributors may be used to endorse or promote products derived from
this software without specific prior written permission.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
72 changes: 46 additions & 26 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,46 +1,66 @@
# Getting Started with Create React App
# pywebview-react-boilerplate
This is a simple boilerplate to help you start with _pywebview_ and React. It sets up the development environment, install dependencies, as well as provides scripts for building an executable. Stack is based on Pywebview, React (create-react-app), SASS, Pyinstaller (Windows/Linux) and Py2app (macOS).

This project was bootstrapped with [Create React App](https://github.com/facebook/create-react-app).
## Requirements
- Python 3
- Node
- virtualenv

## Available Scripts
## Installation

In the project directory, you can run:
``` bash
yarn run init
```

### `yarn start`
This will create a virtual environment, install pip and Node dependencies. Alternatively you can perform these steps manually.

Runs the app in the development mode.\
Open [http://localhost:3000](http://localhost:3000) to view it in the browser.
``` bash
yarn install
pip install -r requirements.txt
```

The page will reload if you make edits.\
You will also see any lint errors in the console.
On Linux systems installation system makes educated guesses. If you run KDE, QT dependencies are installed, otherwise GTK is chosen. `apt` is used for installing GTK dependencies. In case you are running a non apt-based system, you will have to install GTK dependencies manually. See [installation](https://pywebview.flowrl.com/guide/installation.html) for details.

### `yarn test`
## Usage

Launches the test runner in the interactive watch mode.\
See the section about [running tests](https://facebook.github.io/create-react-app/docs/running-tests) for more information.
To launch the application.

### `yarn build`
``` bash
yarn run start
```

Builds the app for production to the `build` folder.\
It correctly bundles React in production mode and optimizes the build for the best performance.
To build an executable. The output binary will be produced in the `dist` directory.

The build is minified and the filenames include the hashes.\
Your app is ready to be deployed!
``` bash
yarn run build
```

See the section about [deployment](https://facebook.github.io/create-react-app/docs/deployment) for more information.
To start a development server (only for testing frontend code).

### `yarn eject`
``` bash
yarn run dev
```

**Note: this is a one-way operation. Once you `eject`, you can’t go back!**
To clean the developement environment, this will delete `gui`, `dist`, `build` directories.

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.
``` bash
yarn run clean
```

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.
To eject create-react-app and tweak the configuration as you may wish.

## Learn More
``` bash
yarn run eject
```

You can learn more in the [Create React App documentation](https://facebook.github.io/create-react-app/docs/getting-started).
To test the frontend code if you have written tests.

To learn React, check out the [React documentation](https://reactjs.org/).
``` bash
yarn run frontend:test
```


## Bug reporting

Please report _pywebview_ related bugs directly to [pywebview's repository](https://github.com/r0x0r/pywebview). This repository is only for the issues related to this boilerplate.
34 changes: 34 additions & 0 deletions build-linux.spec
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
# -*- mode: python -*-

block_cipher = None

added_files = [
('./gui', 'gui'),
]

a = Analysis(['./src/index.py'],
pathex=['./dist'],
binaries=None,
datas=added_files,
hiddenimports=['clr'],
excludes=[],
win_no_prefer_redirects=False,
win_private_assemblies=False,
cipher=block_cipher)
pyz = PYZ(a.pure, a.zipped_data, cipher=block_cipher)
exe = EXE(pyz,
a.scripts,
exclude_binaries=True,
name='pywebview-react-app',
debug=False,
strip=True,
#icon='./src/assets/\logo.ico',
upx=True,
console=False ) # set this to see error output of the executable
coll = COLLECT(exe,
a.binaries,
a.zipfiles,
a.datas,
strip=False,
upx=False,
name='pywebview-react-app')
33 changes: 33 additions & 0 deletions build-macos.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import os
import py2app
import shutil

from distutils.core import setup

def tree(src):
return [(root, map(lambda f: os.path.join(root, f), files))
for (root, dirs, files) in os.walk(os.path.normpath(src))]


if os.path.exists('build'):
shutil.rmtree('build')

if os.path.exists('dist/index.app'):
shutil.rmtree('dist/index.app')

ENTRY_POINT = ['src/index.py']

DATA_FILES = tree('dist')
OPTIONS = {
'argv_emulation': False,
'strip': True,
'iconfile': 'src/assets/logo.icns',
'includes': ['WebKit', 'Foundation', 'webview', 'pkg_resources.py2_warn']
}

setup(
app=ENTRY_POINT,
data_files=DATA_FILES,
options={'py2app': OPTIONS},
setup_requires=['py2app'],
)
34 changes: 34 additions & 0 deletions build-windows.spec
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
# -*- mode: python -*-

block_cipher = None

added_files = [
('.\\gui', 'gui'),
]

a = Analysis(['.\\src\\index.py'],
pathex=['.\\dist'],
binaries=None,
datas=added_files,
hiddenimports=['clr'],
excludes=[],
win_no_prefer_redirects=False,
win_private_assemblies=False,
cipher=block_cipher)
pyz = PYZ(a.pure, a.zipped_data, cipher=block_cipher)
exe = EXE(pyz,
a.scripts,
exclude_binaries=True,
name='pywebview-react-app',
debug=False,
strip=True,
icon='.\\src\\assets\\logo.ico',
upx=True,
console=False ) # set this to see error output of the executable
coll = COLLECT(exe,
a.binaries,
a.zipfiles,
a.datas,
strip=False,
upx=False,
name='pywebview-react-app')
40 changes: 40 additions & 0 deletions index.spec
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
# -*- mode: python ; coding: utf-8 -*-


block_cipher = None


a = Analysis(['src/index.py'],
pathex=[],
binaries=[],
datas=[],
hiddenimports=[],
hookspath=[],
hooksconfig={},
runtime_hooks=[],
excludes=[],
win_no_prefer_redirects=False,
win_private_assemblies=False,
cipher=block_cipher,
noarchive=False)
pyz = PYZ(a.pure, a.zipped_data,
cipher=block_cipher)

exe = EXE(pyz,
a.scripts,
a.binaries,
a.zipfiles,
a.datas,
[],
name='index',
debug=False,
bootloader_ignore_signals=False,
strip=False,
upx=True,
upx_exclude=[],
runtime_tmpdir=None,
console=True,
disable_windowed_traceback=False,
target_arch=None,
codesign_identity=None,
entitlements_file=None )
32 changes: 27 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
"name": "react-pywebview-boilerplate",
"version": "0.1.0",
"private": true,
"homepage": "./",
"dependencies": {
"@testing-library/jest-dom": "^5.11.4",
"@testing-library/react": "^11.1.0",
Expand All @@ -13,14 +14,32 @@
"react": "^17.0.2",
"react-dom": "^17.0.2",
"react-scripts": "4.0.3",
"sass": "^1.43.4",
"typescript": "^4.1.2",
"web-vitals": "^1.0.1"
},
"scripts": {
"start": "react-scripts start",
"build": "react-scripts build",
"test": "react-scripts test",
"eject": "react-scripts eject"
"dev": "react-scripts start",
"frontend:dev": "BUILD_PATH='./gui' react-scripts build",
"frontend:prod": "BUILD_PATH='./gui' react-scripts build",
"frontend:test": "react-scripts test",
"frontend:eject": "react-scripts eject",
"build": "yarn run clean && yarn run frontend:prod && run-script-os",
"build:macos": "./venv-pywebview/bin/python build-macos.py py2app",
"build:windows": ".\\venv-pywebview\\Scripts\\pyinstaller build-windows.spec",
"build:linux": "./venv-pywebview/bin/pyinstaller build-linux.spec --onefile",
"clean": "run-script-os",
"clean:default": "rm -rf gui 2>/dev/null; rm -rf build 2>/dev/null; rm -rf dist 2>/dev/null; ",
"clean:windows": "if exist gui rd /S /Q gui & if exist build rd /S /Q build & if exist dist rd /S /Q dist",
"init": "yarn install && run-script-os",
"init:windows": "virtualenv -p python venv-pywebview && .\\venv-pywebview\\Scripts\\pip install -r requirements.txt",
"init:linux": "virtualenv -p python3 venv-pywebview && if [[ -z \"${KDE_FULL_SESSION}\" ]]; then yarn run init:qt5; else yarn run init:gtk; fi",
"init:default": "virtualenv -p python3 venv-pywebview && ./venv-pywebview/bin/pip install -r requirements.txt",
"init:qt5": "./venv-pywebview/bin/pip install pyqt5 pyqtwebengine -r requirements.txt",
"init:gtk": "sudo apt install libgirepository1.0-dev gcc libcairo2-dev pkg-config python3-dev gir1.2-gtk-3.0 && ./venv-pywebview/bin/pip install pycairo pygobject -r requirements.txt",
"start": "yarn run frontend:dev && run-script-os",
"start:windows": ".\\venv-pywebview\\Scripts\\python src\\index.py",
"start:default": "./venv-pywebview/bin/python src/index.py"
},
"eslintConfig": {
"extends": [
Expand All @@ -39,5 +58,8 @@
"last 1 firefox version",
"last 1 safari version"
]
},
"devDependencies": {
"run-script-os": "^1.1.6"
}
}
}
Loading

0 comments on commit 14a6f6d

Please sign in to comment.