Class: Makit::Cli::Generators::Templates::Node::PackageJson

Inherits:
Object
  • Object
show all
Defined in:
lib/makit/cli/generators/templates/node_templates.rb

Overview

Template generator for Node.js package.json files

Generates a standard package.json file with basic metadata, MIT license, and placeholder test script. Sets up a Node.js project ready for npm package management.

Examples:

package = PackageJson.new("my-node-app")
json_content = package.render

Instance Method Summary collapse

Constructor Details

#initialize(project_name) ⇒ PackageJson

Initialize a new package.json template generator

Parameters:

  • project_name (String)

    the name of the Node.js project



29
30
31
# File 'lib/makit/cli/generators/templates/node_templates.rb', line 29

def initialize(project_name)
  @project_name = project_name
end

Instance Method Details

#renderString

Render the package.json content

Returns:

  • (String)

    the complete package.json content with project metadata



36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
# File 'lib/makit/cli/generators/templates/node_templates.rb', line 36

def render
  <<~JSON
    {
      "name": "#{@project_name}",
      "version": "0.1.0",
      "description": "A Node.js project",
      "main": "index.js",
      "scripts": {
        "test": "echo \\"Error: no test specified\\" && exit 1"
      },
      "keywords": [],
      "author": "",
      "license": "MIT"
    }
  JSON
end