UNPKG

@nimbella/postman-api

Version:

Postman Collection to Nimbella Project: Take your APIs seamlessly into Serverless world with this API

85 lines (84 loc) 3.27 kB
"use strict"; /* * 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 mkdirp_1 = require("mkdirp"); const rimraf = tslib_1.__importStar(require("rimraf")); const ncp = tslib_1.__importStar(require("ncp")); const fs_1 = require("fs"); const path_1 = require("path"); const chalk_1 = require("chalk"); const common_gen_1 = require("./stub/common-gen"); const logger_1 = tslib_1.__importDefault(require("../logger")); const writer_1 = require("../writer"); const test_gen_1 = require("./test/test-gen"); class ProjectGenerator { async createDir(base, dir, verbose = true) { const loc = path_1.join(base, dir); try { mkdirp_1.sync(loc); if (verbose) console.log(`${chalk_1.blue('created :')} ${loc}`); } catch (error) { logger_1.default.error(error); console.log(`Couldn't create directory : ${loc}`); } } createProjectYML(base) { try { fs_1.writeFileSync(`${base}/project.yml`, 'packages:'); } catch (error) { logger_1.default.error(error); console.log(`Couldn't create project.yml at ${base}`); } } updateProjectYML(base, content) { try { fs_1.appendFileSync(`${base}/project.yml`, content); } catch (error) { logger_1.default.error(error); console.log(`Couldn't update project.yml at ${base}`); } } generateSkeleton(opts) { const workDir = path_1.join(opts.base, opts.dir); if (!opts.update) { if (fs_1.existsSync(workDir)) { rimraf.sync(workDir); } this.createDir(opts.base, opts.dir); this.createDir(workDir, 'packages'); const templatePath = path_1.join(__dirname, 'stub', 'templates', 'common'); ncp.ncp(templatePath, workDir, err => { if (err) { logger_1.default.error(err); console.log("Couldn't copy the content"); } }); } this.createProjectYML(workDir); opts.generator .getSupportingItems(opts.collection) .forEach((item) => { fs_1.writeFileSync(path_1.join(workDir, item.location), item.content); }); writer_1.writeReadMe(workDir, common_gen_1.getReadMe((opts.collection.description || '').content)); writer_1.writeEnvFile(workDir, test_gen_1.getEnvVars(opts.collection, undefined)); return workDir; } } exports.default = ProjectGenerator;