metanorma-cli 1.3.9 → 1.4.1

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: a03b03e99303cba8dba1f9cff78ee1e8b2398f717619b193460a58c8bbcd423d
4
- data.tar.gz: 00a06a5126c12f57e1e5a7a77337a600606cd25b026439865012fb41907af664
3
+ metadata.gz: c88ec404d073b5b55e98c46ac5709db3abb0e090855abbe4e5fd37ccb1c6fe1b
4
+ data.tar.gz: fe29640074f35365f061b89227c11a0b4f45e47a8704244c8468bf1f8f3813c0
5
5
  SHA512:
6
- metadata.gz: 32ae08f01d0435a30d418978eeb8baa0c482ae7e707de6bf12562dc4899c3dc37bef83b6fbdb7778899e37a659dc0bdf2d30bb8abb298c19e8bd8724eedac01a
7
- data.tar.gz: 184167a6dca3dc0542e0ff1abf90c7cc96ba92135592939bc28658827e8315a0d6d932578c41a074a3075a20ad4b82593b39ce0e72ebb0093584eb0cc6f27b56
6
+ metadata.gz: 0d1a7bd16a4a5f94ab4a519e1e0f4e7625a553f58c16c68f5e7c09c68873d326153e13eb5ba4d34528f220301984b2cc3155426c1bc3a3476f3826adb4927902
7
+ data.tar.gz: adec9799ab747d3c47645ba328d301728d75dcfd714117a8a459fe08d798ae95fad8d71ac51783b294e2f800a8b0e261c760228d7a9149db42b7b819b2b8735d
data/Gemfile CHANGED
@@ -4,7 +4,6 @@ Encoding.default_internal = Encoding::UTF_8
4
4
  source "https://rubygems.org"
5
5
  git_source(:github) { |repo| "https://github.com/#{repo}" }
6
6
 
7
-
8
7
  gemspec
9
8
 
10
9
  if File.exist? 'Gemfile.devel'
@@ -228,6 +228,32 @@ Options:
228
228
  -c, [--coverpage=COVERPAGE] # Cover page as Liquid template for collection (currently HTML only)
229
229
  ----
230
230
 
231
+ === List supported doctypes (`metanorma list-doctypes`)
232
+
233
+ You want to know what are the supported doctypes and what do they support for
234
+ input and output format? Well, the `metanorma list-doctypes` can help.
235
+
236
+
237
+ [source,sh]
238
+ ----
239
+ metanorma list-doctypes
240
+ ----
241
+
242
+
243
+ To list out the details for a specific flavor run the following command:
244
+
245
+ [source,sh]
246
+ ----
247
+ metanorma list-doctypes <flavor>
248
+ ----
249
+
250
+ e.g.,
251
+
252
+ [source,sh]
253
+ ----
254
+ metanorma list-doctypes iso
255
+ ----
256
+
231
257
  === List supported output formats (`metanorma list-extensions`)
232
258
 
233
259
  Need to know what output formats are supported for a given flavor?
@@ -285,6 +311,21 @@ repository.
285
311
  metanorma template-repo add my-iso https://github.com/you/my-iso-template
286
312
  ----
287
313
 
314
+ === Generate metanorma minisite
315
+
316
+ The `site` interface allows you to manage mini site generation using the CLI.
317
+ To generate a mini site you need to provide the `SOURCE_PATH` and the CLI will
318
+ take care of compiling each of those files and generate deployable site in the
319
+ provided output directory.
320
+
321
+ This interface also supports a YAML manifest file that can be used to customize
322
+ the site generation process. You can check more details here: link:./spec/fixtures/metanorma.yml[metanorma.yml]
323
+
324
+ [source, sh]
325
+ ----
326
+ metanorma site generate SOURCE_PATH -o OUTPUT_PATH -c metanorma.yml
327
+ ----
328
+
288
329
  == Credits
289
330
 
