neocities-red 1.0.1 → 1.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: c066652075fa4d602042ac55ae6238a14d38c6367897d75cb74dd2a116bf3981
4
- data.tar.gz: 6025df450863903e6ac46b2c580d7623671206a574bd0e3668dd589ef59ff364
3
+ metadata.gz: 979f4ecefbbdda5967fa634639786036b9c46d43c64c90207d7e4b849e19827a
4
+ data.tar.gz: 69fbd007930e5b45457f1445df4b9b0a877213b1dd2e523070a46acd1d2e8fc8
5
5
  SHA512:
6
- metadata.gz: 982178ffcfe2a7c8cf11ec9cb1610de806ae05186a165a6a7d9bb23daabc43b1b05a68074cde75088d77f17b5e5858f993378db153b3dc8231028df87b636d3c
7
- data.tar.gz: 8ee3d7c9a53e6c2f81a9edbb783033faeff72c8ec305becae26ee4bfb63d870dbe9df33da92164ada450061d0922d046239a3835025c4fbf132b0e31c26f66e7
6
+ metadata.gz: 86f21b0d75af228b1a4f5ae2feb0eb00773ada2d1614ed77f959afa38a8438c797b7dfd29032f4ca5a5eafd103c6e852a4c25ad41bf23322d32d610dbb8a386f
7
+ data.tar.gz: 43daf46a7d5bf9355cb81ef4e20557439c8901d00afff12d0787f738447775a7ccac766940a8ae8e68fde103d54c7e13bd885278ff6ce2738986f99f28ece234
data/README.md CHANGED
@@ -2,25 +2,33 @@
2
2
 
3
3
  Hello, there is a fork of [neocities-ruby gem](https://github.com/neocities/neocities-ruby) with my own features and implementations. A much of my changes doesn't make sense to be pushed into original repository, so i pushed it here.
4
4
 
5
- ## Main changes/Features:
5
+ ### Currently, neocities-red tests and develop with ruby 3.4.* and supports 4.*
6
6
 
7
- ### Currently, this gems tests with ruby 3.4.*, it doesn't supports ruby 4 due of dependencies
7
+ ## List of improvements and changes:
8
8
 
9
- 1) Added MultiThread uploading of files to neocities. This feature boosts `neocities push`;
10
- 2) Moves from `http.rb` to `faraday` gem;
11
- 3) Fixed `-e` flag to exclude folders recursively;
12
- 4) Added `--ignore-dotfiles` to ignore all files-folders starts with '.';
13
- 5) Added `--optimized` for `neocities push` flag to upload only modified files;
14
- 6) Fixed bug with neocities info on modern rubies;
15
- 7) Re-designed `upload` method;
9
+ ### 0) Refactor all entire project, change dependencies for more flexibility.
10
+
11
+ Currently or implementing new features `neocities-red` is easier than original cli. Also i approaching the philosophy to use modern dependencies to ensure that `neocities-red` will supports newest versions of Ruby.
12
+
13
+ ### 1) upload
14
+
15
+ - Uploading is multi-threaded (Instead of uploading by 1 file linnear it uploads 3-5 files at once.)
16
+ - The logic is differs of original gem (please ensure that by typing the `neocities-red upload` command).
17
+ - Command also uploads folders recursively (It also upload the content that is inside of the target directory).
18
+
19
+ ### 2) push
20
+
21
+ Now, that command is great for users, which uses static site generators (like Jekyll, Hugo, e.t.c.).
22
+
23
+ - Uploading is multi-threaded (Instead of uploading by 1 file linnear it uploads 3-5 files at once.)
24
+ - `neocities push --optimized` command is uploads only files which differs of already uploaded.
25
+ - `neocities push --ignore-dotfiles .` is ignores all files with '.' at the beginning.
26
+ - `neocities push -e <folder>` is ignores folders recursively (Ignoring the content that is inside of the target directory).
16
27
 
17
28
  ## TODO'S:
