@akanjs/devkit 0.0.136 → 0.0.138
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/cjs/src/aiEditor.js +7 -1
- package/cjs/src/executors.js +32 -10
- package/cjs/src/index.js +3 -1
- package/cjs/src/spinner.js +71 -0
- package/esm/src/aiEditor.js +7 -1
- package/esm/src/executors.js +30 -9
- package/esm/src/index.js +1 -0
- package/esm/src/spinner.js +38 -0
- package/package.json +1 -1
- package/src/executors.d.ts +19 -0
- package/src/index.d.ts +1 -0
- package/src/spinner.d.ts +14 -0
package/cjs/src/aiEditor.js
CHANGED
|
@@ -36,6 +36,7 @@ var import_prompts = require("@inquirer/prompts");
|
|
|
36
36
|
var import_messages = require("@langchain/core/messages");
|
|
37
37
|
var import_openai = require("@langchain/openai");
|
|
38
38
|
var import_chalk = __toESM(require("chalk"));
|
|
39
|
+
var import_ora = __toESM(require("ora"));
|
|
39
40
|
var import_auth = require("./auth");
|
|
40
41
|
const MAX_ASK_TRY = 300;
|
|
41
42
|
const supportedLlmModels = ["deepseek-chat", "deepseek-reasoner"];
|
|
@@ -107,23 +108,28 @@ class AiSession {
|
|
|
107
108
|
await AiSession.init();
|
|
108
109
|
if (!AiSession.#chat)
|
|
109
110
|
throw new Error("Failed to initialize the AI session");
|
|
111
|
+
const loader = (0, import_ora.default)(`${AiSession.#chat.model} is thinking...`).start();
|
|
110
112
|
try {
|
|
111
113
|
const humanMessage = new import_messages.HumanMessage(question);
|
|
112
114
|
this.messageHistory.push(humanMessage);
|
|
113
115
|
const stream = await AiSession.#chat.stream(this.messageHistory);
|
|
114
|
-
let fullResponse = "";
|
|
116
|
+
let fullResponse = "", tokenIdx = 0;
|
|
115
117
|
for await (const chunk of stream) {
|
|
118
|
+
if (loader.isSpinning)
|
|
119
|
+
loader.succeed(`${AiSession.#chat.model} responded`);
|
|
116
120
|
const content = chunk.content;
|
|
117
121
|
if (typeof content === "string") {
|
|
118
122
|
fullResponse += content;
|
|
119
123
|
onChunk(content);
|
|
120
124
|
}
|
|
125
|
+
tokenIdx++;
|
|
121
126
|
}
|
|
122
127
|
fullResponse += "\n";
|
|
123
128
|
onChunk("\n");
|
|
124
129
|
this.messageHistory.push(new import_messages.AIMessage(fullResponse));
|
|
125
130
|
return { content: fullResponse, messageHistory: this.messageHistory };
|
|
126
131
|
} catch (error) {
|
|
132
|
+
loader.fail(`${AiSession.#chat.model} failed to respond`);
|
|
127
133
|
throw new Error("Failed to stream response");
|
|
128
134
|
}
|
|
129
135
|
}
|
package/cjs/src/executors.js
CHANGED
|
@@ -32,7 +32,8 @@ __export(executors_exports, {
|
|
|
32
32
|
LibExecutor: () => LibExecutor,
|
|
33
33
|
PkgExecutor: () => PkgExecutor,
|
|
34
34
|
SysExecutor: () => SysExecutor,
|
|
35
|
-
WorkspaceExecutor: () => WorkspaceExecutor
|
|
35
|
+
WorkspaceExecutor: () => WorkspaceExecutor,
|
|
36
|
+
execEmoji: () => execEmoji
|
|
36
37
|
});
|
|
37
38
|
module.exports = __toCommonJS(executors_exports);
|
|
38
39
|
var import_common = require("@akanjs/common");
|
|
@@ -44,10 +45,21 @@ var import_fs = __toESM(require("fs"));
|
|
|
44
45
|
var import_promises = __toESM(require("fs/promises"));
|
|
45
46
|
var import_path = __toESM(require("path"));
|
|
46
47
|
var import_dependencyScanner = require("./dependencyScanner");
|
|
48
|
+
var import_spinner = require("./spinner");
|
|
49
|
+
const execEmoji = {
|
|
50
|
+
workspace: "\u{1F3E0}",
|
|
51
|
+
app: "\u{1F680}",
|
|
52
|
+
lib: "\u{1F527}",
|
|
53
|
+
pkg: "\u{1F4E6}",
|
|
54
|
+
dist: "\u{1F4BF}",
|
|
55
|
+
default: "\u2708\uFE0F"
|
|
56
|
+
// for sys executor
|
|
57
|
+
};
|
|
47
58
|
class Executor {
|
|
48
59
|
name;
|
|
49
60
|
logger;
|
|
50
61
|
cwdPath;
|
|
62
|
+
emoji = execEmoji.default;
|
|
51
63
|
constructor(name, cwdPath) {
|
|
52
64
|
this.name = name;
|
|
53
65
|
this.logger = new import_common.Logger(name);
|
|
@@ -174,6 +186,9 @@ class Executor {
|
|
|
174
186
|
this.logger.verbose(msg);
|
|
175
187
|
return this;
|
|
176
188
|
}
|
|
189
|
+
spinning(msg, { prefix = `${this.emoji}${this.name} -`, indent = 0 } = {}) {
|
|
190
|
+
return new import_spinner.Spinner(msg, { prefix, indent }).start();
|
|
191
|
+
}
|
|
177
192
|
getTsConfig(pathname = "tsconfig.json") {
|
|
178
193
|
const tsconfig = this.readJson(pathname);
|
|
179
194
|
if (tsconfig.extends) {
|
|
@@ -205,7 +220,7 @@ class Executor {
|
|
|
205
220
|
`${dirname}/${filename}`
|
|
206
221
|
);
|
|
207
222
|
this.logger.verbose(`Apply template ${templatePath} to ${convertedTargetPath}`);
|
|
208
|
-
this.writeFile(convertedTargetPath, content);
|
|
223
|
+
this.writeFile(convertedTargetPath, content, { overwrite });
|
|
209
224
|
} else if (targetPath.endsWith(".template")) {
|
|
210
225
|
const content = await import_promises.default.readFile(templatePath, "utf8");
|
|
211
226
|
const convertedTargetPath = Object.entries(dict).reduce(
|
|
@@ -217,7 +232,7 @@ class Executor {
|
|
|
217
232
|
content
|
|
218
233
|
);
|
|
219
234
|
this.logger.verbose(`Apply template ${templatePath} to ${convertedTargetPath}`);
|
|
220
|
-
this.writeFile(convertedTargetPath, convertedContent);
|
|
235
|
+
this.writeFile(convertedTargetPath, convertedContent, { overwrite });
|
|
221
236
|
}
|
|
222
237
|
}
|
|
223
238
|
async applyTemplate({
|
|
@@ -260,8 +275,9 @@ class Executor {
|
|
|
260
275
|
class WorkspaceExecutor extends Executor {
|
|
261
276
|
workspaceRoot;
|
|
262
277
|
repoName;
|
|
278
|
+
emoji = execEmoji.workspace;
|
|
263
279
|
constructor({ workspaceRoot, repoName }) {
|
|
264
|
-
super(
|
|
280
|
+
super("workspace", workspaceRoot);
|
|
265
281
|
this.workspaceRoot = workspaceRoot;
|
|
266
282
|
this.repoName = repoName;
|
|
267
283
|
}
|
|
@@ -416,11 +432,13 @@ class SysExecutor extends Executor {
|
|
|
416
432
|
workspace;
|
|
417
433
|
name;
|
|
418
434
|
type;
|
|
435
|
+
emoji;
|
|
419
436
|
constructor({ workspace = WorkspaceExecutor.fromRoot(), name, type }) {
|
|
420
|
-
super(
|
|
437
|
+
super(name, `${workspace.workspaceRoot}/${type}s/${name}`);
|
|
421
438
|
this.workspace = workspace;
|
|
422
439
|
this.name = name;
|
|
423
440
|
this.type = type;
|
|
441
|
+
this.emoji = execEmoji[type];
|
|
424
442
|
}
|
|
425
443
|
async getConfig(command) {
|
|
426
444
|
return this.type === "app" ? await (0, import_config.getAppConfig)(this.cwdPath, { ...this.workspace.getBaseDevEnv(), type: "app", name: this.name, command }) : await (0, import_config.getLibConfig)(this.cwdPath, { ...this.workspace.getBaseDevEnv(), type: "lib", name: this.name, command });
|
|
@@ -641,9 +659,10 @@ class SysExecutor extends Executor {
|
|
|
641
659
|
}
|
|
642
660
|
class AppExecutor extends SysExecutor {
|
|
643
661
|
dist;
|
|
662
|
+
emoji = execEmoji.app;
|
|
644
663
|
constructor({ workspace, name }) {
|
|
645
664
|
super({ workspace, name, type: "app" });
|
|
646
|
-
this.dist = new Executor(
|
|
665
|
+
this.dist = new Executor(`dist/${name}`, `${this.workspace.workspaceRoot}/dist/apps/${name}`);
|
|
647
666
|
}
|
|
648
667
|
static from(executor, name) {
|
|
649
668
|
if (executor instanceof WorkspaceExecutor)
|
|
@@ -677,9 +696,10 @@ class LibExecutor extends SysExecutor {
|
|
|
677
696
|
workspaceRoot;
|
|
678
697
|
repoName;
|
|
679
698
|
dist;
|
|
699
|
+
emoji = execEmoji.lib;
|
|
680
700
|
constructor({ workspace, name }) {
|
|
681
701
|
super({ workspace, name, type: "lib" });
|
|
682
|
-
this.dist = new Executor(
|
|
702
|
+
this.dist = new Executor(`dist/${name}`, `${this.workspace.workspaceRoot}/dist/libs/${name}`);
|
|
683
703
|
}
|
|
684
704
|
static from(executor, name) {
|
|
685
705
|
if (executor instanceof WorkspaceExecutor)
|
|
@@ -699,11 +719,12 @@ class PkgExecutor extends Executor {
|
|
|
699
719
|
workspace;
|
|
700
720
|
name;
|
|
701
721
|
dist;
|
|
722
|
+
emoji = execEmoji.pkg;
|
|
702
723
|
constructor({ workspace = WorkspaceExecutor.fromRoot(), name }) {
|
|
703
|
-
super(
|
|
724
|
+
super(name, `${workspace.workspaceRoot}/pkgs/${name}`);
|
|
704
725
|
this.workspace = workspace;
|
|
705
726
|
this.name = name;
|
|
706
|
-
this.dist = new Executor(
|
|
727
|
+
this.dist = new Executor(`dist/${name}`, `${this.workspace.workspaceRoot}/dist/pkgs/${name}`);
|
|
707
728
|
}
|
|
708
729
|
static from(executor, name) {
|
|
709
730
|
if (executor instanceof WorkspaceExecutor)
|
|
@@ -740,5 +761,6 @@ class PkgExecutor extends Executor {
|
|
|
740
761
|
LibExecutor,
|
|
741
762
|
PkgExecutor,
|
|
742
763
|
SysExecutor,
|
|
743
|
-
WorkspaceExecutor
|
|
764
|
+
WorkspaceExecutor,
|
|
765
|
+
execEmoji
|
|
744
766
|
});
|
package/cjs/src/index.js
CHANGED
|
@@ -31,6 +31,7 @@ __reExport(src_exports, require("./extractDeps"), module.exports);
|
|
|
31
31
|
__reExport(src_exports, require("./commandDecorators"), module.exports);
|
|
32
32
|
__reExport(src_exports, require("./aiEditor"), module.exports);
|
|
33
33
|
__reExport(src_exports, require("./builder"), module.exports);
|
|
34
|
+
__reExport(src_exports, require("./spinner"), module.exports);
|
|
34
35
|
// Annotate the CommonJS export names for ESM import in node:
|
|
35
36
|
0 && (module.exports = {
|
|
36
37
|
...require("./createTunnel"),
|
|
@@ -49,5 +50,6 @@ __reExport(src_exports, require("./builder"), module.exports);
|
|
|
49
50
|
...require("./extractDeps"),
|
|
50
51
|
...require("./commandDecorators"),
|
|
51
52
|
...require("./aiEditor"),
|
|
52
|
-
...require("./builder")
|
|
53
|
+
...require("./builder"),
|
|
54
|
+
...require("./spinner")
|
|
53
55
|
});
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
var __create = Object.create;
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
6
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
7
|
+
var __export = (target, all) => {
|
|
8
|
+
for (var name in all)
|
|
9
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
10
|
+
};
|
|
11
|
+
var __copyProps = (to, from, except, desc) => {
|
|
12
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
13
|
+
for (let key of __getOwnPropNames(from))
|
|
14
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
15
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
16
|
+
}
|
|
17
|
+
return to;
|
|
18
|
+
};
|
|
19
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
20
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
21
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
22
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
23
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
24
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
25
|
+
mod
|
|
26
|
+
));
|
|
27
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
28
|
+
var spinner_exports = {};
|
|
29
|
+
__export(spinner_exports, {
|
|
30
|
+
Spinner: () => Spinner
|
|
31
|
+
});
|
|
32
|
+
module.exports = __toCommonJS(spinner_exports);
|
|
33
|
+
var import_ora = __toESM(require("ora"));
|
|
34
|
+
class Spinner {
|
|
35
|
+
spinner;
|
|
36
|
+
stopWatch;
|
|
37
|
+
startAt;
|
|
38
|
+
message;
|
|
39
|
+
constructor(message, { prefix = "", indent = 0 } = {}) {
|
|
40
|
+
this.message = message;
|
|
41
|
+
this.spinner = (0, import_ora.default)(message);
|
|
42
|
+
this.spinner.prefixText = prefix;
|
|
43
|
+
this.spinner.indent = indent;
|
|
44
|
+
}
|
|
45
|
+
start() {
|
|
46
|
+
this.startAt = /* @__PURE__ */ new Date();
|
|
47
|
+
const spinner = this.spinner.start();
|
|
48
|
+
this.stopWatch = setInterval(() => {
|
|
49
|
+
spinner.text = `${this.message} (${this.#getElapsedTimeStr()})`;
|
|
50
|
+
}, 1e3);
|
|
51
|
+
return this;
|
|
52
|
+
}
|
|
53
|
+
succeed(message) {
|
|
54
|
+
clearInterval(this.stopWatch);
|
|
55
|
+
this.spinner.succeed(`${message} (${this.#getElapsedTimeStr()})`);
|
|
56
|
+
}
|
|
57
|
+
#getElapsedTimeStr() {
|
|
58
|
+
const ms = (/* @__PURE__ */ new Date()).getTime() - this.startAt.getTime();
|
|
59
|
+
if (ms < 1e3)
|
|
60
|
+
return `${ms}ms`;
|
|
61
|
+
const s = Math.floor(ms / 1e3);
|
|
62
|
+
if (s < 60)
|
|
63
|
+
return `${s}s`;
|
|
64
|
+
const m = Math.floor(s / 60);
|
|
65
|
+
return `${m}m ${s % 60}s`;
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
69
|
+
0 && (module.exports = {
|
|
70
|
+
Spinner
|
|
71
|
+
});
|
package/esm/src/aiEditor.js
CHANGED
|
@@ -3,6 +3,7 @@ import { input, select } from "@inquirer/prompts";
|
|
|
3
3
|
import { AIMessage, HumanMessage } from "@langchain/core/messages";
|
|
4
4
|
import { ChatOpenAI } from "@langchain/openai";
|
|
5
5
|
import chalk from "chalk";
|
|
6
|
+
import ora from "ora";
|
|
6
7
|
import { getAkanGlobalConfig, setAkanGlobalConfig } from "./auth";
|
|
7
8
|
const MAX_ASK_TRY = 300;
|
|
8
9
|
const supportedLlmModels = ["deepseek-chat", "deepseek-reasoner"];
|
|
@@ -74,23 +75,28 @@ class AiSession {
|
|
|
74
75
|
await AiSession.init();
|
|
75
76
|
if (!AiSession.#chat)
|
|
76
77
|
throw new Error("Failed to initialize the AI session");
|
|
78
|
+
const loader = ora(`${AiSession.#chat.model} is thinking...`).start();
|
|
77
79
|
try {
|
|
78
80
|
const humanMessage = new HumanMessage(question);
|
|
79
81
|
this.messageHistory.push(humanMessage);
|
|
80
82
|
const stream = await AiSession.#chat.stream(this.messageHistory);
|
|
81
|
-
let fullResponse = "";
|
|
83
|
+
let fullResponse = "", tokenIdx = 0;
|
|
82
84
|
for await (const chunk of stream) {
|
|
85
|
+
if (loader.isSpinning)
|
|
86
|
+
loader.succeed(`${AiSession.#chat.model} responded`);
|
|
83
87
|
const content = chunk.content;
|
|
84
88
|
if (typeof content === "string") {
|
|
85
89
|
fullResponse += content;
|
|
86
90
|
onChunk(content);
|
|
87
91
|
}
|
|
92
|
+
tokenIdx++;
|
|
88
93
|
}
|
|
89
94
|
fullResponse += "\n";
|
|
90
95
|
onChunk("\n");
|
|
91
96
|
this.messageHistory.push(new AIMessage(fullResponse));
|
|
92
97
|
return { content: fullResponse, messageHistory: this.messageHistory };
|
|
93
98
|
} catch (error) {
|
|
99
|
+
loader.fail(`${AiSession.#chat.model} failed to respond`);
|
|
94
100
|
throw new Error("Failed to stream response");
|
|
95
101
|
}
|
|
96
102
|
}
|
package/esm/src/executors.js
CHANGED
|
@@ -11,10 +11,21 @@ import fs from "fs";
|
|
|
11
11
|
import fsPromise from "fs/promises";
|
|
12
12
|
import path from "path";
|
|
13
13
|
import { TypeScriptDependencyScanner } from "./dependencyScanner";
|
|
14
|
+
import { Spinner } from "./spinner";
|
|
15
|
+
const execEmoji = {
|
|
16
|
+
workspace: "\u{1F3E0}",
|
|
17
|
+
app: "\u{1F680}",
|
|
18
|
+
lib: "\u{1F527}",
|
|
19
|
+
pkg: "\u{1F4E6}",
|
|
20
|
+
dist: "\u{1F4BF}",
|
|
21
|
+
default: "\u2708\uFE0F"
|
|
22
|
+
// for sys executor
|
|
23
|
+
};
|
|
14
24
|
class Executor {
|
|
15
25
|
name;
|
|
16
26
|
logger;
|
|
17
27
|
cwdPath;
|
|
28
|
+
emoji = execEmoji.default;
|
|
18
29
|
constructor(name, cwdPath) {
|
|
19
30
|
this.name = name;
|
|
20
31
|
this.logger = new Logger(name);
|
|
@@ -141,6 +152,9 @@ class Executor {
|
|
|
141
152
|
this.logger.verbose(msg);
|
|
142
153
|
return this;
|
|
143
154
|
}
|
|
155
|
+
spinning(msg, { prefix = `${this.emoji}${this.name} -`, indent = 0 } = {}) {
|
|
156
|
+
return new Spinner(msg, { prefix, indent }).start();
|
|
157
|
+
}
|
|
144
158
|
getTsConfig(pathname = "tsconfig.json") {
|
|
145
159
|
const tsconfig = this.readJson(pathname);
|
|
146
160
|
if (tsconfig.extends) {
|
|
@@ -172,7 +186,7 @@ class Executor {
|
|
|
172
186
|
`${dirname}/${filename}`
|
|
173
187
|
);
|
|
174
188
|
this.logger.verbose(`Apply template ${templatePath} to ${convertedTargetPath}`);
|
|
175
|
-
this.writeFile(convertedTargetPath, content);
|
|
189
|
+
this.writeFile(convertedTargetPath, content, { overwrite });
|
|
176
190
|
} else if (targetPath.endsWith(".template")) {
|
|
177
191
|
const content = await fsPromise.readFile(templatePath, "utf8");
|
|
178
192
|
const convertedTargetPath = Object.entries(dict).reduce(
|
|
@@ -184,7 +198,7 @@ class Executor {
|
|
|
184
198
|
content
|
|
185
199
|
);
|
|
186
200
|
this.logger.verbose(`Apply template ${templatePath} to ${convertedTargetPath}`);
|
|
187
|
-
this.writeFile(convertedTargetPath, convertedContent);
|
|
201
|
+
this.writeFile(convertedTargetPath, convertedContent, { overwrite });
|
|
188
202
|
}
|
|
189
203
|
}
|
|
190
204
|
async applyTemplate({
|
|
@@ -227,8 +241,9 @@ class Executor {
|
|
|
227
241
|
class WorkspaceExecutor extends Executor {
|
|
228
242
|
workspaceRoot;
|
|
229
243
|
repoName;
|
|
244
|
+
emoji = execEmoji.workspace;
|
|
230
245
|
constructor({ workspaceRoot, repoName }) {
|
|
231
|
-
super(
|
|
246
|
+
super("workspace", workspaceRoot);
|
|
232
247
|
this.workspaceRoot = workspaceRoot;
|
|
233
248
|
this.repoName = repoName;
|
|
234
249
|
}
|
|
@@ -383,11 +398,13 @@ class SysExecutor extends Executor {
|
|
|
383
398
|
workspace;
|
|
384
399
|
name;
|
|
385
400
|
type;
|
|
401
|
+
emoji;
|
|
386
402
|
constructor({ workspace = WorkspaceExecutor.fromRoot(), name, type }) {
|
|
387
|
-
super(
|
|
403
|
+
super(name, `${workspace.workspaceRoot}/${type}s/${name}`);
|
|
388
404
|
this.workspace = workspace;
|
|
389
405
|
this.name = name;
|
|
390
406
|
this.type = type;
|
|
407
|
+
this.emoji = execEmoji[type];
|
|
391
408
|
}
|
|
392
409
|
async getConfig(command) {
|
|
393
410
|
return this.type === "app" ? await getAppConfig(this.cwdPath, { ...this.workspace.getBaseDevEnv(), type: "app", name: this.name, command }) : await getLibConfig(this.cwdPath, { ...this.workspace.getBaseDevEnv(), type: "lib", name: this.name, command });
|
|
@@ -608,9 +625,10 @@ class SysExecutor extends Executor {
|
|
|
608
625
|
}
|
|
609
626
|
class AppExecutor extends SysExecutor {
|
|
610
627
|
dist;
|
|
628
|
+
emoji = execEmoji.app;
|
|
611
629
|
constructor({ workspace, name }) {
|
|
612
630
|
super({ workspace, name, type: "app" });
|
|
613
|
-
this.dist = new Executor(
|
|
631
|
+
this.dist = new Executor(`dist/${name}`, `${this.workspace.workspaceRoot}/dist/apps/${name}`);
|
|
614
632
|
}
|
|
615
633
|
static from(executor, name) {
|
|
616
634
|
if (executor instanceof WorkspaceExecutor)
|
|
@@ -644,9 +662,10 @@ class LibExecutor extends SysExecutor {
|
|
|
644
662
|
workspaceRoot;
|
|
645
663
|
repoName;
|
|
646
664
|
dist;
|
|
665
|
+
emoji = execEmoji.lib;
|
|
647
666
|
constructor({ workspace, name }) {
|
|
648
667
|
super({ workspace, name, type: "lib" });
|
|
649
|
-
this.dist = new Executor(
|
|
668
|
+
this.dist = new Executor(`dist/${name}`, `${this.workspace.workspaceRoot}/dist/libs/${name}`);
|
|
650
669
|
}
|
|
651
670
|
static from(executor, name) {
|
|
652
671
|
if (executor instanceof WorkspaceExecutor)
|
|
@@ -666,11 +685,12 @@ class PkgExecutor extends Executor {
|
|
|
666
685
|
workspace;
|
|
667
686
|
name;
|
|
668
687
|
dist;
|
|
688
|
+
emoji = execEmoji.pkg;
|
|
669
689
|
constructor({ workspace = WorkspaceExecutor.fromRoot(), name }) {
|
|
670
|
-
super(
|
|
690
|
+
super(name, `${workspace.workspaceRoot}/pkgs/${name}`);
|
|
671
691
|
this.workspace = workspace;
|
|
672
692
|
this.name = name;
|
|
673
|
-
this.dist = new Executor(
|
|
693
|
+
this.dist = new Executor(`dist/${name}`, `${this.workspace.workspaceRoot}/dist/pkgs/${name}`);
|
|
674
694
|
}
|
|
675
695
|
static from(executor, name) {
|
|
676
696
|
if (executor instanceof WorkspaceExecutor)
|
|
@@ -706,5 +726,6 @@ export {
|
|
|
706
726
|
LibExecutor,
|
|
707
727
|
PkgExecutor,
|
|
708
728
|
SysExecutor,
|
|
709
|
-
WorkspaceExecutor
|
|
729
|
+
WorkspaceExecutor,
|
|
730
|
+
execEmoji
|
|
710
731
|
};
|
package/esm/src/index.js
CHANGED
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import ora from "ora";
|
|
2
|
+
class Spinner {
|
|
3
|
+
spinner;
|
|
4
|
+
stopWatch;
|
|
5
|
+
startAt;
|
|
6
|
+
message;
|
|
7
|
+
constructor(message, { prefix = "", indent = 0 } = {}) {
|
|
8
|
+
this.message = message;
|
|
9
|
+
this.spinner = ora(message);
|
|
10
|
+
this.spinner.prefixText = prefix;
|
|
11
|
+
this.spinner.indent = indent;
|
|
12
|
+
}
|
|
13
|
+
start() {
|
|
14
|
+
this.startAt = /* @__PURE__ */ new Date();
|
|
15
|
+
const spinner = this.spinner.start();
|
|
16
|
+
this.stopWatch = setInterval(() => {
|
|
17
|
+
spinner.text = `${this.message} (${this.#getElapsedTimeStr()})`;
|
|
18
|
+
}, 1e3);
|
|
19
|
+
return this;
|
|
20
|
+
}
|
|
21
|
+
succeed(message) {
|
|
22
|
+
clearInterval(this.stopWatch);
|
|
23
|
+
this.spinner.succeed(`${message} (${this.#getElapsedTimeStr()})`);
|
|
24
|
+
}
|
|
25
|
+
#getElapsedTimeStr() {
|
|
26
|
+
const ms = (/* @__PURE__ */ new Date()).getTime() - this.startAt.getTime();
|
|
27
|
+
if (ms < 1e3)
|
|
28
|
+
return `${ms}ms`;
|
|
29
|
+
const s = Math.floor(ms / 1e3);
|
|
30
|
+
if (s < 60)
|
|
31
|
+
return `${s}s`;
|
|
32
|
+
const m = Math.floor(s / 60);
|
|
33
|
+
return `${m}m ${s % 60}s`;
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
export {
|
|
37
|
+
Spinner
|
|
38
|
+
};
|
package/package.json
CHANGED
package/src/executors.d.ts
CHANGED
|
@@ -1,12 +1,22 @@
|
|
|
1
1
|
import { Logger } from "@akanjs/common";
|
|
2
2
|
import { type AppConfigResult, AppScanResult, type LibConfigResult, LibScanResult, PkgScanResult, WorkspaceScanResult } from "@akanjs/config";
|
|
3
3
|
import { type ExecOptions, type ForkOptions, type SpawnOptions } from "child_process";
|
|
4
|
+
import { Spinner } from "./spinner";
|
|
4
5
|
import type { PackageJson, TsConfigJson } from "./types";
|
|
6
|
+
export declare const execEmoji: {
|
|
7
|
+
workspace: string;
|
|
8
|
+
app: string;
|
|
9
|
+
lib: string;
|
|
10
|
+
pkg: string;
|
|
11
|
+
dist: string;
|
|
12
|
+
default: string;
|
|
13
|
+
};
|
|
5
14
|
export declare class Executor {
|
|
6
15
|
#private;
|
|
7
16
|
name: string;
|
|
8
17
|
logger: Logger;
|
|
9
18
|
cwdPath: string;
|
|
19
|
+
emoji: string;
|
|
10
20
|
constructor(name: string, cwdPath: string);
|
|
11
21
|
exec(command: string, options?: ExecOptions): Promise<unknown>;
|
|
12
22
|
spawn(command: string, args?: string[], options?: SpawnOptions): Promise<{
|
|
@@ -29,6 +39,10 @@ export declare class Executor {
|
|
|
29
39
|
cp(srcPath: string, destPath: string): Promise<void>;
|
|
30
40
|
log(msg: string): this;
|
|
31
41
|
verbose(msg: string): this;
|
|
42
|
+
spinning(msg: string, { prefix, indent }?: {
|
|
43
|
+
prefix?: string | undefined;
|
|
44
|
+
indent?: number | undefined;
|
|
45
|
+
}): Spinner;
|
|
32
46
|
getTsConfig(pathname?: string): TsConfigJson;
|
|
33
47
|
applyTemplate({ basePath, template, scanResult, dict, overwrite, }: {
|
|
34
48
|
basePath: string;
|
|
@@ -48,6 +62,7 @@ export declare class WorkspaceExecutor extends Executor {
|
|
|
48
62
|
#private;
|
|
49
63
|
workspaceRoot: string;
|
|
50
64
|
repoName: string;
|
|
65
|
+
emoji: string;
|
|
51
66
|
constructor({ workspaceRoot, repoName }: ExecutorOptions);
|
|
52
67
|
static fromRoot(): WorkspaceExecutor;
|
|
53
68
|
getBaseDevEnv(): {
|
|
@@ -86,6 +101,7 @@ export declare class SysExecutor extends Executor {
|
|
|
86
101
|
workspace: WorkspaceExecutor;
|
|
87
102
|
name: string;
|
|
88
103
|
type: "app" | "lib";
|
|
104
|
+
emoji: string;
|
|
89
105
|
constructor({ workspace, name, type }: SysExecutorOptions);
|
|
90
106
|
getConfig(command?: string): Promise<LibConfigResult>;
|
|
91
107
|
getModules(): Promise<string[]>;
|
|
@@ -133,6 +149,7 @@ interface AppExecutorOptions {
|
|
|
133
149
|
}
|
|
134
150
|
export declare class AppExecutor extends SysExecutor {
|
|
135
151
|
dist: Executor;
|
|
152
|
+
emoji: string;
|
|
136
153
|
constructor({ workspace, name }: AppExecutorOptions);
|
|
137
154
|
static from(executor: SysExecutor | WorkspaceExecutor, name: string): AppExecutor;
|
|
138
155
|
getConfig(command?: string): Promise<AppConfigResult>;
|
|
@@ -146,6 +163,7 @@ export declare class LibExecutor extends SysExecutor {
|
|
|
146
163
|
workspaceRoot: string;
|
|
147
164
|
repoName: string;
|
|
148
165
|
dist: Executor;
|
|
166
|
+
emoji: string;
|
|
149
167
|
constructor({ workspace, name }: LibExecutorOptions);
|
|
150
168
|
static from(executor: SysExecutor | WorkspaceExecutor, name: string): LibExecutor;
|
|
151
169
|
getConfig(command?: string): Promise<LibConfigResult>;
|
|
@@ -158,6 +176,7 @@ export declare class PkgExecutor extends Executor {
|
|
|
158
176
|
workspace: WorkspaceExecutor;
|
|
159
177
|
name: string;
|
|
160
178
|
dist: Executor;
|
|
179
|
+
emoji: string;
|
|
161
180
|
constructor({ workspace, name }: PkgExecutorOptions);
|
|
162
181
|
static from(executor: SysExecutor | WorkspaceExecutor, name: string): PkgExecutor;
|
|
163
182
|
scan({ packageJson, tsconfig, }?: {
|
package/src/index.d.ts
CHANGED
package/src/spinner.d.ts
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import ora from "ora";
|
|
2
|
+
export declare class Spinner {
|
|
3
|
+
#private;
|
|
4
|
+
spinner: ora.Ora;
|
|
5
|
+
stopWatch: NodeJS.Timeout;
|
|
6
|
+
startAt: Date;
|
|
7
|
+
message: string;
|
|
8
|
+
constructor(message: string, { prefix, indent }?: {
|
|
9
|
+
prefix?: string | undefined;
|
|
10
|
+
indent?: number | undefined;
|
|
11
|
+
});
|
|
12
|
+
start(): this;
|
|
13
|
+
succeed(message: string): void;
|
|
14
|
+
}
|