-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Expand file tree
/
Copy pathfix-bin.js
More file actions
39 lines (37 loc) · 1.22 KB
/
Copy pathfix-bin.js
File metadata and controls
39 lines (37 loc) · 1.22 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
const fs = require('fs-extra');
const path = require('path');
const fg = require('fast-glob');
const absoluteBinPath = path.resolve(__dirname, '../packages/graphql-codegen-cli/dist/cjs/bin.js');
const packageDirectories = fg
.sync(['examples/**/package.json'], { ignore: ['**/node_modules/**'] })
.map(p => path.dirname(p));
packageDirectories.push('website');
for (const dirname of packageDirectories) {
const absolutePath = path.join(__dirname, '..', dirname);
if (fs.lstatSync(absolutePath).isDirectory()) {
const execNames = ['graphql-codegen', 'graphql-codegen-esm'];
for (const execName of execNames) {
const targetPath = path.join(absolutePath, 'node_modules', '.bin', execName);
try {
fs.ensureSymlinkSync(absoluteBinPath, targetPath);
fs.chmodSync(targetPath, '755');
const targetCmdPath = targetPath + '.cmd';
fs.writeFileSync(
targetCmdPath,
`
@IF EXIST "%~dp0\\node.exe" (
"%~dp0\\node.exe" "${absoluteBinPath}" %*
) ELSE (
@SETLOCAL
@SET PATHEXT=%PATHEXT:;.JS;=;%
node "${absoluteBinPath}" %*
)
`,
);
fs.chmodSync(targetCmdPath, '755');
} catch {
/* ignore symlink that already exist */
}
}
}
}