lib/helper.rb in loom-0.0.43 vs lib/helper.rb in loom-0.0.45
- old
+ new
@@ -50,10 +50,18 @@
# Ensures the SDK that is specified in the config is imported
# into the project
def ensure_sdk_imported!
+ sdk_version = config["sdk_version"]
+
+ say "Checking for sdk #{sdk_version}"
+ if !sdk_installed? sdk_version
+ say "Couldn't find the #{sdk_version} sdk, downloading it'"
+ install_remote_sdk sdk_version
+ end
+
# if the sdk artifacts are already here then we don't need to
# do anything
return if(File.exists?("LoomDemo.app") && File.directory?("bin"))
say "Pulling in sdk files..."
@@ -107,11 +115,11 @@
def configure_directory(dir)
say "Configuring Project..."
loom_config = {
- :sdk_version => "0.0.1"
+ :sdk_version => "cocos"
}
config_path = ""
if dir.length > 0
@@ -207,19 +215,65 @@
end
exit(0)
end
+def install_remote_sdk(sdk_version)
+ sdk_path = File.join(LOOM_DIR, "sdks", sdk_version)
+ say "Downloading remote loom SDK..."
+ temp_file = download_sdk(sdk_version)
+ say "Installing remote loom SDK..."
+ unzip_file(temp_file, sdk_path)
+ File.delete(temp_file)
+ say_tab 1, "SDK installed. You can type 'loom use #{sdk_version}' in the future to use this SDK."
+end
+
+def get_default_sdk
+ get_global_config("default_sdk")
+end
+
+def set_default_sdk(sdk_version)
+ set_global_config("default_sdk", sdk_version)
+ say "Default SDK set to #{sdk_version}"
+end
+
+def installed_sdks
+
+ sdks = Array.new
+
+ Dir.foreach(File.join(LOOM_DIR, "sdks")) do |sdk|
+ is_directory = File.directory?(File.join(LOOM_DIR, "sdks", sdk))
+
+ if is_directory && sdk != "." && sdk != ".."
+ sdks << sdk
+ end
+ end
+
+ return sdks
+end
+
def sdk_installed?(version)
File.directory?(File.join(LOOM_DIR, "sdks", version))
end
+def get_local_config(key)
+ ensure_configured!
+
+ loom_config = Loom::Config.load CONFIG_PATH
+ loom_config[key]
+end
+
def set_local_config(key, value)
ensure_configured!
loom_config = Loom::Config.load CONFIG_PATH
loom_config[key] = value
loom_config.save! CONFIG_PATH
+end
+
+def get_global_config(key)
+ loom_config = Loom::Config.load GLOBAL_CONFIG_PATH
+ loom_config[key]
end
def set_global_config(key, value)
loom_config = Loom::Config.load GLOBAL_CONFIG_PATH
loom_config[key] = value
\ No newline at end of file