neocities 0.2.0 → 0.3.0
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 +4 -4
- data/Gemfile +1 -0
- data/README.md +8 -0
- data/lib/neocities/cli.rb +70 -25
- data/lib/neocities/client.rb +4 -2
- data/lib/neocities/version.rb +1 -1
- data/neocities.gemspec +1 -0
- metadata +22 -2
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: c97aed183932a987e86e2fd59f8001620c800007f3365552642d8a43d8a24a6d
|
|
4
|
+
data.tar.gz: 2eeba231d12c9a8d87db79b7324141b3439c6b67d95b8257cba15fece01b3d1f
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 3362281d36af925b2580a1b9c7dbc2ed1fbdef24287f9315c66bc3a45096388695a19a540d3a981d43199e3f427e6a30d1765372e34776cc836829d6ac038654
|
|
7
|
+
data.tar.gz: a3a969acf5a81ca16d3ae59184a361088831ce5d666a7a70f17a7219dbaaedfb5a5ab6d5fc1365f7516ddbc24bd136b43d7311dbdfbd9e3ba5c5a00a1cc58a16
|
data/Gemfile
CHANGED
data/README.md
CHANGED
|
@@ -22,6 +22,14 @@ Install ruby with [RubyInstaller](https://rubyinstaller.org/). Then you can inst
|
|
|
22
22
|
|
|
23
23
|
After that, you are all set! Run `neocities` in a command line to see the options and get started.
|
|
24
24
|
|
|
25
|
+
### Authentication
|
|
26
|
+
|
|
27
|
+
The CLI uses an API key and never asks for your Neocities password. Create or copy a key from your site's [settings](https://neocities.org/settings), then paste it into the prompt the first time you run a command. The key is stored in your local Neocities config for later commands.
|
|
28
|
+
|
|
29
|
+
For CI or other automation, set `NEOCITIES_API_KEY` instead. Keys supplied through the environment are not saved locally.
|
|
30
|
+
|
|
31
|
+
Run `neocities logout -y` to remove a saved key from the computer. Regenerate the key in your site settings if you need to revoke it everywhere.
|
|
32
|
+
|
|
25
33
|
## Neocities::Client
|
|
26
34
|
|
|
27
35
|
This gem also ships with Neocities::Client, which you can use to write code that interfaces with the Neocities API.
|
data/lib/neocities/cli.rb
CHANGED
|
@@ -14,6 +14,7 @@ module Neocities
|
|
|
14
14
|
HELP_SUBCOMMANDS = ['-h', '--help', 'help']
|
|
15
15
|
PENELOPE_MOUTHS = %w{^ o ~ - v U}
|
|
16
16
|
PENELOPE_EYES = %w{o ~ O}
|
|
17
|
+
ALWAYS_EXCLUDED_PUSH_DIRECTORIES = %w{.git}.freeze
|
|
17
18
|
|
|
18
19
|
def initialize(argv)
|
|
19
20
|
@argv = argv.dup
|
|
@@ -40,6 +41,8 @@ module Neocities
|
|
|
40
41
|
end
|
|
41
42
|
|
|
42
43
|
def run
|
|
44
|
+
display_sign_in_status if @argv.empty?
|
|
45
|
+
|
|
43
46
|
if @argv[0] == 'version'
|
|
44
47
|
puts Neocities::VERSION
|
|
45
48
|
exit
|
|
@@ -53,13 +56,15 @@ module Neocities
|
|
|
53
56
|
send "display_#{@subcmd}_help_and_exit"
|
|
54
57
|
end
|
|
55
58
|
|
|
59
|
+
return logout if @subcmd == 'logout'
|
|
60
|
+
|
|
56
61
|
if !@api_key
|
|
57
62
|
begin
|
|
58
63
|
file = File.read @app_config_path
|
|
59
64
|
data = JSON.load file
|
|
60
65
|
|
|
61
66
|
if data
|
|
62
|
-
@api_key = data["API_KEY"]
|
|
67
|
+
@api_key = data["API_KEY"]&.strip # Remove any trailing whitespace causing HTTP requests to fail
|
|
63
68
|
@sitename = data["SITENAME"] # Store the sitename to be able to reference it later
|
|
64
69
|
@last_pull = data["LAST_PULL"] # Store the last time a pull was performed so that we only fetch from updated files
|
|
65
70
|
end
|
|
@@ -68,38 +73,45 @@ module Neocities
|
|
|
68
73
|
end
|
|
69
74
|
end
|
|
70
75
|
|
|
71
|
-
|
|
72
|
-
|
|
76
|
+
prompted_for_api_key = false
|
|
77
|
+
if @api_key.nil? || @api_key.empty?
|
|
78
|
+
puts 'Please enter your Neocities API key.'
|
|
79
|
+
puts 'Create or copy one from https://neocities.org/settings'
|
|
80
|
+
@api_key = @prompt.mask('API key:').to_s.strip
|
|
81
|
+
prompted_for_api_key = true
|
|
82
|
+
end
|
|
83
|
+
|
|
84
|
+
@client = build_client @api_key
|
|
73
85
|
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
86
|
+
if prompted_for_api_key || @sitename.nil?
|
|
87
|
+
resp = @client.info
|
|
88
|
+
if resp[:result] == 'error'
|
|
89
|
+
display_response resp
|
|
90
|
+
exit
|
|
77
91
|
end
|
|
78
92
|
|
|
79
|
-
@
|
|
93
|
+
@sitename = resp[:info][:sitename]
|
|
94
|
+
end
|
|
80
95
|
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
}
|
|
96
|
+
if prompted_for_api_key
|
|
97
|
+
conf = {
|
|
98
|
+
"API_KEY": @api_key,
|
|
99
|
+
"SITENAME": @sitename,
|
|
100
|
+
}
|
|
87
101
|
|
|
88
|
-
|
|
89
|
-
|
|
102
|
+
FileUtils.mkdir_p Pathname(@app_config_path).dirname
|
|
103
|
+
File.write @app_config_path, conf.to_json
|
|
90
104
|
|
|
91
|
-
|
|
92
|
-
else
|
|
93
|
-
display_response resp
|
|
94
|
-
exit
|
|
95
|
-
end
|
|
96
|
-
else
|
|
97
|
-
@client = Neocities::Client.new api_key: @api_key
|
|
105
|
+
puts "The API key for #{@pastel.bold @sitename} has been stored in #{@pastel.bold @app_config_path}."
|
|
98
106
|
end
|
|
99
107
|
|
|
100
108
|
send @subcmd
|
|
101
109
|
end
|
|
102
110
|
|
|
111
|
+
def build_client(api_key)
|
|
112
|
+
Neocities::Client.new api_key: api_key
|
|
113
|
+
end
|
|
114
|
+
|
|
103
115
|
def delete
|
|
104
116
|
display_delete_help_and_exit if @subargs.empty?
|
|
105
117
|
@subargs.each do |file|
|
|
@@ -120,8 +132,8 @@ module Neocities
|
|
|
120
132
|
end
|
|
121
133
|
end
|
|
122
134
|
if confirmed
|
|
123
|
-
FileUtils.
|
|
124
|
-
puts @pastel.bold("Your
|
|
135
|
+
FileUtils.rm_f @app_config_path
|
|
136
|
+
puts @pastel.bold("Your API key has been removed.")
|
|
125
137
|
else
|
|
126
138
|
display_logout_help_and_exit
|
|
127
139
|
end
|
|
@@ -245,6 +257,7 @@ module Neocities
|
|
|
245
257
|
|
|
246
258
|
Dir.chdir(root_path) do
|
|
247
259
|
paths = Dir.glob(File.join('**', '*'), File::FNM_DOTMATCH)
|
|
260
|
+
paths.reject! { |path| always_excluded_push_path?(path) }
|
|
248
261
|
|
|
249
262
|
if @no_gitignore == false
|
|
250
263
|
begin
|
|
@@ -559,6 +572,29 @@ HERE
|
|
|
559
572
|
HERE
|
|
560
573
|
end
|
|
561
574
|
|
|
575
|
+
def display_sign_in_status
|
|
576
|
+
config = {}
|
|
577
|
+
begin
|
|
578
|
+
config = JSON.parse File.read(@app_config_path)
|
|
579
|
+
rescue SystemCallError, JSON::ParserError
|
|
580
|
+
# Status should still be available without a readable config.
|
|
581
|
+
end
|
|
582
|
+
config = {} unless config.is_a?(Hash)
|
|
583
|
+
saved_key = config['API_KEY'].to_s.strip
|
|
584
|
+
environment_key = ENV['NEOCITIES_API_KEY']
|
|
585
|
+
|
|
586
|
+
status = if environment_key && environment_key != saved_key
|
|
587
|
+
environment_key.empty? ? 'Signed out' : 'Using NEOCITIES_API_KEY (username not loaded)'
|
|
588
|
+
elsif saved_key.empty?
|
|
589
|
+
'Signed out'
|
|
590
|
+
elsif config['SITENAME'].to_s.empty?
|
|
591
|
+
'API key saved (username not loaded)'
|
|
592
|
+
else
|
|
593
|
+
"Signed in as: #{config['SITENAME']}"
|
|
594
|
+
end
|
|
595
|
+
puts @pastel.cyan.bold(status)
|
|
596
|
+
end
|
|
597
|
+
|
|
562
598
|
def display_help_and_exit
|
|
563
599
|
display_banner
|
|
564
600
|
puts <<HERE
|
|
@@ -573,10 +609,19 @@ HERE
|
|
|
573
609
|
pull Get the most recent version of files from your site
|
|
574
610
|
pizza Order a free pizza
|
|
575
611
|
|
|
612
|
+
The first command asks for an API key from your site settings.
|
|
613
|
+
Set NEOCITIES_API_KEY to use a key without saving it locally.
|
|
614
|
+
|
|
576
615
|
HERE
|
|
577
616
|
exit
|
|
578
617
|
end
|
|
579
618
|
|
|
619
|
+
def always_excluded_push_path?(path)
|
|
620
|
+
Pathname.new(path).each_filename.any? do |filename|
|
|
621
|
+
ALWAYS_EXCLUDED_PUSH_DIRECTORIES.include?(filename)
|
|
622
|
+
end
|
|
623
|
+
end
|
|
624
|
+
|
|
580
625
|
def self.app_config_path(name)
|
|
581
626
|
platform = if RUBY_PLATFORM =~ /win32/
|
|
582
627
|
:win32
|
|
@@ -616,4 +661,4 @@ HERE
|
|
|
616
661
|
end
|
|
617
662
|
end
|
|
618
663
|
end
|
|
619
|
-
end
|
|
664
|
+
end
|
data/lib/neocities/client.rb
CHANGED
|
@@ -151,7 +151,9 @@ module Neocities
|
|
|
151
151
|
post 'delete', 'filenames[]' => paths
|
|
152
152
|
end
|
|
153
153
|
|
|
154
|
-
def info(sitename)
|
|
154
|
+
def info(sitename=nil)
|
|
155
|
+
return get 'info' if sitename.nil?
|
|
156
|
+
|
|
155
157
|
get 'info', sitename: sitename
|
|
156
158
|
end
|
|
157
159
|
|
|
@@ -168,4 +170,4 @@ module Neocities
|
|
|
168
170
|
JSON.parse resp.body, symbolize_names: true
|
|
169
171
|
end
|
|
170
172
|
end
|
|
171
|
-
end
|
|
173
|
+
end
|
data/lib/neocities/version.rb
CHANGED
data/neocities.gemspec
CHANGED
|
@@ -22,6 +22,7 @@ Gem::Specification.new do |spec|
|
|
|
22
22
|
spec.add_dependency 'tty-prompt', '~> 0.23', '= 0.23.1'
|
|
23
23
|
spec.add_dependency 'pastel', '~> 0.8', '= 0.8.0'
|
|
24
24
|
spec.add_dependency 'http', '~> 5.3', '>= 5.3.1'
|
|
25
|
+
spec.add_dependency 'http-cookie', '~> 1.0', '< 1.1.1'
|
|
25
26
|
spec.add_dependency 'rake', '~> 13', '>= 13.3.0'
|
|
26
27
|
spec.add_dependency 'whirly', '~> 0.3', '>= 0.3.0'
|
|
27
28
|
spec.add_dependency 'openssl', '~> 3.3', '>= 3.3.1'
|
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: neocities
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.
|
|
4
|
+
version: 0.3.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Kyle Drake
|
|
@@ -89,6 +89,26 @@ dependencies:
|
|
|
89
89
|
- - ">="
|
|
90
90
|
- !ruby/object:Gem::Version
|
|
91
91
|
version: 5.3.1
|
|
92
|
+
- !ruby/object:Gem::Dependency
|
|
93
|
+
name: http-cookie
|
|
94
|
+
requirement: !ruby/object:Gem::Requirement
|
|
95
|
+
requirements:
|
|
96
|
+
- - "~>"
|
|
97
|
+
- !ruby/object:Gem::Version
|
|
98
|
+
version: '1.0'
|
|
99
|
+
- - "<"
|
|
100
|
+
- !ruby/object:Gem::Version
|
|
101
|
+
version: 1.1.1
|
|
102
|
+
type: :runtime
|
|
103
|
+
prerelease: false
|
|
104
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
105
|
+
requirements:
|
|
106
|
+
- - "~>"
|
|
107
|
+
- !ruby/object:Gem::Version
|
|
108
|
+
version: '1.0'
|
|
109
|
+
- - "<"
|
|
110
|
+
- !ruby/object:Gem::Version
|
|
111
|
+
version: 1.1.1
|
|
92
112
|
- !ruby/object:Gem::Dependency
|
|
93
113
|
name: rake
|
|
94
114
|
requirement: !ruby/object:Gem::Requirement
|
|
@@ -185,7 +205,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
|
185
205
|
- !ruby/object:Gem::Version
|
|
186
206
|
version: '0'
|
|
187
207
|
requirements: []
|
|
188
|
-
rubygems_version:
|
|
208
|
+
rubygems_version: 4.0.3
|
|
189
209
|
specification_version: 4
|
|
190
210
|
summary: Neocities.org CLI and API client
|
|
191
211
|
test_files: []
|