@spfn/cli 0.0.3 → 0.0.5

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.
Files changed (2) hide show
  1. package/lib/login.js +48 -57
  2. package/package.json +1 -1
package/lib/login.js CHANGED
@@ -7,74 +7,63 @@ import { execSync } from "child_process";
7
7
 
8
8
  const PORT = 5678;
9
9
 
10
- function mergeNetrc(
10
+ /**
11
+ * Git credential helper를 이용해 특정 레포에 대한 인증 정보를 저장합니다.
12
+ * @param username Git 사용자명
13
+ * @param token Git 토큰
14
+ * @param repoPath 호스트 이후의 경로 예: "my-org/my-repo"
15
+ */
16
+ function installGitCredentials(
11
17
  username,
12
- token
18
+ token,
19
+ repoPath
13
20
  )
14
21
  {
15
- const name = process.platform === "win32" ? "_netrc" : ".netrc";
16
- const file = path.join(os.homedir(), name);
17
- let lines = [];
18
-
19
- if (fs.existsSync(file))
22
+ // credential helper 설정
23
+ if (process.platform === "win32")
20
24
  {
21
- lines = fs.readFileSync(file, "utf-8").split(/\r?\n/);
22
- const filtered = [];
23
- let skip = false;
24
- for (const l of lines)
25
- {
26
- if (l.trim().startsWith("machine git.superfunctions.ai"))
27
- {
28
- skip = true;
29
- }
30
- if (!skip)
31
- {
32
- filtered.push(l);
33
- }
34
- if (skip && l.trim() === "")
35
- {
36
- skip = false;
37
- }
38
- }
39
- lines = filtered;
25
+ execSync("git config --global credential.helper manager-core");
26
+ }
27
+ else
28
+ {
29
+ execSync("git config --global credential.helper store");
40
30
  }
41
31
 
42
- lines.push(
43
- "",
44
- "machine git.superfunctions.ai",
45
- ` login ${username}`,
46
- ` password ${token}`,
32
+ // git credential approve 입력 생성
33
+ const cred = [
34
+ "protocol=https",
35
+ "host=git.superfunctions.ai",
36
+ `path=${repoPath}`,
37
+ `username=${username}`,
38
+ `password=${token}`,
47
39
  ""
48
- );
40
+ ].join("\n");
49
41
 
50
- fs.writeFileSync(file, lines.join("\n"), "utf-8");
51
- if (process.platform !== "win32")
52
- {
53
- fs.chmodSync(file, 0o600);
54
- }
55
- console.log(`✔️ Merged netrc: ${file}`);
42
+ execSync("git credential approve", {
43
+ input: cred,
44
+ stdio: ["pipe", "ignore", "inherit"]
45
+ });
46
+
47
+ console.log(`✔️ Stored credentials for git.superfunctions.ai/${repoPath}`);
56
48
  }
57
49
 
58
50
  function mergeGradleInit()
59
51
  {
60
- const dir = path.join(os.homedir(), ".gradle");
61
- const file = path.join(dir, "init.gradle");
62
- const startMarker = "// sf-cli start";
63
- const endMarker = "// sf-cli end";
52
+ const dir = path.join(os.homedir(), ".gradle");
53
+ const file = path.join(dir, "init.gradle");
54
+ const start = "// sf-cli start";
55
+ const end = "// sf-cli end";
56
+ let content = "";
64
57
 
65
- let content = "";
66
58
  if (fs.existsSync(file))
67
59
  {
68
60
  content = fs.readFileSync(file, "utf-8");
69
- const regex = new RegExp(
70
- `${startMarker}[\\s\\S]*?${endMarker}\n?`,
71
- "m"
72
- );
61
+ const regex = new RegExp(`${start}[\s\S]*?${end}\n?`, "m");
73
62
  content = content.replace(regex, "");
74
63
  }
75
64
 
76
65
  const block = [
77
- startMarker,
66
+ start,
78
67
  "allprojects {",
79
68
  " repositories {",
80
69
  " maven {",
@@ -82,13 +71,13 @@ function mergeGradleInit()
82
71
  " url = uri('https://git.superfunctions.ai/api/packages/sf/maven')",
83
72
  " credentials {",
84
73
  " username = System.getenv('SF_USERNAME')",
85
- " password = System.getenv('SF_AUTH_TOKEN')'",
74
+ " password = System.getenv('SF_AUTH_TOKEN')",
86
75
  " }",
87
76
  " }",
88
77
  " mavenCentral()",
89
78
  " }",
90
79
  "}",
91
- endMarker,
80
+ end,
92
81
  ""
93
82
  ].join("\n");
94
83
 
@@ -130,6 +119,8 @@ export function login()
130
119
  }
131
120
 
132
121
  mergeGradleInit();
122
+
123
+ // npm registry 설정 (생략)
133
124
  try
134
125
  {
135
126
  execSync(
@@ -137,19 +128,19 @@ export function login()
137
128
  { stdio: "inherit", env: process.env }
138
129
  );
139
130
  execSync(
140
- `npm config set //git.superfunctions.ai/api/packages/sf/npm/:_authToken "${token}"`,
131
+ `npm config set //git.superfunctions.ai/api/packages/sf/npm/:_authToken \"${token}\"`,
141
132
  { stdio: "inherit", env: process.env }
142
133
  );
143
- console.log(
144
- "✔️ npm registry and authToken set via npm config"
145
- );
134
+ console.log("✔️ npm registry and authToken set via npm config");
146
135
  }
147
136
  catch (e)
148
137
  {
149
138
  console.error("❌ npm config set failed:", e);
150
139
  }
151
140
 
152
- mergeNetrc(username, token);
141
+ // 2개 레포에 대해 각각 자격증명 저장
142
+ installGitCredentials(username, token, `${projectSlug}/${projectSlug}-server`);
143
+ installGitCredentials(username, token, `${projectSlug}/${projectSlug}-app`);
153
144
 
154
145
  res.writeHead(200, { "Content-Type": "text/plain" });
155
146
  res.end("✅ Login successful! You can now close this window.");
@@ -157,10 +148,10 @@ export function login()
157
148
  console.log();
158
149
  console.log("💡 Tips:");
159
150
  console.log(
160
- ` git clone git.superfunctions.ai/${projectSlug}/${projectSlug}-server`
151
+ ` git clone https://git.superfunctions.ai/${projectSlug}/${projectSlug}-server`
161
152
  );
162
153
  console.log(
163
- ` git clone git.superfunctions.ai/${projectSlug}/${projectSlug}-app`
154
+ ` git clone https://git.superfunctions.ai/${projectSlug}/${projectSlug}-app`
164
155
  );
165
156
  console.log();
166
157
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@spfn/cli",
3
- "version": "0.0.3",
3
+ "version": "0.0.5",
4
4
  "description": "Superfunction CLI",
5
5
  "keywords": [
6
6
  "cli",