Esempio n. 1
0
<?php

use Client\Client;
use Client\Project;
return array('arg0' => 'keys', 'command' => 'keys', 'description' => 'List all application keys.', 'run' => function ($args) {
    $client = new Client();
    $keys = $client->get("apps/keys");
    $project = Project::getConfig();
    if (!$args['json']) {
        echo "Application name: {$project['name']}" . PHP_EOL;
        echo "Application keys:" . PHP_EOL;
        foreach ($keys as $key) {
            echo "{" . PHP_EOL;
            echo "\tapp_id: {$key->app_id}" . PHP_EOL;
            echo "\tkey: " . $key->key . PHP_EOL;
            echo "\ttype: " . $key->type . PHP_EOL;
            echo "}" . PHP_EOL;
        }
        if (count($keys) > 0) {
        }
    }
    return $keys;
});
Esempio n. 2
0
<?php

use Client\Client;
use Client\Project;
use Client\Console;
return array('arg0' => 'generate:schema', 'command' => 'generate:schema', 'description' => 'Generate schema definition config.', 'run' => function ($args) use($commands) {
    $dest = Project::root(Project::DIRECTORY_NAME) . '/schema.yaml';
    @mkdir(dirname($dest), 0777, true);
    $client = new Client();
    $client->setRaiseExceptions(false);
    $cached_schema = $client->get('apps/schema');
    $yaml = new Symfony\Component\Yaml\Dumper();
    if (file_exists($dest)) {
        Console::output("You already have a schema.yaml file.\n" . "Your changes will be lost.\n" . "Overwrite? [y/n]");
        $overwrite = Console::readline() == 'y';
        if (!$overwrite) {
            throw new Exception("Aborted.");
        }
    }
    // format schema dump before save
    $schema_dump = "";
    if (!empty($cached_schema)) {
        $schema_dump = str_replace('  ', ' ', $yaml->dump(json_decode(json_encode($cached_schema), true), 3));
        $schema_dump = preg_replace('/^([a-z0-9_]+):\\n/m', "\n\$0", $schema_dump);
    }
    file_put_contents($dest, $schema_dump . file_get_contents(__DIR__ . '/../../templates/schema.yaml'));
    echo "Schema dumped at '{$dest}'." . PHP_EOL;
    if ($editor = getenv('EDITOR')) {
        $descriptors = array(array('file', '/dev/tty', 'r'), array('file', '/dev/tty', 'w'), array('file', '/dev/tty', 'w'));
        $process = proc_open("{$editor} {$dest}", $descriptors, $pipes);
    }
Esempio n. 3
0
<?php

use Client\Client;
use Client\Project;
use Client\Console;
return array('arg0' => 'modules', 'command' => 'modules', 'description' => 'List all application modules', 'run' => function ($args) {
    $client = new Client();
    $modules = $client->get("apps/modules");
    if (!$args['json']) {
        if ($modules) {
            echo "Modules: " . PHP_EOL;
            foreach ($modules as $module) {
                echo "\t'{$module->name}' ({$module->type}) - LoC: " . substr_count($module->code, "\n") . PHP_EOL;
            }
        } else {
            $project = Project::getConfig();
            echo "No modules found for: '{$project['name']}'." . PHP_EOL;
        }
    }
    return $modules;
});
Esempio n. 4
0
<?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']) {
Esempio n. 5
0
<?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;
});
Esempio n. 6
0
<?php

use Client\Client;
use Client\Project;
use Client\Console;
use Symfony\Component\Yaml\Yaml;
return array('arg0' => 'config', 'command' => 'config', 'description' => 'List all app configurations', 'run' => function ($args) {
    $client = new Client();
    $configs = $client->get("apps/configs");
    $project = Project::getConfig();
    if (!$args['json']) {
        foreach ($project as $key => $value) {
            Console::output($key . ': ' . $value);
        }
        Console::output(str_repeat('-', 37));
        if ($configs) {
            print Yaml::dump(json_decode(json_encode($configs), true), PHP_INT_MAX);
        } else {
            Console::output("No configurations found for: '{$project['name']}'.");
        }
    }
    return $configs;
});
Esempio n. 7
0
<?php

use Client\Utils;
use Client\Client;
use Client\Project;
use Client\Console;
return array('arg0' => 'db:seed', 'command' => 'db:seed [<seed-file>]', 'description' => 'Seed collections from YAML files.', 'run' => function ($args) use($commands) {
    $seed_file = '*.yaml';
    if ($args[1] !== null) {
        $seed_file = $args[1] . '.yaml';
    }
    $client = new Client();
    foreach (Utils::glob(Project::root(Project::DIRECTORY_NAME) . '/seeds/' . $seed_file) as $yaml_file) {
        $collection = basename($yaml_file, '.yaml');
        $parser = new Symfony\Component\Yaml\Parser();
        $options = $parser->parse(file_get_contents($yaml_file));
        if (isset($options['truncate']) && $options['truncate']) {
            echo "Truncating '{$collection}'... ";
            try {
                $truncate = $client->delete('collection/' . $collection);
                if (count($truncate) > 0) {
                    echo "Success.";
                }
            } catch (Exception $e) {
                echo "Failed.";
            }
            echo PHP_EOL;
        }
        if (isset($options['data']) && $options['data']) {
            $current_row = 0;
            $total_rows = count($options['data']);
Esempio n. 8
0
return array('arg0' => 'logs', 'command' => 'logs', 'description' => 'Get app back-end logs.', 'run' => function ($cli) {
    $url = "apps/logs";
    $data = array();
    //
    // TODO: http stream not working properly
    //
    // if ($cli['tail']) {
    // 	$data['tail'] = 1;
    // }
    if ($cli['n']) {
        $data['n'] = $cli['n'];
    }
    if (!empty($data)) {
        $url .= '?' . urlencode(json_encode($data));
    }
    $client = new Client();
    // $request = $client->request('get', $url);
    $response = $client->request('get', $url);
    echo $response->text;
    // if ($cli['tail']) {
    // 	// read from stream
    // 	$factory = new \Guzzle\Stream\PhpStreamRequestFactory();
    // 	$stream = $factory->fromRequest($request);
    //
    // 	while (!$stream->feof()) {
    // 		echo $stream->readLine();
    // 	}
    //
    // } else {
    // 	// just output response
    // 	echo $request->send()->getBody(true);
Esempio n. 9
0
<?php

use Client\Client;
use Client\Project;
use Client\Console;
return array('arg0' => 'cache:clear', 'command' => 'cache:clear', 'description' => 'Clear application cache.', 'run' => function ($args) use($commands) {
    $client = new Client();
    $response = $client->delete("apps/cache");
    if ($response->success) {
        Console::output("Cache cleared successfully.");
    } else {
        throw new Exception("Some error ocurred when clearing the cache.");
    }
});
Esempio n. 10
0
<?php

use Client\Console;
use Client\Client;
use Client\Project;
use Client\Utils;
use Carbon\Carbon;
return array('arg0' => 'deploy', 'command' => 'deploy', 'description' => 'Deploy ext directory.', 'run' => function ($args) use($commands) {
    $client = new Client();
    Console::loading_output("Retrieving remote data...");
    $deployed = $client->get('apps/deploy');
    $root_directory = Project::root(Project::DIRECTORY_NAME);
    $js_converted_modules = array();
    // modules
    $local_modules = array();
    $module_types = array('observers', 'routes', 'templates', 'channels');
    foreach ($module_types as $module_type) {
        foreach (Utils::glob($root_directory . '/' . $module_type . '/*') as $module) {
            if (!is_file($module)) {
                continue;
            }
            $extension = pathinfo($module, PATHINFO_EXTENSION);
            if ($extension == "js") {
                $javascript_module = $module;
                $module = preg_replace('/\\.js$/', '.php', $module);
                array_push($js_converted_modules, $module);
                // keep track for removal
                // module may already exists due error on previous upload.
                // ask user to prevent overwriting some manually added .php file
                if (file_exists($module)) {
                    Console::output("Module '" . basename($module) . "' already exists.\nDo you want to overwrite with converted '" . basename($javascript_module) . "' version?\n(y/n)");