Tidy up structure of briefcase
I had a spare fifteen minutes and decided that I should tidy up my monorepo. The work of tidying up is not finished; this is a small step in the right direction. TL;DR - Created a tools directory - Created a scratch directory (see README.md for more information) - Added README.md to third_party - Renamed delete_dotfile_symlinks -> symlinkManager - Packaged symlinkManager as an executable symlink-mgr using buildGo
This commit is contained in:
parent
5ec5a6da8c
commit
fabf1c9334
89 changed files with 53 additions and 41 deletions
2
tools/run/.envrc
Normal file
2
tools/run/.envrc
Normal file
|
@ -0,0 +1,2 @@
|
|||
source_up
|
||||
eval "$(lorri direnv)"
|
30
tools/run/README.md
Normal file
30
tools/run/README.md
Normal file
|
@ -0,0 +1,30 @@
|
|||
# run
|
||||
|
||||
Simplify the commands you call to run scripts on the command line.
|
||||
|
||||
```shell
|
||||
> run path/to/file.py
|
||||
> run path/to/file.ts
|
||||
```
|
||||
|
||||
## How?
|
||||
|
||||
Define a run.json configuration mapping commands to filename extensions like
|
||||
so:
|
||||
```json
|
||||
{
|
||||
".ts": "npx ts-node $file",
|
||||
".py": "python3 $file"
|
||||
}
|
||||
```
|
||||
|
||||
Then call `run path/to/some/file.ts` on the command line, and `npx ts-node
|
||||
file.ts` will run.
|
||||
|
||||
## Installation
|
||||
|
||||
Install `run` using Nix.
|
||||
|
||||
```shell
|
||||
> nix-env -iA briefcase.run
|
||||
```
|
16
tools/run/default.nix
Normal file
16
tools/run/default.nix
Normal file
|
@ -0,0 +1,16 @@
|
|||
{
|
||||
pkgs ? import <nixpkgs> {},
|
||||
depot ? import <depot> {},
|
||||
briefcase ? import <briefcase> {},
|
||||
...
|
||||
}:
|
||||
|
||||
depot.buildGo.program {
|
||||
name = "run";
|
||||
srcs = [
|
||||
./main.go
|
||||
];
|
||||
deps = with briefcase.gopkgs; [
|
||||
utils
|
||||
];
|
||||
}
|
49
tools/run/main.go
Normal file
49
tools/run/main.go
Normal file
|
@ -0,0 +1,49 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"log"
|
||||
"os"
|
||||
"os/exec"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
"utils"
|
||||
)
|
||||
|
||||
func main() {
|
||||
if len(os.Args) != 2 {
|
||||
log.Fatal("You can only call run with a single file at a time.")
|
||||
}
|
||||
|
||||
rulesPath := utils.Resolve("run.json", []string{"/home/wpcarro/.config/run/run.json"})
|
||||
b, err := ioutil.ReadFile(rulesPath)
|
||||
if err != nil {
|
||||
log.Fatal("Could not locate a run.json file: ", err)
|
||||
}
|
||||
rules := map[string]string{}
|
||||
err = json.Unmarshal(b, &rules)
|
||||
if err != nil {
|
||||
log.Fatal("Could not decode run.json as JSON: ", err)
|
||||
}
|
||||
|
||||
fileName := os.Args[1]
|
||||
ext := filepath.Ext(fileName)
|
||||
cmd, ok := rules[ext]
|
||||
|
||||
if !ok {
|
||||
log.Fatalf("No rules for extension, %s, have been defined.", ext)
|
||||
}
|
||||
|
||||
// TODO(wpcarro): Support more sophisticated parsing than just string
|
||||
// splitting. To handle 'cases like this'.
|
||||
tokens := strings.Split(strings.Replace(cmd, "$file", fileName, 1), " ")
|
||||
c := exec.Command(tokens[0], tokens[1:]...)
|
||||
err = c.Start()
|
||||
// TODO(wpcarro): Forward STDERR and STDOUT.
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
fmt.Println(c.Wait())
|
||||
}
|
7
tools/run/shell.nix
Normal file
7
tools/run/shell.nix
Normal file
|
@ -0,0 +1,7 @@
|
|||
{ pkgs ? import <nixpkgs> {}, ... }:
|
||||
|
||||
pkgs.mkShell {
|
||||
buildInputs = with pkgs; [
|
||||
go
|
||||
];
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue