Skip to content

Commit

Permalink
Add company updates (#703)
Browse files Browse the repository at this point in the history
* 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
jsegal205 authored Oct 18, 2024
1 parent a2af7c4 commit 10f8258
Show file tree
Hide file tree
Showing 4 changed files with 136 additions and 26 deletions.
68 changes: 46 additions & 22 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,39 +8,63 @@ A [collection of companies using Elixir](https://elixir-companies.com/) in produ

Proudly built with [Phoenix](https://phoenixframework.org).

### Adding a new company to the list
### Adding a new company be showcased

- Fork the repo
- Use the helper Mix task to generate the file:
```sh
mix create_company_file {{ your company name }}
```

**-- OR --**

- Add your company information to a new `/priv/companies/{{company_name}}.exs` in the following format:

```elixir
# Company file for Acme Corp
# Created on: 2024-01-01
%{
name: "Acme Corp",
website: "https://example.com/",
github: "https://github.com/example/acme-corp",
# 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 Acme Corp goes here.
""",
last_changed_on: ~D[2024-01-01]
}
```

- Create a pull request adding the new company file

- Sign with your GitHub account.
- Click on `Add a company` button and you will be redirected to a form.
- Fill all required data about the company and submit it.

After that, the admin needs to validate the request.
## Development

With everything OK the company will be approved and will appear in companies list.
1. Install current elixir, erlang and nodejs versions

### Adding a new job opportunity for a company
1. This project uses [asdf](https://asdf-vm.com/) to manage the language versions of the project.
1. Follow the instructions on [asdf#getting-started](https://asdf-vm.com/guide/getting-started.html) to install asdf.
1. Once complete, run the following command to install the language versions:

Once your company is available on the list, you are able to add a new Job opportunity for the given company.
```sh
asdf install
```

- Sign with your GitHub account.
- Click on `+ Add a Job` link and you will be redirected to a form.
- Fill all required data about the company and submit it.
**-- OR --**

## Development
1. If you manage your language versions differently, please reference [~/.tool-versions](.tool-versions) for the specific versions to run the project.

1. Install dependencies with `mix deps.get`
1. Create and migrate your database with `mix ecto.setup`
1. Install Node.js dependencies with `cd assets && npm install`
1. Install elixir and nodejs dependencies with `mix setup`
1. Start Phoenix endpoint with `mix phx.server`

Now you can visit [`localhost:4000`](http://localhost:4000) from your browser.

_Note_: You need to set up a [GitHub Application](https://developer.github.com/) and ensure `GITHUB_CLIENT_ID` and `GITHUB_CLIENT_SECRET` are available to your application. The GitHub application needs its callback set to `http://localhost:4000/auth/github/callback` and be given read-only access to the email addresses of the user.

_Note_: You need to have Postgres version 9.5+, due to our use of certain features that are fairly new (JSONB Data Type + ON CONFLICT query).

_Note_: If for some reason you reset the database on your machine, you will see an error as the browser has cookies for a user that does not exist in the database. You will need to clear the cookies and site data for the page on your browser and refresh the page to remove the error.

## Localization

In order to add a new language to the available list of locales, you have to do the following:
Expand Down
18 changes: 14 additions & 4 deletions assets/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions lib/companies_web/templates/layout/navbar.html.eex
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
<%= link gettext("Companies"), to: Routes.live_path(@conn, CompaniesWeb.CompanyLive, locale(@conn)), class: "navbar-item" %>
</div>
<div class="navbar-end">
<%= link gettext("Add a company"), to: "https://github.com/beam-community/elixir-companies?tab=readme-ov-file", class: "button is-link mr-2" %>
<div class="field is-grouped">
<%= render "locales.html", conn: @conn %>
</div>
Expand Down
75 changes: 75 additions & 0 deletions lib/mix/tasks/create_company_file.ex
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

0 comments on commit 10f8258

Please sign in to comment.