@lmcuong29/lublue-cli 1.1.0-beta.3
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.
Potentially problematic release.
This version of @lmcuong29/lublue-cli might be problematic. Click here for more details.
- package/LICENSE.md +21 -0
- package/README.md +10 -0
- package/dist/commands/login.d.ts +3 -0
- package/dist/commands/login.d.ts.map +1 -0
- package/dist/commands/login.js +5 -0
- package/dist/commands/login.js.map +1 -0
- package/dist/commands/logout.d.ts +3 -0
- package/dist/commands/logout.d.ts.map +1 -0
- package/dist/commands/logout.js +51 -0
- package/dist/commands/logout.js.map +1 -0
- package/dist/commands/select.d.ts +3 -0
- package/dist/commands/select.d.ts.map +1 -0
- package/dist/commands/select.js +19 -0
- package/dist/commands/select.js.map +1 -0
- package/dist/commands/theme.d.ts +3 -0
- package/dist/commands/theme.d.ts.map +1 -0
- package/dist/commands/theme.js +222 -0
- package/dist/commands/theme.js.map +1 -0
- package/dist/commands/whoiam.d.ts +3 -0
- package/dist/commands/whoiam.d.ts.map +1 -0
- package/dist/commands/whoiam.js +64 -0
- package/dist/commands/whoiam.js.map +1 -0
- package/dist/config/app-config.d.ts +3 -0
- package/dist/config/app-config.d.ts.map +1 -0
- package/dist/config/app-config.js +7 -0
- package/dist/config/app-config.js.map +1 -0
- package/dist/config/config.json +63 -0
- package/dist/helper/auth.d.ts +6 -0
- package/dist/helper/auth.d.ts.map +1 -0
- package/dist/helper/auth.js +146 -0
- package/dist/helper/auth.js.map +1 -0
- package/dist/helper/axios_hrv.d.ts +3 -0
- package/dist/helper/axios_hrv.d.ts.map +1 -0
- package/dist/helper/axios_hrv.js +82 -0
- package/dist/helper/axios_hrv.js.map +1 -0
- package/dist/helper/check_version.d.ts +8 -0
- package/dist/helper/check_version.d.ts.map +1 -0
- package/dist/helper/check_version.js +55 -0
- package/dist/helper/check_version.js.map +1 -0
- package/dist/helper/conf.d.ts +30 -0
- package/dist/helper/conf.d.ts.map +1 -0
- package/dist/helper/conf.js +93 -0
- package/dist/helper/conf.js.map +1 -0
- package/dist/helper/constants.d.ts +5 -0
- package/dist/helper/constants.d.ts.map +1 -0
- package/dist/helper/constants.js +5 -0
- package/dist/helper/constants.js.map +1 -0
- package/dist/helper/dotfile.d.ts +14 -0
- package/dist/helper/dotfile.d.ts.map +1 -0
- package/dist/helper/dotfile.js +53 -0
- package/dist/helper/dotfile.js.map +1 -0
- package/dist/helper/files.d.ts +14 -0
- package/dist/helper/files.d.ts.map +1 -0
- package/dist/helper/files.js +431 -0
- package/dist/helper/files.js.map +1 -0
- package/dist/helper/haravan-cli-error.d.ts +4 -0
- package/dist/helper/haravan-cli-error.d.ts.map +1 -0
- package/dist/helper/haravan-cli-error.js +10 -0
- package/dist/helper/haravan-cli-error.js.map +1 -0
- package/dist/helper/haravan_api.d.ts +9 -0
- package/dist/helper/haravan_api.d.ts.map +1 -0
- package/dist/helper/haravan_api.js +192 -0
- package/dist/helper/haravan_api.js.map +1 -0
- package/dist/helper/messages.d.ts +21 -0
- package/dist/helper/messages.d.ts.map +1 -0
- package/dist/helper/messages.js +29 -0
- package/dist/helper/messages.js.map +1 -0
- package/dist/helper/utils.d.ts +9 -0
- package/dist/helper/utils.d.ts.map +1 -0
- package/dist/helper/utils.js +86 -0
- package/dist/helper/utils.js.map +1 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +72 -0
- package/dist/index.js.map +1 -0
- package/package.json +74 -0
- package/tsconfig.json +34 -0
|
@@ -0,0 +1,192 @@
|
|
|
1
|
+
import httpHrvAxios from "./axios_hrv.js";
|
|
2
|
+
import config from "../config/app-config.js";
|
|
3
|
+
import { getOAuthSettings } from "./utils.js";
|
|
4
|
+
import { DOTFILE } from "./dotfile.js";
|
|
5
|
+
import fs from "fs-extra";
|
|
6
|
+
import makeDir from "make-dir";
|
|
7
|
+
import path from "path";
|
|
8
|
+
// Hàm chung để xử lý rate limit
|
|
9
|
+
const handleRateLimit = async (response, sleepLimit = true) => {
|
|
10
|
+
if (response?.headers?.["x-haravan-api-call-limit"] && sleepLimit) {
|
|
11
|
+
let limit = response?.headers?.["x-haravan-api-call-limit"];
|
|
12
|
+
let currentCall = limit ? limit.split("/")[0] : null;
|
|
13
|
+
let totalCall = limit ? limit.split("/")[1] : null;
|
|
14
|
+
if (Number(currentCall) >= 70) {
|
|
15
|
+
console.log(`Current call: ${currentCall}/${totalCall}`);
|
|
16
|
+
console.log(`You have reached the limit of 70 calls. Please wait 1 second and try again.`);
|
|
17
|
+
await new Promise((resolve) => setTimeout(resolve, 1000));
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
};
|
|
21
|
+
const HaravanAPI = {
|
|
22
|
+
get: async function (endPoint, type = "json", isOmni = true, sleepLimit = true) {
|
|
23
|
+
try {
|
|
24
|
+
const options = {
|
|
25
|
+
url: endPoint,
|
|
26
|
+
method: "get",
|
|
27
|
+
headers: {},
|
|
28
|
+
timeout: 15 * 1000,
|
|
29
|
+
};
|
|
30
|
+
if (isOmni) {
|
|
31
|
+
options.url = config.host_https + endPoint;
|
|
32
|
+
let getSettingLocal = null;
|
|
33
|
+
let checkExistSettingProject = await DOTFILE.PROJECT().exists();
|
|
34
|
+
if (checkExistSettingProject)
|
|
35
|
+
getSettingLocal = await DOTFILE.PROJECT().read();
|
|
36
|
+
let getToken = await getOAuthSettings(false, getSettingLocal?.org_id);
|
|
37
|
+
options.headers["Authorization"] = `Bearer ${getToken.access_token}`;
|
|
38
|
+
options.headers["User-Agent"] = `onapp_${config.appslug}`;
|
|
39
|
+
}
|
|
40
|
+
if (type === "image") {
|
|
41
|
+
options.responseType = "arraybuffer";
|
|
42
|
+
}
|
|
43
|
+
let response = await httpHrvAxios(options);
|
|
44
|
+
await handleRateLimit(response, sleepLimit);
|
|
45
|
+
if (response.status === 200)
|
|
46
|
+
return response.data;
|
|
47
|
+
return null;
|
|
48
|
+
}
|
|
49
|
+
catch (error) {
|
|
50
|
+
if (error && error.response && error.response.status === 422)
|
|
51
|
+
throw error;
|
|
52
|
+
throw `Error HaravanAPI GET`;
|
|
53
|
+
}
|
|
54
|
+
},
|
|
55
|
+
post: async function (endPoint, data, isFile = false, isOmni = true, sleepLimit = true) {
|
|
56
|
+
try {
|
|
57
|
+
const options = {
|
|
58
|
+
url: endPoint,
|
|
59
|
+
method: "post",
|
|
60
|
+
headers: {
|
|
61
|
+
"Content-Type": "application/json",
|
|
62
|
+
},
|
|
63
|
+
timeout: 15 * 1000,
|
|
64
|
+
};
|
|
65
|
+
if (isFile) {
|
|
66
|
+
options.data = data;
|
|
67
|
+
}
|
|
68
|
+
else {
|
|
69
|
+
options.data = JSON.stringify(data);
|
|
70
|
+
}
|
|
71
|
+
if (isOmni) {
|
|
72
|
+
options.url = config.host_https + endPoint;
|
|
73
|
+
let getSettingLocal = await DOTFILE.PROJECT().read();
|
|
74
|
+
let getToken = await getOAuthSettings(false, getSettingLocal?.org_id);
|
|
75
|
+
options.headers["Authorization"] = `Bearer ${getToken.access_token}`;
|
|
76
|
+
options.headers["User-Agent"] = `onapp_${config.appslug}`;
|
|
77
|
+
}
|
|
78
|
+
let response = await httpHrvAxios(options);
|
|
79
|
+
await handleRateLimit(response, sleepLimit);
|
|
80
|
+
if (response.status === 200)
|
|
81
|
+
return response.data;
|
|
82
|
+
return null;
|
|
83
|
+
}
|
|
84
|
+
catch (error) {
|
|
85
|
+
console.log("An error has occurred. You need to login again");
|
|
86
|
+
return null;
|
|
87
|
+
}
|
|
88
|
+
},
|
|
89
|
+
put: async function (endPoint, data, isFile = false, isOmni = true, sleepLimit = true) {
|
|
90
|
+
try {
|
|
91
|
+
const options = {
|
|
92
|
+
url: endPoint,
|
|
93
|
+
method: "put",
|
|
94
|
+
headers: {
|
|
95
|
+
"Content-Type": "application/json",
|
|
96
|
+
},
|
|
97
|
+
timeout: 15 * 1000,
|
|
98
|
+
};
|
|
99
|
+
if (isFile) {
|
|
100
|
+
options.data = data;
|
|
101
|
+
}
|
|
102
|
+
else {
|
|
103
|
+
options.data = JSON.stringify(data);
|
|
104
|
+
}
|
|
105
|
+
if (isOmni) {
|
|
106
|
+
options.url = config.host_https + endPoint;
|
|
107
|
+
let getSettingLocal = await DOTFILE.PROJECT().read();
|
|
108
|
+
let getToken = await getOAuthSettings(false, getSettingLocal?.org_id);
|
|
109
|
+
options.headers["Authorization"] = `Bearer ${getToken.access_token}`;
|
|
110
|
+
options.headers["User-Agent"] = `onapp_${config.appslug}`;
|
|
111
|
+
}
|
|
112
|
+
let response = await httpHrvAxios(options);
|
|
113
|
+
await handleRateLimit(response, sleepLimit);
|
|
114
|
+
if (response.status === 200 || response.status === 201)
|
|
115
|
+
return response.data;
|
|
116
|
+
return null;
|
|
117
|
+
}
|
|
118
|
+
catch (error) {
|
|
119
|
+
console.log("An error has occurred. You need to login again");
|
|
120
|
+
return null;
|
|
121
|
+
}
|
|
122
|
+
},
|
|
123
|
+
delete: async function (endPoint, isOmni = true, sleepLimit = true) {
|
|
124
|
+
try {
|
|
125
|
+
const options = {
|
|
126
|
+
url: endPoint,
|
|
127
|
+
method: "delete",
|
|
128
|
+
headers: {},
|
|
129
|
+
timeout: 15 * 1000,
|
|
130
|
+
};
|
|
131
|
+
if (isOmni) {
|
|
132
|
+
options.url = config.host_https + endPoint;
|
|
133
|
+
let getSettingLocal = await DOTFILE.PROJECT().read();
|
|
134
|
+
let getToken = await getOAuthSettings(false, getSettingLocal?.org_id);
|
|
135
|
+
options.headers["Authorization"] = `Bearer ${getToken.access_token}`;
|
|
136
|
+
options.headers["User-Agent"] = `onapp_${config.appslug}`;
|
|
137
|
+
}
|
|
138
|
+
let response = await httpHrvAxios(options);
|
|
139
|
+
await handleRateLimit(response, sleepLimit);
|
|
140
|
+
if (response.status === 200)
|
|
141
|
+
return response.data;
|
|
142
|
+
return null;
|
|
143
|
+
}
|
|
144
|
+
catch (error) {
|
|
145
|
+
console.log("An error has occurred. You need to login again");
|
|
146
|
+
return null;
|
|
147
|
+
}
|
|
148
|
+
},
|
|
149
|
+
downloadStreamFile: async function (fileUrl, outputLocationPath) {
|
|
150
|
+
try {
|
|
151
|
+
await makeDir(path.dirname(outputLocationPath));
|
|
152
|
+
const writer = await fs.createWriteStream(outputLocationPath);
|
|
153
|
+
return httpHrvAxios({
|
|
154
|
+
method: "get",
|
|
155
|
+
url: fileUrl,
|
|
156
|
+
responseType: "stream",
|
|
157
|
+
timeout: 15 * 1000,
|
|
158
|
+
})
|
|
159
|
+
.then((response) => {
|
|
160
|
+
return new Promise((resolve, reject) => {
|
|
161
|
+
response.data.pipe(writer);
|
|
162
|
+
let error = null;
|
|
163
|
+
writer.on("error", (err) => {
|
|
164
|
+
error = err;
|
|
165
|
+
writer.close();
|
|
166
|
+
reject(err);
|
|
167
|
+
});
|
|
168
|
+
writer.on("close", () => {
|
|
169
|
+
if (!error) {
|
|
170
|
+
resolve(true);
|
|
171
|
+
}
|
|
172
|
+
else
|
|
173
|
+
reject(error);
|
|
174
|
+
});
|
|
175
|
+
});
|
|
176
|
+
})
|
|
177
|
+
.catch((error) => {
|
|
178
|
+
if (error.code === "ECONNABORTED") {
|
|
179
|
+
throw `Lỗi timeout khi tải file: Quá thời gian 15 giây`;
|
|
180
|
+
}
|
|
181
|
+
throw `Lỗi khi tải file: ${error.message}`;
|
|
182
|
+
});
|
|
183
|
+
}
|
|
184
|
+
catch (error) {
|
|
185
|
+
if (error && error.response && error.response.status === 422)
|
|
186
|
+
throw error;
|
|
187
|
+
throw `Error HaravanAPI downloadStreamFile`;
|
|
188
|
+
}
|
|
189
|
+
},
|
|
190
|
+
};
|
|
191
|
+
export default HaravanAPI;
|
|
192
|
+
//# sourceMappingURL=haravan_api.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"haravan_api.js","sourceRoot":"","sources":["../../src/helper/haravan_api.ts"],"names":[],"mappings":"AAAA,OAAO,YAAY,MAAM,gBAAgB,CAAC;AAC1C,OAAO,MAAM,MAAM,yBAAyB,CAAC;AAC7C,OA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,CAAC;QACL,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YAChB,IAAI,KAAK,IAAI,KAAK,CAAC,QAAQ,IAAI,KAAK,CAAC,QAAQ,CAAC,MAAM,KAAK,GAAG;gBAAE,MAAM,KAAK,CAAC;YAC1E,MAAM,qCAAqC,CAAC;QAC7C,CAAC;IACF,CAAC;CACD,CAAC;AAEF,eAAe,UAAU,CAAC"}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
export declare const ERROR: {
|
|
2
|
+
UNAUTHORIZED: string;
|
|
3
|
+
FS_DIR_WRITE: string;
|
|
4
|
+
FS_FILE_WRITE: string;
|
|
5
|
+
NO_CREDENTIALS: (local: any) => string;
|
|
6
|
+
RATE_LIMIT: string;
|
|
7
|
+
SETTINGS_DNE: () => string;
|
|
8
|
+
UNAUTHENTICATED: string;
|
|
9
|
+
};
|
|
10
|
+
export declare const LOG: {
|
|
11
|
+
AUTH_PAGE_SUCCESSFUL: string;
|
|
12
|
+
AUTH_SUCCESSFUL: string;
|
|
13
|
+
AUTHORIZE: (authUrl: any) => string;
|
|
14
|
+
FINDING_THEMES_DNE: string;
|
|
15
|
+
FINDING_THEMES: string;
|
|
16
|
+
PULLING: string;
|
|
17
|
+
EXPORTING: string;
|
|
18
|
+
PUSHING: string;
|
|
19
|
+
SAVED_CREDS: (isLocalCreds: any) => string;
|
|
20
|
+
};
|
|
21
|
+
//# sourceMappingURL=messages.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"messages.d.ts","sourceRoot":"","sources":["../../src/helper/messages.ts"],"names":[],"mappings":"AAIA,eAAO,MAAM,KAAK;;;;4BAIO,GAAG;;;;CAK3B,CAAC;AAGF,eAAO,MAAM,GAAG;;;yBAGM,GAAG;;;;;;gCAMI,GAAG;CAK/B,CAAC"}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { Conf } from "./conf.js";
|
|
2
|
+
import { PROJECT_NAME } from "./constants.js";
|
|
3
|
+
const config = Conf.get();
|
|
4
|
+
export const ERROR = {
|
|
5
|
+
UNAUTHORIZED: "Error retrieving access token: ",
|
|
6
|
+
FS_DIR_WRITE: "Could not create directory.",
|
|
7
|
+
FS_FILE_WRITE: "Could not write file.",
|
|
8
|
+
NO_CREDENTIALS: (local) => `Could not read API credentials. Are you logged in ${local ? "locally" : "globally"}?`,
|
|
9
|
+
RATE_LIMIT: "Rate limit exceeded. Check quota.",
|
|
10
|
+
SETTINGS_DNE: () => `
|
|
11
|
+
No valid ${config.projectConfig} project file.\nYou need Login first - [haravan login].`,
|
|
12
|
+
UNAUTHENTICATED: "Error: Unauthenticated request: Please try again.",
|
|
13
|
+
};
|
|
14
|
+
// Log messages (some logs take required params)
|
|
15
|
+
export const LOG = {
|
|
16
|
+
AUTH_PAGE_SUCCESSFUL: "Logged in! You may close this page. ",
|
|
17
|
+
AUTH_SUCCESSFUL: "Authorization successful.",
|
|
18
|
+
AUTHORIZE: (authUrl) => `🔑 Authorize ${PROJECT_NAME} by visiting this url:\n${authUrl}\n`,
|
|
19
|
+
FINDING_THEMES_DNE: "No themes found.",
|
|
20
|
+
FINDING_THEMES: "Finding your themes",
|
|
21
|
+
PULLING: "Pulling files…",
|
|
22
|
+
EXPORTING: "Exporting files...",
|
|
23
|
+
PUSHING: "Pushing files…",
|
|
24
|
+
SAVED_CREDS: (isLocalCreds) => isLocalCreds
|
|
25
|
+
? `Local credentials saved to: ${config.authLocal}.
|
|
26
|
+
*Be sure to never commit this file!* It's basically a password.`
|
|
27
|
+
: `Default credentials saved to: ${config.auth}.`,
|
|
28
|
+
};
|
|
29
|
+
//# sourceMappingURL=messages.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"messages.js","sourceRoot":"","sources":["../../src/helper/messages.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AACjC,OAAO,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;AAC9C,MAAM,MAAM,GAAG,IAAI,CAAC,GAAG,EAAE,CAAC;AAE1B,MAAM,CAAC,MAAM,KAAK,GAAG;IACpB,YAAY,EAAE,iCAAiC;IAC/C,YAAY,EAAE,6BAA6B;IAC3C,aAAa,EAAE,uBAAuB;IACtC,cAAc,EAAE,CAAC,KAAU,EAAE,EAAE,CAAC,qDAAqD,KAAK,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,UAAU,GAAG;IACtH,UAAU,EAAE,mCAAmC;IAC/C,YAAY,EAAE,GAAG,EAAE,CAAC;WACV,MAAM,CAAC,aAAa,yDAAyD;IACvF,eAAe,EAAE,mDAAmD;CACpE,CAAC;AAEF,gDAAgD;AAChD,MAAM,CAAC,MAAM,GAAG,GAAG;IAClB,oBAAoB,EAAE,sCAAsC;IAC5D,eAAe,EAAE,2BAA2B;IAC5C,SAAS,EAAE,CAAC,OAAY,EAAE,EAAE,CAAC,gBAAgB,YAAY,2BAA2B,OAAO,IAAI;IAC/F,kBAAkB,EAAE,kBAAkB;IACtC,cAAc,EAAE,qBAAqB;IACrC,OAAO,EAAE,gBAAgB;IACzB,SAAS,EAAE,oBAAoB;IAC/B,OAAO,EAAE,gBAAgB;IACzB,WAAW,EAAE,CAAC,YAAiB,EAAE,EAAE,CAClC,YAAY;QACX,CAAC,CAAC,+BAA+B,MAAM,CAAC,SAAS;gEACY;QAC7D,CAAC,CAAC,iCAAiC,MAAM,CAAC,IAAI,GAAG;CACnD,CAAC"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import ora from "ora";
|
|
2
|
+
export declare const getOAuthSettings: (local: any, org_id?: any) => Promise<any>;
|
|
3
|
+
export declare const spinner: ora.Ora;
|
|
4
|
+
/** Stops the spinner if it is spinning */
|
|
5
|
+
export declare const stopSpinner: () => void;
|
|
6
|
+
export declare const getErrorMessage: (value: any) => any;
|
|
7
|
+
export declare const getProjectSettings: () => Promise<any>;
|
|
8
|
+
export declare const makeRandom: (length: any) => Promise<string>;
|
|
9
|
+
//# sourceMappingURL=utils.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../src/helper/utils.ts"],"names":[],"mappings":"AAAA,OAAO,GAAG,MAAM,KAAK,CAAC;AAOtB,eAAO,MAAM,gBAAgB,UAAiB,GAAG,WAAU,GAAG,iBAe7D,CAAC;AAEF,eAAO,MAAM,OAAO,SAAQ,CAAC;AAC7B,0CAA0C;AAC1C,eAAO,MAAM,WAAW,YAIvB,CAAC;AACF,eAAO,MAAM,eAAe,UAAW,GAAG,QAqBzC,CAAC;AAEF,eAAO,MAAM,kBAAkB,oBAqB9B,CAAC;AAEF,eAAO,MAAM,UAAU,WAAkB,GAAG,oBAU3C,CAAC"}
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
import ora from "ora";
|
|
2
|
+
import { HaravanCliError } from "./haravan-cli-error.js";
|
|
3
|
+
import { Conf } from "./conf.js";
|
|
4
|
+
import { DOTFILE } from "./dotfile.js";
|
|
5
|
+
import { ERROR } from "./messages.js";
|
|
6
|
+
const config = Conf.get();
|
|
7
|
+
export const getOAuthSettings = async (local, org_id = null) => {
|
|
8
|
+
var _a;
|
|
9
|
+
try {
|
|
10
|
+
const result = await DOTFILE.AUTH(local).read();
|
|
11
|
+
if (result && Object.keys(result).length === 1) {
|
|
12
|
+
return result[Object.keys(result)[0]];
|
|
13
|
+
}
|
|
14
|
+
if (org_id) {
|
|
15
|
+
return result[org_id];
|
|
16
|
+
}
|
|
17
|
+
return null;
|
|
18
|
+
}
|
|
19
|
+
catch (error) {
|
|
20
|
+
// throw new HaravanCliError((_a = getErrorMessage(error)) !== null && _a !== void 0 ? _a : ERROR.NO_CREDENTIALS(local));
|
|
21
|
+
}
|
|
22
|
+
};
|
|
23
|
+
export const spinner = ora(); // new Spinner();
|
|
24
|
+
/** Stops the spinner if it is spinning */
|
|
25
|
+
export const stopSpinner = () => {
|
|
26
|
+
if (spinner.isSpinning) {
|
|
27
|
+
spinner.stop();
|
|
28
|
+
}
|
|
29
|
+
};
|
|
30
|
+
export const getErrorMessage = (value) => {
|
|
31
|
+
// Errors are weird. The API returns interesting error structures.
|
|
32
|
+
// TODO(timmerman) This will need to be standardized. Waiting for the API to
|
|
33
|
+
// change error model. Don't review this method now.
|
|
34
|
+
if (value && typeof value.error === "string") {
|
|
35
|
+
return JSON.parse(value.error).error;
|
|
36
|
+
}
|
|
37
|
+
if ((value === null || value === void 0 ? void 0 : value.statusCode) === 401 ||
|
|
38
|
+
((value === null || value === void 0 ? void 0 : value.error) && value.error.error && value.error.error.code === 401)) {
|
|
39
|
+
// TODO check if local creds exist:
|
|
40
|
+
return ERROR.UNAUTHENTICATED;
|
|
41
|
+
}
|
|
42
|
+
if (value && value.code === 429) {
|
|
43
|
+
return ERROR.RATE_LIMIT;
|
|
44
|
+
}
|
|
45
|
+
if (value === null || value === void 0 ? void 0 : value.error) {
|
|
46
|
+
return `~~ API ERROR (${value.statusCode || value.error.code})=\n${value.error}`;
|
|
47
|
+
}
|
|
48
|
+
return undefined;
|
|
49
|
+
};
|
|
50
|
+
export const getProjectSettings = async () => {
|
|
51
|
+
const dotfile = DOTFILE.PROJECT();
|
|
52
|
+
try {
|
|
53
|
+
if (await dotfile.exists()) {
|
|
54
|
+
// Found a dotfile, but does it have the settings, or is it corrupted?
|
|
55
|
+
try {
|
|
56
|
+
const settings = await dotfile.read();
|
|
57
|
+
// Settings must have the script ID. Otherwise we err.
|
|
58
|
+
if (settings)
|
|
59
|
+
return settings;
|
|
60
|
+
return {};
|
|
61
|
+
}
|
|
62
|
+
catch (error) {
|
|
63
|
+
// throw new HaravanCliError(ERROR.SETTINGS_DNE()); // Never found a dotfile
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
// throw new HaravanCliError(ERROR.SETTINGS_DNE()); // Never found a dotfile
|
|
67
|
+
}
|
|
68
|
+
catch (error) {
|
|
69
|
+
if (error instanceof HaravanCliError) {
|
|
70
|
+
throw error;
|
|
71
|
+
}
|
|
72
|
+
throw new HaravanCliError(getErrorMessage(error));
|
|
73
|
+
}
|
|
74
|
+
};
|
|
75
|
+
export const makeRandom = async (length) => {
|
|
76
|
+
let result = "";
|
|
77
|
+
const characters = "abcdefghijklmnopqrstuvwxyz0123456789";
|
|
78
|
+
const charactersLength = characters.length;
|
|
79
|
+
let counter = 0;
|
|
80
|
+
while (counter < length) {
|
|
81
|
+
result += characters.charAt(Math.floor(Math.random() * charactersLength));
|
|
82
|
+
counter += 1;
|
|
83
|
+
}
|
|
84
|
+
return result;
|
|
85
|
+
};
|
|
86
|
+
//# sourceMappingURL=utils.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"utils.js","sourceRoot":"","sources":["../../src/helper/utils.ts"],"names":[],"mappings":"AAAA,OAAO,GAAG,MAAM,KAAK,CAAC;AACtB,OAAO,EAAE,eAAe,EAAE,MAAM,wBAAwB,CAAC;AACzD,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AACjC,OAAO,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AACvC,OAAO,EAAE,KAAK,EAAE,MAAM,eAAe,CAAC;AACtC,MAAM,MAAM,GAAG,IAAI,CAAC,GAAG,EAAE,CAAC;AAE1B,MAAM,CAAC,MAAM,gBAAgB,GAAG,KAAK,EAAE,KAAU,EAAE,SAAc,IAAI,EAAE,EAAE;IACxE,IAAI,EAAE,CAAC;IACP,IAAI,CAAC;QACJ,MAAM,MAAM,GAAQ,MAAM,OAAO,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,IAAI,EAAE,CAAC;QACrD,IAAI,MAAM,IAAI,MAAM,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;YAChD,OAAO,MAAM,CAAC,MAAM,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;QACvC,CAAC;QAED,IAAI,MAAM,EAAE,CAAC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ChB,OAAO,OAAO,GAAG,MAAM,EAAE,CAAC;QACzB,MAAM,IAAI,UAAU,CAAC,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,MAAM,EAAE,GAAG,gBAAgB,CAAC,CAAC,CAAC;QAC1E,OAAO,IAAI,CAAC,CAAC;IACd,CAAC;IACD,OAAO,MAAM,CAAC;AACf,CAAC,CAAC"}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":""}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import { Command } from "commander";
|
|
3
|
+
import { fileURLToPath } from "node:url";
|
|
4
|
+
import { dirname, join } from "node:path";
|
|
5
|
+
import fs from "fs";
|
|
6
|
+
import Table from "cli-table";
|
|
7
|
+
import { spinner, stopSpinner } from "./helper/utils.js";
|
|
8
|
+
import { HaravanCliError } from "./helper/haravan-cli-error.js";
|
|
9
|
+
import login from "./commands/login.js";
|
|
10
|
+
import theme from "./commands/theme.js";
|
|
11
|
+
import select from "./commands/select.js";
|
|
12
|
+
import logout from "./commands/logout.js";
|
|
13
|
+
import checkVersion from "./helper/check_version.js";
|
|
14
|
+
import whoiam from "./commands/whoiam.js";
|
|
15
|
+
import config from "./config/app-config.js";
|
|
16
|
+
const __dirname = dirname(fileURLToPath(import.meta.url));
|
|
17
|
+
let jsonPackage = JSON.parse(fs.readFileSync(join(__dirname, "../package.json"), "utf8"));
|
|
18
|
+
let pakName = String(jsonPackage.name);
|
|
19
|
+
let version = String(jsonPackage.version);
|
|
20
|
+
const program = new Command();
|
|
21
|
+
var table = new Table(config.setting_cli_table);
|
|
22
|
+
// Help text
|
|
23
|
+
table.push(["Command", "Summary"]);
|
|
24
|
+
table.push(["─────────────────────────", "──────────────────────────────────────────────────────────────────────────────"]);
|
|
25
|
+
table.push(["login", "Login to Haravan Org."]);
|
|
26
|
+
table.push(["logout", "Logout all Haravan Org."]);
|
|
27
|
+
table.push(["logout [org_id]", "Logout of a specific Haravan Org."]);
|
|
28
|
+
table.push(["select [org_id]", "Choose Org for local project."]);
|
|
29
|
+
table.push(["theme list", "Lists your remote themes."]);
|
|
30
|
+
table.push(["theme fetch", "Download your remote theme files locally."]);
|
|
31
|
+
table.push(["theme fetch [theme_id]", "Choose a remote theme for the local project and download the files locally."]);
|
|
32
|
+
table.push(["theme export", "Export theme to zip file."]);
|
|
33
|
+
table.push(["theme export [file_name]", "Export theme to zip file with file name."]);
|
|
34
|
+
//table.push(["theme push [file_path]", "Push a specific text file to the theme."]);
|
|
35
|
+
table.push(["whoiam", "Prints a list of logged in Organizations."]);
|
|
36
|
+
program.command("login", { hidden: true }).description(`Login to Haravan Org.`).action(login);
|
|
37
|
+
program
|
|
38
|
+
.command("theme [action] [value]", { hidden: true })
|
|
39
|
+
.description("Show list theme, fetch theme or export theme")
|
|
40
|
+
.action(theme);
|
|
41
|
+
program.command("select [org_id]", { hidden: true }).description("Choose Org for local project.").action(select);
|
|
42
|
+
program
|
|
43
|
+
.command("logout [org_id]", { hidden: true })
|
|
44
|
+
.description("Logout all Haravan Org or Logout of a specific Haravan Org. ")
|
|
45
|
+
.action(logout);
|
|
46
|
+
program.command("whoiam", { hidden: true }).description("Prints a list of logged in Organizations.").action(whoiam);
|
|
47
|
+
program.version(version, "-v, --version", "display the current version");
|
|
48
|
+
program.addHelpText("after", "\n\n" + table.toString() + "\n");
|
|
49
|
+
(async () => {
|
|
50
|
+
try {
|
|
51
|
+
await checkVersion();
|
|
52
|
+
await program.parseAsync(process.argv);
|
|
53
|
+
stopSpinner();
|
|
54
|
+
}
|
|
55
|
+
catch (error) {
|
|
56
|
+
spinner.stop();
|
|
57
|
+
if (error instanceof HaravanCliError) {
|
|
58
|
+
// ClaspError handles process.exitCode
|
|
59
|
+
console.error(error.message);
|
|
60
|
+
}
|
|
61
|
+
else if (error instanceof Error) {
|
|
62
|
+
process.exitCode = 1;
|
|
63
|
+
console.error(error.message);
|
|
64
|
+
}
|
|
65
|
+
else {
|
|
66
|
+
process.exitCode = 1;
|
|
67
|
+
console.error("Unknown error", error);
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
spinner.clear();
|
|
71
|
+
})();
|
|
72
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";AAEA,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AACpC,OAAO,EAAE,aAAa,EAAE,MAAM,UAAU,CAAC;AACzC,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AAC1C,OAAO,EAAE,MAAM,IAAI,CAAC;AAEpB,OAAO,KAAK,MAAM,WAAW,CAAC;AAC9B,OAAO,EAAE,OAAO,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AACzD,OAAO,EAAE,eAAe,EAAE,MAAM,+BAA+B,CAAC;AAChE,OAAO,KAAK,MAAM,qBAAqB,CAAC;AACxC,OAAO,KAAK,MAAM,qBAAqB,CAAC;AACxC,OAAO,MAAM,MAAM,sBAAsB,CAAC;AAC1C,OAAO,MAAM,MAAM,sBAAsB,CAAC;AAC1C,OAAO,YAAY,MAAM,2BAA2B,CAAC;AACrD,OAAO,MAAM,MAAM,sBAAsB,CAAC;AAC1C,OAAO,MAAM,MAAM,wBAAwB,CAAC;AAE5C,MAAM,SAAS,GAAG,OAAO,CAAC,aAAa,CAAC,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC;AAE1D,IAAI,WAAW,GAAG,IAAI,CAAC,KAAK,CAAC,EAAE,CAAC,YAAY,CAAC,IAAI,CAAC,SAAS,EAAE,iBAAiB,CAAC,EAAE,MAAM,CAAC,CAAC,CAAC;AAC1F,IAAI,OAAO,GAAG,MAAM,CAAC,WAAW,C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AI,KAAK,YAAY,KAAK,EAAE,CAAC;YACnC,OAAO,CAAC,QAAQ,GAAG,CAAC,CAAC;YACrB,OAAO,CAAC,KAAK,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC;QAC9B,CAAC;aAAM,CAAC;YACP,OAAO,CAAC,QAAQ,GAAG,CAAC,CAAC;YACrB,OAAO,CAAC,KAAK,CAAC,eAAe,EAAE,KAAK,CAAC,CAAC;QACvC,CAAC;IACF,CAAC;IACD,OAAO,CAAC,KAAK,EAAE,CAAC;AACjB,CAAC,CAAC,EAAE,CAAC"}
|
package/package.json
ADDED
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": "1.1.0-beta.3",
|
|
3
|
+
"name": "@lmcuong29/lublue-cli",
|
|
4
|
+
"description": "lublue-cli",
|
|
5
|
+
"keywords": "lublue-cli",
|
|
6
|
+
"type": "module",
|
|
7
|
+
"exports": {
|
|
8
|
+
".": {
|
|
9
|
+
"types": "./dist/index.d.ts",
|
|
10
|
+
"default": "./dist/index.js"
|
|
11
|
+
}
|
|
12
|
+
},
|
|
13
|
+
"main": "./dist/index.js",
|
|
14
|
+
"types": "./dist/index.d.ts",
|
|
15
|
+
"bin": {
|
|
16
|
+
"haravan": "./dist/index.js"
|
|
17
|
+
},
|
|
18
|
+
"engines": {
|
|
19
|
+
"node": ">=18.18.0"
|
|
20
|
+
},
|
|
21
|
+
"repository": "",
|
|
22
|
+
"scripts": {
|
|
23
|
+
"dev": "tsx src/index.ts",
|
|
24
|
+
"dev-test": "tsx src/test.ts",
|
|
25
|
+
"build": "yarn clean && tsc",
|
|
26
|
+
"clean": "rimraf ./dist tsconfig.tsbuildinfo",
|
|
27
|
+
"start": "node dist/index.js",
|
|
28
|
+
"prestart": "npm run build",
|
|
29
|
+
"test": "vitest run",
|
|
30
|
+
"test-ci": "vitest run"
|
|
31
|
+
},
|
|
32
|
+
"author": "Haravan",
|
|
33
|
+
"license": "MIT",
|
|
34
|
+
"private": false,
|
|
35
|
+
"publishConfig": {
|
|
36
|
+
"access": "public"
|
|
37
|
+
},
|
|
38
|
+
"dependencies": {
|
|
39
|
+
"axios": "1.13.5",
|
|
40
|
+
"axios-auth-refresh": "3.3.6",
|
|
41
|
+
"axios-retry": "3.5.1",
|
|
42
|
+
"cli-table": "0.3.11",
|
|
43
|
+
"commander": "11.0.0",
|
|
44
|
+
"dotf": "1.5.5",
|
|
45
|
+
"fs-extra": "11.1.1",
|
|
46
|
+
"git-rev-sync": "3.0.2",
|
|
47
|
+
"lodash": "4.17.23",
|
|
48
|
+
"make-dir": "4.0.0",
|
|
49
|
+
"moment": "2.29.4",
|
|
50
|
+
"open": "8.4.2",
|
|
51
|
+
"openid-client": "5.4.3",
|
|
52
|
+
"ora": "5.4.1",
|
|
53
|
+
"p-map": "4.0.0",
|
|
54
|
+
"server-destroy": "1.0.1",
|
|
55
|
+
"trash": "10.0.0",
|
|
56
|
+
"ts-node": "10.9.1",
|
|
57
|
+
"ts2gas": "4.2.0",
|
|
58
|
+
"tslib": "2.6.0",
|
|
59
|
+
"zip-a-folder": "4.0.0"
|
|
60
|
+
},
|
|
61
|
+
"devDependencies": {
|
|
62
|
+
"@types/cli-table": "0.3.1",
|
|
63
|
+
"@types/fs-extra": "11.0.1",
|
|
64
|
+
"@types/git-rev-sync": "2.0.0",
|
|
65
|
+
"@types/lodash": "4.14.195",
|
|
66
|
+
"@types/node": "20.4.2",
|
|
67
|
+
"@types/recursive-readdir": "2.2.1",
|
|
68
|
+
"@types/server-destroy": "1.0.1",
|
|
69
|
+
"rimraf": "3.0.2",
|
|
70
|
+
"vitest": "^4.1.2",
|
|
71
|
+
"tsx": "^4.19.2",
|
|
72
|
+
"typescript": "~5.6.3"
|
|
73
|
+
}
|
|
74
|
+
}
|
package/tsconfig.json
ADDED
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
{
|
|
2
|
+
"compilerOptions": {
|
|
3
|
+
"module": "NodeNext",
|
|
4
|
+
"moduleResolution": "NodeNext",
|
|
5
|
+
"target": "ES2022",
|
|
6
|
+
"lib": ["ES2022"],
|
|
7
|
+
"composite": false,
|
|
8
|
+
"declaration": true,
|
|
9
|
+
"declarationMap": true,
|
|
10
|
+
"pretty": true,
|
|
11
|
+
"downlevelIteration": true,
|
|
12
|
+
"esModuleInterop": true,
|
|
13
|
+
"sourceMap": true,
|
|
14
|
+
"noEmitOnError": true,
|
|
15
|
+
"experimentalDecorators": true,
|
|
16
|
+
"noUnusedParameters": false,
|
|
17
|
+
"noUnusedLocals": false,
|
|
18
|
+
"importHelpers": true,
|
|
19
|
+
"strictNullChecks": true,
|
|
20
|
+
"noImplicitAny": true,
|
|
21
|
+
"noImplicitThis": true,
|
|
22
|
+
"resolveJsonModule": true,
|
|
23
|
+
"skipLibCheck": true,
|
|
24
|
+
"typeRoots": ["./node_modules/@types"],
|
|
25
|
+
"outDir": "dist",
|
|
26
|
+
"baseUrl": ".",
|
|
27
|
+
"rootDir": "src"
|
|
28
|
+
},
|
|
29
|
+
"ts-node": {
|
|
30
|
+
"esm": true
|
|
31
|
+
},
|
|
32
|
+
"include": ["./src/**/*.ts", "./src/**/*.json"],
|
|
33
|
+
"exclude": ["node_modules", "dist", "**/*.test.ts", "src/helper/__test__/**"]
|
|
34
|
+
}
|