Skip to content

Commit

Permalink
Bootstrap application
Browse files Browse the repository at this point in the history
  • Loading branch information
Mauko Quiroga committed Sep 1, 2017
1 parent a085bd0 commit 837a048
Show file tree
Hide file tree
Showing 38 changed files with 858 additions and 0 deletions.
16 changes: 16 additions & 0 deletions assets/elm-package.json
@@ -0,0 +1,16 @@
{
"version": "0.0.1",
"summary": "Rendre disponible, valoriser et améliorer les données transports",
"license": "AGPL-3.0",
"repository": "https://github.com/etalab/transport-site.git",
"source-directories": [
"."
],
"exposed-modules": [],
"dependencies": {
"elm-lang/core": "5.1.1 <= v < 6.0.0",
"elm-lang/html": "2.0.0 <= v < 3.0.0",
"elm-lang/http": "1.0.0 <= v < 2.0.0"
},
"elm-version": "0.18.0 <= v < 0.19.0"
}
15 changes: 15 additions & 0 deletions assets/javascripts/Transport.elm
@@ -0,0 +1,15 @@
module Transport exposing (..)

import Html exposing (..)

-- MAIN

main : Html String
main =
view

-- VIEW

view : Html String
view =
h1 [] [ text "transport.beta.gouv.fr" ]
2 changes: 2 additions & 0 deletions assets/javascripts/app.js
@@ -0,0 +1,2 @@
const Elm = require('./Transport');
Elm.Transport.embed(document.getElementById('elm-main'));
23 changes: 23 additions & 0 deletions assets/package.json
@@ -0,0 +1,23 @@
{
"scripts": {
"watch": "webpack --stdin --progress --color",
"build": "webpack",
"deploy": "webpack -p",
"errors": "webpack --display-error-details"
},
"dependencies": {
"normalize.css": "^7.0.0"
},
"devDependencies": {
"babel-core": "^7.0.0-alpha.12",
"babel-loader": "^7.0.0",
"babel-preset-es2017": "^7.0.0-alpha.12",
"css-loader": "^0.28.4",
"elm-webpack-loader": "^4.3.1",
"extract-text-webpack-plugin": "^2.1.2",
"import-glob-loader": "^1.1.0",
"node-sass": "^4.5.3",
"sass-loader": "^6.0.5",
"webpack": "^2.5.1"
}
}
24 changes: 24 additions & 0 deletions assets/stylesheets/app.scss
@@ -0,0 +1,24 @@
@import '~normalize.css';

$black: hsl(0, 0%, 10%);

html,
body {
height: 100%;
}

body {
font-family: 'Hurme-No3', sans-serif;
}

main {
align-items: center;
display: flex;
height: 100%;
justify-content: center;
}

h1 {
color: $black;
font-size: calc(4vw + 1em);
}
65 changes: 65 additions & 0 deletions assets/webpack.config.js
@@ -0,0 +1,65 @@
const { resolve } = require('path');
const ExtractTextPlugin = require('extract-text-webpack-plugin');
const extractSass = new ExtractTextPlugin({ filename: '../css/app.css', allChunks: true });

module.exports = {
entry: ['./javascripts/app.js', './stylesheets/app.scss'],
output: {
path: resolve('../priv/static/js'),
filename: 'app.js'
},
resolve: {
modules: [
resolve('./javascripts'),
resolve('./stylesheets'),
resolve('elm-stuff'),
resolve('node_modules')
],
extensions: ['.elm', '.js', '.scss']
},
plugins: [extractSass],
devtool: 'source-map',
module: {
noParse: /\.elm$/,
rules: [{
test: /\.elm$/,
exclude: [/elm-stuff/, /node_modules/],
use: {
loader: 'elm-webpack-loader',
options: {
cwd: __dirname,
debug: false,
warn: true
}
}
}, {
test: /\.js$/,
exclude: [/elm-stuff/, /node_modules/],
use: {
loader: 'babel-loader',
options: {
presets: ['es2017']
}
}
}, {
test: /\.scss$/,
use: extractSass.extract({
use: [{
loader: 'css-loader',
options: {
sourceMap: true
}
}, {
loader: 'sass-loader',
options: {
sourceMap: true
}
}]
})
}, {
test: /\.(js|scss)$/,
enforce: 'pre',
loader: 'import-glob-loader'
}]
}
};
23 changes: 23 additions & 0 deletions config/config.exs
@@ -0,0 +1,23 @@
# This file is responsible for configuring your application
# and its dependencies with the aid of the Mix.Config module.
#
# This configuration file is loaded before any dependency and
# is restricted to this project.
use Mix.Config

