Skip to content

Commit

Permalink
Using .iorc instead of protos directory.
Browse files Browse the repository at this point in the history
Added basic functions to command-line tool.
  • Loading branch information
josip committed Mar 14, 2010
1 parent 7514c15 commit e1e771c
Show file tree
Hide file tree
Showing 5 changed files with 151 additions and 43 deletions.
107 changes: 104 additions & 3 deletions bin/eerie
Original file line number Diff line number Diff line change
@@ -1,6 +1,107 @@
#!/usr/bin/env io
Eerie
(System args size == 3) ifTrue(
Eerie Package with(System args at(1), System args at(2)) install)
Kano

#Eerie Package with("Ike", "git://github.com/defunkt/ike.git") install
Eerie do(
_log := getSlot("log")
log = method(str, mode,
(mode == nil or mode == "info" or mode == "error") ifTrue(
self _log(str, mode)))
)

Namespaces Env := Namespace clone
Eerie Env describe do(
setNamespace(Namespaces Env)
setRequiresClone(true)

createClone = method(args,
Eerie Env named(args removeFirst))

task("create") do(
describe("Creates a new environment.")
createClone = method(args,
self targetObj with(args removeFirst))

after(r, "Created #{self targetObj name} env." interpolate)
)

task("activate") do(
describe("Activates the environment, all binaries and addons in it will be loaded by default.")
after(r, "#{Eerie activeEnv name} is now the default env." interpolate)
)

task("remove") do(
describe("Removes an environemnt with all its packages.")
after(r, "#{self targetObj name} was removed." interpolate)
)
) done

Eerie describe do(
setNamespace(Namespaces Env)

task("active") callsSlot("activeEnv") do(
describe("Prints the name of active environment.")
after(env, env name)
)

task("list") callsSlot("envs") do(
describe("Lists all available environments.")
after(envs,
envs map(env, if(env isActive, env name .. " *", env name)) select(!= nil) sort)
returns(List, Map with("joinWith", "\n"))
)
) done

Namespaces Pkg := Namespace clone
Eerie Package describe do(
setNamespace(Namespaces Pkg)
setRequiresClone(true)

createClone = method(args,
Eerie activeEnv packageNamed(args removeFirst))

task("install") do(
describe("Installs a new package.")
createClone = method(args,
Eerie Package fromUri(args removeFirst))

after(pkg,
"Package #{pkg name} has been installed." interpolate println

readme := pkg config at("meta") ?at("readme")
if(readme isNil,
""
,
readmeFile := File with(pkg path .. "/" .. readme)
readmeFile exists ifFalse(return(""))

"Opening readme file..." println
System sleep(2)

openCommand := if(System platform == "Darwin", "open", System getEnvironmentVariable("EDITOR"))
openCommand isNil ifTrue(openCommand = "more")

System system(openCommand .. " " .. readmeFile path)
""))
)

task("update") do(
describe("Updates the package and all of its submodules.")
after(result, "Package #{self targetObj name} has been updated." interpolate)
)

task("remove") do(
describe("Removes the package.")
after(result, "Package #{self targetObj name} has been removed." interpolate)
)

task("list") do(
describe("Lists all packages installed within current environment")
targetObj = Eerie activeEnv
callsSlot("packages")
after(result, result map(name))
returns(List, Map with("joinWih"))
)
) done

Kano clone setUseExternalFile(false) run
2 changes: 1 addition & 1 deletion io/Eerie.io
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,6 @@ Eerie clone = Eerie do(
doRelativeFile("Eerie/PackageDownloader.io")
doRelativeFile("Eerie/PackageInstaller.io")
doRelativeFile("Eerie/Env.io")

init
)
28 changes: 10 additions & 18 deletions io/Eerie/Env.io
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,14 @@ Env := Object clone do(
"packages", List clone)
Eerie envs appendIfAbsent(self))

with := method(_name,
self clone setName(_name))
with := method(name_,
self clone setName(name_))

named := method(_name,
Eerie envs detect(name == _name))
named := method(name_,
Eerie envs detect(name == name_))

withConfig := method(_name, _config,
self clone setName(_name) setConfig(_config))
withConfig := method(name_, config_,
self clone setName(name_) setConfig(config_))

