@spfn/cli 0.0.6 → 0.0.8
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/lib/index.js +1 -1
- package/lib/login.js +52 -69
- package/package.json +7 -5
package/lib/index.js
CHANGED
package/lib/login.js
CHANGED
@@ -1,11 +1,10 @@
|
|
1
1
|
import http from "http";
|
2
2
|
import open from "open";
|
3
|
-
import fs from "fs";
|
4
|
-
import os from "os";
|
5
|
-
import path from "path";
|
6
3
|
import { execSync } from "child_process";
|
7
4
|
|
8
|
-
const
|
5
|
+
const isDev = process.env.NODE_ENV === "development" || process.env.SF_ENV === "local";
|
6
|
+
const GIT_HOST = isDev ? "gitea:13000" : "git.superfunctions.ai";
|
7
|
+
const GIT_PROTOCOL = isDev ? "http" : "https";
|
9
8
|
|
10
9
|
/**
|
11
10
|
* Git credential helper를 이용해 특정 레포에 대한 인증 정보를 저장합니다.
|
@@ -16,10 +15,14 @@ const PORT = 5678;
|
|
16
15
|
function installGitCredentials(
|
17
16
|
username,
|
18
17
|
token,
|
19
|
-
|
18
|
+
{
|
19
|
+
protocol = "https",
|
20
|
+
host,
|
21
|
+
path // optional
|
22
|
+
}
|
20
23
|
)
|
21
24
|
{
|
22
|
-
// credential helper 설정
|
25
|
+
// credential helper 설정 (글로벌, 1회면 충분)
|
23
26
|
if (process.platform === "win32")
|
24
27
|
{
|
25
28
|
execSync("git config --global credential.helper manager-core");
|
@@ -31,62 +34,30 @@ function installGitCredentials(
|
|
31
34
|
|
32
35
|
// git credential approve 입력 생성
|
33
36
|
const cred = [
|
34
|
-
|
35
|
-
|
36
|
-
`path=${
|
37
|
+
`protocol=${protocol}`,
|
38
|
+
`host=${host}`,
|
39
|
+
path ? `path=${path}` : null,
|
37
40
|
`username=${username}`,
|
38
41
|
`password=${token}`,
|
39
42
|
""
|
40
|
-
].join("\n");
|
43
|
+
].filter(Boolean).join("\n");
|
41
44
|
|
42
45
|
execSync("git credential approve", {
|
43
46
|
input: cred,
|
44
47
|
stdio: ["pipe", "ignore", "inherit"]
|
45
48
|
});
|
46
49
|
|
47
|
-
|
48
|
-
}
|
49
|
-
|
50
|
-
function mergeGradleInit(username, token)
|
51
|
-
{
|
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 = "";
|
57
|
-
|
58
|
-
if (fs.existsSync(file))
|
50
|
+
if (path)
|
59
51
|
{
|
60
|
-
|
61
|
-
|
62
|
-
|
52
|
+
console.log(`✔️ Stored credentials for ${protocol}://${host}/${path}`);
|
53
|
+
}
|
54
|
+
else
|
55
|
+
{
|
56
|
+
console.log(`✔️ Stored credentials for ${protocol}://${host}`);
|
63
57
|
}
|
64
|
-
|
65
|
-
const block = [
|
66
|
-
start,
|
67
|
-
"allprojects {",
|
68
|
-
" repositories {",
|
69
|
-
" maven {",
|
70
|
-
" name = 'Gitea'",
|
71
|
-
" url = uri('https://git.superfunctions.ai/api/packages/sf/maven')",
|
72
|
-
" credentials {",
|
73
|
-
` username = '${username}'`,
|
74
|
-
` password = '${token}'`,
|
75
|
-
" }",
|
76
|
-
" }",
|
77
|
-
" mavenCentral()",
|
78
|
-
" }",
|
79
|
-
"}",
|
80
|
-
end,
|
81
|
-
""
|
82
|
-
].join("\n");
|
83
|
-
|
84
|
-
fs.mkdirSync(dir, { recursive: true });
|
85
|
-
fs.writeFileSync(file, content + "\n" + block, "utf-8");
|
86
|
-
console.log(`✔️ Merged Gradle init script: ${file}`);
|
87
58
|
}
|
88
59
|
|
89
|
-
export function login()
|
60
|
+
export async function login()
|
90
61
|
{
|
91
62
|
try
|
92
63
|
{
|
@@ -111,24 +82,22 @@ export function login()
|
|
111
82
|
{
|
112
83
|
try
|
113
84
|
{
|
114
|
-
const { username, token
|
85
|
+
const { username, token } = JSON.parse(body);
|
115
86
|
if (!username || !token)
|
116
87
|
{
|
117
88
|
res.writeHead(400).end("Missing username or token");
|
118
89
|
return;
|
119
90
|
}
|
120
91
|
|
121
|
-
mergeGradleInit(username, token);
|
122
|
-
|
123
92
|
// npm registry 설정 (생략)
|
124
93
|
try
|
125
94
|
{
|
126
95
|
execSync(
|
127
|
-
`npm config set @sf:registry
|
96
|
+
`npm config set @sf:registry ${GIT_PROTOCOL}://${GIT_HOST}/api/packages/spfn/npm/`,
|
128
97
|
{ stdio: "inherit", env: process.env }
|
129
98
|
);
|
130
99
|
execSync(
|
131
|
-
`npm config set
|
100
|
+
`npm config set //${GIT_HOST}/api/packages/spfn/npm/:_authToken \"${token}\"`,
|
132
101
|
{ stdio: "inherit", env: process.env }
|
133
102
|
);
|
134
103
|
console.log("✔️ npm registry and authToken set via npm config");
|
@@ -139,22 +108,14 @@ export function login()
|
|
139
108
|
}
|
140
109
|
|
141
110
|
// 2개 레포에 대해 각각 자격증명 저장
|
142
|
-
installGitCredentials(username, token,
|
143
|
-
|
111
|
+
installGitCredentials(username, token, {
|
112
|
+
protocol: GIT_PROTOCOL,
|
113
|
+
host: GIT_HOST
|
114
|
+
});
|
144
115
|
|
145
116
|
res.writeHead(200, { "Content-Type": "text/plain" });
|
146
117
|
res.end("✅ Login successful! You can now close this window.");
|
147
118
|
|
148
|
-
console.log();
|
149
|
-
console.log("💡 Tips:");
|
150
|
-
console.log(
|
151
|
-
` git clone https://git.superfunctions.ai/${projectSlug}/${projectSlug}-server`
|
152
|
-
);
|
153
|
-
console.log(
|
154
|
-
` git clone https://git.superfunctions.ai/${projectSlug}/${projectSlug}-app`
|
155
|
-
);
|
156
|
-
console.log();
|
157
|
-
|
158
119
|
server.close();
|
159
120
|
}
|
160
121
|
catch (err)
|
@@ -171,14 +132,36 @@ export function login()
|
|
171
132
|
}
|
172
133
|
});
|
173
134
|
|
174
|
-
|
135
|
+
const port = await getAvailablePort();
|
136
|
+
|
137
|
+
// 로그인 UI 주소도 분기
|
138
|
+
const isDev = process.env.NODE_ENV === "development" || process.env.SF_ENV === "local";
|
139
|
+
const LOGIN_UI_URL = isDev
|
140
|
+
? `http://localhost:3000/cli-login?port=${port}`
|
141
|
+
: `https://console.superfunctions.ai/cli-login?port=${port}`;
|
142
|
+
|
143
|
+
server.listen(port, () =>
|
175
144
|
{
|
176
145
|
console.log("🌐 Opening browser for login...");
|
177
|
-
open(
|
146
|
+
open(LOGIN_UI_URL);
|
178
147
|
});
|
179
148
|
}
|
180
149
|
catch (err)
|
181
150
|
{
|
182
151
|
console.error(err);
|
183
152
|
}
|
184
|
-
}
|
153
|
+
}
|
154
|
+
|
155
|
+
function getAvailablePort(defaultPort = 5678) {
|
156
|
+
return new Promise((resolve) => {
|
157
|
+
const srv = http.createServer();
|
158
|
+
srv.listen(defaultPort, () => {
|
159
|
+
srv.close(() => resolve(defaultPort));
|
160
|
+
});
|
161
|
+
srv.on("error", () => {
|
162
|
+
// 사용 중이면 10000~20000 사이 랜덤 포트
|
163
|
+
const randomPort = Math.floor(Math.random() * 10000) + 10000;
|
164
|
+
resolve(randomPort);
|
165
|
+
});
|
166
|
+
});
|
167
|
+
}
|
package/package.json
CHANGED
@@ -1,7 +1,12 @@
|
|
1
1
|
{
|
2
2
|
"name": "@spfn/cli",
|
3
|
-
"version": "0.0.
|
3
|
+
"version": "0.0.8",
|
4
4
|
"description": "Superfunction CLI",
|
5
|
+
"scripts": {
|
6
|
+
"start": "node lib/index.js",
|
7
|
+
"start:dev": "NODE_ENV=development node lib/index.js",
|
8
|
+
"start:prod": "NODE_ENV=production node lib/index.js"
|
9
|
+
},
|
5
10
|
"keywords": [
|
6
11
|
"cli",
|
7
12
|
"superfunction",
|
@@ -12,7 +17,7 @@
|
|
12
17
|
"homepage": "https://console.superfunctions.ai",
|
13
18
|
"repository": {
|
14
19
|
"type": "git",
|
15
|
-
"url": "https://git.superfunctions.ai/
|
20
|
+
"url": "https://git.superfunctions.ai/spfn/sf-cli.git"
|
16
21
|
},
|
17
22
|
"license": "MIT",
|
18
23
|
"author": "Superfunction Ray <rayim@superfunctions.ai>",
|
@@ -27,9 +32,6 @@
|
|
27
32
|
"files": [
|
28
33
|
"lib/**/*"
|
29
34
|
],
|
30
|
-
"scripts": {
|
31
|
-
"start": "node lib/index.js"
|
32
|
-
},
|
33
35
|
"dependencies": {
|
34
36
|
"commander": "^13.1.0",
|
35
37
|
"open": "^10.1.1"
|