UNPKG

@nxrocks/nx-flutter

Version:

Nx plugin adding first class support for Flutter in your Nx workspace

106 lines 5.42 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.getProjectTypeAndTargetsFromFile = getProjectTypeAndTargetsFromFile; exports.getProjectTypeAndTargetsFromOptions = getProjectTypeAndTargetsFromOptions; const devkit_1 = require("@nx/devkit"); const common_1 = require("@nxrocks/common"); const plugin_1 = require("../graph/plugin"); function getProjectTypeAndTargetsFromFile(projectRootFile, pluginOptions) { const { root } = (0, common_1.getNameAndRoot)(projectRootFile); const platforms = []; let template = 'app'; if ((0, common_1.hasProjectFile)({ root }, 'android')) platforms.push('android'); if ((0, common_1.hasProjectFile)({ root }, 'ios')) platforms.push('ios'); if ((0, common_1.hasProjectFile)({ root }, 'linux')) platforms.push('linux'); if ((0, common_1.hasProjectFile)({ root }, 'macos')) platforms.push('macos'); if ((0, common_1.hasProjectFile)({ root }, 'web')) platforms.push('web'); if ((0, common_1.hasProjectFile)({ root }, 'windows')) platforms.push('windows'); if ((0, common_1.hasProjectFile)({ root }, '.metadata')) { const projectMetadata = (0, common_1.getProjectFileContent)({ root }, '.metadata'); template = /project_type: (\w+)/.exec(projectMetadata)?.[1] || 'app'; } return getProjectTypeAndTargets(root, template, platforms, (0, plugin_1.normalizePluginOptions)(pluginOptions)); } function getProjectTypeAndTargetsFromOptions(options) { return getProjectTypeAndTargets(options.projectRoot, options.template, options.platforms, (0, plugin_1.normalizePluginOptions)({ useFvm: options.useFvm })); } function getProjectTypeAndTargets(projectRoot, template, platforms, pluginOptions) { const targets = {}; const commands = [ { key: pluginOptions.analyzeTargetName, value: 'analyze' }, { key: pluginOptions.assembleTargetName, value: 'assemble' }, { key: pluginOptions.cleanTargetName, value: 'clean' }, { key: pluginOptions.formatTargetName, value: `format ${(0, devkit_1.joinPathFragments)(projectRoot, '*')}`, }, { key: pluginOptions.testTargetName, value: 'test' }, { key: pluginOptions.genL10nTargetName, value: 'gen-l10n' }, { key: pluginOptions.pubGetTargetName, value: 'pub get' }, { key: pluginOptions.pubUpgradeTargetName, value: 'pub upgrade' }, { key: pluginOptions.pubDowngradeTargetName, value: 'pub downgrade' }, { key: pluginOptions.pubOutdatedTargetName, value: 'pub outdated' }, { key: pluginOptions.pubAddTargetName, value: 'pub add {args.package}' }, { key: pluginOptions.pubRemoveTargetName, value: 'pub remove {args.package}', }, { key: pluginOptions.pubRunTargetName, value: 'pub run {args.executable}' }, //{ key: pluginOptions.pubCacheTargetName, value: 'pub cache' }, //{ key: pluginOptions.pubGlobalTargetName, value: 'pub global' }, { key: pluginOptions.pubPublishTargetName, value: 'pub publish' }, { key: pluginOptions.pubDepsTargetName, value: 'pub deps' }, { key: pluginOptions.pubVersionTargetName, value: 'pub version' }, ]; if (template === 'app') { commands.push({ key: pluginOptions.attachTargetName, value: 'attach' }, { key: pluginOptions.driveTargetName, value: 'drive' }, { key: pluginOptions.installTargetName, value: 'install' }, { key: pluginOptions.runTargetName, value: 'run' }); } if (platforms?.indexOf('android') != -1) { commands.push({ key: pluginOptions.buildAarTargetName, value: 'build aar' }, { key: pluginOptions.buildApkTargetName, value: 'build apk' }, { key: pluginOptions.buildAppbundleTargetName, value: 'build appbundle' }, { key: pluginOptions.buildBundleTargetName, value: 'build bundle' }); } if (platforms?.indexOf('ios') != -1) { commands.push({ key: pluginOptions.buildIosTargetName, value: 'build ios' }, { key: pluginOptions.buildIosFrameworkTargetName, value: 'build ios-framework', }, { key: pluginOptions.buildIpaTargetName, value: 'build ipa' }); } for (const command of commands) { targets[command.key] = { executor: `nx:run-commands`, options: { command: `${command.key === pluginOptions.formatTargetName ? 'dart' : `${pluginOptions.useFvm === true ? 'fvm ' : ''}flutter`} ${command.value}`, cwd: projectRoot, }, ...([ pluginOptions.buildAarTargetName, pluginOptions.buildApkTargetName, pluginOptions.buildAppbundleTargetName, pluginOptions.buildBundleTargetName, pluginOptions.buildIosTargetName, pluginOptions.buildIosFrameworkTargetName, pluginOptions.buildIpaTargetName, ].includes(command.key) ? { outputs: [ (0, devkit_1.joinPathFragments)('{workspaceRoot}', projectRoot, 'build'), ], } : {}), }; } return { projectType: template === 'app' ? 'application' : 'library', targets, }; } //# sourceMappingURL=plugin-utils.js.map