# Configures the endpoint
config :transport, TransportWeb.Endpoint,
url: [host: "127.0.0.1"],
secret_key_base: (System.get_env("SECRET_KEY_BASE") || "asdf1234"),
render_errors: [view: TransportWeb.ErrorView, accepts: ~w(html json)],
pubsub: [name: Transport.PubSub,
adapter: Phoenix.PubSub.PG2]

# Configures Elixir's Logger
config :logger, :console,
format: "$time $metadata[$level] $message\n",
metadata: [:request_id]

# Import environment specific config. This must remain at the bottom
# of this file so it overrides the configuration defined above.
import_config "#{Mix.env}.exs"
49 changes: 49 additions & 0 deletions config/dev.exs
@@ -0,0 +1,49 @@
use Mix.Config

# For development, we disable any cache and enable
# debugging and code reloading.
#
# The watchers configuration can be used to run external
# watchers to your application. For example, we use it
# with brunch.io to recompile .js and .css sources.
config :transport, TransportWeb.Endpoint,
http: [port: 5000],
debug_errors: true,
code_reloader: true,
check_origin: false,
watchers: ["npm": ["run", "--prefix", "assets", "watch"]]

# ## SSL Support
#
# In order to use HTTPS in development, a self-signed
# certificate can be generated by running the following
# command from your terminal:
#
# openssl req -new -newkey rsa:4096 -days 365 -nodes -x509 -subj "/C=US/ST=Denial/L=Springfield/O=Dis/CN=www.example.com" -keyout priv/server.key -out priv/server.pem
#
# The `http:` config above can be replaced with:
#
# https: [port: 4000, keyfile: "priv/server.key", certfile: "priv/server.pem"],
#
# If desired, both `http:` and `https:` keys can be
# configured to run both http and https servers on
# different ports.

# Watch static and templates for browser reloading.
config :transport, TransportWeb.Endpoint,
live_reload: [
url: "ws://127.0.0.1:5000",
patterns: [
~r{priv/static/.*(js|css|png|jpeg|jpg|gif|svg)$},
~r{priv/gettext/.*(po)$},
~r{lib/transport_web/views/.*(ex)$},
~r{lib/transport_web/templates/.*(eex)$}
]
]

# Do not include metadata nor timestamps in development logs
config :logger, :console, format: "[$level] $message\n"

# Set a higher stacktrace during development. Avoid configuring such
# in production as building large stacktraces may be expensive.
config :phoenix, :stacktrace_depth, 20
65 changes: 65 additions & 0 deletions config/prod.exs
@@ -0,0 +1,65 @@
use Mix.Config

# For production, we often load configuration from external
# sources, such as your system environment. For this reason,
# you won't find the :http configuration below, but set inside
# TransportWeb.Endpoint.init/2 when load_from_system_env is
# true. Any dynamic configuration should be done there.
#
# Don't forget to configure the url host to something meaningful,
# Phoenix uses this information when generating URLs.
#
# Finally, we also include the path to a cache manifest
# containing the digested version of static files. This
# manifest is generated by the mix phx.digest task
# which you typically run after static files are built.
config :transport, TransportWeb.Endpoint,
http: [port: {:system, "PORT"}],
url: [scheme: "https", host: "transport.beta.gouv.fr", port: 443],
cache_static_manifest: "priv/static/cache_manifest.json",
secret_key_base: System.get_env("SECRET_KEY_BASE")

# Do not print debug messages in production
config :logger, level: :info

