1#!/usr/bin/env perl
2use strict;
3use warnings;
4
5# Core modules
6use Cwd qw( abs_path );
7use List::Util qw( first );
8use File::Find;
9use File::Spec::Functions qw( abs2rel );
10use File::Basename qw( dirname );
11#
12# Updates the MANIFEST file to include all generated web UI assets
13# that are tracked in Git.
14#
15
16die "Usage: update-manifest.pl [DIRECTORY]" unless scalar @ARGV == 1;
17
18my $server_path = $ARGV[0];
19die "$server_path not found" unless -r $server_path;
20
21my $htdocs_path = abs_path("$server_path/htdocs");
22my $mf_path = abs_path("$server_path/MANIFEST");
23my $mf_dir = dirname($mf_path);
24
25# read MANIFEST contents (but filter out htdocs/*)
26open my $mf, '<', $mf_path or die "Could not open manifest $mf_path: $!\n";
27my @contents = ();
28@contents = grep { $_ !~ /^htdocs\// } <$mf>;
29chomp @contents;
30close $mf;
31
32# search for tag
33my $index = first { $contents[$_] =~ m/UPDATE_MANIFEST_UI_LIST/ } 0..$#contents
34 or die "Tag UPDATE_MANIFEST_UI_LIST not found in MANIFEST\n";
35
36# list files on disk
37my @files;
38find({ no_chdir => 1, wanted => sub { push @files, abs2rel($_, $mf_dir) if -f } }, $htdocs_path);
39
40# insert file list into MANIFEST contents
41splice @contents, $index+1, 0, sort @files;
42
43# write MANIFEST
44open $mf, '>', $mf_path or die "Could not open manifest for writing\n";
45print $mf join "\n", @contents;
46close $mf;
47