@mokup/cli 0.0.1 → 0.1.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/dist/cli.cjs CHANGED
@@ -2,7 +2,7 @@
2
2
  'use strict';
3
3
 
4
4
  const node_process = require('node:process');
5
- const index = require('./shared/cli.yAHcdIVy.cjs');
5
+ const index = require('./shared/cli.BdZQ4JPf.cjs');
6
6
  require('node:fs');
7
7
  require('pathe');
8
8
  require('node:buffer');
package/dist/cli.mjs CHANGED
@@ -1,6 +1,6 @@
1
1
  #!/usr/bin/env node
2
2
  import { argv, exit } from 'node:process';
3
- import { b as buildManifest } from './shared/cli.D0D0o7Rg.mjs';
3
+ import { b as buildManifest } from './shared/cli.DqkcmI0-.mjs';
4
4
  import 'node:fs';
5
5
  import 'pathe';
6
6
  import 'node:buffer';
package/dist/index.cjs CHANGED
@@ -1,6 +1,6 @@
1
1
  'use strict';
2
2
 
3
- const index = require('./shared/cli.yAHcdIVy.cjs');
3
+ const index = require('./shared/cli.BdZQ4JPf.cjs');
4
4
  require('node:fs');
5
5
  require('node:process');
6
6
  require('pathe');
package/dist/index.mjs CHANGED
@@ -1,4 +1,4 @@
1
- export { b as buildManifest } from './shared/cli.D0D0o7Rg.mjs';
1
+ export { b as buildManifest } from './shared/cli.DqkcmI0-.mjs';
2
2
  import 'node:fs';
3
3
  import 'node:process';
4
4
  import 'pathe';