18
- 1) Check all entire cli and client logic, fix bugs.
19
- 2) Change dependencies for modern analogs.
20
- 3) Refactor `cli.rb` or use `rails/thor` gem instead.
21
- 4) Add tests
22
- 5) Make sure that gem is compatible with Linux, Freebsd, Windows
23
- 6) Make it compatible with ruby 4.0.0
29
+ 1) Refactor `cli.rb` or use `rails/thor` gem instead.
30
+ 2) Add tests.
31
+ 3) Make sure that gem is compatible with Linux, Freebsd and Windows
24
32
 
25
33
  # The Neocities Gem
26
34
 
@@ -28,8 +36,14 @@ A CLI and library for using the Neocities API. Makes it easy to quickly upload,
28
36
 
29
37
  ## Installation
30
38
 
31
- ```
32
- gem install neocities-red
39
+ 1) Install Ruby Programming Language to your system.
40
+ - If you're not a programmer - just install version directly from https://www.ruby-lang.org/en/.
41
+ - If you're programmes, just use any of tools which supports programming language supports. I am prefer to use `asdf` of `mise`.
42
+
43
+ 2) Install gem just typing:
44
+
45
+ ```bash
46
+ gem install neocities-red
33
47
  ```
34
48
 
35
49
  ### Running
@@ -62,3 +76,9 @@ client.delete(path)
62
76
  client.push(path)
63
77
  client.list(path)
64
78
  ```
79
+
80
+ # Contributions ..?
81
+
82
+ I'm glad to see everyone, so for contribution you need to check issues and take one typing something like "i'd like to take this issue". After that you should to make fork of this repository, create new branch, complete the task and share with solution via pull request.
83
+
84
+ If there are no tasks, just ping me (o-200) for the new issue, and we will think together about what can be implemented or fixed.
data/bin/neocities-red CHANGED
@@ -1,6 +1,6 @@
1
1
  #!/usr/bin/env ruby
2
2
  # frozen_string_literal: true
3
3
 
4
- require File.join(File.dirname(__FILE__), '..', 'lib', 'neocities')
4
+ require './lib/neocities'
5
5
  cli = Neocities::CLI.new ARGV
6
6
  cli.run
data/lib/neocities/cli.rb CHANGED
@@ -10,7 +10,8 @@ require 'whirly'
10
10
  require 'digest'
11
11
  require 'time'
12
12
 
13
- # warning - the big quantity of working threads could be considered like-a DDOS. Your ip-address could get banned for a few days.
13
+ # warning - the big quantity of working threads could be considered like-a DDOS.
14
+ # Your ip-address could get banned for a few days.
14
15
  MAX_THREADS = 5
15
16
 
16
17
  module Neocities
@@ -116,7 +117,7 @@ module Neocities
116
117
  display_delete_help_and_exit if @subargs.empty?
117
118
 
118
119
  @subargs.each do |path|
119
- FileRemover.new(@client, path).remove
120
+ Services::FileRemover.new(@client, path).remove
120
121
  end
121
122
  end
122
123
 
@@ -145,7 +146,7 @@ module Neocities
145
146
  end
146
147
 
147
148
  def info
148
- profile_info = ProfileInfo.new(@client, @subargs, @sitename).pretty_print
149
+ profile_info = Services::ProfileInfo.new(@client, @subargs, @sitename).pretty_print
149
150
  puts TTY::Table.new(profile_info)
150
151
  rescue Exception => e
151
152
  display_response(e)
@@ -160,7 +161,7 @@ module Neocities
160
161
 
161
162
  path = @subargs[0]
162
163
 
163
- FileList.new(@client, path, @detail).show
164
+ Services::FileList.new(@client, path, @detail).show
164
165
  end
165
166
 
166
167
  def push
@@ -304,7 +305,7 @@ module Neocities
304
305
  end
305
306
  next if path.nil? || path.directory?
306
307
 
307
- Neocities::FileUploader.new(@client, path, path).upload
308
+ Services::FileUploader.new(@client, path, path).upload
308
309
  end
309
310
  end
310
311
  end
@@ -315,22 +316,12 @@ module Neocities
315
316
  end
316
317
 
317
318
  def upload
318
- display_upload_help_and_exit if @subargs.empty?
319
-
320
- loop do
321
- case @subargs[0]
322
- when /^-/
323
- puts @pastel.red.bold("Unknown option: #{@subargs[0].inspect}")
324
- display_upload_help_and_exit
325
- else
326
- break
327
- end
328
- end
319
+ display_upload_help_and_exit if @subargs[0].nil? || @subargs[1].nil?
329
320
 
