j1-template 2022.0.14 → 2022.0.18

Sign up to get free protection for your applications and to get access to all the features.
Files changed (83) hide show
  1. checksums.yaml +4 -4
  2. data/assets/error_pages/HTTP204.html +1 -1
  3. data/assets/error_pages/HTTP400.html +1 -1
  4. data/assets/error_pages/HTTP401.html +1 -1
  5. data/assets/error_pages/HTTP403.html +1 -1
  6. data/assets/error_pages/HTTP404.html +1 -1
  7. data/assets/error_pages/HTTP444.html +1 -1
  8. data/assets/error_pages/HTTP445.html +1 -1
  9. data/assets/error_pages/HTTP446.html +1 -1
  10. data/assets/error_pages/HTTP447.html +1 -1
  11. data/assets/error_pages/HTTP448.html +1 -1
  12. data/assets/error_pages/HTTP500.html +1 -1
  13. data/assets/error_pages/HTTP501.html +1 -1
  14. data/assets/error_pages/HTTP502.html +1 -1
  15. data/assets/error_pages/HTTP503.html +1 -1
  16. data/assets/themes/j1/adapter/js/clipboard.js +1 -1
  17. data/assets/themes/j1/adapter/js/customFunctions.js +221 -0
  18. data/assets/themes/j1/adapter/js/customModule.js +221 -0
  19. data/assets/themes/j1/adapter/js/dropdowns.js +319 -0
  20. data/assets/themes/j1/adapter/js/rtable.js +2 -6
  21. data/assets/themes/j1/core/css/vendor.css +6 -1
  22. data/assets/themes/j1/core/css/vendor.min.css +1 -1
  23. data/assets/themes/j1/core/js/template.js +4 -3
  24. data/assets/themes/j1/core/js/template.min.js +1 -1
  25. data/assets/themes/j1/core/js/template.min.js.map +1 -1
  26. data/assets/themes/j1/modules/dropdowns/css/theme/uno/dropdowns.css +109 -0
  27. data/assets/themes/j1/modules/dropdowns/css/theme/uno/dropdowns.min.css +15 -0
  28. data/assets/themes/j1/modules/dropdowns/js/cash.js +978 -0
  29. data/assets/themes/j1/modules/dropdowns/js/dropdowns.js +864 -0
  30. data/exe/j1 +31 -11
  31. data/lib/j1/commands/generate.rb +48 -42
  32. data/lib/j1/commands/help.rb +35 -0
  33. data/lib/j1/commands/patch.rb +76 -0
  34. data/lib/j1/commands/rebuild.rb +42 -0
  35. data/lib/j1/commands/reset.rb +44 -0
  36. data/lib/j1/commands/setup.rb +123 -0
  37. data/lib/j1/commands/site.rb +36 -0
  38. data/lib/j1/external.rb +1 -1
  39. data/lib/j1/utils/{exec.rb → exec1.rb} +1 -1
  40. data/lib/j1/utils/exec2.rb +57 -0
  41. data/lib/j1/utils.rb +55 -1
  42. data/lib/j1/version.rb +1 -1
  43. data/lib/starter_web/Gemfile +1 -1
  44. data/lib/starter_web/_config.yml +1 -1
  45. data/lib/starter_web/_data/apps/carousel.yml +138 -140
  46. data/lib/starter_web/_data/blocks/banner.yml +7 -7
  47. data/lib/starter_web/_data/modules/defaults/dropdowns.yml +164 -0
  48. data/lib/starter_web/_data/modules/defaults/themer.yml +3 -2
  49. data/lib/starter_web/_data/modules/dropdowns.yml +77 -0
  50. data/lib/starter_web/_data/modules/themer.yml +2 -1
  51. data/lib/starter_web/_data/resources.yml +73 -2
  52. data/lib/starter_web/_includes/attributes.asciidoc +1 -1
  53. data/lib/starter_web/_plugins/lunr_index.rb +2 -2
  54. data/lib/starter_web/package.json +6 -2
  55. data/lib/starter_web/pages/public/about/about_site.adoc +1 -1
  56. data/lib/starter_web/pages/public/asciidoc_skeletons/documentation/000_intro.adoc +1 -1
  57. data/lib/starter_web/pages/public/asciidoc_skeletons/documentation/documentation.adoc +1 -1
  58. data/lib/starter_web/pages/public/asciidoc_skeletons/multi-document/multi.adoc +1 -1
  59. data/lib/starter_web/pages/public/asciidoc_skeletons/simple-document/simple.adoc +1 -1
  60. data/lib/starter_web/pages/public/learn/roundtrip/100_present_images.adoc +1 -1
  61. data/lib/starter_web/pages/public/learn/roundtrip/100_present_images.ads.asciidoc +1 -1
  62. data/lib/starter_web/pages/public/learn/roundtrip/100_present_images.base.asciidoc +1 -1
  63. data/lib/starter_web/pages/public/learn/roundtrip/100_present_images.comments.asciidoc +1 -1
  64. data/lib/starter_web/pages/public/learn/roundtrip/200_typography.adoc +1 -1
  65. data/lib/starter_web/pages/public/learn/roundtrip/300_icon_fonts.adoc +1 -1
  66. data/lib/starter_web/pages/public/learn/roundtrip/400_asciidoc_extensions.adoc +8 -8
  67. data/lib/starter_web/pages/public/learn/roundtrip/410_bs_modals_extentions.adoc +1 -1
  68. data/lib/starter_web/pages/public/learn/roundtrip/420_responsive_tables_extensions.adoc +1 -1
  69. data/lib/starter_web/pages/public/learn/roundtrip/500_themes.adoc +1 -1
  70. data/lib/starter_web/pages/public/learn/roundtrip/600_quicksearch.adoc +1 -1
  71. data/lib/starter_web/pages/public/learn/where_to_go.adoc +1 -1
  72. data/lib/starter_web/pages/public/legal/en/100_copyright.adoc +1 -1
  73. data/lib/starter_web/pages/public/legal/en/200_impress.adoc +1 -1
  74. data/lib/starter_web/pages/public/legal/en/400_comment_policy.adoc +1 -1
  75. data/lib/starter_web/pages/public/manuals/j1-dropdown.adoc +294 -0
  76. data/lib/starter_web/pages/public/manuals/{dropdown-help.adoc → msdropdown.adoc} +0 -0
  77. data/lib/starter_web/pages/public/panels/intro_panel/panel.adoc +1 -1
  78. data/lib/starter_web/pages/public/previewer/preview_bootstrap_theme.adoc +1 -1
  79. data/lib/starter_web/utilsrv/_defaults/package.json +1 -1
  80. data/lib/starter_web/utilsrv/package.json +1 -1
  81. metadata +22 -7
  82. data/assets/themes/j1/modules/fab/css/theme/uno/fab.css +0 -373
  83. data/assets/themes/j1/modules/fab/css/theme/uno/fab.min.css +0 -15
