subtree(users/wpcarro): docking briefcase at '24f5a642'

git-subtree-dir: users/wpcarro
git-subtree-mainline: 464bbcb15c
git-subtree-split: 24f5a642af
Change-Id: I6105b3762b79126b3488359c95978cadb3efa789
This commit is contained in:
Vincent Ambo 2021-12-14 01:51:19 +03:00
commit 019f8fd211
766 changed files with 175420 additions and 0 deletions

View file

@ -0,0 +1,21 @@
# Boilerplate
Storing some boilerplate code to help me reduce the time it takes me to develop
and deploy applications.
## Usage
Let's say that you would like to create a game for
`sandbox.wpcarro.dev/game`. We will create a new TypeScript project with the
following:
```shell
$ cp ~/briefcase/boilerplate/typescript ~/briefcase/website/sandbox/game
```
This initializes the project. To start developing, run:
```shell
$ nix-shell
$ yarn run dev
```

View file

@ -0,0 +1,2 @@
source_up
use_nix

View file

@ -0,0 +1,4 @@
/.lein-repl-history
/target
/?
/.nrepl-port

View file

@ -0,0 +1,33 @@
# Clojure Boilerplate
This boilerplate uses `lein` to manage the project.
## Files to change
To use this boilerplate, run the following in a shell:
```shell
$ cp ~/briefcase/boilerplate/clojure path/to/new-project
```
After running the above command, change the following files to remove the
placeholder values:
- `README.md`: Change the title; change the description; drop "Files to change";
keep "Getting started"
- `project.clj`: Change title
- `src/main.clj`: Change `:doc`; drop `main/foo`
## Getting started
From a shell, run:
```shell
$ lein repl
```
From Emacs, navigate to a source code buffer and run:
```
M-x cider-jack-in
```

View file

@ -0,0 +1,2 @@
(defproject boilerplate "0.0.1"
:dependencies [[org.clojure/clojure "1.8.0"]])

View file

@ -0,0 +1,8 @@
let
briefcase = import <briefcase> {};
pkgs = briefcase.third_party.pkgs;
in pkgs.mkShell {
buildInputs = with pkgs; [
leiningen
];
}

View file

@ -0,0 +1,8 @@
(ns ^{:doc "Top-level module."
:author "William Carroll"}
main)
(declare main)
(defn foo [a b]
(+ a b))

View file

@ -0,0 +1,2 @@
source_up
use_nix

View file

@ -0,0 +1,3 @@
/elm-stuff
/Main.min.js
/output.css

View file

@ -0,0 +1,18 @@
# Elm
Elm has one of the best developer experiences that I'm aware of. The error
messages are helpful and the entire experience is optimized to improve the ease
of writing web applications.
## Developing
If you're interested in contributing, the following will create an environment
in which you can develop:
```shell
$ nix-shell
$ npx tailwindcss build index.css -o output.css
$ elm-live -- src/Main.elm --output=Main.min.js
```
You can now view your web client at `http://localhost:8000`!

View file

@ -0,0 +1,30 @@
{
"type": "application",
"source-directories": [
"src"
],
"elm-version": "0.19.1",
"dependencies": {
"direct": {
"elm/browser": "1.0.2",
"elm/core": "1.0.5",
"elm/html": "1.0.0",
"elm/random": "1.0.0",
"elm/svg": "1.0.1",
"elm/time": "1.0.0",
"elm-community/list-extra": "8.2.3",
"elm-community/maybe-extra": "5.2.0",
"elm-community/random-extra": "3.1.0"
},
"indirect": {
"elm/json": "1.1.3",
"elm/url": "1.0.0",
"elm/virtual-dom": "1.0.2",
"owanturist/elm-union-find": "1.0.0"
}
},
"test-dependencies": {
"direct": {},
"indirect": {}
}
}

View file

@ -0,0 +1,3 @@
@tailwind base;
@tailwind components;
@tailwind utilities;

View file

@ -0,0 +1,15 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<title>Elm SPA</title>
<link rel="stylesheet" href="./output.css" />
<script src="./Main.min.js"></script>
</head>
<body class="font-serif">
<div id="mount"></div>
<script>
Elm.Main.init({node: document.getElementById("mount")});
</script>
</body>
</html>

