salix-front/test/cypress/docker/find/find.js

37 lines
1.1 KiB
JavaScript

import { execSync } from 'child_process';
import { findImports } from './find-imports.js';
import { getModules } from './get-modules.js';
const E2E_PATH = 'test/cypress/integration';
const FINDED_PATHS = ['src', E2E_PATH];
function getGitDiff(options) {
const TARGET_BRANCH = options[2] || 'dev';
const diff = execSync(`git diff --name-only origin/${TARGET_BRANCH}`, {
encoding: 'utf-8',
});
return diff.split('\n');
}
async function getChangedModules() {
let changedModules = new Set();
const changes = getGitDiff(process.argv);
for (const change of changes) {
if (!change) continue;
if (!FINDED_PATHS.some((prefix) => change.startsWith(prefix))) return '';
const changedArray = [
...changedModules,
...new Set(getModules(await findImports(change))),
];
if (change.startsWith(E2E_PATH)) changedArray.push(change);
changedModules = new Set(changedArray);
}
return [...changedModules].join('\n');
}
getChangedModules()
.then((modules) => console.log(modules)) // is return
.catch((e) => {
console.error(e);
process.exit(1);
});