290
331
  This gem is developed, maintained and funded by https://www.metanorma.com/docs/getting-started/[Ribose Inc.]
@@ -10,6 +10,7 @@ module Metanorma
10
10
  "metanorma-iec",
11
11
  "metanorma-ietf",
12
12
  #"metanorma-gb",
13
+ "metanorma-bipm",
13
14
  "metanorma-cc",
14
15
  "metanorma-csa",
15
16
  "metanorma-iho",
@@ -3,6 +3,7 @@ require "metanorma/cli/compiler"
3
3
  require "metanorma/cli/generator"
4
4
  require "metanorma/cli/git_template"
5
5
  require "metanorma/cli/commands/template_repo"
6
+ require "metanorma/cli/commands/site"
6
7
  require "metanorma"
7
8
 
8
9
  module Metanorma
@@ -31,9 +32,9 @@ module Metanorma
31
32
  option :version, aliases: "-v", desc: "Print version of code (accompanied with -t)"
32
33
  option "output-dir", aliases: "-o", desc: "Directory to save compiled files"
33
34
 
34
- option :agree_to_terms, type: :boolean, desc: "Agree / Disagree with all third-party licensing terms presented (WARNING: do know what you are agreeing with!)"
35
- option :no_install_fonts, type: :boolean, desc: "Skip the font installation process"
36
- option :continue_without_fonts, type: :boolean, desc: "Continue processing even when fonts are missing"
35
+ option :"agree-to-terms", type: :boolean, desc: "Agree / Disagree with all third-party licensing terms presented (WARNING: do know what you are agreeing with!)"
36
+ option :"no-install-fonts", type: :boolean, desc: "Skip the font installation process"
37
+ option :"continue-without-fonts", type: :boolean, desc: "Continue processing even when fonts are missing"
37
38
 
38
39
  def compile(file_name = nil)
39
40
  if file_name && !options[:version]
@@ -57,12 +58,16 @@ module Metanorma
57
58
  option :format, aliases: "-x", type: :string, desc: "Formats to generate"
58
59
  option "output-folder", aliases: "-w", required: true, desc: "Directory to save compiled files"
59
60
  option :coverpage, aliases: "-c", desc: "Liquid template"
61
+ option :"agree-to-terms", type: :boolean, desc: "Agree / Disagree with all third-party licensing terms presented (WARNING: do know what you are agreeing with!)"
62
+ option :"no-install-fonts", type: :boolean, desc: "Skip the font installation process"
63
+ option :"continue-without-fonts", type: :boolean, desc: "Continue processing even when fonts are missing"
60
64
 
61
65
  def collection(filename = nil)
62
66
  if filename
63
67
  opts = options.dup
64
68
  opts[:format] &&= opts[:format].split(",").map &:to_sym
65
69
  opts[:output_folder] = opts.delete :"output-folder"
70
+ opts[:compile] = opts.select { |k, v| ["agree-to-terms", "no-install-fonts", "continue-without-fonts"].include?(k)}.map { |k, v| [k.to_sym, v] }.to_h
66
71
  coll = Metanorma::Collection.parse filename
67
72
  coll.render opts
68
73
  else UI.say("Need to specify a file to process")
@@ -89,9 +94,23 @@ module Metanorma
89
94
  UI.say("Couldn't load #{type}, please provide a valid type!")
90
95
  end
91
96
 
97
+ desc "list-doctypes", "List supported doctypes"
98
+ def list_doctypes(type = nil)
99
+ processors = backend_processors
100
+
101
+ if type && processors[type.to_sym]
102
+ processors = { type.to_sym => processors[type.to_sym] }
103
+ end
104
+
105
+ print_doctypes_table(processors)
106
+ end
107
+
92
108
  desc "template-repo", "Manage metanorma templates repository"
93
109
  subcommand :template_repo, Metanorma::Cli::Commands::TemplateRepo
94
110
 
