MCPcopy Index your code
hub / github.com/CommandCodeAI/BaseAI / ensurePackageJson

Function ensurePackageJson

packages/baseai/src/init/index.ts:37–68  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

35}
36
37async function ensurePackageJson(): Promise<void> {
38 const exists = await checkFileExists('package.json');
39 if (!exists) {
40 const create = await p.confirm({
41 message: `No ${color.red('package.json')} found. Would you like to create one using ${color.cyan(color.bold('npm init -y'))}?`
42 });
43
44 if (p.isCancel(create)) {
45 p.cancel('Operation cancelled.');
46 process.exit(0);
47 }
48
49 if (!create) {
50 exitSetupFailed({
51 errorMessage: 'Cannot proceed without a package.json file.',
52 warningMessage:
53 'Run the command in a directory with a package.json file or allow the setup to create one.'
54 });
55 }
56
57 try {
58 await execa('npm', ['init', '-y']);
59 p.log.success('Created package.json file.');
60 } catch (error) {
61 exitSetupFailed({
62 errorMessage: `Failed to create package.json: ${error instanceof Error ? error.message : String(error)}`,
63 warningMessage:
64 'Ensure you have permission to create files in this directory and npm is installed.'
65 });
66 }
67 }
68}
69
70async function getPackageManager(targetDir: string): Promise<PackageManager> {
71 const packageManager = await detect({ programmatic: true, cwd: targetDir });

Callers 1

initFunction · 0.85

Calls 3

checkFileExistsFunction · 0.85
exitSetupFailedFunction · 0.85
cancelMethod · 0.45

Tested by

no test coverage detected