nx/scripts/generate-graph.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

111 lines
2.7 KiB
TypeScript

import { execSync } from 'child_process';
import { existsSync, mkdirSync, readFileSync, writeFileSync } from 'fs';
import { join } from 'path';
import * as yargs from 'yargs';
import { ensureDirSync, statSync } from 'fs-extra';
async function generateGraph(directory: string, name: string) {
if (!existsSync(directory)) {
console.error(`Could not find directory ${directory}`);
return;
}
try {
execSync(
'npx nx graph --file ./node_modules/.cache/nx-graph-gen/graph.html',
{ cwd: directory, stdio: 'ignore', windowsHide: true }
);
} catch {
console.error(`Could not run graph command in directory ${directory}`);
return;
}
const environmentJs = readFileSync(
join(directory, 'node_modules/.cache/nx-graph-gen/static/environment.js'),
{ encoding: 'utf-8' }
);
const projectGraphResponse = environmentJs.match(
/window.projectGraphResponse = (.*?);/
);
const taskGraphResponse = environmentJs.match(
/window.taskGraphResponse = (.*?);/
);
const expandedTaskInputsReponse = environmentJs.match(
/window.expandedTaskInputsResponse = (.*?);/
);
const sourceMapsResponse = environmentJs.match(
/window.sourceMapsResponse = (.*?);/
);
ensureDirSync(
join(__dirname, '../graph/client/src/assets/generated-project-graphs/')
);
ensureDirSync(
join(__dirname, '../graph/client/src/assets/generated-task-graphs/')
);
ensureDirSync(
join(__dirname, '../graph/client/src/assets/generated-task-inputs/')
);
ensureDirSync(
join(__dirname, '../graph/client/src/assets/generated-source-maps/')
);
writeFileSync(
join(
__dirname,
'../graph/client/src/assets/generated-project-graphs/',
`${name}.json`
),
projectGraphResponse[1]
);
writeFileSync(
join(
__dirname,
'../graph/client/src/assets/generated-task-graphs/',
`${name}.json`
),
taskGraphResponse[1]
);
writeFileSync(
join(
__dirname,
'../graph/client/src/assets/generated-task-inputs/',
`${name}.json`
),
expandedTaskInputsReponse[1]
);
writeFileSync(
join(
__dirname,
'../graph/client/src/assets/generated-source-maps/',
`${name}.json`
),
sourceMapsResponse[1]
);
}
(async () => {
const parsedArgs = yargs
.scriptName('pnpm generate-graph')
.strictOptions()
.option('name', {
type: 'string',
requiresArg: true,
description: 'The snake-case name of the file created',
})
.option('directory', {
type: 'string',
requiresArg: true,
description: 'Directory of workspace',
})
.parseSync();
await generateGraph(parsedArgs.directory, parsedArgs.name);
})();