Class: WhatsAppNotifier::Generators::InstallServiceGenerator

Inherits:
Rails::Generators::Base
  • Object
show all
Defined in:
lib/generators/whatsapp_notifier/install_service_generator.rb

Constant Summary collapse

SERVICE_FILES =

Eject an explicit file list, never ‘directory ’.‘`: source_root is the LIVE gem service dir, so once the service has run it also contains node_modules (hundreds of MB of platform-native binaries), .wwebjs / .puppeteer session caches and *.test.ts — none of which belong in the host app. The app rebuilds deps with `bun install`.

%w[
  index.ts
  inbound.ts
  init_gate.ts
  metrics.ts
  sessions.ts
  package.json
  bun.lock
].freeze

Instance Method Summary collapse

Instance Method Details

#add_to_gitignoreObject



29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/generators/whatsapp_notifier/install_service_generator.rb', line 29

def add_to_gitignore
  entries = [
    "# WhatsApp Service",
    "/whatsapp_service/node_modules",
    "/whatsapp_service/.wwebjs_cache",
    "/whatsapp_service/.wwebjs_auth"
  ]
  content = File.exist?(".gitignore") ? File.read(".gitignore") : ""
  missing_entries = entries.reject { |entry| content.include?(entry) }
  return if missing_entries.empty?

  append_to_file ".gitignore", "\n#{missing_entries.join("\n")}\n"
end

#copy_service_filesObject



23
24
25
26
27
# File 'lib/generators/whatsapp_notifier/install_service_generator.rb', line 23

def copy_service_files
  SERVICE_FILES.each do |file|
    copy_file file, File.join("whatsapp_service", file)
  end
end

#show_readmeObject



43
44
45
46
47
# File 'lib/generators/whatsapp_notifier/install_service_generator.rb', line 43

def show_readme
  say "\nWhatsApp Service installed in /whatsapp_service", :green
  say "Make sure you have Bun installed: https://bun.sh", :yellow
  say "To start the service manually: cd whatsapp_service && bun index.ts", :yellow
end