111
+ desc "site", "Manage site for metanorma collections"
112
+ subcommand :site, Metanorma::Cli::Commands::Site
113
+
95
114
  private
96
115
 
97
116
  def single_type_extensions(type)
@@ -120,6 +139,13 @@ module Metanorma
120
139
  end
121
140
  end
122
141
 
142
+ def backend_processors
143
+ @backend_processors ||= (
144
+ Metanorma::Cli.load_flavors
145
+ Metanorma::Registry.instance.processors
146
+ )
147
+ end
148
+
123
149
  def find_backend(type)
124
150
  load_flavours(type)
125
151
  Metanorma::Registry.instance.find_processor(type&.to_sym)
@@ -156,6 +182,18 @@ module Metanorma
156
182
  require "metanorma-#{type}"
157
183
  end
158
184
  end
185
+
186
+ def print_doctypes_table(processors)
187
+ table_data = processors.map do |type_sym, processor|
188
+ [
189
+ type_sym.to_s,
190
+ processor.input_format,
191
+ join_keys(processor.output_formats.keys),
192
+ ]
193
+ end
194
+
195
+ UI.table(["Type", "Input", "Supported output format"], table_data)
196
+ end
159
197
  end
160
198
  end
161
199
  end
@@ -0,0 +1,26 @@
1
+ require "pathname"
2
+ require "metanorma/cli/site_generator"
3
+
4
+ module Metanorma
5
+ module Cli
6
+ module Commands
7
+ class Site < Thor
8
+ desc "generate SOURCE_PATH", "Geneate site from collection"
9
+ option :config, aliases: "-c", desc: "The metanorma configuration file"
10
+ option(
11
+ :output_dir,
12
+ aliases: "-o",
13
+ default: Pathname.new(Dir.pwd).join("site").to_s,
14
+ desc: "Output directory for the generated site",
15
+ )
16
+
17
+ def generate(source_path)
18
+ Cli::SiteGenerator.generate(source_path, options.dup)
19
+ UI.say("Site has been generated at #{options[:output_dir]}")
20
+ rescue Cli::Errors::InvalidManifestFileError
21
+ UI.error("Invalid data in: #{options[:config]}")
22
+ end
23
+ end
24
+ end
25
+ end
26
+ end
@@ -4,6 +4,7 @@ module Metanorma
4
4
  class DuplicateTemplateError < StandardError; end
5
5
 
6
6
  class FileNotFoundError < StandardError; end
7
+ class InvalidManifestFileError < StandardError; end
7
8
  end
8
9
  end
9
10
  end