330
321
  if File.file?(@subargs[0])
331
- FileUploader.new(@client, @subargs[0], @subargs[1]).upload
322
+ Services::FileUploader.new(@client, @subargs[0], @subargs[1]).upload
332
323
  elsif File.directory?(@subargs[0])
333
- FolderUploader.new(@client, @subargs[0], @subargs[1]).upload
324
+ Services::FolderUploader.new(@client, @subargs[0], @subargs[1]).upload
334
325
  end
335
326
  end
336
327
 
@@ -341,8 +332,8 @@ module Neocities
341
332
  last_pull_time = data['LAST_PULL']['time']
342
333
  last_pull_loc = data['LAST_PULL']['loc']
343
334
 
344
- SiteExporter.new(@client, @sitename, data, @app_config_path)
345
- .export(quiet, last_pull_time, last_pull_loc)
335
+ Services::SiteExporter.new(@client, @sitename, data, @app_config_path)
336
+ .export(quiet, last_pull_time, last_pull_loc)
346
337
  end
347
338
 
348
339
  # only for development purposes
@@ -367,7 +358,7 @@ module Neocities
367
358
  end
368
359
 
369
360
  def display_pizza_help_and_exit
370
- puts Pizza.new.make_order
361
+ puts Services::Pizza.new.make_order
371
362
  end
372
363
 
373
364
  def display_list_help_and_exit
@@ -414,7 +405,10 @@ HERE
414
405
 
415
406
  #{@pastel.dim 'Examples:'}
416
407
 
417
- #{@pastel.green '$ neocities upload /img.jpg /images/img2.jpg'} Upload img.jpg to /images folder and with img2.jpg name
408
+ #{@pastel.green '$ neocities upload ./img.jpg ./images/img2.jpg'} Upload img.jpg to /images folder and with img2.jpg name
409
+
410
+ #{@pastel.green '$ neocities upload images/ images/'} Upload images folder with their content to /images folder
411
+
418
412
  HERE
419
413
  exit
420
414
  end
@@ -447,7 +441,7 @@ HERE
447
441
 
448
442
  #{@pastel.green '$ neocities push --dry-run .'} Just show what would be uploaded
449
443
 
450
- #{@pastel.green '$ neocities push --optimized .'} Do not upload unchanged files.#{' '}
444
+ #{@pastel.green '$ neocities push --optimized .'} Do not upload unchanged files.#{' '}
451
445
 
452
446
  #{@pastel.green '$ neocities push --prune .'} Delete site files not in dir (be careful!)
453
447
 
@@ -3,7 +3,7 @@
3
3
  require 'pastel'
4
4
  require 'tty/table'
5
5
 
6
- module Neocities
6
+ module Neocities::Services
7
7
  class FileList
8
8
  def initialize(client, path, detail)
9
9
  @client = client
@@ -2,7 +2,7 @@
2
2
 
3
3
  require 'pastel'
4
4
 
5
- module Neocities
5
+ module Neocities::Services
6
6
  class FileRemover
7
7
  attr_accessor :client, :filepath
8
8
 
