subtree(users/wpcarro): docking briefcase at '24f5a642'
git-subtree-dir: users/wpcarro git-subtree-mainline:464bbcb15cgit-subtree-split:24f5a642afChange-Id: I6105b3762b79126b3488359c95978cadb3efa789
This commit is contained in:
commit
019f8fd211
766 changed files with 175420 additions and 0 deletions
21
users/wpcarro/boilerplate/README.md
Normal file
21
users/wpcarro/boilerplate/README.md
Normal 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
|
||||
```
|
||||
2
users/wpcarro/boilerplate/clojure/.envrc
Normal file
2
users/wpcarro/boilerplate/clojure/.envrc
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
source_up
|
||||
use_nix
|
||||
4
users/wpcarro/boilerplate/clojure/.gitignore
vendored
Normal file
4
users/wpcarro/boilerplate/clojure/.gitignore
vendored
Normal file
|
|
@ -0,0 +1,4 @@
|
|||
/.lein-repl-history
|
||||
/target
|
||||
/?
|
||||
/.nrepl-port
|
||||
33
users/wpcarro/boilerplate/clojure/README.md
Normal file
33
users/wpcarro/boilerplate/clojure/README.md
Normal 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
|
||||
```
|
||||
2
users/wpcarro/boilerplate/clojure/project.clj
Normal file
2
users/wpcarro/boilerplate/clojure/project.clj
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
(defproject boilerplate "0.0.1"
|
||||
:dependencies [[org.clojure/clojure "1.8.0"]])
|
||||
8
users/wpcarro/boilerplate/clojure/shell.nix
Normal file
8
users/wpcarro/boilerplate/clojure/shell.nix
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
let
|
||||
briefcase = import <briefcase> {};
|
||||
pkgs = briefcase.third_party.pkgs;
|
||||
in pkgs.mkShell {
|
||||
buildInputs = with pkgs; [
|
||||
leiningen
|
||||
];
|
||||
}
|
||||
8
users/wpcarro/boilerplate/clojure/src/main.clj
Normal file
8
users/wpcarro/boilerplate/clojure/src/main.clj
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
(ns ^{:doc "Top-level module."
|
||||
:author "William Carroll"}
|
||||
main)
|
||||
|
||||
(declare main)
|
||||
|
||||
(defn foo [a b]
|
||||
(+ a b))
|
||||
2
users/wpcarro/boilerplate/elm/.envrc
Normal file
2
users/wpcarro/boilerplate/elm/.envrc
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
source_up
|
||||
use_nix
|
||||
3
users/wpcarro/boilerplate/elm/.gitignore
vendored
Normal file
3
users/wpcarro/boilerplate/elm/.gitignore
vendored
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
/elm-stuff
|
||||
/Main.min.js
|
||||
/output.css
|
||||
18
users/wpcarro/boilerplate/elm/README.md
Normal file
18
users/wpcarro/boilerplate/elm/README.md
Normal 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`!
|
||||
30
users/wpcarro/boilerplate/elm/elm.json
Normal file
30
users/wpcarro/boilerplate/elm/elm.json
Normal 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": {}
|
||||
}
|
||||
}
|
||||
3
users/wpcarro/boilerplate/elm/index.css
Normal file
3
users/wpcarro/boilerplate/elm/index.css
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
@tailwind base;
|
||||
@tailwind components;
|
||||
@tailwind utilities;
|
||||
15
users/wpcarro/boilerplate/elm/index.html
Normal file
15
users/wpcarro/boilerplate/elm/index.html
Normal 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>
|
||||
10
users/wpcarro/boilerplate/elm/shell.nix
Normal file
10
users/wpcarro/boilerplate/elm/shell.nix
Normal 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
|
||||
];
|
||||
}
|
||||
13
users/wpcarro/boilerplate/elm/src/Landing.elm
Normal file
13
users/wpcarro/boilerplate/elm/src/Landing.elm
Normal 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!" ]
|
||||
]
|
||||
13
users/wpcarro/boilerplate/elm/src/Login.elm
Normal file
13
users/wpcarro/boilerplate/elm/src/Login.elm
Normal 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" ]
|
||||
]
|
||||
31
users/wpcarro/boilerplate/elm/src/Main.elm
Normal file
31
users/wpcarro/boilerplate/elm/src/Main.elm
Normal 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
|
||||
}
|
||||
43
users/wpcarro/boilerplate/elm/src/State.elm
Normal file
43
users/wpcarro/boilerplate/elm/src/State.elm
Normal 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
|
||||
)
|
||||
2
users/wpcarro/boilerplate/typescript/.envrc
Normal file
2
users/wpcarro/boilerplate/typescript/.envrc
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
source_up
|
||||
use_nix
|
||||
3
users/wpcarro/boilerplate/typescript/.gitignore
vendored
Normal file
3
users/wpcarro/boilerplate/typescript/.gitignore
vendored
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
/.cache
|
||||
/dist
|
||||
/node_modules
|
||||
26
users/wpcarro/boilerplate/typescript/README.md
Normal file
26
users/wpcarro/boilerplate/typescript/README.md
Normal 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
|
||||
```
|
||||
19
users/wpcarro/boilerplate/typescript/default.nix
Normal file
19
users/wpcarro/boilerplate/typescript/default.nix
Normal 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
|
||||
'';
|
||||
}
|
||||
27
users/wpcarro/boilerplate/typescript/package.json
Normal file
27
users/wpcarro/boilerplate/typescript/package.json
Normal 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"
|
||||
}
|
||||
}
|
||||
7
users/wpcarro/boilerplate/typescript/postcss.config.js
Normal file
7
users/wpcarro/boilerplate/typescript/postcss.config.js
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
const tailwindcss = require('tailwindcss')
|
||||
|
||||
module.exports = {
|
||||
plugins: [
|
||||
tailwindcss('./tailwind.config.js')
|
||||
]
|
||||
}
|
||||
9
users/wpcarro/boilerplate/typescript/shell.nix
Normal file
9
users/wpcarro/boilerplate/typescript/shell.nix
Normal file
|
|
@ -0,0 +1,9 @@
|
|||
let
|
||||
briefcase = import <briefcase> {};
|
||||
pkgs = briefcase.third_party.pkgs;
|
||||
in pkgs.mkShell {
|
||||
buildInputs = with pkgs; [
|
||||
nodejs
|
||||
yarn
|
||||
];
|
||||
}
|
||||
52
users/wpcarro/boilerplate/typescript/src/App.tsx
Normal file
52
users/wpcarro/boilerplate/typescript/src/App.tsx
Normal 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;
|
||||
3
users/wpcarro/boilerplate/typescript/src/index.css
Normal file
3
users/wpcarro/boilerplate/typescript/src/index.css
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
@tailwind base;
|
||||
@tailwind components;
|
||||
@tailwind utilities;
|
||||
11
users/wpcarro/boilerplate/typescript/src/index.html
Normal file
11
users/wpcarro/boilerplate/typescript/src/index.html
Normal 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>
|
||||
12
users/wpcarro/boilerplate/typescript/src/index.tsx
Normal file
12
users/wpcarro/boilerplate/typescript/src/index.tsx
Normal 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")
|
||||
);
|
||||
26
users/wpcarro/boilerplate/typescript/src/store.ts
Normal file
26
users/wpcarro/boilerplate/typescript/src/store.ts
Normal 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 });
|
||||
7
users/wpcarro/boilerplate/typescript/tailwind.config.js
Normal file
7
users/wpcarro/boilerplate/typescript/tailwind.config.js
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
module.exports = {
|
||||
theme: {
|
||||
extend: {},
|
||||
},
|
||||
variants: {},
|
||||
plugins: [],
|
||||
}
|
||||
25
users/wpcarro/boilerplate/typescript/tsconfig.json
Normal file
25
users/wpcarro/boilerplate/typescript/tsconfig.json
Normal 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/**/*"
|
||||
]
|
||||
}
|
||||
5670
users/wpcarro/boilerplate/typescript/yarn.lock
Normal file
5670
users/wpcarro/boilerplate/typescript/yarn.lock
Normal file
File diff suppressed because it is too large
Load diff
Loading…
Add table
Add a link
Reference in a new issue