@@ -0,0 +1,134 @@
1
+ require "yaml"
2
+ require "pathname"
3
+ require "fileutils"
4
+
5
+ module Metanorma
6
+ module Cli
7
+ class SiteGenerator
8
+ def initialize(source, options = {})
9
+ @source = find_realpath(source)
10
+ @site_path = options.fetch(:output_dir, "site").to_s
11
+ @asset_folder = options.fetch(:asset_folder, "documents").to_s
12
+ @collection_name = options.fetch(:collection_name, "documents.xml")
13
+ @manifest_file = find_realpath(options.fetch(:config, default_config))
14
+
15
+ ensure_site_asset_directory!
16
+ end
17
+
18
+ def self.generate(source, options = {})
19
+ new(source, options).generate
20
+ end
21
+
22
+ def generate
23
+ site_directory = asset_directory.join("..")
24
+ select_source_files.each { |source| compile(source) }
25
+
26
+ Dir.chdir(site_directory) do
27
+ build_collection_file(collection_name)
28
+ convert_to_html_page(collection_name, "index.html")
29
+ end
30
+ end
31
+
32
+ private
33
+
34
+ attr_reader :source, :asset_folder, :asset_directory
35
+ attr_reader :site_path, :manifest_file, :collection_name
36
+
37
+ def find_realpath(source_path)
38
+ Pathname.new(source_path.to_s).realpath if source_path
39
+ rescue Errno::ENOENT
40
+ source_path
41
+ end
42
+
43
+ def default_config
44
+ default_file = Pathname.new(Dir.pwd).join("metanorma.yml")
45
+ default_file if File.exist?(default_file)
46
+ end
47
+
48
+ def select_source_files
49
+ files = source_from_manifest
50
+
51
+ if files.empty?
52
+ files = Dir[File.join(source, "**", "*.adoc")]
53
+ end
54
+
55
+ files.flatten.uniq.reject { |file| File.directory?(file) }
56
+ end
57
+
58
+ def build_collection_file(collection_name)
59
+ collection_path = [site_path, collection_name].join("/")
60
+ UI.info("Building collection file: #{collection_path} ...")
61
+
62
+ Relaton::Cli::RelatonFile.concatenate(
63
+ asset_folder,
64
+ collection_name,
65
+ title: manifest[:collection_name],
66
+ organization: manifest[:collection_organization],
67
+ )
68
+ end
69
+
70
+ def compile(source)
71
+ UI.info("Compiling #{source} ...")
72
+
73
+ Metanorma::Cli::Compiler.compile(
74
+ source.to_s, format: :asciidoc, "output-dir" => asset_directory
75
+ )
76
+ end
77
+
78
+ def convert_to_html_page(collection, page_name)
79
+ UI.info("Generating html site in #{site_path} ...")
80
+
81
+ Relaton::Cli::XMLConvertor.to_html(collection)
82
+ File.rename(Pathname.new(collection).sub_ext(".html").to_s, page_name)
83
+ end
84
+
85
+ def manifest
86
+ @manifest ||= config_from_manifest || {
87
+ files: [], collection_name: "", collection_organization: ""
88
+ }
89
+ end
90
+
91
+ def config_from_manifest
92
+ if manifest_file
93
+ manifest_config(YAML.safe_load(File.read(manifest_file.to_s)))
94
+ end
95
+ end
96
+
97
+ def manifest_config(manifest)
98
+ {
99
+ files: extract_config_data(
100
+ manifest["metanorma"]["source"], "files"
101
+ ) || [],
102
+
103
+ collection_name: extract_config_data(
104
+ manifest["relaton"]["collection"], "name"
105
+ ),
106
+
107
+ collection_organization: extract_config_data(
108
+ manifest["relaton"]["collection"], "organization"
109
+ ),
110
+ }
111
+ rescue NoMethodError
112
+ raise Errors::InvalidManifestFileError.new("Invalid manifest file")
113
+ end
114
+
115
+ def extract_config_data(node, key)
116
+ node ? node[key] : nil
117
+ end
118
+
119
+ def source_from_manifest
120
+ @source_from_manifest ||= manifest[:files].map do |source_file|
121
+ file_path = source.join(source_file).to_s
122
+ file_path.include?("*") ? Dir.glob(file_path) : file_path
123
+ end.flatten
124
+ end
125
+
126
+ def ensure_site_asset_directory!
127
+ asset_path = [site_path, asset_folder].join("/")
128
+ @asset_directory = Pathname.new(Dir.pwd).join(asset_path)
129
+
130
+ FileUtils.mkdir_p(@asset_directory) unless @asset_directory.exist?
131
+ end
132
+ end
133
+ end
134
+ end
@@ -11,10 +11,18 @@ module Metanorma
11
11
  new.say(message)
12
12
  end
13
13
 
14
+ def self.info(message)
15
+ new.say(["[info]", message].join(": "))
16
+ end
17
+
14
18
  def self.error(message)
15
19
  new.error(message)
16
20
  end
17
21
 
22
+ def self.table(header, data)
23
+ new.print_table(data.unshift(header))
24
+ end
25
+
18
26
  def self.run(command)
19
27
  require "open3"
20
28
  Open3.capture3(command)
@@ -1,5 +1,5 @@
1
1
  module Metanorma
2
2
  module Cli
