Skip to content

Commit

Permalink
Merge pull request #20 from sbash64/bunning
Browse files Browse the repository at this point in the history
Bunning
  • Loading branch information
sbash64 authored May 18, 2024
2 parents 0d625bb + 8d09169 commit 864b976
Show file tree
Hide file tree
Showing 11 changed files with 140 additions and 166 deletions.
72 changes: 11 additions & 61 deletions .github/workflows/create-release.yml
Original file line number Diff line number Diff line change
@@ -1,76 +1,26 @@
on:
push:
tags:
- v[0-9]+.[0-9]+.[0-9]+
- "[0-9]+.[0-9]+.[0-9]+"

jobs:
build-linux-x86_64:
name: build for linux x86_64
release:
name: build for linux x86_64 and release
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
- uses: oven-sh/setup-bun@v1
- name: generate buildsystem
env:
CXX: g++-10
CXX: g++
run: cmake -S . -B build -DSBASH64_BUDGET_ENABLE_WEB=1 -DCMAKE_BUILD_TYPE=Release
- name: build app
- name: build backend
run: cmake --build build --config Release --target sbash64-budget-web
- name: webpack
run: |
npm install
npx webpack
- name: build frontend
run: bun build web/main.ts --outdir dist
- name: zip files
run: zip -j sbash64-budget-web-linux-x86_64.zip build/web/sbash64-budget-web dist/index.html dist/main.js
- name: upload release asset
uses: actions/upload-artifact@v3
with:
name: release-assets
path: sbash64-budget-web-linux-x86_64.zip
build-raspberry-pi-zero:
name: build for raspberry pi zero
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: download cross compiler
run: |
wget https://sourceforge.net/projects/raspberry-pi-cross-compilers/files/Raspberry%20Pi%20GCC%20Cross-Compiler%20Toolchains/Bullseye/GCC%2010.3.0/Raspberry%20Pi%201%2C%20Zero/cross-gcc-10.3.0-pi_0-1.tar.gz/download
tar xzf download
- name: generate buildsystem
env:
CXX: cross-pi-gcc-10.3.0-0/bin/arm-linux-gnueabihf-g++
CC: cross-pi-gcc-10.3.0-0/bin/arm-linux-gnueabihf-gcc
run: cmake -S . -B build -DSBASH64_BUDGET_ENABLE_WEB=1 -DCMAKE_BUILD_TYPE=Release
- name: build app
run: cmake --build build --config Release --target sbash64-budget-web
- name: webpack
run: |
npm install
npx webpack
- name: zip files
run: zip -j sbash64-budget-web-linux-armv6.zip build/web/sbash64-budget-web dist/index.html dist/main.js
- name: upload release asset
uses: actions/upload-artifact@v3
with:
name: release-assets
path: sbash64-budget-web-linux-armv6.zip
create-release:
name: create github release
needs: [build-linux-x86_64, build-raspberry-pi-zero]
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3

