@akanjs/cli 0.0.31 → 0.0.33
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/index.js +296 -6
- package/package.json +4 -2
package/index.js
CHANGED
|
@@ -1,6 +1,293 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
+
var __create = Object.create;
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
+
var __copyProps = (to, from, except, desc) => {
|
|
9
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
10
|
+
for (let key of __getOwnPropNames(from))
|
|
11
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
12
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
13
|
+
}
|
|
14
|
+
return to;
|
|
15
|
+
};
|
|
16
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
17
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
18
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
19
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
20
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
21
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
22
|
+
mod
|
|
23
|
+
));
|
|
24
|
+
|
|
25
|
+
// pkgs/@akanjs/cli/index.ts
|
|
2
26
|
var import_commander = require("commander");
|
|
3
|
-
var
|
|
27
|
+
var import_prompts = require("@inquirer/prompts");
|
|
28
|
+
|
|
29
|
+
// pkgs/@akanjs/common/src/isDayjs.ts
|
|
30
|
+
var import_dayjs = require("dayjs");
|
|
31
|
+
|
|
32
|
+
// pkgs/@akanjs/common/src/isQueryEqual.ts
|
|
33
|
+
var import_dayjs2 = __toESM(require("dayjs"));
|
|
34
|
+
|
|
35
|
+
// pkgs/@akanjs/common/src/isValidDate.ts
|
|
36
|
+
var import_dayjs3 = __toESM(require("dayjs"));
|
|
37
|
+
var import_customParseFormat = __toESM(require("dayjs/plugin/customParseFormat"));
|
|
38
|
+
import_dayjs3.default.extend(import_customParseFormat.default);
|
|
39
|
+
|
|
40
|
+
// pkgs/@akanjs/common/src/pluralize.ts
|
|
41
|
+
var import_pluralize = __toESM(require("pluralize"));
|
|
42
|
+
|
|
43
|
+
// pkgs/@akanjs/common/src/Logger.ts
|
|
44
|
+
var import_dayjs4 = __toESM(require("dayjs"));
|
|
45
|
+
var logLevels = ["trace", "verbose", "debug", "log", "info", "warn", "error"];
|
|
46
|
+
var clc = {
|
|
47
|
+
bold: (text) => `\x1B[1m${text}\x1B[0m`,
|
|
48
|
+
green: (text) => `\x1B[32m${text}\x1B[39m`,
|
|
49
|
+
yellow: (text) => `\x1B[33m${text}\x1B[39m`,
|
|
50
|
+
red: (text) => `\x1B[31m${text}\x1B[39m`,
|
|
51
|
+
magentaBright: (text) => `\x1B[95m${text}\x1B[39m`,
|
|
52
|
+
cyanBright: (text) => `\x1B[96m${text}\x1B[39m`
|
|
53
|
+
};
|
|
54
|
+
var colorizeMap = {
|
|
55
|
+
trace: clc.bold,
|
|
56
|
+
verbose: clc.cyanBright,
|
|
57
|
+
debug: clc.magentaBright,
|
|
58
|
+
log: clc.green,
|
|
59
|
+
info: clc.green,
|
|
60
|
+
warn: clc.yellow,
|
|
61
|
+
error: clc.red
|
|
62
|
+
};
|
|
63
|
+
var Logger = class _Logger {
|
|
64
|
+
static #ignoreCtxSet = /* @__PURE__ */ new Set([
|
|
65
|
+
"InstanceLoader",
|
|
66
|
+
"RoutesResolver",
|
|
67
|
+
"RouterExplorer",
|
|
68
|
+
"NestFactory",
|
|
69
|
+
"WebSocketsController",
|
|
70
|
+
"GraphQLModule",
|
|
71
|
+
"NestApplication"
|
|
72
|
+
]);
|
|
73
|
+
static level = process.env.NEXT_PUBLIC_LOG_LEVEL ?? "log";
|
|
74
|
+
static #levelIdx = logLevels.findIndex((l) => l === process.env.NEXT_PUBLIC_LOG_LEVEL);
|
|
75
|
+
static #startAt = (0, import_dayjs4.default)();
|
|
76
|
+
static setLevel(level) {
|
|
77
|
+
this.level = level;
|
|
78
|
+
this.#levelIdx = logLevels.findIndex((l) => l === level);
|
|
79
|
+
}
|
|
80
|
+
name;
|
|
81
|
+
constructor(name) {
|
|
82
|
+
this.name = name;
|
|
83
|
+
}
|
|
84
|
+
trace(msg, context = "") {
|
|
85
|
+
if (_Logger.#levelIdx <= 0)
|
|
86
|
+
_Logger.#printMessages(this.name ?? "App", msg, context, "trace");
|
|
87
|
+
}
|
|
88
|
+
verbose(msg, context = "") {
|
|
89
|
+
if (_Logger.#levelIdx <= 1)
|
|
90
|
+
_Logger.#printMessages(this.name ?? "App", msg, context, "verbose");
|
|
91
|
+
}
|
|
92
|
+
debug(msg, context = "") {
|
|
93
|
+
if (_Logger.#levelIdx <= 2)
|
|
94
|
+
_Logger.#printMessages(this.name ?? "App", msg, context, "debug");
|
|
95
|
+
}
|
|
96
|
+
log(msg, context = "") {
|
|
97
|
+
if (_Logger.#levelIdx <= 3)
|
|
98
|
+
_Logger.#printMessages(this.name ?? "App", msg, context, "log");
|
|
99
|
+
}
|
|
100
|
+
info(msg, context = "") {
|
|
101
|
+
if (_Logger.#levelIdx <= 4)
|
|
102
|
+
_Logger.#printMessages(this.name ?? "App", msg, context, "info");
|
|
103
|
+
}
|
|
104
|
+
warn(msg, context = "") {
|
|
105
|
+
if (_Logger.#levelIdx <= 5)
|
|
106
|
+
_Logger.#printMessages(this.name ?? "App", msg, context, "warn");
|
|
107
|
+
}
|
|
108
|
+
error(msg, context = "") {
|
|
109
|
+
if (_Logger.#levelIdx <= 6)
|
|
110
|
+
_Logger.#printMessages(this.name ?? "App", msg, context, "error");
|
|
111
|
+
}
|
|
112
|
+
rawLog(msg, method) {
|
|
113
|
+
_Logger.rawLog(msg, method);
|
|
114
|
+
}
|
|
115
|
+
static trace(msg, context = "") {
|
|
116
|
+
if (_Logger.#levelIdx <= 0)
|
|
117
|
+
_Logger.#printMessages("App", msg, context, "trace");
|
|
118
|
+
}
|
|
119
|
+
static verbose(msg, context = "") {
|
|
120
|
+
if (_Logger.#levelIdx <= 1)
|
|
121
|
+
_Logger.#printMessages("App", msg, context, "verbose");
|
|
122
|
+
}
|
|
123
|
+
static debug(msg, context = "") {
|
|
124
|
+
if (_Logger.#levelIdx <= 2)
|
|
125
|
+
_Logger.#printMessages("App", msg, context, "debug");
|
|
126
|
+
}
|
|
127
|
+
static log(msg, context = "") {
|
|
128
|
+
if (_Logger.#levelIdx <= 3)
|
|
129
|
+
_Logger.#printMessages("App", msg, context, "log");
|
|
130
|
+
}
|
|
131
|
+
static info(msg, context = "") {
|
|
132
|
+
if (_Logger.#levelIdx <= 4)
|
|
133
|
+
_Logger.#printMessages("App", msg, context, "info");
|
|
134
|
+
}
|
|
135
|
+
static warn(msg, context = "") {
|
|
136
|
+
if (_Logger.#levelIdx <= 5)
|
|
137
|
+
_Logger.#printMessages("App", msg, context, "warn");
|
|
138
|
+
}
|
|
139
|
+
static error(msg, context = "") {
|
|
140
|
+
if (_Logger.#levelIdx <= 6)
|
|
141
|
+
_Logger.#printMessages("App", msg, context, "error");
|
|
142
|
+
}
|
|
143
|
+
static #colorize(msg, logLevel) {
|
|
144
|
+
return colorizeMap[logLevel](msg);
|
|
145
|
+
}
|
|
146
|
+
static #printMessages(name, content, context, logLevel, writeStreamType = logLevel === "error" ? "stderr" : "stdout") {
|
|
147
|
+
if (this.#ignoreCtxSet.has(context))
|
|
148
|
+
return;
|
|
149
|
+
const now = (0, import_dayjs4.default)();
|
|
150
|
+
const processMsg = this.#colorize(
|
|
151
|
+
`[${name ?? "App"}] ${global.process?.pid ?? "window"} -`,
|
|
152
|
+
logLevel
|
|
153
|
+
);
|
|
154
|
+
const timestampMsg = now.format("MM/DD/YYYY, HH:mm:ss A");
|
|
155
|
+
const logLevelMsg = this.#colorize(logLevel.toUpperCase().padStart(7, " "), logLevel);
|
|
156
|
+
const contextMsg = context ? clc.yellow(`[${context}] `) : "";
|
|
157
|
+
const contentMsg = this.#colorize(content, logLevel);
|
|
158
|
+
const timeDiffMsg = clc.yellow(`+${now.diff(_Logger.#startAt, "ms")}ms`);
|
|
159
|
+
if (typeof window === "undefined")
|
|
160
|
+
process[writeStreamType].write(
|
|
161
|
+
`${processMsg} ${timestampMsg} ${logLevelMsg} ${contextMsg} ${contentMsg} ${timeDiffMsg}
|
|
162
|
+
`
|
|
163
|
+
);
|
|
164
|
+
else
|
|
165
|
+
console.log(`${processMsg} ${timestampMsg} ${logLevelMsg} ${contextMsg} ${contentMsg} ${timeDiffMsg}
|
|
166
|
+
`);
|
|
167
|
+
}
|
|
168
|
+
static rawLog(msg, method) {
|
|
169
|
+
if (typeof window === "undefined" && method !== "console" && global.process)
|
|
170
|
+
global.process.stdout.write(msg);
|
|
171
|
+
else
|
|
172
|
+
console.log(msg);
|
|
173
|
+
}
|
|
174
|
+
};
|
|
175
|
+
|
|
176
|
+
// pkgs/@akanjs/common/src/sleep.ts
|
|
177
|
+
var sleep = async (ms) => {
|
|
178
|
+
return new Promise((resolve) => {
|
|
179
|
+
setTimeout(() => {
|
|
180
|
+
resolve(true);
|
|
181
|
+
}, ms);
|
|
182
|
+
});
|
|
183
|
+
};
|
|
184
|
+
|
|
185
|
+
// pkgs/@akanjs/cli/login.ts
|
|
186
|
+
var import_open = __toESM(require("open"));
|
|
187
|
+
var import_uuid = require("uuid");
|
|
188
|
+
|
|
189
|
+
// pkgs/@akanjs/cli/utils/constants.ts
|
|
190
|
+
var import_os = require("os");
|
|
191
|
+
var basePath = `${(0, import_os.homedir)()}/.akan`;
|
|
192
|
+
var configPath = `${basePath}/config.json`;
|
|
193
|
+
var akanCloudHost = process.env.NEXT_PUBLIC_OPERATION_MODE === "local" ? "http://localhost" : "https://akasys-debug.akamir.com";
|
|
194
|
+
var akanCloudBackendUrl = `${akanCloudHost}${process.env.NEXT_PUBLIC_OPERATION_MODE === "local" ? ":8080" : ""}/backend`;
|
|
195
|
+
var akanCloudClientUrl = `${akanCloudHost}${process.env.NEXT_PUBLIC_OPERATION_MODE === "local" ? ":4200" : ""}`;
|
|
196
|
+
var defaultHostConfig = {};
|
|
197
|
+
var defaultAkanConfig = {};
|
|
198
|
+
|
|
199
|
+
// pkgs/@akanjs/cli/utils/auth.ts
|
|
200
|
+
var import_fs = __toESM(require("fs"));
|
|
201
|
+
var getAkanConfig = () => {
|
|
202
|
+
const akanConfig = import_fs.default.existsSync(configPath) ? JSON.parse(import_fs.default.readFileSync(configPath, "utf8")) : defaultAkanConfig;
|
|
203
|
+
return akanConfig;
|
|
204
|
+
};
|
|
205
|
+
var setAkanConfig = (akanConfig) => {
|
|
206
|
+
import_fs.default.mkdirSync(basePath, { recursive: true });
|
|
207
|
+
import_fs.default.writeFileSync(configPath, JSON.stringify(akanConfig, null, 2));
|
|
208
|
+
};
|
|
209
|
+
var getHostConfig = (host = akanCloudHost) => {
|
|
210
|
+
const akanConfig = getAkanConfig();
|
|
211
|
+
return akanConfig[host] ?? defaultHostConfig;
|
|
212
|
+
};
|
|
213
|
+
var setHostConfig = (host = akanCloudHost, config = {}) => {
|
|
214
|
+
const akanConfig = getAkanConfig();
|
|
215
|
+
akanConfig[host] = config;
|
|
216
|
+
setAkanConfig(akanConfig);
|
|
217
|
+
};
|
|
218
|
+
var getSelf = async (token) => {
|
|
219
|
+
try {
|
|
220
|
+
const res = await fetch(`${akanCloudBackendUrl}/user/getSelf`, { headers: { Authorization: `Bearer ${token}` } });
|
|
221
|
+
const user = await res.json();
|
|
222
|
+
return user;
|
|
223
|
+
} catch (e) {
|
|
224
|
+
return null;
|
|
225
|
+
}
|
|
226
|
+
};
|
|
227
|
+
|
|
228
|
+
// pkgs/@akanjs/cli/login.ts
|
|
229
|
+
var login = async () => {
|
|
230
|
+
const config = getHostConfig();
|
|
231
|
+
const self = config.authToken ? await getSelf(config.authToken) : null;
|
|
232
|
+
if (self) {
|
|
233
|
+
Logger.rawLog(`Already logged in
|
|
234
|
+
`);
|
|
235
|
+
return true;
|
|
236
|
+
}
|
|
237
|
+
const remoteId = (0, import_uuid.v4)();
|
|
238
|
+
Logger.rawLog(`Please sign in below link
|
|
239
|
+
`);
|
|
240
|
+
const signinUrl = `${akanCloudClientUrl}/signin?remoteId=${remoteId}`;
|
|
241
|
+
Logger.rawLog(`${signinUrl}
|
|
242
|
+
`);
|
|
243
|
+
await (0, import_open.default)(signinUrl);
|
|
244
|
+
const MAX_RETRY = 300;
|
|
245
|
+
for (let i = 0; i < MAX_RETRY; i++) {
|
|
246
|
+
const res = await fetch(`${akanCloudBackendUrl}/user/getRemoteAuthToken/${remoteId}`);
|
|
247
|
+
const { jwt } = await res.json();
|
|
248
|
+
if (jwt) {
|
|
249
|
+
setHostConfig(akanCloudHost, { authToken: jwt });
|
|
250
|
+
Logger.rawLog(`Login successful
|
|
251
|
+
`);
|
|
252
|
+
return true;
|
|
253
|
+
}
|
|
254
|
+
await sleep(2e3);
|
|
255
|
+
}
|
|
256
|
+
throw new Error("Failed to login");
|
|
257
|
+
};
|
|
258
|
+
|
|
259
|
+
// pkgs/@akanjs/cli/logout.ts
|
|
260
|
+
var logout = () => {
|
|
261
|
+
setHostConfig(akanCloudHost, {});
|
|
262
|
+
Logger.rawLog(`Logout success
|
|
263
|
+
`);
|
|
264
|
+
};
|
|
265
|
+
|
|
266
|
+
// pkgs/@akanjs/cli/createWorkspace.ts
|
|
267
|
+
var import_fs2 = __toESM(require("fs"));
|
|
268
|
+
var createWorkspace = async (name) => {
|
|
269
|
+
import_fs2.default.mkdirSync(name, { recursive: true });
|
|
270
|
+
const dependencies = [
|
|
271
|
+
"@akanjs/base",
|
|
272
|
+
"@akanjs/cli",
|
|
273
|
+
"@akanjs/client",
|
|
274
|
+
"@akanjs/common",
|
|
275
|
+
"@akanjs/config",
|
|
276
|
+
"@akanjs/constant",
|
|
277
|
+
"@akanjs/dictionary",
|
|
278
|
+
"@akanjs/document",
|
|
279
|
+
"@akanjs/nest",
|
|
280
|
+
"@akanjs/next",
|
|
281
|
+
"@akanjs/server",
|
|
282
|
+
"@akanjs/service",
|
|
283
|
+
"@akanjs/signal",
|
|
284
|
+
"@akanjs/store",
|
|
285
|
+
"@akanjs/ui"
|
|
286
|
+
];
|
|
287
|
+
const devDependencies = ["@akanjs/test", "@akanjs/devkit"];
|
|
288
|
+
};
|
|
289
|
+
|
|
290
|
+
// pkgs/@akanjs/cli/index.ts
|
|
4
291
|
import_commander.program.version("0.0.1").description("An example CLI for managing a directory");
|
|
5
292
|
import_commander.program.command("application").argument("<name>", "application name").action((name, options, command) => {
|
|
6
293
|
});
|
|
@@ -8,15 +295,18 @@ import_commander.program.command("library").argument("<name>", "library name").a
|
|
|
8
295
|
});
|
|
9
296
|
import_commander.program.command("package").argument("<name>", "package name").action((name, options, command) => {
|
|
10
297
|
});
|
|
11
|
-
import_commander.program.command("workspace").
|
|
298
|
+
import_commander.program.command("workspace").option("-n, --name <type>", "application name").action(async (options, command) => {
|
|
299
|
+
const name = options.name ?? await (0, import_prompts.input)({ message: "Enter the workspace name: " });
|
|
300
|
+
await createWorkspace(name);
|
|
12
301
|
});
|
|
13
|
-
import_commander.program.command("login").action((options, command) => {
|
|
14
|
-
|
|
302
|
+
import_commander.program.command("login").action(async (options, command) => {
|
|
303
|
+
await login();
|
|
15
304
|
});
|
|
16
305
|
import_commander.program.command("logout").action((options, command) => {
|
|
17
|
-
|
|
306
|
+
logout();
|
|
18
307
|
});
|
|
19
|
-
|
|
308
|
+
var run = async () => {
|
|
20
309
|
await import_commander.program.parseAsync(process.argv);
|
|
21
310
|
};
|
|
22
311
|
void run();
|
|
312
|
+
//! Temp
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"type": "commonjs",
|
|
3
3
|
"name": "@akanjs/cli",
|
|
4
|
-
"version": "0.0.
|
|
4
|
+
"version": "0.0.33",
|
|
5
5
|
"bin": {
|
|
6
6
|
"akan": "index.js"
|
|
7
7
|
},
|
|
@@ -14,11 +14,13 @@
|
|
|
14
14
|
"directory": "pkgs/@akanjs/cli"
|
|
15
15
|
},
|
|
16
16
|
"dependencies": {
|
|
17
|
+
"@inquirer/prompts": "^7.2.1",
|
|
17
18
|
"@urql/core": "^5.1.0",
|
|
18
19
|
"commander": "^13.1.0",
|
|
19
20
|
"dayjs": "^1.11.13",
|
|
21
|
+
"open": "^10.1.1",
|
|
20
22
|
"pluralize": "^8.0.0",
|
|
21
|
-
"
|
|
23
|
+
"uuid": "^11.0.3"
|
|
22
24
|
},
|
|
23
25
|
"main": "./index.js"
|
|
24
26
|
}
|