create := method(
root := Directory with((Eerie root) .. "/env/" .. (self name))
Expand All @@ -37,16 +37,13 @@ Env := Object clone do(
root create
root createSubdirectory("bin")
root createSubdirectory("addons")
root createSubdirectory("protos")

Eerie config at("envs") atPut(self name, self config)
Eerie saveConfig
Eerie log("Created #{self name} env.")

self)

use := method(
Eerie log("Using #{self name} env.")
Eerie activeEnv isNil ifFalse(
AddonLoader searchPaths remove(Eerie activeEnv path))

Expand Down Expand Up @@ -78,21 +75,16 @@ Env := Object clone do(
self packages = self config at("packages") map(pkgConfig,
Eerie Package withConfig(pkgConfig)))

packageNamed := method(pkgName,
self packages detect(name == pkgName))

registerPackage := method(package,
self config at("packages") appendIfAbsent(package asJson)
self packages appendIfAbsent(package)
Eerie saveConfig

package providesProtos foreach(providedProto,
l := """
AddonLoader appendSearchPath(System getEnvironmentVariable("EERIEDIR") .. "/env/#{self name}/addons")
AddonLoader loadAddonNamed("#{providedProto}")
""" interpolate
File with("#{self path}/protos/#{providedProto}.io" interpolate) create openForUpdating write(l) close)

Eerie log("Installed package #{package name}.")
self)

removePackage := method(package,
"removePackage" println)

Expand Down
36 changes: 21 additions & 15 deletions io/Eerie/Package.io
Original file line number Diff line number Diff line change
Expand Up @@ -32,22 +32,27 @@ Package := Object clone do(
"path", nil,
"meta", Map clone))

with := method(_name, _uri,
with := method(name_, uri_,
self clone setConfig(Map with(
"name", _name,
"uri", _uri,
"path", (Eerie activeEnv path) .. "/addons/" .. _name)))
"name", name_,
"uri", uri_,
"path", (Eerie activeEnv path) .. "/addons/" .. name_)))

withConfig := method(config,
self clone setConfig(config))

guessName := method(_uri,
f := File with(_uri)
f exists ifTrue(
return(f baseName makeFirstCharacterUppercase))
fromUri := method(path_,
self with(self guessName(path_), path_))

guessName := method(uri_,
f := File with(uri_)
(uri_ exSlice(-1) == "/") ifTrue(
uri_ = uri_ exSlice(0, -1))

_uri containsSeq("://") ifTrue(
return(_uri split("/") last split(".") first makeFirstCharacterUppercase)))
if(f exists,
# We can't use baseName here because it returns nil for directories
f name split(".") first makeFirstCharacterUppercase,
uri_ split("/") last split(".") first makeFirstCharacterUppercase))

setInstaller := method(inst,
self installer = inst
Expand All @@ -65,13 +70,13 @@ Package := Object clone do(
Exception raise("Package #{self name} is already installed." interpolate)))

event := if(isUpdate, "Update", "Install")
Eerie log("#{event}ing '#{self name}' from #{self uri}...")
#Eerie log("#{event}ing '#{self name}' from #{self uri}...")
self runHook("before" .. event)

Directory with(self path) createIfAbsent
self setDownloader(Eerie PackageDownloader detect(self uri, self path))
self downloader download

self loadMetadata
self installDependencies

Expand All @@ -81,12 +86,13 @@ Package := Object clone do(
self loadMetadata
Eerie activeEnv registerPackage(self)

self runHook("after" .. event))
self runHook("after" .. event)
self)

installDependencies := method(
deps := self dependencies("packages")
deps foreach(_uri,
self with(self guessName(_uri), _uri) install))
self fromUri(_uri) install))

update := method(
self runHook("beforeUpdateDownload")
Expand All @@ -108,7 +114,7 @@ Package := Object clone do(
true)

runHook := method(hook,
f := File with("#{self path}/hooks/#{hook}.io")
f := File with("#{self path}/hooks/#{hook}.io" interpolate)
f exists ifTrue(
try(
Thread createThread(f contents))
Expand Down
21 changes: 15 additions & 6 deletions setup.io
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,10 @@ Object clone do(
# Four Commandments of Eerie
EERIEDIR="#{eerieDir}"
IOIMPORT=$IOIMPORT:$EERIEDIR/activeEnv/protos
#IOIMPORT=$IOIMPORT:$EERIEDIR/activeEnv/protos
PATH=$PATH:$EERIEDIR/activeEnv/bin
export EERIEDIR IOIMPORT PATH
export EERIEDIR PATH
# That's all folks
""" interpolate

Expand All @@ -32,17 +33,25 @@ export EERIEDIR IOIMPORT PATH
f close)

" - Updated bash profile." println

iorc := File with(homeDir .. "/.iorc")
iorc exists ifFalse(iorc create)
loaderCode := """AddonLoader appendSearchPath(System getEnvironmentVariable("EERIEDIR") .. "/activeEnv/addons")"""
iorc openForAppending contents containsSeq("EERIEDIR") ifFalse(
iorc appendToContents(loaderCode .. "\n"))
iorc close
" - Updated iorc file." println

System setEnvironmentVariable("EERIEDIR", eerieDir)

Directory with(eerieDir) create
Directory with(eerieDir .. "/env") create

#protosLoader := """AddonLoader appendSearchPath(System getEnvironmentVariable("EERIEDIR") .. "/activeEnv/addons")"""
#File with(eerieDir .. "/loader.io") create openForUpdating write(protosLoader) close
File with(eerieDir .. "/config.json") create openForUpdating write("{\"envs\": {}}") close

Eerie Env with("base") create activate use
Eerie Package with("Eerie", Directory currentWorkingDirectory) install
" -.-" println
" - Is there an eerie sound coming out of your basement?" println)
" ---- Fin ----" println
System sleep(1)
" - Oh, wait, is there an eerie sound coming out of your basement?" println)
) setup

0 comments on commit e1e771c

Please sign in to comment.