jok
Version:
Bundle of utility functions for code generation related to nodejs and graphql
75 lines (74 loc) • 3.13 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
var chalk_1 = require("chalk");
var program = require("commander");
// tslint:enable
var graphql_client_1 = require("./commands/graphql-client");
var init_1 = require("./commands/init");
// tslint:disable
var pkg = require('../package.json');
program
.name('Jok CLI')
.description(pkg.description)
.version(pkg.version);
// init command
program
.command('init <directory-name>')
.description('Initialize new pre-configured project')
.usage("[options] " + chalk_1.default.green('<directory-name>'))
.option('--nextjs', 'with next.js')
.option('--graphql', 'with graphql')
.action(function (name, _a) {
var nextjs = _a.nextjs, graphql = _a.graphql;
(0, init_1.default)({
projectName: name,
nextjs: nextjs,
graphql: graphql,
});
})
.on('--help', function () {
console.log();
console.log('Examples:');
console.log(" " + chalk_1.default.gray('$') + " jok init " + chalk_1.default.green('cool-app'));
console.log(" " + chalk_1.default.gray('$') + " jok init " + chalk_1.default.green('server-app') + " --graphql");
console.log(" " + chalk_1.default.gray('$') + " jok init " + chalk_1.default.green('client-app') + " --nextjs");
console.log();
});
// graphql-client command
program
.command('graphql-client')
.description('Generate graphql client')
.option('-e, --endpointUrl <endpointUrl>', 'graphql endpoint url', /.+/i)
.option('-o, --output <output>', 'result file address', /.+/i)
.option('--defaultFragments', 'generate default fragments')
.option('--useApolloClient3', 'use Apollo Client v3 (otherwise use v2)')
.option('--includeTypeName', 'include __typename in type definitions')
.option('--prefix <prefix>', 'type name prefix')
.option('--postfix <postfix>', 'type name prefix')
.action(function (_a) {
var endpointUrl = _a.endpointUrl, output = _a.output, defaultFragments = _a.defaultFragments, _b = _a.useApolloClient3, useApolloClient3 = _b === void 0 ? false : _b, _c = _a.includeTypeName, includeTypeName = _c === void 0 ? false : _c, _d = _a.prefix, prefix = _d === void 0 ? '' : _d, _e = _a.postfix, postfix = _e === void 0 ? '' : _e;
if (!endpointUrl || !output) {
console.warn(chalk_1.default.red('Missing options') + " please pass --endpointUrl and --output");
return;
}
(0, graphql_client_1.default)({
endpointUrl: endpointUrl,
output: output,
generateDefaultFragments: defaultFragments,
useApolloClientV3: useApolloClient3,
includeTypeName: includeTypeName,
typeNamePrefix: prefix,
typeNamePostfix: postfix,
});
})
.on('--help', function () {
console.log();
console.log('Examples:');
console.log(" " +
(chalk_1.default.gray('$') + " jok graphql-client ") +
("-e " + chalk_1.default.green('https://server.jok.io') + " ") +
("-o " + chalk_1.default.green('src/generated/graph.ts')));
console.log();
});
program.parse(process.argv);