Skip to content

Commit

Permalink
feat: add useFvm in the plugin options (nx.json) to control whether…
Browse files Browse the repository at this point in the history
… to use `FVM`to run `flutter`
  • Loading branch information
tinesoft committed Jun 21, 2024
1 parent a1b7e03 commit a4e9878
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 6 deletions.
6 changes: 6 additions & 0 deletions packages/nx-flutter/src/graph/plugin.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
import { isFlutterInstalled } from '../utils/flutter-utils';

export interface NxFlutterPluginOptions {
useFvm?: boolean;
analyzeTargetName?: string;
cleanTargetName?: string;
formatTargetName?: string;
Expand All @@ -23,8 +26,11 @@ export function normalizePluginOptions(
opts?: NxFlutterPluginOptions
): NxFlutterPluginOptions {
const options = opts ?? {};
const isFvmInstalled = isFlutterInstalled(true);

return {
...options,
useFvm: options.useFvm && isFvmInstalled,
analyzeTargetName: options.analyzeTargetName ?? 'analyze',
cleanTargetName: options.cleanTargetName ?? 'clean',
formatTargetName: options.formatTargetName ?? 'format',
Expand Down
8 changes: 2 additions & 6 deletions packages/nx-flutter/src/utils/plugin-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ export function getProjectTypeAndTargetsFromFile(

const platforms: PlatformType[] = [];
let template: TemplateType = 'app';
const useFvm = isFlutterInstalled(true);

if (hasProjectFile({ root }, 'android')) platforms.push('android');
if (hasProjectFile({ root }, 'ios')) platforms.push('ios');
Expand All @@ -43,7 +42,6 @@ export function getProjectTypeAndTargetsFromFile(
root,
template,
platforms,
useFvm,
normalizePluginOptions(pluginOptions)
);
}
Expand All @@ -53,16 +51,14 @@ export function getProjectTypeAndTargetsFromOptions(options: NormalizedSchema) {
options.projectRoot,
options.template,
options.platforms,
options.useFvm,
normalizePluginOptions()
normalizePluginOptions({ useFvm: options.useFvm })
);
}

function getProjectTypeAndTargets(
projectRoot: string,
template: TemplateType,
platforms: PlatformType[],
useFvm: boolean,
pluginOptions: NxFlutterPluginOptions
) {
const targets = {};
Expand Down Expand Up @@ -115,7 +111,7 @@ function getProjectTypeAndTargets(
command: `${
command.key === pluginOptions.formatTargetName
? 'dart'
: `${useFvm === true ? 'fvm ' : ''}flutter`
: `${pluginOptions.useFvm === true ? 'fvm ' : ''}flutter`
} ${command.value}`,
cwd: projectRoot,
},
Expand Down

0 comments on commit a4e9878

Please sign in to comment.