bibi-cli 0.1.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.
@@ -0,0 +1,4 @@
1
+ === 0.1.0 / 2020-07-29
2
+
3
+ * Initial release:
4
+
data/Gemfile ADDED
@@ -0,0 +1,7 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gemspec
4
+
5
+ group :development do
6
+ gem 'kramdown'
7
+ end
@@ -0,0 +1,154 @@
1
+ = Bibi CLI
2
+
3
+ = {doctitle}
4
+
5
+ * link:https://rubygems.org/gems/bibi-cli[Homepage]
6
+ * link:http://rubydoc.info/gems/bibi-cli[Documentation]
7
+ * mailto:KitaitiMakoto-at-gmail.com[Email]
8
+
9
+ == Description
10
+
11
+ Bibi CLI is a command-line tools to work with https://github.com/satorumurmur/bibi[Bibi], an EPUB reader application. Currently, it provides only `bibi publish` command.
12
+
13
+ bibi publish a command line tool that uploads EPUB files to S3 and make them readable via web using Bibi.
14
+
15
+ == Features
16
+
17
+ * Uploads files in EPUB document to Bibi's bookshelf directory on Amazon S3
18
+ * Generates HTML file to show given EPUB and uploads to S3
19
+
20
+ == Examples
21
+
22
+ % bibi publish moby-dick.epub
23
+ % bibi publish moby-dick.epub moby-dick-book
24
+ % bibi publish --bibi=s3://yourbucket/subdir/bibi moby-dick.epub moby-dick-book
25
+
26
+ == Requirements
27
+
28
+ * AWS account
29
+ * Environment that is able to upload files to S3 bucket
30
+ * S3 bucket which you can access and is configuread for a static website hosting
31
+ * AWS CLI and configuration
32
+
33
+ == Install
34
+
35
+ % gem install bibi-publish
36
+
37
+ == Synopsis
38
+
39
+ === Dry run
40
+
41
+ bibi publish supports `--dry-run` option that shows file to upload but doesn't do it actually.
42
+
43
+ % bibi publish --bibi=s3://yourbucket/subdir/bibi path/to/moby-dick.epub moby-dick-book --dry-run
44
+
45
+ === Uploading to given bucket and path
46
+
47
+ % bibi publish --bibi=s3://yourbucket/subdir/bibi path/to/moby-dick.epub
48
+
49
+ does:
50
+
51
+ * upload files in EPUB file `moby-dick.epub` to `s3://yourbucket/subdir/bibi-bookshelf/moby-dick`
52
+ * upload a HTML file to read the EPUB document using Bibi to `s3://yourbucket/subdir/bibi/moby-dick.html`
53
+
54
+ Note that:
55
+
56
+ * bookshelf directory `bibi-bookshelf` is automatically determined by bibi publish
57
+ * bookshelf subdirectory name `moby-dick` is automatically determined by bibi publish according to the basename of given EPUB file `moby-dick.epub`
58
+
59
+ === Specifying directory name under Bibi bookshelf
60
+
61
+ % bibi publish --bibi=s3://yourbucket/subdir/bibi path/to/moby-dick.epub moby-dick-book
62
+
63
+ The second argument `page-blanch-book` is used for subdirectory and HTML file name on S3, which means it uses:
64
+
65
+ * `s3://yourbucket/subdir/bibi-bookshelf/moby-dick-book` instead of `s3://yourbucket/subdir/bibi-bookshelf/moby-dick`
66
+ * `s3://yourbucket/subdir/bibi/moby-dick-book.html` instead of `s3://yourbucket/subdir/bibi/moby-dick.html`
67
+
68
+ === Not generating HTML file
69
+
70
+ % bibi publish --bibi=s3://yourbucket/subdir/bibi --no-page path/to/moby-dick.epub moby-dick-book
71
+
72
+ Pass `--no-page` option to the command.
73
+
74
+ Note that you can read EPUB by visiting Bibi's usual URI `\https://s3.your-region.amazonaws.com/yourbucket/subdir/bibi/?book=moby-dick-book`.
75
+
76
+ === Inserting arbitrary fragments to generated HTML
77
+
78
+ bibi publish inserts HTML fragments from given files to at the end of `<head>` and `<body>` by `--head-end` and `--body-end` options respectively.
79
+
80
+ Assume we want to insert generator name in head element of Bibi HTML:
81
+
82
+ % cat ./generator.html
83
+ <meta name="generator" content="bibi publish">
84
+
85
+ Specify path to the the file by `--head-end` option:
86
+
87
+ % bibi publish --bibi=s3://yourbucket/subdir/bibi --head-end=./generator.html path/to/moby-dick.epub
88
+
89
+ Now the HTML fragment is inserted into HTML file:
90
+
91
+ ----
92
+ % curl -s https://s3.your-region.amazonaws.com/yourbucket/subdir/bibi/moby-dick.html | rg -B3 -A3 '</head>'
93
+ <meta name="generator" content="bibi publish">
94
+
95
+
96
+ </head>
97
+
98
+
99
+ <body data-bibi-book="moby-dick">
100
+ ----
101
+
102
+ `--body-end` option inserts HTML fragment in given file at just before `</body>` in HTML.
103
+
104
+ == Configuration
105
+
106
+ You can configure bibi publish by the file `~/.config/bibi/publish.toml` in https://toml.io/[TOML] format. This is especially useful for avoiding to specify options such as `--bibi` and `--bookshelf` each time.
107
+
108
+ Example is here:
109
+
110
+ ~/.config/bibi/publish.toml
111
+ [source,toml]
112
+ ----
113
+ # `default` table is used by default
114
+ [default]
115
+ bibi = "s3://yourbucket/subdir/bibi"
116
+ bookshelf = "s3://yourbucket/epubs"
117
+ page = true
118
+ ----
119
+
120
+ This is equivalent to pass command-line options `--bibi=s3://yourbucket/subdir/bibi`, `--bookshelf=s3://yourbucket/epubs` and `--page`.
121
+
122
+ If you want to switch set of configuration depending on situation, add another table and specify it by `--profile` option.
123
+
124
+ ~/.config/bibi/publish.toml
125
+ [source,toml]
126
+ ----
127
+ [production]
128
+ bibi = "s3://your-production-bucket/bibi"
129
+
130
+ [staging]
131
+ bibi = "s3://your-staging-bucket/bibi"
132
+
133
+ ----
134
+
135
+ % bibi publish --profile=staging moby-dick.epub
136
+
137
+ Currently supported keys are `bibi`, `bookshelf`, `page`, `head_end` and `body_end`.
138
+
139
+ === AWS profile
140
+
141
+ Use environment variable `AWS_PROFILE`:
142
+
143
+ % AWS_PROFILE=publicbibi bibi publish path/to/doc.epub
144
+
145
+ == See also
146
+
147
+ * https://github.com/satorumurmur/bibi[Bibi] is an EPUB reader which runs in web browser with beautiful UI.
148
+ * https://aws.amazon.com/cli/[AWS CLI] for install and configuration for AWS profile, which bibi publish also uses
149
+
150
+ == Copyright
151
+
152
+ Copyright (c) 2020 Kitaiti Makoto
153
+
154
+ See {file:COPYING.txt} for details.
@@ -0,0 +1,154 @@
1
+ = bibi publish
2
+
3
+ = {doctitle}
4
+
5
+ * link:https://rubygems.org/gems/bibi-publish[Homepage]
6
+ * link:http://rubydoc.info/gems/bibi-publish[Documentation]
7
+ * mailto:KitaitiMakoto-at-gmail.com[Email]
8
+
9
+ == 説明
10
+
11
+ Bibi CLIは https://github.com/satorumurmur/bibi[Bibi] というEPUBリーダーアプリケーションで作業するためのコマンドラインツールです。現在提供しているのは `bibi publish` コマンドのみです。
12
+
13
+ bibi publishはEPUBファイルをS3にアップロードし、Bibiでというで閲覧可能にするコマンドラインツールです。
14
+
15
+ == 機能
16
+
17
+ * EPUBドキュメント内のファイルをAmazon S3上のBibiのbookshelfディレクトリーにアップロード
18
+ * EPUB閲覧用のHTMLファイルを作成してS3にアップロード
19
+
20
+ == 使用例
21
+
22
+ % bibi publish moby-dick.epub
23
+ % bibi publish moby-dick.epub moby-dick-book
24
+ % bibi publish --bibi=s3://yourbucket/subdir/bibi moby-dick.epub moby-dick-book
25
+
26
+ == 前提条件
27
+
28
+ * AWSアカウント
29
+ * S3バケットにファイルをアップロード可能な環境
30
+ * アクセス可能で静的ウェブサイトホスティングように設定されたS3バケット
31
+ * AWS CLIとその設定
32
+
33
+ == インストール
34
+
35
+ % gem install bibi-publish
36
+
37
+ == 概要
38
+
39
+ === 予行
40
+
41
+ bibi publishは `--dry-run` オプションをサポートしています。これはアップロード予定のファイルを表示はするが実際にはアップロードしないというオプションです。
42
+
43
+ % bibi publish --bibi=s3://yourbucket/subdir/bibi path/to/moby-dick.epub moby-dick-book --dry-run
44
+
45
+ === 与えられたバケットとパスへのアップロード
46
+
47
+ % bibi publish --bibi=s3://yourbucket/subdir/bibi path/to/moby-dick.epub
48
+
49
+ これは次のことを行います。
50
+
51
+ * `moby-dick.epub` というEPUBファイル内のファイルを `s3://yourbucket/subdir/bibi-bookshelf/moby-dick` へアップロード
52
+ * Bibiを使ってこのEPUBドキュメントを読むためのHTMLファイルを `s3://yourbucket/subdir/bibi/moby-dick.html` へアップロード
53
+
54
+ 以下の点に注目してください。
55
+
56
+ * `bibi-bookshelf` というbookshelfディレクトリーはbibi publishが自動的に決定する
57
+ * `moby-dick` というbookshelfのサブディレクトリーは、 `moby-dick.epub` という与えられたEPUBファイルからbibi publishが自動的に決定する
58
+
59
+ === Bibi bookshelf下のディレクトリー名の指定
60
+
61
+ % bibi publish --bibi=s3://yourbucket/subdir/bibi path/to/moby-dick.epub moby-dick-book
62
+
63
+ `page-blanch-book` という第二引数はS3上のサブディレクトリーとHTMLファイル名に使われます。つまり以下のようになります。
64
+
65
+ * `s3://yourbucket/subdir/bibi-bookshelf/moby-dick` ではなく `s3://yourbucket/subdir/bibi-bookshelf/moby-dick-book`
66
+ * `s3://yourbucket/subdir/bibi/moby-dick.html` ではなく `s3://yourbucket/subdir/bibi/moby-dick-book.html`
67
+
68
+ === HTMLを生成しない
69
+
70
+ % bibi publish --bibi=s3://yourbucket/subdir/bibi --no-page path/to/moby-dick.epub moby-dick-book
71
+
72
+ コマンドに `--no-page` オプションを渡してください。
73
+
74
+ Bibiの通常のURIである `\https://s3.your-region.amazonaws.com/yourbucket/subdir/bibi/?book=moby-dick-book` に行くことでEPUBを閲覧することはできます。
75
+
76
+ === 生成するHTMLへの任意のフラグメントの挿入
77
+
78
+ bibi publishは `<head>` と `<body>` の終わりに、それぞれ `--head-end` オプションと `--body-end` オプションで指定されたファイルからHTMLフラグメントを挿入します。
79
+
80
+ BibiのHTMLのhead要素に生成プログラムの名前を挿入したいとしましょう。
81
+
82
+ % cat ./generator.html
83
+ <meta name="generator" content="bibi publish">
84
+
85
+ `--head-end` オプションでこのファイルへのパスを指定します。
86
+
87
+ % bibi publish --bibi=s3://yourbucket/subdir/bibi --head-end=./generator.html path/to/moby-dick.epub
88
+
89
+ これでHTMLファイルにHTMLフラグメントが挿入されます。
90
+
91
+ ----
92
+ % curl -s https://s3.your-region.amazonaws.com/yourbucket/subdir/bibi/moby-dick.html | rg -B3 -A3 '</head>'
93
+ <meta name="generator" content="bibi publish">
94
+
95
+
96
+ </head>
97
+
98
+
99
+ <body data-bibi-book="moby-dick">
100
+ ----
101
+
102
+ `--body-end` オプションは指定されたファイルのHTMLフラグメントをHTMLの `</body>` の直前に挿入します。
103
+
104
+ == 設定
105
+
106
+ `~/.config/bibi/publish.toml` というファイルで、link:https://toml.io/[TOML]形式でbibi publishの設定をすることができます。 `--bibi` や `--bookshelf` といった特定のオプションを毎回指定するのを避けるために特に有用です。
107
+
108
+ 例えばこうです。
109
+
110
+ ~/.config/bibi/publish.toml
111
+ [source,toml]
112
+ ----
113
+ # `default` table is used by default
114
+ [default]
115
+ bibi = "s3://yourbucket/subdir/bibi"
116
+ bookshelf = "s3://yourbucket/epubs"
117
+ page = true
118
+ ----
119
+
120
+ これはコマンドラインオプションで `--bibi=s3://yourbucket/subdir/bibi` と `--bookshelf=s3://yourbucket/epubs` 、 `--page` を渡すのと同等です。
121
+
122
+ 状況に応じて設定を切り替えたい場合は、別のテーブルを追加して `--option` オプションでそれを指定します。
123
+
124
+ ~/.config/bibi/publish.toml
125
+ [source,toml]
126
+ ----
127
+ [production]
128
+ bibi = "s3://your-production-bucket/bibi"
129
+
130
+ [staging]
131
+ bibi = "s3://your-staging-bucket/bibi"
132
+
133
+ ----
134
+
135
+ % bibi publish --profile=staging moby-dick.epub
136
+
137
+ 現在サポートしているキーは `bibi` 、 `bookshelf` 、 `page` 、 `head_end` 、 `body_end` です。
138
+
139
+ === AWSプロファイル
140
+
141
+ 環境変数 `AWS_PROFILE` を使用してください。
142
+
143
+ % AWS_PROFILE=publicbibi bibi publish path/to/doc.epub
144
+
145
+ == 参考
146
+
147
+ * https://github.com/satorumurmur/bibi[Bibi] はウェブブラウザーで動作する素晴らしいUIを持ったEPUBリーダーです。
148
+ * https://aws.amazon.com/cli/[AWS CLI] を見てインストールしAWSプロフファイルの設定をしてください。bibi publishはこの設定を使用します。
149
+
150
+ == 著作権
151
+
152
+ Copyright (c) 2020 Kitaiti Makoto
153
+
154
+ 詳細は{file:COPYING.txt}をご覧ください。
@@ -0,0 +1,26 @@
1
+ # encoding: utf-8
2
+
3
+ require 'rubygems'
4
+
5
+ begin
6
+ require 'bundler/setup'
7
+ rescue LoadError => e
8
+ abort e.message
9
+ end
10
+
11
+ require 'rake'
12
+
13
+
14
+ require 'rubygems/tasks'
15
+ Gem::Tasks.new
16
+
17
+ require 'yard'
18
+ YARD::Rake::YardocTask.new
19
+ task :doc => :yard
20
+
21
+ require 'rake/testtask'
22
+ Rake::TestTask.new do |test|
23
+ test.libs << 'test'
24
+ test.pattern = 'test/**/test_*.rb'
25
+ test.verbose = true
26
+ end
@@ -0,0 +1,46 @@
1
+ # -*- encoding: utf-8 -*-
2
+
3
+ lib = File.expand_path('../lib', __FILE__)
4
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
5
+ require 'bibi/cli/version'
6
+
7
+ Gem::Specification.new do |gem|
8
+ gem.name = "bibi-cli"
9
+ gem.version = Bibi::CLI::VERSION
10
+ gem.summary = %q{Command-line tools to work with Bibi}
11
+ gem.description = %q{Command-line tools to work with Bibi, incliding bibi publish which uploads EPUB files to S3 and make them readable via web using Bibi a EPUB reader application.}
12
+ gem.license = "AGPL-3.0"
13
+ gem.authors = ["Kitaiti Makoto"]
14
+ gem.email = "KitaitiMakoto@gmail.com"
15
+ gem.homepage = "https://gitlab.com/KitaitiMakoto/bibi-cli"
16
+
17
+ gem.files = `git ls-files`.split($/)
18
+
19
+ `git submodule --quiet foreach --recursive pwd`.split($/).each do |submodule|
20
+ submodule.sub!("#{Dir.pwd}/",'')
21
+
22
+ Dir.chdir(submodule) do
23
+ `git ls-files`.split($/).map do |subpath|
24
+ gem.files << File.join(submodule,subpath)
25
+ end
26
+ end
27
+ end
28
+ gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
29
+ gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
30
+ gem.require_paths = ['lib']
31
+
32
+ gem.add_runtime_dependency "archive-zip"
33
+ gem.add_runtime_dependency "aws-sdk-s3"
34
+ gem.add_runtime_dependency "dry-cli"
35
+ gem.add_runtime_dependency "dry-configurable"
36
+ gem.add_runtime_dependency "epub-parser"
37
+ gem.add_runtime_dependency "tomlrb"
38
+ gem.add_runtime_dependency "xdg"
39
+
40
+ gem.add_development_dependency "asciidoctor"
41
+ gem.add_development_dependency 'bundler'
42
+ gem.add_development_dependency 'rake'
43
+ gem.add_development_dependency 'rubygems-tasks'
44
+ gem.add_development_dependency "test-unit"
45
+ gem.add_development_dependency 'yard'
46
+ end
@@ -0,0 +1,17 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ root = File.expand_path(File.join(File.dirname(__FILE__),'..'))
4
+ if File.directory?(File.join(root,'.git'))
5
+ Dir.chdir(root) do
6
+ begin
7
+ require 'bundler/setup'
8
+ rescue LoadError => e
9
+ warn e.message
10
+ warn "Run `gem install bundler` to install Bundler"
11
+ exit -1
12
+ end
13
+ end
14
+ end
15
+
16
+ require "bibi/cli/commands/publish"
17
+ Dry::CLI.new(Bibi::CLI::Commands).call
@@ -0,0 +1,9 @@
1
+ require "dry/cli"
2
+
3
+ module Bibi
4
+ module CLI
5
+ module Commands
6
+ extend Dry::CLI::Registry
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,31 @@
1
+ require "bibi/cli/commands"
2
+ require "bibi/publish"
3
+
4
+ module Bibi::CLI::Commands
5
+ class Publish < Dry::CLI::Command
6
+ desc "Publish EPUB file"
7
+
8
+ argument :epub, required: true, desc: "EPUB path"
9
+ argument :name, required: false, desc: "directory name in Bibi bookshelf directory"
10
+
11
+ option :bibi, desc: "URI of Bibi directory"
12
+ option :bookshelf, desc: "URI of Bibi bookshelf, default: {bibi}/../bibi-bookshelf"
13
+ option :page, type: :boolean, default: true, desc: "generate HTML page"
14
+ option :head_end, desc: "path to HTML file to be inserted at the end of <head> in html. Effective when page switch is on"
15
+ option :body_end, desc: "path to HTML file to be inserted at the end of <body> in html. Effective when page switch is on"
16
+ option :endpoint, desc: "S3 endpoint URL. useful when using MinIO and so on"
17
+ option :profile, default: :default, desc: "configuration profile"
18
+ option :dry_run, type: :boolean, default: false, desc: "Shows uploading file but doesn't upload actually"
19
+
20
+ example [
21
+ "--bibi=s3://mybucket/subdir/bibi path/to/doc.epub"
22
+ ]
23
+
24
+ def call(epub:, name: File.basename(epub, ".*"), **options)
25
+ options[:profile] = options[:profile]&.intern
26
+ Bibi::Publish.new(**options).run(epub, name)
27
+ end
28
+ end
29
+
30
+ register "publish", Publish
31
+ end