@@ -71,7 +71,7 @@ const configExtensions = [".ts", ".js", ".mjs", ".cjs"];
71
71
  async function loadModule$1(file) {
72
72
  const ext = configExtensions.find((extension) => file.endsWith(extension));
73
73
  if (ext === ".cjs") {
74
- const require$1 = node_module.createRequire((typeof document === 'undefined' ? require('u' + 'rl').pathToFileURL(__filename).href : (_documentCurrentScript && _documentCurrentScript.tagName.toUpperCase() === 'SCRIPT' && _documentCurrentScript.src || new URL('shared/cli.yAHcdIVy.cjs', document.baseURI).href)));
74
+ const require$1 = node_module.createRequire((typeof document === 'undefined' ? require('u' + 'rl').pathToFileURL(__filename).href : (_documentCurrentScript && _documentCurrentScript.tagName.toUpperCase() === 'SCRIPT' && _documentCurrentScript.src || new URL('shared/cli.BdZQ4JPf.cjs', document.baseURI).href)));
75
75
  delete require$1.cache[file];
76
76
  return require$1(file);
77
77
  }
@@ -316,8 +316,8 @@ async function writeHandlerIndex(handlerModuleMap, handlersDir, outDir) {
316
316
  await node_fs.promises.writeFile(pathe.join(handlersDir, "index.d.ts"), dts.join("\n"), "utf8");
317
317
  await node_fs.promises.writeFile(pathe.join(handlersDir, "index.d.mts"), dts.join("\n"), "utf8");
318
318
  }
319
- function buildResponse(response, options) {
320
- if (typeof response === "function") {
319
+ function buildResponse(handler, options) {
320
+ if (typeof handler === "function") {
321
321
  if (!options.handlers) {
322
322
  return null;
323
323
  }
@@ -334,29 +334,29 @@ function buildResponse(response, options) {
334
334
  ruleIndex: options.ruleIndex
335
335
  };
336
336
  }
337
- if (typeof response === "string") {
337
+ if (typeof handler === "string") {
338
338
  return {
339
339
  type: "text",
340
- body: response
340
+ body: handler
341
341
  };
342
342
  }
343
- if (response instanceof Uint8Array || response instanceof ArrayBuffer) {
343
+ if (handler instanceof Uint8Array || handler instanceof ArrayBuffer) {
344
344
  return {
345
345
  type: "binary",
346
- body: node_buffer.Buffer.from(response).toString("base64"),
346
+ body: node_buffer.Buffer.from(handler).toString("base64"),
347
347
  encoding: "base64"
348
348
  };
349
349
  }
350
- if (node_buffer.Buffer.isBuffer(response)) {
350
+ if (node_buffer.Buffer.isBuffer(handler)) {
351
351
  return {
352
352
  type: "binary",
353
- body: response.toString("base64"),
353
+ body: handler.toString("base64"),
354
354
  encoding: "base64"
355
355
  };
356
356
  }
357
357
  return {
358
358
  type: "json",
359
- body: response
359
+ body: handler
360
360
  };
361
361
  }
362
362
  async function bundleHandlers(files, root, handlersDir) {
@@ -516,7 +516,7 @@ async function readJsonFile(file) {
516
516
  async function loadModule(file) {
517
517
  const ext = pathe.extname(file).toLowerCase();
518
518
  if (ext === ".cjs") {
519
- const require$1 = node_module.createRequire((typeof document === 'undefined' ? require('u' + 'rl').pathToFileURL(__filename).href : (_documentCurrentScript && _documentCurrentScript.tagName.toUpperCase() === 'SCRIPT' && _documentCurrentScript.src || new URL('shared/cli.yAHcdIVy.cjs', document.baseURI).href)));
519
+ const require$1 = node_module.createRequire((typeof document === 'undefined' ? require('u' + 'rl').pathToFileURL(__filename).href : (_documentCurrentScript && _documentCurrentScript.tagName.toUpperCase() === 'SCRIPT' && _documentCurrentScript.src || new URL('shared/cli.BdZQ4JPf.cjs', document.baseURI).href)));
520
520
  delete require$1.cache[file];
521
521
  return require$1(file);
522
522
  }
@@ -551,7 +551,7 @@ async function loadRules(file) {
551
551
  }
552
552
  return [
553
553
  {
554
- response: json
554
+ handler: json
555
555
  }
556
556
  ];
557
557
  }
@@ -566,7 +566,7 @@ async function loadRules(file) {
566
566
  if (typeof value === "function") {
567
567
  return [
568
568
  {
569
- response: value
569
+ handler: value
570
570
  }
571
571
  ];
572
572
  }
@@ -614,7 +614,17 @@ async function buildManifest(options = {}) {
614
614
  if (!rule || typeof rule !== "object") {
615
615
  continue;
616
616
  }
617
- if (typeof rule.response === "undefined") {
617
+ const ruleValue = rule;
618
+ const unsupportedKeys = ["response", "url", "method"].filter(
619
+ (key2) => key2 in ruleValue
620
+ );
621
+ if (unsupportedKeys.length > 0) {
622
+ options.log?.(
623
+ `Skip mock with unsupported fields (${unsupportedKeys.join(", ")}): ${fileInfo.file}`
624
+ );
625
+ continue;
626
+ }
627
+ if (typeof rule.handler === "undefined") {
618
628
  continue;
619
629
  }
620
630
  const resolveParams = {
@@ -637,7 +647,7 @@ async function buildManifest(options = {}) {
637
647
  }
638
648
  seen.add(key);
639
649
  const response = buildResponse(
640
- rule.response,
650
+ rule.handler,
641
651
  {
642
652
  file: fileInfo.file,
643
653
  handlers: options.handlers !== false,
@@ -313,8 +313,8 @@ async function writeHandlerIndex(handlerModuleMap, handlersDir, outDir) {
313
313
  await promises.writeFile(join(handlersDir, "index.d.ts"), dts.join("\n"), "utf8");
314
314
  await promises.writeFile(join(handlersDir, "index.d.mts"), dts.join("\n"), "utf8");
315
315
  }
316
- function buildResponse(response, options) {
317
- if (typeof response === "function") {
316
+ function buildResponse(handler, options) {
317
+ if (typeof handler === "function") {
318
318
  if (!options.handlers) {
319
319
  return null;
320
320
  }
@@ -331,29 +331,29 @@ function buildResponse(response, options) {
331
331
  ruleIndex: options.ruleIndex
332
332
  };
333
333
  }
334
- if (typeof response === "string") {
334
+ if (typeof handler === "string") {
335
335
  return {
336
336
  type: "text",
337
- body: response
337
+ body: handler
338
338
  };
339
339
  }
340
- if (response instanceof Uint8Array || response instanceof ArrayBuffer) {
340
+ if (handler instanceof Uint8Array || handler instanceof ArrayBuffer) {
341
341
  return {
342
342
  type: "binary",
343
- body: Buffer.from(response).toString("base64"),
343
+ body: Buffer.from(handler).toString("base64"),
344
344
  encoding: "base64"
345
345
  };
346
346
  }
347
- if (Buffer.isBuffer(response)) {
347
+ if (Buffer.isBuffer(handler)) {
348
348
  return {
349
349
  type: "binary",
350
- body: response.toString("base64"),
350
+ body: handler.toString("base64"),
351
351
  encoding: "base64"
352
352
  };
353
353
  }
354
354
  return {
355
355
  type: "json",
356
- body: response
356
+ body: handler
357
357
  };
358
358
  }
359
359
  async function bundleHandlers(files, root, handlersDir) {
@@ -548,7 +548,7 @@ async function loadRules(file) {
548
548
  }
549
549
  return [
550
550
  {
551
- response: json
551
+ handler: json
552
552
  }
553
553
  ];
554
554
  }
@@ -563,7 +563,7 @@ async function loadRules(file) {
563
563
  if (typeof value === "function") {
564
564
  return [
565
565
  {
566
- response: value
566
+ handler: value
567
567
  }
568
568
  ];
569
569
  }
@@ -611,7 +611,17 @@ async function buildManifest(options = {}) {
611
611
  if (!rule || typeof rule !== "object") {
612
612
  continue;
613
613
  }
614
- if (typeof rule.response === "undefined") {
614
+ const ruleValue = rule;
615
+ const unsupportedKeys = ["response", "url", "method"].filter(
616
+ (key2) => key2 in ruleValue
617
+ );
618
+ if (unsupportedKeys.length > 0) {
619
+ options.log?.(
620
+ `Skip mock with unsupported fields (${unsupportedKeys.join(", ")}): ${fileInfo.file}`
621
+ );
622
+ continue;
623
+ }
624
+ if (typeof rule.handler === "undefined") {
615
625
  continue;
616
626
  }
617
627
  const resolveParams = {
@@ -634,7 +644,7 @@ async function buildManifest(options = {}) {
634
644
  }
635
645
  seen.add(key);
636
646
  const response = buildResponse(
637
- rule.response,
647
+ rule.handler,
638
648
  {
639
649
  file: fileInfo.file,
640
650
  handlers: options.handlers !== false,
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@mokup/cli",
3
3
  "type": "module",
4
- "version": "0.0.1",
4
+ "version": "0.1.0",
5
5
  "description": "CLI for building mokup manifests and handlers.",
6
6
  "license": "MIT",
7
7
  "homepage": "https://mokup.icebreaker.top",
@@ -33,7 +33,7 @@
33
33
  "esbuild": "^0.27.2",
34
34
  "jsonc-parser": "^3.3.1",
35
35
  "pathe": "^2.0.3",
36
- "@mokup/runtime": "0.0.1"
36
+ "@mokup/runtime": "0.1.0"
37
37
  },
38
38
  "devDependencies": {
39
39
  "@types/node": "^25.0.9",