@nimbella/postman-api
Version:
Postman Collection to Nimbella Project: Take your APIs seamlessly into Serverless world with this API
55 lines (54 loc) • 2.19 kB
JavaScript
;
/*
* Copyright (c) 2019 - present Nimbella Corp.
*
* This file is licensed to you under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. You may obtain a copy
* of the License at http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software distributed under
* the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
* OF ANY KIND, either express or implied. See the License for the specific language
* governing permissions and limitations under the License.
*/
Object.defineProperty(exports, "__esModule", { value: true });
const tslib_1 = require("tslib");
const fs_1 = require("fs");
const path_1 = require("path");
const handlebars_1 = require("handlebars");
const utils_1 = require("../../utils");
const base_gen_1 = tslib_1.__importDefault(require("./base-gen"));
class JsGenerator extends base_gen_1.default {
constructor() {
super('js');
this.eslintStub = fs_1.readFileSync(path_1.join(this.tmplPath, 'eslint.hbs'));
this.tmplEslint = handlebars_1.compile(this.eslintStub.toString());
this.packageStub = fs_1.readFileSync(path_1.join(this.tmplPath, 'package.hbs'));
this.tmplPackage = handlebars_1.compile(this.packageStub.toString());
}
getSupportingItems(collection) {
const name = utils_1.sanitizeFileName(collection.name || '');
const desc = (collection.description || '').content;
const re = new RegExp(/^(.*?)[.?!]\s/);
const shortDesc = re.exec(desc);
const params = {
name,
description: shortDesc ? shortDesc[0] : '',
};
return [
{
location: '.gitignore',
content: this.tmplGitignore(collection),
},
{
location: '.eslintrc.json',
content: this.tmplEslint(this),
},
{
location: 'package.json',
content: this.tmplPackage(Object.assign({}, params)),
},
];
}
}
exports.default = JsGenerator;