@@ -0,0 +1,43 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'pathname'
4
+ require 'pastel'
5
+
6
+ module Neocities
7
+ module Services
8
+ class FileIsNotExists < StandardError; end
9
+
10
+ class FileUploader
11
+ def initialize(client, filepath, remote_path = nil)
12
+ @client = client
13
+ @filepath = filepath
14
+ @remote_path = remote_path
15
+ @pastel = Pastel.new(eachline: "\n")
16
+ end
17
+
18
+ def upload
19
+ path = Pathname(@filepath)
20
+
21
+ raise FileIsNotExists, "#{path} does not exist locally." unless path.exist?
22
+
23
+ if path.directory?
24
+ puts @pastel.bold("#{path} is a directory, skipping")
25
+ return
26
+ end
27
+
28
+ puts @pastel.bold("Uploading #{path} to #{@remote_path} ...")
29
+
30
+ response = @client.upload(path, @remote_path)
31
+ puts response if response[:result] == 'error'
32
+
33
+ if response[:result] == 'error' && response[:error_type] == 'file_exists'
34
+ puts @pastel.yellow.bold('EXISTS')
35
+ elsif response[:result] == 'success'
36
+ puts @pastel.green.bold('SUCCESS')
37
+ end
38
+
39
+ response
40
+ end
41
+ end
42
+ end
43
+ end
@@ -0,0 +1,58 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'pathname'
4
+ require 'pastel'
5
+
6
+ module Neocities
7
+ module Services
8
+ class FileIsNotExists < StandardError; end
9
+
10
+ # warning - the big quantity of working threads could be considered like-a DDOS.
11
+ # Your ip-address could get banned for a few days.
12
+ MAX_THREADS = 5
13
+
14
+ class FolderUploader
15
+ def initialize(client, filepath, remote_path)
16
+ @client = client
17
+ @filepath = filepath
18
+ @remote_path = remote_path
19
+ @pastel = Pastel.new(eachline: "\n")
20
+ end
21
+
22
+ def upload
23
+ path = Pathname(@filepath)
24
+
25
+ raise FileIsNotExists, "#{path} does not exist locally." unless path.exist?
26
+
27
+ if path.file?
28
+ puts @pastel.bold("#{path} is not a directory, skipping")
29
+ return
30
+ end
31
+
32
+ Dir.chdir(path) do
33
+ files = Dir.glob('**/*', File::FNM_DOTMATCH).select { |f| File.file?(f) }
34
+
35
+ queue = Queue.new
36
+ files.each { |file| queue << file }
37
+
38
+ workers = Array.new(MAX_THREADS) do
39
+ Thread.new do
40
+ loop do
41
+ begin
42
+ file = queue.pop(true)
43
+ rescue ThreadError
44
+ break # queue is empty
45
+ end
46
+
47
+ remote_path = File.join(@remote_path, file)
48
+ FileUploader.new(@client, file, remote_path).upload
49
+ end
50
+ end
51
+ end
52
+
53
+ workers.each(&:join)
54
+ end
55
+ end
56
+ end
57
+ end
58
+ end
@@ -2,7 +2,7 @@
2
2
 
3
3
  require 'pastel'
4
4
 
5
- module Neocities
5
+ module Neocities::Services
6
6
  class Pizza
