Skip to content
This repository has been archived by the owner on Oct 22, 2021. It is now read-only.

Commit

Permalink
Merge pull request #18 from strukturart/package_script
Browse files Browse the repository at this point in the history
add a build and a package script
  • Loading branch information
strukturart authored Sep 8, 2020
2 parents a299ebe + d975d95 commit 1cae80f
Show file tree
Hide file tree
Showing 10 changed files with 212 additions and 47 deletions.
28 changes: 28 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
name: Build and upload artifact
on: push

jobs:
build:
name: Build

runs-on: ubuntu-latest

steps:
- name: Checkout
uses: actions/checkout@v2

- name: Set Node.js 12.x
uses: actions/setup-node@v1
with:
node-version: 12.x

- name: npm install
run: npm install

- name: build
run: npm run package

- uses: actions/upload-artifact@v2
with:
name: App
path: build/bhacker-store.zip
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
build
tmp
node_modules
11 changes: 11 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,3 +39,14 @@ offline version

## Donation
<a href="https://www.buymeacoffee.com/vj6Q8lR" target="_blank"><img src="https://cdn.buymeacoffee.com/buttons/lato-orange.png" alt="Buy Me A Coffee" style="height: 25px !important;width: 108px !important;" ></a>


### Packaging

This only works on linux(and maybe osx) at the moment
```sh
npm i
npm run package
```

The resulting package can be found in the build folder.
99 changes: 52 additions & 47 deletions application/assets/js/install.js
Original file line number Diff line number Diff line change
@@ -1,67 +1,72 @@
var path;


var sdcard = navigator.getDeviceStorage('sdcard');

sdcard.addEventListener("change", function(event) {

var reason = event.reason;
path = event.path;
install(path)

});

function install(param) {
const { install, installPkg } = (_ => {
var path, sdcard;
var initialized = false;

try {
var sdcard = navigator.getDeviceStorage("sdcard");
sdcard.addEventListener("change", function(event) {
// var reason = event.reason;
path = event.path;
install(path);
});
var initialized = true;
} catch (error) {
console.error("initialisation of sdcard failed:", error);
}

function install(param) {
if (!initialized) throw new Error("install module is not initialized yet");

var request = sdcard.get(param);

request.onsuccess = function() {
var file = this.result;
installPkg(file)
}
var file = this.result;
installPkg(file);
};

request.onerror = function() {
alert("Unable to get the file: " + this.error);
}
}

alert("Unable to get the file: " + this.error);
};
}

function installPkg(packageFile) {
navigator.mozApps.mgmt.import(packageFile).then(function() {
function installPkg(packageFile) {
if (!initialized) throw new Error("install module is not initialized yet");
navigator.mozApps.mgmt
.import(packageFile)
.then(function() {
download_counter();
toaster("<br><br><br><br>THANK YOU<br> for installing the app.<br><br> If you like it I would be happy about a donation, press the option button.<br><br><br><br><br><br>", 6000);

}).catch(e => {
alert('Installation error: ' + e.name + ' ' + e.message)
})
let appGetter = navigator.mozApps.mgmt.getAll()
toaster(
"<br><br><br><br>THANK YOU<br> for installing the app.<br><br> If you like it I would be happy about a donation, press the option button.<br><br><br><br><br><br>",
6000
);
})
.catch(e => {
alert("Installation error: " + e.name + " " + e.message);
});
let appGetter = navigator.mozApps.mgmt.getAll();
appGetter.onsuccess = function() {
let apps = appGetter.result


}
appGetter.onerror = function(e) {}
}
let apps = appGetter.result;
};
appGetter.onerror = function(e) {};
}

function download_counter() {
const url = "https://bhackers.uber.space/srs/v1/download_counter/count/" + app_slug
function download_counter() {
const url =
"https://bhackers.uber.space/srs/v1/download_counter/count/" + app_slug;
let xhttp = new XMLHttpRequest({ mozSystem: true });

xhttp.open('GET', url, true)
xhttp.open("GET", url, true);
xhttp.withCredentials = true;
xhttp.timeout = 2000;

xhttp.responseType = 'json';
xhttp.responseType = "json";

xhttp.send(null);

xhttp.onload = function() {

if (xhttp.readyState === xhttp.DONE && xhttp.status === 200) {

let data = xhttp.response;

}
if (xhttp.readyState === xhttp.DONE && xhttp.status === 200) {
let data = xhttp.response;
}
};

}
}
})();
1 change: 1 addition & 0 deletions application/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@
<script src="assets/js/install.js"></script>
<script src="assets/js/search.js"></script>
<script src="app.js"></script>
<script src="bundle.min.js"></script>


</body>
Expand Down
Binary file removed build/bhacker-store.zip
Binary file not shown.
53 changes: 53 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

24 changes: 24 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
{
"name": "bhackers-store",
"version": "1.0.0",
"description": "An client for https://gitlab.com/banana-hackers/store-db",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"package": "./tools/build.sh && ./tools/package.sh"
},
"repository": {
"type": "git",
"url": "git+https://github.com/strukturart/kaiOs-alt-app-store.git"
},
"author": "strukturart <https://github.com/strukturart>",
"license": "MIT",
"bugs": {
"url": "https://github.com/strukturart/kaiOs-alt-app-store/issues"
},
"devDependencies": {
"prettier": "2.1.1",
"terser": "^5.3.0"
},
"homepage": "https://github.com/strukturart/kaiOs-alt-app-store#readme"
}
21 changes: 21 additions & 0 deletions tools/build.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#!/bin/bash
set -e #fail on error
mkdir -p ./build/app
rm -rf ./build/app/* || true

# copy folders
mkdir -p ./build/app/assets
cp -r ./application/assets/css ./build/app/assets/css
cp -r ./application/icons ./build/app/icons
# copy metadata file
cp ./application/manifest.webapp ./build/app/manifest.webapp

# minify js
# documentation under https://terser.org/docs/cli-usage
npx terser ./application/assets/js/*.js ./application/app.js \
-o ./build/app/bundle.min.js \
--source-map "url='bundle.min.js.map',root='application/',includeSources=true"\
--ecma 5

# copy index file
cp ./application/index.html ./build/app/index.html
19 changes: 19 additions & 0 deletions tools/package.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#!/bin/bash
set -e #fail on error

mkdir -p ./build/tmp

rm ./build/tmp/application.zip || true
rm ./build/bhacker-store.zip || true

echo "{\"version\": 1,\"manifestURL\":\"app://bHacker-Store.org/manifest.webapp\"}" > ./build/tmp/metadata.json

cd build/tmp

zip -jqr application.zip ../app

cd ..

zip -jqr bhacker-store.zip tmp

echo "Created bhacker-store.zip"

0 comments on commit 1cae80f

Please sign in to comment.