-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpre-parse.pl
executable file
·40 lines (30 loc) · 973 Bytes
/
pre-parse.pl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
#!/usr/bin/perl
# Script returns repo scripts to add to ACDEF and the modified CLI input.
# use strict;
# use warnings;
# use diagnostics;
my $input = $ARGV[0];
my $output = "\n";
my ($workspace_name, $cli_remainder) = $input =~ /^[ \t]*?yarn[ \t]+?workspace[ \t]+?([^ \t]+?)[ \t]+?(.*)/;
# ----- Input logic -----
if ($cli_remainder) { $output = "yarn $cli_remainder"; }
# ----- ACDEF logic -----
if ($input =~ /^[ \t]*?yarn[ \t]+?([^ \t]*?)$/) {
my $cwd = $ENV{'PWD'};
my $pkg = '';
# If a workspace use its location.
if ($workspace_name) { $cwd .= "/$1"; }
while ($cwd) {
if (-e "$cwd/package.json") { $pkg = "$cwd/package.json"; last; }
$cwd = substr($cwd, 0, rindex($cwd, '/'));
}
if ($pkg) {
my $pkgcontents = do{local(@ARGV,$/)=$pkg;<>};
if ($pkgcontents =~ /"scripts"\s*:\s*{([\s\S]*?)}(,|$)/) {
my @matches = ($1 =~ /"([^"]*)"\s*:/g);
foreach (@matches) { $output .= '.' . $_ . " --\n"; }
chomp($output);
}
}
}
print $output;