|
1 |
| -import { |
2 |
| - Config, |
3 |
| - DEFAULT_COMPONENTS, |
4 |
| - DEFAULT_LIB, |
5 |
| - getConfig, |
6 |
| - rawConfigSchema, |
7 |
| - resolveConfigPaths, |
8 |
| -} from '@/src/utils/get-config'; |
| 1 | +import { Config, getConfig } from '@/src/utils/get-config'; |
9 | 2 | import { getPackageManager } from '@/src/utils/get-package-manager';
|
10 | 3 | import { handleError } from '@/src/utils/handle-error';
|
11 | 4 | import { logger } from '@/src/utils/logger';
|
| 5 | +import { promptForConfig } from '@/src/utils/prompt-for-config'; |
12 | 6 | import chalk from 'chalk';
|
13 | 7 | import { Command } from 'commander';
|
14 | 8 | import { execa } from 'execa';
|
15 | 9 | import { existsSync, promises as fs } from 'fs';
|
16 | 10 | import ora, { Ora } from 'ora';
|
17 | 11 | import path from 'path';
|
18 | 12 | import prompts from 'prompts';
|
| 13 | +import { fileURLToPath } from 'url'; |
19 | 14 | import { z } from 'zod';
|
20 | 15 | import { Component, INVALID_COMPONENT_ERROR, getAllComponentsToWrite } from '../items';
|
21 | 16 | import { COMPONENTS } from '../items/components';
|
22 |
| -import { fileURLToPath } from 'url'; |
23 | 17 |
|
24 | 18 | const filePath = fileURLToPath(import.meta.url);
|
25 | 19 | const fileDir = path.dirname(filePath);
|
@@ -242,47 +236,3 @@ function fixImports(rawfile: string, componentsAlias: string, libAlias: string)
|
242 | 236 | .replaceAll('../../components', componentsAlias)
|
243 | 237 | .replaceAll('../../lib', libAlias);
|
244 | 238 | }
|
245 |
| - |
246 |
| -async function promptForConfig(cwd: string) { |
247 |
| - const highlight = (text: string) => chalk.cyan(text); |
248 |
| - |
249 |
| - const options = await prompts([ |
250 |
| - { |
251 |
| - type: 'text', |
252 |
| - name: 'components', |
253 |
| - message: `Configure the import alias for ${highlight('components')}:`, |
254 |
| - initial: DEFAULT_COMPONENTS, |
255 |
| - }, |
256 |
| - { |
257 |
| - type: 'text', |
258 |
| - name: 'lib', |
259 |
| - message: `Configure the import alias for ${highlight('lib')}:`, |
260 |
| - initial: DEFAULT_LIB, |
261 |
| - }, |
262 |
| - ]); |
263 |
| - |
264 |
| - const config = rawConfigSchema.parse({ |
265 |
| - aliases: { |
266 |
| - lib: options.lib, |
267 |
| - components: options.components, |
268 |
| - }, |
269 |
| - }); |
270 |
| - |
271 |
| - const { proceed } = await prompts({ |
272 |
| - type: 'confirm', |
273 |
| - name: 'proceed', |
274 |
| - message: `Write configuration to ${highlight('components.json')}. Proceed?`, |
275 |
| - initial: true, |
276 |
| - }); |
277 |
| - |
278 |
| - if (proceed) { |
279 |
| - // Write to file. |
280 |
| - logger.info(''); |
281 |
| - const spinner = ora(`Writing components.json...`).start(); |
282 |
| - const targetPath = path.resolve(cwd, 'components.json'); |
283 |
| - await fs.writeFile(targetPath, JSON.stringify(config, null, 2), 'utf8'); |
284 |
| - spinner.succeed(); |
285 |
| - } |
286 |
| - |
287 |
| - return await resolveConfigPaths(cwd, config); |
288 |
| -} |
0 commit comments