data/exe/j1 CHANGED
@@ -11,17 +11,37 @@ Mercenary.program(:j1) do |p|
11
11
  p.description 'J1 Template is a gem-based Template made for Jekyll'
12
12
  p.syntax 'j1 <subcommand> [options]'
13
13
 
14
- p.command(:generate) do |c|
15
- c.description 'Generates a starter site scaffold in PATH'
16
- c.syntax 'generate PATH'
17
- c.option 'force', '--force', ' Force a site to be created even the PATH already exists'
18
- c.option 'skip-bundle', '--skip-bundle', ' Skip bundle install'
19
- c.option 'skip-patches', '--skip-patches', ' Skip install any PATCHES buildin with J1'
20
- c.option 'system', '--system', ' Run "bundle install" for the Ruby SYSTEM gem folder'
21
- c.action do |args, options|
22
- J1::Commands::Generate.process(args, options)
14
+ # available options for all subcommands
15
+ #
16
+ # p.option 'force', '--force'
17
+ # p.option 'skip-bundle', '--skip-bundle'
18
+ # p.option 'skip-patches', '--skip-patches'
19
+ # p.option 'system', '--system'
20
+
21
+ # J1::External.require_if_present(J1::External.blessed_gems) do |g, ver_constraint|
22
+ # cmd = g.split("-").last
23
+ # p.command(cmd.to_sym) do |c|
24
+ # c.syntax cmd
25
+ # c.action do
26
+ # J1.logger.abort_with "You must install the '#{g}' gem" \
27
+ # " version #{ver_constraint} to use the 'jekyll #{cmd}' command."
28
+ # end
29
+ # end
30
+ # end
31
+
32
+ J1::Command.subclasses.each { |c| c.init_with_program(p) }
33
+
34
+ p.action do |args, _|
35
+ if args.empty?
36
+ J1.logger.error "A subcommand is required."
37
+ puts p
38
+ abort
39
+ else
40
+ subcommand = args.first
41
+ unless p.has_command? subcommand
42
+ J1.logger.abort_with "fatal: 'j1 #{args.first}' failed." \
43
+ " No subcommand '#{args.first}' available."
44
+ end
23
45
  end
