-
Notifications
You must be signed in to change notification settings - Fork 2.2k
/
nx.ts
65 lines (61 loc) · 1.78 KB
/
nx.ts
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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
#!/usr/bin/env node
import { statSync } from 'fs';
import * as path from 'path';
function findWorkspaceRoot(dir: string) {
if (path.dirname(dir) === dir) return null;
if (exists(path.join(dir, 'angular.json'))) {
return { type: 'angular', dir };
} else if (exists(path.join(dir, 'workspace.json'))) {
return { type: 'nx', dir };
} else {
return findWorkspaceRoot(path.dirname(dir));
}
}
function exists(filePath: string): boolean {
try {
return statSync(filePath).isFile() || statSync(filePath).isDirectory();
} catch (err) {
return false;
}
}
const workspace = findWorkspaceRoot(__dirname);
// we are running a local nx
if (workspace) {
// The commandsObject is a Yargs object declared in `nx-commands.ts`,
// It is exposed and bootstrapped here to provide CLI features.
const w = require('@nrwl/workspace');
if (w.supportedNxCommands.includes(process.argv[2])) {
// The commandsObject is a Yargs object declared in `nx-commands.ts`,
// It is exposed and bootstrapped here to provide CLI features.
w.commandsObject.argv;
} else if (workspace.type === 'nx') {
require(path.join(
workspace.dir,
'node_modules',
'@nrwl',
'tao',
'index.js'
));
} else if (workspace.type === 'angular') {
w.output.note({
title: `Nx didn't recognize the command, forwarding on to the Angular CLI.`
});
require(path.join(
workspace.dir,
'node_modules',
'@angular',
'cli',
'lib',
'init.js'
));
}
} else {
// we are running global nx
const w = findWorkspaceRoot(process.cwd());
if (w) {
require(path.join(w.dir, 'node_modules', '@nrwl', 'cli', 'bin', 'nx.js'));
} else {
console.log(`The current directory isn't part of an Nx workspace.`);
process.exit(0);
}
}