aboutsummaryrefslogtreecommitdiff
path: root/examples/tomo-install
diff options
context:
space:
mode:
authorBruce Hill <bruce@bruce-hill.com>2025-05-20 15:22:41 -0400
committerBruce Hill <bruce@bruce-hill.com>2025-05-20 15:22:41 -0400
commitefb3aae55908cb88f5a9c900d6563603ab792d6a (patch)
treece4293828ab43de4e6440bed0accf871a2d82f94 /examples/tomo-install
parent3d313c5956510a807c2ce7d1ffd9c3bfbb708444 (diff)
Add more advanced configuration options to modules.ini and support
automatically downloading and installing from it.
Diffstat (limited to 'examples/tomo-install')
-rw-r--r--examples/tomo-install/CHANGES.md5
-rw-r--r--examples/tomo-install/tomo-install.tm84
2 files changed, 0 insertions, 89 deletions
diff --git a/examples/tomo-install/CHANGES.md b/examples/tomo-install/CHANGES.md
deleted file mode 100644
index 42ae752c..00000000
--- a/examples/tomo-install/CHANGES.md
+++ /dev/null
@@ -1,5 +0,0 @@
-# Version History
-
-## v1.0
-
-Initial version
diff --git a/examples/tomo-install/tomo-install.tm b/examples/tomo-install/tomo-install.tm
deleted file mode 100644
index e9838859..00000000
--- a/examples/tomo-install/tomo-install.tm
+++ /dev/null
@@ -1,84 +0,0 @@
-use shell_v1.0
-use patterns_v1.0
-
-_USAGE := "
- tomo-install file.tm...
-"
-
-_HELP := "
- tomo-install: a tool for installing libraries for the Tomo language
- Usage: $_USAGE
-"
-
-func find_urls(path:Path -> [Text])
- urls : @[Text]
- if path.is_directory()
- for f in path.children()
- urls.insert_all(find_urls(f))
- else if path.is_file() and path.extension() == ".tm"
- for line in path.by_line()!
- if captures := line.pattern_captures($Pat/use{space}{url}/) or line.pattern_captures($Pat/{id}{space}:={space}use{space}{url}/)
- urls.insert(captures[-1])
- return urls
-
-func main(paths:[Path])
- if paths.length == 0
- paths = [(./)]
-
- urls := (++: find_urls(p) for p in paths) or []
-
- github_token := (~/.config/tomo/github-token).read()
-
- (~/.local/share/tomo/installed).create_directory()
- (~/.local/share/tomo/lib).create_directory()
-
- for url in urls
- original_url := url
- url_without_protocol := url.trim_pattern($Pat"http{0-1 s}://", right=no)
- hash := $Shell@(echo -n @url_without_protocol | sha256sum).get_output()!.slice(to=32)
- if (~/.local/share/tomo/installed/$hash).is_directory()
- say("Already installed: $url")
- skip
-
- alias : Text?
- curl_flags := ["-L"]
- if github := url_without_protocol.pattern_captures($Pat"github.com/{!/}/{!/}#{..}")
- user := github[1]
- repo := github[2]
- tag := github[3]
- url = "https://api.github.com/repos/$user/$repo/tarball/$tag"
- alias = "$(repo.without_prefix("tomo-")).$(tag).$(user)"
- if github_token
- curl_flags ++= ["-H", "Authorization: Bearer $github_token"]
- curl_flags ++= [
- "-H", "Accept: application/vnd.github+json",
- "-H", "X-GitHub-Api-Version: 2022-11-28",
- ]
-
- (~/.local/share/tomo/downloads/$hash).create_directory()
- say($Shell@`
- set -euo pipefail
- cd ~/.local/share/tomo/downloads/@hash
- curl @curl_flags @url | tar xz -C ~/.local/share/tomo/installed --strip-components=1 --one-top-level=@hash
- echo @original_url > ~/.local/share/tomo/installed/@hash/source.url
- tomo -L ~/.local/share/tomo/installed/@hash
- if [ "`uname -s`" = "Darwin" ]; then
- ln -f -s ../installed/@hash/lib@hash.dylib ~/.local/share/tomo/lib/lib@hash.dylib
- else
- ln -f -s ../installed/@hash/lib@hash.so ~/.local/share/tomo/lib/lib@hash.so
- fi
- `.get_output()!)
-
- if alias
- say($Shell(
- set -exuo pipefail
- ln -f -s @hash ~/.local/share/tomo/installed/@alias
- if [ "`uname -s`" = "Darwin" ]; then
- ln -f -s lib@hash.dylib ~/.local/share/tomo/lib/lib@alias.dylib
- else
- ln -f -s lib@hash.so ~/.local/share/tomo/lib/lib@alias.so
- fi
- ).get_output()!)
-
- say("\[1]Installed $url!\[]")
-