@ptkdev/all-shields-cli
Version:
Tool to help automate your badges of shields.io, badgen.net, fury.io, github action and snyk.io from .all-shieldsrc dotfile for your markdown files. You can use Liquid variables like {{name}} or {{version}} which refer to your package.json. Inspired by al
92 lines • 3.19 kB
JavaScript
;
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.mergeDotFiles = exports.readDotFiles = void 0;
/**
* Read and Merge dotfiles
* =====================
*
* Manage package.json and all-shields-cli rc dotfile
*
* @contributors: Patryk Rzucidło [@ptkdev] <support@ptkdev.io> (https://ptk.dev)
*
* @license: MIT License
*
*/
const fs_1 = __importDefault(require("fs"));
const util_1 = __importDefault(require("util"));
const nunjucks_1 = __importDefault(require("./nunjucks"));
const readFile = util_1.default.promisify(fs_1.default.readFile);
/**
* readDotFiles
* =====================
*
* Gets package.json and all-shields-cli rc dotfile
*
* @return {Promise<ReadDotfilesResponseInterface>} { pkg, rc } - (async) string of package.json and .all-shieldsrc dot file
*
*/
const readDotFiles = () => __awaiter(void 0, void 0, void 0, function* () {
let pkg = "";
let rc = "";
try {
pkg = (yield readFile(`${process.cwd()}/package.json`)).toString();
}
catch (error) {
return { pkg, rc, error };
}
try {
rc = (yield readFile(`${process.cwd()}/.all-shieldsrc`)).toString();
}
catch (error) {
try {
rc = (yield readFile(`${process.cwd()}/.all-shieldsrc.json`)).toString();
}
catch (error) {
return { pkg, rc, error };
}
}
return {
pkg,
rc
};
});
exports.readDotFiles = readDotFiles;
/**
* mergeDotFiles
* =====================
*
* Merge all-shieldsrc liquid variables from package.json keys
*
* @param {ReadDotfilesResponseInterface} pkg - pkg string from package.json
* @param {ReadDotfilesResponseInterface} rc - rc string from .all-shieldsrc
*
* @return {Promise<MergeDotfilesResponseInterface>} { json, error } - (async) merge string of package.json and .all-shieldsrc dot file
*
*/
const mergeDotFiles = ({ pkg, rc }) => __awaiter(void 0, void 0, void 0, function* () {
let json = "";
try {
json = JSON.parse(nunjucks_1.default.nunjucks.renderString(rc, JSON.parse(pkg)));
}
catch (error) {
return { json, error };
}
return {
json
};
});
exports.mergeDotFiles = mergeDotFiles;
exports.default = { readDotFiles: exports.readDotFiles, mergeDotFiles: exports.mergeDotFiles };
//# sourceMappingURL=dotfiles.js.map