24
46
  end
25
-
26
- p.default_command(:generate)
27
47
  end
@@ -1,36 +1,34 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'erb'
2
- require 'rbconfig'
3
- require 'fileutils'
4
4
 
5
5
  module J1
6
6
  module Commands
7
7
  class Generate < Command
8
8
  class << self
9
9
 
10
- # def init_with_program(prog)
11
- # prog.command(:generate) do |c|
12
- # c.description 'Generates a starter site scaffold in PATH'
13
- # c.syntax 'generate PATH'
14
- # c.option 'force', '--force', 'Force a site to be created even the PATH already exists'
15
- # c.option 'skip-bundle', '--skip-bundle', 'Skip bundle install'
16
- # c.option 'skip-patches', '--skip-patches', 'Skip install any PATCHES buildin with J1'
17
- # c.option 'system', '--system', 'Run "bundle install" for the Ruby SYSTEM gem folder'
18
- # c.action do |args, options|
19
- # J1::Commands::Generate.process(args, options)
20
- # end
21
- # end
22
- # end
23
-
24
- def is_windows?
25
- RbConfig::CONFIG["host_os"] =~ %r!mswin|mingw|cygwin!i
10
+ def init_with_program(prog)
11
+ prog.command(:generate) do |c|
12
+ c.description 'Generates a J1 project scaffold in PATH'
13
+ c.syntax 'generate PATH'
14
+ c.option 'force', '--force', 'Force a site to be created even the PATH already exists'
15
+ c.option 'skip-bundle', '--skip-bundle', 'Skip bundle install'
16
+ c.option 'skip-patches', '--skip-patches', 'Skip install any PATCHES build-in with J1'
17
+ c.option 'system', '--system', 'Run "bundle install" for the Ruby SYSTEM gem folder'
18
+ c.action do |args, options|
19
+ J1::Commands::Generate.process(args, options)
20
+ end
21
+ end
26
22
  end
27
23
 
28
24
  def process(args, options = {})
29
- raise ArgumentError, 'You must specify a path.' if args.empty?
25
+ timestamp = Time.now.strftime("%Y-%m-%d %H:%M:%S")
26
+ raise ArgumentError, "#{timestamp} - GENERATE: You must specify a path." if args.empty?
27
+
30
28
  new_blog_path = File.expand_path(args.join(' '), Dir.pwd)
31
29
  FileUtils.mkdir_p new_blog_path
32
30
  if preserve_source_location?(new_blog_path, options)
33
- J1.logger.abort_with 'Conflict:', "#{new_blog_path} exists and is not empty."
31
+ J1.logger.abort_with "#{timestamp} - GENERATE: Conflict:", "#{new_blog_path} exists and is not empty."
34
32
  end
35
33
 
36
34
  if options['blank']
@@ -40,6 +38,8 @@ module J1
40
38
  end
41
39
 
42
40
  after_install(new_blog_path, options)
41
+ timestamp = Time.now.strftime("%Y-%m-%d %H:%M:%S")
42
+ J1.logger.info "#{timestamp} - GENERATE: To setup the site, change to the project folder #{new_blog_path} and run: j1 setup"
43
43
  end
44
44
 
45
45
  def create_blank_site(path)
@@ -90,42 +90,44 @@ module J1
90
90
  # then automatically execute bundle install from within the generate blog dir
91
91
  # unless the user opts to generate a blank blog or skip 'bundle install'.
92
92
  def after_install(path, options = {})
93
+ timestamp = Time.now.strftime("%Y-%m-%d %H:%M:%S")
93
94
  unless options['skip-bundle']
94
95
  bundle_install(path, options)
95
- unless options['skip-patches']
96
- patch_install(options)
96
+ if options['skip-patches']
97
+ J1.logger.info "#{timestamp} - GENERATE: Install build-in patches skipped ..."
97
98
  else
98
- J1.logger.info "Install build-in patches skipped ..."
99
+ patch_install(options)
99
100
  end
100
101
  end
101
- unless options['force']
102
- J1.logger.info "Generated Jekyll site installed in folder #{path}"
102
+ timestamp = Time.now.strftime("%Y-%m-%d %H:%M:%S")
103
+ if options['force']
104
+ J1.logger.info "#{timestamp} - GENERATE: Generated Jekyll site force installed in folder #{path}"
103
105
  else
