pokit 0.0.13 → 0.0.15
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 +101 -14
- package/package.json +5 -2
- package/src/protocol.ts +13 -7
package/bin/pok.ts
CHANGED
|
@@ -55,6 +55,87 @@ function findConfigFileSimple(startDir: string): { configPath: string; configDir
|
|
|
55
55
|
}
|
|
56
56
|
}
|
|
57
57
|
|
|
58
|
+
/**
|
|
59
|
+
* Simple inline package.json search.
|
|
60
|
+
*/
|
|
61
|
+
function findPackageJsonSimple(startDir: string): { pkgPath: string; pkgDir: string } | null {
|
|
62
|
+
let dir = startDir;
|
|
63
|
+
|
|
64
|
+
while (true) {
|
|
65
|
+
const pkgPath = path.join(dir, 'package.json');
|
|
66
|
+
if (fs.existsSync(pkgPath)) {
|
|
67
|
+
return { pkgPath, pkgDir: dir };
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
const parentDir = path.dirname(dir);
|
|
71
|
+
if (parentDir === dir) {
|
|
72
|
+
return null;
|
|
73
|
+
}
|
|
74
|
+
dir = parentDir;
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
/**
|
|
79
|
+
* Try to resolve a module from the project directory, then from the launcher's own dependencies.
|
|
80
|
+
*/
|
|
81
|
+
async function resolveModule(name: string, configDir: string) {
|
|
82
|
+
try {
|
|
83
|
+
// 1. Try resolving from the project's node_modules
|
|
84
|
+
const projectModulePath = await resolve(name, configDir);
|
|
85
|
+
return await import(projectModulePath);
|
|
86
|
+
} catch {
|
|
87
|
+
try {
|
|
88
|
+
// 2. Try resolving from the launcher's own dependencies
|
|
89
|
+
return await import(name);
|
|
90
|
+
} catch {
|
|
91
|
+
return null;
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
/**
|
|
97
|
+
* Run pok in fallback mode when no config is found but package.json exists.
|
|
98
|
+
*/
|
|
99
|
+
async function runInFallbackMode(pkgDir: string) {
|
|
100
|
+
const core = await resolveModule('@pokit/core', pkgDir);
|
|
101
|
+
const reporter = await resolveModule('@pokit/reporter-clack', pkgDir);
|
|
102
|
+
const prompter = await resolveModule('@pokit/prompter-clack', pkgDir);
|
|
103
|
+
|
|
104
|
+
if (!core || !reporter || !prompter) {
|
|
105
|
+
console.error(
|
|
106
|
+
`Error: Required pok modules not found.\n\n` +
|
|
107
|
+
`Install them in your project to enable the fallback menu:\n` +
|
|
108
|
+
` bun add -d @pokit/core @pokit/reporter-clack @pokit/prompter-clack\n\n` +
|
|
109
|
+
`Or run \`pok init\` to bootstrap a configuration.`
|
|
110
|
+
);
|
|
111
|
+
process.exit(1);
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
const { runCli, defineCommand } = core;
|
|
115
|
+
const { createReporterAdapter } = reporter;
|
|
116
|
+
const { createPrompter } = prompter;
|
|
117
|
+
const { runInit } = await import('../src/init');
|
|
118
|
+
|
|
119
|
+
await runCli(process.argv.slice(2), {
|
|
120
|
+
commandsDir: path.join(pkgDir, 'commands'),
|
|
121
|
+
projectRoot: pkgDir,
|
|
122
|
+
appName: path.basename(pkgDir),
|
|
123
|
+
reporterAdapter: createReporterAdapter(),
|
|
124
|
+
prompter: createPrompter(),
|
|
125
|
+
pmScripts: true,
|
|
126
|
+
pmCommands: true,
|
|
127
|
+
extraCommands: {
|
|
128
|
+
init: defineCommand({
|
|
129
|
+
label: 'init',
|
|
130
|
+
description: 'Initialize pok config in this repo',
|
|
131
|
+
run: async () => {
|
|
132
|
+
await runInit();
|
|
133
|
+
},
|
|
134
|
+
}),
|
|
135
|
+
},
|
|
136
|
+
});
|
|
137
|
+
}
|
|
138
|
+
|
|
58
139
|
async function main() {
|
|
59
140
|
const processCwd = process.cwd();
|
|
60
141
|
|
|
@@ -62,7 +143,14 @@ async function main() {
|
|
|
62
143
|
const configResult = findConfigFileSimple(processCwd);
|
|
63
144
|
|
|
64
145
|
if (!configResult) {
|
|
65
|
-
|
|
146
|
+
// Look for package.json
|
|
147
|
+
const pkgJsonResult = findPackageJsonSimple(processCwd);
|
|
148
|
+
if (pkgJsonResult) {
|
|
149
|
+
await runInFallbackMode(pkgJsonResult.pkgDir);
|
|
150
|
+
return;
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
console.error(`Error: No pok configuration or package.json found.
|
|
66
154
|
|
|
67
155
|
Run \`pok init\` to create a pok.config.ts file.
|
|
68
156
|
`);
|
|
@@ -72,12 +160,9 @@ Run \`pok init\` to create a pok.config.ts file.
|
|
|
72
160
|
const { configPath, configDir } = configResult;
|
|
73
161
|
|
|
74
162
|
// Step 2: Dynamically resolve @pokit/core from the project directory
|
|
75
|
-
|
|
163
|
+
const configModule = await resolveModule('@pokit/core', configDir);
|
|
76
164
|
|
|
77
|
-
|
|
78
|
-
const configModulePath = await resolve('@pokit/core', configDir);
|
|
79
|
-
configModule = await import(configModulePath);
|
|
80
|
-
} catch {
|
|
165
|
+
if (!configModule) {
|
|
81
166
|
console.error(
|
|
82
167
|
`Error: @pokit/core is not installed in ${configDir}\n\n` +
|
|
83
168
|
'Install it with:\n' +
|
|
@@ -107,7 +192,9 @@ Run \`pok init\` to create a pok.config.ts file.
|
|
|
107
192
|
// Verify commands directory exists
|
|
108
193
|
if (!fs.existsSync(commandsDir)) {
|
|
109
194
|
console.error(`Error: Commands directory not found: ${commandsDir}\n`);
|
|
110
|
-
console.error(
|
|
195
|
+
console.error(
|
|
196
|
+
`The commandsDir path in ${configPath} resolves to a directory that doesn't exist.`
|
|
197
|
+
);
|
|
111
198
|
process.exit(1);
|
|
112
199
|
}
|
|
113
200
|
|
|
@@ -120,13 +207,13 @@ Run \`pok init\` to create a pok.config.ts file.
|
|
|
120
207
|
projectRoot: cwd, // core uses projectRoot, config uses cwd
|
|
121
208
|
appName: config.appName,
|
|
122
209
|
version: config.version,
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
210
|
+
reporterAdapter: config.reporter,
|
|
211
|
+
prompter: config.prompter,
|
|
212
|
+
tabs: config.tabs,
|
|
213
|
+
pmScripts: config.pmScripts,
|
|
214
|
+
pmCommands: config.pmCommands,
|
|
215
|
+
});
|
|
216
|
+
}
|
|
130
217
|
|
|
131
218
|
main().catch((err) => {
|
|
132
219
|
console.error(err);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "pokit",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.15",
|
|
4
4
|
"description": "Global CLI launcher for pok - install once, run anywhere",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"license": "MIT",
|
|
@@ -30,7 +30,10 @@
|
|
|
30
30
|
"access": "public"
|
|
31
31
|
},
|
|
32
32
|
"devDependencies": {
|
|
33
|
-
"@types/bun": "latest"
|
|
33
|
+
"@types/bun": "latest",
|
|
34
|
+
"@pokit/core": "0.0.15",
|
|
35
|
+
"@pokit/reporter-clack": "0.0.15",
|
|
36
|
+
"@pokit/prompter-clack": "0.0.15"
|
|
34
37
|
},
|
|
35
38
|
"engines": {
|
|
36
39
|
"bun": ">=1.0.0"
|
package/src/protocol.ts
CHANGED
|
@@ -24,13 +24,19 @@ export interface LauncherSkeleton {
|
|
|
24
24
|
prompter: any;
|
|
25
25
|
/** Optional tabs adapter instance */
|
|
26
26
|
tabs?: any;
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
27
|
+
/**
|
|
28
|
+
* Package manager scripts to include as commands.
|
|
29
|
+
* - true: Include all scripts from root package.json
|
|
30
|
+
* - string[]: List of script names, glob patterns (e.g. 'test:*'),
|
|
31
|
+
* or package discovery paths (e.g. 'packages/*')
|
|
32
|
+
*/
|
|
33
|
+
pmScripts?: boolean | string[];
|
|
34
|
+
/**
|
|
35
|
+
* Native package manager commands to include (e.g. 'install', 'add', 'run').
|
|
36
|
+
* - true: Include standard lifecycle commands
|
|
37
|
+
* - string[]: List of specific commands to include
|
|
38
|
+
*/
|
|
39
|
+
pmCommands?: boolean | string[];
|
|
34
40
|
}
|
|
35
41
|
|
|
36
42
|
/**
|