Skip to content

Commit

Permalink
tea can install pantry without git (#65)
Browse files Browse the repository at this point in the history
  • Loading branch information
mxcl committed Sep 28, 2022
1 parent 019dc51 commit 061a972
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 20 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ Change how your team works.
 


# tea/cli 0.6.6
# tea/cli 0.6.7

tea is a universal virtual‑environment manager:

Expand Down
56 changes: 41 additions & 15 deletions src/hooks/usePantry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -119,16 +119,6 @@ const getScript = async (pkg: Package, key: 'build' | 'test', deps: Installation
}
}

const update = async () => {
//FIXME real fix is: don’t use git!
const git = usePrefix().join('git-scm.org/v*')
if (git.isDirectory() || Path.root.join("usr/bin/git").isExecutableFile()) {
await run({
cmd: ["git", "-C", prefix, "pull", "origin", "HEAD", "--no-edit"]
})
}
}

const getProvides = async (pkg: Package | PackageRequirement) => {
const yml = await entry(pkg).yml()
const node = yml["provides"]
Expand All @@ -150,21 +140,56 @@ function coerceNumber(input: any) {
if (isNumber(input)) return input
}


const find_git = async () => {
const in_cellar = await useCellar().has({
project: 'git-scm.org',
constraint: new semver.Range('*')
})
if (in_cellar) {
return in_cellar.path.join('bin/git')
}

for (const path_ in Deno.env.get('PATH')?.split(':') ?? []) {
const path = new Path(path_).join('git')
if (path.isExecutableFile()) {
return path
}
}
}

//TODO we have a better system in mind than git
async function installIfNecessary() {
if (!prefix.exists()) {
const cwd = prefix.parent().parent().mkpath()
async function install() {
if (prefix.exists()) return

const git = await find_git()
const cwd = prefix.parent().parent().mkpath()

if (git) {
await run({
cmd: ["git", "clone", "https://github.com/teaxyz/pantry"],
cmd: [git, "clone", "https://github.com/teaxyz/pantry"],
cwd
})
} else {
//TODO use our tar if necessary
const src = new URL('https://github.com/teaxyz/pantry/archive/refs/heads/main.tar.gz')
const zip = await useDownload().download({ src })
await run({cmd: ["tar", "xf", zip], cwd})
}
}

const update = async () => {
const git = await find_git()
const cwd = prefix.parent().parent().mkpath()
if (git) {
await run({cmd: [git, "pull", "origin", "HEAD", "--no-edit"], cwd})
}
}

function entry(pkg: Package | PackageRequirement): Entry {
const dir = prefix.join(pkg.project)
const yml = async () => {
await installIfNecessary()
await install()
// deno-lint-ignore no-explicit-any
const yml = await dir.join("package.yml").readYAML() as any
if (!isPlainObject(yml)) throw "bad-yaml"
Expand Down Expand Up @@ -332,6 +357,7 @@ function expand_env(env_: PlainObject, pkg: Package, deps: Installation[]): stri

//////////////////////////////////////////// useMoustaches() additions
import useMoustachesBase from "./useMoustaches.ts"
import useDownload from "./useDownload.ts"

function useMoustaches() {
const base = useMoustachesBase()
Expand Down
4 changes: 0 additions & 4 deletions src/hooks/useVirtualEnv.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,6 @@ async function extractFromMarkdown(path: Path): Promise<VirtualEnvSubset | undef
const text = await path.read()
const lines = text.split("\n")

console.debug("HI")

const findTable = (header: string) => {
let rows: [string, string][] | undefined = undefined
let found: 'nope' | 'header' | 'table' = 'nope'
Expand Down Expand Up @@ -114,8 +112,6 @@ async function extractFromMarkdown(path: Path): Promise<VirtualEnvSubset | undef
)

const fromFirstHeader = () => {
console.debug("HI2")

for (let line of lines) {
line = line.trim()
if (/^#+/.test(line)) {
Expand Down

0 comments on commit 061a972

Please sign in to comment.