added user info
parent
6bb0f6ad05
commit
a180505a8c
19
README.md
19
README.md
|
@ -1,3 +1,20 @@
|
|||
# API-CLI
|
||||
|
||||
A commandline interface for generating and linting apibuilder-based api-specs.
|
||||
A commandline interface for generating and linting apibuilder-based api-specs.
|
||||
|
||||
# Installation
|
||||
|
||||
<code>npm install -g @nclazz/api-cli</code>
|
||||
|
||||
# Generate a new service
|
||||
|
||||
Generating is a new service spec is easily done with the <code>generate</code> command.
|
||||
|
||||
i.e.:
|
||||
|
||||
<code>api-cli generate --name=myservice --description="My Service description" --silent</code>
|
||||
|
||||
As a template a default template will be used. The template can be overridden either by specifying it as a parameter
|
||||
<code>--template=<path-to-template></code> or by creating a template json file in <code>~/.api/templates/default.json</code>
|
||||
|
||||
If the parameter <code>--silent</code> is not given an interactive prompt will lead through the generation process.
|
||||
|
|
|
@ -2,24 +2,37 @@ const path = require('path');
|
|||
const fs = require('fs');
|
||||
const linter = require('./linter');
|
||||
const prompt = require('./prompt');
|
||||
const { toNamespacedPath } = require('path');
|
||||
const os = require('os')
|
||||
|
||||
const it_root_questions = [
|
||||
{ question: 'Service name', name: 'name', validator: linter.regex.NAME_REGEX, error: "Name must only contain lowercase letters, numbers or '-_'!" },
|
||||
{ question: 'Service description', name: 'description', validator: linter.regex.DESCRIPTION_REGEX, error: "Description must be a descriptive sentence starting with a uppercase letter and ending with a '.'!" },
|
||||
{ question: 'Template', name: 'template', default: defaultTemplatePath},
|
||||
{ question: 'Output', name: 'output', default: results => defaultOutputPath(results.name) },
|
||||
{ question: 'Namespace', name: 'namespace' },
|
||||
{ question: 'Base URL', name: 'base_url'}
|
||||
];
|
||||
|
||||
function userTemplatePath(name) {
|
||||
let templatePath = path.join(os.homedir(), '.api', 'templates', name)
|
||||
if(fs.existsSync(templatePath)) {
|
||||
return templatePath;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
function defaultTemplatePath() {
|
||||
return path.join(__dirname, '..', 'templates', 'default.json');
|
||||
return userTemplatePath('default.json') || path.join(__dirname, '..', 'templates', 'default.json')
|
||||
}
|
||||
|
||||
function defaultOutputPath(name) {
|
||||
return path.join(process.cwd(), `${name}.json`)
|
||||
}
|
||||
|
||||
|
||||
function doInteractiveGeneration(args) {
|
||||
prompt.start([
|
||||
{ question: 'Service name', name: 'name', validator: linter.regex.NAME_REGEX, error: "Name must only contain lowercase letters, numbers or '-_'!" },
|
||||
{ question: 'Service description', name: 'description', validator: linter.regex.DESCRIPTION_REGEX, error: "Description must be a descriptive sentence starting with a uppercase letter and ending with a '.'!" },
|
||||
{ question: 'Template', name: 'template', default: defaultTemplatePath},
|
||||
{ question: 'Output', name: 'output', default: results => defaultOutputPath(results.name) },
|
||||
{ question: 'Namespace', name: 'namespace' },
|
||||
{ question: 'Base URL', name: 'base_url'}
|
||||
...it_root_questions
|
||||
], results => {
|
||||
generateTemplate(results);
|
||||
});
|
||||
|
@ -34,6 +47,7 @@ function doSilentGeneration(args) {
|
|||
config.output = args.output || defaultOutputPath(args.name)
|
||||
config.namespace = args.namespace || undefined
|
||||
config.base_url = args.base_url || undefined
|
||||
config.info = userTemplatePath('info.json') || undefined
|
||||
|
||||
generateTemplate(config);
|
||||
}
|
||||
|
@ -47,6 +61,10 @@ function generateTemplate(config) {
|
|||
template.namespace = config.namespace
|
||||
template.base_url = config.base_url
|
||||
|
||||
if(config.info) {
|
||||
template.info = require(config.info)
|
||||
}
|
||||
|
||||
let messages = linter.lint(template);
|
||||
if(messages.length) {
|
||||
console.error("Failed to generate service spec:");
|
||||
|
|
|
@ -1,13 +1,7 @@
|
|||
{
|
||||
"name": "",
|
||||
"description": "Common resources to be implemented by all other services. This spec can be used as a template for other services.",
|
||||
"info": {
|
||||
"contact": {
|
||||
"name": "Niclas Thobaben",
|
||||
"email": "info@nclazz.de",
|
||||
"url": "nclazz.de"
|
||||
}
|
||||
},
|
||||
"info": {},
|
||||
"imports": [],
|
||||
"headers": [],
|
||||
"enums": {},
|
||||
|
|
Loading…
Reference in New Issue