nx/scripts/generate-graph-environment.ts
MaxKless b73f1e0e00
fix(core): set windowsHide: true wherever possible (#28073)
<!-- Please make sure you have read the submission guidelines before
posting an PR -->
<!--
https://github.com/nrwl/nx/blob/master/CONTRIBUTING.md#-submitting-a-pr
-->

<!-- Please make sure that your commit message follows our format -->
<!-- Example: `fix(nx): must begin with lowercase` -->

<!-- If this is a particularly complex change or feature addition, you
can request a dedicated Nx release for this pull request branch. Mention
someone from the Nx team or the `@nrwl/nx-pipelines-reviewers` and they
will confirm if the PR warrants its own release for testing purposes,
and generate it for you if appropriate. -->

## Current Behavior
<!-- This is the behavior we have today -->

## Expected Behavior
<!-- This is the behavior we should expect with the changes in this PR
-->

## Related Issue(s)
<!-- Please link the issue being fixed so it gets closed when this is
merged. -->

Fixes #
2024-09-24 11:31:22 -04:00

83 lines
2.3 KiB
TypeScript

import { ensureDirSync } from 'fs-extra';
import { join } from 'path';
import { readdirSync, writeFileSync } from 'fs';
import { execSync } from 'child_process';
function generateFileContent(
workspaces: { id: string; label: string; url: string }[]
) {
return `
window.exclude = [];
window.watch = false;
window.environment = 'dev';
window.useXstateInspect = false;
window.appConfig = {
showDebugger: true,
showExperimentalFeatures: true,
workspaces: ${JSON.stringify(workspaces)},
defaultWorkspaceId: '${workspaces[0].id}',
};
`;
}
function writeFile() {
let generatedGraphs;
try {
generatedGraphs = readdirSync(
join(__dirname, '../graph/client/src/assets/generated-project-graphs')
).map((filename) => {
const id = filename.substring(0, filename.length - 5);
return {
id,
label: id,
projectGraphUrl: join('assets/generated-project-graphs/', filename),
taskGraphUrl: join('assets/generated-task-graphs/', filename),
taskInputsUrl: join('assets/generated-task-inputs/', filename),
sourceMapsUrl: join('assets/generated-source-maps/', filename),
};
});
} catch {
generatedGraphs = [];
}
let pregeneratedGraphs;
try {
pregeneratedGraphs = readdirSync(
join(__dirname, '../graph/client/src/assets/project-graphs')
).map((filename) => {
const id = filename.substring(0, filename.length - 5);
return {
id,
label: id,
projectGraphUrl: join('assets/project-graphs/', filename),
taskGraphUrl: join('assets/task-graphs/', filename),
taskInputsUrl: join('assets/task-inputs/', filename),
sourceMapsUrl: join('assets/source-maps/', filename),
};
});
} catch {
pregeneratedGraphs = [];
}
// if no generated projects are found, generate one for nx and try this again
if (generatedGraphs.length === 0) {
execSync('nx run graph-client:generate-graph --directory ./ --name nx', {
windowsHide: true,
});
writeFile();
return;
}
const projects = generatedGraphs.concat(pregeneratedGraphs);
ensureDirSync(join(__dirname, '../graph/client/src/assets/dev/'));
writeFileSync(
join(__dirname, '../graph/client/src/assets/dev/', `environment.js`),
generateFileContent(projects)
);
}
writeFile();