View file

@ -0,0 +1,10 @@
let
briefcase = import <briefcase> {};
pkgs = briefcase.third_party.pkgs;
in pkgs.mkShell {
buildInputs = with pkgs.elmPackages; [
elm
elm-format
elm-live
];
}

View file

@ -0,0 +1,13 @@
module Landing exposing (render)
import Html exposing (..)
import Html.Attributes exposing (..)
import Html.Events exposing (..)
import State
render : State.Model -> Html State.Msg
render model =
div [ class "pt-10 pb-20 px-10" ]
[ p [] [ text "Welcome to the landing page!" ]
]

View file

@ -0,0 +1,13 @@
module Login exposing (render)
import Html exposing (..)
import Html.Attributes exposing (..)
import Html.Events exposing (..)
import State
render : State.Model -> Html State.Msg
render model =
div [ class "pt-10 pb-20 px-10" ]
[ p [] [ text "Please authenticate" ]
]

View file

@ -0,0 +1,31 @@
module Main exposing (main)
import Browser
import Html exposing (..)
import Landing
import Login
import State
subscriptions : State.Model -> Sub State.Msg
subscriptions model =
Sub.none
view : State.Model -> Html State.Msg
view model =
case model.view of
State.Landing ->
Landing.render model
State.Login ->
Login.render model
main =
Browser.element
{ init = \() -> ( State.init, Cmd.none )
, subscriptions = subscriptions
, update = State.update
, view = view
}

View file

@ -0,0 +1,43 @@
module State exposing (..)
type Msg
= DoNothing
| SetView View
type View
= Landing
| Login
type alias Model =
{ isLoading : Bool
, view : View
}
{-| The initial state for the application.
-}
init : Model
init =
{ isLoading = False
, view = Landing
}
{-| Now that we have state, we need a function to change the state.
-}
update : Msg -> Model -> ( Model, Cmd Msg )
update msg model =
case msg of
DoNothing ->
( model, Cmd.none )
SetView x ->
( { model
| view = x
, isLoading = True
}
, Cmd.none
)

View file

@ -0,0 +1,2 @@
source_up
use_nix

View file

@ -0,0 +1,3 @@
/.cache
/dist
/node_modules

View file

@ -0,0 +1,26 @@
# Frontend Boilerplate
While many times I prefer using alt-languages like ReasonML, ClojureScript, or
Elm, sometimes I prefer to write an application using TypeScript. This directory
contains the necessary starter code to create these applications.
- React: Maps application state to UI
- React-Router: Stateful routing for SPAs
- Redux: Application state management
- TypeScript: Type-safety
- TailwindCSS: Styling library using utility classes
- Prettier: Source code formatting
- Jest: Test runner
## Developing
```shell
$ nix-shell
$ yarn run dev
```
## Building
```shell
$ nix-build
```

View file

@ -0,0 +1,19 @@
{ pkgs, ... }:
pkgs.stdenv.mkDerivation {
name = "typescript";
srcs = builtins.path { path = ./.; name = "typescript"; };
buildInputs = with pkgs; [
nodejs
# Exposes lscpu for parcel.js
utillinux
];
# parcel.js needs number of CPUs
PARCEL_WORKERS = "1";
buildPhase = ''
npx parcel build src/index.html --public-url ./
'';
installPhase = ''
mv dist $out
'';
}

View file

@ -0,0 +1,27 @@
{
"name": "tailwindcss",
"version": "1.0.0",
"main": "index.js",
"license": "MIT",
"scripts": {
"dev": "parcel src/index.html & npx tsc --watch --noEmit",
"prettier": "prettier --ignore-path .gitignore --write \"**/*.{js,ts,jsx,tsx,html,css.json}\""
},
"devDependencies": {
"@types/node": "^13.9.3",
"parcel-bundler": "^1.12.4",
"prettier": "^2.0.2",
"tailwindcss": "^1.2.0",
"typescript": "^3.8.3"
},
"dependencies": {
"@reduxjs/toolkit": "^1.2.5",
"@types/react-dom": "^16.9.5",
"@types/react-redux": "^7.1.7",
"@types/react-router-dom": "^5.1.3",
"react": "^16.13.1",
"react-dom": "^16.13.1",
"react-redux": "^7.2.0",
"react-router-dom": "^5.1.2"
}
}

