fontist 1.8.13 → 1.9.3
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/.github/workflows/metanorma.yml +2 -2
- data/.github/workflows/rspec.yml +1 -1
- data/README.md +71 -7
- data/fontist.gemspec +1 -1
- data/lib/fontist.rb +25 -3
- data/lib/fontist/cli.rb +26 -4
- data/lib/fontist/errors.rb +20 -0
- data/lib/fontist/font.rb +2 -2
- data/lib/fontist/font_installer.rb +3 -2
- data/lib/fontist/formula.rb +2 -7
- data/lib/fontist/index.rb +28 -0
- data/lib/fontist/indexes/base_index.rb +8 -2
- data/lib/fontist/repo.rb +60 -0
- data/lib/fontist/repo_cli.rb +51 -0
- data/lib/fontist/update.rb +78 -0
- data/lib/fontist/utils/downloader.rb +15 -2
- data/lib/fontist/utils/locking.rb +1 -0
- data/lib/fontist/version.rb +1 -1
- metadata +10 -7
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: e2cce6f6f02c9c70f594e7b6084ac854a74b903f27b49252047e898d47137a1f
|
|
4
|
+
data.tar.gz: d9cb729ca432229c90bf2cb0da204cf0cc401f997e1cd915e853e240613e35ea
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 6a5f1250db7da8b327716fcb1a22abf71c2ab3c57f58b4954efc82b2273f7e880c3d8519693925b13d3c3adf81fb5f261a912b13d95e69f0711b5716bd349d53
|
|
7
|
+
data.tar.gz: 293524c79e1be4ebbc8ef6db50a7de91e195d5921abd9e8fd1791597bfd80616bfe4d8d82eada54e71fcbdfaeab1baf6d72659e334111cf460b84c0d5193be1a
|
|
@@ -2,7 +2,7 @@ name: metanorma
|
|
|
2
2
|
|
|
3
3
|
on:
|
|
4
4
|
push:
|
|
5
|
-
branches: [
|
|
5
|
+
branches: [ main, v1.9.x ]
|
|
6
6
|
pull_request:
|
|
7
7
|
|
|
8
8
|
jobs:
|
|
@@ -13,7 +13,7 @@ jobs:
|
|
|
13
13
|
strategy:
|
|
14
14
|
fail-fast: false
|
|
15
15
|
matrix:
|
|
16
|
-
ruby: [ '2.
|
|
16
|
+
ruby: [ '2.5', '2.6', '2.7', '3.0' ]
|
|
17
17
|
os: [ ubuntu-latest, windows-latest, macos-latest ]
|
|
18
18
|
experimental: [ true ]
|
|
19
19
|
steps:
|
data/.github/workflows/rspec.yml
CHANGED
data/README.md
CHANGED
|
@@ -399,6 +399,70 @@ bin/rspec
|
|
|
399
399
|
All formulas are kept in the [formulas][fontist-formulas] repository. If you'd
|
|
400
400
|
like to add a new one or change any existing, please refer to its documentation.
|
|
401
401
|
|
|
402
|
+
### Private repos
|
|
403
|
+
|
|
404
|
+
There is an ability to use private fonts via private fontist repo. Fontist repo
|
|
405
|
+
is a git repo which contains YAML formula files. Formulas can be created
|
|
406
|
+
manually (see [examples](https://github.com/fontist/formulas/tree/master/Formulas)),
|
|
407
|
+
or [auto-generated from an archive](#auto-generate-a-formula).
|
|
408
|
+
|
|
409
|
+
A repo can be either HTTPS or SSH Git repo. In case of SSH, a corresponding SSH key
|
|
410
|
+
should be setup with ssh-agent in order to access this private repo.
|
|
411
|
+
|
|
412
|
+
The `repo setup` command fetches a repo's formulas, and saves repo's name and url
|
|
413
|
+
for later use.
|
|
414
|
+
|
|
415
|
+
Internally all repos are stored at `~/.fontist/formulas/Formulas/private`.
|
|
416
|
+
|
|
417
|
+
```sh
|
|
418
|
+
fontist repo setup NAME URL
|
|
419
|
+
```
|
|
420
|
+
|
|
421
|
+
E.g.
|
|
422
|
+
|
|
423
|
+
```sh
|
|
424
|
+
fontist repo setup acme https://example.com/acme/formulas.git
|
|
425
|
+
# or
|
|
426
|
+
fontist repo setup acme git@example.com:acme/formulas.git
|
|
427
|
+
```
|
|
428
|
+
|
|
429
|
+
Then you can just install fonts from this repo:
|
|
430
|
+
|
|
431
|
+
```sh
|
|
432
|
+
fontist install "private font"
|
|
433
|
+
```
|
|
434
|
+
|
|
435
|
+
There is no need in any additional command to be run, but if you add new
|
|
436
|
+
formulas to your repo, you can fetch them with the `repo update` command:
|
|
437
|
+
|
|
438
|
+
```sh
|
|
439
|
+
fontist repo update acme
|
|
440
|
+
```
|
|
441
|
+
|
|
442
|
+
If there is a need to avoid using private formulas, the repo can be removed with:
|
|
443
|
+
|
|
444
|
+
```sh
|
|
445
|
+
fontist repo remove acme
|
|
446
|
+
```
|
|
447
|
+
|
|
448
|
+
### Private formulas
|
|
449
|
+
|
|
450
|
+
Authorization of private archives in private formulas can be implemented with
|
|
451
|
+
headers. Here is an example which works with Github releases:
|
|
452
|
+
|
|
453
|
+
```yaml
|
|
454
|
+
resources:
|
|
455
|
+
fonts.zip:
|
|
456
|
+
urls:
|
|
457
|
+
- url: https://example.com/repos/acme/formulas/releases/assets/38777461
|
|
458
|
+
headers:
|
|
459
|
+
Accept: application/octet-stream
|
|
460
|
+
Authorization: token ghp_1234567890abcdefghi
|
|
461
|
+
```
|
|
462
|
+
|
|
463
|
+
A token can be obtained on [this page](https://github.com/settings/tokens).
|
|
464
|
+
It should have at least the `repo` scope.
|
|
465
|
+
|
|
402
466
|
### Auto-generate a formula
|
|
403
467
|
|
|
404
468
|
A formula could be generated from a fonts archive. Just specify a URL to the
|
|
@@ -409,20 +473,21 @@ fontist create-formula https://www.latofonts.com/download/lato2ofl-zip/
|
|
|
409
473
|
cp lato.yml ~/.fontist/formulas/Formulas/
|
|
410
474
|
```
|
|
411
475
|
|
|
476
|
+
Though indexes are auto-generated now, maintainers should rebuild indexes
|
|
477
|
+
in the main repo for backward compatibility with fontist prior to 1.9.x versions.
|
|
412
478
|
A formula index should be rebuild, when a new formula is generated or an
|
|
413
479
|
existing one changed:
|
|
414
480
|
|
|
415
481
|
```sh
|
|
416
|
-
fontist rebuild-index
|
|
482
|
+
fontist rebuild-index --main-repo
|
|
417
483
|
```
|
|
418
484
|
|
|
419
|
-
Then, both the formula and the updated
|
|
485
|
+
Then, both the formula and the updated indexes should be commited and pushed to
|
|
420
486
|
the formula repository:
|
|
421
487
|
|
|
422
488
|
```sh
|
|
423
489
|
cd ~/.fontist/formulas
|
|
424
|
-
git add Formulas/lato.yml
|
|
425
|
-
git add index.yml
|
|
490
|
+
git add Formulas/lato.yml index.yml filename_index.yml
|
|
426
491
|
git commit -m "Add Lato formula"
|
|
427
492
|
```
|
|
428
493
|
|
|
@@ -441,7 +506,7 @@ repository [formulas][fontist-formulas]:
|
|
|
441
506
|
|
|
442
507
|
```
|
|
443
508
|
cd ~/.fontist/formulas
|
|
444
|
-
git add Formulas/google
|
|
509
|
+
git add Formulas/google index.yml filename_index.yml
|
|
445
510
|
git commit -m "Google Fonts update"
|
|
446
511
|
git push
|
|
447
512
|
```
|
|
@@ -454,8 +519,7 @@ can be updated with:
|
|
|
454
519
|
```sh
|
|
455
520
|
fontist import-sil
|
|
456
521
|
cd ~/.fontist/formulas
|
|
457
|
-
git add Formulas/sil
|
|
458
|
-
git add index.yml
|
|
522
|
+
git add Formulas/sil index.yml filename_index.yml
|
|
459
523
|
git commit -m "SIL fonts update"
|
|
460
524
|
git push
|
|
461
525
|
```
|
data/fontist.gemspec
CHANGED
|
@@ -40,7 +40,7 @@ Gem::Specification.new do |spec|
|
|
|
40
40
|
spec.add_development_dependency "nokogiri", "~> 1.0"
|
|
41
41
|
spec.add_development_dependency "rake", "~> 13"
|
|
42
42
|
spec.add_development_dependency "rspec", "~> 3.0"
|
|
43
|
-
spec.add_development_dependency "rubocop", "
|
|
43
|
+
spec.add_development_dependency "rubocop", "1.5.2"
|
|
44
44
|
spec.add_development_dependency "rubocop-rails"
|
|
45
45
|
spec.add_development_dependency "rubocop-performance"
|
|
46
46
|
spec.add_development_dependency "ruby-protocol-buffers", "~> 1.0"
|
data/lib/fontist.rb
CHANGED
|
@@ -7,6 +7,7 @@ require "singleton"
|
|
|
7
7
|
require "fontist/errors"
|
|
8
8
|
require "fontist/version"
|
|
9
9
|
|
|
10
|
+
require "fontist/repo"
|
|
10
11
|
require "fontist/font"
|
|
11
12
|
require "fontist/formula"
|
|
12
13
|
require "fontist/system_font"
|
|
@@ -28,7 +29,11 @@ module Fontist
|
|
|
28
29
|
end
|
|
29
30
|
|
|
30
31
|
def self.fontist_path
|
|
31
|
-
Pathname.new(ENV["FONTIST_PATH"] ||
|
|
32
|
+
Pathname.new(ENV["FONTIST_PATH"] || default_fontist_path)
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
def self.default_fontist_path
|
|
36
|
+
Pathname.new(File.join(Dir.home, ".fontist"))
|
|
32
37
|
end
|
|
33
38
|
|
|
34
39
|
def self.fonts_path
|
|
@@ -47,6 +52,10 @@ module Fontist
|
|
|
47
52
|
Fontist.formulas_repo_path.join("Formulas")
|
|
48
53
|
end
|
|
49
54
|
|
|
55
|
+
def self.private_formulas_path
|
|
56
|
+
Fontist.formulas_path.join("private")
|
|
57
|
+
end
|
|
58
|
+
|
|
50
59
|
def self.downloads_path
|
|
51
60
|
Fontist.fontist_path.join("downloads")
|
|
52
61
|
end
|
|
@@ -60,10 +69,23 @@ module Fontist
|
|
|
60
69
|
end
|
|
61
70
|
|
|
62
71
|
def self.formula_index_path
|
|
63
|
-
Fontist.
|
|
72
|
+
@formula_index_path || Fontist.formula_index_dir.join("formula_index.yml")
|
|
73
|
+
end
|
|
74
|
+
|
|
75
|
+
def self.formula_index_path=(path)
|
|
76
|
+
@formula_index_path = path
|
|
64
77
|
end
|
|
65
78
|
|
|
66
79
|
def self.formula_filename_index_path
|
|
67
|
-
|
|
80
|
+
@formula_filename_index_path ||
|
|
81
|
+
Fontist.formula_index_dir.join("filename_index.yml")
|
|
82
|
+
end
|
|
83
|
+
|
|
84
|
+
def self.formula_filename_index_path=(path)
|
|
85
|
+
@formula_filename_index_path = path
|
|
86
|
+
end
|
|
87
|
+
|
|
88
|
+
def self.formula_index_dir
|
|
89
|
+
Fontist.fontist_path
|
|
68
90
|
end
|
|
69
91
|
end
|
data/lib/fontist/cli.rb
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
require "thor"
|
|
2
|
+
require "fontist/repo_cli"
|
|
2
3
|
|
|
3
4
|
module Fontist
|
|
4
5
|
class CLI < Thor
|
|
@@ -10,6 +11,9 @@ module Fontist
|
|
|
10
11
|
STATUS_MANIFEST_COULD_NOT_BE_FOUND_ERROR = 5
|
|
11
12
|
STATUS_MANIFEST_COULD_NOT_BE_READ_ERROR = 6
|
|
12
13
|
STATUS_FONT_INDEX_CORRUPTED = 7
|
|
14
|
+
STATUS_REPO_NOT_FOUND = 8
|
|
15
|
+
STATUS_MAIN_REPO_NOT_FOUND = 9
|
|
16
|
+
STATUS_REPO_COULD_NOT_BE_UPDATED = 10
|
|
13
17
|
|
|
14
18
|
ERROR_TO_STATUS = {
|
|
15
19
|
Fontist::Errors::UnsupportedFontError => [STATUS_NON_SUPPORTED_FONT_ERROR],
|
|
@@ -20,6 +24,8 @@ module Fontist
|
|
|
20
24
|
Fontist::Errors::ManifestCouldNotBeReadError => [STATUS_MANIFEST_COULD_NOT_BE_READ_ERROR,
|
|
21
25
|
"Manifest could not be read."],
|
|
22
26
|
Fontist::Errors::FontIndexCorrupted => [STATUS_FONT_INDEX_CORRUPTED],
|
|
27
|
+
Fontist::Errors::RepoNotFoundError => [STATUS_REPO_NOT_FOUND],
|
|
28
|
+
Fontist::Errors::MainRepoNotFoundError => [STATUS_MAIN_REPO_NOT_FOUND],
|
|
23
29
|
}.freeze
|
|
24
30
|
|
|
25
31
|
def self.exit_on_failure?
|
|
@@ -78,8 +84,11 @@ module Fontist
|
|
|
78
84
|
desc "update", "Update formulas"
|
|
79
85
|
def update
|
|
80
86
|
Formula.update_formulas_repo
|
|
81
|
-
Fontist.ui.
|
|
87
|
+
Fontist.ui.success("Formulas have been successfully updated.")
|
|
82
88
|
success
|
|
89
|
+
rescue Fontist::Errors::RepoCouldNotBeUpdatedError => e
|
|
90
|
+
Fontist.ui.error(e.message)
|
|
91
|
+
STATUS_REPO_COULD_NOT_BE_UPDATED
|
|
83
92
|
end
|
|
84
93
|
|
|
85
94
|
desc "manifest-locations MANIFEST",
|
|
@@ -123,11 +132,21 @@ module Fontist
|
|
|
123
132
|
|
|
124
133
|
desc "rebuild-index", "Rebuild formula index (used by formulas maintainers)"
|
|
125
134
|
long_desc <<-LONGDESC
|
|
126
|
-
|
|
127
|
-
|
|
135
|
+
Index should be rebuilt when any formula changes.
|
|
136
|
+
|
|
137
|
+
It is done automatically when formulas are updated, or private formulas
|
|
138
|
+
are set up.
|
|
128
139
|
LONGDESC
|
|
140
|
+
option :main_repo, type: :boolean,
|
|
141
|
+
desc: "Updates indexes in the main repo (for backward " \
|
|
142
|
+
"compatibility with versions prior to 1.9)"
|
|
129
143
|
def rebuild_index
|
|
130
|
-
|
|
144
|
+
if options[:main_repo]
|
|
145
|
+
Fontist::Index.rebuild_for_main_repo
|
|
146
|
+
else
|
|
147
|
+
Fontist::Index.rebuild
|
|
148
|
+
end
|
|
149
|
+
|
|
131
150
|
Fontist.ui.say("Formula index has been rebuilt.")
|
|
132
151
|
STATUS_SUCCESS
|
|
133
152
|
end
|
|
@@ -138,6 +157,9 @@ module Fontist
|
|
|
138
157
|
Fontist::Import::SilImport.new.call
|
|
139
158
|
end
|
|
140
159
|
|
|
160
|
+
desc "repo SUBCOMMAND ...ARGS", "Manage custom repositories"
|
|
161
|
+
subcommand "repo", Fontist::RepoCLI
|
|
162
|
+
|
|
141
163
|
private
|
|
142
164
|
|
|
143
165
|
def success
|
data/lib/fontist/errors.rb
CHANGED
|
@@ -3,17 +3,37 @@ module Fontist
|
|
|
3
3
|
class GeneralError < StandardError; end
|
|
4
4
|
|
|
5
5
|
class BinaryCallError < GeneralError; end
|
|
6
|
+
|
|
6
7
|
class FontIndexCorrupted < GeneralError; end
|
|
8
|
+
|
|
7
9
|
class FontNotFoundError < GeneralError; end
|
|
10
|
+
|
|
11
|
+
# for backward compatibility with metanorma,
|
|
12
|
+
# it depends on this exception to automatically download formulas
|
|
8
13
|
class FormulaIndexNotFoundError < GeneralError; end
|
|
14
|
+
|
|
15
|
+
class MainRepoNotFoundError < FormulaIndexNotFoundError; end
|
|
16
|
+
|
|
9
17
|
class InvalidResourceError < GeneralError; end
|
|
18
|
+
|
|
10
19
|
class LicensingError < GeneralError; end
|
|
20
|
+
|
|
11
21
|
class ManifestCouldNotBeFoundError < GeneralError; end
|
|
22
|
+
|
|
12
23
|
class ManifestCouldNotBeReadError < GeneralError; end
|
|
24
|
+
|
|
13
25
|
class MissingAttributeError < GeneralError; end
|
|
26
|
+
|
|
27
|
+
class RepoNotFoundError < GeneralError; end
|
|
28
|
+
|
|
29
|
+
class RepoCouldNotBeUpdatedError < GeneralError; end
|
|
30
|
+
|
|
14
31
|
class TamperedFileError < GeneralError; end
|
|
32
|
+
|
|
15
33
|
class TimeoutError < GeneralError; end
|
|
34
|
+
|
|
16
35
|
class UnknownFontTypeError < GeneralError; end
|
|
36
|
+
|
|
17
37
|
class UnknownArchiveError < GeneralError; end
|
|
18
38
|
|
|
19
39
|
class FontError < GeneralError
|
data/lib/fontist/font.rb
CHANGED
|
@@ -54,11 +54,12 @@ module Fontist
|
|
|
54
54
|
end
|
|
55
55
|
|
|
56
56
|
def download_file(source)
|
|
57
|
-
|
|
57
|
+
request = source.urls.first
|
|
58
|
+
url = request.respond_to?(:url) ? request.url : request
|
|
58
59
|
Fontist.ui.say(%(Downloading font "#{@formula.key}" from #{url}))
|
|
59
60
|
|
|
60
61
|
Fontist::Utils::Downloader.download(
|
|
61
|
-
|
|
62
|
+
request,
|
|
62
63
|
sha: source.sha256,
|
|
63
64
|
file_size: source.file_size,
|
|
64
65
|
progress_bar: !@no_progress
|
data/lib/fontist/formula.rb
CHANGED
|
@@ -1,17 +1,12 @@
|
|
|
1
1
|
require "fontist/index"
|
|
2
2
|
require "fontist/helpers"
|
|
3
|
+
require "fontist/update"
|
|
3
4
|
require "git"
|
|
4
5
|
|
|
5
6
|
module Fontist
|
|
6
7
|
class Formula
|
|
7
8
|
def self.update_formulas_repo
|
|
8
|
-
|
|
9
|
-
Git.open(Fontist.formulas_repo_path).pull
|
|
10
|
-
else
|
|
11
|
-
Git.clone(Fontist.formulas_repo_url,
|
|
12
|
-
Fontist.formulas_repo_path,
|
|
13
|
-
depth: 1)
|
|
14
|
-
end
|
|
9
|
+
Update.call
|
|
15
10
|
end
|
|
16
11
|
|
|
17
12
|
def self.all
|
data/lib/fontist/index.rb
CHANGED
|
@@ -3,9 +3,37 @@ require_relative "indexes/filename_index"
|
|
|
3
3
|
|
|
4
4
|
module Fontist
|
|
5
5
|
class Index
|
|
6
|
+
def self.rebuild_for_main_repo
|
|
7
|
+
unless Dir.exist?(Fontist.private_formulas_path)
|
|
8
|
+
return do_rebuild_for_main_repo_with
|
|
9
|
+
end
|
|
10
|
+
|
|
11
|
+
Dir.mktmpdir do |dir|
|
|
12
|
+
tmp_private_path = File.join(dir, "private")
|
|
13
|
+
FileUtils.mv(Fontist.private_formulas_path, tmp_private_path)
|
|
14
|
+
|
|
15
|
+
do_rebuild_for_main_repo_with
|
|
16
|
+
|
|
17
|
+
FileUtils.mv(tmp_private_path, Fontist.private_formulas_path)
|
|
18
|
+
end
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
def self.do_rebuild_for_main_repo_with
|
|
22
|
+
Fontist.formula_index_path = Fontist.formulas_repo_path.join("index.yml")
|
|
23
|
+
Fontist.formula_filename_index_path =
|
|
24
|
+
Fontist.formulas_repo_path.join("filename_index.yml")
|
|
25
|
+
|
|
26
|
+
rebuild
|
|
27
|
+
|
|
28
|
+
Fontist.formula_index_path = nil
|
|
29
|
+
Fontist.formula_filename_index_path = nil
|
|
30
|
+
end
|
|
31
|
+
|
|
6
32
|
def self.rebuild
|
|
7
33
|
Fontist::Indexes::FontIndex.rebuild
|
|
8
34
|
Fontist::Indexes::FilenameIndex.rebuild
|
|
35
|
+
|
|
36
|
+
reset_cache
|
|
9
37
|
end
|
|
10
38
|
|
|
11
39
|
def self.reset_cache
|
|
@@ -5,10 +5,14 @@ module Fontist
|
|
|
5
5
|
class BaseIndex
|
|
6
6
|
def self.from_yaml
|
|
7
7
|
@from_yaml ||= begin
|
|
8
|
-
unless
|
|
9
|
-
raise Errors::
|
|
8
|
+
unless Dir.exist?(Fontist.formulas_repo_path)
|
|
9
|
+
raise Errors::MainRepoNotFoundError.new(
|
|
10
|
+
"Please fetch formulas with `fontist update`.",
|
|
11
|
+
)
|
|
10
12
|
end
|
|
11
13
|
|
|
14
|
+
rebuild unless File.exist?(path)
|
|
15
|
+
|
|
12
16
|
data = YAML.load_file(path)
|
|
13
17
|
new(data)
|
|
14
18
|
end
|
|
@@ -63,6 +67,8 @@ module Fontist
|
|
|
63
67
|
end
|
|
64
68
|
|
|
65
69
|
def to_yaml
|
|
70
|
+
dir = File.dirname(self.class.path)
|
|
71
|
+
FileUtils.mkdir_p(dir) unless File.exist?(dir)
|
|
66
72
|
File.write(self.class.path, YAML.dump(to_h))
|
|
67
73
|
end
|
|
68
74
|
|
data/lib/fontist/repo.rb
ADDED
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
require "git"
|
|
2
|
+
|
|
3
|
+
module Fontist
|
|
4
|
+
class Repo
|
|
5
|
+
class << self
|
|
6
|
+
def setup(name, url)
|
|
7
|
+
ensure_private_formulas_path_exists
|
|
8
|
+
fetch_repo(name, url)
|
|
9
|
+
Index.rebuild
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
def update(name)
|
|
13
|
+
path = repo_path(name)
|
|
14
|
+
unless Dir.exist?(path)
|
|
15
|
+
raise(Errors::RepoNotFoundError, "No such repo '#{name}'.")
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
Git.open(path).pull
|
|
19
|
+
Index.rebuild
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
def remove(name)
|
|
23
|
+
path = repo_path(name)
|
|
24
|
+
unless Dir.exist?(path)
|
|
25
|
+
raise(Errors::RepoNotFoundError, "No such repo '#{name}'.")
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
FileUtils.rm_r(path)
|
|
29
|
+
Index.rebuild
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
def list
|
|
33
|
+
Dir.glob(Fontist.private_formulas_path.join("*"))
|
|
34
|
+
.select { |path| File.directory?(path) }
|
|
35
|
+
.map { |path| File.basename(path) }
|
|
36
|
+
end
|
|
37
|
+
|
|
38
|
+
private
|
|
39
|
+
|
|
40
|
+
def ensure_private_formulas_path_exists
|
|
41
|
+
Fontist.private_formulas_path.tap do |path|
|
|
42
|
+
FileUtils.mkdir_p(path) unless Dir.exist?(path)
|
|
43
|
+
end
|
|
44
|
+
end
|
|
45
|
+
|
|
46
|
+
def fetch_repo(name, url)
|
|
47
|
+
path = repo_path(name)
|
|
48
|
+
if Dir.exist?(path)
|
|
49
|
+
Git.open(path).pull
|
|
50
|
+
else
|
|
51
|
+
Git.clone(url, path, depth: 1)
|
|
52
|
+
end
|
|
53
|
+
end
|
|
54
|
+
|
|
55
|
+
def repo_path(name)
|
|
56
|
+
Fontist.private_formulas_path.join(name)
|
|
57
|
+
end
|
|
58
|
+
end
|
|
59
|
+
end
|
|
60
|
+
end
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
module Fontist
|
|
2
|
+
class RepoCLI < Thor
|
|
3
|
+
desc "setup NAME URL",
|
|
4
|
+
"Setup a custom fontist repo named NAME for the repository at URL " \
|
|
5
|
+
"and fetches its formulas"
|
|
6
|
+
def setup(name, url)
|
|
7
|
+
Repo.setup(name, url)
|
|
8
|
+
Fontist.ui.success(
|
|
9
|
+
"Fontist repo '#{name}' from '#{url}' has been successfully set up.",
|
|
10
|
+
)
|
|
11
|
+
CLI::STATUS_SUCCESS
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
desc "update NAME", "Update formulas in a fontist repo named NAME"
|
|
15
|
+
def update(name)
|
|
16
|
+
Repo.update(name)
|
|
17
|
+
Fontist.ui.success(
|
|
18
|
+
"Fontist repo '#{name}' has been successfully updated.",
|
|
19
|
+
)
|
|
20
|
+
CLI::STATUS_SUCCESS
|
|
21
|
+
rescue Errors::RepoNotFoundError
|
|
22
|
+
handle_repo_not_found(name)
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
desc "remove NAME", "Remove fontist repo named NAME"
|
|
26
|
+
def remove(name)
|
|
27
|
+
Repo.remove(name)
|
|
28
|
+
Fontist.ui.success(
|
|
29
|
+
"Fontist repo '#{name}' has been successfully removed.",
|
|
30
|
+
)
|
|
31
|
+
CLI::STATUS_SUCCESS
|
|
32
|
+
rescue Errors::RepoNotFoundError
|
|
33
|
+
handle_repo_not_found(name)
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
desc "list", "List fontist repos"
|
|
37
|
+
def list
|
|
38
|
+
Repo.list.each do |name|
|
|
39
|
+
Fontist.ui.say(name)
|
|
40
|
+
end
|
|
41
|
+
CLI::STATUS_SUCCESS
|
|
42
|
+
end
|
|
43
|
+
|
|
44
|
+
private
|
|
45
|
+
|
|
46
|
+
def handle_repo_not_found(name)
|
|
47
|
+
Fontist.ui.error("Fontist repo '#{name}' is not found.")
|
|
48
|
+
CLI::STATUS_REPO_NOT_FOUND
|
|
49
|
+
end
|
|
50
|
+
end
|
|
51
|
+
end
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
module Fontist
|
|
2
|
+
class Update
|
|
3
|
+
BRANCH = "master".freeze
|
|
4
|
+
|
|
5
|
+
def self.call
|
|
6
|
+
new(BRANCH).call
|
|
7
|
+
end
|
|
8
|
+
|
|
9
|
+
def initialize(branch = "main")
|
|
10
|
+
@branch = branch
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
def call
|
|
14
|
+
update_main_repo
|
|
15
|
+
update_private_repos
|
|
16
|
+
ensure
|
|
17
|
+
rebuild_index
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
private
|
|
21
|
+
|
|
22
|
+
def update_main_repo
|
|
23
|
+
dir = File.dirname(Fontist.formulas_repo_path)
|
|
24
|
+
FileUtils.mkdir_p(dir) unless File.exist?(dir)
|
|
25
|
+
|
|
26
|
+
unless Dir.exist?(Fontist.formulas_repo_path)
|
|
27
|
+
return Git.clone(Fontist.formulas_repo_url,
|
|
28
|
+
Fontist.formulas_repo_path,
|
|
29
|
+
branch: @branch,
|
|
30
|
+
depth: 1)
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
git = Git.open(Fontist.formulas_repo_path)
|
|
34
|
+
return git.pull("origin", @branch) if git.current_branch == @branch
|
|
35
|
+
|
|
36
|
+
git.config("remote.origin.fetch",
|
|
37
|
+
"+refs/heads/#{@branch}:refs/remotes/origin/#{@branch}")
|
|
38
|
+
git.fetch
|
|
39
|
+
git.checkout(@branch)
|
|
40
|
+
git.pull("origin", @branch)
|
|
41
|
+
end
|
|
42
|
+
|
|
43
|
+
def update_private_repos
|
|
44
|
+
private_repos.each do |path|
|
|
45
|
+
update_repo(path)
|
|
46
|
+
end
|
|
47
|
+
end
|
|
48
|
+
|
|
49
|
+
def update_repo(path)
|
|
50
|
+
Git.open(path).pull
|
|
51
|
+
rescue Git::GitExecuteError => e
|
|
52
|
+
name = repo_name(path)
|
|
53
|
+
raise Errors::RepoCouldNotBeUpdatedError.new(<<~MSG.chomp)
|
|
54
|
+
Formulas repo '#{name}' could not be updated.
|
|
55
|
+
Please consider reinitializing it with:
|
|
56
|
+
fontist remove #{name}
|
|
57
|
+
fontist setup #{name} REPO_URL
|
|
58
|
+
|
|
59
|
+
Git error:
|
|
60
|
+
#{e.message}
|
|
61
|
+
MSG
|
|
62
|
+
end
|
|
63
|
+
|
|
64
|
+
def private_repos
|
|
65
|
+
Dir.glob(Fontist.private_formulas_path.join("*")).select do |path|
|
|
66
|
+
File.directory?(path)
|
|
67
|
+
end
|
|
68
|
+
end
|
|
69
|
+
|
|
70
|
+
def repo_name(path)
|
|
71
|
+
File.basename(path)
|
|
72
|
+
end
|
|
73
|
+
|
|
74
|
+
def rebuild_index
|
|
75
|
+
Index.rebuild
|
|
76
|
+
end
|
|
77
|
+
end
|
|
78
|
+
end
|
|
@@ -20,7 +20,7 @@ module Fontist
|
|
|
20
20
|
end
|
|
21
21
|
|
|
22
22
|
def download
|
|
23
|
-
file = @cache.fetch(
|
|
23
|
+
file = @cache.fetch(url) do
|
|
24
24
|
download_file
|
|
25
25
|
end
|
|
26
26
|
|
|
@@ -56,9 +56,11 @@ module Fontist
|
|
|
56
56
|
|
|
57
57
|
def download_file
|
|
58
58
|
file = Down.download(
|
|
59
|
-
|
|
59
|
+
url,
|
|
60
60
|
open_timeout: 10,
|
|
61
61
|
read_timeout: 10,
|
|
62
|
+
max_redirects: 10,
|
|
63
|
+
headers: headers,
|
|
62
64
|
content_length_proc: ->(content_length) {
|
|
63
65
|
@progress_bar.total = content_length if content_length
|
|
64
66
|
},
|
|
@@ -73,6 +75,17 @@ module Fontist
|
|
|
73
75
|
rescue Down::NotFound
|
|
74
76
|
raise(Fontist::Errors::InvalidResourceError.new("Invalid URL: #{@file}"))
|
|
75
77
|
end
|
|
78
|
+
|
|
79
|
+
def url
|
|
80
|
+
@file.respond_to?(:url) ? @file.url : @file
|
|
81
|
+
end
|
|
82
|
+
|
|
83
|
+
def headers
|
|
84
|
+
@file.respond_to?(:headers) &&
|
|
85
|
+
@file.headers &&
|
|
86
|
+
@file.headers.to_h.map { |k, v| [k.to_s, v] }.to_h || # rubocop:disable Style/HashTransformKeys, Metrics/LineLength
|
|
87
|
+
{}
|
|
88
|
+
end
|
|
76
89
|
end
|
|
77
90
|
|
|
78
91
|
class ProgressBar
|
data/lib/fontist/version.rb
CHANGED
metadata
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: fontist
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 1.
|
|
4
|
+
version: 1.9.3
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Ribose Inc.
|
|
8
|
-
autorequire:
|
|
8
|
+
autorequire:
|
|
9
9
|
bindir: exe
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date: 2021-
|
|
11
|
+
date: 2021-08-06 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: down
|
|
@@ -184,14 +184,14 @@ dependencies:
|
|
|
184
184
|
requirements:
|
|
185
185
|
- - '='
|
|
186
186
|
- !ruby/object:Gem::Version
|
|
187
|
-
version:
|
|
187
|
+
version: 1.5.2
|
|
188
188
|
type: :development
|
|
189
189
|
prerelease: false
|
|
190
190
|
version_requirements: !ruby/object:Gem::Requirement
|
|
191
191
|
requirements:
|
|
192
192
|
- - '='
|
|
193
193
|
- !ruby/object:Gem::Version
|
|
194
|
-
version:
|
|
194
|
+
version: 1.5.2
|
|
195
195
|
- !ruby/object:Gem::Dependency
|
|
196
196
|
name: rubocop-rails
|
|
197
197
|
requirement: !ruby/object:Gem::Requirement
|
|
@@ -302,9 +302,12 @@ files:
|
|
|
302
302
|
- lib/fontist/manifest.rb
|
|
303
303
|
- lib/fontist/manifest/install.rb
|
|
304
304
|
- lib/fontist/manifest/locations.rb
|
|
305
|
+
- lib/fontist/repo.rb
|
|
306
|
+
- lib/fontist/repo_cli.rb
|
|
305
307
|
- lib/fontist/system.yml
|
|
306
308
|
- lib/fontist/system_font.rb
|
|
307
309
|
- lib/fontist/system_index.rb
|
|
310
|
+
- lib/fontist/update.rb
|
|
308
311
|
- lib/fontist/utils.rb
|
|
309
312
|
- lib/fontist/utils/cache.rb
|
|
310
313
|
- lib/fontist/utils/downloader.rb
|
|
@@ -337,8 +340,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
|
337
340
|
- !ruby/object:Gem::Version
|
|
338
341
|
version: '0'
|
|
339
342
|
requirements: []
|
|
340
|
-
rubygems_version: 3.0.3
|
|
341
|
-
signing_key:
|
|
343
|
+
rubygems_version: 3.0.3.1
|
|
344
|
+
signing_key:
|
|
342
345
|
specification_version: 4
|
|
343
346
|
summary: Install openly-licensed fonts on Windows, Linux and Mac!
|
|
344
347
|
test_files: []
|