@tahminator/pipeline 1.0.9 → 1.0.11

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.
@@ -1,19 +1,16 @@
1
+ import yargs from "yargs";
2
+ import { hideBin } from "yargs/helpers";
1
3
  import { NPMClient } from "../../npm";
2
- import { Utils } from "../../utils";
4
+ const { dryRun } = await yargs(hideBin(process.argv))
5
+ .option("dryRun", {
6
+ type: "boolean",
7
+ default: false,
8
+ })
9
+ .strict()
10
+ .parse();
3
11
  async function main() {
4
- const { npmToken } = parseCiEnv(await Utils.getEnvVariables(["ci"]));
5
- await using npmClient = await NPMClient.create(npmToken);
6
- await npmClient.publish();
7
- }
8
- function parseCiEnv(ciEnv) {
9
- const npmToken = (() => {
10
- const v = ciEnv["NPM_TOKEN"];
11
- if (!v) {
12
- throw new Error("Missing NPM_TOKEN from .env.ci");
13
- }
14
- return v;
15
- })();
16
- return { npmToken };
12
+ await using npmClient = await NPMClient.create();
13
+ await npmClient.publish(dryRun);
17
14
  }
18
15
  main()
19
16
  .then(() => {
@@ -1,12 +1,24 @@
1
1
  export declare class NPMClient {
2
2
  private constructor();
3
- static create(npmToken: string): Promise<NPMClient>;
3
+ /**
4
+ * __You must use [Trusted Publishing](https://docs.npmjs.com/trusted-publishers) now.__ Using tokens
5
+ * now are extremely flaky and should be avoided.
6
+ *
7
+ * __NOTE: Base yaml must have this property__
8
+ *
9
+ * @example
10
+ * ```yaml
11
+ * permissions:
12
+ * id-token: write # Required for OIDC
13
+ * ```
14
+ */
15
+ static create(): Promise<NPMClient>;
4
16
  /**
5
17
  * @note You must ensure that the current root directory `package.json`
6
18
  * is filled out with the name of the package and the version you would like to
7
19
  * deploy.
8
20
  */
9
- publish(): Promise<void>;
21
+ publish(dryRun?: boolean): Promise<void>;
10
22
  [Symbol.asyncDispose](): Promise<void>;
11
23
  cleanup(): Promise<void>;
12
24
  }
@@ -1,8 +1,21 @@
1
1
  import { $ } from "bun";
2
+ import { Utils } from "../utils";
2
3
  export class NPMClient {
3
4
  constructor() { }
4
- static async create(npmToken) {
5
- await $ `npm config set //registry.npmjs.org/:_authToken=${npmToken}`;
5
+ /**
6
+ * __You must use [Trusted Publishing](https://docs.npmjs.com/trusted-publishers) now.__ Using tokens
7
+ * now are extremely flaky and should be avoided.
8
+ *
9
+ * __NOTE: Base yaml must have this property__
10
+ *
11
+ * @example
12
+ * ```yaml
13
+ * permissions:
14
+ * id-token: write # Required for OIDC
15
+ * ```
16
+ */
17
+ static async create() {
18
+ // await $`npm config set //registry.npmjs.org/:_authToken=${npmToken}`;
6
19
  return new this();
7
20
  }
8
21
  /**
@@ -10,14 +23,21 @@ export class NPMClient {
10
23
  * is filled out with the name of the package and the version you would like to
11
24
  * deploy.
12
25
  */
13
- async publish() {
14
- await $ `npm publish --access public`;
26
+ async publish(dryRun) {
27
+ const dryRunFlag = dryRun ? ["--dry-run"] : [];
28
+ if (Utils.Log.isDebug) {
29
+ console.log(await $ `ls .`.text());
30
+ console.log(await $ `ls ./dist/`.text());
31
+ console.log(await $ `pwd`.text());
32
+ console.log(await $ `cat ./package.json`.text());
33
+ }
34
+ await $ `npm publish --access public --provenance ${dryRunFlag} ./`;
15
35
  console.log("Package has been successfully published");
16
36
  }
17
37
  async [Symbol.asyncDispose]() {
18
38
  await this.cleanup();
19
39
  }
20
40
  async cleanup() {
21
- await $ `npm logout`;
41
+ // await $`npm logout`;
22
42
  }
23
43
  }
@@ -1,8 +1,10 @@
1
1
  import { Colors } from "./colors";
2
2
  import { getEnvVariables } from "./env";
3
+ import { Log } from "./log";
3
4
  import { generateShortId } from "./short";
4
5
  export declare class Utils {
5
6
  static Colors: typeof Colors;
7
+ static Log: typeof Log;
6
8
  static getEnvVariables(...args: Parameters<typeof getEnvVariables>): Promise<Record<string, string>>;
7
9
  static generateShortId(...args: Parameters<typeof generateShortId>): string;
8
10
  static updateAllPackageJsonsWithVersion(version: string): Promise<void>;
@@ -1,10 +1,12 @@
1
1
  import { $ } from "bun";
2
2
  import { Colors } from "./colors";
3
3
  import { getEnvVariables } from "./env";
4
+ import { Log } from "./log";
4
5
  import { generateShortId } from "./short";
5
6
  export class Utils {
6
7
  // hoist
7
8
  static Colors = Colors;
9
+ static Log = Log;
8
10
  static getEnvVariables(...args) {
9
11
  return getEnvVariables(...args);
10
12
  }
@@ -0,0 +1,3 @@
1
+ export declare class Log {
2
+ static get isDebug(): boolean;
3
+ }
@@ -0,0 +1,6 @@
1
+ export class Log {
2
+ // automatically injected from setup action in CI
3
+ static get isDebug() {
4
+ return process.env.DEBUG === "true";
5
+ }
6
+ }
package/package.json CHANGED
@@ -1,7 +1,12 @@
1
1
  {
2
2
  "name": "@tahminator/pipeline",
3
3
  "type": "module",
4
- "version": "1.0.9",
4
+ "author": "Tahmid Ahmed",
5
+ "description": "A collection of Bun shell scripts that can be re-used in various CICD pipelines.",
6
+ "version": "1.0.11",
7
+ "repository": {
8
+ "url": "https://github.com/tahminator/pipeline"
9
+ },
5
10
  "main": "./dist/index.js",
6
11
  "module": "./dist/index.js",
7
12
  "types": "./dist/index.d.ts",
@@ -24,8 +29,7 @@
24
29
  "prettier": "prettier --check .",
25
30
  "prettier:fix": "prettier --write .",
26
31
  "vt": "vitest run",
27
- "build": "tsc -p tsconfig.build.json",
28
- "prepublishOnly": "bun run build"
32
+ "build": "tsc -p tsconfig.build.json"
29
33
  },
30
34
  "devDependencies": {
31
35
  "@eslint/js": "^10.0.1",
@@ -44,8 +48,10 @@
44
48
  "dependencies": {
45
49
  "@octokit/rest": "^22.0.1",
46
50
  "@types/semver": "^7.7.1",
51
+ "@types/yargs": "^17.0.35",
47
52
  "semver": "^7.7.4",
48
53
  "yaml": "^2.8.2",
54
+ "yargs": "^18.0.0",
49
55
  "zod": "^4.3.6"
50
56
  }
51
57
  }