Create a formula for the given library name

Parameters

  • string $name the library name or full path to the plugin

Returns

boolean

Source

						public function formulate($name = null) {
		if (!$name) {
			$name = $this->in("please supply a name");
		}
		$result = false;
		$path = $this->_toPath($name);
		$name = basename($path);
		$formula = "{$path}/config/{$name}.json";

		$data = array();

		if (file_exists($formula)) {
			$data = json_decode(file_get_contents($formula), true);
		}
		if (empty($data['version'])) {
			$data['version'] = $this->in("please supply a version");
		}
		if (empty($data['summary'])) {
			$data['summary'] = $this->in("please supply a summary");
		}
		if (file_exists($path) && !file_exists($formula)) {
			$defaults = array(
				'name' => $name, 'version' => '0.1',
				'summary' => "a plugin called {$name}",
				'maintainers' => array(array(
					'name' => '', 'email' => '', 'website' => ''
				)),
				'sources' => array("http://{$this->server}/lab/download/{$name}.phar.gz"),
				'commands' => array(
					'install' => array(), 'update' => array(), 'remove' => array()
				),
				'requires' => array()
			);
			$data += $defaults;

			if (!is_dir(dirname($formula)) && !mkdir(dirname($formula), 0755, true)) {
				$this->error("Formula for {$name} not created in {$path}");
				return false;
			}
		}
		if (is_dir(dirname($formula)) && file_put_contents($formula, json_encode($data))) {
			$this->out("Formula for {$name} created in {$path}.");
			return true;
		}
		$this->error("Formula for {$name} not created in {$path}");
		return false;
	}