Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 15 additions & 1 deletion src/commands/create/cli.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
import { execSync } from 'child_process';

import prompts from 'prompts';
import { unflatten } from 'flat';

import {
adapterOptions, packageManagerOptions, pluginOptions, databaseDriversForAdapter, environmentVariablesPrompts,
} from './options.js';
import { CreateCommand } from './command.js';
import { CreateCommandInput } from './types.js';
import { CreateCommandInput, PackageManager } from './types.js';

const questions: prompts.PromptObject[] = [
{
Expand All @@ -32,6 +34,18 @@ const questions: prompts.PromptObject[] = [
message: 'Select a package manager',
choices: packageManagerOptions,
},
{
type: (prev) => {
if (prev !== PackageManager.Yarn) {
return null;
}
const isYarn1 = execSync('yarn --version', { stdio: 'pipe' }).toString().trim().startsWith('1');
return isYarn1 ? null : 'confirm';
},
name: 'yarnPnp',
message: 'Would you like to enable Yarn PnP?',
initial: false,
},
{
type: 'select',
name: 'plugin',
Expand Down
20 changes: 20 additions & 0 deletions src/commands/create/handlers/BaseSetup.handler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@ export class BaseSetupHandler extends BaseCommandHandler<CreateCommandInput> {
await this.modifyPackageName();
await this.copyDotFile('.eslintrc.cjs');
await this.copyDotFile('.prettierrc');
if (this.options.packageManager === 'yarn') {
await this.setupYarnrc(!!this.options.yarnPnp);
}
logger.info('Base template setup successful.');
}

Expand Down Expand Up @@ -52,4 +55,21 @@ export class BaseSetupHandler extends BaseCommandHandler<CreateCommandInput> {
destination,
);
}

protected async setupYarnrc(pnpEnabled: boolean) {
const yarnrcPath = path.join(process.cwd(), this.options.projectName, '.yarnrc.yml');
let content = pnpEnabled ? 'nodeLinker: pnp' : 'nodeLinker: node-modules';

// An workaround for dependencies problem
// Ref: https://github.com/ueberdosis/tiptap/issues/3746
if (pnpEnabled) {
content += `
packageExtensions:
'@tiptap/starter-kit@^2.0.0':
peerDependencies:
'@tiptap/pm': '^2.0.0'`;
}

await fs.writeFile(yarnrcPath, content, 'utf8');
}
}
1 change: 1 addition & 0 deletions src/commands/create/options.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import {
export const packageManagerOptions = [
{ title: 'NPM', value: PackageManager.NPM },
{ title: 'Yarn', value: PackageManager.Yarn },
{ title: 'PNPM', value: PackageManager.PNPM },
];

export const pluginOptions = [
Expand Down
2 changes: 2 additions & 0 deletions src/commands/create/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ export enum AdminJSPlugin {
export enum PackageManager {
NPM = 'npm',
Yarn = 'yarn',
PNPM = 'pnpm',
}

export enum DatabaseDriver {
Expand All @@ -37,6 +38,7 @@ export interface CreateCommandInput {
adapter: AdminJSAdapter;
plugin: AdminJSPlugin;
packageManager: PackageManager;
yarnPnp?: boolean;
databaseDriver?: DatabaseDriver;
env?: {
DATABASE_URL: string;
Expand Down