Skip to content

Commit

Permalink
make sh work
Browse files Browse the repository at this point in the history
  • Loading branch information
kla committed Aug 17, 2024
1 parent 536870a commit 8ba9647
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 8 deletions.
13 changes: 12 additions & 1 deletion src/app.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import Container from '~/container'
import Staxfile from '~/staxfile'
import setup from '~/setup'

export default class App {
Expand All @@ -22,14 +23,24 @@ export default class App {
return setup(contextName, location)
}

static all(contextName: string): App[] {
const containers = {}

Container.all(contextName).forEach((container) => {
if (!containers[container.app]) containers[container.app] = []
containers[container.app].push(container)
})

return Object.keys(containers).map((name) => new App(name, containers[name]))
}

static find(contextName: string, name: string): App | null{
const container = Container.find(contextName, name, { mustExist: true })

if (!container) {
console.warn(`🤷 App '${name}@${contextName}' not found`)
return null
}

return new App(name, [container])
}

Expand Down
2 changes: 1 addition & 1 deletion src/container.ts
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ export default class Container {
}

async exec(command: string) {
return docker.compose(this.contextName, `exec -it ${this.name} ${command}`, this.name, { append: false })
return docker.container(`exec -it ${this.name} ${command}`)
}

async rebuild() {
Expand Down
6 changes: 5 additions & 1 deletion src/docker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@ async function compose(contextName: string, command: string, path: string, optio
return run(`${base} -f ${path} ${command}`, options)
}

async function container(command: string) {
return run(`docker container ${command}`)
}

/**
* Returns a list of all Docker containers.
* @returns An array of strings representing the Docker containers.
Expand All @@ -24,5 +28,5 @@ function ps(contextName: string): Array<Record<string,any>> {
return capture('docker ps --all --format json').split("\n").map(attributes => JSON.parse(attributes))
}

const docker = { compose, ps }
const docker = { compose, container, ps }
export default docker
9 changes: 4 additions & 5 deletions src/stax.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,17 +27,16 @@ export default class Stax {
App.setup(this.name, location)
}

find(name: string): App | undefined {
const app = this.apps().find(app => app.name == name)
find(appName: string): App | undefined {
const app = this.apps().find(app => app.name == appName)

if (!app)
return exit(1, `No app named '${name}@${this.name}' was found.`)
return exit(1, `No app named '${appName}@${this.name}' was found.`)

return app
}

apps(): App[] {
return Container.all(this.name)
.map(container => App.find(this.name, container.name))
return App.all(this.name)
}
}

0 comments on commit 8ba9647

Please sign in to comment.