From 163ab517b3f6b51af6cde40bddf5eba8f36906c8 Mon Sep 17 00:00:00 2001 From: Dan Stepanov Date: Tue, 20 Aug 2024 00:55:36 -0700 Subject: [PATCH] Revert "feat: use new --yes flag on nwui" This reverts commit d5fe3d31120f6b93ff188bff50753ba4e0030616. --- cli/__tests__/cli-integration.test.ts | 15 +++++---- cli/src/utilities/generateNWUI.ts | 43 -------------------------- cli/src/utilities/printOutput.ts | 44 +++++++++++++++++++++++---- 3 files changed, 47 insertions(+), 55 deletions(-) delete mode 100644 cli/src/utilities/generateNWUI.ts diff --git a/cli/__tests__/cli-integration.test.ts b/cli/__tests__/cli-integration.test.ts index 0eb18767..89722ea3 100644 --- a/cli/__tests__/cli-integration.test.ts +++ b/cli/__tests__/cli-integration.test.ts @@ -141,14 +141,17 @@ for (const packageManager of packageManagers) { expect(fileList).toMatchSnapshot(`${finalFlags.join(', ')}-file-list`); - const { stderr, stdout, exitCode } = await Bun.$`cd ${projectName} && bun run tsc --noEmit`; + // once nwui cli examples are fixed we can remove this + if (!finalFlags.includes('--nativewindui')) { + const { stderr, stdout, exitCode } = await Bun.$`cd ${projectName} && bun run tsc --noEmit`; - if (exitCode !== 0) { - console.warn('stdout', stdout.toString()); - console.warn('stderr', stderr.toString()); - } + if (exitCode !== 0) { + console.warn('stdout', stdout.toString()); + console.warn('stderr', stderr.toString()); + } - expect(exitCode).toBe(0); + expect(exitCode).toBe(0); + } }); } } diff --git a/cli/src/utilities/generateNWUI.ts b/cli/src/utilities/generateNWUI.ts deleted file mode 100644 index ab4e07e7..00000000 --- a/cli/src/utilities/generateNWUI.ts +++ /dev/null @@ -1,43 +0,0 @@ -import { GluegunToolbox } from 'gluegun'; -import { CliResults } from '../types'; -import { nativeWindUIOptions } from '../constants'; -import { getPackageManagerRunnerX } from './getPackageManager'; -import { ONLY_ERRORS, runSystemCommand } from './systemCommand'; - -export async function generateNWUI(cliResults: CliResults, toolbox: GluegunToolbox) { - const isNativeWindUISelected = cliResults.packages.some((p) => p.name === 'nativewindui'); - - if (!isNativeWindUISelected) { - return; - } - - const runnerType = getPackageManagerRunnerX(toolbox, cliResults); - - const nativeWindUIComponents = - cliResults.packages.find((p) => p.name === 'nativewindui').options.selectedComponents ?? []; - - // we do this to account for older stored config e.g that has selectable text in it - const onlySupportedComponents = nativeWindUIComponents.filter((component) => nativeWindUIOptions.includes(component)); - - const finalComponents = Array.from(new Set([...onlySupportedComponents, 'text'])); - - toolbox.print.info(`Adding nativewindui components...`); - - await runSystemCommand({ - command: `${runnerType} --yes nwui-cli@latest add --yes -d ${cliResults.projectName} ${finalComponents.join(' ')}`, - errorMessage: 'Error adding nativewindui components', - toolbox, - stdio: ONLY_ERRORS, - - // for some reason running as shell breaks nwui when running in ci - shell: false, - - // this is how we pass env variables to the child process when not running as shell - env: { - ...process.env, - ...(process.env.NODE_ENV === 'development' ? { API_BASE_URL: 'https://nativewindui.com' } : {}) - } - }); - - toolbox.print.info('Nativewindui components added!'); -} diff --git a/cli/src/utilities/printOutput.ts b/cli/src/utilities/printOutput.ts index 555d638c..217e4baf 100644 --- a/cli/src/utilities/printOutput.ts +++ b/cli/src/utilities/printOutput.ts @@ -1,8 +1,8 @@ import { outro, spinner } from '@clack/prompts'; import { Toolbox } from 'gluegun/build/types/domain/toolbox'; +import { nativeWindUIOptions } from '../constants'; import { AvailablePackages, CliResults } from '../types'; import { copyBaseAssets } from './copyBaseAssets'; -import { generateNWUI } from './generateNWUI'; import { getPackageManager, getPackageManagerRunnerX } from './getPackageManager'; import { easConfigure } from './runEasConfigure'; import { ONLY_ERRORS, runSystemCommand } from './systemCommand'; @@ -78,8 +78,6 @@ export async function printOutput( s.stop('Packages updated!'); - await generateNWUI(cliResults, toolbox); - s.start(`Cleaning up your project...`); // format the files with prettier and eslint using installed packages. @@ -92,11 +90,10 @@ export async function printOutput( s.stop('Project files formatted!'); } else { - await generateNWUI(cliResults, toolbox); - - s.start(`formatting your project using ${runnerType} prettier...`); + s.start(`No installation found.\nCleaning up your project using ${runnerType}...`); // Running prettier using global runners against the template. + // Use --no-config to prevent using project's config (that may have plugins/dependencies) await runSystemCommand({ toolbox, command: `${runnerType} prettier "${projectName}/**/*.{json,js,jsx,ts,tsx}" --no-config --write`, @@ -107,6 +104,41 @@ export async function printOutput( s.stop('Project files formatted!'); } + const isNativeWindUISelected = cliResults.packages.some((p) => p.name === 'nativewindui'); + + if (isNativeWindUISelected) { + const nativeWindUIComponents = + cliResults.packages.find((p) => p.name === 'nativewindui').options.selectedComponents ?? []; + + // we do this to account for older stored config e.g that has selectable text in it + const onlySupportedComponents = nativeWindUIComponents.filter((component) => + nativeWindUIOptions.includes(component) + ); + + const finalComponents = Array.from(new Set([...onlySupportedComponents, 'text'])); + + s.start(`Adding nativewindui components...`); + + await runSystemCommand({ + command: `${runnerType} --yes nwui-cli@latest add --overwrite -d ${cliResults.projectName} ${finalComponents.join(' ')}`, + errorMessage: 'Error adding nativewindui components', + toolbox, + stdio: ONLY_ERRORS, + + // for some reason running as shell breaks nwui when running in ci + shell: false, + + // this is how we pass env variables to the child process when not running as shell + env: { + ...process.env, + EXPO_NO_GIT_STATUS: '1', + ...(process.env.NODE_ENV === 'development' ? { API_BASE_URL: 'https://nativewindui.com' } : {}) + } + }); + + s.stop('Nativewindui components added!'); + } + if (!options.noGit && !flags.noGit && process.env.NODE_ENV !== 'test') { s.start(`Initializing git...`); // initialize git repo and add first commit