UNPKG

@nx-dart/nx-dart

Version:

A Nx plugin, that adds support for developing Dart and Flutter packages in a Nx workspace

121 lines (117 loc) 4.98 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.ensureWorkspacePubspec = exports.setupWorkspaceForNxDart = void 0; const tslib_1 = require("tslib"); const devkit_1 = require("@nrwl/devkit"); const misc_1 = require("../../utils/misc"); const generator_1 = require("../change-lints/generator"); const generator_2 = require("../utils/generator"); const nx_workspace_1 = require("../utils/nx-workspace"); const analysis_options_1 = require("./analysis-options"); const setupWorkspaceForNxDart = (tree, options) => tslib_1.__awaiter(void 0, void 0, void 0, function* () { const tasks = []; addWorkspaceGitignoreRules(tree); tasks.push(yield setupWorkspaceDependencies(tree)); setupNxJson(tree); ensureWorkspacePubspec(tree); if (tree.exists('analysis_options.yaml')) { (0, analysis_options_1.excludeNodeModulesFromAnalysisOptions)(tree); } if (options.lints) { tasks.push(yield (0, generator_1.default)(tree, { lints: options.lints })); } yield (0, devkit_1.formatFiles)(tree); return (0, generator_2.runAllTasks)(tasks); }); exports.setupWorkspaceForNxDart = setupWorkspaceForNxDart; function setupWorkspaceDependencies(tree) { return tslib_1.__awaiter(this, void 0, void 0, function* () { // When a workspace is created with a preset, that preset will be added to the dependencies // but we want to add the plugin to the devDependencies. So we remove it from the dependencies // first. const uninstall = (0, devkit_1.removeDependenciesFromPackageJson)(tree, ['@nx-dart/nx-dart'], []); const install = (0, devkit_1.addDependenciesToPackageJson)(tree, {}, { '@nx-dart/nx-dart': (0, misc_1.nxDartPackageJson)().version }); return (0, generator_2.runAllTasks)([uninstall, install]); }); } function setupNxJson(tree) { (0, nx_workspace_1.updateNxJson)(tree, (nxJson) => { var _a, _b, _c, _d, _e; // Add this plugin to plugins. const plugins = (nxJson.plugins = (_a = nxJson.plugins) !== null && _a !== void 0 ? _a : []); if (!plugins.includes('@nx-dart/nx-dart')) { plugins.push('@nx-dart/nx-dart'); } // Make this plugin the default collection. nxJson.cli = Object.assign(Object.assign({}, nxJson.cli), { defaultCollection: '@nx-dart/nx-dart' }); const tasksRunnerOptions = (_b = nxJson.tasksRunnerOptions) !== null && _b !== void 0 ? _b : {}; const taskRunner = tasksRunnerOptions.default; const taskRunnerOptions = (taskRunner.options = (_c = taskRunner.options) !== null && _c !== void 0 ? _c : {}); // Add a runtime cache input for Dart / Flutter SDK. const runtimeCacheInputs = (taskRunnerOptions.runtimeCacheInputs = (_d = taskRunnerOptions.runtimeCacheInputs) !== null && _d !== void 0 ? _d : []); const input = 'flutter --version || dart --version'; if (!runtimeCacheInputs.includes(input)) { runtimeCacheInputs.push(input); } // Add Dart / Flutter related cacheable operations. const cacheableOperations = (taskRunnerOptions.cacheableOperations = (_e = taskRunnerOptions.cacheableOperations) !== null && _e !== void 0 ? _e : []); const operations = ['format', 'analyze']; for (const operation of operations) { if (!cacheableOperations.includes(operation)) { cacheableOperations.push(operation); } } return nxJson; }); } const nxDartIgnoreRules = ` # Ignore rules added by nx-dart ## Node node_modules/ ## Dart .packages .dart_tool/ build/ doc/api/ # We only ignore the pubspec.lock at the workspace root here. # Other lock files should be ignored at the package level. /pubspec.lock ## Flutter .flutter-plugins .flutter-plugins-dependencies `; function addWorkspaceGitignoreRules(tree) { let gitignore = ''; const currentGitignore = tree.read('.gitignore', 'utf-8'); if (currentGitignore) { gitignore += currentGitignore; gitignore += '\n'; } gitignore += nxDartIgnoreRules; tree.write('.gitignore', gitignore); } const workspacePubspec = ` name: workspace publish_to: none environment: sdk: '>=2.17.0 <3.0.0' `; function ensureWorkspacePubspec(tree) { if (!tree.exists('pubspec.yaml')) { tree.write('pubspec.yaml', workspacePubspec); } (0, nx_workspace_1.updateNxJson)(tree, (nxJson) => { var _a; // Make the pubspec.yaml at the workspace root an implicit dependencies. const implicitDependencies = (nxJson.implicitDependencies = (_a = nxJson.implicitDependencies) !== null && _a !== void 0 ? _a : {}); if (!('pubspec.yaml' in implicitDependencies)) { implicitDependencies['pubspec.yaml'] = '*'; } return nxJson; }); } exports.ensureWorkspacePubspec = ensureWorkspacePubspec; //# sourceMappingURL=setup-workspace.js.map