@wocker/utils 2.0.6-beta.0 → 2.0.6-beta.1

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/lib/index.d.ts CHANGED
@@ -1,3 +1,4 @@
1
+ export * from "./makes";
1
2
  export * from "./prompts";
2
3
  export * from "./tools";
3
4
  export * from "./validators";
package/lib/index.js CHANGED
@@ -14,6 +14,7 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
14
  for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
15
  };
16
16
  Object.defineProperty(exports, "__esModule", { value: true });
17
+ __exportStar(require("./makes"), exports);
17
18
  __exportStar(require("./prompts"), exports);
18
19
  __exportStar(require("./tools"), exports);
19
20
  __exportStar(require("./validators"), exports);
@@ -8,10 +8,13 @@ class Volume {
8
8
  this.options = options;
9
9
  }
10
10
  toString() {
11
- return `${this.source}:${this.destination}`;
11
+ return `${this.source}:${this.destination}` + (this.options ? `:${this.options}` : "");
12
12
  }
13
13
  static parse(volume) {
14
- const [, source, destination, options] = Volume.REGEX.exec(volume) || [];
14
+ if (!Volume.REGEX.test(volume)) {
15
+ throw new Error(`Invalid volume format for volume "${volume}"`);
16
+ }
17
+ const [, source = "/", destination = "/", options] = Volume.REGEX.exec(volume) || [];
15
18
  return new Volume(source, destination, options);
16
19
  }
17
20
  }
@@ -0,0 +1 @@
1
+ export * from "./Volume";
@@ -0,0 +1,17 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ __exportStar(require("./Volume"), exports);
@@ -1,7 +1,8 @@
1
+ import { Stats } from "fs";
1
2
  import { PromptConfig } from "../types/PromptConfig";
2
3
  type Config = PromptConfig<string, {
3
- type?: "file" | "directory" | "any";
4
4
  basePath?: string;
5
+ filter?: "file" | "directory" | ((path: string, stat: Stats) => boolean);
5
6
  showHidden?: boolean;
6
7
  }>;
7
8
  export declare const promptPath: import("@inquirer/type").Prompt<string, Config>;
@@ -22,7 +22,7 @@ const prepareMessage_1 = require("../tools/prepareMessage");
22
22
  const prepareValue_1 = require("../tools/prepareValue");
23
23
  const prepareHelp_1 = require("../tools/prepareHelp");
24
24
  exports.promptPath = (0, core_1.createPrompt)((config, done) => {
25
- const { message = "Enter path", type = "any", basePath = process.cwd(), showHidden = false, default: defaultValue = "" } = config;
25
+ const { message = "Enter path", basePath = process.cwd(), showHidden = false, filter, default: defaultValue = "" } = config;
26
26
  const theme = (0, core_1.makeTheme)({
27
27
  style: {
28
28
  message: prepareMessage_1.prepareMessage,
@@ -51,26 +51,27 @@ exports.promptPath = (0, core_1.createPrompt)((config, done) => {
51
51
  if (!fs_1.default.existsSync(currentDir)) {
52
52
  return [];
53
53
  }
54
- const files = fs_1.default.readdirSync(currentDir);
55
- return files
56
- .filter(file => {
54
+ return fs_1.default.readdirSync(currentDir)
55
+ .filter((file) => {
57
56
  if (!showHidden && file.startsWith("."))
58
57
  return false;
59
58
  if (!file.toLowerCase().startsWith(base.toLowerCase()))
60
59
  return false;
61
60
  const filePath = path_1.default.join(currentDir, file);
62
61
  const stats = fs_1.default.statSync(filePath);
63
- if (type === "file")
64
- return stats.isFile();
65
- if (type === "directory")
62
+ if (typeof filter === "function") {
63
+ return filter(filePath, stats);
64
+ }
65
+ else if (filter === "file") {
66
+ return stats.isFile() || stats.isDirectory();
67
+ }
68
+ else if (filter === "directory") {
66
69
  return stats.isDirectory();
70
+ }
67
71
  return true;
68
72
  })
69
73
  .sort((a, b) => {
70
- const aPath = path_1.default.join(currentDir, a);
71
- const bPath = path_1.default.join(currentDir, b);
72
- const aIsDir = fs_1.default.statSync(aPath).isDirectory();
73
- const bIsDir = fs_1.default.statSync(bPath).isDirectory();
74
+ const aPath = path_1.default.join(currentDir, a), bPath = path_1.default.join(currentDir, b), aIsDir = fs_1.default.statSync(aPath).isDirectory(), bIsDir = fs_1.default.statSync(bPath).isDirectory();
74
75
  if (aIsDir && !bIsDir)
75
76
  return -1;
76
77
  if (!aIsDir && bIsDir)
@@ -1,6 +1,3 @@
1
- export type Volume = {
2
- source: string;
3
- destination: string;
4
- options?: string;
5
- };
6
- export declare const volumeFormat: (volume: Volume) => string;
1
+ import { VolumeData } from "../types/VolumeData";
2
+ /** @deprecated */
3
+ export declare const volumeFormat: (volume: VolumeData) => string;
@@ -1,8 +1,9 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.volumeFormat = void 0;
4
+ const Volume_1 = require("../makes/Volume");
5
+ /** @deprecated */
4
6
  const volumeFormat = (volume) => {
5
- const { source = "/", destination = "/", options } = volume;
6
- return `${source}:${destination}` + (options ? `:${options}` : "");
7
+ return (new Volume_1.Volume(volume.source || "/", volume.destination || "/", volume.options)).toString();
7
8
  };
8
9
  exports.volumeFormat = volumeFormat;
@@ -1,2 +1,3 @@
1
- import { Volume } from "./volumeFormat";
2
- export declare const volumeParse: (volume: string) => Volume;
1
+ import { VolumeData } from "../types/VolumeData";
2
+ /** @deprecated */
3
+ export declare const volumeParse: (volume: string) => VolumeData;
@@ -1,13 +1,19 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.volumeParse = void 0;
4
+ const Volume_1 = require("../makes/Volume");
5
+ /** @deprecated */
4
6
  const volumeParse = (volume) => {
5
- const regVolume = /^([^:]+):([^:]+)(?::([^:]+))?$/;
6
- const [, source, destination, options] = regVolume.exec(volume) || [];
7
- return {
8
- source,
9
- destination,
10
- options
11
- };
7
+ try {
8
+ const v = Volume_1.Volume.parse(volume);
9
+ return {
10
+ source: v.source,
11
+ destination: v.destination,
12
+ options: v.options
13
+ };
14
+ }
15
+ catch (_a) {
16
+ return {};
17
+ }
12
18
  };
13
19
  exports.volumeParse = volumeParse;
@@ -0,0 +1,5 @@
1
+ export type VolumeData = {
2
+ source: string;
3
+ destination: string;
4
+ options?: string | undefined;
5
+ };
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@wocker/utils",
3
3
  "type": "commonjs",
4
- "version": "2.0.6-beta.0",
4
+ "version": "2.0.6-beta.1",
5
5
  "author": "Kris Papercut <krispcut@gmail.com>",
6
6
  "description": "Utils for @wocker",
7
7
  "license": "MIT",