Skip to content

Commit

Permalink
Utilitie scripts for development restructured
Browse files Browse the repository at this point in the history
  • Loading branch information
yohasebe committed Aug 15, 2024
1 parent 8428ec3 commit 70b141e
Show file tree
Hide file tree
Showing 5 changed files with 60 additions and 25 deletions.
6 changes: 5 additions & 1 deletion bin/monadic_dev
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,14 @@ elif [ "$1" == "stop" ]; then
elif [ "$1" == "restart" ]; then
./bin/monadic_dev restart --daemonize
echo "Monadic script executed with 'restart' argument 🔄"
elif [ "$1" == "export" ]; then
./bin/monadic_dev export
elif [ "$1" == "import" ]; then
./bin/monadic_dev import
elif [ "$1" == "status" ]; then
./bin/monadic_dev status
else
echo "Usage: monadic_dev [start|stop|restart|debug]"
echo "Usage: monadic_dev [start|stop|restart|debug|status|export|import]"
./bin/monadic_dev status
fi

4 changes: 0 additions & 4 deletions docker/services/ruby/bin/export_db

This file was deleted.

4 changes: 0 additions & 4 deletions docker/services/ruby/bin/import_db

This file was deleted.

67 changes: 53 additions & 14 deletions docker/services/ruby/bin/monadic_dev
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
# frozen_string_literal: false

require "optimist"

require_relative "../lib/monadic/version"

# change current directory to the parent directory of the directory containing this file
Expand All @@ -13,6 +12,9 @@ DEFAULT_PORT = 4567

PID_FILE = __dir__ + "/thin.pid"

# Set the data directory $HOME/monadic/data
DATA_DIR = File.expand_path(File.join(ENV["HOME"], "monadic", "data"))

selenium_image = "selenium/standalone-chrome:latest"
if `uname -s`.chomp.include? "Darwin"
if `uname -m`.chomp == "arm64"
Expand All @@ -26,7 +28,7 @@ ENV["HOST_OS"] = `uname -s`.chomp
# Parse command line options
opts = Optimist.options do
version Monadic::VERSION.to_s
banner "Usage: monadic [start|stop|restart] [options]"
banner "Usage: monadic [start|stop|restart|export|input] [options]"
opt :daemonize, "Enable or disable daemon mode", default: false
opt :log, "Enable or disable logging mode", default: false
opt :port, "Specify the port number", type: :integer, default: DEFAULT_PORT
Expand Down Expand Up @@ -107,6 +109,49 @@ def restart_server(opts)
start_server(opts)
end

def print_status
if File.exist?(PID_FILE)
pid = File.read(PID_FILE).to_i
begin
Process.kill 0, pid
puts "Server is running"
rescue StandardError
puts "Server is not running"
end
else
puts "Server is not running"
end
end

def export_document_db
command = <<~SHELL
pg_dump monadic | gzip > "#{DATA_DIR}/monadic.gz"
SHELL

# run command and get the result with error reporting
res = system(command)

if res
puts "Document DB exported to 'monadic.gz'"
else
puts "Failed to export document DB"
end
end

def import_document_db
command = <<~SHELL
dropdb monadic && createdb --locale=C --template=template0 monadic && gunzip -c "#{DATA_DIR}/monadic.gz" | psql monadic
SHELL

res = system(command)

if res
puts "Document DB imported from 'monadic.gz'"
else
puts "Failed to import document DB"
end
end

# Parse subcommand
subcommand = ARGV.shift

Expand All @@ -118,18 +163,12 @@ when "stop"
stop_server
when "restart"
restart_server(opts)
when "export"
export_document_db
when "import"
import_document_db
when "status"
if File.exist?(PID_FILE)
pid = File.read(PID_FILE).to_i
begin
Process.kill 0, pid
puts "Server is running"
rescue StandardError
puts "Server is not running"
end
else
puts "Server is not running"
end
print_status
else
Optimist.die "Unknown subcommand. Use \"start\", \"stop\", or \"restart\"."
Optimist.die "Unknown subcommand. Use \"start\", \"stop\", \"restart\", \"export\", \"import\", or \"status\""
end
4 changes: 2 additions & 2 deletions docker/services/ruby/lib/monadic.rb
Original file line number Diff line number Diff line change
Expand Up @@ -121,17 +121,17 @@ def init_apps
if app.settings[:mathjax]
initial_prompt_suffix << <<~INITIAL
Use double dollar signs `$$` to enclose MathJax/LaTeX expressions that should be displayed as a separate block; Use single dollar signs `$` before and after the expressions that should appear inline with the text. Without these, the expressions will not render correctly.
Use double dollar signs `$$` to enclose MathJax/LaTeX expressions that should be displayed as a separate block; Use single dollar signs `$` before and after the expressions that should appear inline with the text. Without these, the expressions will not render correctly.
Good example:
`$[1 + 2 + 3 + … + k + (k + 1) = \frac{k(k + 1)}{2} + (k + 1)]$` for inline expressions
`$$[1 + 2 + 3 + … + k + (k + 1) = \frac{k(k + 1)}{2} + (k + 1)]$$` for separate block expressions
`$\begin{align} 1 + 2 + … + k + (k+1) &= \frac{k(k+1)}{2} + (k+1)\end{align}$`
`$$\begin{align} 1 + 2 + … + k + (k+1) &= \frac{k(k+1)}{2} + (k+1)\end{align}$$`
INITIAL

prompt_suffix << <<~SUFFIX
IT'S EXTREMELY IMPORTANT TO USE THE CORRECT MATHJAX/LATEX SYNTAX. IF YOU DON'T USE THE CORRECT SYNTAX, THE EQUATIONS WILL NOT RENDER CORRECTLY.
SUFFIX
end

Expand Down

0 comments on commit 70b141e

Please sign in to comment.