-
-
Notifications
You must be signed in to change notification settings - Fork 34
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(nx-flutter): fix non-interactive generation of flutter projects
BREAKING CHANGE: `interactive` option has been renamed into `skipAdditionalPrompts` `interactive` is a reserved option for `nx generate` command, that gets deleted once Nx has interpreted it, so we need our own. Must still be combined with `--no-interactive` (from Nx), for fully non-interactivity
- Loading branch information
Showing
9 changed files
with
93 additions
and
92 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
115 changes: 56 additions & 59 deletions
115
packages/nx-flutter/src/generators/project/generator.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,75 +1,72 @@ | ||
import { Tree, addProjectConfiguration, } from '@nrwl/devkit'; | ||
import { addPluginToNxJson, NX_FLUTTER_PKG } from '@nxrocks/common'; | ||
|
||
import { isFlutterInstalled } from '../../utils/flutter-utils'; | ||
import { normalizeOptions, promptAdditionalOptions, generateFlutterProject } from './lib'; | ||
import { ProjectGeneratorOptions } from './schema'; | ||
|
||
export async function projectGenerator(tree:Tree, options: ProjectGeneratorOptions) { | ||
|
||
if (!isFlutterInstalled()) { | ||
throw new Error("'flutter' was not found on your system's PATH.\nPlease make sure you have installed it correctly.\n👉🏾 https://flutter.dev/docs/get-started/install"); | ||
} | ||
|
||
const normalizedOptions = normalizeOptions(tree,options); | ||
|
||
if(options.interactive ) | ||
await promptAdditionalOptions(tree,normalizedOptions); | ||
if(!options.skipAdditionalPrompts ) { | ||
await promptAdditionalOptions(tree,normalizedOptions); | ||
} | ||
|
||
const targets = {}; | ||
const commands = [ | ||
{ key: 'analyze', value: 'analyze' }, | ||
{ key: 'clean', value: 'clean' }, | ||
{ key: 'format', value: `format ${normalizedOptions.projectRoot}/*` }, | ||
{ key: 'test', value: 'test' }, | ||
]; | ||
|
||
if(normalizedOptions.template === 'app'){ | ||
commands.push( | ||
{ key: 'assemble', value: 'assemble' }, | ||
{ key: 'attach', value: 'attach' }, | ||
{ key: 'drive', value: 'drive' }, | ||
{ key: 'gen-l10n', value: 'gen-l10n' }, | ||
{ key: 'install', value: 'install' }, | ||
{ key: 'run', value: 'run' }, | ||
) | ||
} | ||
|
||
const targets = {}; | ||
const commands = [ | ||
{ key: 'analyze', value: 'analyze' }, | ||
{ key: 'clean', value: 'clean' }, | ||
{ key: 'format', value: `format ${normalizedOptions.projectRoot}/*` }, | ||
{ key: 'test', value: 'test' }, | ||
]; | ||
|
||
if(normalizedOptions.template === 'app'){ | ||
commands.push( | ||
{ key: 'assemble', value: 'assemble' }, | ||
{ key: 'attach', value: 'attach' }, | ||
{ key: 'drive', value: 'drive' }, | ||
{ key: 'gen-l10n', value: 'gen-l10n' }, | ||
{ key: 'install', value: 'install' }, | ||
{ key: 'run', value: 'run' }, | ||
) | ||
} | ||
if(normalizedOptions.platforms?.indexOf('android') != -1) { | ||
commands.push( | ||
{key: 'build-aar', value: 'build aar'}, | ||
{key: 'build-apk', value: 'build apk'}, | ||
{key: 'build-appbundle', value: 'build appbundle'}, | ||
{key: 'build-bundle', value: 'build bundle'}, | ||
) | ||
} | ||
|
||
if(normalizedOptions.platforms?.indexOf('android') != -1) { | ||
commands.push( | ||
{key: 'build-aar', value: 'build aar'}, | ||
{key: 'build-apk', value: 'build apk'}, | ||
{key: 'build-appbundle', value: 'build appbundle'}, | ||
{key: 'build-bundle', value: 'build bundle'}, | ||
) | ||
} | ||
if(normalizedOptions.platforms?.indexOf('ios') != -1) { | ||
commands.push( | ||
{key: 'build-ios', value: 'build ios'}, | ||
{key: 'build-ios-framework', value: 'build ios-framework'}, | ||
{key: 'build-ipa', value: 'build ipa'}, | ||
) | ||
} | ||
|
||
for (const command of commands) { | ||
targets[command.key] = { | ||
executor: `@nrwl/workspace:run-commands`, | ||
options: { | ||
command: `flutter ${command.value}`, | ||
cwd: normalizedOptions.projectRoot | ||
} | ||
}; | ||
} | ||
addProjectConfiguration(tree, normalizedOptions.projectName, { | ||
root: normalizedOptions.projectRoot, | ||
sourceRoot: `${normalizedOptions.projectRoot}/src`, | ||
projectType: normalizedOptions.template === 'app' ? 'application' : 'library', | ||
targets: targets, | ||
tags: normalizedOptions.parsedTags, | ||
}); | ||
|
||
if(normalizedOptions.platforms?.indexOf('ios') != -1) { | ||
commands.push( | ||
{key: 'build-ios', value: 'build ios'}, | ||
{key: 'build-ios-framework', value: 'build ios-framework'}, | ||
{key: 'build-ipa', value: 'build ipa'}, | ||
) | ||
} | ||
|
||
for (const command of commands) { | ||
targets[command.key] = { | ||
executor: `@nrwl/workspace:run-commands`, | ||
options: { | ||
command: `flutter ${command.value}`, | ||
cwd: normalizedOptions.projectRoot | ||
} | ||
}; | ||
} | ||
addProjectConfiguration(tree, normalizedOptions.projectName, { | ||
root: normalizedOptions.projectRoot, | ||
sourceRoot: `${normalizedOptions.projectRoot}/src`, | ||
projectType: normalizedOptions.template === 'app' ? 'application' : 'library', | ||
targets: targets, | ||
tags: normalizedOptions.parsedTags, | ||
}); | ||
await generateFlutterProject(tree,normalizedOptions) | ||
addPluginToNxJson(NX_FLUTTER_PKG, tree); | ||
await generateFlutterProject(tree,normalizedOptions) | ||
addPluginToNxJson(NX_FLUTTER_PKG, tree); | ||
} | ||
|
||
export default projectGenerator; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters