Method: CapsuleCD::Javascript::JavascriptEngine#build_step

Defined in:
lib/capsulecd/javascript/javascript_engine.rb

#build_stepObject



10
11
12
13
14
15
16
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
# File 'lib/capsulecd/javascript/javascript_engine.rb', line 10

def build_step
  super

  @_is_bower = File.exist?(@source_git_local_path + '/bower.json')
  @_is_npm = File.exist?(@source_git_local_path + '/package.json')

  # validate that the metadata files exist
  if !@_is_bower && !@_is_npm
    fail CapsuleCD::Error::BuildPackageInvalid, 'package.json or bower.json file must be present for Javascript packages'
  end

  # we can't bump the npm version here because the npm version patch command will set it.
  # howerver we need to make sure the bower.json and package.json versions are insync.
  # we'll take the latest version of either the package.json or bower.json and set that as the version of both.
  sync_versions

  # now that the bower and package versions are in sync, lets bump the version of bower.json
  # (because package.json will be bumped automatically.)
  if @_is_bower
    bower_file = File.read(@source_git_local_path + '/bower.json')
    bower_data = JSON.parse(bower_file)
    next_version = bump_version(SemVer.parse(bower_data['version']))
    bower_data['version'] = next_version.to_s
    File.write(@source_git_local_path + '/bower.json', JSON.pretty_generate(bower_data))
  end


  # TODO: check if this module name and version already exist.

  # check for/create any required missing folders/files
  unless File.exist?(@source_git_local_path + '/test')
    FileUtils.mkdir(@source_git_local_path + '/test')
  end
  unless File.exist?(@source_git_local_path + '/.gitignore')
    CapsuleCD::GitUtils.create_gitignore(@source_git_local_path, ['Node','Yeoman'])
  end
end