import execa from 'execa' import { Listr } from 'listr2' import { webTasksList, apiTasksList } from './base-tasks.mts' import { setOutputPath } from './paths.mts' import { getExecaOptions, getCfwBin } from './util.mts' interface WebTasksOptions { linkWithLatestFwBuild: boolean verbose: boolean packageManager?: 'yarn' | 'npm' | 'pnpm' } export async function webTasks( outputPath: string, { linkWithLatestFwBuild, verbose, packageManager = 'yarn' }: WebTasksOptions, ) { setOutputPath(outputPath) const cedarBin = packageManager === 'npm' ? 'npx' : packageManager const cfwBin = packageManager === 'npm' ? 'npx' : packageManager const baseTasks = webTasksList(false, packageManager) // Some tasks returns an array of tasks, those needs to be wrapped in a Listr // instance const wrappedTasks = baseTasks.map((taskDef) => { return { title: taskDef.title, task: taskDef.isNested ? async () => new Listr(await taskDef.task()) : taskDef.task, } }) return new Listr( [ ...wrappedTasks, // ====== NOTE: cfw needs this workaround for tailwind ======= // Setup tailwind in a linked project, due to cfw we install deps manually { title: 'Install tailwind dependencies', // @NOTE: use cfw, because calling the copy function doesn't seem to work here task: () => { const workspaceCmd = packageManager === 'yarn' ? 'yarn workspace web add -D' : packageManager === 'pnpm' ? 'pnpm --filter web add -D' : 'npm install -w web --save-dev' return execa( `${workspaceCmd} tailwindcss@^4.3.3 @tailwindcss/vite@^4.3.3 prettier-plugin-tailwindcss@^0.8.0`, [], getExecaOptions(outputPath), ) }, enabled: () => linkWithLatestFwBuild, }, { title: '[link] Copy local framework files again', // @NOTE: use cfw, because calling the copy function doesn't seem to work here task: () => execa( `${cfwBin} ${getCfwBin(outputPath)} project:copy`, [], getExecaOptions(outputPath), ), enabled: () => linkWithLatestFwBuild, }, // ========= { title: 'Adding Tailwind', task: () => { return execa( `${cedarBin} cedar setup ui tailwindcss`, ['--force', linkWithLatestFwBuild && '--no-install'].filter( (i: string | boolean): i is string => Boolean(i), ), getExecaOptions(outputPath), ) }, }, ], { exitOnError: true, renderer: verbose ? 'verbose' : 'default', }, ) } interface ApiTasksOptions { verbose: boolean linkWithLatestFwBuild: boolean packageManager?: 'yarn' | 'npm' | 'pnpm' } export async function apiTasks( outputPath: string, { verbose, linkWithLatestFwBuild, packageManager = 'yarn' }: ApiTasksOptions, ) { setOutputPath(outputPath) const baseTasks = apiTasksList({ dbAuth: 'canary', linkWithLatestFwBuild, packageManager, }) // Some tasks returns an array of tasks, those needs to be wrapped in a Listr // instance const wrappedTasks = baseTasks.map((taskDef) => { return { title: taskDef.title, task: taskDef.isNested ? async () => new Listr(await taskDef.task()) : taskDef.task, } }) return new Listr(wrappedTasks, { exitOnError: true, renderer: verbose ? 'verbose' : 'default', }) }