@wiztivi/dana-cli 0.0.11 → 0.0.12

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.
@@ -20,4 +20,8 @@ export declare class AuthenticationManager {
20
20
  token: string;
21
21
  expiration?: Date;
22
22
  }>;
23
+ static loginGradle(organization: string, credentials: AwsCredentials): Promise<{
24
+ token: string;
25
+ expiration?: Date;
26
+ }>;
23
27
  }
@@ -3,10 +3,12 @@ import express from "express";
3
3
  import { CredentialsHelper } from "./helper/CredentialsHelper.js";
4
4
  import open from "open";
5
5
  import jwt from "jsonwebtoken";
6
- import { createCodeArtifactClient, getRepositoryEndpoint } from "./helper/CodeArtifactHelper.js";
6
+ import { createCodeArtifactClient, formatRepositoryString, getRepositoryEndpoint, } from "./helper/CodeArtifactHelper.js";
7
7
  import { GetAuthorizationTokenCommand } from "@aws-sdk/client-codeartifact";
8
8
  import { DOMAIN, DOMAIN_OWNER } from "./authentConst.js";
9
9
  import { execSync } from "node:child_process";
10
+ import fs from "node:fs";
11
+ import path from "node:path";
10
12
  export class AuthenticationManager {
11
13
  static getAPIURL(organization) {
12
14
  return `https://api.${organization}.dana-framework.com`; // Or http://localhost:3001
@@ -104,4 +106,45 @@ export class AuthenticationManager {
104
106
  expiration,
105
107
  };
106
108
  }
109
+ static async loginGradle(organization, credentials) {
110
+ const client = createCodeArtifactClient(credentials);
111
+ const tokenCommand = new GetAuthorizationTokenCommand({
112
+ domain: DOMAIN,
113
+ domainOwner: DOMAIN_OWNER,
114
+ });
115
+ const { authorizationToken, expiration } = await client.send(tokenCommand);
116
+ if (!authorizationToken) {
117
+ throw new Error("Authorization token not found");
118
+ }
119
+ const repository = formatRepositoryString(organization);
120
+ if (!fs.existsSync(path.join(process.env.HOME, ".gradle"))) {
121
+ fs.mkdirSync(path.join(process.env.HOME, ".gradle"));
122
+ }
123
+ const gradlePropertiesFilePath = path.join(process.env.HOME, ".gradle", "gradle.properties");
124
+ const gradlePropertiesFile = fs.existsSync(gradlePropertiesFilePath)
125
+ ? fs.readFileSync(gradlePropertiesFilePath, { encoding: "utf-8" })
126
+ : "";
127
+ const key = `dana.${repository}.token`;
128
+ let replaced = false;
129
+ let lastEmptyLine = 0;
130
+ const lines = gradlePropertiesFile.split("\n").reduce((lines, line, index) => {
131
+ if (line.startsWith(key + "=")) {
132
+ line = `${key}=${authorizationToken}`;
133
+ replaced = true;
134
+ }
135
+ else if (line === "" && index > lastEmptyLine) {
136
+ lastEmptyLine = index;
137
+ }
138
+ lines.push(line);
139
+ return lines;
140
+ }, []);
141
+ if (!replaced) {
142
+ lines.splice(lastEmptyLine, 0, `${key}=${authorizationToken}`);
143
+ }
144
+ fs.writeFileSync(gradlePropertiesFilePath, lines.join("\n"));
145
+ return {
146
+ token: authorizationToken,
147
+ expiration,
148
+ };
149
+ }
107
150
  }
@@ -14,6 +14,7 @@ const login = async ({ org }) => {
14
14
  const validCredentials = await AuthenticationManager.login(credentials.org);
15
15
  prompts.outro(colors.green("✓") + ` Login successful`);
16
16
  const npmToken = await AuthenticationManager.loginNPM(credentials.org, validCredentials.aws);
17
+ await AuthenticationManager.loginGradle(credentials.org, validCredentials.aws);
17
18
  let stepText = "Successfully logged in to npm repository.";
18
19
  if (npmToken.expiration) {
19
20
  stepText += `\nLogin expires in 12 hours at: ${npmToken.expiration.toLocaleString()}`;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@wiztivi/dana-cli",
3
- "version": "0.0.11",
3
+ "version": "0.0.12",
4
4
  "description": "Dana create app CLI",
5
5
  "type": "module",
6
6
  "exports": "./dist/index.js",
@@ -28,7 +28,7 @@
28
28
  "dependencies": {
29
29
  "@aws-sdk/client-codeartifact": "^3.859.0",
30
30
  "@clack/prompts": "0.10.0",
31
- "@wiztivi/dana-templates": "^0.0.11",
31
+ "@wiztivi/dana-templates": "^0.0.12",
32
32
  "child_process": "1.0.x",
33
33
  "command-exists": "1.2.9",
34
34
  "commander": "11.1.x",