@tahminator/pipeline 1.0.63 → 1.0.64

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/README.md CHANGED
@@ -252,6 +252,7 @@ await frontendClient.uploadTestCoverage();
252
252
  Assorted helper class used by clients and useful as an exported class to pipelines.
253
253
 
254
254
  ```ts
255
+ // ----- strings -----
255
256
  const githubPrivateKey = await Utils.decodeBase64EncodedString(
256
257
  process.env.GH_PRIVATE_KEY_B64!,
257
258
  );
@@ -262,9 +263,42 @@ if (await Utils.isCmdAvailable("gh")) {
262
263
  console.log(Utils.Colors.green(`gh is installed (${shortId})`));
263
264
  }
264
265
 
265
- if (!Utils.SemVer.validate("1.2.3")) throw new Error("invalid version");
266
+ // ----- required -----
267
+ const token = Utils.required(process.env.GITHUB_TOKEN); // will throw if null or undefined
268
+
269
+ // ----- wait / polling -----
270
+ const reachable = await Utils.waitUntil({
271
+ predicate: async () => await Utils.isCmdAvailable("docker"),
272
+ attempts: 10,
273
+ intervalMs: 500,
274
+ });
275
+
276
+ if (!reachable) throw new Error("docker unavailable");
277
+
278
+ // ----- debug -----
279
+ if (Utils.Log.isDebug) {
280
+ console.log(Utils.Colors.dim("debug logging enabled"));
281
+ }
266
282
  ```
267
283
 
284
+ Available Utils APIs:
285
+
286
+ - `Utils.decodeBase64EncodedString(s: string): string`
287
+ - `Utils.generateShortId(len = 7): string`
288
+ - `Utils.isCmdAvailable(cmd: string): Promise<boolean>`
289
+ - `Utils.waitUntil({ predicate, attempts?, intervalMs? }): Promise<boolean>`
290
+ - `Utils.required<T>(value: T | null | undefined): T`
291
+ - `Utils.SemVer.validate(version: string | semver.SemVer): boolean`
292
+ - `Utils.Log.isDebug: boolean` (`true` when `DEBUG=true`)
293
+ - `Utils.Colors.<formatter>(s: string): string`
294
+
295
+ `Utils.Colors` formatters:
296
+
297
+ - `black`, `red`, `green`, `yellow`, `blue`, `magenta`, `cyan`, `white`, `gray`
298
+ - `brightRed`, `brightGreen`, `brightYellow`, `brightBlue`, `brightMagenta`, `brightCyan`, `brightWhite`
299
+ - `pink`, `orange`
300
+ - `bold`, `dim`, `italic`, `underline`
301
+
268
302
  ### `EnvClient`
269
303
 
270
304
  Load environment variables from encrypted files and automatically mask them in GitHub Actions logs.
@@ -4,6 +4,7 @@ import { Colors } from "./colors";
4
4
  import { Log } from "./log";
5
5
  import { SemVer } from "./semver";
6
6
  import { generateShortId } from "./short";
7
+ import { required } from "./string";
7
8
  import { waitUntil } from "./wait";
8
9
  export declare class Utils {
9
10
  static Colors: typeof Colors;
@@ -13,4 +14,5 @@ export declare class Utils {
13
14
  static isCmdAvailable(...args: Parameters<typeof isCmdAvailable>): Promise<boolean>;
14
15
  static decodeBase64EncodedString(...args: Parameters<typeof decodeBase64EncodedString>): Promise<string>;
15
16
  static waitUntil(...args: Parameters<typeof waitUntil>): Promise<boolean>;
17
+ static required<T>(...args: Parameters<typeof required<T>>): T;
16
18
  }
@@ -4,6 +4,7 @@ import { Colors } from "./colors";
4
4
  import { Log } from "./log";
5
5
  import { SemVer } from "./semver";
6
6
  import { generateShortId } from "./short";
7
+ import { required } from "./string";
7
8
  import { waitUntil } from "./wait";
8
9
  export class Utils {
9
10
  // hoist
@@ -22,4 +23,7 @@ export class Utils {
22
23
  static async waitUntil(...args) {
23
24
  return waitUntil(...args);
24
25
  }
26
+ static required(...args) {
27
+ return required(...args);
28
+ }
25
29
  }
@@ -0,0 +1 @@
1
+ export declare function required<T>(value: T | null | undefined): T;
@@ -0,0 +1,6 @@
1
+ export function required(value) {
2
+ if (value == null) {
3
+ throw new Error("Expected a value but received null or undefined");
4
+ }
5
+ return value;
6
+ }
package/package.json CHANGED
@@ -3,7 +3,7 @@
3
3
  "type": "module",
4
4
  "author": "Tahmid Ahmed",
5
5
  "description": "A collection of Bun shell scripts that can be re-used in various CICD pipelines.",
6
- "version": "1.0.63",
6
+ "version": "1.0.64",
7
7
  "repository": {
8
8
  "url": "git+https://github.com/tahminator/pipeline.git"
9
9
  },