Skip to content

Commit

Permalink
Update init.mjs
Browse files Browse the repository at this point in the history
  • Loading branch information
haydenbleasel committed Jan 12, 2025
1 parent ca02cba commit acfed93
Showing 1 changed file with 21 additions and 14 deletions.
35 changes: 21 additions & 14 deletions scripts/init.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,10 @@ const internalContentFiles = [
const allInternalContent = [...internalContentDirs, ...internalContentFiles];

const runCommand = {
pnpm: 'pnpm',
npm: 'npx',
yarn: 'yarn',
bun: 'bun',
pnpm: 'pnpm create next-app@latest',
npm: 'npx create-next-app@latest',
yarn: 'yarn create next-app@latest',
bun: 'bun create next-app@latest',
};

program
Expand All @@ -57,23 +57,36 @@ program

log(chalk.green('Creating new next-forge project...'));
execSync(
`${runCommand[packageManager]} create next-app@latest ${projectName} --example "${url}" --disable-git`,
`${runCommand[packageManager]} ${projectName} --example "${url}" --disable-git`,
execSyncOpts
);
process.chdir(projectDir);

if (packageManager === 'bun') {
log(chalk.green('Configuring Bun workspaces...'));
if (packageManager !== 'pnpm') {
const packageJsonPath = join(projectDir, 'package.json');
const packageJson = JSON.parse(readFileSync(packageJsonPath, 'utf8'));

log(chalk.green('Updating package manager configuration...'));

if (packageManager === 'bun') {
packageJson.packageManager = '[email protected]';
} else if (packageManager === 'npm') {
packageJson.packageManager = '[email protected]';
} else if (packageManager === 'yarn') {
packageJson.packageManager = '[email protected]';
}

log(chalk.green('Updating workspace config...'));
packageJson.workspaces = ['apps/*', 'packages/*'];
packageJson.packageManager = '[email protected]';

writeFileSync(
packageJsonPath,
`${JSON.stringify(packageJson, null, 2)}\n`
);

log(chalk.green('Removing pnpm configuration...'));
rmSync('pnpm-lock.yaml', { force: true });
rmSync('pnpm-workspace.yaml', { force: true });
}

log(chalk.green('Deleting internal content...'));
Expand All @@ -98,12 +111,6 @@ program
}
}

if (packageManager !== 'pnpm') {
log(chalk.green('Removing pnpm lockfile and workspace config...'));
rmSync('pnpm-lock.yaml', { force: true });
rmSync('pnpm-workspace.yaml', { force: true });
}

log(chalk.green('Installing dependencies...'));
execSync(`${packageManager} install`, execSyncOpts);

Expand Down

0 comments on commit acfed93

Please sign in to comment.