Skip to content

Commit

Permalink
Update template-distillery to match last version of github.com/ocsige…
Browse files Browse the repository at this point in the history
…n/os_template
  • Loading branch information
balat committed Aug 27, 2024
1 parent 81759c8 commit 3cea91a
Show file tree
Hide file tree
Showing 20 changed files with 269 additions and 120 deletions.
4 changes: 2 additions & 2 deletions template.distillery/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ cordova
# Style
.sass-cache

static/css/%%%PROJECT_NAME%%%.css.map
static/css/%%%PROJECT_NAME%%%.css
static/css/project_name.css.map
static/css/project_name.css

# Dune
_build
4 changes: 0 additions & 4 deletions template.distillery/Makefile.options
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,6 @@ USE_NPM := yes
##----------------------------------------------------------------------
## The following part contains the configuration for the ocsigenserver.

# User to run server with (make run.*)
WWWUSER := www-data
WWWGROUP := www-data

# Port for running the server (make run.*)
PORT := 80

Expand Down
27 changes: 20 additions & 7 deletions template.distillery/Makefile.os
Original file line number Diff line number Diff line change
Expand Up @@ -56,12 +56,28 @@ test.opt:: opt | $(addprefix $(TEST_PREFIX),$(DIST_DIRS)) staticfiles
@echo "==== The website is available at http://localhost:$(TEST_PORT) ===="
$(OCSIGENSERVER.OPT) $(RUN_DEBUG) -c $(patsubst %.conf.in,$(TEST_PREFIX)$(ETCDIR)/%-test.conf,$(CONF_IN))

test.static.byte: static.byte | $(addprefix $(TEST_PREFIX),$(DIST_DIRS)) staticfiles
@echo "==== The website is available at http://localhost:$(TEST_PORT) ===="
dune exec ./%%%PROJECT_NAME%%%_main.bc
test.static.opt: static.opt | $(addprefix $(TEST_PREFIX),$(DIST_DIRS)) staticfiles
@echo "==== The website is available at http://localhost:$(TEST_PORT) ===="
dune exec ./%%%PROJECT_NAME%%%_main.exe

$(addprefix $(TEST_PREFIX), $(DIST_DIRS)):
mkdir -p $@

staticfiles:
cp -rf $(LOCAL_STATIC_CSS) $(LOCAL_STATIC_IMAGES) $(LOCAL_STATIC_FONTS) $(TEST_PREFIX)$(ELIOMSTATICDIR)

##----------------------------------------------------------------------
## Static executable

static.byte: byte
dune build %%%PROJECT_NAME%%%_main.bc

static.opt: opt
dune build %%%PROJECT_NAME%%%_main.exe

##----------------------------------------------------------------------
## Installing & Running

Expand Down Expand Up @@ -155,7 +171,7 @@ $(TEST_CONFIG_FILES): $(TEST_PREFIX)$(ETCDIR)/%-test.conf: %.conf.in $(JS_AND_CS
##----------------------------------------------------------------------
## Compilation

.PHONY: gen-dune config-files
.PHONY: config-files

config-files: | $(TEST_PREFIX)$(ELIOMSTATICDIR) $(TEST_PREFIX)$(LIBDIR)
HASH=`md5sum _build/default/client/$(PROJECT_NAME).bc.js | cut -d ' ' -f 1` && \
Expand All @@ -164,20 +180,17 @@ config-files: | $(TEST_PREFIX)$(ELIOMSTATICDIR) $(TEST_PREFIX)$(LIBDIR)
cp -f _build/default/$(PROJECT_NAME).cm* $(TEST_PREFIX)$(LIBDIR)/
$(MAKE) $(CONFIG_FILES) $(TEST_CONFIG_FILES) PROJECT_NAME=$(PROJECT_NAME)

all:: gen-dune
all::
$(ENV_PSQL) dune build $(DUNE_OPTIONS) @install @$(PROJECT_NAME) $(PROJECT_NAME).cmxs

byte:: gen-dune
byte::
$(ENV_PSQL) dune build $(DUNE_OPTIONS) @$(PROJECT_NAME)
make config-files PROJECT_NAME=$(PROJECT_NAME)

opt:: gen-dune
opt::
$(ENV_PSQL) dune build $(DUNE_OPTIONS) $(PROJECT_NAME).cmxs @$(PROJECT_NAME)
make config-files PROJECT_NAME=$(PROJECT_NAME)

gen-dune:
@ocaml tools/gen_dune.ml > client/dune.client

##----------------------------------------------------------------------

##----------------------------------------------------------------------
Expand Down
2 changes: 1 addition & 1 deletion template.distillery/Makefile.style
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ ifeq ($(shell which sassc),)
[ -d $(SASSDIR) ] && \
SASS_PATH=$(SASS_PATH) sass --style compressed $(SASS_SRC) $@
else
[ -d $(SASSDIR) ] && \
[ -d $(SASSDIR) ] &&
sassc -t compressed $(addprefix -I ,$(subst :, ,$(SASS_PATH))) $(SASS_SRC) $@
endif
$(POSTCSS) --use autoprefixer --replace $@
Expand Down
6 changes: 3 additions & 3 deletions template.distillery/PROJECT_NAME.conf.in
Original file line number Diff line number Diff line change
Expand Up @@ -21,18 +21,18 @@
<!-- we use the PostgreSQL backend for ocsipersist,
but there is also a DBM and an SQLite backend -->
<!--
<extension findlib-package="ocsipersist.dbm">
<extension findlib-package="ocsipersist-dbm-config">
<delayloading val="false"/>
<store dir="%%DATADIR%%"/>
<ocsidbm name="ocsidbm"/>
</extension>
-->
<!--
<extension findlib-package="ocsipersist.sqlite">
<extension findlib-package="ocsipersist-sqlite-config">
<database file="%%DATADIR%%/ocsidb"/>
</extension>
-->
<extension findlib-package="ocsipersist.pgsql">
<extension findlib-package="ocsipersist-pgsql-config">
<database
host="%%DB_HOST%%"
port="%%DB_PORT%%"
Expand Down
4 changes: 3 additions & 1 deletion template.distillery/PROJECT_NAME.eliom
Original file line number Diff line number Diff line change
Expand Up @@ -95,8 +95,10 @@ module Demo_timepicker = Demo_timepicker
module Demo_tips = Demo_tips
module Demo_tongue = Demo_tongue
module Demo_users = Demo_users
module %%%MODULE_NAME%%%_config = %%%MODULE_NAME%%%_config

[%%client.start]

module %%%MODULE_NAME%%%_config = %%%MODULE_NAME%%%_config
module %%%MODULE_NAME%%%_language = %%%MODULE_NAME%%%_language
module %%%MODULE_NAME%%%_mobile = %%%MODULE_NAME%%%_mobile
module %%%MODULE_NAME%%%_phone_connect = %%%MODULE_NAME%%%_phone_connect
6 changes: 3 additions & 3 deletions template.distillery/PROJECT_NAME.opam
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ version: "0.1"
synopsis: "Pseudo package for defining project dependencies"

depends: [
"eliom" {>= "10.0.0" & < "11.0.0"}
"ocsipersist-pgsql" {>= "1.0" & < "2.0"}
"ocsigen-start"
"eliom" {>= "11.0.0" & < "12.0.0"}
"ocsipersist-pgsql-config" {>= "2.0" & < "3.0"}
"ocsigen-start" {>= "7.0.0" & < "8.0.0"}
]
1 change: 1 addition & 0 deletions template.distillery/PROJECT_NAME_base.eliom
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
(* This file was generated by Ocsigen Start.
Feel free to use it, modify it, and redistribute it as you wish. *)

let%server () = %%%MODULE_NAME%%%_static_config.set_static_config ()
let%server application_name = !%%%MODULE_NAME%%%_config.app_name
let%client application_name = Eliom_client.get_application_name ()
let%shared displayed_app_name = "%%%PROJECT_NAME%%%"
Expand Down
4 changes: 3 additions & 1 deletion template.distillery/PROJECT_NAME_config.eliom
Original file line number Diff line number Diff line change
Expand Up @@ -70,4 +70,6 @@ let os_db =
in
element ~name:"os-db" ~attributes ()

let _ = Eliom_config.parse_config [app; avatars; os_db]
let _ =
if Ocsigen_config.has_configuration_file ()
then Eliom_config.parse_config [app; avatars; os_db]
9 changes: 9 additions & 0 deletions template.distillery/PROJECT_NAME_main.eliom
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
(** This is the main file if you are using static linking without config file.
It is not used if you are using a config file and ocsigenserver *)

module%shared %%%MODULE_NAME%%% = %%%MODULE_NAME%%%

let%server _ =
Ocsigen_server.start
[ Ocsigen_server.host
[Staticmod.run ~dir:"local/var/www/%%%PROJECT_NAME%%%" (); Eliom.run ()] ]
6 changes: 0 additions & 6 deletions template.distillery/PROJECT_NAME_mobile.eliom
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,6 @@

[%%client.start]

[@@@ocaml.warning "-33"]

open %%%MODULE_NAME%%% (* for dependency reasons *)

[@@@ocaml.warning "+33"]

[%%client open Js_of_ocaml]
[%%client open Js_of_ocaml_lwt]

Expand Down
31 changes: 31 additions & 0 deletions template.distillery/PROJECT_NAME_static_config.eliom.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
(* Set static configuration in case you are using static linking only.
These information are taken from the config file otherwise.
*)
let%server set_static_config () =
if not (Ocsigen_config.has_configuration_file ())
then begin
Ocsigen_config.set_ports [`All, 8080];
Ocsigen_config.set_veryverbose ();
Ocsigen_config.set_debugmode true;
Ocsigen_config.set_logdir "local/var/log/%%%PROJECT_NAME%%%";
Ocsigen_config.set_datadir "local/var/data/%%%PROJECT_NAME%%%";
Ocsigen_config.set_uploaddir (Some "/tmp");
Ocsigen_config.set_usedefaulthostname true;
Ocsigen_config.set_command_pipe "local/var/run/%%%PROJECT_NAME%%%-cmd";
Ocsigen_config.set_default_charset (Some "utf-8");
Ocsipersist_settings.set_host "%%PGHOST%%";
Ocsipersist_settings.set_port %%PGPORT%%;
Ocsipersist_settings.set_database "ocsipersist_%%%PROJECT_NAME%%%";
Ocsipersist.init ();
%%%MODULE_NAME%%%_config.os_db_database := Some "%%PGDATABASE%%";
%%%MODULE_NAME%%%_config.os_db_host := Some "%%PGHOST%%";
%%%MODULE_NAME%%%_config.os_db_user :=
(let u = "%%PGUSER%%" in if u = "" then None else Some u);
%%%MODULE_NAME%%%_config.os_db_password := Some "%%PGPASSWORD%%";
%%%MODULE_NAME%%%_config.os_db_port := Some %%PGPORT%%;
%%%MODULE_NAME%%%_config.app_name :=
Filename.chop_suffix
(Unix.readlink "local/var/www/%%%PROJECT_NAME%%%/%%%PROJECT_NAME%%%.js") ".js" ;
%%%MODULE_NAME%%%_config.css_name :=
Unix.readlink "local/var/www/%%%PROJECT_NAME%%%/css/%%%PROJECT_NAME%%%.css";
end
26 changes: 20 additions & 6 deletions template.distillery/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,22 @@ you can try updating it with `sudo npm install -g npm`. Depending on your
setup, you may have to update your `$PATH` for the new `npm` to become
visible.

Generally, you can compile it and run ocsigenserver on it by

First create a local database:
```shell
make db-init
make db-create
make db-schema
```
Then compile and run the app, either as a library loaded dynamically
into ocsigenserver using a configuration file:
```shell
make test.byte (or test.opt)
```
or as an OCaml executable, using ocsigenserver as a libary
(without configuration file):
```shell
make test.static.byte (or test.static.opt)
```

Then connect to `http://localhost:8080` to see the running app skeleton.
Registration will work only if sendmail if configured on your system.
Expand Down Expand Up @@ -95,27 +103,33 @@ make db-status
```

- Test your application by compiling it and running ocsigenserver locally
with a configuration file:
```
make test.byte (or test.opt)
```

- Test your application by compiling it as an OCaml executable without
configuration file:
```
make test.static.byte (or test.static.opt)
```

- Compile it only
```Shell
make all (or byte or opt)
```

- Deploy your project on your system
- DEPRECATED Deploy your project on your system
```Shell
sudo make install (or install.byte or install.opt)
```

- Run the server on the deployed project
- DEPRECATED Run the server on the deployed project
```Shell
sudo make run.byte (or run.opt)
```

If `WWWUSER` in the `Makefile.options` is you, you don't need the
`sudo`. If Eliom isn't installed globally, however, you need to
If Eliom isn't installed globally, however, you need to
re-export some environment variables to make this work:
```Shell
sudo PATH=$PATH OCAMLPATH=$OCAMLPATH LD_LIBRARY_PATH=$LD_LIBRARY_PATH make run.byte/run.opt
Expand Down
18 changes: 0 additions & 18 deletions template.distillery/client!dune

This file was deleted.

Loading

0 comments on commit 3cea91a

Please sign in to comment.