UNPKG

@storm-software/workspace-tools

Version:

Tools for managing a Storm workspace, including various Nx generators and executors for common development tasks.

94 lines (85 loc) 4.44 kB
"use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } function _optionalChain(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; } var _chunkZMFVKBRMjs = require('./chunk-ZMFVKBRM.js'); var _chunk3GQAWCBQjs = require('./chunk-3GQAWCBQ.js'); // src/executors/cargo-publish/executor.ts var _devkit = require('@nx/devkit'); var _child_process = require('child_process'); var _fs = require('fs'); var _https = require('https'); var _https2 = _interopRequireDefault(_https); var LARGE_BUFFER = 1024 * 1e6; async function runExecutor(options, context) { const isDryRun = process.env.NX_DRY_RUN === "true" || options.dryRun || false; if (!context.projectName) { throw new Error("The executor requires a projectName."); } console.info(`\u{1F680} Running Storm Cargo Publish executor on the ${context.projectName} crate`); if (!context.projectName || !_optionalChain([context, 'access', _2 => _2.projectsConfigurations, 'optionalAccess', _3 => _3.projects]) || !context.projectsConfigurations.projects[context.projectName] || !_optionalChain([context, 'access', _4 => _4.projectsConfigurations, 'access', _5 => _5.projects, 'access', _6 => _6[context.projectName], 'optionalAccess', _7 => _7.root])) { throw new Error("The executor requires projectsConfigurations."); } const registry = options.registry ? options.registry : process.env.STORM_REGISTRY_CARGO ? process.env.STORM_REGISTRY_CARGO : "https://crates.io"; const root = _optionalChain([context, 'access', _8 => _8.projectsConfigurations, 'access', _9 => _9.projects, 'access', _10 => _10[context.projectName], 'optionalAccess', _11 => _11.root]); const packageRoot = _devkit.joinPathFragments.call(void 0, context.root, options.packageRoot ? options.packageRoot : root); const cargoToml = _chunkZMFVKBRMjs.parseCargoToml.call(void 0, _fs.readFileSync.call(void 0, _devkit.joinPathFragments.call(void 0, packageRoot, "Cargo.toml"), "utf-8")); try { const result = await getRegistryVersion(cargoToml.package.name, cargoToml.package.version, registry); if (result) { console.warn(`Skipped package "${cargoToml.package.name}" from project "${context.projectName}" because v${cargoToml.package.version} already exists in ${registry} with tag "latest"`); return { success: true }; } } catch (_) { } const cargoPublishCommandSegments = [ `cargo publish --allow-dirty -p ${cargoToml.package.name}` ]; if (isDryRun) { cargoPublishCommandSegments.push("--dry-run"); } try { const cargoPublishCommand = cargoPublishCommandSegments.join(" "); console.log(""); console.log(`Running "${cargoPublishCommand}"...`); console.log(""); _child_process.execSync.call(void 0, cargoPublishCommand, { maxBuffer: LARGE_BUFFER, env: { ...process.env, FORCE_COLOR: "true" }, cwd: packageRoot, stdio: [ "ignore", "pipe", "pipe" ] }); console.log(""); if (isDryRun) { console.log(`Would publish to ${registry}, but [dry-run] was set`); } else { console.log(`Published to ${registry}`); } return { success: true }; } catch (error) { console.error(`Failed to publish to ${registry}`); console.error(error); console.log(""); return { success: false }; } } _chunk3GQAWCBQjs.__name.call(void 0, runExecutor, "runExecutor"); var getRegistryVersion = /* @__PURE__ */ _chunk3GQAWCBQjs.__name.call(void 0, (name, version, registry) => { return new Promise((resolve) => _https2.default.get(`${registry}/api/v1/crates/${encodeURIComponent(name)}/${encodeURIComponent(version)}`, (res) => { res.on("data", (d) => { resolve(d); }); }).on("error", (e) => { throw e; })); }, "getRegistryVersion"); exports.runExecutor = runExecutor; exports.getRegistryVersion = getRegistryVersion;