Commit ec805e50 authored by Mikko Ahlroth's avatar Mikko Ahlroth

Some progress, build now works but watch is broken

parent b864d453
{
"presets": ["es2015", "es2016"]
}
......@@ -22,6 +22,7 @@ erl_crash.dump
# we ignore priv/static. You may want to comment
# this depending on your deployment strategy.
/priv/static/
.tmp/
# The config/prod.secret.exs file by default contains sensitive
# data and you should not commit it into version control.
......
......@@ -62,13 +62,9 @@ config :code_stats,
# Configures Elixir's Logger
config :logger, :console,
format: "$time $metadata[$level] $message\n",
format: "$time $metadata[$level] $message",
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"
# Configure phoenix generators
config :phoenix, :generators,
migration: true,
......@@ -83,3 +79,7 @@ config :number,
delimiter: ",",
separator: "."
]
# 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"
......@@ -26,7 +26,7 @@ config :code_stats, CodeStats.Endpoint,
]
# Do not include metadata nor timestamps in development logs
config :logger, :console, format: "[$level] $message\n"
config :logger, :console, format: "[$level] $message"
# Set a higher stacktrace during development.
# Do not configure such in production as keeping
......
defmodule Mix.Tasks.Frontend.Build.Assets do
use Mix.Task
import CodeStats.{FrontendConfs}
@shortdoc "Copy other assets to target dir"
def run(_) do
File.cp_r!("#{src_path()}/assets", "#{dist_path()}")
end
end
defmodule Mix.Tasks.Frontend.Build.Bundle do
use Mix.Task
import CodeStats.{TaskUtils, FrontendConfs}
@shortdoc "Bundle the JavaScript sources into app.js"
def run(_) do
run_task("frontend.build.transpile")
out_path = "#{dist_path()}/js"
# Browserify won't create output directory automatically
File.mkdir_p!(out_path)
exec(
node_bin("browserify"),
[
"--outfile",
"#{out_path}/app.js",
"--entry",
"#{tmp_path()}/transpiled/js/app.js"
]
) |> listen()
end
end
......@@ -5,9 +5,12 @@ defmodule Mix.Tasks.Frontend.Build do
@shortdoc "Build the frontend"
def run(_) do
run_task("frontend.clean")
run_tasks([
"frontend.build.riot",
"frontend.build.scss"
"frontend.build.bundle",
"frontend.build.scss",
"frontend.build.assets"
])
end
end
defmodule Mix.Tasks.Frontend.Build.Js.Copy do
use Mix.Task
import CodeStats.{FrontendConfs}
@shortdoc "Copy JavaScript files to babel source dir"
def run(_) do
out_path = "#{tmp_path()}/compiled/js"
File.mkdir_p!(out_path)
File.cp_r!("#{src_path()}/js", out_path)
end
end
defmodule Mix.Tasks.Frontend.Build.Minify do
use Mix.Task
import CodeStats.TaskUtils
import CodeStats.{TaskUtils, FrontendConfs}
@shortdoc "Minify built JS files"
def run(_) do
outdir = "priv/static/js"
outdir = "#{dist_path()}/js"
exec(
node_path("/.bin/uglifyjs"),
node_bin("uglifyjs"),
[
"--source-map",
"#{outdir}/app.min.js.map",
......@@ -20,7 +20,7 @@ defmodule Mix.Tasks.Frontend.Build.Minify do
"#{outdir}/app.min.js",
"--"
] ++ Path.wildcard(
"priv/static/riot/*.js"
"#{dist_path()}/riot/*.js"
)
) |> listen()
end
......
defmodule Mix.Tasks.Frontend.Build.Riot do
use Mix.Task
import CodeStats.TaskUtils
import CodeStats.{TaskUtils, FrontendConfs}
@shortdoc "Build the RiotJS sources"
def riot_paths(), do: [
"web/static/riot",
"priv/static/riot"
"#{src_path()}/riot",
"#{tmp_path()}/compiled/js/riot"
]
def run(_) do
exec(node_path("/.bin/riot"), riot_paths()) |> listen()
exec(node_bin("riot"), riot_paths()) |> listen()
end
end
defmodule Mix.Tasks.Frontend.Build.Scss do
use Mix.Task
import CodeStats.TaskUtils
import CodeStats.{TaskUtils, FrontendConfs}
@shortdoc "Build the SCSS sources"
def sass_args() do
[
"-o",
"priv/static/css",
"#{dist_path()}/css",
"--source-map",
"true",
"--include-path",
"node_modules/bootstrap-sass/assets/stylesheets",
"#{node_path()}/bootstrap-sass/assets/stylesheets",
"--precision",
"8"
]
end
def scss_file(), do: "web/static/css/app.scss"
def scss_file(), do: "#{src_path()}/css/app.scss"
def run(_) do
exec(
node_path("/.bin/node-sass"),
node_bin("node-sass"),
sass_args() ++ [scss_file()]
) |> listen()
end
......
defmodule Mix.Tasks.Frontend.Build.Transpile do
use Mix.Task
import CodeStats.{TaskUtils, FrontendConfs}
@shortdoc "Transpile JS sources to ES5"
def run(_) do
run_tasks(["frontend.build.riot", "frontend.build.js.copy"])
exec(
node_bin("babel"),
[
"#{tmp_path()}/compiled/js",
"--out-dir",
"#{tmp_path()}/transpiled/js"
]
) |> listen()
end
end
defmodule Mix.Tasks.Frontend.Clean do
use Mix.Task
import CodeStats.{FrontendConfs}
@shortdoc "Clean build artifacts"
def run(_) do
File.rm_rf!(tmp_path())
File.rm_rf!(dist_path())
end
end
defmodule Mix.Tasks.Frontend.Watch do
use Mix.Task
import CodeStats.TaskUtils
import CodeStats.{TaskUtils, FrontendConfs}
alias Mix.Tasks.Frontend.Build.{Riot, Scss}
@shortdoc "Watch frontend and rebuild when necessary"
......@@ -8,11 +8,11 @@ defmodule Mix.Tasks.Frontend.Watch do
def run(_) do
[
exec(
node_path("/.bin/riot"),
node_bin("riot"),
["-w"] ++ Riot.riot_paths()
),
exec(
node_path("/.bin/node-sass"),
node_bin("node-sass"),
Scss.sass_args() ++ [
"-w",
Scss.scss_file()
......
defmodule CodeStats.FrontendConfs do
import CodeStats.TaskUtils
@moduledoc """
Project specific paths and other stuff for CodeStats frontend.
"""
@doc """
Get absolute path to node_modules.
"""
def node_path() do
"#{proj_path()}/node_modules"
end
@doc """
Get absolute path to binary installed with npm.
"""
def node_bin(executable), do: "#{node_path()}/.bin/#{executable}"
@doc """
Get absolute path to source directory for frontend build.
"""
def src_path(), do: "#{proj_path()}/web/static"
@doc """
Get absolute path to temp directory for build artifacts.
"""
def tmp_path(), do: "#{proj_path()}/.tmp"
@doc """
Get absolute path to target directory for frontend build.
"""
def dist_path(), do: "#{proj_path()}/priv/static"
end
......@@ -41,15 +41,6 @@ defmodule CodeStats.TaskUtils do
System.find_executable(program)
end
@doc """
Get absolute path to node_modules, with optional postfix.
Postfix should have leading slash.
"""
def node_path(postfix \\ "") do
"#{proj_path()}/node_modules#{postfix}"
end
@doc """
Run the given Mix task and wait for it to stop before returning.
......
import { clear_children } from './utils';
import Elm from '../elm-bin/elm-app';
/**
* Handles connecting to the index page socket and sending updates to Elm.
......@@ -39,16 +38,13 @@ class IndexPageUpdater {
installElm() {
this.clearDOM();
this.iu_app = Elm.IndexPage.Updater.embed(this.iu_div);
}
initializeElm(init_data) {
this.iu_app.ports.iu_initialize.send(init_data);
}
newPulse(msg) {
for (const xp of msg.xps) {
this.iu_app.ports.iu_new_xp.send(xp);
}
}
}
......
import { clear_children } from './utils';
import Elm from '../elm-bin/elm-app';
/**
* Handles connecting to the profile page socket and sending updates to Elm.
......@@ -48,18 +47,12 @@ class ProfilePageUpdater {
installElm() {
this.clearDOM();
this.tu_app = Elm.Profile.TotalUpdater.embed(this.tu_div);
this.mu_app = Elm.Profile.MainUpdater.embed(this.mu_div);
}
initializeElm(init_data) {
this.tu_app.ports.tu_initialize.send(init_data);
this.mu_app.ports.mu_initialize.send(init_data);
}
newPulse(msg) {
this.tu_app.ports.tu_new_xp.send(msg);
this.mu_app.ports.mu_new_xp.send(msg);
}
}
......
......@@ -6,6 +6,9 @@
<script>
// logic comes here
this.items = [1, 2, 3];
for (const item of items) {
console.log(item);
}
</script>
</todo>
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment