Module: Cyborg::NPM
Constant Summary collapse
- DEPENDENCIES =
YAML.load %Q{ private: true devDependencies: browserify: ^16.2.1 browserify-incremental: ^3.1.1 svgo: ^1.0.5 }
Instance Method Summary collapse
- #package_path ⇒ Object
- #read_package_json ⇒ Object
- #setup ⇒ Object
- #update_package_json ⇒ Object
- #write_package_json(contents) ⇒ Object
Instance Method Details
#package_path ⇒ Object
25 26 27 |
# File 'lib/cyborg/command/npm.rb', line 25 def package_path File.join(Dir.pwd, 'package.json') end |
#read_package_json ⇒ Object
37 38 39 |
# File 'lib/cyborg/command/npm.rb', line 37 def read_package_json JSON.parse File.read(package_path) end |
#setup ⇒ Object
15 16 17 18 19 20 21 22 23 |
# File 'lib/cyborg/command/npm.rb', line 15 def setup puts "\nInstalling npm dependencies…".bold if File.exist?(package_path) update_package_json else write_package_json(DEPENDENCIES) end end |
#update_package_json ⇒ Object
41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 |
# File 'lib/cyborg/command/npm.rb', line 41 def update_package_json package = read_package_json package['dependencies'] ||= {} package['devDependencies'] ||= {} deps = DEPENDENCIES['devDependencies'] deps.keys.each do |dep| d = deps[dep] if package['devDependencies'][dep].nil? && package['dependencies'][dep].nil? package['devDependencies'][dep] = d end end package.delete('dependencies') if package['dependencies'].empty? write_package_json(package) end |
#write_package_json(contents) ⇒ Object
29 30 31 32 33 34 35 |
# File 'lib/cyborg/command/npm.rb', line 29 def write_package_json(contents) File.open(package_path, 'w') do |io| io.write(JSON.pretty_generate(contents)) end puts "create".rjust(12).colorize(:green).bold + " #{package_path}" end |