mirror of
https://github.com/fhem/fhem-mirror.git
synced 2025-03-10 09:16:53 +00:00
42_npmjs: add event trigger
git-svn-id: https://svn.fhem.de/fhem/trunk@18579 2b470e98-0d58-463d-a4d8-8e2adae1ed80
This commit is contained in:
parent
1c2402dc9f
commit
8ba8f74f65
@ -62,6 +62,7 @@ BEGIN {
|
||||
modules
|
||||
Log3
|
||||
Debug
|
||||
DoTrigger
|
||||
CommandAttr
|
||||
attr
|
||||
AttrVal
|
||||
@ -444,7 +445,6 @@ sub Set($$@) {
|
||||
return "Unknown argument $cmd, choose one of $list";
|
||||
}
|
||||
|
||||
FhemTrigger($hash);
|
||||
AsynchronousExecuteNpmCommand($hash);
|
||||
|
||||
return undef;
|
||||
@ -538,23 +538,23 @@ sub Get($$@) {
|
||||
}
|
||||
}
|
||||
|
||||
sub FhemTrigger ($) {
|
||||
sub FhemTrigger ($$) {
|
||||
my $hash = shift;
|
||||
my $trigger = shift;
|
||||
my $name = $hash->{NAME};
|
||||
return
|
||||
unless ( defined( $hash->{".fhem"}{npm}{cmd} )
|
||||
&& $hash->{".fhem"}{npm}{cmd} =~
|
||||
m/^(install|uninstall|update)(?: (.+))/i );
|
||||
|
||||
# my $cmd = $1;
|
||||
# my $packages = $2;
|
||||
#
|
||||
# foreach my $package ( split / /, $1 ) {
|
||||
# next
|
||||
# unless ( $package =~ /^(?:@([\w-]+)\/)?([\w-]+)(?:@([\d\.=<>]+))?$/ );
|
||||
#
|
||||
# DoTrigger( $name, "UPDATESTART package", 1 );
|
||||
# }
|
||||
my $cmd = $1;
|
||||
my $packages = $2;
|
||||
|
||||
foreach my $package ( split / /, $packages ) {
|
||||
next
|
||||
unless ( $package =~ /^(?:@([\w-]+)\/)?([\w-]+)(?:@([\d\.=<>]+))?$/ );
|
||||
DoTrigger( $name, uc($trigger) . uc($cmd) . " $2", 1 );
|
||||
}
|
||||
}
|
||||
|
||||
###################################
|
||||
@ -633,6 +633,7 @@ sub AsynchronousExecuteNpmCommand($) {
|
||||
return undef;
|
||||
}
|
||||
|
||||
FhemTrigger( $hash, "BEGIN" );
|
||||
Log3 $name, 4, "npmjs ($name) - execute command asynchronously (PID= $pid)";
|
||||
|
||||
$hash->{".fhem"}{subprocess} = $subprocess;
|
||||
@ -793,7 +794,7 @@ sub ExecuteNpmCommand($) {
|
||||
}
|
||||
}
|
||||
else {
|
||||
my @packages;
|
||||
my @packages = "";
|
||||
foreach my $package ( split / /, $1 ) {
|
||||
next
|
||||
unless ( $package =~
|
||||
@ -815,14 +816,14 @@ sub ExecuteNpmCommand($) {
|
||||
push @packages, $package;
|
||||
}
|
||||
my $pkglist = join( ' ', @packages );
|
||||
return unless ($pkglist);
|
||||
return unless ( $pkglist ne "" );
|
||||
$npm->{npminstall} =~ s/%PACKAGES%/$pkglist/gi;
|
||||
}
|
||||
print qq($npm->{npminstall}\n) if ( $npm->{debug} == 1 );
|
||||
$response = NpmInstall($npm);
|
||||
}
|
||||
elsif ( $cmd->{cmd} =~ /^uninstall (.+)/ ) {
|
||||
my @packages;
|
||||
my @packages = "";
|
||||
foreach my $package ( split / /, $1 ) {
|
||||
next
|
||||
unless (
|
||||
@ -830,13 +831,13 @@ sub ExecuteNpmCommand($) {
|
||||
push @packages, $package;
|
||||
}
|
||||
my $pkglist = join( ' ', @packages );
|
||||
return unless ($pkglist);
|
||||
return unless ( $pkglist ne "" );
|
||||
$npm->{npmuninstall} =~ s/%PACKAGES%/$pkglist/gi;
|
||||
print qq($npm->{npmuninstall}\n) if ( $npm->{debug} == 1 );
|
||||
$response = NpmUninstall($npm);
|
||||
}
|
||||
elsif ( $cmd->{cmd} =~ /^update(?: (.+))?/ ) {
|
||||
my $pkglist;
|
||||
my $pkglist = "";
|
||||
if ( defined($1) ) {
|
||||
my @packages;
|
||||
foreach my $package ( split / /, $1 ) {
|
||||
@ -1141,6 +1142,7 @@ sub WriteReadings($$) {
|
||||
);
|
||||
}
|
||||
|
||||
FhemTrigger( $hash, "FINISH" );
|
||||
readingsEndUpdate( $hash, 1 );
|
||||
|
||||
ProcessUpdateTimer($hash)
|
||||
|
Loading…
x
Reference in New Issue
Block a user