<?php use Client\Client; return array('arg0' => 'key:new', 'command' => 'key:new', 'description' => 'Create a new key to application.', 'run' => function ($args) { $client = new Client(); $key = $client->post("apps/keys"); if (!$args['json']) { echo "App: {$args['app']}" . PHP_EOL; echo "New access token:" . PHP_EOL; echo "{" . PHP_EOL; echo "\tappId: {$key->app_id}" . PHP_EOL; echo "\tkey: {$key->key}" . PHP_EOL; echo "}" . PHP_EOL . PHP_EOL; } return $key; });
} catch (Exception $e) { echo "Failed."; } echo PHP_EOL; } if (isset($options['data']) && $options['data']) { $current_row = 0; $total_rows = count($options['data']); foreach ($options['data'] as $data) { // Look for special data fields foreach ($data as $field => $value) { if (preg_match('/\\!upload ([^$]+)/', $value, $file)) { $filepath = Project::root(Project::DIRECTORY_NAME) . '/seeds/' . $file[1]; // stop when file doens't exists if (!file_exists($filepath)) { throw new Exception("File not found: '{$filepath}'"); } $mime_type = Utils::mime_type($filepath); $data[$field] = 'data:' . $mime_type . ';base64,' . base64_encode(file_get_contents($filepath)); } } $client->post('collection/' . $collection, array('data' => $data)); $current_row += 1; $percent = round($current_row / $total_rows * 100); echo "Seeding '{$collection}': " . "{$percent}%" . str_repeat("\r", strlen($percent) + 1); } } echo PHP_EOL; } echo "Done." . PHP_EOL; });
<?php use Client\Project; use Client\Client; use Client\Console; return array('arg0' => 'app:new', 'command' => 'app:new <application-name>', 'description' => 'Create a new application.', 'run' => function ($args) { if (!$args[1]) { throw new Exception("'application-name' is required."); } $client = new Client(); $app = $client->post('apps', array('app' => array('name' => $args[1]))); // Generate security file $dest = Project::root(Project::DIRECTORY_NAME) . '/'; @mkdir($dest, 0777, true); @mkdir($dest . 'config/', 0777, true); @mkdir($dest . 'credentials/', 0777, true); $default_config_files = array('security.yaml', 'packages.yaml', 'schedule.yaml', 'schema.yaml', 'config/config.yaml', 'config/config.environment.yaml'); foreach ($default_config_files as $config_file) { $dest_file = $dest . $config_file; $template = file_get_contents(__DIR__ . '/../../templates/' . $config_file); // replace environment on file if (preg_match('/\\.environment\\./', $dest_file)) { $dest_file = preg_replace('/\\.(environment)\\./', '.' . Project::getEnvironment() . '.', $dest_file); $template = preg_replace('/{{environment}}/', Project::getEnvironment(), $template); } if (!file_exists($dest_file)) { Console::success('create ' . str_replace(Project::root(), "", $dest_file)); file_put_contents($dest_file, $template); } } if (!$args['json']) {
// compatibility with v0.2.x $config = null; if (file_exists($root_directory . '/config.yaml')) { echo "DEPRECATE WARNING: Please move 'hook-ext/config.yaml' file to 'hook-ext/config/config.yaml'." . PHP_EOL; // TODO: remove on v0.4.x $config = Utils::parse_yaml($root_directory . '/config.yaml'); } else { $config = Utils::parse_yaml($root_directory . '/config/config.yaml'); } // try to read environment-specific configuration $environment_config_file = $root_directory . '/config/config.' . Project::getEnvironment() . '.yaml'; if (file_exists($environment_config_file)) { $environment_config = Utils::parse_yaml($environment_config_file); $config = array_replace_recursive($config, $environment_config); } $stats = $client->post('apps/deploy', array('modules' => $module_sync, 'schema' => Utils::parse_yaml($root_directory . '/schema.yaml'), 'schedule' => $schedule, 'config' => $config, 'security' => Utils::parse_yaml($root_directory . '/security.yaml'), 'packages' => Utils::parse_yaml($root_directory . '/packages.yaml'))); // remove auto-generated PHP files if (count($js_converted_modules) > 0) { foreach ($js_converted_modules as $module) { unlink($module); } } if (isset($stats->error)) { Console::error($stats->error); } if (isset($stats->schedule)) { Console::output("Schedule updated."); } if (isset($stats->schema) && $stats->schema > 0) { Console::output($stats->schema . " collection(s) migrated."); }