# https://github.saobby.my.eu.orgmunity/t/how-to-get-just-the-tag-name/16241/7
- name: Get the version
id: get_version
run: echo ::set-output name=VERSION::${GITHUB_REF/refs\/tags\//}

- name: download release assets
uses: actions/download-artifact@v3
with:
name: release-assets
run: zip -j sbash64-budget-web-linux-x86_64.zip build/web/sbash64-budget-web web/index.html web/styles.css dist/main.js LICENSE NOTICE.txt
- name: create GitHub release
run: |
gh release create ${{ steps.get_version.outputs.VERSION }} -n "" -t ${{ steps.get_version.outputs.VERSION }} *.zip
run: gh release create "${{ github.ref_name }}" *.zip
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
4 changes: 2 additions & 2 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,13 @@ jobs:
matrix:
include:
- os: ubuntu-latest
cpp-compiler: g++-10
cpp-compiler: g++
- os: macOS-latest
cpp-compiler: clang++
- os: windows-latest
cpp-compiler: cl
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v4
- name: generate buildsystem
env:
CXX: ${{ matrix.cpp-compiler }}
Expand Down
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ if(${SBASH64_BUDGET_ENABLE_WEB})
FetchContent_MakeAvailable(asio)
FetchContent_Declare(
nlohmann_json
URL https://github.com/nlohmann/json/releases/download/v3.11.2/json.tar.xz
URL https://github.com/nlohmann/json/releases/download/v3.11.3/json.tar.xz
)
FetchContent_MakeAvailable(nlohmann_json)

Expand Down
101 changes: 101 additions & 0 deletions NOTICE.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
This project uses the following third-party software.

JSON (https://github.com/nlohmann/json.git)
License Text:
Copyright (c) 2013-2022 Niels Lohmann

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

GSL (https://github.com/microsoft/GSL.git)
License Text:
Copyright (c) 2015 Microsoft Corporation. All rights reserved.

This code is licensed under the MIT License (MIT).

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
of the Software, and to permit persons to whom the Software is furnished to do
so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.

websocketpp (https://github.com/zaphoyd/websocketpp.git)
License Text:
Copyright (c) 2014, Peter Thorson. All rights reserved.

Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
* Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
* 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.
* Neither the name of the WebSocket++ Project 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 PETER THORSON 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.

asio (https://github.com/chriskohlhoff/asio.git)
License Text:
Copyright (c) 2003-2024 Christopher M. Kohlhoff (chris at kohlhoff dot com)

Boost Software License - Version 1.0 - August 17th, 2003

Permission is hereby granted, free of charge, to any person or organization
obtaining a copy of the software and accompanying documentation covered by
this license (the "Software") to use, reproduce, display, distribute,
execute, and transmit the Software, and to prepare derivative works of the
Software, and to permit third-parties to whom the Software is furnished to
do so, all subject to the following:

The copyright notices in the Software and this entire statement, including
the above license grant, this restriction and the following disclaimer,
must be included in all copies of the Software, in whole or in part, and
all derivative works of the Software, unless such copies or derivative
works are solely in the form of machine-executable object code generated by
a source language processor.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
DEALINGS IN THE SOFTWARE.
1 change: 1 addition & 0 deletions lib/presentation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,7 @@ void BudgetPresenter::notifyThatHasUnsavedChanges() {
void BudgetPresenter::add(View *view) {
view->updateNetIncome(format(netIncome));
view->addNewAccountTable(incomeAccountName, 0);
incomeAccountPresenter.catchUp(view);
gsl::index i{0};
for (const auto &account : orderedChildren) {
view->addNewAccountTable(account->name(), ++i);
Expand Down
11 changes: 0 additions & 11 deletions package.json

This file was deleted.

14 changes: 0 additions & 14 deletions tsconfig.json

This file was deleted.

5 changes: 3 additions & 2 deletions web/index.html
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
<!DOCTYPE html>
<!doctype html>
<html>
<head>
<meta charset="utf-8" />
<title>Bashford Budget</title>
<script src="main.js"></script>
<link rel="stylesheet" href="styles.css" />
<script async src="main.js"></script>
</head>
<body></body>
</html>
71 changes: 20 additions & 51 deletions web/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
#include <ostream>
#include <sstream>
#include <string>
#include <string_view>
#include <utility>

namespace sbash64::budget {
Expand Down Expand Up @@ -180,44 +181,6 @@ static auto backupDirectory(const std::filesystem::path &parentPath,
return parentPath / backupDirectory.str();
}

namespace {
struct App {
ObservableTransactionInMemory::Factory transactionFactory;
AccountInMemory incomeAccount{transactionFactory};
AccountInMemory::Factory accountFactory{transactionFactory};
BudgetInMemory budget{incomeAccount, accountFactory};
FileStreamFactory streamFactory;
WritesTransactionToStream::Factory transactionRecordSerializationFactory;
WritesAccountToStream::Factory accountSerializationFactory{
transactionRecordSerializationFactory};
WritesBudgetToStream sessionSerialization{streamFactory,
accountSerializationFactory};
ReadsTransactionFromStream::Factory transactionRecordDeserializationFactory;
ReadsAccountFromStream::Factory accountDeserializationFactory{
transactionRecordDeserializationFactory};
ReadsBudgetFromStream budgetDeserialization{streamFactory,
accountDeserializationFactory};
BrowserView browserView;
BudgetPresenter presenter;
std::filesystem::path backupDirectory;
std::string budgetFilePath;
std::uintmax_t backupCount = 0;

App(websocketpp::server<websocketpp::config::asio> &server,
websocketpp::connection_hdl connection, const std::string &budgetFilePath,
const std::filesystem::path &backupParentPath)
: streamFactory{budgetFilePath},
browserView{server, std::move(connection)}, presenter{incomeAccount},
backupDirectory{budget::backupDirectory(
backupParentPath, std::chrono::system_clock::now())},
budgetFilePath{budgetFilePath} {
budget.attach(&presenter);
budget.load(budgetDeserialization);
std::filesystem::create_directory(backupDirectory);
}
};
} // namespace

static auto date(std::string_view s) -> Date {
Date date{};
std::stringstream stream{std::string{s}};
Expand Down Expand Up @@ -313,6 +276,19 @@ handleMessage(Budget &budget, std::uintmax_t &backupCount,
}
} // namespace sbash64::budget

static void setBody(
const std::string &filePath,
const std::shared_ptr<websocketpp::connection<websocketpp::config::asio>>
&con,
const std::string &contentType = {}) {
std::ifstream response{filePath};
std::ostringstream stream;
stream << response.rdbuf();
con->set_body(stream.str());
if (!contentType.empty())
con->append_header("Content-Type", contentType);
}

int main(int argc, char *argv[]) {
if (argc < 4) {
return EXIT_FAILURE;
Expand Down Expand Up @@ -387,19 +363,12 @@ int main(int argc, char *argv[]) {
});
server.set_http_handler([&server](websocketpp::connection_hdl connection) {
const auto con = server.get_con_from_hdl(std::move(connection));
if (con->get_resource() == "/") {
std::ifstream response{"index.html"};
std::ostringstream stream;
stream << response.rdbuf();
con->set_body(stream.str());
}
if (con->get_resource() == "/main.js") {
std::ifstream response{"main.js"};
std::ostringstream stream;
stream << response.rdbuf();
con->set_body(stream.str());
con->append_header("Content-Type", "text/javascript");
}
if (con->get_resource() == "/" || con->get_resource() == "/index.html")
setBody("index.html", con);
else if (con->get_resource() == "/main.js")
setBody("main.js", con, "text/javascript");
else if (con->get_resource() == "/styles.css")
setBody("styles.css", con, "text/css");
con->set_status(websocketpp::http::status_code::ok);
});
server.listen(port);
Expand Down
6 changes: 1 addition & 5 deletions web/main.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import "./styles.css";
main();

function adoptChild(parent: HTMLElement, child: HTMLElement) {
parent.append(child);
Expand Down Expand Up @@ -536,7 +536,3 @@ function main() {
}
});
}

document.addEventListener("DOMContentLoaded", () => {
main();
});
19 changes: 0 additions & 19 deletions webpack.config.js

This file was deleted.

0 comments on commit 864b976

Please sign in to comment.