Last active
November 19, 2018 14:25
-
-
Save sylvainbx/3c2a0f161b945ae1f231e69a52798e59 to your computer and use it in GitHub Desktop.
Convert JSdoc comments from coffeescript to javascript
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/perl | |
use strict; | |
use warnings; | |
my $file = shift @ARGV; | |
# open (read) file from command line argument | |
open(my $jsfile, '<', $file) or die "Can't read file '$file' [$!]\n"; | |
# undef the line separator ($/) for this script, to grab the whole file | |
local $/; | |
# read file | |
my $js = <$jsfile>; | |
close $jsfile; | |
sub tojsdoc { | |
my($doc) = @_; | |
$doc =~ s!^( *)// #!$1/**!; | |
$doc =~ s!( *)// #$!$1 */!; | |
$doc =~ s!^( *)//( #)?! $2 ||'' eq '#' ? "$1/*" : "$1 *" !gme; | |
$doc | |
} | |
# process jsdoc comments | |
$js =~ s!(// #\R *// (.+?\n)+( *)// #\R)!tojsdoc($1)!gme; | |
$js =~ s!// # *(.*)$!// $1!gm; | |
# open (write) file from command line argument | |
open(my $fh, '>', $file) or die "Can't write to file '$file' [$!]\n"; | |
# print to file | |
print $fh $js; | |
close $fh; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment