Skip to content

Commit

Permalink
chore: Add few helpers to create-vitnode-app
Browse files Browse the repository at this point in the history
  • Loading branch information
aXenDeveloper committed Jul 11, 2024
1 parent 9e3214c commit 93ae3fe
Show file tree
Hide file tree
Showing 5 changed files with 68 additions and 16 deletions.
15 changes: 15 additions & 0 deletions packages/create-vitnode-app/helpers/get-pkg-manager.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
export type PackageManager = 'npm' | 'pnpm' | 'yarn';

export function getPkgManager(): PackageManager {
const userAgent = process.env.npm_config_user_agent || '';

if (userAgent.startsWith('yarn')) {
return 'yarn';
}

if (userAgent.startsWith('pnpm')) {
return 'pnpm';
}

return 'npm';
}
11 changes: 11 additions & 0 deletions packages/create-vitnode-app/helpers/is-writeable.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import { W_OK } from 'constants';
import { access } from 'fs/promises';

export async function isWriteable(directory: string): Promise<boolean> {
try {
await access(directory, W_OK);
return true;
} catch (err) {
return false;
}
}
54 changes: 40 additions & 14 deletions packages/create-vitnode-app/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,30 +6,41 @@ import figlet from 'figlet';
import packageJson from './package.json' assert { type: 'json' };
import prompts from 'prompts';
import { validateNpmName } from './helpers/validate-pkg';
import { basename, resolve } from 'path';
import { basename, dirname, resolve } from 'path';
import { existsSync } from 'fs';
import { isFolderEmpty } from './helpers/is-folder-empty';
import { getPkgManager } from './helpers/get-pkg-manager';
import { isWriteable } from './helpers/is-writeable';

let projectPath: string = '';

const program = new Command()
const program = new Command(packageJson.name)
.version(packageJson.version)
.argument('[project-directory]')
.usage(`${colors.green('[project-directory]')} [options]`)
.action(name => {
projectPath = name;
});
})
.option('--turbo', 'Enable Turbopack by default for development.')
.option('--use-npm', 'Use NPM as the package manager.')
.option('--use-yarn', 'Use Yarn as the package manager.')
.option('--use-pnpm', 'Use PNPM as the package manager.')
.option(
'--skip-install',
'Skip installing packages after initializing the project.',
)
.parse(process.argv)
.opts();

program.option('--turbo', 'Enable Turbopack by default for development.');
program.option('--use-npm', 'Use NPM as the package manager.');
// program.option('--use-yarn', 'Use Yarn as the package manager.');
program.option('--use-pnpm', 'Use PNPM as the package manager.');
program.option(
'--skip-install',
'Skip installing packages after initializing the project.',
);

program.parse(process.argv);
const packageManager = !!program.useNpm
? 'npm'
: !!program.usePnpm
? 'pnpm'
: !!program.useYarn
? 'yarn'
: !!program.useBun
? 'bun'
: getPkgManager();

(async () => {
console.log(
Expand All @@ -47,7 +58,9 @@ program.parse(process.argv);
message: 'What is your project named?',
initial: 'my-app',
validate: name => {
const validation = validateNpmName({ name: basename(resolve(name)) });
const validation = validateNpmName({
name: basename(resolve(name)),
});
if (validation.valid) return true;

return `Invalid project name: ${validation.problems[0]}`;
Expand Down Expand Up @@ -100,5 +113,18 @@ program.parse(process.argv);
process.exit(1);
}

/**
* Verify the project dir is writeable
*/
if (!(await isWriteable(dirname(root)))) {
console.error(
'The application path is not writable, please check folder permissions and try again.',
);
console.error(
'It is likely you do not have write permissions for this folder.',
);
process.exit(1);
}

console.log(`Creating a new VitNode app in ${resolvedProjectPath}.\n`);
})();
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ export const AuthAdminLayout = ({ children }: AuthAdminLayoutProps) => {
<AsideAuthAdmin />
{/* <HeaderAdmin /> */}

<main className="text-card-foreground p-5 sm:pl-2 md:ml-[240px] xl:ml-[260px]">
<main className="text-card-foreground px-10 py-5 md:ml-[240px] xl:ml-[260px]">
<div className="container">{children}</div>
</main>
</>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ export const LinkItemNavAdmin = ({

const buttonClass = (active: boolean) =>
cn(
'hover:text-foreground/90 text-muted-foreground relative h-9 w-full justify-start font-normal [&>svg]:flex [&>svg]:size-4 [&>svg]:flex-shrink-0 [&>svg]:items-center [&>svg]:justify-center [&[data-state=open]>svg:not(:first-child)]:rotate-180',
'hover:text-foreground/90 text-muted-foreground relative h-8 w-full justify-start font-normal [&>svg]:flex [&>svg]:size-4 [&>svg]:flex-shrink-0 [&>svg]:items-center [&>svg]:justify-center [&[data-state=open]>svg:not(:first-child)]:rotate-180',
{
'bg-primary/10 text-primary [&>svg]:text-primary hover:text-primary font-semibold':
active,
Expand Down

0 comments on commit 93ae3fe

Please sign in to comment.