Repository navigation
Expand file tree
/
Copy pathtns
More file actions
executable file
·76 lines (69 loc) · 2.43 KB
/
Copy pathtns
File metadata and controls
executable file
·76 lines (69 loc) · 2.43 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
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
66
67
68
69
70
71
72
73
74
75
76
#!/usr/bin/env node
"use strict";
var path = require("path"),
fs = require("fs"),
// In the published package dist/ is the root, so lib/ already sits next to
// bin/. In a source checkout lib/ holds only TypeScript and the compiled
// output lives under dist/.
distLib = path.join(__dirname, "..", "dist", "lib"),
pathToLib = fs.existsSync(distLib)
? distLib
: path.join(__dirname, "..", "lib"),
pathToCommon = path.join(pathToLib, "common");
require(path.join(pathToCommon, "verify-node-version")).verifyNodeVersion();
// Prefer a project-local CLI install when one is resolvable from the current
// directory: the project pins its own nativescript version, and running the
// invoked (typically global) copy against it means two CLI versions
// disagreeing about one project. The probe must never break the CLI - any
// failure falls through to the invoked copy. Opt out per invocation with
// --no-local-cli or NS_CLI_NO_LOCAL=1; NS_CLI_LOCAL_DELEGATED marks the
// handed-off process so the local copy never delegates again.
var noLocalFlagIndex = process.argv.indexOf("--no-local-cli");
if (noLocalFlagIndex !== -1) {
process.argv.splice(noLocalFlagIndex, 1);
}
if (
!process.env.NS_CLI_LOCAL_DELEGATED &&
!process.env.NS_CLI_NO_LOCAL &&
noLocalFlagIndex === -1
) {
var localEntry = null;
var localVersion = null;
var localDir = null;
try {
var localPackageJsonPath = require.resolve("nativescript/package.json", {
paths: [process.cwd()],
});
var ownPackageJsonPath = path.join(__dirname, "..", "package.json");
// realpath both sides so an npm-linked or symlinked install of the
// same copy is not mistaken for a different one.
if (
fs.realpathSync(localPackageJsonPath) !==
fs.realpathSync(ownPackageJsonPath)
) {
localDir = path.dirname(localPackageJsonPath);
var candidate = path.join(localDir, "bin", "tns");
if (fs.existsSync(candidate)) {
localEntry = candidate;
localVersion = require(localPackageJsonPath).version;
}
}
} catch (err) {
// No local install resolvable from cwd - run the invoked copy.
}
if (localEntry) {
process.env.NS_CLI_LOCAL_DELEGATED = "1";
// stderr, so scripts parsing stdout (e.g. `ns --version`) are unaffected.
console.error(
"Using the project-local nativescript@" +
localVersion +
" (" +
localDir +
").",
);
require(localEntry);
return;
}
}
var pathToCliExecutable = path.join(pathToLib, "nativescript-cli.js");
require(pathToCliExecutable);