Skip to content

Commit

Permalink
add portable build
Browse files Browse the repository at this point in the history
  • Loading branch information
ndunks committed Oct 17, 2019
1 parent 6e92cad commit 3c09158
Show file tree
Hide file tree
Showing 12 changed files with 7,012 additions and 2,361 deletions.
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
/dist
/.trash
/node_modules
/portable/node/
/portable/data/
/portable/dist/
/portable/os/*/bin/
/portable/node_modules
4,477 changes: 4,477 additions & 0 deletions package-lock.json

Large diffs are not rendered by default.

10 changes: 5 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,13 @@
"scripts": {
"build": "yarn --cwd server build && yarn --cwd client build",
"postbuild": "mkdir dist; cp -rv server/dist dist/server; cp -rv client/dist dist/client; cp client/package.json dist/client/; cp server/package.json dist/server/; cp -uv package.json dist/",
"dockerize": "docker build -t qcdesa -f Dockerfile ."
"dockerize": "docker build -t qcdesa -f Dockerfile .",
"portable": "yarn -W --cwd portable && portable/pack.sh",
"clean": "rm -rf dist server/dist client/dist portable/dist",
"postinstall": "yarn -W --cwd portable"
},
"workspaces": [
"server",
"client"
],
"dependencies": {
"@vue/cli-plugin-typescript": "^3.9.0"
}
]
}
106 changes: 106 additions & 0 deletions portable/js/qcdesa.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@

process.argv.reduce((param, current) => {
if (param.length) {
process.argv[param] = current;
current = '';
} else if (current[0] == '-') {
current = current.replace(/^-+/, '');
process.argv[current] = true;
}
return current;
}, '');

if (process.argv.help) {
console.log(`Penggunaan:
${process.argv.self || 'qcdesa'} [--listen 80] [--passcode ADMIN_PASSWORD]
--listen Port untuk diakses client via browser, default 80
--passcode Password admin, default admin
Contoh:
${process.argv.self || 'qcdesa'} --listen 80 --passcode rahasia
`)
process.exit();
}

const path = require('path');
const fs = require('fs');
if (path.basename(__dirname) === 'js') {
process.chdir(path.resolve(__dirname, '..'));
} else {
process.chdir(__dirname);
}

let SERVER_DIR, CLIENT_DIR;

if (fs.existsSync('server')) {
// Guest from dist folder
SERVER_DIR = path.join(__dirname, '../server');
CLIENT_DIR = path.join(__dirname, '../client');
} else {
SERVER_DIR = path.resolve(__dirname, '../../dist/server');
CLIENT_DIR = path.resolve(__dirname, '../../dist/client');
}
const SERVER_JS = `${SERVER_DIR}/index.js`;

if (!fs.existsSync(SERVER_DIR) || !fs.existsSync(CLIENT_DIR)) {
console.error('Tidak dapat menemukan direktori aplikasi JS qcdesa');
process.exit(1);
}

console.log('Menjalankan Server..');
const caller = require('vm').runInThisContext(require('module').wrap(fs.readFileSync(SERVER_JS)));
try {
caller(exports, require, module, SERVER_JS, SERVER_DIR);
console.log('Server OK')
} catch (error) {
console.error('Server ERROR: ', error);
}
console.log('Menjalankan Client..');
const http = require('http'),
static = require('node-static'),
httpProxy = require('http-proxy'),
listen = process.argv.listen || 80;

const clientRoot = new static.Server(CLIENT_DIR);
const apiRoot = new static.Server(path.join(process.cwd(), 'data/public'), {

});
console.log("Public path", path.join(process.cwd(), 'data/public'));

const apiProxy = httpProxy.createProxyServer({ target: 'http://127.0.0.1:8888' })

/** @type {http.RequestListener} */
const requestHandler = (request, response) => {
const urls = request.url.split('/').slice(1);
console.log(urls);
if (urls[0] == 'public') {
request.url = request.url.replace(/^\/public/,'');
apiRoot.serve(request, response);
} else if (urls[0] == 'api') {
if (urls[1] == 'public') {
request.url = request.url.replace(/^\/api\/public/,'');
apiRoot.serve(request, response);
} else {
apiProxy.web(request, response);
}
} else {
request.addListener('end', function () {
clientRoot.serve(request, response, (e, res) => {
if (e && (e.status === 404)) { // Fallback index.html
clientRoot.serveFile('/index.html', 200, {}, request, response);
}
});
}).resume();
}
}