104
- J1.logger.info "Generated Jekyll site force installed in folder #{path}"
106
+ J1.logger.info "#{timestamp} - GENERATE: Generated Jekyll site installed in folder #{path}"
105
107
  end
106
- J1.logger.info 'Installation (bundle) of RubyGems skipped' if options['skip-bundle']
108
+ J1.logger.info "#{timestamp} - GENERATE: Installation (bundle) of RubyGems skipped" if options['skip-bundle']
107
109
  end
108
110
 
109
111
  def bundle_install(path, options)
112
+ timestamp = Time.now.strftime("%Y-%m-%d %H:%M:%S")
110
113
  J1::External.require_with_graceful_fail 'bundler'
111
- J1.logger.info "Running bundle install in #{path} ..."
114
+ J1.logger.info "#{timestamp} - GENERATE: Running bundle install in #{path} ..."
112
115
  Dir.chdir(path) do
113
116
  if options['system']
114
- J1.logger.info "Install bundle in Ruby gem SYSTEM folder ..."
117
+ J1.logger.info "#{timestamp} - GENERATE: Install bundle in Ruby gem SYSTEM folder ..."
115
118
  else
116
- J1.logger.info "Install bundle in USER gem folder ~/.gem ..."
117
- process, output = J1::Utils::Exec.run('bundle', 'config', 'set', '--local', 'path', '~/.gem')
118
- end
119
- process, output = J1::Utils::Exec.run('bundle', 'install')
120
- output.to_s.each_line do |line|
121
- J1.logger.info('Bundler:', line.strip) unless line.to_s.empty?
119
+ J1.logger.info "#{timestamp} - GENERATE: Install bundle in USER gem folder ~/.gem ..."
120
+ process = J1::Utils::Exec2.run('GENERATE','bundle', 'config', 'set', '--local', 'path', '~/.gem')
121
+ raise SystemExit unless process.success?
122
122
  end
123
+ process = J1::Utils::Exec2.run( 'GENERATE', 'bundle', 'install')
123
124
  raise SystemExit unless process.success?
124
125
  end
125
126
  end
126
127
 
127
128
  def patch_install(options)
128
- if is_windows?
129
+ timestamp = Time.now.strftime("%Y-%m-%d %H:%M:%S")
130
+ if J1::Utils::is_windows?
129
131
  major, minor = RUBY_VERSION.split('.')
130
132
  lib_version = major + '.' + minor
131
133
  curr_path = File.expand_path(File.dirname(File.dirname(__FILE__)))
@@ -134,20 +136,24 @@ module J1
134
136
  patch_eventmachine_source_path = curr_path + '/patches/rubygems' + '/' + patch_gem_eventmachine + '/lib/' + lib_version
135
137
  patch_execjs_source_path = curr_path + '/patches/rubygems' + '/' + patch_gem_execjs + '/lib/execjs/external_runtime.rb'
136
138
 
137
- process, output = J1::Utils::Exec.run('gem', 'env', 'gempath')
139
+ process, output = J1::Utils::Exec1.run('gem', 'env', 'gempath')
140
+ output.to_s.each_line do |line|
141
+ J1.logger.info("#{timestamp} - GENERATE: ", line.strip) unless line.to_s.empty?
142
+ end
138
143
  raise SystemExit unless process.success?
139
144
 
140
145
  result = output.split(';')
141
146
  user_path = result[0]
142
147
  system_path = result[1]
148
+ timestamp = Time.now.strftime("%Y-%m-%d %H:%M:%S")
143
149
 
144
150
  if options['system']
145
- J1.logger.info "Install patches in SYSTEM folder ..."
146
- J1.logger.info "Install patches on path #{system_path} ..."
151
+ J1.logger.info "#{timestamp} - GENERATE: Install patches in SYSTEM folder ..."
152
+ J1.logger.info "#{timestamp} - GENERATE: Install patches on path #{system_path} ..."
147
153
  dest = system_path + '/gems/' + patch_gem_eventmachine + '/lib'
148
154
  else
149
- J1.logger.info "Install patches in USER gem folder ~/.gem ..."
150
- J1.logger.info "Install patches on path #{user_path} ..."
155
+ J1.logger.info "#{timestamp} - GENERATE: Install patches in USER gem folder ~/.gem ..."
156
+ J1.logger.info "#{timestamp} - GENERATE: Install patches on path #{user_path} ..."
151
157
  dest = user_path + '/gems/' + patch_gem_eventmachine + '/lib'
