Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 21 additions & 1 deletion lib/neocities/cli.rb
Original file line number Diff line number Diff line change
Expand Up @@ -189,12 +189,14 @@ def push
@excluded_files = []
@dry_run = false
@prune = false
@preview_file = nil
loop do
case @subargs[0]
when '--no-gitignore' then @subargs.shift; @no_gitignore = true
when '-e' then @subargs.shift; @excluded_files.push(@subargs.shift)
when '--dry-run' then @subargs.shift; @dry_run = true
when '--prune' then @subargs.shift; @prune = true
when '--preview-file' then @subargs.shift; @preview_file = @subargs.shift
when /^-/ then puts(@pastel.red.bold("Unknown option: #{@subargs[0].inspect}")); display_push_help_and_exit
else break
end
Expand All @@ -212,7 +214,7 @@ def push
end

if !root_path.directory?
display_response result: 'error', message: 'provided path is not a directory'
display_response result: 'error', message: "provided path #{root_path} is not a directory"
display_push_help_and_exit
end

Expand Down Expand Up @@ -267,6 +269,22 @@ def push

paths.collect! { |path| Pathname path }

if @preview_file
preview_file_path = Pathname @preview_file
if !preview_file_path.file?
display_response result: 'error', message: "preview file #{@preview_file} does not exist or is not a regular file"
display_push_help_and_exit
elsif !paths.any? { |path| Pathname(path).cleanpath == preview_file_path.cleanpath }
display_response result: 'error', message: "preview file #{@preview_file} is ignored"
display_push_help_and_exit
end

# The file used for preview is the first file that is uploaded in a SiteChange
# Ensure the preview file is uploaded first to make sure it is the preview
paths.reject! { |p| p.cleanpath == preview_file_path.cleanpath }
paths.unshift(preview_file_path)
end

paths.each do |path|
next if path.directory?
print @pastel.bold("Uploading #{path} ... ")
Expand Down Expand Up @@ -435,6 +453,8 @@ def display_push_help_and_exit

#{@pastel.green '$ neocities push --prune .'} Delete site files not in dir (be careful!)

#{@pastel.green '$ neocities push --preview-file index.html .'} Use index.html as the main preview image in activity feed entries

HERE
exit
end
Expand Down