@plastic-ant/nx-dvc
Version:
[](https://lbesson.mit-license.org/) [](https://npmjs.com/package/@plastic-ant/nx-dvc) [;
exports.createNodesV2 = void 0;
const devkit_1 = require("@nx/devkit");
const devkit_2 = require("@nx/devkit");
const node_path_1 = require("node:path");
const get_named_inputs_1 = require("@nx/devkit/src/utils/get-named-inputs");
const node_fs_1 = require("node:fs");
const calculate_hash_for_create_nodes_1 = require("@nx/devkit/src/utils/calculate-hash-for-create-nodes");
const cache_directory_1 = require("nx/src/utils/cache-directory");
const file_hasher_1 = require("nx/src/hasher/file-hasher");
function normalizeOptions(options) {
options ??= {};
options.reproTargetName ??= "dvc-repro";
return options;
}
function readTargetsCache(cachePath) {
return (0, node_fs_1.existsSync)(cachePath) ? (0, devkit_2.readJsonFile)(cachePath) : {};
}
function writeTargetsToCache(cachePath, results) {
(0, devkit_2.writeJsonFile)(cachePath, results);
}
exports.createNodesV2 = [
"**/dvc.yaml",
async (configFiles, opts, context) => {
const options = normalizeOptions(opts);
const optionsHash = (0, file_hasher_1.hashObject)(options);
const cachePath = (0, node_path_1.join)(cache_directory_1.workspaceDataDirectory, `pas-nx-msbuild-${optionsHash}.hash`);
const targetsCache = readTargetsCache(cachePath);
try {
return await (0, devkit_1.createNodesFromFiles)((configFile, options, context) => createNodesInternal(configFile, normalizeOptions(options), context, targetsCache), configFiles, options, context);
}
finally {
writeTargetsToCache(cachePath, targetsCache);
}
},
];
async function createNodesInternal(configFilePath, options, context, targetsCache) {
const projectRoot = (0, node_path_1.dirname)(configFilePath);
const siblingFiles = (0, node_fs_1.readdirSync)((0, node_path_1.join)(context.workspaceRoot, projectRoot));
if (!siblingFiles.includes("package.json") && !siblingFiles.includes("project.json")) {
return {};
}
options = normalizeOptions(options);
const hash = await (0, calculate_hash_for_create_nodes_1.calculateHashForCreateNodes)(projectRoot, options, context);
targetsCache[hash] ??= buildTargets(configFilePath, projectRoot, options, context);
const targets = targetsCache[hash];
return {
projects: {
[projectRoot]: {
root: projectRoot,
targets,
},
},
};
}
function buildTargets(configPath, projectRoot, options, context) {
const configOutputs = getOutputs(context.workspaceRoot, projectRoot, configPath);
const namedInputs = (0, get_named_inputs_1.getNamedInputs)(projectRoot, context);
const targets = {};
if (options.reproTargetName) {
targets[options.reproTargetName] = buildTarget(options, namedInputs, configOutputs, projectRoot);
}
return targets;
}
function buildTarget(options, namedInputs, outputs, projectRoot) {
return {
command: `dvc repro`,
cache: true,
options: { cwd: (0, devkit_2.joinPathFragments)(projectRoot) },
inputs: [...("production" in namedInputs ? ["production", "^production"] : ["default", "^default"])],
outputs,
};
}
function getOutputs(workspaceRoot, projectRoot, configPath) {
// const cdkConfig = JSON.parse(readFileSync(configPath, "utf-8"));
//const outputs: string[] = [];
return []; //outputs.concat([join("{projectRoot}", cdkConfig.output ?? "cdk.out")]);
}
//# sourceMappingURL=index.js.map