Class: Dev::Template::Docker::Node::Application

Inherits:
ApplicationInterface show all
Defined in:
lib/firespring_dev_commands/templates/docker/node/application.rb

Overview

Class for default rake tasks associated with a node project

Instance Method Summary collapse

Methods inherited from BaseInterface

#create_tasks!

Constructor Details

#initialize(application, container_path: nil, local_path: nil, exclude: []) ⇒ Application

Allow for custom container path for the application



11
12
13
14
# File 'lib/firespring_dev_commands/templates/docker/node/application.rb', line 11

def initialize(application, container_path: nil, local_path: nil, exclude: [])
  @node = Dev::Node.new(container_path: container_path, local_path: local_path)
  super(application, exclude: exclude)
end

Instance Method Details

#create_audit_task! ⇒ Object

Create the rake tasks which runs the security audits of application packages



104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
# File 'lib/firespring_dev_commands/templates/docker/node/application.rb', line 104

def create_audit_task!
  # Have to set a local variable to be accessible inside of the instance_eval block
  application = @name
  node = @node
  exclude = @exclude
  return if exclude.include?(:audit)

  DEV_COMMANDS_TOP_LEVEL.instance_eval do
    namespace application do
      desc 'Run all security audits'
      task audit: %w(node:audit) do
        # This is just a placeholder to execute the dependencies
      end

      namespace :node do
        desc 'Run NPM Audit on the target application' \
             "\n\tuse MIN_SEVERITY=(info low moderate high critical) to fetch only severity type selected and above (default=high)." \
             "\n\tuse IGNORELIST=(comma delimited list of ids) removes the entry from the list."
        task audit: %w(init_docker up_no_deps) do
          opts = []
          opts << '-T' if Dev::Common.new.running_codebuild?

          # Retrieve results of the scan.
          data = Dev::Docker::Compose.new(services: application, options: opts, capture: true).exec(*node.audit_command)
          Dev::Node::Audit.new(data).to_report.check
        end

        namespace :audit do
          desc 'Run NPM Audit fix command'
          task fix: %w(init_docker up_no_deps) do
            Dev::Docker::Compose.new(services: application).exec(*node.audit_fix_command)
          end
        end
      end
    end
  end
end

#create_install_task! ⇒ Object

Create the rake task which runs the install command for the application packages



84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
# File 'lib/firespring_dev_commands/templates/docker/node/application.rb', line 84

def create_install_task!
  # Have to set a local variable to be accessible inside of the instance_eval block
  application = @name
  node = @node
  exclude = @exclude
  return if exclude.include?(:install)

  DEV_COMMANDS_TOP_LEVEL.instance_eval do
    namespace application do
      namespace :node do
        desc 'Install all npm packages'
        task install: %w(init_docker up_no_deps) do
          Dev::Docker::Compose.new(services: application).exec(*node.install_command)
        end
      end
    end
  end
end

#create_lint_task! ⇒ Object

Create the rake task which runs linting for the application name



17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
# File 'lib/firespring_dev_commands/templates/docker/node/application.rb', line 17

def create_lint_task!
  application = @name
  node = @node
  exclude = @exclude
  return if exclude.include?(:lint)

  DEV_COMMANDS_TOP_LEVEL.instance_eval do
    namespace application do
      desc 'Run all linting software'
      task lint: %w(node:lint) do
        # This is just a placeholder to execute the dependencies
      end

      namespace :node do
        desc "Run the node linting software against the #{application}'s codebase"
        task lint: %w(init_docker up_no_deps) do
          LOG.debug('Check for node linting errors')

          options = []
          options << '-T' if Dev::Common.new.running_codebuild?
          Dev::Docker::Compose.new(services: application, options: options).exec(*node.lint_command)
        end

        namespace :lint do
          desc "Run the linting software against the #{application}'s codebase and apply all available fixes"
          task fix: %w(init_docker up_no_deps) do
            LOG.debug('Check and fix linting errors')

            options = []
            options << '-T' if Dev::Common.new.running_codebuild?
            Dev::Docker::Compose.new(services: application, options: options).exec(*node.lint_fix_command)
          end
        end
      end
    end
  end
end

#create_test_task! ⇒ Object

Create the rake task which runs all tests for the application name



56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
# File 'lib/firespring_dev_commands/templates/docker/node/application.rb', line 56

def create_test_task!
  application = @name
  node = @node
  exclude = @exclude
  return if exclude.include?(:test)

  DEV_COMMANDS_TOP_LEVEL.instance_eval do
    namespace application do
      desc 'Run all tests'
      task test: %w(node:test) do
        # This is just a placeholder to execute the dependencies
      end

      namespace :node do
        desc "Run all node tests against the #{application}'s codebase"
        task test: %w(init_docker up) do
          LOG.debug("Running all node tests in the #{application} codebase")

          options = []
          options << '-T' if Dev::Common.new.running_codebuild?
          Dev::Docker::Compose.new(services: application, options: options).exec(*node.test_command)
        end
      end
    end
  end
end