@storm-software/workspace-tools
Version:
Tools for managing a Storm workspace, including various Nx generators and executors for common development tasks.
447 lines (429 loc) • 16.5 kB
JavaScript
;Object.defineProperty(exports, "__esModule", {value: true}); function _nullishCoalesce(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return rhsFn(); } } 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 _chunkULBTYC2Bjs = require('./chunk-ULBTYC2B.js');
var _chunk7YRW5HNXjs = require('./chunk-7YRW5HNX.js');
var _chunk3GQAWCBQjs = require('./chunk-3GQAWCBQ.js');
// src/plugins/rust/cargo-toml.ts
var _devkit = require('@nx/devkit');
var _fs = require('fs');
var _path = require('path');
var _projectgraph = require('nx/src/config/project-graph');
var name = "storm-software/rust";
var description = "Plugin for parsing Cargo.toml files";
var DefaultCargoPluginProfileMap = {
development: "dev",
production: "prod"
};
var DEFAULT_ERROR_MESSAGE = "An error occurred in the Storm Rust Nx plugin.";
var createNodesV2 = [
"*/**/Cargo.toml",
async (configFiles, options, context) => {
return await _devkit.createNodesFromFiles.call(void 0, (configFile, options2, context2) => {
try {
console.log(`Processing Cargo.toml file: ${configFile}`);
const profiles = _nullishCoalesce(_optionalChain([options2, 'optionalAccess', _2 => _2.profiles]), () => ( {}));
const includeApps = _nullishCoalesce(_optionalChain([options2, 'optionalAccess', _3 => _3.includeApps]), () => ( true));
const toolchain = _optionalChain([options2, 'optionalAccess', _4 => _4.toolchain]);
const skipDocs = _nullishCoalesce(_optionalChain([options2, 'optionalAccess', _5 => _5.skipDocs]), () => ( false));
const metadata = _chunkULBTYC2Bjs.cargoMetadata.call(void 0, );
if (!metadata) {
return {};
}
const { packages: cargoPackages } = metadata;
const externalNodes = {};
const projects = {};
const profs = {
...DefaultCargoPluginProfileMap,
...profiles
};
const configurations = Object.keys(profs).reduce((ret, key) => {
ret[key] = {
profile: profs[key]
};
return ret;
}, {});
const cargoPackageMap = cargoPackages.reduce((acc, p) => {
if (!acc.has(p.name)) {
acc.set(p.name, p);
}
return acc;
}, /* @__PURE__ */ new Map());
for (const cargoPackage of cargoPackages) {
if (!_chunkULBTYC2Bjs.isExternal.call(void 0, cargoPackage, context2.workspaceRoot)) {
const root = _path.dirname.call(void 0, configFile);
const project = {
root,
name: cargoPackage.name
};
if (_fs.existsSync.call(void 0, _devkit.joinPathFragments.call(void 0, root, "project.json"))) {
const projectJson = _devkit.readJsonFile.call(void 0, _devkit.joinPathFragments.call(void 0, root, "project.json"));
if (projectJson) {
Object.keys(projectJson).forEach((key) => {
if (!project[key]) {
project[key] = projectJson[key];
}
});
}
}
if (includeApps === false && project.projectType === "application") {
continue;
}
project.targets = {
"lint-markdown": {
cache: true,
outputs: [
"{projectRoot}/**/*.md",
"{projectRoot}/**/*.mdx"
],
inputs: [
"linting",
"{projectRoot}/**/*.md",
"{projectRoot}/**/*.mdx"
],
dependsOn: [
"^lint-markdown"
],
executor: "nx:run-commands",
options: {
command: 'pnpm exec markdownlint-cli2 "{projectRoot}/*.{md,mdx}" "{projectRoot}/**/*.{md,mdx}" --config "node_modules/@storm-software/markdownlint/config/base.markdownlint-cli2.jsonc" --fix'
}
},
"lint-ls": {
cache: true,
inputs: [
"linting",
"rust",
"^production"
],
dependsOn: [
"^lint-ls"
],
options: {
command: 'pnpm exec ls-lint --config="./node_modules/@storm-software/linting-tools/ls-lint/.ls-lint.yml" ',
color: true
}
},
lint: {
cache: true,
inputs: [
"linting",
"rust",
"^production"
],
dependsOn: [
"lint-ls",
"lint-markdown",
"^lint"
],
executor: "@storm-software/workspace-tools:cargo-clippy",
options: {
toolchain,
fix: false
},
defaultConfiguration: "development",
configurations
},
check: {
cache: true,
inputs: [
"linting",
"rust",
"^production"
],
dependsOn: [
"lint",
"^check"
],
executor: "@storm-software/workspace-tools:cargo-check",
options: {
toolchain
},
defaultConfiguration: "development",
configurations
},
"format-readme": {
cache: true,
inputs: [
"linting",
"documentation",
"{projectRoot}/{README.md,package.json,Cargo.toml,executors.json,generators.json}"
],
outputs: [
"{projectRoot}/README.md"
],
dependsOn: [
"^format-readme"
],
executor: "nx:run-commands",
options: {
command: 'pnpm exec storm-git readme --templates="tools/readme-templates" --project="{projectName}"'
}
},
"format-toml": {
cache: true,
inputs: [
"linting",
"{projectRoot}/**/*.toml"
],
outputs: [
"{projectRoot}/**/*.toml"
],
dependsOn: [
"^format-toml"
],
executor: "nx:run-commands",
options: {
command: 'pnpm exec taplo format --config="node_modules/@storm-software/linting-tools/taplo/config.toml" --cache-path="node_modules/.cache/taplo/{projectRoot}" --colors="always" "{projectRoot}/*.toml" "{projectRoot}/**/*.toml" '
}
},
"format-clippy": {
cache: true,
inputs: [
"linting",
"rust",
"^production"
],
dependsOn: [
"^format-clippy"
],
executor: "@storm-software/workspace-tools:cargo-clippy",
options: {
toolchain,
fix: true
},
defaultConfiguration: "development",
configurations
},
format: {
cache: true,
inputs: [
"linting",
"documentation",
"rust",
"^production"
],
dependsOn: [
"format-readme",
"format-clippy",
"format-toml",
"^format"
],
executor: "@storm-software/workspace-tools:cargo-format",
options: {
toolchain,
fix: true
},
defaultConfiguration: "development",
configurations
},
clean: {
cache: true,
inputs: [
"rust",
"^production"
],
outputs: [
`{workspaceRoot}/dist/target/{projectRoot}`
],
executor: "nx:run-commands",
options: {
command: `pnpm exec rimraf dist/target/crates/${cargoPackage.name}`,
color: true,
cwd: "{workspaceRoot}"
}
},
build: {
cache: true,
inputs: [
"rust",
"^production"
],
dependsOn: [
"build-base",
"^build"
],
executor: "@storm-software/workspace-tools:cargo-build",
outputs: [
`{workspaceRoot}/dist/target/{projectRoot}`
],
options: {
toolchain
},
defaultConfiguration: "development",
configurations
},
rebuild: {
cache: false,
inputs: [
"rust",
"^production"
],
dependsOn: [
"clean",
"^build"
],
executor: "@storm-software/workspace-tools:cargo-build",
outputs: [
`{workspaceRoot}/dist/target/{projectRoot}`
],
options: {
toolchain
},
defaultConfiguration: "development",
configurations
},
test: {
cache: true,
inputs: [
"testing",
"rust",
"^production"
],
dependsOn: [
"build",
"^test"
],
executor: "@monodon/rust:test",
outputs: [
"{options.target-dir}"
],
options: {
"target-dir": `{workspaceRoot}/dist/target/{projectRoot}`
},
defaultConfiguration: "development",
configurations
}
};
if (skipDocs != true) {
project.targets.docs = {
cache: true,
inputs: [
"linting",
"documentation",
"default",
"^production"
],
dependsOn: [
"format-readme",
"lint-docs",
"^docs"
],
outputs: [
`{workspaceRoot}/dist/docs/{projectRoot}`
],
executor: "@storm-software/workspace-tools:cargo-doc",
options: {
toolchain
},
defaultConfiguration: "production",
configurations
};
}
if (cargoPackage.publish === null || cargoPackage.publish === void 0 || cargoPackage.publish === true || Array.isArray(cargoPackage.publish) && cargoPackage.publish.length > 0) {
_chunk7YRW5HNXjs.addProjectTag.call(void 0, project, _chunk7YRW5HNXjs.ProjectTagConstants.Registry.TAG_ID, _chunk7YRW5HNXjs.ProjectTagConstants.Registry.CARGO, {
overwrite: true
});
project.targets["nx-release-publish"] = {
cache: true,
inputs: [
"linting",
"testing",
"documentation",
"rust",
"^production"
],
dependsOn: [
"build",
"^nx-release-publish"
],
executor: "@storm-software/workspace-tools:cargo-publish",
options: {
packageRoot: root
},
defaultConfiguration: "production",
configurations
};
}
_chunk7YRW5HNXjs.addProjectTag.call(void 0, project, _chunk7YRW5HNXjs.ProjectTagConstants.Language.TAG_ID, _chunk7YRW5HNXjs.ProjectTagConstants.Language.RUST, {
overwrite: true
});
_chunk7YRW5HNXjs.setDefaultProjectTags.call(void 0, project, name);
projects[root] = {
...project,
release: {
...project.release,
version: {
..._optionalChain([project, 'access', _6 => _6.release, 'optionalAccess', _7 => _7.version]),
generator: "@storm-software/workspace-tools:release-version"
}
}
};
}
for (const dep of cargoPackage.dependencies) {
if (_chunkULBTYC2Bjs.isExternal.call(void 0, dep, context2.workspaceRoot)) {
const externalDepName = `cargo:${dep.name}`;
if (!_optionalChain([externalNodes, 'optionalAccess', _8 => _8[externalDepName]])) {
externalNodes[externalDepName] = {
type: "cargo",
name: externalDepName,
data: {
packageName: dep.name,
version: _nullishCoalesce(_optionalChain([cargoPackageMap, 'access', _9 => _9.get, 'call', _10 => _10(dep.name), 'optionalAccess', _11 => _11.version]), () => ( "0.0.0"))
}
};
}
}
}
}
return {
projects,
externalNodes
};
} catch (e) {
console.error(DEFAULT_ERROR_MESSAGE);
console.error(e);
throw new Error(DEFAULT_ERROR_MESSAGE, {
cause: e
});
}
}, configFiles, options, context);
}
];
var createDependencies = /* @__PURE__ */ _chunk3GQAWCBQjs.__name.call(void 0, (_, context) => {
const metadata = _chunkULBTYC2Bjs.cargoMetadata.call(void 0, );
if (!metadata) {
return [];
}
const { packages: cargoPackages } = metadata;
const dependencies = [];
for (const pkg of cargoPackages) {
if (context.projects[pkg.name]) {
console.debug(`Local Cargo package found: ${pkg.name}`);
for (const deps of pkg.dependencies) {
if (!cargoPackages.find((p) => p.name === deps.name)) {
console.debug(`Dependency ${deps.name} not found in the cargo metadata.`);
continue;
}
if (context.projects[deps.name]) {
dependencies.push(createDependency(pkg, deps.name, _projectgraph.DependencyType.static));
} else {
const externalDepName = `cargo:${deps.name}`;
if (externalDepName in (_nullishCoalesce(context.externalNodes, () => ( {})))) {
dependencies.push(createDependency(pkg, externalDepName, _projectgraph.DependencyType.static));
}
}
}
}
}
return dependencies;
}, "createDependencies");
function createDependency(pkg, depName, type) {
const target = pkg.manifest_path.replace(/\\/g, "/");
return {
type,
source: pkg.name,
target: depName,
sourceFile: target.replace(`${_devkit.workspaceRoot.replace(/\\/g, "/")}/`, "")
};
}
_chunk3GQAWCBQjs.__name.call(void 0, createDependency, "createDependency");
exports.name = name; exports.description = description; exports.DefaultCargoPluginProfileMap = DefaultCargoPluginProfileMap; exports.DEFAULT_ERROR_MESSAGE = DEFAULT_ERROR_MESSAGE; exports.createNodesV2 = createNodesV2; exports.createDependencies = createDependencies;