7
7
  EXCUSES = [
8
8
  "Sorry, we're fresh out of pineapple today.",
@@ -3,7 +3,7 @@
3
3
  require 'time'
4
4
  require 'pastel'
5
5
 
6
- module Neocities
6
+ module Neocities::Services
7
7
  class ClientError < StandardError; end
8
8
 
9
9
  class ProfileInfo
@@ -3,7 +3,7 @@
3
3
  require 'whirly'
4
4
  require 'pastel'
5
5
 
6
- module Neocities
6
+ module Neocities::Services
7
7
  class SiteExporter
8
8
  attr_accessor :client, :sitename, :data, :app_config_path
9
9
 
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Neocities
4
- VERSION = '1.0.1'
4
+ VERSION = '1.0.2'
5
5
  end
data/lib/neocities.rb CHANGED
@@ -3,10 +3,12 @@
3
3
  require File.join(File.dirname(__FILE__), 'neocities', 'version')
4
4
  require File.join(File.dirname(__FILE__), 'neocities', 'client')
5
5
  require File.join(File.dirname(__FILE__), 'neocities', 'cli')
6
- require File.join(File.dirname(__FILE__), 'neocities', 'profile_info')
7
- require File.join(File.dirname(__FILE__), 'neocities', 'file_uploader')
8
- require File.join(File.dirname(__FILE__), 'neocities', 'folder_uploader')
9
- require File.join(File.dirname(__FILE__), 'neocities', 'file_remover')
10
- require File.join(File.dirname(__FILE__), 'neocities', 'file_list')
11
- require File.join(File.dirname(__FILE__), 'neocities', 'site_exporter')
12
- require File.join(File.dirname(__FILE__), 'neocities', 'pizza')
6
+
7
+ require File.join(File.dirname(__FILE__), 'neocities', 'services', 'file_uploader')
8
+ require File.join(File.dirname(__FILE__), 'neocities', 'services', 'folder_uploader')
9
+ require File.join(File.dirname(__FILE__), 'neocities', 'services', 'file_remover')
10
+ require File.join(File.dirname(__FILE__), 'neocities', 'services', 'file_list')
11
+
12
+ require File.join(File.dirname(__FILE__), 'neocities', 'services', 'profile_info')
13
+ require File.join(File.dirname(__FILE__), 'neocities', 'services', 'site_exporter')
14
+ require File.join(File.dirname(__FILE__), 'neocities', 'services', 'pizza')
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: neocities-red
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.1
4
+ version: 1.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Kyle Drake
@@ -174,13 +174,13 @@ files:
174
174
  - lib/neocities.rb
175
175
  - lib/neocities/cli.rb
176
176
  - lib/neocities/client.rb
177
- - lib/neocities/file_list.rb
178
- - lib/neocities/file_remover.rb
179
- - lib/neocities/file_uploader.rb
180
- - lib/neocities/folder_uploader.rb
181
- - lib/neocities/pizza.rb
182
- - lib/neocities/profile_info.rb
183
- - lib/neocities/site_exporter.rb
177
+ - lib/neocities/services/file_list.rb
178
+ - lib/neocities/services/file_remover.rb
179
+ - lib/neocities/services/file_uploader.rb
180
+ - lib/neocities/services/folder_uploader.rb
181
+ - lib/neocities/services/pizza.rb
182
+ - lib/neocities/services/profile_info.rb
183
+ - lib/neocities/services/site_exporter.rb
184
184
  - lib/neocities/version.rb
185
185
  - neocities-red.gemspec
186
186
  homepage: https://github.com/o-200/neocities-red
@@ -201,7 +201,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
201
201
  - !ruby/object:Gem::Version
202
202
  version: '0'
203
203
  requirements: []
204
- rubygems_version: 4.0.1
204
+ rubygems_version: 4.0.3
205
205
  specification_version: 4
206
206
  summary: Yet Another Neocities.org CLI and API client with improvements
207
207
  test_files: []
@@ -1,41 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'pathname'
4
- require 'pastel'
5
-
6
- module Neocities
7
- class FileIsNotExists < StandardError; end
8
-
9
- class FileUploader
10
- def initialize(client, filepath, remote_path = nil)
11
- @client = client
12
- @filepath = filepath
13
- @remote_path = remote_path
14
- @pastel = Pastel.new(eachline: "\n")
15
- end
16
-
17
- def upload
18
- path = Pathname(@filepath)
19
-
20
- raise FileIsNotExists, "#{path} does not exist locally." unless path.exist?
21
-
22
- if path.directory?
23
- puts @pastel.bold("#{path} is a directory, skipping")
24
- return
25
- end
26
-
27
- puts @pastel.bold("Uploading #{path} to #{@remote_path} ...")
28
-
29
- response = @client.upload(path, @remote_path)
30
- puts response if response[:result] == 'error'
31
-
32
- if response[:result] == 'error' && response[:error_type] == 'file_exists'
33
- puts @pastel.yellow.bold('EXISTS')
34
- elsif response[:result] == 'success'
35
- puts @pastel.green.bold('SUCCESS')
36
- end
37
-
38
- response
39
- end
40
- end
41
- end
@@ -1,36 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'pathname'
4
- require 'pastel'
5
-
6
- module Neocities
7
- class FileIsNotExists < StandardError; end
8
-
9
- class FolderUploader
10
- def initialize(client, filepath, remote_path = nil)
11
- @client = client
12
- @filepath = filepath
13
- @remote_path = remote_path
14
- @pastel = Pastel.new(eachline: "\n")
15
- end
16
-
17
- def upload
18
- path = Pathname(@filepath)
19
-
20
- raise FileIsNotExists, "#{path} does not exist locally." unless path.exist?
21
-
22
- if path.file?
23
- puts @pastel.bold("#{path} is not a directory, skipping")
24
- return
25
- end
26
-
27
- Dir.chdir(path) do
28
- files = Dir.glob('**', File::FNM_DOTMATCH)[1..]
29
- files.each do |file|
30
- remote_path = File.join(@remote_path, file)
31
- FileUploader.new(@client, file, remote_path).upload
32
- end
33
- end
34
- end
35
- end
36
- end