152
158
  end
153
159
  src = patch_eventmachine_source_path
@@ -163,7 +169,7 @@ module J1
163
169
  if Dir.exist?(dest)
164
170
  FileUtils.cp(src, dest)
165
171
  else
166
- J1.logger.info "Skipped install patches for execjs-2.7.0 ..."
172
+ J1.logger.info "#{timestamp} - GENERATE: Skipped install patches for execjs-2.7.0 ..."
167
173
  end
168
174
  end
169
175
 
@@ -0,0 +1,35 @@
1
+ # frozen_string_literal: true
2
+
3
+ module J1
4
+ module Commands
5
+ class Help < Command
6
+ class << self
7
+
8
+ def init_with_program(prog)
9
+ prog.command(:help) do |c|
10
+ c.syntax "help [subcommand]"
11
+ c.description "Show the help message, optionally for a given subcommand"
12
+
13
+ c.action do |args, _|
14
+ cmd = (args.first || "").to_sym
15
+ if args.empty?
16
+ J1.logger.info prog.to_s
17
+ elsif prog.has_command? cmd
18
+ J1.logger.info prog.commands[cmd].to_s
19
+ else
20
+ invalid_command(prog, cmd)
21
+ abort
22
+ end
23
+ end
24
+ end
25
+ end
26
+
27
+ def invalid_command(prog, cmd)
28
+ J1.logger.error "Error:",
29
+ "Hmm... we don't know what the '#{cmd}' command is."
30
+ J1.logger.info "Valid commands:", prog.commands.keys.join(", ")
31
+ end
32
+ end
33
+ end
34
+ end
35
+ end
@@ -0,0 +1,76 @@
1
+ # frozen_string_literal: true
2
+
3
+ module J1
4
+ module Commands
5
+ class Patch < Command
6
+ #noinspection MissingYardParamTag
7
+ class << self
8
+
9
+ def init_with_program(prog)
10
+ prog.command(:patch) do |c|
11
+ c.description 'Install patches available for J1 projects'
12
+ c.syntax 'patch'
13
+ c.option 'force', '--force', 'Force to install patches even already exists'
14
+ c.option 'system', '--system', 'Install patches on the Ruby SYSTEM gem folder'
15
+ c.action do |args, options|
16
+ J1::Commands::Patch.process(args, options)
17
+ end
18
+ end
19
+ end
20
+
21
+ def process(args, options = {})
22
+ @args = args
23
+ patch_install(options)
24
+ end
25
+
26
+ private
27
+
28
+ def patch_install(options)
29
+ if J1::Utils::is_windows?
30
+ major, minor = RUBY_VERSION.split('.')
31
+ lib_version = major + '.' + minor
32
+ curr_path = File.expand_path(File.dirname(File.dirname(__FILE__)))
33
+ patch_gem_eventmachine = 'eventmachine-1.2.7-x64-mingw32'
34
+ patch_gem_execjs = 'execjs-2.7.0'
35
+ patch_eventmachine_source_path = curr_path + '/patches/rubygems' + '/' + patch_gem_eventmachine + '/lib/' + lib_version
36
+ patch_execjs_source_path = curr_path + '/patches/rubygems' + '/' + patch_gem_execjs + '/lib/execjs/external_runtime.rb'
37
+
38
+ process, output = J1::Utils::Exec1.run('gem', 'env', 'gempath')
39
+ raise SystemExit unless process.success?
40
+
41
+ result = output.split(';')
42
+ user_path = result[0]
43
+ system_path = result[1]
44
+
45
+ if options['system']
46
+ J1.logger.info "PATCH: Install patches in SYSTEM folder ..."
47
+ J1.logger.info "PATCH: Install patches on path #{system_path} ..."
48
+ dest = system_path + '/gems/' + patch_gem_eventmachine + '/lib'
49
+ else
50
+ J1.logger.info "PATCH: Install patches in USER gem folder ~/.gem ..."
51
+ J1.logger.info "PATCH: Install patches on path #{user_path} ..."
52
+ dest = user_path + '/gems/' + patch_gem_eventmachine + '/lib'
53
+ end
54
+ src = patch_eventmachine_source_path
55
+ FileUtils.cp_r(src, dest)
56
+
57
+ if lib_version === '2.7'
58
+ if options['system']
59
+ dest = system_path + '/gems/' + patch_gem_execjs + '/lib/execjs'
60
+ else
61
+ dest = user_path + '/gems/' + patch_gem_execjs + '/lib/execjs'
62
+ end
63
+ src = patch_execjs_source_path
64
+ if Dir.exist?(dest)
65
+ FileUtils.cp(src, dest)
66
+ else
67
+ J1.logger.info "PATCH: Skipped install patches for execjs-2.7.0 ..."
68
+ end
69
+ end
70
+
71
+ end
72
+ end
73
+ end
74
+ end
75
+ end
76
+ end
@@ -0,0 +1,42 @@
1
+ # frozen_string_literal: true
2
+
3
+ module J1
4
+ module Commands
5
+ class Rebuild < Command
6
+ #noinspection MissingYardParamTag
7
+ class << self
8
+
9
+ def init_with_program(prog)
10
+ prog.command(:rebuild) do |c|
11
+ c.description 'Rebuild the J1 projects website'
12
+ c.syntax 'rebuild'
13
+ c.action do |args, options|
14
+ J1::Commands::Rebuild.process(args, options)
15
+ end
16
+ end
17
+ end
18
+
19
+ def process(args, options = {})
20
+ if J1::Utils::is_project?
21
+ if J1::Utils::is_project_setup?
22
+ J1.logger.info "REBUILD: Rebuild the projects website ..."
23
+ J1.logger.info "REBUILD: Be patient, this will take a while ..."
24
+ process = J1::Utils::Exec2.run('REBUILD','npm', 'run', 'rebuild')
25
+ if process.success?
26
+ J1.logger.info "REBUILD: The projects website has been rebuild successfully."
27
+ J1.logger.info "REBUILD: To open the site, run: j1 site"
28
+ else
29
+ raise SystemExit
30
+ end
31
+ else
32
+ raise SystemExit
33
+ end
34
+ else
35
+ raise SystemExit
36
+ end
37
+ end
38
+
39
+ end
40
+ end
41
+ end
42
+ end
@@ -0,0 +1,44 @@
1
+ # frozen_string_literal: true
2
+
3
+ module J1
4
+ module Commands
5
+ class Reset < Command
6
+ #noinspection MissingYardParamTag
7
+ class << self
8
+
9
+ def init_with_program(prog)
10
+ prog.command(:reset) do |c|
11
+ c.description 'Reset a J1 project to factory state'
12
+ c.syntax 'reset'
13
+ c.action do |args, options|
14
+ J1::Commands::Reset.process(args, options)
15
+ end
16
+ end
17
+ end
18
+
19
+ def process(args, options = {})
20
+ timestamp = Time.now.strftime("%Y-%m-%d %H:%M:%S")
21
+ if J1::Utils::is_project?
22
+ if J1::Utils::is_project_setup?
23
+ J1.logger.info "#{timestamp} - RESET: Reset the project to factory state ..."
24
+ J1.logger.info "#{timestamp} - RESET: Be patient, this will take a while ..."
25
+ process = J1::Utils::Exec2.run('RESET','npm', 'run', 'reset')
26
+ if process.success?
27
+ timestamp = Time.now.strftime("%Y-%m-%d %H:%M:%S")
28
+ J1.logger.info "#{timestamp} - RESET: The project reset finished successfully."
29
+ J1.logger.info "#{timestamp} - RESET: To setup the project, run: j1 setup"
30
+ else
31
+ raise SystemExit
32
+ end
33
+ else
34
+ raise SystemExit
35
+ end
36
+ else
37
+ raise SystemExit
38
+ end
39
+ end
40
+
41
+ end
42
+ end
43
+ end
44
+ end
@@ -0,0 +1,123 @@
1
+ # frozen_string_literal: true
2
+ # require "futils"
3
+
4
+ module J1
5
+ module Commands
6
+ class Setup < Command
7
+ #noinspection MissingYardParamTag
8
+ class << self
9
+
10
+ def init_with_program(prog)
11
+ prog.command(:setup) do |c|
12
+ c.description 'Initialize a J1 project for first use'
13
+ c.syntax 'setup'
14
+ c.option 'force', '--force', ' Force to install patches even already exists'
15
+ c.option 'system', '--system', ' Install patches on the Ruby SYSTEM gem folder'
16
+ c.option 'skip-patches', '--skip-patches', 'Skip install any PATCHES build-in with J1'
17
+ c.action do |args, options|
18
+ J1::Commands::Setup.process(args, options)
19
+ end
20
+ end
21
+ end
22
+
23
+ def process(args, options = {})
24
+ @args = args
25
+ path = File.expand_path(Dir.getwd)
26
+
27
+ if J1::Utils::is_project?
28
+ bundle_install(path, options)
29
+ if options['skip-patches']
30
+ J1.logger.info "#{timestamp} - SETUP: Install build-in patches skipped ..."
31
+ else
32
+ patch_install(options)
33
+ end
34
+
35
+ timestamp = Time.now.strftime("%Y-%m-%d %H:%M:%S")
36
+ J1.logger.info "#{timestamp} - SETUP: Initialize the project ..."
37
+ J1.logger.info "#{timestamp} - SETUP: Be patient, this will take a while ..."
38
+ # process, output = J1::Utils::Exec.run('npm', 'run', 'setup')
39
+ # output.to_s.each_line do |line|
40
+ # J1.logger.info('SETUP:', line.strip) unless line.to_s.empty?
41
+ # end
42
+ process = J1::Utils::Exec2.run('SETUP','npm', 'run', 'setup')
43
+ if process.success?
44
+ timestamp = Time.now.strftime("%Y-%m-%d %H:%M:%S")
45
+ J1.logger.info "#{timestamp} - SETUP: Initializing the project finished successfully."
46
+ J1.logger.info "#{timestamp} - SETUP: To open your site, run: j1 site"
47
+ else
48
+ raise SystemExit
49
+ end
50
+ else
51
+ raise SystemExit
52
+ end
53
+ end
54
+
55
+ private
56
+
57
+ def bundle_install(path, options)
58
+ timestamp = Time.now.strftime("%Y-%m-%d %H:%M:%S")
59
+ J1::External.require_with_graceful_fail 'bundler'
60
+ J1.logger.info "#{timestamp} - SETUP: Running bundle install in #{path} ..."
61
+ Dir.chdir(path) do
62
+ if options['system']
63
+ J1.logger.info "#{timestamp} - SETUP: Install bundle in Ruby gem SYSTEM folder ..."
64
+ else
65
+ J1.logger.info "#{timestamp} - SETUP: Install bundle in USER gem folder ~/.gem ..."
66
+ process = J1::Utils::Exec2.run('SETUP','bundle', 'config', 'set', '--local', 'path', '~/.gem')
67
+ raise SystemExit unless process.success?
68
+ end
69
+ process = J1::Utils::Exec2.run('SETUP','bundle', 'install')
70
+ raise SystemExit unless process.success?
71
+ end
72
+ end
73
+
74
+ def patch_install(options)
75
+ timestamp = Time.now.strftime("%Y-%m-%d %H:%M:%S")
76
+ if J1::Utils::is_windows?
77
+ major, minor = RUBY_VERSION.split('.')
78
+ lib_version = major + '.' + minor
79
+ curr_path = File.expand_path(File.dirname(File.dirname(__FILE__)))
80
+ patch_gem_eventmachine = 'eventmachine-1.2.7-x64-mingw32'
81
+ patch_gem_execjs = 'execjs-2.7.0'
82
+ patch_eventmachine_source_path = curr_path + '/patches/rubygems' + '/' + patch_gem_eventmachine + '/lib/' + lib_version
83
+ patch_execjs_source_path = curr_path + '/patches/rubygems' + '/' + patch_gem_execjs + '/lib/execjs/external_runtime.rb'
84
+
85
+ process, output = J1::Utils::Exec1.run('gem', 'env', 'gempath')
86
+ raise SystemExit unless process.success?
87
+
88
+ result = output.split(';')
89
+ user_path = result[0]
90
+ system_path = result[1]
91
+
92
+ if options['system']
93
+ J1.logger.info "#{timestamp} - SETUP: Install patches in SYSTEM folder ..."
94
+ J1.logger.info "#{timestamp} - SETUP: Install patches on path #{system_path} ..."
95
+ dest = system_path + '/gems/' + patch_gem_eventmachine + '/lib'
96
+ else
97
+ J1.logger.info "#{timestamp} - SETUP: Install patches in USER gem folder ~/.gem ..."
98
+ J1.logger.info "#{timestamp} - SETUP: Install patches on path #{user_path} ..."
99
+ dest = user_path + '/gems/' + patch_gem_eventmachine + '/lib'
100
+ end
101
+ src = patch_eventmachine_source_path
102
+ FileUtils.cp_r(src, dest)
103
+
104
+ if lib_version === '2.7'
105
+ if options['system']
106
+ dest = system_path + '/gems/' + patch_gem_execjs + '/lib/execjs'
107
+ else
108
+ dest = user_path + '/gems/' + patch_gem_execjs + '/lib/execjs'
109
+ end
110
+ src = patch_execjs_source_path
111
+ if Dir.exist?(dest)
112
+ FileUtils.cp(src, dest)
113
+ else
114
+ J1.logger.info "#{timestamp} - SETUP: Skipped install patches for execjs-2.7.0 ..."
115
+ end
116
+ end
117
+
118
+ end
119
+ end
120
+ end
121
+ end
122
+ end
123
+ end
@@ -0,0 +1,36 @@
1
+ # frozen_string_literal: true
2
+
3
+ module J1
4
+ module Commands
5
+ class Site < Command
6
+ #noinspection MissingYardParamTag
7
+ class << self
8
+
9
+ def init_with_program(prog)
10
+ prog.command(:site) do |c|
11
+ c.description 'Run the website of a J1 project'
12
+ c.syntax 'site'
13
+ c.action do |args, options|
14
+ J1::Commands::Site.process(args, options)
15
+ end
16
+ end
17
+ end
18
+
19
+ def process(args, options = {})
20
+ timestamp = Time.now.strftime("%Y-%m-%d %H:%M:%S")
21
+ if J1::Utils::is_project?
22
+ if J1::Utils::is_project_setup?
23
+ J1.logger.info "#{timestamp} - SITE: Starting up your site ..."
24
+ process = J1::Utils::Exec2.run('SITE','npm', 'run', 'j1-site')
25
+ else
26
+ raise SystemExit
27
+ end
28
+ else
29
+ raise SystemExit
30
+ end
31
+ end
32
+
33
+ end
34
+ end
35
+ end
36
+ end
data/lib/j1/external.rb CHANGED
@@ -50,7 +50,7 @@ The full error message from Ruby is: '#{e.message}'
50
50
 
