capsium 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (43) hide show
  1. checksums.yaml +7 -0
  2. data/.github/workflows/rake.yml +18 -0
  3. data/.github/workflows/release.yml +24 -0
  4. data/.gitignore +11 -0
  5. data/.rspec +3 -0
  6. data/.rubocop.yml +8 -0
  7. data/CODE_OF_CONDUCT.md +84 -0
  8. data/Gemfile +12 -0
  9. data/README.adoc +258 -0
  10. data/Rakefile +12 -0
  11. data/bin/console +11 -0
  12. data/bin/setup +8 -0
  13. data/capsium.gemspec +54 -0
  14. data/exe/capsium +6 -0
  15. data/images/005df7415a331c466ad2d9a42efdd212b6f42fe50b5fd3b3174c86c706f58244.png +0 -0
  16. data/images/0374025b3af99b8a473282c8cbbf9fcd29573cf41e586982f328f86c0690f43d.png +0 -0
  17. data/images/0bb4da785be40ef58e219470ebccb979325928b75453dc46bac23c6ee8a7a7cb.png +0 -0
  18. data/images/6aa294dccc81af594aacbe804e7ddffdc17eacc28357338108aea5d021d831ff.png +0 -0
  19. data/images/72dd3fbf3f4b475e27a0e7fb8137c475c32c41f8d222bcf62d6a9ccf102d9532.png +0 -0
  20. data/images/8772b6961d169738d7b0fa0b669b06fc2f40632d4c62586c7634fc17b93182a3.png +0 -0
  21. data/images/a998d842405933d45723606ff3f70162ec95b4ef30db25464a366184fd08fb9b.png +0 -0
  22. data/images/aa8980547e8c003d33273ab4d80e62da7f317bd7581b293c06d67f5331f24f31.png +0 -0
  23. data/images/bb78a872b539e0e9b2d80dee58acbb688f3f2727b324a5bf8bf417a69d94a166.png +0 -0
  24. data/images/c48fc83b17725d85fbb64d971196ebfccd8c5c757fe6aa5845303f6e315879b6.png +0 -0
  25. data/images/f08ef07308d08119ac2124bb7428c8bef17ef1ca70045696604d6e83015a9b91.png +0 -0
  26. data/images/f7514206111b695647eae9adfcf498ba3e0ff83ecfe25f3fc3ed8e9f04c5c726-1.png +0 -0
  27. data/images/f7514206111b695647eae9adfcf498ba3e0ff83ecfe25f3fc3ed8e9f04c5c726.png +0 -0
  28. data/lib/capsium/cli.rb +96 -0
  29. data/lib/capsium/converters/jekyll.rb +59 -0
  30. data/lib/capsium/package/dataset.rb +86 -0
  31. data/lib/capsium/package/manifest.rb +97 -0
  32. data/lib/capsium/package/metadata.rb +48 -0
  33. data/lib/capsium/package/routes.rb +157 -0
  34. data/lib/capsium/package/storage.rb +52 -0
  35. data/lib/capsium/package.rb +142 -0
  36. data/lib/capsium/packager.rb +100 -0
  37. data/lib/capsium/protector.rb +95 -0
  38. data/lib/capsium/reactor.rb +82 -0
  39. data/lib/capsium/thor_ext.rb +71 -0
  40. data/lib/capsium/version.rb +5 -0
  41. data/lib/capsium.rb +15 -0
  42. data/sig/capsium.rbs +4 -0
  43. metadata +354 -0
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: e89423acb8bc50c9e1fc53ad06ad472114f379159cf66f49d90f92f08a22c907
4
+ data.tar.gz: 70e5bcdcfcbf17028102da8c6dd45a4b9d5fe58a0618f048214f278fc212516b
5
+ SHA512:
6
+ metadata.gz: 98aa164541a7fdb7678baaa084cad87bccb9f5673913a521d91ed19747153c119bccdbaeb7771c2312f131270d066412fcf1972c43cc7ac38dc4b3016e1f96b8
7
+ data.tar.gz: e3d043c1c4c1692160811fbefdce727c2c0d606e65ad934de9474b41af88a3e621bd51b9620581f186dd257800e3386661f125ab94921277a4bd5a7b1e801a49
@@ -0,0 +1,18 @@
1
+ # Auto-generated by Cimas: Do not edit it manually!
2
+ # See https://github.com/metanorma/cimas
3
+ name: rake
4
+
5
+ on:
6
+ push:
7
+ branches: [ master, main ]
8
+ tags: [ v* ]
9
+ pull_request:
10
+
11
+ permissions:
12
+ contents: write
13
+
14
+ jobs:
15
+ rake:
16
+ uses: metanorma/ci/.github/workflows/libreoffice-rake.yml@main
17
+ secrets:
18
+ pat_token: ${{ secrets.METANORMA_CI_PAT_TOKEN }}
@@ -0,0 +1,24 @@
1
+ # Auto-generated by Cimas: Do not edit it manually!
2
+ # See https://github.com/metanorma/cimas
3
+ name: release
4
+
5
+ on:
6
+ workflow_dispatch:
7
+ inputs:
8
+ next_version:
9
+ description: |
10
+ Next release version. Possible values: x.y.z, major, minor, patch (or pre|rc|etc).
11
+ Also, you can pass 'skip' to skip 'git tag' and do 'gem push' for the current version
12
+ required: true
13
+ default: 'skip'
14
+ repository_dispatch:
15
+ types: [ do-release ]
16
+
17
+ jobs:
18
+ release:
19
+ uses: metanorma/ci/.github/workflows/rubygems-release.yml@main
20
+ with:
21
+ next_version: ${{ github.event.inputs.next_version }}
22
+ secrets:
23
+ rubygems-api-key: ${{ secrets.METANORMA_CI_RUBYGEMS_API_KEY }}
24
+ pat_token: ${{ secrets.METANORMA_CI_PAT_TOKEN }}
data/.gitignore ADDED
@@ -0,0 +1,11 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /_yardoc/
4
+ /coverage/
5
+ /doc/
6
+ /pkg/
7
+ /spec/reports/
8
+ /tmp/
9
+
10
+ # rspec failure tracking
11
+ .rspec_status
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --format documentation
2
+ --color
3
+ --require spec_helper
data/.rubocop.yml ADDED
@@ -0,0 +1,8 @@
1
+ AllCops:
2
+ TargetRubyVersion: 3.0
3
+
4
+ Style/StringLiterals:
5
+ EnforcedStyle: double_quotes
6
+
7
+ Style/StringLiteralsInInterpolation:
8
+ EnforcedStyle: double_quotes
@@ -0,0 +1,84 @@
1
+ # Contributor Covenant Code of Conduct
2
+
3
+ ## Our Pledge
4
+
5
+ We as members, contributors, and leaders pledge to make participation in our community a harassment-free experience for everyone, regardless of age, body size, visible or invisible disability, ethnicity, sex characteristics, gender identity and expression, level of experience, education, socio-economic status, nationality, personal appearance, race, religion, or sexual identity and orientation.
6
+
7
+ We pledge to act and interact in ways that contribute to an open, welcoming, diverse, inclusive, and healthy community.
8
+
9
+ ## Our Standards
10
+
11
+ Examples of behavior that contributes to a positive environment for our community include:
12
+
13
+ * Demonstrating empathy and kindness toward other people
14
+ * Being respectful of differing opinions, viewpoints, and experiences
15
+ * Giving and gracefully accepting constructive feedback
16
+ * Accepting responsibility and apologizing to those affected by our mistakes, and learning from the experience
17
+ * Focusing on what is best not just for us as individuals, but for the overall community
18
+
19
+ Examples of unacceptable behavior include:
20
+
21
+ * The use of sexualized language or imagery, and sexual attention or
22
+ advances of any kind
23
+ * Trolling, insulting or derogatory comments, and personal or political attacks
24
+ * Public or private harassment
25
+ * Publishing others' private information, such as a physical or email
26
+ address, without their explicit permission
27
+ * Other conduct which could reasonably be considered inappropriate in a
28
+ professional setting
29
+
30
+ ## Enforcement Responsibilities
31
+
32
+ Community leaders are responsible for clarifying and enforcing our standards of acceptable behavior and will take appropriate and fair corrective action in response to any behavior that they deem inappropriate, threatening, offensive, or harmful.
33
+
34
+ Community leaders have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct, and will communicate reasons for moderation decisions when appropriate.
35
+
36
+ ## Scope
37
+
38
+ This Code of Conduct applies within all community spaces, and also applies when an individual is officially representing the community in public spaces. Examples of representing our community include using an official e-mail address, posting via an official social media account, or acting as an appointed representative at an online or offline event.
39
+
40
+ ## Enforcement
41
+
42
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be reported to the community leaders responsible for enforcement at ronald.tse@ribose.com. All complaints will be reviewed and investigated promptly and fairly.
43
+
44
+ All community leaders are obligated to respect the privacy and security of the reporter of any incident.
45
+
46
+ ## Enforcement Guidelines
47
+
48
+ Community leaders will follow these Community Impact Guidelines in determining the consequences for any action they deem in violation of this Code of Conduct:
49
+
50
+ ### 1. Correction
51
+
52
+ **Community Impact**: Use of inappropriate language or other behavior deemed unprofessional or unwelcome in the community.
53
+
54
+ **Consequence**: A private, written warning from community leaders, providing clarity around the nature of the violation and an explanation of why the behavior was inappropriate. A public apology may be requested.
55
+
56
+ ### 2. Warning
57
+
58
+ **Community Impact**: A violation through a single incident or series of actions.
59
+
60
+ **Consequence**: A warning with consequences for continued behavior. No interaction with the people involved, including unsolicited interaction with those enforcing the Code of Conduct, for a specified period of time. This includes avoiding interactions in community spaces as well as external channels like social media. Violating these terms may lead to a temporary or permanent ban.
61
+
62
+ ### 3. Temporary Ban
63
+
64
+ **Community Impact**: A serious violation of community standards, including sustained inappropriate behavior.
65
+
66
+ **Consequence**: A temporary ban from any sort of interaction or public communication with the community for a specified period of time. No public or private interaction with the people involved, including unsolicited interaction with those enforcing the Code of Conduct, is allowed during this period. Violating these terms may lead to a permanent ban.
67
+
68
+ ### 4. Permanent Ban
69
+
70
+ **Community Impact**: Demonstrating a pattern of violation of community standards, including sustained inappropriate behavior, harassment of an individual, or aggression toward or disparagement of classes of individuals.
71
+
72
+ **Consequence**: A permanent ban from any sort of public interaction within the community.
73
+
74
+ ## Attribution
75
+
76
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 2.0,
77
+ available at https://www.contributor-covenant.org/version/2/0/code_of_conduct.html.
78
+
79
+ Community Impact Guidelines were inspired by [Mozilla's code of conduct enforcement ladder](https://github.com/mozilla/diversity).
80
+
81
+ [homepage]: https://www.contributor-covenant.org
82
+
83
+ For answers to common questions about this code of conduct, see the FAQ at
84
+ https://www.contributor-covenant.org/faq. Translations are available at https://www.contributor-covenant.org/translations.
data/Gemfile ADDED
@@ -0,0 +1,12 @@
1
+ # frozen_string_literal: true
2
+
3
+ source "https://rubygems.org"
4
+
5
+ # Specify your gem's dependencies in capsium.gemspec
6
+ gemspec
7
+
8
+ gem "rake", "~> 13.0"
9
+
10
+ gem "rspec", "~> 3.0"
11
+
12
+ gem "rubocop", "~> 1.21"
data/README.adoc ADDED
@@ -0,0 +1,258 @@
1
+ = Capsium
2
+
3
+ Capsium: Common architecture for portable secure information interchange and
4
+ unified management.
5
+
6
+ Capsium is designed to facilitate the creation, management and deployment of
7
+ content packages with ease.
8
+
9
+ This gem provides a structured way to handle content, data, and metadata for
10
+ various applications.
11
+
12
+
13
+ == Testing out how it works
14
+
15
+ Download the mn-samples-iso built site: https://github.com/metanorma/mn-samples-iso/actions/runs/8862815829/artifacts/1453746303[mn-samples-iso-Linux].
16
+
17
+ Then run these commands:
18
+
19
+ [source,bash]
20
+ ----
21
+ $ unzip mn-samples-iso-Linux.zip
22
+ $ cd mn-samples-iso-Linux
23
+ $ mkdir content
24
+ $ mv index.html documents.xml documents content
25
+ $ echo '{"name": "mn-samples-iso","version":"0.1.0"}' > metadata.json
26
+ $ cd ..
27
+ $ bundle exec capsium package pack -f mn-samples-iso-Linux
28
+ Package created: mn-samples-iso-0.1.0.cap
29
+ $ bundle exec capsium reactor serve mn-samples-iso-0.1.0.cap
30
+ Starting server on http://localhost:8864
31
+ [2024-06-05 14:56:41] INFO WEBrick::HTTPServer#start: pid=8234 port=8864
32
+ ...
33
+ ----
34
+
35
+ == Installation
36
+
37
+ To install the Capsium gem, add it to your Gemfile:
38
+
39
+ [source,ruby]
40
+ ----
41
+ gem 'capsium'
42
+ ----
43
+
44
+ Then, run the following command to install it:
45
+
46
+ [source,bash]
47
+ ----
48
+ bundle install
49
+ ----
50
+
51
+ Alternatively, you can install the gem directly using:
52
+
53
+ [source,bash]
54
+ ----
55
+ gem install capsium
56
+ ----
57
+
58
+ == What is a Capsium package?
59
+
60
+ A Capsium package is a structured collection of content, data, metadata, and routing information. It is designed to encapsulate all resources needed for a particular application or service in a well-organized format. A package typically includes:
61
+
62
+ * **Content**: Static files like HTML, CSS, and JavaScript.
63
+ * **Data**: Structured data files, such as YAML or JSON.
64
+ * **Metadata**: Descriptive information about the package, such as its name, version, and dependencies.
65
+ * **Routes**: Mapping of URLs to content or data endpoints.
66
+ * **Storage**: Definitions for datasets and their sources, formats, and schemas.
67
+
68
+ == What is a Capsium reactor?
69
+
70
+ A Capsium reactor is a runtime environment that serves Capsium packages. It reads the package configuration and starts a server that can handle HTTP requests according to the routes defined in the package. The reactor ensures that the content and data within the package are served correctly, allowing for easy integration and deployment of packaged applications.
71
+
72
+ == CLI: Package
73
+
74
+ To pack a package, you need to define the content, data, metadata, routes, and storage configurations. Once defined, you can use the Capsium command-line interface (CLI) to create and manage your packages.
75
+
76
+ Capsium provides a CLI to help you pack and manage your packages. Here are some common commands:
77
+
78
+ [source,bash]
79
+ ----
80
+ # TODO: Create a new package
81
+ # Full command
82
+ capsium package new my_package
83
+ # Shorthand
84
+ capsium package my_package
85
+
86
+ # TODO: Add content to the package
87
+ capsium package add content example.html example.css example.js
88
+
89
+ # TODO: Add data to the package
90
+ capsium package add data animals.yaml
91
+
92
+ # TODO: Add metadata to the package
93
+ capsium package add metadata name=sample_package version=0.1.0
94
+
95
+ # TODO: Define routes for the package
96
+ capsium package add route /=example.html /index=index.html /api/v1/data/animals={type:dataset,name:animals}
97
+
98
+ # TODO: Define storage for the package
99
+ capsium package add storage datasets=[{name:animals,source:data/animals.yaml,format:yaml,schema:data/animals_schema.yaml}]
100
+ ----
101
+
102
+ === Packing a package
103
+
104
+ To pack an existing Capsium package directory, use the following command:
105
+
106
+ [source,bash]
107
+ ----
108
+ capsium package pack [--force/-f] path-to-package
109
+ ----
110
+
111
+ This command will pack your package into a single file with the
112
+ filename:
113
+
114
+ * `{package-name}-{package-version}.cap`
115
+ * where the name and version both come from `{package-path}/metadata.json`
116
+
117
+ .Sample `pack` command
118
+ ====
119
+ [source,bash]
120
+ ----
121
+ capsium package pack -f spec/fixtures/bare_package
122
+ ----
123
+ ====
124
+
125
+
126
+
127
+ == CLI: Reactor
128
+
129
+ === Starting a reactor on your package
130
+
131
+ To start a Capsium reactor on your package, use the following command:
132
+
133
+ [source,bash]
134
+ ----
135
+ capsium reactor serve my_package.cap
136
+ ----
137
+
138
+
139
+ == Programmatically managing packages
140
+
141
+ You can also create, load, and use packages programmatically within your Ruby application.
142
+
143
+ === Creating packages
144
+
145
+ [source,ruby]
146
+ ----
147
+ require 'capsium'
148
+
149
+ package = Capsium::Package.new(
150
+ name: 'sample_package',
151
+ version: '0.1.0',
152
+ content: {
153
+ 'example.html' => 'text/html',
154
+ 'example.css' => 'text/css',
155
+ 'example.js' => 'application/javascript'
156
+ },
157
+ data: {
158
+ 'animals.yaml' => {
159
+ 'animals' => [
160
+ { 'name' => 'Lion', 'type' => 'Mammal', 'habitat' => 'Savannah' },
161
+ { 'name' => 'Eagle', 'type' => 'Bird', 'habitat' => 'Mountains' },
162
+ { 'name' => 'Shark', 'type' => 'Fish', 'habitat' => 'Ocean' }
163
+ ]
164
+ }
165
+ },
166
+ metadata: {
167
+ 'name' => 'sample_package',
168
+ 'version' => '0.1.0',
169
+ 'dependencies' => []
170
+ },
171
+ routes: {
172
+ '/' => 'example.html',
173
+ '/index' => 'index.html',
174
+ '/index.html' => 'index.html',
175
+ '/example.css' => 'example.css',
176
+ '/example.js' => 'example.js',
177
+ '/api/v1/data/animals' => { 'type' => 'dataset', 'name' => 'animals' }
178
+ },
179
+ storage: {
180
+ 'datasets' => [
181
+ {
182
+ 'name' => 'animals',
183
+ 'source' => 'data/animals.yaml',
184
+ 'format' => 'yaml',
185
+ 'schema' => 'data/animals_schema.yaml'
186
+ }
187
+ ]
188
+ }
189
+ )
190
+
191
+ # Save the package to a file
192
+ File.write('my_package.json', package.to_json(pretty: true))
193
+ ----
194
+
195
+ === Loading packages
196
+
197
+ To load an existing package from a JSON file, you can use the `Capsium::Package.new(path)` method:
198
+
199
+ [source,ruby]
200
+ ----
201
+ require 'capsium'
202
+
203
+ # Read the package file or folder
204
+ package = Capsium::Package.new(path)
205
+
206
+ # Inspect the loaded package
207
+ puts package.inspect
208
+ ----
209
+
210
+ === Using packages in your program
211
+
212
+ Once you have created or loaded a package, you can use it within your Ruby application to access its content, data, and other properties.
213
+
214
+ [source,ruby]
215
+ ----
216
+ # Accessing package metadata
217
+ puts "Package Name: #{package.metadata['name']}"
218
+ puts "Package Version: #{package.metadata['version']}"
219
+
220
+ # Accessing content
221
+ package.content.each do |filename, content_type|
222
+ puts "Content File: #{filename}, Content Type: #{content_type}"
223
+ end
224
+
225
+ # Accessing data
226
+ animals_data = package.data['animals.yaml']
227
+ puts "Animals Data: #{animals_data.inspect}"
228
+
229
+ # Accessing routes
230
+ package.routes.each do |route, destination|
231
+ puts "Route: #{route}, Destination: #{destination}"
232
+ end
233
+
234
+ # Accessing storage definitions
235
+ package.storage['datasets'].each do |dataset|
236
+ puts "Dataset Name: #{dataset['name']}, Source: #{dataset['source']}, Format: #{dataset['format']}"
237
+ end
238
+ ----
239
+
240
+ == Contributing
241
+
242
+ We welcome contributions to the Capsium gem. If you would like to contribute, please fork the repository and submit a pull request.
243
+
244
+ === Running tests
245
+
246
+ To run the tests, use the following command:
247
+
248
+ [source,bash]
249
+ ----
250
+ rspec
251
+ ----
252
+
253
+ == License
254
+
255
+ Copyright Ribose.
256
+
257
+ Capsium is released under the MIT License. See the LICENSE file for more details.
258
+
data/Rakefile ADDED
@@ -0,0 +1,12 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "bundler/gem_tasks"
4
+ require "rspec/core/rake_task"
5
+
6
+ RSpec::Core::RakeTask.new(:spec)
7
+
8
+ require "rubocop/rake_task"
9
+
10
+ RuboCop::RakeTask.new
11
+
12
+ task default: %i[spec rubocop]
data/bin/console ADDED
@@ -0,0 +1,11 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
4
+ require "bundler/setup"
5
+ require "capsium"
6
+
7
+ # You can add fixtures and/or initialization code here to make experimenting
8
+ # with your gem easier. You can also use a different console, if you like.
9
+
10
+ require "irb"
11
+ IRB.start(__FILE__)
data/bin/setup ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
data/capsium.gemspec ADDED
@@ -0,0 +1,54 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "lib/capsium/version"
4
+
5
+ Gem::Specification.new do |spec|
6
+ spec.name = "capsium"
7
+ spec.version = Capsium::VERSION
8
+ spec.authors = ["Ribose Inc."]
9
+ spec.email = ["open.source@ribose.com'"]
10
+
11
+ spec.summary = "Capsium"
12
+ spec.description = "Capsium"
13
+ spec.homepage = "https://github.com/metanorma/capsium"
14
+ spec.license = "MIT"
15
+
16
+ spec.metadata["homepage_uri"] = spec.homepage
17
+ spec.metadata["source_code_uri"] = spec.homepage
18
+ spec.metadata["changelog_uri"] = "https://github.com/metanorma/capsium/releases"
19
+
20
+ # Specify which files should be added to the gem when it is released.
21
+ # The `git ls-files -z` loads the files in the RubyGem
22
+ # that have been added into git.
23
+ spec.files = Dir.chdir(File.expand_path(__dir__)) do
24
+ `git ls-files -z`
25
+ .split("\x0")
26
+ .reject { |f| f.match(%r{^(test|spec|features)/}) }
27
+ end
28
+ spec.bindir = "exe"
29
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
30
+ spec.require_paths = ["lib"]
31
+
32
+ spec.required_ruby_version = ">= 2.7.0"
33
+
34
+ spec.add_dependency "cssminify"
35
+ spec.add_dependency "csv"
36
+ spec.add_dependency "htmlcompressor"
37
+ spec.add_dependency "html-proofer"
38
+ spec.add_dependency "json"
39
+ spec.add_dependency "listen"
40
+ spec.add_dependency "marcel"
41
+ spec.add_dependency "rubyzip", "~>2.3.2"
42
+ spec.add_dependency "scss_lint"
43
+ spec.add_dependency "shale"
44
+ spec.add_dependency "sqlite3"
45
+ spec.add_dependency "thor"
46
+ spec.add_dependency "uglifier"
47
+ spec.add_dependency "webrick"
48
+ spec.add_dependency "yaml"
49
+
50
+ spec.add_development_dependency "pry", "~> 0.12.2"
51
+ spec.add_development_dependency "rake", "~> 13.0"
52
+ spec.add_development_dependency "rspec", "~> 3.11"
53
+ spec.add_development_dependency "rubocop", "~> 1.58"
54
+ end
data/exe/capsium ADDED
@@ -0,0 +1,6 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
4
+ require "capsium/cli"
5
+
6
+ Capsium::Cli.start(ARGV)
@@ -0,0 +1,96 @@
1
+ # frozen_string_literal: true
2
+
3
+ # lib/capsium/cli.rb
4
+ require "thor"
5
+ require_relative "package"
6
+ require_relative "reactor"
7
+ require_relative "thor_ext"
8
+ require_relative "converters/jekyll"
9
+
10
+ module Capsium
11
+ class Cli < Thor
12
+ extend ThorExt::Start
13
+
14
+ class Package < Thor
15
+ extend ThorExt::Start
16
+
17
+ desc "info PACKAGE_PATH", "Display information about the package"
18
+ def info(path_to_package)
19
+ package = Capsium::Package.new(path_to_package)
20
+ puts "Package Path: #{package.path}"
21
+ puts "Routes: #{package.routes.as_json}"
22
+ puts "Manifest: #{package.manifest.as_json}"
23
+ end
24
+
25
+ desc "manifest PATH_TO_PACKAGE", "Show the manifest content of the package"
26
+ def manifest(path_to_package)
27
+ package = Capsium::Package.new(path_to_package)
28
+ puts JSON.pretty_generate(package.manifest.as_json)
29
+ end
30
+
31
+ desc "storage PATH_TO_PACKAGE", "Show the storage datasets of the package"
32
+ def storage(path_to_package)
33
+ package = Capsium::Package.new(path_to_package)
34
+ puts JSON.pretty_generate(package.storage.as_json)
35
+ end
36
+
37
+ desc "routes PATH_TO_PACKAGE", "Show the routes of the package"
38
+ def routes(path_to_package)
39
+ package = Capsium::Package.new(path_to_package)
40
+ puts JSON.pretty_generate(package.routes.as_json)
41
+ end
42
+
43
+ desc "metadata PATH_TO_PACKAGE", "Show the metadata of the package"
44
+ def metadata(path_to_package)
45
+ package = Capsium::Package.new(path_to_package)
46
+ puts JSON.pretty_generate(package.metadata.as_json)
47
+ end
48
+
49
+ desc "pack PATH_TO_PACKAGE_FOLDER", "Package the files into the package"
50
+ option :force, type: :boolean, default: false, aliases: "-f"
51
+ def pack(path_to_package)
52
+ package = Capsium::Package.new(path_to_package)
53
+ packager = Capsium::Packager.new
54
+ packager.pack(package, options)
55
+ rescue StandardError => e
56
+ puts e
57
+ puts e.inspect
58
+ puts e.backtrace
59
+ end
60
+ end
61
+
62
+ class Reactor < Thor
63
+ extend ThorExt::Start
64
+ desc "serve PACKAGE_PATH", "Start the Capsium reactor to serve the package"
65
+ def serve(path_to_package)
66
+ package = Capsium::Package.new(path_to_package)
67
+ reactor = Capsium::Reactor.new(package)
68
+ reactor.serve
69
+ rescue StandardError => e
70
+ puts e
71
+ puts e.inspect
72
+ puts e.backtrace
73
+ ensure
74
+ package.cleanup
75
+ end
76
+ end
77
+
78
+ class Convert < Thor
79
+ extend ThorExt::Start
80
+ desc "jekyll SITE_DIRECTORY OUTPUT_DIRECTORY", "Convert a Jekyll site directory to a Capsium package"
81
+ def jekyll(site_directory, output_directory)
82
+ converter = Capsium::Converters::Jekyll.new(site_directory, output_directory)
83
+ converter.convert
84
+ end
85
+ end
86
+
87
+ desc "package SUBCOMMAND ...ARGS", "Manage packages"
88
+ subcommand "package", Capsium::Cli::Package
89
+
90
+ desc "reactor SUBCOMMAND ...ARGS", "Manage the reactor"
91
+ subcommand "reactor", Capsium::Cli::Reactor
92
+
93
+ desc "converter SUBCOMMAND ...ARGS", "Convert from another format"
94
+ subcommand "converter", Capsium::Cli::Convert
95
+ end
96
+ end