const server = http.createServer(requestHandler)
server.listen(listen, (err) => {
if (err) {
console.error(err);
process.exit();
}
console.log(`Buka browser pada http://localhost${listen == 80 ? '' : ':' + listen}/`);
})
16 changes: 16 additions & 0 deletions portable/os/linux-x64/qcdesa.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#!/bin/bash
cd "$( dirname "${BASH_SOURCE[0]}" )" &> /dev/null

NODE=node
if [ -e ./bin/node ]; then
NODE="$PWD/bin/node"
fi

if ! "$NODE" -v &>/dev/null; then
echo "NodeJS not found, please install it."
read -n 1
exit 1
fi

# Overwrite passcode by passing arguments, (the last is used) ./qcdesa.sh --passcode 1234
exec "$NODE" ./js/qcdesa.js --self "$0" --passcode admin --listen 8080 "$@"
16 changes: 16 additions & 0 deletions portable/os/win-x64/qcdesa.cmd
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
@echo off
cd "%~dp0"
set NODE=node
if exist "bin\node.exe" (
set NODE="bin\node.exe"
)

"%NODE%" -v

IF NOT ERRORLEVEL 0 (
echo "NodeJS not found, please install it."
exit
)

rem Overwrite passcode by passing arguments, (the last is used) ./qcdesa.cmd --passcode 1234
"%NODE%" js\qcdesa.js --self "%~dpnx0" --passcode admin
1 change: 1 addition & 0 deletions portable/os/win-x86/qcdesa.cmd
42 changes: 42 additions & 0 deletions portable/pack.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
#!/bin/bash
# Portable packer
cd "$( dirname "${BASH_SOURCE[0]}" )" &> /dev/null
VER=$(grep '"version"' ../package.json | cut -d '"' -f4)
NAME="qcdesa-$VER"

# All OS without NODE
OS_ALL="$PWD/dist/$NAME.zip"

[ -d dist ] || mkdir dist
rm -rf dist/*

if [ ! -d ../dist ]; then
yarn --cwd "../" build
fi

zip -ur9 "$OS_ALL" "js" "node_modules" "package.json"
pushd ../dist
zip -Dr9 "$OS_ALL" *
popd

# OS depend
for OS in os/*/; do
if [ ! -e "$OS/bin/node"* ]; then
echo "NodeJS binary not found in $OS"
exit 1
fi
OS_ZIP="$PWD/dist/$NAME-$( basename $OS).zip"
cp "$OS_ALL" "$OS_ZIP";
pushd $OS
zip -ur9 "$OS_ZIP" *
echo $OS;
popd
done

# All OS Script
pushd os/linux-x64/
zip -9 "$OS_ALL" qcdesa.sh
popd && pushd os/win-x64/
zip -9 "$OS_ALL" qcdesa.cmd
popd

10 changes: 10 additions & 0 deletions portable/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"name": "qcdesa-portable",
"version": "1.0.0",
"main": "index.js",
"license": "MIT",
"dependencies": {
"http-proxy": "^1.18.0",
"node-static": "^0.7.11"
}
}
1 change: 1 addition & 0 deletions portable/qcdesa.sh
78 changes: 78 additions & 0 deletions portable/yarn.lock
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
# THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY.
# yarn lockfile v1


colors@>=0.6.0:
version "1.4.0"
resolved "https://registry.yarnpkg.com/colors/-/colors-1.4.0.tgz#c50491479d4c1bdaed2c9ced32cf7c7dc2360f78"
integrity sha512-a+UqTh4kgZg/SlGvfbzDHpgRu7AAQOmmqRHJnxhRZICKFUT91brVhNNt58CMWU9PsBbv3PDCZUHbVxuDiH2mtA==

debug@^3.0.0:
version "3.2.6"
resolved "https://registry.yarnpkg.com/debug/-/debug-3.2.6.tgz#e83d17de16d8a7efb7717edbe5fb10135eee629b"
integrity sha512-mel+jf7nrtEl5Pn1Qx46zARXKDpBbvzezse7p7LqINmdoIk8PYP5SySaxEmYv6TZ0JyEKA1hsCId6DIhgITtWQ==
dependencies:
ms "^2.1.1"

