@coat/cli
Version:
TODO: See #3
74 lines (68 loc) • 3.5 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.printCreateCustomizationHelp = printCreateCustomizationHelp;
var _boxen = _interopRequireDefault(require("boxen"));
var _chalk = _interopRequireDefault(require("chalk"));
var _wrapAnsi = _interopRequireDefault(require("wrap-ansi"));
var _jsonColorizer = _interopRequireDefault(require("json-colorizer"));
var _centerText = require("../ui/center-text");
var _getUsableTerminalSize = require("../ui/get-usable-terminal-size");
var _fillLastLine = require("../ui/fill-last-line");
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
/**
* Prints getting started guidance for the customization of the generated
* coat files.
*
* On tiny terminal sizes, no help text is printed since it would overwhelm
* the terminal log.
*/
function printCreateCustomizationHelp() {
const usableTerminalSize = (0, _getUsableTerminalSize.getUsableTerminalSize)(process.stdout);
// Don't print any customization help if the terminal window is tiny
if (usableTerminalSize.size === _getUsableTerminalSize.TerminalSize.Tiny) {
return;
}
// prettier-ignore
const customizationExplanation = [(0, _chalk.default)`Files that are generated by {cyan coat} will be continuously kept up to date via your {cyan coat} template.`, (0, _chalk.default)`This means that you can't edit these files directly, because they will be overwritten when running {cyan coat sync}.`, "", (0, _chalk.default)`However, {cyan coat} allows you to customize the final file by creating a {green <filename>-custom.js} file next to the file you want to customize.`, "", (0, _chalk.default)`As an example, a configuration file named {green config.json} can be customized by placing a {green config.json-custom.js} file next to it.`, "The export will be merged into the file provided by coat:"].join('\n');
const maxWidth = usableTerminalSize.width;
const borderConfig = {
dimBorder: true,
padding: 1
};
// Colorize JSON examples and put them into boxes
const exampleConfigs = [
// config.json from coat
(0, _jsonColorizer.default)(JSON.stringify({
coatConfig: "value from your coat template"
}), {
pretty: true
}),
// config.json-custom.js
`module.exports = ${(0, _jsonColorizer.default)(JSON.stringify({
customConfig: "value specified by you"
}), {
pretty: true
})}`,
// Resulting config.json
(0, _jsonColorizer.default)(JSON.stringify({
coatConfig: "value from your coat template",
customConfig: "value specified by you"
}), {
pretty: true
})].map(exampleConfig =>
// place example config in a box and fill
// the last line of the string to have
// equally sized boxes
(0, _boxen.default)((0, _fillLastLine.fillLastLine)(exampleConfig, maxWidth), borderConfig));
const text = [(0, _centerText.centerText)("💡 Before you get started 💡", maxWidth), "", (0, _wrapAnsi.default)(customizationExplanation, maxWidth), "", _chalk.default.dim("// config.json from coat"), exampleConfigs[0], "", _chalk.default.dim("// config.json-custom.js"), exampleConfigs[1], "", _chalk.default.dim("// config.json that will be placed"), exampleConfigs[2]].join("\n");
// TODO: See #52
// Add link to customization documentation once it exists
// Place customization help into a box
const customizationTextBox = (0, _boxen.default)(text, {
...borderConfig,
float: "center"
});
console.log(customizationTextBox);
}