-
Notifications
You must be signed in to change notification settings - Fork 368
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* update readme to align with current steps to add company * update development steps docs * add new company mix task * update instructions to include new mix task * chore - update package-lock from mix setup * update moddoc * add link to the nav bar to point to the readme for adding a company
- Loading branch information
Showing
4 changed files
with
136 additions
and
26 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
# lib/mix/tasks/create_company_file.ex | ||
defmodule Mix.Tasks.CreateCompanyFile do | ||
use Mix.Task | ||
require Logger | ||
|
||
@shortdoc "Creates a company file in the priv/companies directory" | ||
|
||
@moduledoc """ | ||
Generate company file in desired location and structure to render in UI | ||
$ mix create_company_file Acme Corp | ||
$ mix create_company_file "Acme Corp" | ||
$ mix create_company_file Acme Corp | ||
""" | ||
|
||
@impl Mix.Task | ||
@doc false | ||
def run(args) do | ||
case parse_args(args) do | ||
"" -> | ||
Logger.error("Expected at least one argument: the company name") | ||
Logger.info("Usage: mix create_company_file COMPANY_NAME") | ||
|
||
company_name -> | ||
maybe_create_file(company_name) | ||
end | ||
end | ||
|
||
defp parse_args(args) do | ||
args | ||
|> Enum.flat_map(&String.split(&1, ~r{\s}, trim: true)) | ||
|> Enum.join(" ") | ||
|> String.trim() | ||
end | ||
|
||
defp maybe_create_file(company_name) do | ||
file_name = company_name |> String.replace(" ", "_") |> String.downcase() | ||
file_path = Path.join(["priv", "companies", "#{file_name}.exs"]) | ||
|
||
if File.exists?(file_path) do | ||
Logger.error("Error: File already exists at #{file_path}") | ||
Logger.info("Please choose a different company name or alter the existing file.") | ||
else | ||
content = """ | ||
# Company file for #{company_name} | ||
# Created on: #{Date.utc_today()} | ||
%{ | ||
name: "#{company_name}", | ||
website: "https://example.com/", | ||
github: "https://github.com/example/#{file_name}", | ||
# reference lib/companies/industries.ex for a list of recommended industries to use here | ||
industry: "Technology", | ||
location: %{ | ||
city: "City", | ||
state: "State", | ||
country: "Country" | ||
}, | ||
description: \"\"\" | ||
Description of #{company_name} goes here. | ||
\"\"\", | ||
last_changed_on: ~D[#{Date.utc_today()}] | ||
} | ||
""" | ||
|
||
case File.write(file_path, content) do | ||
:ok -> | ||
Logger.info("Company file created successfully: #{file_path}") | ||
|
||
{:error, reason} -> | ||
Logger.error("Failed to create company file: #{:file.format_error(reason)}") | ||
end | ||
end | ||
end | ||
end |