pokit 0.0.21 → 0.0.35
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/bin/pok.ts +1 -0
- package/bin/poks.ts +123 -0
- package/package.json +6 -5
- package/src/protocol.ts +4 -0
package/bin/pok.ts
CHANGED
package/bin/poks.ts
ADDED
|
@@ -0,0 +1,123 @@
|
|
|
1
|
+
#!/usr/bin/env bun
|
|
2
|
+
import { resolve } from 'bun';
|
|
3
|
+
import * as fs from 'fs';
|
|
4
|
+
import * as path from 'path';
|
|
5
|
+
|
|
6
|
+
main().catch((err) => {
|
|
7
|
+
console.error(err);
|
|
8
|
+
process.exit(1);
|
|
9
|
+
});
|
|
10
|
+
|
|
11
|
+
async function main() {
|
|
12
|
+
const args = process.argv.slice(2);
|
|
13
|
+
|
|
14
|
+
const processCwd = process.cwd();
|
|
15
|
+
const configResult = findConfigFileSimple(processCwd);
|
|
16
|
+
|
|
17
|
+
let appName: string;
|
|
18
|
+
let configDir: string;
|
|
19
|
+
|
|
20
|
+
if (configResult) {
|
|
21
|
+
configDir = configResult.configDir;
|
|
22
|
+
try {
|
|
23
|
+
const rawConfig = await import(configResult.configPath);
|
|
24
|
+
appName = rawConfig.default?.appName ?? path.basename(configDir);
|
|
25
|
+
} catch {
|
|
26
|
+
appName = path.basename(configDir);
|
|
27
|
+
}
|
|
28
|
+
} else {
|
|
29
|
+
configDir = processCwd;
|
|
30
|
+
appName = path.basename(processCwd);
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
const core = await resolveModule('@pokit/core', configDir);
|
|
34
|
+
if (!core) {
|
|
35
|
+
console.error('Error: @pokit/core is not installed.');
|
|
36
|
+
process.exit(1);
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
const { loadHistory, formatEntryLabel, clearHistory } = core;
|
|
40
|
+
|
|
41
|
+
if (args[0] === '--clear') {
|
|
42
|
+
clearHistory(appName);
|
|
43
|
+
console.log('History cleared.');
|
|
44
|
+
return;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
const entries = loadHistory(appName);
|
|
48
|
+
|
|
49
|
+
if (entries.length === 0) {
|
|
50
|
+
console.log('No command history yet.');
|
|
51
|
+
return;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
const reporter = await resolveModule('@pokit/reporter-clack', configDir);
|
|
55
|
+
const prompter = await resolveModule('@pokit/prompter-clack', configDir);
|
|
56
|
+
|
|
57
|
+
if (!reporter || !prompter) {
|
|
58
|
+
console.error('Error: @pokit/reporter-clack and @pokit/prompter-clack are required.');
|
|
59
|
+
process.exit(1);
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
const { createPrompter } = prompter;
|
|
63
|
+
const p = createPrompter();
|
|
64
|
+
|
|
65
|
+
const options = entries.map((entry: any) => ({
|
|
66
|
+
value: entry,
|
|
67
|
+
label: formatEntryLabel(entry),
|
|
68
|
+
}));
|
|
69
|
+
|
|
70
|
+
const choose = p.autocomplete ? p.autocomplete.bind(p) : p.select.bind(p);
|
|
71
|
+
|
|
72
|
+
const selected: any = await choose({
|
|
73
|
+
message: 'Recent commands',
|
|
74
|
+
options,
|
|
75
|
+
});
|
|
76
|
+
|
|
77
|
+
if (!selected) {
|
|
78
|
+
return;
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
const rerunArgs = [...selected.commandPath, ...selected.args];
|
|
82
|
+
|
|
83
|
+
const { execSync } = await import('child_process');
|
|
84
|
+
execSync(`pok ${rerunArgs.join(' ')}`, {
|
|
85
|
+
stdio: 'inherit',
|
|
86
|
+
cwd: processCwd,
|
|
87
|
+
});
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
function findConfigFileSimple(startDir: string): { configPath: string; configDir: string } | null {
|
|
91
|
+
let dir = startDir;
|
|
92
|
+
|
|
93
|
+
while (true) {
|
|
94
|
+
const configPath = path.join(dir, 'pok.config.ts');
|
|
95
|
+
if (fs.existsSync(configPath)) {
|
|
96
|
+
return { configPath, configDir: dir };
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
const dotConfigPath = path.join(dir, '.config', 'pok.config.ts');
|
|
100
|
+
if (fs.existsSync(dotConfigPath)) {
|
|
101
|
+
return { configPath: dotConfigPath, configDir: dir };
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
const parentDir = path.dirname(dir);
|
|
105
|
+
if (parentDir === dir) {
|
|
106
|
+
return null;
|
|
107
|
+
}
|
|
108
|
+
dir = parentDir;
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
async function resolveModule(name: string, configDir: string) {
|
|
113
|
+
try {
|
|
114
|
+
const projectModulePath = await resolve(name, configDir);
|
|
115
|
+
return await import(projectModulePath);
|
|
116
|
+
} catch {
|
|
117
|
+
try {
|
|
118
|
+
return await import(name);
|
|
119
|
+
} catch {
|
|
120
|
+
return null;
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "pokit",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.35",
|
|
4
4
|
"description": "Global CLI launcher for pok - install once, run anywhere",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"license": "MIT",
|
|
@@ -14,7 +14,8 @@
|
|
|
14
14
|
"url": "https://github.com/notation-dev/openpok/issues"
|
|
15
15
|
},
|
|
16
16
|
"bin": {
|
|
17
|
-
"pok": "./bin/pok.ts"
|
|
17
|
+
"pok": "./bin/pok.ts",
|
|
18
|
+
"poks": "./bin/poks.ts"
|
|
18
19
|
},
|
|
19
20
|
"exports": {
|
|
20
21
|
".": {
|
|
@@ -31,9 +32,9 @@
|
|
|
31
32
|
},
|
|
32
33
|
"devDependencies": {
|
|
33
34
|
"@types/bun": "latest",
|
|
34
|
-
"@pokit/core": "0.0.
|
|
35
|
-
"@pokit/
|
|
36
|
-
"@pokit/
|
|
35
|
+
"@pokit/core": "0.0.35",
|
|
36
|
+
"@pokit/prompter-clack": "0.0.35",
|
|
37
|
+
"@pokit/reporter-clack": "0.0.35"
|
|
37
38
|
},
|
|
38
39
|
"engines": {
|
|
39
40
|
"bun": ">=1.0.0"
|