58 lines
1.4 KiB
Plaintext
58 lines
1.4 KiB
Plaintext
// cell get <locator> - Fetch a module and add it to dependencies
|
|
|
|
var fd = use('fd')
|
|
var shop = use('shop')
|
|
var miniz = use('miniz')
|
|
var http = use('http')
|
|
|
|
if (args.length < 1) {
|
|
log.console("Usage: cell get <locator> [alias]")
|
|
log.console("Examples:")
|
|
log.console(" cell get git.world/jj/mod@v0.6.3")
|
|
log.console(" cell get git.world/jj/mod (uses head/master)")
|
|
$_.stop()
|
|
return
|
|
}
|
|
|
|
var locator = args[0]
|
|
var parsed = shop.parse_locator(locator)
|
|
|
|
var config = shop.load_config()
|
|
if (!config) {
|
|
log.error("Failed to load cell.toml")
|
|
$_.stop()
|
|
return
|
|
}
|
|
|
|
// Use the module name as the default alias
|
|
var alias = parsed.name
|
|
if (args.length > 1)
|
|
alias = args[1]
|
|
|
|
if (!alias) {
|
|
log.error("Failed to determine alias")
|
|
$_.stop()
|
|
return
|
|
}
|
|
|
|
// Check if already exists
|
|
if (config.dependencies && config.dependencies[alias]) {
|
|
log.console("Dependency '" + alias + "' already exists with version: " + config.dependencies[alias])
|
|
log.console("Use 'cell update " + alias + "' to change version")
|
|
$_.stop()
|
|
return
|
|
}
|
|
|
|
// Add to dependencies
|
|
log.console("Adding dependency: " + alias + " = " + locator)
|
|
shop.add_dependency(alias, locator)
|
|
|
|
// Create module directory
|
|
var module_dir = '.cell/modules/' + alias + '@' + parsed.version
|
|
if (!fd.is_directory(module_dir))
|
|
fd.mkdir(module_dir)
|
|
|
|
// TODO: Actually fetch the module from the repository
|
|
log.console("Module directory created at: " + module_dir)
|
|
|
|
$_.stop() |