pokit 0.0.16 → 0.0.18
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 +66 -19
- package/package.json +4 -4
package/bin/pok.ts
CHANGED
|
@@ -94,17 +94,65 @@ async function resolveModule(name: string, configDir: string) {
|
|
|
94
94
|
}
|
|
95
95
|
|
|
96
96
|
/**
|
|
97
|
-
* Detect the package manager
|
|
97
|
+
* Detect the package manager and workspace status.
|
|
98
98
|
*/
|
|
99
|
-
function
|
|
100
|
-
|
|
101
|
-
|
|
99
|
+
function getPMInfo(projectRoot: string): {
|
|
100
|
+
name: 'npm' | 'pnpm' | 'yarn' | 'bun';
|
|
101
|
+
isWorkspaceRoot: boolean;
|
|
102
|
+
} {
|
|
103
|
+
let name: 'npm' | 'pnpm' | 'yarn' | 'bun' = 'npm';
|
|
104
|
+
let isWorkspaceRoot = false;
|
|
105
|
+
|
|
106
|
+
if (fs.existsSync(path.join(projectRoot, 'pnpm-lock.yaml'))) {
|
|
107
|
+
name = 'pnpm';
|
|
108
|
+
if (fs.existsSync(path.join(projectRoot, 'pnpm-workspace.yaml'))) {
|
|
109
|
+
isWorkspaceRoot = true;
|
|
110
|
+
}
|
|
111
|
+
} else if (
|
|
102
112
|
fs.existsSync(path.join(projectRoot, 'bun.lockb')) ||
|
|
103
113
|
fs.existsSync(path.join(projectRoot, 'bun.lock'))
|
|
104
|
-
)
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
114
|
+
) {
|
|
115
|
+
name = 'bun';
|
|
116
|
+
// Bun doesn't strictly require a flag for root, but we can detect it
|
|
117
|
+
try {
|
|
118
|
+
const pkg = JSON.parse(fs.readFileSync(path.join(projectRoot, 'package.json'), 'utf-8'));
|
|
119
|
+
if (pkg.workspaces) isWorkspaceRoot = true;
|
|
120
|
+
} catch {}
|
|
121
|
+
} else if (fs.existsSync(path.join(projectRoot, 'yarn.lock'))) {
|
|
122
|
+
name = 'yarn';
|
|
123
|
+
try {
|
|
124
|
+
const pkg = JSON.parse(fs.readFileSync(path.join(projectRoot, 'package.json'), 'utf-8'));
|
|
125
|
+
if (pkg.workspaces) isWorkspaceRoot = true;
|
|
126
|
+
} catch {}
|
|
127
|
+
} else {
|
|
128
|
+
name = 'npm';
|
|
129
|
+
try {
|
|
130
|
+
const pkg = JSON.parse(fs.readFileSync(path.join(projectRoot, 'package.json'), 'utf-8'));
|
|
131
|
+
if (pkg.workspaces) isWorkspaceRoot = true;
|
|
132
|
+
} catch {}
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
return { name, isWorkspaceRoot };
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
/**
|
|
139
|
+
* Generate the appropriate installation command for the detected PM.
|
|
140
|
+
*/
|
|
141
|
+
function getInstallCommand(pkgDir: string, moduleNames: string[]): string {
|
|
142
|
+
const { name, isWorkspaceRoot } = getPMInfo(pkgDir);
|
|
143
|
+
const modules = moduleNames.join(' ');
|
|
144
|
+
|
|
145
|
+
switch (name) {
|
|
146
|
+
case 'pnpm':
|
|
147
|
+
return `pnpm add -D ${modules}${isWorkspaceRoot ? ' -w' : ''}`;
|
|
148
|
+
case 'yarn':
|
|
149
|
+
return `yarn add -D ${modules}${isWorkspaceRoot ? ' -W' : ''}`;
|
|
150
|
+
case 'bun':
|
|
151
|
+
return `bun add -d ${modules}`;
|
|
152
|
+
case 'npm':
|
|
153
|
+
default:
|
|
154
|
+
return `npm install --save-dev ${modules}`;
|
|
155
|
+
}
|
|
108
156
|
}
|
|
109
157
|
|
|
110
158
|
/**
|
|
@@ -127,15 +175,8 @@ async function askYesNo(question: string): Promise<boolean> {
|
|
|
127
175
|
* Ensure required pok modules are installed in the project.
|
|
128
176
|
*/
|
|
129
177
|
async function ensureModulesInstalled(pkgDir: string, moduleNames: string[]): Promise<boolean> {
|
|
130
|
-
const pm =
|
|
131
|
-
const installCmd =
|
|
132
|
-
pm === 'npm'
|
|
133
|
-
? `npm install --save-dev ${moduleNames.join(' ')}`
|
|
134
|
-
: pm === 'pnpm'
|
|
135
|
-
? `pnpm add -D ${moduleNames.join(' ')}`
|
|
136
|
-
: pm === 'yarn'
|
|
137
|
-
? `yarn add -D ${moduleNames.join(' ')}`
|
|
138
|
-
: `bun add -d ${moduleNames.join(' ')}`;
|
|
178
|
+
const { name: pm } = getPMInfo(pkgDir);
|
|
179
|
+
const installCmd = getInstallCommand(pkgDir, moduleNames);
|
|
139
180
|
|
|
140
181
|
const confirmed = await askYesNo(
|
|
141
182
|
`Required pok modules (${moduleNames.join(', ')}) are missing locally. Install them with ${pm}?`
|
|
@@ -181,10 +222,15 @@ async function runInFallbackMode(pkgDir: string) {
|
|
|
181
222
|
}
|
|
182
223
|
|
|
183
224
|
if (!core || !reporter || !prompter) {
|
|
225
|
+
const installCmd = getInstallCommand(pkgDir, [
|
|
226
|
+
'@pokit/core',
|
|
227
|
+
'@pokit/reporter-clack',
|
|
228
|
+
'@pokit/prompter-clack',
|
|
229
|
+
]);
|
|
184
230
|
console.error(
|
|
185
231
|
`Error: Required pok modules not found.\n\n` +
|
|
186
232
|
`Install them in your project to enable the fallback menu:\n` +
|
|
187
|
-
`
|
|
233
|
+
` ${installCmd}\n\n` +
|
|
188
234
|
`Or run \`pok init\` to bootstrap a configuration.`
|
|
189
235
|
);
|
|
190
236
|
process.exit(1);
|
|
@@ -248,10 +294,11 @@ Run \`pok init\` to create a pok.config.ts file.
|
|
|
248
294
|
}
|
|
249
295
|
|
|
250
296
|
if (!configModule) {
|
|
297
|
+
const installCmd = getInstallCommand(configDir, ['@pokit/core']);
|
|
251
298
|
console.error(
|
|
252
299
|
`Error: @pokit/core is not installed in ${configDir}\n\n` +
|
|
253
300
|
'Install it with:\n' +
|
|
254
|
-
|
|
301
|
+
` ${installCmd}\n`
|
|
255
302
|
);
|
|
256
303
|
process.exit(1);
|
|
257
304
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "pokit",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.18",
|
|
4
4
|
"description": "Global CLI launcher for pok - install once, run anywhere",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"license": "MIT",
|
|
@@ -31,9 +31,9 @@
|
|
|
31
31
|
},
|
|
32
32
|
"devDependencies": {
|
|
33
33
|
"@types/bun": "latest",
|
|
34
|
-
"@pokit/core": "0.0.
|
|
35
|
-
"@pokit/
|
|
36
|
-
"@pokit/
|
|
34
|
+
"@pokit/core": "0.0.18",
|
|
35
|
+
"@pokit/prompter-clack": "0.0.18",
|
|
36
|
+
"@pokit/reporter-clack": "0.0.18"
|
|
37
37
|
},
|
|
38
38
|
"engines": {
|
|
39
39
|
"bun": ">=1.0.0"
|