-
Notifications
You must be signed in to change notification settings - Fork 319
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
added warning message for invalid project
- Loading branch information
Showing
3 changed files
with
82 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
import { dim, gray, yellow } from 'kolorist'; | ||
import { exitOnCancel } from './exit-on-cancel'; | ||
import { outro, text } from '@clack/prompts'; | ||
import { execaCommand } from 'execa'; | ||
import * as p from '@clack/prompts'; | ||
|
||
export async function invalidProjectWarningMessage() { | ||
console.warn( | ||
yellow( | ||
'Warning: The current directory does not appear to be a recognized project folder.' | ||
) | ||
); | ||
|
||
const choice = await p.select({ | ||
message: 'Want to setup a new project' + ':', | ||
options: [ | ||
{ | ||
label: 'Node + Vitest project', | ||
value: 'node-vitest', | ||
}, | ||
{ | ||
label: 'Exit', | ||
value: 'cancel', | ||
}, | ||
], | ||
}); | ||
|
||
if (choice === 'node-vitest') { | ||
const command = `npm init -y && npm install typescript tsx @types/node vitest -D && npx tsc --init`; | ||
|
||
console.log(''); | ||
|
||
console.log(dim(`Running: ${command}`)); | ||
|
||
await execaCommand(command, { | ||
stdio: 'inherit', | ||
shell: process.env.SHELL || true, | ||
}).catch(() => { | ||
// No need to handle, will go to stderr | ||
}); | ||
|
||
process.exit(); | ||
} else if (choice === 'cancel') { | ||
outro('Goodbye!'); | ||
process.exit(0); | ||
} | ||
|
||
process.exit(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
import fs from 'fs/promises'; | ||
import path from 'path'; | ||
|
||
export async function isCorrectProject(): Promise<boolean> { | ||
const currentDir = process.cwd(); | ||
const packageJsonPath = path.join(currentDir, 'package.json'); | ||
const requirementsTxtPath = path.join(currentDir, 'requirements.txt'); | ||
|
||
try { | ||
await fs.access(packageJsonPath); | ||
return true; | ||
} catch { | ||
// Do nothing if file doesn't exist | ||
} | ||
|
||
try { | ||
await fs.access(requirementsTxtPath); | ||
return true; | ||
} catch { | ||
// Do nothing if file doesn't exist | ||
} | ||
|
||
return false; | ||
} |