-
Notifications
You must be signed in to change notification settings - Fork 2
/
build_dist.pl
executable file
·165 lines (136 loc) · 7.06 KB
/
build_dist.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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
#!/usr/bin/env perl
use strict;
use warnings;
use utf8;
use 5.010;
use JSON;
use Path::Tiny;
use Const::Fast;
const my $dash_renderer_package_name => 'dash_renderer';
const my $dash_component_packages => [ qw(
dash-core-components
dash-html-components
dash-table
) ];
# TODO dash path from command line
# TODO version from command line
# TODO pull repo to find tag version
my $base_dash_python_path = path('..');
my $dash_path = $base_dash_python_path->child('dash');
my $dist_share_js = path('share/assets');
# Generate componentes
# "Inject" perl generation files
my $python_folder_destination = $dash_path->child('dash')->child('development');
my $distro_python_patched_files = path('tool', 'python');
# Only works for $python_folder_destination
$distro_python_patched_files->visit(sub {
$_->copy($python_folder_destination) if /\.py$/;
},
{recurse => 1}
);
# Dash Renderer
my $dash_venv_path = $dash_path->child('.venv')->child('dev')->child('bin')->child('activate');
my $dash_renderer_path = $dash_path->child('dash-renderer');
my $dash_renderer_assets = $dash_renderer_path->child('dash_renderer');
$dash_renderer_assets->visit(sub {
$_->remove() if /\.js$/ || /\.map$/;
});
#$dash_renderer_path->child('node_modules')->remove_tree(); # This usually fail with the folder .cache
system("source $dash_venv_path; cd $dash_renderer_path; renderer build");
my $node_modules_renderer = $dash_renderer_path->child('node_modules');
my $dist_share_js_renderer = $dist_share_js->child('dash_renderer');
$dist_share_js_renderer->remove_tree();
$dist_share_js_renderer->mkpath();
for my $js_file ($dash_renderer_assets->children(qr/\.js$/)) {
$js_file->copy($dist_share_js_renderer);
my $package_name = $js_file->basename;
$package_name =~ s/([^@]+)@.+/$1/;
my $package_dist = $node_modules_renderer->child($package_name);
if ($package_dist->exists) {
my $license_destination_file = $dist_share_js_renderer->child($js_file->basename . '.LICENSE');
say 'Copying LICENSE to ' . $license_destination_file;
$package_dist->child('LICENSE')->copy($license_destination_file);
} elsif ($package_name eq 'polyfill') {
$package_name = '@babel';
$package_dist = $node_modules_renderer->child($package_name)->child('polyfill');
if ($package_dist->exists) {
my $license_destination_file = $dist_share_js_renderer->child($js_file->basename . '.LICENSE');
say 'Copying LICENSE to ' . $license_destination_file;
$package_dist->child('LICENSE')->copy($license_destination_file);
} else {
say 'LICENSE not found for ' . $js_file->basename;
}
}
}
# Dash renderer LICENSE
for my $js_renderer_file ($dist_share_js_renderer->children(qr/dash_renderer/)) {
$dash_path->child('LICENSE')->copy($dist_share_js_renderer->child($js_renderer_file->basename . '.LICENSE'));
}
my $python_script_extract_renderer_js_deps = path('tool', 'python', 'aux_dash_renderer.py');
my $dash_renderer_deps_path = $dist_share_js_renderer->child('js_deps.json');
# TODO extract js_deps.json into Dash::Renderer using aux_dash_renderer.py
system("source $dash_venv_path; python $python_script_extract_renderer_js_deps > $dash_renderer_deps_path");
for my $component_suite (@$dash_component_packages) {
print "Building $component_suite <============================================================>\n";
# TODO pull repo
my $component_suite_path = $base_dash_python_path->child($component_suite);
# Install js deps
system("cd $component_suite_path; npm ci");
#system("cd $component_suite_path; npm update");
system("source $dash_venv_path; cd $component_suite_path; npm run build");
my $perl_base_path = $component_suite_path->child('Perl');
my $component_suite_assets_directory_name = $component_suite;
$component_suite_assets_directory_name =~ s/-/_/g;
my $component_suite_assets_path = $dist_share_js->child($component_suite_assets_directory_name);
$component_suite_assets_path->remove_tree();
$component_suite_assets_path->mkpath();
$perl_base_path->child('js_deps.json')->copy($component_suite_assets_path);
# TODO source map files
my $node_modules_component_suite = $component_suite_path->child('node_modules');
for my $js_file ($perl_base_path->child('deps')->children()) {
$js_file->copy($component_suite_assets_path);
if ($js_file =~ /\.js$/) {
my $package_name = $js_file->basename;
print 'Searching LICENSE for ' . $package_name;
if ($package_name =~ /@/) {
$package_name =~ s/([^@]+)@.+/$1/;
my $package_dist = $node_modules_component_suite->child($package_name);
say ' in ' . $package_dist;
if ($package_dist->exists) {
my $license_destination_file = $component_suite_assets_path->child($js_file->basename . '.LICENSE');
say 'Copying LICENSE file from ' . $package_dist . ' to ' . $license_destination_file;
$package_dist->child('LICENSE')->copy($license_destination_file);
}
} elsif ($package_name =~ /$component_suite_assets_directory_name/) {
my $package_dist = $component_suite_path;
say ' in ' . $package_dist;
my $license_destination_file = $component_suite_assets_path->child($js_file->basename . '.LICENSE');
say 'Copying LICENSE file from ' . $package_dist . ' to ' . $license_destination_file;
$package_dist->child('LICENSE')->copy($license_destination_file);
} elsif ($package_name =~ /async~/) {
$package_name =~ s/async~(.+)/$1/;
my $package_dist = $node_modules_component_suite->child($package_name);
say ' in ' . $package_dist;
if ($package_dist->exists) {
my $license_destination_file = $component_suite_assets_path->child($js_file->basename . '.LICENSE');
say 'Copying LICENSE file from ' . $package_dist . ' to ' . $license_destination_file;
$package_dist->child('LICENSE')->copy($license_destination_file);
} else {
say 'Assuming there is not LICENSE file for ' . $js_file . ' because is part of the main component suite';
}
} else {
say 'Assuming there is not LICENSE file for ' . $js_file . ' because is part of the main component suite';
}
}
}
my $component_suite_package_files_directory = path('lib', map {ucfirst } split(/-/, $component_suite));
$component_suite_package_files_directory->remove_tree();
$component_suite_package_files_directory->mkpath();
for my $pm_file ($perl_base_path->child($component_suite_assets_directory_name)->children(qr/\.pm$/)) {
$pm_file->copy($component_suite_package_files_directory);
}
for my $pm_file ($perl_base_path->children(qr/\.pm$/)) {
$pm_file->copy($component_suite_package_files_directory->parent);
}
}
# TODO Automatic Components.pm generation