Esempio n. 1
0
var ExampleCommand = /** @class */ (function (_super) {
    __extends(ExampleCommand, _super);
    function ExampleCommand() {
        return _super !== null && _super.apply(this, arguments) || this;
    }
    ExampleCommand.prototype.run = function () {
        return __awaiter(this, void 0, void 0, function () {
            var _a;
            return __generator(this, function (_b) {
                _a = this.flags;
                return [2 /*return*/];
            });
        });
    };
    ExampleCommand.topic = 'example';
    ExampleCommand.command = 'command';
    ExampleCommand.description = 'example command';
    ExampleCommand.flags = {
        stage: prisma_cli_engine_1.flags.string({
            char: 't',
            description: 'Target name',
            defaultValue: 'dev',
        }),
    };
    return ExampleCommand;
}(prisma_cli_engine_1.Command));
Esempio n. 2
0
var Login = /** @class */ (function (_super) {
    __extends(Login, _super);
    function Login() {
        return _super !== null && _super.apply(this, arguments) || this;
    }
    Login.prototype.run = function () {
        return __awaiter(this, void 0, void 0, function () {
            var key;
            return __generator(this, function (_a) {
                switch (_a.label) {
                    case 0:
                        key = this.flags.key;
                        return [4 /*yield*/, this.client.login(key)];
                    case 1:
                        _a.sent();
                        return [2 /*return*/];
                }
            });
        });
    };
    Login.topic = 'login';
    Login.description = 'Login or signup to the Prisma Cloud';
    Login.flags = {
        key: prisma_cli_engine_1.flags.string({
            char: 'k',
            description: 'Cloud session key',
        }),
    };
    return Login;
}(prisma_cli_engine_1.Command));
Esempio n. 3
0
var Seed = /** @class */ (function (_super) {
    __extends(Seed, _super);
    function Seed() {
        return _super !== null && _super.apply(this, arguments) || this;
    }
    Seed.prototype.run = function () {
        return __awaiter(this, void 0, void 0, function () {
            var _a, stage, reset, serviceName, clusterName, cluster, seeder;
            return __generator(this, function (_b) {
                switch (_b.label) {
                    case 0:
                        _a = this.flags, stage = _a.stage, reset = _a.reset;
                        return [4 /*yield*/, this.definition.load(this.flags)];
                    case 1:
                        _b.sent();
                        serviceName = this.definition.definition.service;
                        clusterName = this.definition.getClusterName();
                        cluster = this.env.clusterByName(clusterName, true);
                        this.env.setActiveCluster(cluster);
                        seeder = new Seeder_1.Seeder(this.definition, this.client, this.out, this.config);
                        return [4 /*yield*/, seeder.seed(serviceName, stage, reset)];
                    case 2:
                        _b.sent();
                        return [2 /*return*/];
                }
            });
        });
    };
    Seed.topic = 'seed';
    Seed.description = 'Seed a service with data';
    Seed.flags = {
        stage: prisma_cli_engine_1.flags.string({
            char: 's',
            description: 'Stage name',
            defaultValue: 'dev',
        }),
        reset: prisma_cli_engine_1.flags.boolean({
            char: 'r',
            description: 'Reset the service before seeding',
        }),
    };
    return Seed;
}(prisma_cli_engine_1.Command));
Esempio n. 4
0
var ClusterToken = /** @class */ (function (_super) {
    __extends(ClusterToken, _super);
    function ClusterToken() {
        return _super !== null && _super.apply(this, arguments) || this;
    }
    ClusterToken.prototype.run = function () {
        return __awaiter(this, void 0, void 0, function () {
            var copy, serviceName, stage, clusterName, cluster, token;
            return __generator(this, function (_a) {
                switch (_a.label) {
                    case 0:
                        copy = this.flags.copy;
                        return [4 /*yield*/, this.definition.load(this.flags)];
                    case 1:
                        _a.sent();
                        serviceName = this.definition.definition.service;
                        stage = this.definition.definition.stage;
                        clusterName = this.definition.getClusterName();
                        cluster = this.env.clusterByName(clusterName, true);
                        if (!clusterName) {
                            throw new Error("Please provide a cluster in your prisma.yml");
                        }
                        return [4 /*yield*/, cluster.getToken(serviceName, this.definition.getWorkspace() || undefined, stage)];
                    case 2:
                        token = _a.sent();
                        if (!copy) return [3 /*break*/, 4];
                        return [4 /*yield*/, new Promise(function (r) {
                                ncp.copy(token, function () { return r(); });
                            })];
                    case 3:
                        _a.sent();
                        this.out.log("Token copied to clipboard");
                        return [3 /*break*/, 5];
                    case 4:
                        this.out.log(token);
                        _a.label = 5;
                    case 5: return [2 /*return*/];
                }
            });
        });
    };
    ClusterToken.topic = 'cluster-token';
    ClusterToken.description = 'Create a new cluster token';
    ClusterToken.flags = {
        copy: prisma_cli_engine_1.flags.boolean({
            char: 'c',
            description: 'Copy token to clipboard',
        }),
    };
    return ClusterToken;
}(prisma_cli_engine_1.Command));
Esempio n. 5
0
var Logs = /** @class */ (function (_super) {
    __extends(Logs, _super);
    function Logs() {
        return _super !== null && _super.apply(this, arguments) || this;
    }
    Logs.prototype.run = function () {
        return __awaiter(this, void 0, void 0, function () {
            var docker;
            return __generator(this, function (_a) {
                switch (_a.label) {
                    case 0:
                        docker = new Docker_1.default(this.out, this.config, this.env, this.flags.name);
                        return [4 /*yield*/, docker.init()];
                    case 1:
                        _a.sent();
                        return [4 /*yield*/, docker.logs()];
                    case 2:
                        _a.sent();
                        return [2 /*return*/];
                }
            });
        });
    };
    Logs.topic = 'local';
    Logs.command = 'logs';
    Logs.description = 'Print cluster logs';
    Logs.group = 'local';
    Logs.hidden = true;
    Logs.flags = {
        name: prisma_cli_engine_1.flags.string({
            char: 'n',
            description: 'Name of the cluster instance',
            defaultValue: 'local',
        }),
    };
    return Logs;
}(prisma_cli_engine_1.Command));
Esempio n. 6
0
var Playground = /** @class */ (function (_super) {
    __extends(Playground, _super);
    function Playground() {
        return _super !== null && _super.apply(this, arguments) || this;
    }
    Playground.prototype.run = function () {
        return __awaiter(this, void 0, void 0, function () {
            var web, envFile, serviceName, stage, clusterName, cluster, graphqlBin, localPlaygroundPath, endpoint, envPath, url;
            return __generator(this, function (_a) {
                switch (_a.label) {
                    case 0:
                        web = this.flags.web;
                        envFile = this.flags['env-file'];
                        return [4 /*yield*/, this.definition.load(this.flags, envFile)];
                    case 1:
                        _a.sent();
                        serviceName = this.definition.definition.service;
                        stage = this.definition.definition.stage;
                        clusterName = this.definition.getClusterName();
                        cluster = this.env.clusterByName(clusterName, true);
                        this.env.setActiveCluster(cluster);
                        if (!(this.config.findConfigDir() === this.config.definitionDir)) return [3 /*break*/, 4];
                        return [4 /*yield*/, getGraphQLCliBin_1.default()];
                    case 2:
                        graphqlBin = _a.sent();
                        debug({ graphqlBin: graphqlBin });
                        this.out.log("Running " + chalk_1.default.cyan("$ graphql playground") + "...");
                        return [4 /*yield*/, spawn_1.spawn(graphqlBin, ['playground'])];
                    case 3:
                        _a.sent();
                        return [3 /*break*/, 5];
                    case 4:
                        localPlaygroundPath = "/Applications/GraphQL Playground.app/Contents/MacOS/GraphQL Playground";
                        endpoint = cluster.getApiEndpoint(this.definition.definition.service, stage, this.definition.getWorkspace() || undefined);
                        if (fs.pathExistsSync(localPlaygroundPath) && !web) {
                            envPath = path.join(os.tmpdir(), randomString() + ".json");
                            fs.writeFileSync(envPath, JSON.stringify(process.env));
                            url = "graphql-playground://?cwd=" + process.cwd() + "&envPath=" + envPath + "&endpoint=" + endpoint;
                            opn(url, { wait: false });
                            debug(url);
                            debug(process.env);
                        }
                        else {
                            opn(endpoint);
                        }
                        _a.label = 5;
                    case 5: return [2 /*return*/];
                }
            });
        });
    };
    Playground.topic = 'playground';
    Playground.description = 'Open service endpoints in GraphQL Playground';
    Playground.group = 'general';
    Playground.flags = (_a = {
            web: prisma_cli_engine_1.flags.boolean({
                char: 'w',
                description: 'Force open web playground',
            })
        },
        _a['env-file'] = prisma_cli_engine_1.flags.string({
            description: 'Path to .env file to inject env vars',
            char: 'e',
        }),
        _a);
    return Playground;
}(prisma_cli_engine_1.Command));
Esempio n. 7
0
var Reset = /** @class */ (function (_super) {
    __extends(Reset, _super);
    function Reset() {
        return _super !== null && _super.apply(this, arguments) || this;
    }
    Reset.prototype.run = function () {
        return __awaiter(this, void 0, void 0, function () {
            var force, envFile, serviceName, stage, clusterName, cluster;
            return __generator(this, function (_a) {
                switch (_a.label) {
                    case 0:
                        force = this.flags.force;
                        envFile = this.flags['env-file'];
                        return [4 /*yield*/, this.definition.load(this.flags, envFile)];
                    case 1:
                        _a.sent();
                        serviceName = this.definition.definition.service;
                        stage = this.definition.definition.stage;
                        clusterName = this.definition.getClusterName();
                        cluster = this.env.clusterByName(clusterName, true);
                        this.env.setActiveCluster(cluster);
                        if (!!force) return [3 /*break*/, 3];
                        return [4 /*yield*/, this.askForConfirmation(serviceName, stage)];
                    case 2:
                        _a.sent();
                        _a.label = 3;
                    case 3: return [4 /*yield*/, this.reset(serviceName, stage)];
                    case 4:
                        _a.sent();
                        return [2 /*return*/];
                }
            });
        });
    };
    Reset.prototype.reset = function (serviceName, stageName) {
        return __awaiter(this, void 0, void 0, function () {
            var before;
            return __generator(this, function (_a) {
                switch (_a.label) {
                    case 0:
                        before = Date.now();
                        this.out.action.start("Resetting " + chalk_1.default.bold(serviceName + "@" + stageName));
                        return [4 /*yield*/, this.client.reset(serviceName, stageName, this.definition.getToken(serviceName, stageName), this.definition.getWorkspace() || undefined)];
                    case 1:
                        _a.sent();
                        this.out.action.stop(chalk_1.default.cyan(Date.now() - before + "ms"));
                        return [2 /*return*/];
                }
            });
        });
    };
    Reset.prototype.askForConfirmation = function (serviceName, stage) {
        return __awaiter(this, void 0, void 0, function () {
            var confirmationQuestion, confirmation;
            return __generator(this, function (_a) {
                switch (_a.label) {
                    case 0:
                        confirmationQuestion = {
                            name: 'confirmation',
                            type: 'input',
                            message: "Are you sure that you want to reset the data of " + chalk_1.default.bold(serviceName) + " in stage " + chalk_1.default.bold(stage) + "? y/N",
                            default: 'n',
                        };
                        return [4 /*yield*/, this.out.prompt(confirmationQuestion)];
                    case 1:
                        confirmation = (_a.sent()).confirmation;
                        if (confirmation.toLowerCase().startsWith('n')) {
                            this.out.exit(0);
                        }
                        return [2 /*return*/];
                }
            });
        });
    };
    Reset.topic = 'reset';
    Reset.description = 'Reset the stage data';
    Reset.group = 'general';
    Reset.flags = (_a = {
            force: prisma_cli_engine_1.flags.boolean({
                char: 'f',
                description: 'Force reset data without confirmation',
            })
        },
        _a['env-file'] = prisma_cli_engine_1.flags.string({
            description: 'Path to .env file to inject env vars',
            char: 'e',
        }),
        _a);
    return Reset;
}(prisma_cli_engine_1.Command));
Esempio n. 8
0
var Export = /** @class */ (function (_super) {
    __extends(Export, _super);
    function Export() {
        return _super !== null && _super.apply(this, arguments) || this;
    }
    Export.prototype.run = function () {
        return __awaiter(this, void 0, void 0, function () {
            var exportPath, envFile, serviceName, stage, clusterName, cluster, importCommand;
            return __generator(this, function (_a) {
                switch (_a.label) {
                    case 0:
                        exportPath = this.flags['path'] || "export-" + new Date().toISOString() + ".zip";
                        if (!exportPath.endsWith('.zip')) {
                            throw new Error("export-path must point to a .zip file");
                        }
                        envFile = this.flags['env-file'];
                        return [4 /*yield*/, this.definition.load(this.flags, envFile)];
                    case 1:
                        _a.sent();
                        serviceName = this.definition.definition.service;
                        stage = this.definition.definition.stage;
                        clusterName = this.definition.getClusterName();
                        cluster = this.env.clusterByName(clusterName, true);
                        this.env.setActiveCluster(cluster);
                        return [4 /*yield*/, this.export(serviceName, stage, exportPath, this.definition.getToken(serviceName, stage), this.definition.getWorkspace() || undefined)];
                    case 2:
                        _a.sent();
                        importCommand = chalk_1.default.green.bold("$ prisma import --data " + exportPath);
                        this.out.log("Exported service to " + chalk_1.default.bold(exportPath) + "\nYou can import it to a new service with\n  " + importCommand);
                        return [2 /*return*/];
                }
            });
        });
    };
    Export.prototype.export = function (serviceName, stage, exportPath, token, workspaceSlug) {
        return __awaiter(this, void 0, void 0, function () {
            var exporter;
            return __generator(this, function (_a) {
                switch (_a.label) {
                    case 0:
                        exporter = new Exporter_1.Exporter(exportPath, this.client, this.out, this.config);
                        return [4 /*yield*/, exporter.download(serviceName, stage, token, workspaceSlug)];
                    case 1:
                        _a.sent();
                        return [2 /*return*/];
                }
            });
        });
    };
    Export.topic = 'export';
    Export.description = 'Export service data to local file';
    Export.group = 'data';
    Export.flags = (_a = {},
        _a['path'] = prisma_cli_engine_1.flags.string({
            char: 'p',
            description: 'Path to export .zip file',
        }),
        _a['env-file'] = prisma_cli_engine_1.flags.string({
            description: 'Path to .env file to inject env vars',
            char: 'e',
        }),
        _a);
    return Export;
}(prisma_cli_engine_1.Command));