51
51
  If you run into trouble, you can find helpful resources at https://jekyllrb.com/help/!
52
52
  MSG
53
- raise Jekyll::Errors::MissingDependencyException, name
53
+ raise J1::Errors::MissingDependencyException, name
54
54
  end
55
55
  end
56
56
  end
@@ -2,7 +2,7 @@ require "open3"
2
2
 
3
3
  module J1
4
4
  module Utils
5
- module Exec
5
+ module Exec1
6
6
  extend self
7
7
 
8
8
  # Runs a program in a sub-shell.
@@ -0,0 +1,57 @@
1
+ require "open3"
2
+
3
+ module J1
4
+ module Utils
5
+ module Exec2
6
+ extend self
7
+
8
+ # Runs a program in a sub-shell and return a Process::Status on exit
9
+ #
10
+ # title - prepend a title on all messages
11
+ # *args - a list of strings containing the program name and arguments
12
+ #
13
+ def run(title, *args)
14
+ Open3.popen3(*args) do |stdin, stdout, stderr, status|
15
+
16
+ # manage software interrupt on Ctrl-C
17
+ trap('INT') {
18
+ timestamp = Time.now.strftime("%Y-%m-%d %H:%M:%S")
19
+ puts "#{timestamp} - #{title}: Received Ctrl-C to stop"
20
+ [stdin, stdout, stderr].each(&:close)
21
+ raise SystemExit
22
+ }
23
+
24
+ # manage messages on stdout
25
+ stdout_thr = Thread.new do
26
+ # exit the tread silently
27
+ Thread.current.report_on_exception = false
28
+ stdout.each_line do |line|
29
+ timestamp = Time.now.strftime("%Y-%m-%d %H:%M:%S")
30
+ puts "#{timestamp} - #{title}: #{line}"
31
+ end
32
+ end
33
+
34
+ # manage messages on stdout
35
+ stderr_thr = Thread.new do
36
+ # exit the tread silently
37
+ Thread.current.report_on_exception = false
38
+ stderr.each_line do |line|
39
+ timestamp = Time.now.strftime("%Y-%m-%d %H:%M:%S")
40
+ puts "#{timestamp} - " + "\e[31m" + "#{title}: #{line}" + "\e[0m"
41
+ end
42
+ end
43
+
44
+ # combine channels stdout, stderr for output
45
+ [stdout_thr, stderr_thr].each(&:join)
46
+
47
+ # close channels explicitly to exit gracefully
48
+ [stdin, stdout, stderr].each(&:close)
49
+
50
+ # exit and return Process::Status
51
+ status.value
52
+ end
53
+ end
54
+
55
+ end
56
+ end
57
+ end