@vexify-org/yaggs 6.13.0 → 6.15.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/index.js CHANGED
@@ -181,6 +181,14 @@ class Yaggs {
181
181
  return this.parser.http(url, options);
182
182
  }
183
183
 
184
+ file(path, options = {}) {
185
+ return this.parser.file(path, options);
186
+ }
187
+
188
+ template(str, data = {}) {
189
+ return this.parser.template(str, data);
190
+ }
191
+
184
192
  check(fn) {
185
193
  this.middleware(fn);
186
194
  return this;
package/lib/parser.js CHANGED
@@ -1097,6 +1097,56 @@ complete -c ${this.scriptName} `;
1097
1097
  });
1098
1098
  }
1099
1099
 
1100
+ file(path, options = {}) {
1101
+ const fs = require('fs');
1102
+ const pathMod = require('path');
1103
+
1104
+ return {
1105
+ read: () => {
1106
+ const encoding = options.encoding || 'utf8';
1107
+ return fs.readFileSync(path, encoding);
1108
+ },
1109
+ readJson: () => {
1110
+ const content = fs.readFileSync(path, 'utf8');
1111
+ return JSON.parse(content);
1112
+ },
1113
+ write: (content) => {
1114
+ const encoding = options.encoding || 'utf8';
1115
+ return fs.writeFileSync(path, content, encoding);
1116
+ },
1117
+ writeJson: (content, space = 2) => {
1118
+ const json = JSON.stringify(content, null, space);
1119
+ return fs.writeFileSync(path, json, 'utf8');
1120
+ },
1121
+ exists: () => fs.existsSync(path),
1122
+ mkdir: () => fs.mkdirSync(path, { recursive: true }),
1123
+ rm: () => fs.unlinkSync(path),
1124
+ stat: () => fs.statSync(path),
1125
+ dirname: () => pathMod.dirname(path),
1126
+ basename: () => pathMod.basename(path),
1127
+ extname: () => pathMod.extname(path),
1128
+ resolve: () => pathMod.resolve(path)
1129
+ };
1130
+ }
1131
+
1132
+ template(str, data = {}) {
1133
+ return str.replace(/{{([^}]+)}}/g, (match, key) => {
1134
+ const keys = key.trim().split('.');
1135
+ let value = data;
1136
+
1137
+ for (const k of keys) {
1138
+ if (value && typeof value === 'object') {
1139
+ value = value[k];
1140
+ } else {
1141
+ value = undefined;
1142
+ break;
1143
+ }
1144
+ }
1145
+
1146
+ return value !== undefined ? value : match;
1147
+ });
1148
+ }
1149
+
1100
1150
  getHelp() {
1101
1151
  let help = `\u001b[36m${this.scriptName}\u001b[0m`;
1102
1152
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vexify-org/yaggs",
3
- "version": "6.13.0",
3
+ "version": "6.15.0",
4
4
  "description": "A powerful CLI argument parser, better than yargs",
5
5
  "main": "index.js",
6
6
  "scripts": {