pokit 0.0.15 → 0.0.16

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.
Files changed (2) hide show
  1. package/bin/pok.ts +89 -4
  2. package/package.json +1 -1
package/bin/pok.ts CHANGED
@@ -93,13 +93,92 @@ async function resolveModule(name: string, configDir: string) {
93
93
  }
94
94
  }
95
95
 
96
+ /**
97
+ * Detect the package manager used in the project (simple version for launcher).
98
+ */
99
+ function getPackageManagerSimple(projectRoot: string): 'npm' | 'pnpm' | 'yarn' | 'bun' {
100
+ if (fs.existsSync(path.join(projectRoot, 'pnpm-lock.yaml'))) return 'pnpm';
101
+ if (
102
+ fs.existsSync(path.join(projectRoot, 'bun.lockb')) ||
103
+ fs.existsSync(path.join(projectRoot, 'bun.lock'))
104
+ )
105
+ return 'bun';
106
+ if (fs.existsSync(path.join(projectRoot, 'yarn.lock'))) return 'yarn';
107
+ return 'npm';
108
+ }
109
+
110
+ /**
111
+ * Simple dependency-free Yes/No prompt.
112
+ */
113
+ async function askYesNo(question: string): Promise<boolean> {
114
+ if (!process.stdout.isTTY) return false;
115
+
116
+ process.stdout.write(`${question} (Y/n) `);
117
+ for await (const line of console) {
118
+ const input = line.trim().toLowerCase();
119
+ if (input === '' || input === 'y' || input === 'yes') return true;
120
+ if (input === 'n' || input === 'no') return false;
121
+ process.stdout.write('Please enter y or n: ');
122
+ }
123
+ return false;
124
+ }
125
+
126
+ /**
127
+ * Ensure required pok modules are installed in the project.
128
+ */
129
+ async function ensureModulesInstalled(pkgDir: string, moduleNames: string[]): Promise<boolean> {
130
+ const pm = getPackageManagerSimple(pkgDir);
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(' ')}`;
139
+
140
+ const confirmed = await askYesNo(
141
+ `Required pok modules (${moduleNames.join(', ')}) are missing locally. Install them with ${pm}?`
142
+ );
143
+
144
+ if (!confirmed) return false;
145
+
146
+ console.log(`\nInstalling modules: ${installCmd}...\n`);
147
+
148
+ try {
149
+ const { $ } = await import('bun');
150
+ await $`${{ raw: installCmd }}`.cwd(pkgDir);
151
+ console.log('\nModules installed successfully!\n');
152
+ return true;
153
+ } catch (err) {
154
+ console.error(
155
+ `\nFailed to install modules: ${err instanceof Error ? err.message : String(err)}`
156
+ );
157
+ return false;
158
+ }
159
+ }
160
+
96
161
  /**
97
162
  * Run pok in fallback mode when no config is found but package.json exists.
98
163
  */
99
164
  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);
165
+ let core = await resolveModule('@pokit/core', pkgDir);
166
+ let reporter = await resolveModule('@pokit/reporter-clack', pkgDir);
167
+ let prompter = await resolveModule('@pokit/prompter-clack', pkgDir);
168
+
169
+ if (!core || !reporter || !prompter) {
170
+ const missing = [];
171
+ if (!core) missing.push('@pokit/core');
172
+ if (!reporter) missing.push('@pokit/reporter-clack');
173
+ if (!prompter) missing.push('@pokit/prompter-clack');
174
+
175
+ if (await ensureModulesInstalled(pkgDir, missing)) {
176
+ // Retry resolution after installation
177
+ core = await resolveModule('@pokit/core', pkgDir);
178
+ reporter = await resolveModule('@pokit/reporter-clack', pkgDir);
179
+ prompter = await resolveModule('@pokit/prompter-clack', pkgDir);
180
+ }
181
+ }
103
182
 
104
183
  if (!core || !reporter || !prompter) {
105
184
  console.error(
@@ -160,7 +239,13 @@ Run \`pok init\` to create a pok.config.ts file.
160
239
  const { configPath, configDir } = configResult;
161
240
 
162
241
  // Step 2: Dynamically resolve @pokit/core from the project directory
163
- const configModule = await resolveModule('@pokit/core', configDir);
242
+ let configModule = await resolveModule('@pokit/core', configDir);
243
+
244
+ if (!configModule) {
245
+ if (await ensureModulesInstalled(configDir, ['@pokit/core'])) {
246
+ configModule = await resolveModule('@pokit/core', configDir);
247
+ }
248
+ }
164
249
 
165
250
  if (!configModule) {
166
251
  console.error(
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "pokit",
3
- "version": "0.0.15",
3
+ "version": "0.0.16",
4
4
  "description": "Global CLI launcher for pok - install once, run anywhere",
5
5
  "type": "module",
6
6
  "license": "MIT",