UNPKG

nativescript

Version:

Command-line interface for building NativeScript projects

79 lines 3.64 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.EmbedCommand = void 0; const yok_1 = require("../../common/yok"); const prepare_1 = require("../prepare"); const path_1 = require("path"); const color_1 = require("../../color"); class EmbedCommand extends prepare_1.PrepareCommand { constructor($options, $prepareController, $platformValidationService, $projectData, $platformCommandParameter, $platformsDataService, $prepareDataService, $migrateController, $logger, $fs, $projectConfigService) { super($options, $prepareController, $platformValidationService, $projectData, $platformCommandParameter, $platformsDataService, $prepareDataService, $migrateController); this.$options = $options; this.$prepareController = $prepareController; this.$platformValidationService = $platformValidationService; this.$projectData = $projectData; this.$platformCommandParameter = $platformCommandParameter; this.$platformsDataService = $platformsDataService; this.$prepareDataService = $prepareDataService; this.$migrateController = $migrateController; this.$logger = $logger; this.$fs = $fs; this.$projectConfigService = $projectConfigService; } resolveHostProjectPath(hostProjectPath) { if (hostProjectPath.charAt(0) === ".") { // resolve relative to the project dir const projectDir = this.$projectData.projectDir; return (0, path_1.resolve)(projectDir, hostProjectPath); } return (0, path_1.resolve)(hostProjectPath); } async execute(args) { const hostProjectPath = args[1]; const resolvedHostProjectPath = this.resolveHostProjectPath(hostProjectPath); if (!this.$fs.exists(resolvedHostProjectPath)) { this.$logger.error(`The host project path ${color_1.color.yellow(hostProjectPath)} (resolved to: ${color_1.color.yellow.dim(resolvedHostProjectPath)}) does not exist.`); return; } this.$options["hostProjectPath"] = resolvedHostProjectPath; if (args.length > 2) { this.$options["hostProjectModuleName"] = args[2]; } return super.execute(args); } async canExecute(args) { const canSuperExecute = await super.canExecute(args); if (!canSuperExecute) { return false; } // args[0] is the platform // args[1] is the path to the host project // args[2] is the host project module name const platform = args[0].toLowerCase(); // also allow these to be set in the nativescript.config.ts if (!args[1]) { const hostProjectPath = this.getEmbedConfigForKey("hostProjectPath", platform); if (hostProjectPath) { args[1] = hostProjectPath; } } if (!args[2]) { const hostProjectModuleName = this.getEmbedConfigForKey("hostProjectModuleName", platform); if (hostProjectModuleName) { args[2] = hostProjectModuleName; } } console.log(args); if (args.length < 2) { return false; } return true; } getEmbedConfigForKey(key, platform) { // get the embed.<platform>.<key> value, or fallback to embed.<key> value return this.$projectConfigService.getValue(`embed.${platform}.${key}`, this.$projectConfigService.getValue(`embed.${key}`)); } } exports.EmbedCommand = EmbedCommand; yok_1.injector.registerCommand("embed", EmbedCommand); //# sourceMappingURL=embed.js.map