md-generator
Version:
NPM Package which bootstraps Development by creating all required .md files to meet community standards.
143 lines (142 loc) • 5.77 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
var tslib_1 = require("tslib");
var fs_1 = tslib_1.__importDefault(require("fs"));
var path_1 = tslib_1.__importDefault(require("path"));
var index_1 = require("../../common/index");
var getResolvedPath = function (relativePath) { return path_1.default.resolve(__dirname, relativePath); };
var getArgs = function (args, option) { return args.find(function (item) { return item === option; }); };
var getValues = function (args, resp) { return ({
file: getArgs(args, 'file'),
required: getArgs(args, 'required'),
optional: getArgs(args, 'optional'),
all: getArgs(args, 'all'),
isEmpty: getArgs(args, 'empty'),
resp: resp,
}); };
exports.getValues = getValues;
var checkFileExist = function (relativePath) { return !!fs_1.default.existsSync(relativePath); };
var requiredFiles = {
README: {
name: 'README.md',
exists: checkFileExist('./README.md'),
path: './README.md',
},
LICENSE: {
name: 'LICENSE',
exists: checkFileExist('./LICENSE'),
path: './LICENSE',
},
CODE_OF_CONDUCT: {
name: 'CODE_OF_CONDUCT.md',
exists: checkFileExist('./CODE_OF_CONDUCT.md'),
path: './CODE_OF_CONDUCT.md',
templatePath: getResolvedPath('../../templates/files/required/template-CODE_OF_CONDUCT.md'),
},
PULL_REQUEST_TEMPLATE: {
name: 'PULL_REQUEST_TEMPLATE.md',
exists: checkFileExist('./.github/PULL_REQUEST_TEMPLATE.md'),
path: './.github/PULL_REQUEST_TEMPLATE.md',
templatePath: getResolvedPath('../../templates/files/required/template-PULL_REQUEST_TEMPLATE.md'),
},
BUG_REPORT: {
name: 'bug_report.md',
exists: checkFileExist('./.github/ISSUE_TEMPLATE/bug_report.md'),
path: './.github/ISSUE_TEMPLATE/bug_report.md',
templatePath: getResolvedPath('../../templates/files/required/template-BUG_REPORT.md'),
},
FEATURE_REQUEST: {
name: 'feature_request.md',
exists: checkFileExist('./.github/ISSUE_TEMPLATE/feature_request.md'),
path: './.github/ISSUE_TEMPLATE/feature_request.md',
templatePath: getResolvedPath('../../templates/files/required/template-FEATURE_REQUEST.md'),
},
};
exports.requiredFiles = requiredFiles;
var optionalFiles = {
CHANGELOG: {
name: 'CHANGELOG.md',
exists: checkFileExist('./CHANGELOG.md'),
path: './CHANGELOG.md',
templatePath: getResolvedPath('../../templates/files/optional/template-CHANGELOG.md'),
},
SUPPORT: {
name: 'SUPPORT.md',
exists: checkFileExist('./SUPPORT.md'),
path: './SUPPORT.md',
templatePath: getResolvedPath('../../templates/files/optional/template-SUPPORT.md'),
},
CONTRIBUTORS: {
name: 'CONTRIBUTORS.md',
exists: checkFileExist('./CONTRIBUTORS.md'),
path: './CONTRIBUTORS.md',
templatePath: getResolvedPath('../../templates/files/optional/template-CONTRIBUTORS.md'),
},
AUTHORS: {
name: 'AUTHORS.md',
exists: checkFileExist('./AUTHORS.md'),
path: './AUTHORS.md',
templatePath: getResolvedPath('../../templates/files/optional/template-AUTHORS.md'),
},
ACKNOWLEDGMENTS: {
name: 'ACKNOWLEDGMENTS.md',
exists: checkFileExist('./ACKNOWLEDGMENTS.md'),
path: './ACKNOWLEDGMENTS.md',
templatePath: getResolvedPath('../../templates/files/optional/template-ACKNOWLEDGMENTS.md'),
},
CODEOWNERS: {
name: 'CODEOWNERS.md',
exists: checkFileExist('./CODEOWNERS.md'),
path: './CODEOWNERS.md',
templatePath: getResolvedPath('../../templates/files/optional/template-CODEOWNERS.md'),
},
};
exports.optionalFiles = optionalFiles;
var allFiles = tslib_1.__assign(tslib_1.__assign({}, requiredFiles), optionalFiles);
exports.allFiles = allFiles;
var checkFilesExist = function (data, allMdFiles) {
var foundFiles = [];
var filesNotFound = [];
data.forEach(function (item) {
var newItem = item.split('.')[0].toUpperCase();
var file = Object.keys(allMdFiles).find(function (key) { return key === newItem && allMdFiles[newItem].exists; });
if (file) {
foundFiles.push(file);
}
else {
filesNotFound.push(newItem);
}
});
return { foundFiles: foundFiles, filesNotFound: filesNotFound };
};
exports.checkFilesExist = checkFilesExist;
var removeDotMdAttribute = function (item) {
var newItem = [];
item.forEach(function (key) { return newItem.push(key.split('.')[0].toUpperCase()); });
return newItem;
};
exports.removeDotMdAttribute = removeDotMdAttribute;
var allExistingFiles = function (files) {
if (files === void 0) { files = allFiles; }
return Object.values(files).filter(function (item) { return !!item.exists; });
};
exports.allExistingFiles = allExistingFiles;
var getArrayOfValues = function (files) {
if (files === void 0) { files = allFiles; }
return Object.values(files);
};
exports.getArrayOfValues = getArrayOfValues;
var queryFilesExistence = function (values) {
var args = !values.parent ? values.join(' ') : values.parent.rawArgs[4];
if ((!args || args.length === 0) && values.parent) {
index_1.fileNotDetectedAlert();
process.exit(1);
}
var data = args.split(' ').filter(function (item) { return item.length > 0; });
return checkFilesExist(data, allFiles);
};
exports.queryFilesExistence = queryFilesExistence;
var getItemFromFileName = function (fileName) {
return Object.values(allFiles).find(function (value) { return value.name.toUpperCase().includes(fileName); });
};
exports.getItemFromFileName = getItemFromFileName;