md-generator
Version:
NPM Package which bootstraps Development by creating all required .md files to meet community standards.
73 lines (72 loc) • 3.85 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
var tslib_1 = require("tslib");
var inquirer_1 = tslib_1.__importDefault(require("inquirer"));
var lodash_1 = require("lodash");
var index_1 = require("./setupQuestions/index");
var utils = tslib_1.__importStar(require("../../projectEnv/utils"));
var projectInfo_1 = tslib_1.__importDefault(require("../../projectEnv/projectInfo"));
exports.find = function (files, item) { return files.find(function (element) { return element === item; }); };
exports.getAppropriateQuestion = function (files) {
var readmeQstn = exports.find(files, 'README') ? index_1.readmeQuestions : null;
var licenseQstn = exports.find(files, 'LICENSE') ? index_1.licenseQuestions : null;
var codeOfConductQstn = exports.find(files, 'CODE_OF_CONDUCT')
? index_1.codeOfConductQuestions
: null;
return readmeQstn || licenseQstn || codeOfConductQstn;
};
var askQuestions = function (projectInfos, useDefaultAnswers, filesToBeCreated) { return tslib_1.__awaiter(void 0, void 0, void 0, function () {
var filteredQuestions, getQuestions, ask, question, answersContext, _a, isGithubRepos, repositoryUrl;
return tslib_1.__generator(this, function (_b) {
switch (_b.label) {
case 0:
filteredQuestions = exports.getAppropriateQuestion(filesToBeCreated);
getQuestions = function (questions) {
return lodash_1.flatMap(Object.values(questions), function (questionBuilder) { return questionBuilder(projectInfos); });
};
ask = function (questions) { return tslib_1.__awaiter(void 0, void 0, void 0, function () {
var data;
return tslib_1.__generator(this, function (_a) {
switch (_a.label) {
case 0:
if (!questions) return [3, 2];
return [4, inquirer_1.default.prompt(questions)];
case 1:
data = _a.sent();
return [2, data];
case 2: return [2, utils.getDefaultAnswers(getQuestions(index_1.readmeQuestions))];
}
});
}); };
question = filteredQuestions ? getQuestions(filteredQuestions) : null;
if (!useDefaultAnswers) return [3, 1];
_a = utils.getDefaultAnswers(getQuestions(index_1.readmeQuestions));
return [3, 3];
case 1: return [4, ask(question)];
case 2:
_a = _b.sent();
_b.label = 3;
case 3:
answersContext = _a;
isGithubRepos = projectInfos.isGithubRepos, repositoryUrl = projectInfos.repositoryUrl;
return [2, tslib_1.__assign({ isGithubRepos: isGithubRepos,
repositoryUrl: repositoryUrl, projectPrerequisites: undefined, isProjectOnNpm: utils.isProjectAvailableOnNpm(answersContext.projectName) }, answersContext)];
}
});
}); };
exports.askQuestions = askQuestions;
var getInfos = function (useDefaultAnswers, filesToBeCreated) { return tslib_1.__awaiter(void 0, void 0, void 0, function () {
var projectInformations, answersContext;
return tslib_1.__generator(this, function (_a) {
switch (_a.label) {
case 0: return [4, projectInfo_1.default()];
case 1:
projectInformations = _a.sent();
return [4, askQuestions(projectInformations, useDefaultAnswers, filesToBeCreated)];
case 2:
answersContext = _a.sent();
return [2, answersContext];
}
});
}); };
exports.getInfos = getInfos;