adr
Version:
轻量级架构记录工具 - Command-line tools for working with Architecture Decision Records
61 lines • 5.01 kB
JavaScript
let Table = require('table');
import Utils from './utils';
import StatusHelper from './StatusHelper';
import Config from './Config';
import getAdrFiles from './helpers/getAdrFiles';
let path = Config.getSavePath();
let getAllFilesName = function () {
let outputArray = [''];
let files = getAdrFiles();
files.forEach(function (file) {
let fileName = file.relativePath;
let index = Utils.getIndexByString(fileName);
if (index) {
outputArray[index] = fileName;
}
});
return outputArray;
};
function createLogsHeader(allStatus) {
let tableHeader = [];
let currentStatus = allStatus[0];
let splitCurrentStatus = currentStatus.split(' ');
for (let i = 0; i < splitCurrentStatus.length; i++) {
tableHeader.push(' - ');
}
return tableHeader;
}
function createLogsBody(allStatus, tableData) {
for (let i = 0; i < allStatus.length; i++) {
let tableHeader = [];
let currentStatus = allStatus[i];
let splitCurrentStatus = currentStatus.split(' ');
for (let i = 0; i < splitCurrentStatus.length; i++) {
tableHeader.push(splitCurrentStatus[i]);
}
tableData.push(tableHeader);
}
return tableData;
}
export function logs(index) {
let outputArray = getAllFilesName();
let currentFileName = outputArray[index];
if (!currentFileName) {
console.log(`File with index ${index} does not exist.`);
return `File with index ${index} does not exist.`;
}
let filePath = path + currentFileName;
let allStatus = StatusHelper.getAllStatus(filePath);
if (allStatus.length === 0) {
console.log('no status: did .adr.json config has correct config of language??');
return '';
}
let tableData = [];
let tableHeader = createLogsHeader(allStatus);
tableData.push(tableHeader);
createLogsBody(allStatus, tableData);
let output = Table.table(tableData);
console.log(output);
return output;
}
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoibG9ncy5qcyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uLy4uLy4uL3NyYy9saWIvbG9ncy50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiQUFBQSxJQUFJLEtBQUssR0FBRyxPQUFPLENBQUMsT0FBTyxDQUFDLENBQUE7QUFFNUIsT0FBTyxLQUFLLE1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