3
- VERSION = "1.3.9"
3
+ VERSION = "1.4.1"
4
4
  end
5
5
  end
@@ -37,23 +37,24 @@ Gem::Specification.new do |spec|
37
37
  spec.add_development_dependency "sassc"
38
38
 
39
39
  spec.add_runtime_dependency "thor", "~> 1.0"
40
- spec.add_runtime_dependency "metanorma-iso", "~> 1.5.0"
40
+ spec.add_runtime_dependency "metanorma-iso", "~> 1.6.0"
41
41
  spec.add_runtime_dependency "metanorma-ietf", "~> 2.2.0"
42
42
  #spec.add_runtime_dependency "metanorma-gb", "~> 1.5.0"
43
43
  spec.add_runtime_dependency "metanorma-iec", "~> 1.2.0"
44
44
  spec.add_runtime_dependency "metanorma-cc", "~> 1.6.0"
45
- spec.add_runtime_dependency "metanorma-csa", "~> 1.6.0"
45
+ spec.add_runtime_dependency "metanorma-csa", "~> 1.7.0"
46
46
  #spec.add_runtime_dependency 'metanorma-ribose', "~> 1.6.0"
47
47
  spec.add_runtime_dependency "metanorma-m3aawg", "~> 1.6.0"
48
- spec.add_runtime_dependency "metanorma-generic", "~> 1.8.0"
49
- spec.add_runtime_dependency "metanorma-standoc", "~> 1.6.0"
48
+ spec.add_runtime_dependency "metanorma-bipm", "~> 1.0.0"
49
+ spec.add_runtime_dependency "metanorma-generic", "~> 1.8.2"
50
+ spec.add_runtime_dependency "metanorma-standoc", "~> 1.7.0"
50
51
  #spec.add_runtime_dependency 'metanorma-mpfa', "~> 0.5.0"
51
52
  spec.add_runtime_dependency "metanorma-un", "~> 0.5.0"
52
53
  spec.add_runtime_dependency "metanorma-ogc", "~> 1.2.0"
53
54
  spec.add_runtime_dependency "metanorma-nist", "~> 1.2.0"
54
55
  spec.add_runtime_dependency "metanorma-itu", "~> 1.2.0"
55
56
  spec.add_runtime_dependency "metanorma-iho", "~> 0.2.0"
56
- spec.add_runtime_dependency "isodoc", ">= 1.3.0"
57
+ spec.add_runtime_dependency "isodoc", ">= 1.4.2"
57
58
  spec.add_runtime_dependency "metanorma", "~> 1.2.0"
58
59
  spec.add_runtime_dependency "git", "~> 1.5"
59
60
  spec.add_runtime_dependency "relaton-cli", ">= 0.8.2"
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: metanorma-cli
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.3.9
4
+ version: 1.4.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ribose Inc.
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2020-12-04 00:00:00.000000000 Z
11
+ date: 2021-01-11 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: pry
@@ -170,14 +170,14 @@ dependencies:
170
170
  requirements:
171
171
  - - "~>"
172
172
  - !ruby/object:Gem::Version
173
- version: 1.5.0
173
+ version: 1.6.0
174
174
  type: :runtime
175
175
  prerelease: false
176
176
  version_requirements: !ruby/object:Gem::Requirement
177
177
  requirements:
178
178
  - - "~>"
179
179
  - !ruby/object:Gem::Version
180
- version: 1.5.0
180
+ version: 1.6.0
181
181
  - !ruby/object:Gem::Dependency
182
182
  name: metanorma-ietf
183
183
  requirement: !ruby/object:Gem::Requirement
@@ -226,14 +226,14 @@ dependencies:
226
226
  requirements:
227
227
  - - "~>"
228
228
  - !ruby/object:Gem::Version
229
- version: 1.6.0
229
+ version: 1.7.0
230
230
  type: :runtime
231
231
  prerelease: false
232
232
  version_requirements: !ruby/object:Gem::Requirement
