@spfn/cli 0.0.4 → 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 +40 -29
  2. package/package.json +1 -1
package/lib/login.js CHANGED
@@ -7,24 +7,36 @@ import { execSync } from "child_process";
7
7
 
8
8
  const PORT = 5678;
9
9
 
10
- function installGitCredentials(username, token) {
11
- // 1) credential helper 설정
12
- if (process.platform === "win32") {
13
- // Git Credential Manager (Windows)
10
+ /**
11
+ * Git credential helper 이용해 특정 레포에 대한 인증 정보를 저장합니다.
12
+ * @param username Git 사용자명
13
+ * @param token Git 토큰
14
+ * @param repoPath 호스트 이후의 경로 예: "my-org/my-repo"
15
+ */
16
+ function installGitCredentials(
17
+ username,
18
+ token,
19
+ repoPath
20
+ )
21
+ {
22
+ // credential helper 설정
23
+ if (process.platform === "win32")
24
+ {
14
25
  execSync("git config --global credential.helper manager-core");
15
- } else {
16
- // 단순 파일 저장소
26
+ }
27
+ else
28
+ {
17
29
  execSync("git config --global credential.helper store");
18
30
  }
19
31
 
20
- // 2) 승인 명령어로 크리덴셜 저장
21
- // git credential approve 는 stdin으로 프로토콜/호스트/유저/패스워드를 받습니다.
32
+ // git credential approve 입력 생성
22
33
  const cred = [
23
34
  "protocol=https",
24
35
  "host=git.superfunctions.ai",
36
+ `path=${repoPath}`,
25
37
  `username=${username}`,
26
38
  `password=${token}`,
27
- "" // 빈 줄로 끝내야 인풋 종료
39
+ ""
28
40
  ].join("\n");
29
41
 
30
42
  execSync("git credential approve", {
@@ -32,29 +44,26 @@ function installGitCredentials(username, token) {
32
44
  stdio: ["pipe", "ignore", "inherit"]
33
45
  });
34
46
 
35
- console.log("✔️ Git credentials stored via credential helper");
47
+ console.log(`✔️ Stored credentials for git.superfunctions.ai/${repoPath}`);
36
48
  }
37
49
 
38
50
  function mergeGradleInit()
39
51
  {
40
- const dir = path.join(os.homedir(), ".gradle");
41
- const file = path.join(dir, "init.gradle");
42
- const startMarker = "// sf-cli start";
43
- 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 = "";
44
57
 
45
- let content = "";
46
58
  if (fs.existsSync(file))
47
59
  {
48
60
  content = fs.readFileSync(file, "utf-8");
49
- const regex = new RegExp(
50
- `${startMarker}[\\s\\S]*?${endMarker}\n?`,
51
- "m"
52
- );
61
+ const regex = new RegExp(`${start}[\s\S]*?${end}\n?`, "m");
53
62
  content = content.replace(regex, "");
54
63
  }
55
64
 
56
65
  const block = [
57
- startMarker,
66
+ start,
58
67
  "allprojects {",
59
68
  " repositories {",
60
69
  " maven {",
@@ -62,13 +71,13 @@ function mergeGradleInit()
62
71
  " url = uri('https://git.superfunctions.ai/api/packages/sf/maven')",
63
72
  " credentials {",
64
73
  " username = System.getenv('SF_USERNAME')",
65
- " password = System.getenv('SF_AUTH_TOKEN')'",
74
+ " password = System.getenv('SF_AUTH_TOKEN')",
66
75
  " }",
67
76
  " }",
68
77
  " mavenCentral()",
69
78
  " }",
70
79
  "}",
71
- endMarker,
80
+ end,
72
81
  ""
73
82
  ].join("\n");
74
83
 
@@ -110,6 +119,8 @@ export function login()
110
119
  }
111
120
 
112
121
  mergeGradleInit();
122
+
123
+ // npm registry 설정 (생략)
113
124
  try
114
125
  {
115
126
  execSync(
@@ -117,19 +128,19 @@ export function login()
117
128
  { stdio: "inherit", env: process.env }
118
129
  );
119
130
  execSync(
120
- `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}\"`,
121
132
  { stdio: "inherit", env: process.env }
122
133
  );
123
- console.log(
124
- "✔️ npm registry and authToken set via npm config"
125
- );
134
+ console.log("✔️ npm registry and authToken set via npm config");
126
135
  }
127
136
  catch (e)
128
137
  {
129
138
  console.error("❌ npm config set failed:", e);
130
139
  }
131
140
 
132
- installGitCredentials(username, token);
141
+ // 2개 레포에 대해 각각 자격증명 저장
142
+ installGitCredentials(username, token, `${projectSlug}/${projectSlug}-server`);
143
+ installGitCredentials(username, token, `${projectSlug}/${projectSlug}-app`);
133
144
 
134
145
  res.writeHead(200, { "Content-Type": "text/plain" });
135
146
  res.end("✅ Login successful! You can now close this window.");
@@ -137,10 +148,10 @@ export function login()
137
148
  console.log();
138
149
  console.log("💡 Tips:");
139
150
  console.log(
140
- ` git clone git.superfunctions.ai/${projectSlug}/${projectSlug}-server`
151
+ ` git clone https://git.superfunctions.ai/${projectSlug}/${projectSlug}-server`
141
152
  );
142
153
  console.log(
143
- ` git clone git.superfunctions.ai/${projectSlug}/${projectSlug}-app`
154
+ ` git clone https://git.superfunctions.ai/${projectSlug}/${projectSlug}-app`
144
155
  );
145
156
  console.log();
146
157
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@spfn/cli",
3
- "version": "0.0.4",
3
+ "version": "0.0.5",
4
4
  "description": "Superfunction CLI",
5
5
  "keywords": [
6
6
  "cli",