Plugins don't get all the needed information...
NathanaelA opened this issue · 7 comments
When using the hook; plugins don't know if the hook is being targeted at ios or android. I'm having to parse the command line myself to pull this info out even though the nativescript command should have that information.
In addition the platform folder imho should be pointing to the actual platform that is being targetted; not the ./platforms folder, as I then have to create the entire path to where the ios or android build data resides.
@Fatme any news on this?
Facing this issue too
@farfromrefug - Actually you can get that information a different way. Here is the code now use to figure this all out:
module.exports = function (logger, platformsData, projectData, hookArgs) {
// Are we doing this for ios? (In this specific plugin hook I only need to worry about ios)
if (hookArgs.platform != 'ios') return;
// Could have used the hookArgs.platform here, but I find it easier to read hard coding it
var platformData = platformsData.getPlatformData('ios');
// Use the platform data to get the actual output directory...
var platformOutDir = platformData.appDestinationDirectoryPath;
};
Please note; you can use my cool https://searchcode.nativescript.rocks to find other hook files that other developers wrote that show some of the other features that are now available. Biggest issue now is that nothing is really documented anywhere, so searchcode is invaluable to see what can be done.
The first option is to use $options.argv._. It will return the full command line as array. After that you can search for ios or android item.
module.exports = function ($options) {
const commandLine = $options.argv._;
const isiOSPlatform = commandLine.find(item => item.toLowerCase() === "ios");
}
The second option is to use $devicesService.platform but it will NOT work for all the commands and all the hooks.
It will work only for device related commands (where device discovery is started) like tns run android, tns run ios, tns debug ios, tns debug anroid.
It will not work for device related commands when the platform is not provided - for example tns run.
It will not work for commands like tns preapre ios where device discovery is not started.
module.exports = function ($devicesService) {
const platform = $devicesService.platform;
}
@Fatme @NathanaelA thanks for the explanations! I think I ll use the command line args.
The drawback of this approach is that it will not work when {N} CLI is used as library.
@Fatme when is it used as a library? sidekick?
@farfromrefug
Yes, sidekick