@uides/stepwise 1.0.4 → 1.0.5

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.
@@ -41,41 +41,53 @@ function _validate() {
41
41
  templateUrlOrName = "http://localhost/api/templates/".concat(templateUrlOrName);
42
42
  return _context.abrupt("break", 11);
43
43
  case 11:
44
+ template = {};
44
45
  if (!(templateType === 'remote')) {
45
- _context.next = 18;
46
+ _context.next = 19;
46
47
  break;
47
48
  }
48
- _context.next = 14;
49
+ _context.next = 15;
49
50
  return (0, _nodeFetch["default"])(templateUrlOrName)["catch"](function (err) {
50
51
  return console.error("Could not fetch ".concat(templateUrlOrName, ". Error: ").concat(err));
51
52
  });
52
- case 14:
53
+ case 15:
53
54
  response = _context.sent;
54
- _context.next = 17;
55
+ _context.next = 18;
55
56
  return response === null || response === void 0 ? void 0 : response.json()["catch"](function (err) {
56
57
  return console.error("Could not parse JSON from ".concat(templateUrlOrName, ". Error: ").concat(err));
57
58
  });
58
- case 17:
59
- template = _context.sent;
60
59
  case 18:
60
+ template = _context.sent;
61
+ case 19:
61
62
  if (!(templateType === 'local')) {
62
- _context.next = 23;
63
+ _context.next = 24;
63
64
  break;
64
65
  }
65
66
  templatePath = _path["default"].join(process.cwd(), templateUrlOrName);
66
67
  if (_fs["default"].existsSync(templatePath)) {
67
- _context.next = 22;
68
+ _context.next = 23;
68
69
  break;
69
70
  }
70
71
  throw new Error("File ".concat(templatePath, " does not exist"));
71
- case 22:
72
- template = JSON.parse(_fs["default"].readFileSync(templatePath, 'utf8'));
73
72
  case 23:
73
+ template = JSON.parse(_fs["default"].readFileSync(templatePath, 'utf8'));
74
+ case 24:
74
75
  process.stdout.write('✅\n');
75
76
  console.log(_chalk["default"].dim("Validating template..."));
76
77
  errors = valibot.safeParse(_template.TemplateSource, template).issues;
77
- if (!(errors !== null && errors !== void 0 && errors.length)) console.log(_chalk["default"].greenBright('Template is valid!'));
78
- case 27:
78
+ if (!(errors !== null && errors !== void 0 && errors.length)) {
79
+ console.log(_chalk["default"].greenBright('Template is valid!'));
80
+ } else if (errors) {
81
+ console.log(_chalk["default"].redBright('Template is invalid!'));
82
+ errors.forEach(function (issue) {
83
+ var _issue$path;
84
+ var path = issue === null || issue === void 0 ? void 0 : (_issue$path = issue.path) === null || _issue$path === void 0 ? void 0 : _issue$path.map(function (p) {
85
+ return p.key;
86
+ }).join('/');
87
+ console.log(_chalk["default"].redBright("".concat(template.refname, "/").concat(path, ": ").concat(issue.message)));
88
+ });
89
+ }
90
+ case 28:
79
91
  case "end":
80
92
  return _context.stop();
81
93
  }
@@ -31,41 +31,53 @@ function _validate() {
31
31
  templateUrlOrName = "http://localhost/api/templates/".concat(templateUrlOrName);
32
32
  return _context.abrupt("break", 11);
33
33
  case 11:
34
+ template = {};
34
35
  if (!(templateType === 'remote')) {
35
- _context.next = 18;
36
+ _context.next = 19;
36
37
  break;
37
38
  }
38
- _context.next = 14;
39
+ _context.next = 15;
39
40
  return fetch(templateUrlOrName)["catch"](function (err) {
40
41
  return console.error("Could not fetch ".concat(templateUrlOrName, ". Error: ").concat(err));
41
42
  });
42
- case 14:
43
+ case 15:
43
44
  response = _context.sent;
44
- _context.next = 17;
45
+ _context.next = 18;
45
46
  return response === null || response === void 0 ? void 0 : response.json()["catch"](function (err) {
46
47
  return console.error("Could not parse JSON from ".concat(templateUrlOrName, ". Error: ").concat(err));
47
48
  });
48
- case 17:
49
- template = _context.sent;
50
49
  case 18:
50
+ template = _context.sent;
51
+ case 19:
51
52
  if (!(templateType === 'local')) {
52
- _context.next = 23;
53
+ _context.next = 24;
53
54
  break;
54
55
  }
55
56
  templatePath = path.join(process.cwd(), templateUrlOrName);
56
57
  if (fs.existsSync(templatePath)) {
57
- _context.next = 22;
58
+ _context.next = 23;
58
59
  break;
59
60
  }
60
61
  throw new Error("File ".concat(templatePath, " does not exist"));
61
- case 22:
62
- template = JSON.parse(fs.readFileSync(templatePath, 'utf8'));
63
62
  case 23:
63
+ template = JSON.parse(fs.readFileSync(templatePath, 'utf8'));
64
+ case 24:
64
65
  process.stdout.write('✅\n');
65
66
  console.log(chalk.dim("Validating template..."));
66
67
  errors = valibot.safeParse(TemplateSource, template).issues;
67
- if (!(errors !== null && errors !== void 0 && errors.length)) console.log(chalk.greenBright('Template is valid!'));
68
- case 27:
68
+ if (!(errors !== null && errors !== void 0 && errors.length)) {
69
+ console.log(chalk.greenBright('Template is valid!'));
70
+ } else if (errors) {
71
+ console.log(chalk.redBright('Template is invalid!'));
72
+ errors.forEach(function (issue) {
73
+ var _issue$path;
74
+ var path = issue === null || issue === void 0 ? void 0 : (_issue$path = issue.path) === null || _issue$path === void 0 ? void 0 : _issue$path.map(function (p) {
75
+ return p.key;
76
+ }).join('/');
77
+ console.log(chalk.redBright("".concat(template.refname, "/").concat(path, ": ").concat(issue.message)));
78
+ });
79
+ }
80
+ case 28:
69
81
  case "end":
70
82
  return _context.stop();
71
83
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@uides/stepwise",
3
- "version": "1.0.4",
3
+ "version": "1.0.5",
4
4
  "description": "@uides stepwise specification",
5
5
  "main": "cjs/index.js",
6
6
  "bin": {
@@ -21,7 +21,7 @@ export default async function validate(templateUrlOrName: string) {
21
21
  break;
22
22
  }
23
23
 
24
- let template;
24
+ let template:any ={};
25
25
  if (templateType === 'remote') {
26
26
  const response = await fetch(templateUrlOrName).catch((err) =>
27
27
  console.error(`Could not fetch ${templateUrlOrName}. Error: ${err}`)
@@ -45,5 +45,14 @@ export default async function validate(templateUrlOrName: string) {
45
45
  process.stdout.write('✅\n');
46
46
  console.log(chalk.dim(`Validating template...`));
47
47
  const errors = valibot.safeParse(TemplateSource, template).issues;
48
- if (!errors?.length) console.log(chalk.greenBright('Template is valid!'));
48
+
49
+ if (!errors?.length) {
50
+ console.log(chalk.greenBright('Template is valid!'))
51
+ } else if (errors) {
52
+ console.log(chalk.redBright('Template is invalid!'))
53
+ errors.forEach(issue => {
54
+ const path = issue?.path?.map((p) => p.key).join('/');
55
+ console.log(chalk.redBright(`${template.refname}/${path}: ${issue.message}`));
56
+ });
57
+ }
49
58
  }