233
233
  requirements:
234
234
  - - "~>"
235
235
  - !ruby/object:Gem::Version
236
- version: 1.6.0
236
+ version: 1.7.0
237
237
  - !ruby/object:Gem::Dependency
238
238
  name: metanorma-m3aawg
239
239
  requirement: !ruby/object:Gem::Requirement
@@ -248,34 +248,48 @@ dependencies:
248
248
  - - "~>"
249
249
  - !ruby/object:Gem::Version
250
250
  version: 1.6.0
251
+ - !ruby/object:Gem::Dependency
252
+ name: metanorma-bipm
253
+ requirement: !ruby/object:Gem::Requirement
254
+ requirements:
255
+ - - "~>"
256
+ - !ruby/object:Gem::Version
257
+ version: 1.0.0
258
+ type: :runtime
259
+ prerelease: false
260
+ version_requirements: !ruby/object:Gem::Requirement
261
+ requirements:
262
+ - - "~>"
263
+ - !ruby/object:Gem::Version
264
+ version: 1.0.0
251
265
  - !ruby/object:Gem::Dependency
252
266
  name: metanorma-generic
253
267
  requirement: !ruby/object:Gem::Requirement
254
268
  requirements:
255
269
  - - "~>"
256
270
  - !ruby/object:Gem::Version
257
- version: 1.8.0
271
+ version: 1.8.2
258
272
  type: :runtime
259
273
  prerelease: false
260
274
  version_requirements: !ruby/object:Gem::Requirement
261
275
  requirements:
262
276
  - - "~>"
263
277
  - !ruby/object:Gem::Version
264
- version: 1.8.0
278
+ version: 1.8.2
265
279
  - !ruby/object:Gem::Dependency
266
280
  name: metanorma-standoc
267
281
  requirement: !ruby/object:Gem::Requirement
268
282
  requirements:
269
283
  - - "~>"
270
284
  - !ruby/object:Gem::Version
271
- version: 1.6.0
285
+ version: 1.7.0
272
286
  type: :runtime
273
287
  prerelease: false
274
288
  version_requirements: !ruby/object:Gem::Requirement
275
289
  requirements:
276
290
  - - "~>"
277
291
  - !ruby/object:Gem::Version
278
- version: 1.6.0
292
+ version: 1.7.0
279
293
  - !ruby/object:Gem::Dependency
280
294
  name: metanorma-un
281
295
  requirement: !ruby/object:Gem::Requirement
@@ -352,14 +366,14 @@ dependencies:
352
366
  requirements:
353
367
  - - ">="
354
368
  - !ruby/object:Gem::Version
355
- version: 1.3.0
369
+ version: 1.4.2
356
370
  type: :runtime
357
371
  prerelease: false
358
372
  version_requirements: !ruby/object:Gem::Requirement
359
373
  requirements:
360
374
  - - ">="
361
375
  - !ruby/object:Gem::Version
362
- version: 1.3.0
376
+ version: 1.4.2
363
377
  - !ruby/object:Gem::Dependency
364
378
  name: metanorma
365
379
  requirement: !ruby/object:Gem::Requirement
@@ -447,11 +461,13 @@ files:
447
461
  - lib/metanorma-cli.rb
448
462
  - lib/metanorma/cli.rb
449
463
  - lib/metanorma/cli/command.rb
464
+ - lib/metanorma/cli/commands/site.rb
450
465
  - lib/metanorma/cli/commands/template_repo.rb
451
466
  - lib/metanorma/cli/compiler.rb
452
467
  - lib/metanorma/cli/errors.rb
453
468
  - lib/metanorma/cli/generator.rb
454
469
  - lib/metanorma/cli/git_template.rb
470
+ - lib/metanorma/cli/site_generator.rb
455
471
  - lib/metanorma/cli/template_repo.rb
456
472
  - lib/metanorma/cli/ui.rb
457
473
  - lib/metanorma/cli/version.rb