WWW-Shopify-Tools-Themer
view release on metacpan or search on metacpan
shopify-themer.pl view on Meta::CPAN
if ($^O !~ m/MSWin/i) {
# *NIX Derivatives install, probably.
die "Must have HOME environment variable defined; Sorry, automatic gedit installation isn't supported without this.\n" unless $ENV{'HOME'};
print "Checking to see if gedit exists... ";
`gedit --version`;
die "Can't detect gedit.\n" unless $? == 0;
print "Yes.\n";
print "Checking to see if python exists... ";
`python --version`;
die "Can't detect python.\n" unless $? == 0;
my $share_directory = $ENV{'HOME'} . "/.local/share";
$plugin_directory = "$share_directory/gedit/plugins";
$target_directory = "$plugin_directory/shopifyeditor";
$language_directory = "$share_directory/gtksourceview-3.0";
$icon_directory = "$share_directory/icons/hicolor/scalable/apps";
}
else {
die "Can't find program files environment variable." unless $ENV{'PROGRAMFILES'};
my $share_directory = $ENV{'PROGRAMFILES'} . "/gedit";
if (!(-d $share_directory) && $ENV{'PROGRAMFILES(X86)'}) {
$share_directory = $ENV{'PROGRAMFILES(X86)'} . "/gedit";
}
if (!-d $share_directory) {
print "Can't find gedit directory in Program Files; enter it here: " unless -d $share_directory;
$share_directory = <STDIN>;
}
die "Directory doesn't exist." unless -d $share_directory;
$share_directory = "$share_directory/share";
$plugin_directory = "$share_directory/plugins";
$target_directory = "$plugin_directory/shopifyeditor";
$language_directory = "$share_directory/gtksourceview-2.0";
$icon_directory = "$share_directory/icons/hicolor/scalable/apps";
}
if (!-e $target_directory) {
print "Checking for presence of gedit settings directory in $plugin_directory... ";
prompt_directory($plugin_directory);
print "Symlinking sharedir to directory... ";
die "Can't symlink, for some reason.\n" if symlink($dist_directory, $target_directory) != 1;
print "OK.\n";
}
if (!-e "$language_directory/language-specs") {
print "Checking for presence of source view languages in $language_directory... ";
prompt_directory($language_directory);
print "Symlinking language dir to directory... ";
die "Can't symlink for some reason.\n" if symlink("$dist_directory/languages", "$language_directory/language-specs") != 1;
print "OK.\n";
}
if (!-e "$icon_directory") {
print "Checking for presence of icon directory in $icon_directory... ";
prompt_directory($icon_directory);
}
if (!-l "$icon_directory/shopify-icon.png") {
print "Symlinking icon to directory... ";
die "Can't symlink, for some reason.\n" if symlink("$dist_directory/shopify-icon.png", "$icon_directory/shopify-icon.png") != 1;
print "OK.\n";
}
print "Done.\n";
exit(0);
}
my ($settingFile, $manifestFile) = ($settings->{directory} . "/.shopsettings", $settings->{directory} . "/.shopmanifest");
my $filesettings = decode_json(read_file($settingFile)) if (-e $settingFile);
for (keys(%$filesettings)) { $settings->{$_} = $filesettings->{$_} unless defined $settings->{$_}; }
die "Please specify a --url, --apikey xor --email and --password when using for the first time.\n" unless defined $settings->{url} && defined $settings->{password} && (defined $settings->{apikey} xor defined $settings->{email});
my %saveSettings = map { $_ => $settings->{$_} } grep { $_ ne "directory" } keys(%$settings);
write_file($settingFile, encode_json(\%saveSettings));
my $STC = new WWW::Shopify::Tools::Themer($settings);
use List::Util qw(first);
my $interactive = $action eq "interactive";
my %actions = (
'info' => sub {
my @themes = $STC->get_themes;
print encode_json(int(@themes) > 0 ? \@themes : []) . "\n";
},
'pullAll' => sub {
$STC->pull_all;
},
'pushAll' => sub {
$STC->push_all;
},
'push_pages' => sub {
$STC->push_pages;
},
'pull_pages' => sub {
$STC->pull_pages;
},
'watch' => sub {
use File::Find;
my $theme = undef;
if ($ARGS[1]) {
if ($ARGS[1] =~ m/^\d+$/) {
$theme = first { $_->{id} eq $ARGS[1] } @{$STC->manifest->{themes}};
}
else {
$theme = first { $_->{name} eq $ARGS[1] } @{$STC->manifest->{themes}}
}
}
die "Unable to find theme " . $ARGS[1] . "\n" unless $theme;
print "Entering Check Loop for " . ($theme ? "theme " . $theme->{name} . " (" . $theme->{id} . ") " : "all themes ") . "...\n";
my $directory = $theme ? $STC->directory . "/" . $STC->shop_url_truncated . "-" . $theme->{id} : $STC->directory;
while (1) {
my $should_push = 0;
find({ wanted => sub {
my ($file) = $_;
$should_push = 1 if !$should_push && !-d $file && $file !~ m/\/\.[^\/]+$/ && $STC->manifest->has_local_changes($file);
}, no_chdir => 1 }, $directory);
if ($should_push) {
print "Change detected. Pushing ...\n";
if ($theme) {
$STC->push(new WWW::Shopify::Model::Theme($theme));
}
else {
$STC->push_all;
}
print "Done.\n";
}
sleep($interval);
}
( run in 0.435 second using v1.01-cache-2.11-cpan-71847e10f99 )