eventemitter3@^4.0.0:
version "4.0.0"
resolved "https://registry.yarnpkg.com/eventemitter3/-/eventemitter3-4.0.0.tgz#d65176163887ee59f386d64c82610b696a4a74eb"
integrity sha512-qerSRB0p+UDEssxTtm6EDKcE7W4OaoisfIMl4CngyEhjpYglocpNg6UEqCvemdGhosAsg4sO2dXJOdyBifPGCg==

follow-redirects@^1.0.0:
version "1.9.0"
resolved "https://registry.yarnpkg.com/follow-redirects/-/follow-redirects-1.9.0.tgz#8d5bcdc65b7108fe1508649c79c12d732dcedb4f"
integrity sha512-CRcPzsSIbXyVDl0QI01muNDu69S8trU4jArW9LpOt2WtC6LyUJetcIrmfHsRBx7/Jb6GHJUiuqyYxPooFfNt6A==
dependencies:
debug "^3.0.0"

http-proxy@^1.18.0:
version "1.18.0"
resolved "https://registry.yarnpkg.com/http-proxy/-/http-proxy-1.18.0.tgz#dbe55f63e75a347db7f3d99974f2692a314a6a3a"
integrity sha512-84I2iJM/n1d4Hdgc6y2+qY5mDaz2PUVjlg9znE9byl+q0uC3DeByqBGReQu5tpLK0TAqTIXScRUV+dg7+bUPpQ==
dependencies:
eventemitter3 "^4.0.0"
follow-redirects "^1.0.0"
requires-port "^1.0.0"

mime@^1.2.9:
version "1.6.0"
resolved "https://registry.yarnpkg.com/mime/-/mime-1.6.0.tgz#32cd9e5c64553bd58d19a568af452acff04981b1"
integrity sha512-x0Vn8spI+wuJ1O6S7gnbaQg8Pxh4NNHb7KSINmEWKiPE4RKOplvijn+NkmYmmRgP68mc70j2EbeTFRsrswaQeg==

minimist@~0.0.1:
version "0.0.10"
resolved "https://registry.yarnpkg.com/minimist/-/minimist-0.0.10.tgz#de3f98543dbf96082be48ad1a0c7cda836301dcf"
integrity sha1-3j+YVD2/lggr5IrRoMfNqDYwHc8=

ms@^2.1.1:
version "2.1.2"
resolved "https://registry.yarnpkg.com/ms/-/ms-2.1.2.tgz#d09d1f357b443f493382a8eb3ccd183872ae6009"
integrity sha512-sGkPx+VjMtmA6MX27oA4FBFELFCZZ4S4XqeGOXCv68tT+jb3vk/RyaKWP0PTKyWtmLSM0b+adUTEvbs1PEaH2w==

node-static@^0.7.11:
version "0.7.11"
resolved "https://registry.yarnpkg.com/node-static/-/node-static-0.7.11.tgz#60120d349f3cef533e4e820670057eb631882e7f"
integrity sha512-zfWC/gICcqb74D9ndyvxZWaI1jzcoHmf4UTHWQchBNuNMxdBLJMDiUgZ1tjGLEIe/BMhj2DxKD8HOuc2062pDQ==
dependencies:
colors ">=0.6.0"
mime "^1.2.9"
optimist ">=0.3.4"

optimist@>=0.3.4:
version "0.6.1"
resolved "https://registry.yarnpkg.com/optimist/-/optimist-0.6.1.tgz#da3ea74686fa21a19a111c326e90eb15a0196686"
integrity sha1-2j6nRob6IaGaERwybpDrFaAZZoY=
dependencies:
minimist "~0.0.1"
wordwrap "~0.0.2"

requires-port@^1.0.0:
version "1.0.0"
resolved "https://registry.yarnpkg.com/requires-port/-/requires-port-1.0.0.tgz#925d2601d39ac485e091cf0da5c6e694dc3dcaff"
integrity sha1-kl0mAdOaxIXgkc8NpcbmlNw9yv8=

wordwrap@~0.0.2:
version "0.0.3"
resolved "https://registry.yarnpkg.com/wordwrap/-/wordwrap-0.0.3.tgz#a3d5da6cd5c0bc0008d37234bbaf1bed63059107"
integrity sha1-o9XabNXAvAAI03I0u68b7WMFkQc=
Loading

0 comments on commit 3c09158

Please sign in to comment.