UNPKG

@nx-dart/nx-dart

Version:

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

58 lines 2.16 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); const tslib_1 = require("tslib"); const devkit_1 = require("@nrwl/devkit"); const path = require("path"); const dart_source_1 = require("../../utils/dart-source"); const execute_command_1 = require("../../utils/execute-command"); function runExecutor(options, context) { return tslib_1.__awaiter(this, void 0, void 0, function* () { const graph = yield (0, devkit_1.createProjectGraphAsync)(); const projectNode = graph.nodes[context.projectName]; // We pass the individual files to format, instead of the project root, because // we don't want to format files in nested projects. const filePaths = filesToFormat(projectNode); const chunks = chunkify(filePaths, 10); let success = true; for (const chunk of chunks) { if (!(yield format(projectNode.data.root, chunk, options.check))) { success = false; } } return { success, }; }); } exports.default = runExecutor; function filesToFormat(projectNode) { return projectNode.data.files.map((file) => file.file).filter(dart_source_1.isDartFile); } function format(projectRoot, files, check) { return tslib_1.__awaiter(this, void 0, void 0, function* () { const args = buildFormatArguments(check, files.map((filePath) => path.relative(projectRoot, filePath))); return (0, execute_command_1.executeCommand)({ executable: 'dart', arguments: args, cwd: projectRoot, throwOnFailure: false, }); }); } function buildFormatArguments(check, files) { const command = ['format', '--show', 'all']; if (check) { command.push('--set-exit-if-changed', '--output', 'none'); } command.push(...files); return command; } function chunkify(target, size) { return target.reduce((current, value, index) => { if (index % size === 0) current.push([]); current[current.length - 1].push(value); return current; }, []); } //# sourceMappingURL=executor.js.map