mirror of
https://github.com/Mibew/mibew.git
synced 2025-04-11 02:10:12 +03:00
Improve cli tool for bulk update of headers
This commit is contained in:
parent
6b20d0c8b6
commit
d115befab9
@ -3,7 +3,7 @@
|
|||||||
|
|
||||||
This file is a part of Mibew Messenger.
|
This file is a part of Mibew Messenger.
|
||||||
|
|
||||||
Copyright 2005-2020 the original author or authors.
|
Copyright 2005-2021 the original author or authors.
|
||||||
|
|
||||||
Licensed under the Apache License, Version 2.0 (the "License");
|
Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
you may not use this file except in compliance with the License.
|
you may not use this file except in compliance with the License.
|
||||||
@ -135,7 +135,7 @@ sub update_dir {
|
|||||||
|
|
||||||
# Function: update_file
|
# Function: update_file
|
||||||
# Description
|
# Description
|
||||||
# Function to update header of the (php) file
|
# Function to update header of the (php|js) file
|
||||||
# Argument(s)
|
# Argument(s)
|
||||||
# 1. (string) name of the file
|
# 1. (string) name of the file
|
||||||
# 2. (string) new header as a valid comment
|
# 2. (string) new header as a valid comment
|
||||||
@ -148,8 +148,8 @@ sub update_file {
|
|||||||
my $quiet = shift || 0;
|
my $quiet = shift || 0;
|
||||||
|
|
||||||
# check file's extension
|
# check file's extension
|
||||||
unless ($file =~ /\.php$/) {
|
unless ($file =~ /\.(php|js)$/) {
|
||||||
print "[info] Skipped file $file: not a php script\n" unless $quiet;
|
print "[info] Skipped file $file: neither a php script, nor a js\n" unless $quiet;
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -161,13 +161,24 @@ sub update_file {
|
|||||||
}
|
}
|
||||||
|
|
||||||
# check file's content to be a php code
|
# check file's content to be a php code
|
||||||
unless ($content->{'content'} =~ /^<\?php/) {
|
my $type = ($content->{'content'} =~ /^<\?php/)
|
||||||
print "[info] Skipped file $file: not a php script\n" unless $quiet;
|
? 'php'
|
||||||
|
: ($content->{'content'} =~ /^\/\*!/)
|
||||||
|
? 'js'
|
||||||
|
: undef;
|
||||||
|
unless (defined($type)) {
|
||||||
|
print "[info] Skipped file $file: neither a php script, nor a js\n" unless $quiet;
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
# update header
|
# update header
|
||||||
$content->{'content'} =~ s~^(<\?php\n)/\*.*?\*/~$1$header~s;
|
if ($type eq 'php') {
|
||||||
|
$content->{'content'} =~ s~^(<\?php\n)/\*.*?\*/~$1$header~s;
|
||||||
|
}
|
||||||
|
elsif ($type eq 'js') {
|
||||||
|
$content->{'content'} =~ s~^(/\*!\n).*?\*/~$header~s;
|
||||||
|
$content->{'content'} =~ s/^(\/\*)/$1!/;
|
||||||
|
}
|
||||||
|
|
||||||
# try to set the new contents of the file
|
# try to set the new contents of the file
|
||||||
if (set_file_content($file, $content->{'content'})) {
|
if (set_file_content($file, $content->{'content'})) {
|
||||||
|
Loading…
Reference in New Issue
Block a user