nativescript
Version:
Command-line interface for building NativeScript projects
123 lines (122 loc) • 4.64 kB
JavaScript
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.StaticConfig = exports.Configuration = void 0;
const path = require("path");
const shelljs = require("shelljs");
const os = require("os");
const _ = require("lodash");
const yok_1 = require("./common/yok");
class Configuration {
constructor($fs) {
this.$fs = $fs;
this.DEBUG = false;
this.ANDROID_DEBUG_UI = null;
this.USE_POD_SANDBOX = false;
this.GA_TRACKING_ID = null;
this.DISABLE_HOOKS = false;
_.extend(this, this.loadConfig("config"));
}
loadConfig(name) {
const configFileName = this.getConfigPath(name);
return this.$fs.readJson(configFileName);
}
getConfigPath(filename) {
return path.join(__dirname, "../config", filename + ".json");
}
}
exports.Configuration = Configuration;
yok_1.injector.register("config", Configuration);
class StaticConfig {
get PROFILE_DIR_NAME() {
return ".nativescript-cli";
}
constructor($injector) {
this.$injector = $injector;
this.QR_SIZE = 5;
this.PROJECT_FILE_NAME = "package.json";
this.CLIENT_NAME_KEY_IN_PROJECT_FILE = "nativescript";
this.CLIENT_NAME = "tns";
this.CLIENT_NAME_ALIAS = "NativeScript";
this.TRACK_FEATURE_USAGE_SETTING_NAME = "TrackFeatureUsage";
this.ERROR_REPORT_SETTING_NAME = "TrackExceptions";
this.ANALYTICS_INSTALLATION_ID_SETTING_NAME = "AnalyticsInstallationID";
this.RESOURCE_DIR_PATH = path.join(__dirname, "..", "resources");
this.version = require("../package.json").version;
this.cliBinPath = path.resolve(__dirname, "..", "bin", "nativescript.js");
this._adbFilePath = null;
this._userAgent = null;
}
get disableCommandHooks() {
return true;
}
get HTML_CLI_HELPERS_DIR() {
return path.join(__dirname, "../docs/helpers");
}
get pathToPackageJson() {
return path.join(__dirname, "..", "package.json");
}
get PATH_TO_BOOTSTRAP() {
return path.join(__dirname, "bootstrap.js");
}
async getAdbFilePath() {
if (!this._adbFilePath) {
const androidToolsInfo = this.$injector.resolve("androidToolsInfo");
this._adbFilePath =
(await androidToolsInfo.getPathToAdbFromAndroidHome()) ||
(await this.getAdbFilePathCore());
}
return this._adbFilePath;
}
get USER_AGENT_NAME() {
if (!this._userAgent) {
this._userAgent = `${this.CLIENT_NAME}CLI`;
}
return this._userAgent;
}
set USER_AGENT_NAME(userAgentName) {
this._userAgent = userAgentName;
}
get MAN_PAGES_DIR() {
return path.join(__dirname, "..", "docs", "man_pages");
}
get HTML_PAGES_DIR() {
return path.join(__dirname, "..", "docs", "html");
}
get HTML_COMMON_HELPERS_DIR() {
return path.join(__dirname, "common", "docs", "helpers");
}
async getAdbFilePathCore() {
const $childProcess = this.$injector.resolve("$childProcess");
try {
const proc = await $childProcess.spawnFromEvent("adb", ["version"], "exit", undefined, { throwError: false });
if (proc.stderr) {
return await this.spawnPrivateAdb();
}
}
catch (e) {
if (e.code === "ENOENT") {
return await this.spawnPrivateAdb();
}
}
return "adb";
}
async spawnPrivateAdb() {
const $fs = this.$injector.resolve("$fs"), $childProcess = this.$injector.resolve("$childProcess"), $hostInfo = this.$injector.resolve("$hostInfo");
const defaultAdbDirPath = path.join(__dirname, "common", "resources", "platform-tools", "android", process.platform);
const pathToPackageJson = path.join(__dirname, "..", "package.json");
const nsCliVersion = require(pathToPackageJson).version;
const tmpDir = path.join(os.tmpdir(), `nativescript-cli-${nsCliVersion}`);
$fs.createDirectory(tmpDir);
const targetAdb = path.join(tmpDir, "adb");
if (!$fs.exists(tmpDir) || !$fs.readDirectory(tmpDir).length) {
shelljs.cp(path.join(defaultAdbDirPath, "*"), tmpDir);
if (!$hostInfo.isWindows) {
shelljs.chmod("+x", targetAdb);
}
}
await $childProcess.spawnFromEvent(targetAdb, ["start-server"], "exit");
return targetAdb;
}
}
exports.StaticConfig = StaticConfig;
yok_1.injector.register("staticConfig", StaticConfig);