Skip to content

Commit

Permalink
feat: detect if in a valid project and generate one if not
Browse files Browse the repository at this point in the history
  • Loading branch information
steve8708 committed Jun 12, 2024
1 parent f0af3fa commit b8a5731
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 11 deletions.
6 changes: 3 additions & 3 deletions src/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import { RunOptions, runAll } from './helpers/run';
import { interactiveMode } from './helpers/interactive-mode';
import { fileExists } from './helpers/file-exists';
import { outro } from '@clack/prompts';
import { isCorrectProject } from './helpers/validate-project';
import { isValidProject } from './helpers/validate-project';
import { invalidProjectWarningMessage } from './helpers/invalid-project-warning';

cli(
Expand Down Expand Up @@ -85,9 +85,9 @@ cli(
};
try {
if (!argv._.filePath || !argv.flags.test) {
const isCorrectFolderStructure = await isCorrectProject();
const isValidproject = await isValidProject();

if (!isCorrectFolderStructure) {
if (!isValidproject) {
await invalidProjectWarningMessage();
} else {
await interactiveMode(runOptions);
Expand Down
9 changes: 4 additions & 5 deletions src/helpers/invalid-project-warning.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
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';
import { outro } from '@clack/prompts';
import { execaCommand } from 'execa';
import { dim, yellow } from 'kolorist';

export async function invalidProjectWarningMessage() {
console.warn(
Expand All @@ -12,7 +11,7 @@ export async function invalidProjectWarningMessage() {
);

const choice = await p.select({
message: 'Want to setup a new project' + ':',
message: 'Want to setup a new project?',
options: [
{
label: 'Node + Vitest project',
Expand Down
6 changes: 3 additions & 3 deletions src/helpers/validate-project.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import fs from 'fs/promises';
import path from 'path';
import { findPackageJson } from './find-package-json';

export async function isCorrectProject(): Promise<boolean> {
export async function isValidProject(): 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);
await findPackageJson();
return true;
} catch {
// Do nothing if file doesn't exist
Expand Down

0 comments on commit b8a5731

Please sign in to comment.