View file

@ -0,0 +1,7 @@
const tailwindcss = require('tailwindcss')
module.exports = {
plugins: [
tailwindcss('./tailwind.config.js')
]
}

View file

@ -0,0 +1,9 @@
let
briefcase = import <briefcase> {};
pkgs = briefcase.third_party.pkgs;
in pkgs.mkShell {
buildInputs = with pkgs; [
nodejs
yarn
];
}

View file

@ -0,0 +1,52 @@
import React, { useEffect } from "react";
import { BrowserRouter as Router, Switch, Route } from "react-router-dom";
import { useDispatch } from "react-redux";
import { actions, useTypedSelector } from "./store";
import { Link } from "react-router-dom";
const App: React.FC = () => {
const dispatch = useDispatch();
const { isLoading } = useTypedSelector(state => ({
isLoading: state.isLoading,
}));
return (
<Router>
<nav className="bg-blue-400">
<ul className="container mx-auto justify-between flex py-6 text-white">
<li>
<Link to="/">Home</Link>
</li>
<li>
<Link to="/about">About</Link>
</li>
<li>
<Link to="/contact">Contact</Link>
</li>
</ul>
</nav>
<Switch>
<Route exact path="/">
<div className="container mx-auto">
<h1>Welcome to the home page. Loading: {isLoading ? "true" : "false"}</h1>
<button
className="bg-gray-300 py-4 px-6"
onClick={() => dispatch(actions.toggleIsLoading())}>isLoading</button>
</div>
</Route>
<Route exact path="/about">
<div className="container mx-auto">
<h1>Here is the about page.</h1>
</div>
</Route>
<Route exact path="/contact">
<div className="container mx-auto">
<h1>Here is the contact page.</h1>
</div>
</Route>
</Switch>
</Router>
);
};
export default App;

View file

@ -0,0 +1,3 @@
@tailwind base;
@tailwind components;
@tailwind utilities;

View file

@ -0,0 +1,11 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<link rel="stylesheet" href="./index.css" />
</head>
<body>
<div id="mount"></div>
<script src="./index.tsx"></script>
</body>
</html>

View file

@ -0,0 +1,12 @@
import React from "react";
import ReactDOM from "react-dom";
import App from "./App";
import { Provider } from "react-redux";
import store from "./store";
ReactDOM.render(
<Provider store={store}>
<App />
</Provider>,
document.getElementById("mount")
);

View file

@ -0,0 +1,26 @@
import { createSlice, configureStore, PayloadAction } from "@reduxjs/toolkit";
import { useSelector, TypedUseSelectorHook } from "react-redux";
export interface State {
isLoading: boolean;
}
const initialState: State = {
isLoading: true,
};
export const { actions, reducer } = createSlice({
name: "application",
initialState,
reducers: {
toggleIsLoading: state => ({ ...state, isLoading: !state.isLoading }),
}
});
/**
* Defining and consuming this allows us to avoid annotating State in all of our
* selectors.
*/
export const useTypedSelector: TypedUseSelectorHook<State> = useSelector;
export default configureStore({ reducer });

View file

@ -0,0 +1,7 @@
module.exports = {
theme: {
extend: {},
},
variants: {},
plugins: [],
}

View file

@ -0,0 +1,25 @@
{
"compilerOptions": {
"target": "es5",
"lib": [
"dom",
"dom.iterable",
"esnext"
],
"allowJs": true,
"skipLibCheck": true,
"esModuleInterop": true,
"allowSyntheticDefaultImports": true,
"strict": true,
"forceConsistentCasingInFileNames": true,
"module": "esnext",
"moduleResolution": "node",
"resolveJsonModule": true,
"isolatedModules": true,
"noEmit": true,
"jsx": "react"
},
"include": [
"src/**/*"
]
}

File diff suppressed because it is too large Load diff