# ## SSL Support
#
# To get SSL working, you will need to add the `https` key
# to the previous section and set your `:url` port to 443:
#
# config :transport, TransportWeb.Endpoint,
# ...
# url: [host: "example.com", port: 443],
# https: [:inet6,
# port: 443,
# keyfile: System.get_env("SOME_APP_SSL_KEY_PATH"),
# certfile: System.get_env("SOME_APP_SSL_CERT_PATH")]
#
# Where those two env variables return an absolute path to
# the key and cert in disk or a relative path inside priv,
# for example "priv/ssl/server.key".
#
# We also recommend setting `force_ssl`, ensuring no data is
# ever sent via http, always redirecting to https:
#
# config :transport, TransportWeb.Endpoint,
# force_ssl: [hsts: true]
#
# Check `Plug.SSL` for all available options in `force_ssl`.

# ## Using releases
#
# If you are doing OTP releases, you need to instruct Phoenix
# to start the server for all endpoints:
#
# config :phoenix, :serve_endpoints, true
#
# Alternatively, you can configure exactly which server to
# start per endpoint:
#
# config :transport, TransportWeb.Endpoint, server: true
#

# Finally import the config/prod.secret.exs
# which should be versioned separately.
import_config "prod.secret.exs"
10 changes: 10 additions & 0 deletions config/test.exs
@@ -0,0 +1,10 @@
use Mix.Config

# We don't run a server during test. If one is required,
# you can enable the server option below.
config :transport, TransportWeb.Endpoint,
http: [port: 5001],
server: false

# Print only warnings and errors during test
config :logger, level: :warn
16 changes: 16 additions & 0 deletions lib/mix/tasks/elm.ex
@@ -0,0 +1,16 @@
defmodule Mix.Tasks.Elm do
@moduledoc """
Executes elm scripts from assets directory.
"""

use Mix.Task

@elm_path "./node_modules/elm/binwrappers/elm-package"

def run([cmd | _tail]) do
case Mix.shell.cmd("cd ./assets && #{@elm_path} #{cmd}", stderr_to_stdout: true) do
0 -> :ok
a -> raise "elm command failure exit code: #{a}"
end
end
end
14 changes: 14 additions & 0 deletions lib/mix/tasks/npm.ex
@@ -0,0 +1,14 @@
defmodule Mix.Tasks.Npm do
@moduledoc """
Executes npm scripts from assets directory.
"""

use Mix.Task

def run([cmd | _tail]) do
case Mix.shell.cmd("cd ./assets && npm #{cmd}", stderr_to_stdout: true) do
0 -> :ok
a -> raise "npm command failure exit code: #{a}"
end
end
end
9 changes: 9 additions & 0 deletions lib/transport.ex
@@ -0,0 +1,9 @@
defmodule Transport do
@moduledoc """
Transport keeps the contexts that define your domain
and business logic.
Contexts are also responsible for managing your data, regardless
if it comes from the database, an external API or others.
"""
end
29 changes: 29 additions & 0 deletions lib/transport/application.ex
@@ -0,0 +1,29 @@
defmodule Transport.Application do
use Application

# See https://hexdocs.pm/elixir/Application.html
# for more information on OTP Applications
def start(_type, _args) do
import Supervisor.Spec

# Define workers and child supervisors to be supervised
children = [
# Start the endpoint when the application starts
supervisor(TransportWeb.Endpoint, []),
# Start your own worker by calling: Transport.Worker.start_link(arg1, arg2, arg3)
# worker(Transport.Worker, [arg1, arg2, arg3]),
]

# See https://hexdocs.pm/elixir/Supervisor.html
# for other strategies and supported options
opts = [strategy: :one_for_one, name: Transport.Supervisor]
Supervisor.start_link(children, opts)
end

# Tell Phoenix to update the endpoint configuration
# whenever the application is updated.
def config_change(changed, _new, removed) do
TransportWeb.Endpoint.config_change(changed, removed)
:ok
end
end

0 comments on commit 837a048

Please sign in to comment.