UNPKG

1.5 kBJavaScriptView Raw
1"use strict";
2Object.defineProperty(exports, "__esModule", { value: true });
3exports.SchematicOption = void 0;
4const formatting_1 = require("../utils/formatting");
5class SchematicOption {
6 constructor(name, value) {
7 this.name = name;
8 this.value = value;
9 }
10 get normalizedName() {
11 return (0, formatting_1.normalizeToKebabOrSnakeCase)(this.name);
12 }
13 toCommandString() {
14 if (typeof this.value === 'string') {
15 if (this.name === 'name') {
16 return `--${this.normalizedName}=${this.format()}`;
17 }
18 else if (this.name === 'version' || this.name === 'path') {
19 return `--${this.normalizedName}=${this.value}`;
20 }
21 else {
22 return `--${this.normalizedName}="${this.value}"`;
23 }
24 }
25 else if (typeof this.value === 'boolean') {
26 const str = this.normalizedName;
27 return this.value ? `--${str}` : `--no-${str}`;
28 }
29 else {
30 return `--${this.normalizedName}=${this.value}`;
31 }
32 }
33 format() {
34 return (0, formatting_1.normalizeToKebabOrSnakeCase)(this.value)
35 .split('')
36 .reduce((content, char) => {
37 if (char === '(' || char === ')' || char === '[' || char === ']') {
38 return `${content}\\${char}`;
39 }
40 return `${content}${char}`;
41 }, '');
42 }
43}
44exports.SchematicOption = SchematicOption;