avm 0.2.0 → 0.4.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/avm/app_src/base.rb +45 -0
- data/lib/avm/app_src/configuration/_locale.rb +16 -0
- data/lib/avm/app_src/configuration/_rubocop.rb +24 -0
- data/lib/avm/app_src/configuration/_tests.rb +27 -0
- data/lib/avm/app_src/configuration.rb +55 -0
- data/lib/avm/app_src.rb +9 -0
- data/lib/avm/executables.rb +24 -0
- data/lib/avm/files/appendable/file_content.rb +24 -0
- data/lib/avm/files/appendable/plain_directory.rb +25 -0
- data/lib/avm/files/appendable/resource_base.rb +13 -0
- data/lib/avm/files/appendable/tar_output_command.rb +26 -0
- data/lib/avm/files/appendable/templatized_directory.rb +29 -0
- data/lib/avm/files/appendable.rb +55 -0
- data/lib/avm/files/appender.rb +11 -0
- data/lib/avm/files/deploy.rb +71 -0
- data/lib/avm/files/formatter/formats/base.rb +62 -0
- data/lib/avm/files/formatter/formats/generic_plain.rb +34 -0
- data/lib/avm/files/formatter/formats/html.rb +45 -0
- data/lib/avm/files/formatter/formats/javascript.rb +24 -0
- data/lib/avm/files/formatter/formats/json.rb +27 -0
- data/lib/avm/files/formatter/formats/php.rb +22 -0
- data/lib/avm/files/formatter/formats/python.rb +22 -0
- data/lib/avm/files/formatter/formats/ruby.rb +22 -0
- data/lib/avm/files/formatter/formats/xml.rb +28 -0
- data/lib/avm/files/formatter/formats.rb +13 -0
- data/lib/avm/files/formatter/utf8_assert.rb +74 -0
- data/lib/avm/files/formatter.rb +90 -0
- data/lib/avm/files/rotate.rb +107 -0
- data/lib/avm/files.rb +9 -0
- data/lib/avm/git/auto_commit/commit_info.rb +23 -0
- data/lib/avm/git/auto_commit/rules/base.rb +39 -0
- data/lib/avm/git/auto_commit/rules/last.rb +19 -0
- data/lib/avm/git/auto_commit/rules/manual.rb +45 -0
- data/lib/avm/git/auto_commit/rules/new.rb +24 -0
- data/lib/avm/git/auto_commit/rules/nth.rb +31 -0
- data/lib/avm/git/auto_commit/rules/unique.rb +21 -0
- data/lib/avm/git/auto_commit/rules.rb +31 -0
- data/lib/avm/git/auto_commit_path/ruby.rb +20 -0
- data/lib/avm/git/auto_commit_path.rb +28 -0
- data/lib/avm/git/commit/class_methods.rb +31 -0
- data/lib/avm/git/commit/deploy.rb +38 -0
- data/lib/avm/git/commit/deploy_methods.rb +19 -0
- data/lib/avm/git/commit/diff_tree_line.rb +32 -0
- data/lib/avm/git/commit/file.rb +46 -0
- data/lib/avm/git/commit.rb +59 -0
- data/lib/avm/git/file_auto_fixup.rb +83 -0
- data/lib/avm/git/issue/complete/commits.rb +42 -0
- data/lib/avm/git/issue/complete/git_subrepos.rb +23 -0
- data/lib/avm/git/issue/complete/local_branch.rb +54 -0
- data/lib/avm/git/issue/complete/local_tag.rb +39 -0
- data/lib/avm/git/issue/complete/push.rb +54 -0
- data/lib/avm/git/issue/complete/remote.rb +33 -0
- data/lib/avm/git/issue/complete/test.rb +45 -0
- data/lib/avm/git/issue/complete/tracker.rb +28 -0
- data/lib/avm/git/issue/complete/validation.rb +31 -0
- data/lib/avm/git/issue/complete/validations.rb +53 -0
- data/lib/avm/git/issue/complete/working_tree.rb +19 -0
- data/lib/avm/git/issue/complete.rb +51 -0
- data/lib/avm/git/issue/deliver.rb +56 -0
- data/lib/avm/git/issue.rb +11 -0
- data/lib/avm/git/organize/reference_update.rb +34 -0
- data/lib/avm/git/organize/repository.rb +76 -0
- data/lib/avm/git/organize.rb +11 -0
- data/lib/avm/git/revision_test.rb +105 -0
- data/lib/avm/git/subrepo_check/parent.rb +51 -0
- data/lib/avm/git/subrepo_check/remote.rb +89 -0
- data/lib/avm/git/subrepo_check/show_result.rb +32 -0
- data/lib/avm/git/subrepo_check.rb +38 -0
- data/lib/avm/git/subrepo_checks.rb +59 -0
- data/lib/avm/git.rb +10 -0
- data/lib/avm/jobs/base.rb +62 -0
- data/lib/avm/jobs/variables_source.rb +22 -0
- data/lib/avm/jobs.rb +9 -0
- data/lib/avm/result.rb +86 -0
- data/lib/avm/version.rb +1 -1
- metadata +179 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 0a5a8832847c76afcae4e76ef3e8f7d1391d7cfb0b13788c3dc7273f9ef879f1
|
4
|
+
data.tar.gz: 0b89bd147edb92e0e3e4d158d16f0995ef41f0544a680beb053f9fa55b96a282
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a70af189af9aee66a693706ba031e5eb7c6d4c8533144099f325dfe2b88b9ef08daae16de8d2f09857f194816d653d3669527d6bc9c07d173566c9ab9121c3f6
|
7
|
+
data.tar.gz: d66a1741ec6295f54166a2007a4d168eddd4e7de30f538f87329067b580faf2572514d99302bb467e0b408dfe1a44dd54a9e4e2abaaed0292b3a7ba69bb02b95
|
@@ -0,0 +1,45 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'eac_git'
|
4
|
+
require 'eac_ruby_utils/core_ext'
|
5
|
+
|
6
|
+
module Avm
|
7
|
+
module AppSrc
|
8
|
+
class Base
|
9
|
+
enable_simple_cache
|
10
|
+
enable_listable
|
11
|
+
lists.add_symbol :option, :parent
|
12
|
+
common_constructor :path, :options, default: [{}] do
|
13
|
+
self.path = path.to_pathname
|
14
|
+
self.options = self.class.lists.option.hash_keys_validate!(options)
|
15
|
+
end
|
16
|
+
|
17
|
+
delegate :to_s, to: :path
|
18
|
+
|
19
|
+
# @return [Avm::AppSrc::Base]
|
20
|
+
def parent
|
21
|
+
options[OPTION_PARENT]
|
22
|
+
end
|
23
|
+
|
24
|
+
# @return [Pathname]
|
25
|
+
def relative_path
|
26
|
+
return path if parent.blank?
|
27
|
+
|
28
|
+
path.relative_path_from(parent.path)
|
29
|
+
end
|
30
|
+
|
31
|
+
# @return [Enumerable<Avm::AppSrc::Base>]
|
32
|
+
def subs
|
33
|
+
git_repo.subrepos
|
34
|
+
.map { |subrepo| self.class.new(subrepo.subpath.expand_path(path), parent: self) }
|
35
|
+
end
|
36
|
+
|
37
|
+
private
|
38
|
+
|
39
|
+
# @return [EacGit::Local]
|
40
|
+
def git_repo_uncached
|
41
|
+
::EacGit::Local.new(path)
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'avm/patches/eac_ruby_gems_utils/gem'
|
4
|
+
require 'i18n'
|
5
|
+
|
6
|
+
module Avm
|
7
|
+
module AppSrc
|
8
|
+
class Configuration < ::EacConfig::OldConfigs
|
9
|
+
LOCALE_KEY = :locale
|
10
|
+
|
11
|
+
def locale
|
12
|
+
read_entry(LOCALE_KEY) || ::I18n.default_locale
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Avm
|
4
|
+
module AppSrc
|
5
|
+
class Configuration < ::EacConfig::OldConfigs
|
6
|
+
RUBOCOP_COMMAND_KEY = 'ruby.rubocop.command'
|
7
|
+
RUBOCOP_GEMFILE_KEY = 'ruby.rubocop.gemfile'
|
8
|
+
|
9
|
+
def rubocop_command
|
10
|
+
read_command(RUBOCOP_COMMAND_KEY)
|
11
|
+
end
|
12
|
+
|
13
|
+
def rubocop_gemfile
|
14
|
+
gemfile_path = read_entry(RUBOCOP_GEMFILE_KEY)
|
15
|
+
return nil if gemfile_path.blank?
|
16
|
+
|
17
|
+
gemfile_path = gemfile_path.to_pathname.expand_path(storage_path.parent)
|
18
|
+
return gemfile_path if gemfile_path.file?
|
19
|
+
|
20
|
+
raise "Gemfile path \"#{gemfile_path}\" does not exist or is not a file"
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'avm/patches/eac_ruby_gems_utils/gem'
|
4
|
+
|
5
|
+
module Avm
|
6
|
+
module AppSrc
|
7
|
+
class Configuration < ::EacConfig::OldConfigs
|
8
|
+
BUNDLE_TEST_COMMAND_KEY = 'test.bundle_command'
|
9
|
+
TEST_COMMAND_KEY = 'test.command'
|
10
|
+
|
11
|
+
def any_test_command
|
12
|
+
bundle_test_command || test_command
|
13
|
+
end
|
14
|
+
|
15
|
+
def test_command
|
16
|
+
read_command(TEST_COMMAND_KEY)
|
17
|
+
end
|
18
|
+
|
19
|
+
def bundle_test_command
|
20
|
+
read_entry(BUNDLE_TEST_COMMAND_KEY).if_present do |v|
|
21
|
+
args = v.is_a?(::Enumerable) ? v.map(&:to_s) : ::Shellwords.split(v)
|
22
|
+
::EacRubyGemsUtils::Gem.new(::File.dirname(storage_path)).bundle(*args).chdir_root
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
@@ -0,0 +1,55 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'eac_config/old_configs'
|
4
|
+
require 'eac_ruby_utils/core_ext'
|
5
|
+
require 'yaml'
|
6
|
+
|
7
|
+
module Avm
|
8
|
+
module AppSrc
|
9
|
+
class Configuration < ::EacConfig::OldConfigs
|
10
|
+
require_sub __FILE__
|
11
|
+
|
12
|
+
FILENAMES = %w[.avm.yml .avm.yaml].freeze
|
13
|
+
|
14
|
+
class << self
|
15
|
+
def find_by_path(path)
|
16
|
+
path = ::Pathname.new(path.to_s) unless path.is_a?(::Pathname)
|
17
|
+
internal_find_path(path.expand_path)
|
18
|
+
end
|
19
|
+
|
20
|
+
def find_in_path(path)
|
21
|
+
absolute_pathname = path.to_pathname.expand_path
|
22
|
+
if absolute_pathname.directory?
|
23
|
+
FILENAMES.each do |filename|
|
24
|
+
file = absolute_pathname.join(filename)
|
25
|
+
return new(file) if file.exist?
|
26
|
+
end
|
27
|
+
end
|
28
|
+
nil
|
29
|
+
end
|
30
|
+
|
31
|
+
private
|
32
|
+
|
33
|
+
def internal_find_path(absolute_pathname)
|
34
|
+
r = find_in_path(absolute_pathname)
|
35
|
+
return r if r.present?
|
36
|
+
|
37
|
+
internal_find_path(absolute_pathname.dirname) unless absolute_pathname.root?
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
def initialize(path)
|
42
|
+
super(nil, storage_path: path)
|
43
|
+
end
|
44
|
+
|
45
|
+
# Utility to read a configuration as a [EacRubyUtils::Envs::Command].
|
46
|
+
# @return [EacRubyUtils::Envs::Command]
|
47
|
+
def read_command(key)
|
48
|
+
read_entry(key).if_present do |v|
|
49
|
+
args = v.is_a?(::Enumerable) ? v.map(&:to_s) : ::Shellwords.split(v)
|
50
|
+
::EacRubyUtils::Envs.local.command(args).chdir(::File.dirname(storage_path))
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
data/lib/avm/app_src.rb
ADDED
@@ -0,0 +1,24 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'eac_ruby_utils/envs'
|
4
|
+
require 'eac_ruby_utils/simple_cache'
|
5
|
+
|
6
|
+
module Avm
|
7
|
+
module Executables
|
8
|
+
class << self
|
9
|
+
include ::EacRubyUtils::SimpleCache
|
10
|
+
|
11
|
+
def env
|
12
|
+
::EacRubyUtils::Envs.local
|
13
|
+
end
|
14
|
+
|
15
|
+
private
|
16
|
+
|
17
|
+
%w[file git js-beautify latex php-cs-fixer tidy yapf xdg-open].each do |program|
|
18
|
+
define_method(program.underscore + '_uncached') do
|
19
|
+
env.executable(program, '--version')
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'eac_ruby_utils/core_ext'
|
4
|
+
require 'avm/files/appendable/resource_base'
|
5
|
+
|
6
|
+
module Avm
|
7
|
+
module Files
|
8
|
+
module Appendable
|
9
|
+
class FileContent < ::Avm::Files::Appendable::ResourceBase
|
10
|
+
attr_reader :target_path, :content
|
11
|
+
|
12
|
+
def initialize(deploy, target_path, content)
|
13
|
+
super(deploy)
|
14
|
+
@target_path = target_path
|
15
|
+
@content = content
|
16
|
+
end
|
17
|
+
|
18
|
+
def write_on(target_dir)
|
19
|
+
target_dir.join(target_path).write(content)
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'eac_ruby_utils/core_ext'
|
4
|
+
require 'avm/files/appendable/resource_base'
|
5
|
+
|
6
|
+
module Avm
|
7
|
+
module Files
|
8
|
+
module Appendable
|
9
|
+
class PlainDirectory < ::Avm::Files::Appendable::ResourceBase
|
10
|
+
attr_reader :source_path
|
11
|
+
|
12
|
+
def initialize(appender, source_path)
|
13
|
+
super(appender)
|
14
|
+
@source_path = source_path.to_pathname
|
15
|
+
end
|
16
|
+
|
17
|
+
def write_on(target_dir)
|
18
|
+
raise "\"#{source_path}\" is not a directory" unless source_path.directory?
|
19
|
+
|
20
|
+
::FileUtils.cp_r("#{source_path}/.", target_dir.to_path)
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'eac_ruby_utils/core_ext'
|
4
|
+
require 'eac_ruby_utils/envs'
|
5
|
+
require 'avm/files/appendable/resource_base'
|
6
|
+
|
7
|
+
module Avm
|
8
|
+
module Files
|
9
|
+
module Appendable
|
10
|
+
class TarOutputCommand < ::Avm::Files::Appendable::ResourceBase
|
11
|
+
attr_reader :command
|
12
|
+
|
13
|
+
def initialize(appender, command)
|
14
|
+
super(appender)
|
15
|
+
@command = command
|
16
|
+
end
|
17
|
+
|
18
|
+
def write_on(target_dir)
|
19
|
+
command.pipe(
|
20
|
+
::EacRubyUtils::Envs.local.command('tar', '-xf', '-', '-C', target_dir)
|
21
|
+
).execute!
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'eac_ruby_utils/core_ext'
|
4
|
+
require 'avm/files/appendable/resource_base'
|
5
|
+
require 'eac_templates/directory'
|
6
|
+
|
7
|
+
module Avm
|
8
|
+
module Files
|
9
|
+
module Appendable
|
10
|
+
class TemplatizedDirectory < ::Avm::Files::Appendable::ResourceBase
|
11
|
+
attr_reader :source_path
|
12
|
+
|
13
|
+
def initialize(appender, source_path)
|
14
|
+
super(appender)
|
15
|
+
@source_path = source_path
|
16
|
+
end
|
17
|
+
|
18
|
+
def write_on(target_dir)
|
19
|
+
raise 'Variables source not set' if appender.variables_source.blank?
|
20
|
+
|
21
|
+
::EacTemplates::Directory.new(source_path).apply(
|
22
|
+
appender.variables_source,
|
23
|
+
target_dir
|
24
|
+
)
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
@@ -0,0 +1,55 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'eac_ruby_utils/core_ext'
|
4
|
+
|
5
|
+
module Avm
|
6
|
+
module Files
|
7
|
+
module Appendable
|
8
|
+
require_sub __FILE__
|
9
|
+
|
10
|
+
attr_reader :variables_source
|
11
|
+
|
12
|
+
def appended
|
13
|
+
@appended ||= []
|
14
|
+
end
|
15
|
+
|
16
|
+
def append_templatized_directories(directories)
|
17
|
+
directories.each { |directory| append_templatized_directory(directory) }
|
18
|
+
self
|
19
|
+
end
|
20
|
+
|
21
|
+
def append_plain_directory(directory)
|
22
|
+
appended << ::Avm::Files::Appendable::PlainDirectory.new(self, directory)
|
23
|
+
self
|
24
|
+
end
|
25
|
+
|
26
|
+
def append_tar_output_command(tar_command)
|
27
|
+
appended << ::Avm::Files::Appendable::TarOutputCommand.new(self, tar_command)
|
28
|
+
self
|
29
|
+
end
|
30
|
+
|
31
|
+
def append_templatized_directory(directory)
|
32
|
+
appended << ::Avm::Files::Appendable::TemplatizedDirectory.new(self, directory)
|
33
|
+
self
|
34
|
+
end
|
35
|
+
|
36
|
+
def append_file_content(target_path, content)
|
37
|
+
appended << ::Avm::Files::Appendable::FileContent
|
38
|
+
.new(self, target_path, content)
|
39
|
+
self
|
40
|
+
end
|
41
|
+
|
42
|
+
def variables_source_set(source)
|
43
|
+
@variables_source = source
|
44
|
+
self
|
45
|
+
end
|
46
|
+
|
47
|
+
def write_appended_on(target_dir)
|
48
|
+
target_dir = target_dir.to_pathname
|
49
|
+
raise "\"#{target_dir}\" is not a directory" unless target_dir.directory?
|
50
|
+
|
51
|
+
appended.each { |append| append.write_on(target_dir) }
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
@@ -0,0 +1,71 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'addressable'
|
4
|
+
require 'avm/files/appendable'
|
5
|
+
require 'eac_ruby_utils/core_ext'
|
6
|
+
|
7
|
+
module Avm
|
8
|
+
module Files
|
9
|
+
class Deploy
|
10
|
+
include ::Avm::Files::Appendable
|
11
|
+
enable_simple_cache
|
12
|
+
|
13
|
+
attr_reader :build_dir, :target_env, :target_path
|
14
|
+
|
15
|
+
common_constructor :target_env, :target_path
|
16
|
+
|
17
|
+
def run
|
18
|
+
on_build_dir do
|
19
|
+
copy_content_to_build_dir
|
20
|
+
mkdir_target
|
21
|
+
clear_content
|
22
|
+
send_untar_package
|
23
|
+
set_target_permission
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
private
|
28
|
+
|
29
|
+
def on_build_dir
|
30
|
+
@build_dir = ::Dir.mktmpdir
|
31
|
+
yield
|
32
|
+
ensure
|
33
|
+
::FileUtils.rm_rf(@build_dir)
|
34
|
+
end
|
35
|
+
|
36
|
+
def copy_content_to_build_dir
|
37
|
+
write_appended_on(build_dir)
|
38
|
+
end
|
39
|
+
|
40
|
+
def mkdir_target
|
41
|
+
target_env.command('mkdir', '-p', target_path).execute!
|
42
|
+
end
|
43
|
+
|
44
|
+
def clear_content
|
45
|
+
target_env.command(
|
46
|
+
'find', target_path, '-mindepth', '1', '-maxdepth', '1', '-exec', 'rm', '-rf', '{}', ';'
|
47
|
+
).execute!
|
48
|
+
end
|
49
|
+
|
50
|
+
def send_untar_package
|
51
|
+
tar_build_command.pipe(untar_build_command).execute!
|
52
|
+
end
|
53
|
+
|
54
|
+
def set_target_permission
|
55
|
+
target_env.command('chmod', '755', target_path).execute!
|
56
|
+
end
|
57
|
+
|
58
|
+
def tar_build_command
|
59
|
+
source_env.command('tar', '-czO', '-C', build_dir, '.')
|
60
|
+
end
|
61
|
+
|
62
|
+
def untar_build_command
|
63
|
+
target_env.command('tar', '-xzf', '-', '-C', target_path)
|
64
|
+
end
|
65
|
+
|
66
|
+
def source_env
|
67
|
+
::EacRubyUtils::Envs.local
|
68
|
+
end
|
69
|
+
end
|
70
|
+
end
|
71
|
+
end
|
@@ -0,0 +1,62 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'eac_fs/file_info'
|
4
|
+
require 'ostruct'
|
5
|
+
|
6
|
+
module Avm
|
7
|
+
module Files
|
8
|
+
class Formatter
|
9
|
+
module Formats
|
10
|
+
class Base
|
11
|
+
def apply(files)
|
12
|
+
old_content = Hash[files.map { |f| [f, File.read(f)] }]
|
13
|
+
::Avm::Files::Formatter::Utf8Assert.assert_files(files) { internal_apply(files) }
|
14
|
+
files.map { |f| build_file_result(f, old_content[f]) }
|
15
|
+
end
|
16
|
+
|
17
|
+
def name
|
18
|
+
self.class.name.demodulize
|
19
|
+
end
|
20
|
+
|
21
|
+
def match?(file)
|
22
|
+
match_by_filename?(file) || match_by_type?(file)
|
23
|
+
end
|
24
|
+
|
25
|
+
def valid_basenames
|
26
|
+
constant_or_array('VALID_BASENAMES')
|
27
|
+
end
|
28
|
+
|
29
|
+
def valid_types
|
30
|
+
constant_or_array('VALID_TYPES')
|
31
|
+
end
|
32
|
+
|
33
|
+
private
|
34
|
+
|
35
|
+
def constant_or_array(name)
|
36
|
+
return [] unless self.class.const_defined?(name)
|
37
|
+
|
38
|
+
self.class.const_get(name)
|
39
|
+
end
|
40
|
+
|
41
|
+
def build_file_result(file, old_content)
|
42
|
+
::OpenStruct.new(file: file, format: self.class,
|
43
|
+
changed: (old_content != File.read(file)))
|
44
|
+
end
|
45
|
+
|
46
|
+
def match_by_filename?(file)
|
47
|
+
valid_basenames.any? do |valid_basename|
|
48
|
+
file.basename.fnmatch?(valid_basename)
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
def match_by_type?(file)
|
53
|
+
info = ::EacFs::FileInfo.new(file)
|
54
|
+
return unless info.content_type.type == 'text'
|
55
|
+
|
56
|
+
valid_types.include?(info.content_type.subtype)
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end
|
62
|
+
end
|
@@ -0,0 +1,34 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'avm/files/formatter/formats/base'
|
4
|
+
|
5
|
+
module Avm
|
6
|
+
module Files
|
7
|
+
class Formatter
|
8
|
+
module Formats
|
9
|
+
class GenericPlain < ::Avm::Files::Formatter::Formats::Base
|
10
|
+
VALID_BASENAMES = %w[*.bat *.css.coffee *.java *.js *.rb *.scss *.sql *.tex *.url *.yml
|
11
|
+
*.yaml].freeze
|
12
|
+
|
13
|
+
VALID_TYPES = %w[plain x-shellscript].freeze
|
14
|
+
|
15
|
+
def internal_apply(files)
|
16
|
+
files.each { |file| file_apply(file) }
|
17
|
+
end
|
18
|
+
|
19
|
+
def file_apply(file)
|
20
|
+
file.write(string_apply(file.read))
|
21
|
+
end
|
22
|
+
|
23
|
+
def string_apply(string)
|
24
|
+
b = ''
|
25
|
+
string.each_line do |line|
|
26
|
+
b += "#{line.rstrip}\n"
|
27
|
+
end
|
28
|
+
"#{b.strip}\n".gsub(/\t/, ' ')
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
@@ -0,0 +1,45 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'avm/files/formatter/formats/generic_plain'
|
4
|
+
require 'htmlbeautifier'
|
5
|
+
|
6
|
+
module Avm
|
7
|
+
module Files
|
8
|
+
class Formatter
|
9
|
+
module Formats
|
10
|
+
class Html < ::Avm::Files::Formatter::Formats::GenericPlain
|
11
|
+
VALID_BASENAMES = %w[*.html *.html.erb].freeze
|
12
|
+
VALID_TYPES = ['html'].freeze
|
13
|
+
|
14
|
+
def file_apply(path)
|
15
|
+
input = ::File.read(path)
|
16
|
+
temppath = tempfile_path
|
17
|
+
::File.open(temppath, 'w') do |output|
|
18
|
+
beautify path, input, output
|
19
|
+
end
|
20
|
+
::FileUtils.mv(temppath, path)
|
21
|
+
super(path)
|
22
|
+
end
|
23
|
+
|
24
|
+
private
|
25
|
+
|
26
|
+
def beautify(name, input, output)
|
27
|
+
output.puts ::HtmlBeautifier.beautify(input, htmlbeautify_options)
|
28
|
+
rescue StandardError => e
|
29
|
+
raise "Error parsing #{name}: #{e}"
|
30
|
+
end
|
31
|
+
|
32
|
+
def htmlbeautify_options
|
33
|
+
@htmlbeautify_options ||= { indent: ' ' }
|
34
|
+
end
|
35
|
+
|
36
|
+
def tempfile_path
|
37
|
+
tempfile = ::Tempfile.new
|
38
|
+
tempfile.close
|
39
|
+
tempfile.path
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'avm/executables'
|
4
|
+
require 'avm/files/formatter/formats/generic_plain'
|
5
|
+
|
6
|
+
module Avm
|
7
|
+
module Files
|
8
|
+
class Formatter
|
9
|
+
module Formats
|
10
|
+
class Javascript < ::Avm::Files::Formatter::Formats::GenericPlain
|
11
|
+
VALID_BASENAMES = %w[*.js].freeze
|
12
|
+
VALID_TYPES = [].freeze
|
13
|
+
|
14
|
+
def internal_apply(files)
|
15
|
+
::Avm::Executables.js_beautify.command.append(
|
16
|
+
['--indent-size=2', '--end-with-newline', '--replace', *files]
|
17
|
+
).system!
|
18
|
+
super(files)
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'avm/files/formatter/formats/generic_plain'
|
4
|
+
|
5
|
+
module Avm
|
6
|
+
module Files
|
7
|
+
class Formatter
|
8
|
+
module Formats
|
9
|
+
class Json < ::Avm::Files::Formatter::Formats::GenericPlain
|
10
|
+
VALID_BASENAMES = %w[*.json].freeze
|
11
|
+
VALID_TYPES = [].freeze
|
12
|
+
|
13
|
+
def file_apply(file)
|
14
|
+
::File.write(file, ::JSON.pretty_generate(::JSON.parse(::File.read(file))))
|
15
|
+
end
|
16
|
+
|
17
|
+
def json_file?(file)
|
18
|
+
::JSON.parse(::File.read(file))
|
19
|
+
true
|
20
|
+
rescue JSON::ParserError
|
21
|
+
false
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|