Publish Progress #1
1
.gitignore
vendored
1
.gitignore
vendored
@ -25,3 +25,4 @@ yarn-error.log*
|
||||
# my additions
|
||||
logs
|
||||
dist
|
||||
db
|
||||
|
2048
package-lock.json
generated
2048
package-lock.json
generated
File diff suppressed because it is too large
Load Diff
15
package.json
15
package.json
@ -13,13 +13,14 @@
|
||||
},
|
||||
"homepage": "https://github.com/Hyperling/food_diary#readme",
|
||||
"dependencies": {
|
||||
"@types/node": "^18.14.6",
|
||||
"@types/react": "^18.0.28",
|
||||
"@types/react-dom": "^18.0.11",
|
||||
"package.json": "^2.0.1",
|
||||
"typescript": "",
|
||||
"react": "",
|
||||
"react-dom": ""
|
||||
"react": "^18.2.0",
|
||||
"react-dom": "^18.2.0",
|
||||
"sqlite3": "^5.1.4",
|
||||
"typescript": "^4.9.5"
|
||||
},
|
||||
"removedDependencies": {
|
||||
"@types/react": "",
|
||||
"@types/react-dom": ""
|
||||
}
|
||||
"removedDependencies": {}
|
||||
}
|
||||
|
49
run.sh
49
run.sh
@ -11,21 +11,17 @@ if [[ $DIR == "." ]]; then
|
||||
fi
|
||||
|
||||
## Install any system packages. ##
|
||||
if [[ -z `which npm` ]]; then
|
||||
echo "NPM needs to be installed."
|
||||
sudo apt install npm
|
||||
else
|
||||
echo "NPM is already available."
|
||||
fi
|
||||
|
||||
if [[ -z `which tsc` ]]; then
|
||||
echo "TSC needs to be installed."
|
||||
sudo apt install node-typescript
|
||||
if [[ -z `which npm` || -z `which tsc` || -z `which sqlite` ]]; then
|
||||
echo "A dependency is missing, going through install process."
|
||||
sudo apt install npm node-typescript sqlite
|
||||
else
|
||||
echo "TSC is already available."
|
||||
echo "All packages are available."
|
||||
fi
|
||||
|
||||
## Install/update any project modules. ##
|
||||
|
||||
# Ensure it is safe to be running an npm nstall.
|
||||
if [[ `pwd` != $DIR && -e package.json ]]; then
|
||||
cat <<- EOF
|
||||
WARNING: It seems you are currently in a different JS project which already
|
||||
@ -40,21 +36,32 @@ if [[ `pwd` != $DIR && -e package.json ]]; then
|
||||
exit 1
|
||||
fi
|
||||
fi
|
||||
|
||||
# Use package.json in project directory to evaluate if any modules need added.
|
||||
echo "Refreshing NPM packages."
|
||||
bash -c "rm -r $DIR/node_modules $DIR/package-lock.json"
|
||||
npm install $DIR
|
||||
|
||||
## Main ##
|
||||
|
||||
# Fork somehow other than just doing &? Then...
|
||||
# Start backend in a forked process
|
||||
echo "Starting back-end in a child process and sleeping for 5 seconds."
|
||||
mkdir -p $DIR/db
|
||||
node $DIR/dist/server.js "$DIR" >>$DIR/logs/server.log 2>&1 &
|
||||
sleep 5
|
||||
|
||||
if [[ $parent ]]; then
|
||||
# Start backend
|
||||
node $DIR/server.js >$DIR/logs/server.log 2>&1 &
|
||||
else
|
||||
# Start frontend.
|
||||
tsc --project $DIR
|
||||
# ??? $DIR/dist/index.js >$DIR/logs/ui.log 2>&1
|
||||
fi
|
||||
# Start frontend.
|
||||
touch $DIR/dist &&
|
||||
sh -c "rm -rv $DIR/dist" &&
|
||||
tsc --project $DIR &&
|
||||
ls -l $DIR/dist &&
|
||||
# ??? $DIR/dist/index.js >$DIR/logs/ui.log 2>&1
|
||||
echo "Started front-end successfully!" ||
|
||||
echo "Failed to start front-end."
|
||||
echo "Front-end service has stopped."
|
||||
|
||||
# Or just run them each with & and then kill with another shell script? stop.sh
|
||||
## Finish ##
|
||||
|
||||
# If we've reached this point then the front-end has been terminated and the
|
||||
# back-end needs to be stopped as well. use the helper script to do it
|
||||
echo "Finishing the back-end as well."
|
||||
$DIR/stop.sh
|
||||
|
@ -6,17 +6,12 @@
|
||||
|
||||
import "objects.ts";
|
||||
|
||||
// Connect to a SQLite database.
|
||||
function connect_db () {
|
||||
|
||||
}
|
||||
|
||||
// Retrieve data from a connected database.
|
||||
function select_db () {
|
||||
|
||||
null;
|
||||
}
|
||||
|
||||
// Send data to a connected database.
|
||||
function post_db () {
|
||||
|
||||
null;
|
||||
}
|
||||
|
@ -8,8 +8,6 @@
|
||||
*/
|
||||
|
||||
// Attach all the needed helpers.
|
||||
import "src/includes.ts";
|
||||
import "includes.ts";
|
||||
|
||||
/* Main, UI */
|
||||
|
||||
|
||||
|
@ -7,7 +7,8 @@
|
||||
interface record {
|
||||
user_id: number;
|
||||
cal_date: string;
|
||||
meal: string; // Only wants options: Breakfast, Lunch, Dinner, Snack.
|
||||
food: string;
|
||||
caused_issue: boolean;
|
||||
comments: string;
|
||||
}
|
||||
}
|
||||
|
@ -5,11 +5,55 @@
|
||||
*/
|
||||
"use strict";
|
||||
|
||||
/* DB Setup */
|
||||
/* Usage */
|
||||
|
||||
function usage (exit_code) {
|
||||
console.log(
|
||||
process.argv[1] + " is used to expose the SQLite backend to React.\n" +
|
||||
" It accepts the following parameters: \n" +
|
||||
" -h or --help: Display this usage text.\n" +
|
||||
" /path/to/project: Where the project lives and the db + scripts exist."
|
||||
);
|
||||
process.exit(exit_code);
|
||||
}
|
||||
|
||||
/* Test Code */
|
||||
// Just playing with the DB until learning React.
|
||||
/* Arguments */
|
||||
|
||||
let DIR = "";
|
||||
if (process.argv.length == 2 || process.argv.length >= 4 || process.argv[2] == undefined) {
|
||||
console.log('Expected one argument!');
|
||||
usage(1);
|
||||
} else if (process.argv[2] === "-h" || process.argv[2] === "--help") {
|
||||
usage(0);
|
||||
} else {
|
||||
DIR = process.argv[2];
|
||||
console.log("Successfully got DIR: ", DIR);
|
||||
}
|
||||
|
||||
/* Setup */
|
||||
|
||||
const sqlite3 = require('sqlite3').verbose();
|
||||
|
||||
async function finish () {
|
||||
await db.close();
|
||||
}
|
||||
|
||||
/* Main Program */
|
||||
|
||||
async function main() {
|
||||
console.log("Connecting to DB "+DIR+"/db/main");
|
||||
let db = await new sqlite3.Database(DIR+"/db/main");
|
||||
console.log(db);
|
||||
await db.run(`
|
||||
CREATE TABLE journal(
|
||||
user_id INTEGER NOT NULL,
|
||||
cal_date TEXT NOT NULL,
|
||||
meal TEXT NOT NULL,
|
||||
food TEXT NOT NULL,
|
||||
caused_issue INTEGER NOT NULL,
|
||||
comments TEXT
|
||||
) STRICT
|
||||
`);
|
||||
}
|
||||
|
||||
main();
|
||||
|
31
stop.sh
31
stop.sh
@ -10,10 +10,31 @@ if [[ $DIR == "." ]]; then
|
||||
echo $DIR/$PROG
|
||||
fi
|
||||
|
||||
## Stop all services. ##
|
||||
## Stop Frontend Services ##
|
||||
# Kill the frontend if it's still rnning for some reason.
|
||||
# ???
|
||||
|
||||
# Kill frontend.
|
||||
# killall $DIR//index.tsx >$DIR/logs/stop.log 2>&1
|
||||
## Stop Backend Services ##
|
||||
|
||||
# Kill backend
|
||||
killall $DIR/server.js >$DIR/logs/stop.log 2>&1
|
||||
# Let backend know it's time to close then loop over status until it stops.
|
||||
echo "Stopping the backend service."
|
||||
# curl POST localhost:8080/stop
|
||||
count=1
|
||||
still_up="Y"
|
||||
while [[ $still_up == "Y" ]]; do
|
||||
echo "Check #$count"
|
||||
if (( $count >= 20 )); then
|
||||
# Force kill backend if we have gone through 20 rounds.
|
||||
killall $DIR/dist/server.js
|
||||
fi
|
||||
|
||||
# curl GET localhost:8080/check_status
|
||||
status=$?
|
||||
|
||||
if [[ $status != 0 ]]; then
|
||||
still_up="N"
|
||||
fi
|
||||
|
||||
count=$(( count + 1 ))
|
||||
sleep 1
|
||||
done
|
||||
|
@ -1,6 +1,6 @@
|
||||
{
|
||||
"compilerOptions": {
|
||||
"outDir": "./dist/",
|
||||
"outDir": "dist/",
|
||||
"noImplicitAny": true,
|
||||
"module": "es6",
|
||||
"target": "es5",
|
||||
@ -8,4 +8,4 @@
|
||||
"allowJs": true,
|
||||
"moduleResolution": "node",
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user