Skip to content

Commit

Permalink
Provide attributes for git config (#434)
Browse files Browse the repository at this point in the history
* Provide attributes for git config

* Add git config data and development usage

* Fix installation section

* Fix typo

* Remove database condition

* Add author and email to shard.yml

* Fix wrong var name

* Avoid empty `user.name` or `user.email`

* Use system

* Add type

* Mention amber encrypt and add mysql

* Remove variable

* Fix default

* Clarify fetch code
  • Loading branch information
faustinoaq authored and elorest committed Dec 13, 2017
1 parent 7aa7800 commit 9cdc372
Show file tree
Hide file tree
Showing 3 changed files with 85 additions and 16 deletions.
34 changes: 34 additions & 0 deletions src/amber/cli/templates/app.cr
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,17 @@ module Amber::CLI
@model : String
@db_url : String
@wait_for : String
@author : String
@email : String
@github_name : String

def initialize(@name, @database = "pg", @language = "slang", @model = "granite")
@db_url = ""
@wait_for = ""
@database_name_base = generate_database_name_base
@author = fetch_author
@email = fetch_email
@github_name = fetch_github_name
end

def filter(entries)
Expand All @@ -24,5 +30,33 @@ module Amber::CLI
private def generate_database_name_base
@name.gsub('-', '_')
end

def which_git_command
system("which git >/dev/null")
end

def fetch_author
if which_git_command
user_name = `git config --get user.name`.strip
user_name = nil if user_name.empty?
end
user_name || "your-name-here"
end

def fetch_email
if which_git_command
user_email = `git config --get user.email`.strip
user_email = nil if user_email.empty?
end
user_email || "your-email-here"
end

def fetch_github_name
if which_git_command
github_user = `git config --get github.user`.strip
github_user = nil if github_user.empty?
end
github_user || "your-github-user"
end
end
end
61 changes: 48 additions & 13 deletions src/amber/cli/templates/app/README.md.ecr
Original file line number Diff line number Diff line change
@@ -1,52 +1,87 @@
# <%= @name %>

Your description here
A new project using [Amber Framework](https://amberframework.org/)

## Installation

Install back-end and front-end dependencies.

```
shards install
npm install
```

Configure the `config/environments/development.yml` and set the `database_url` with your credentials to your database.

Then:

```shellsession
shards update
```
amber db create migrate
```

## Usage

To run the demo:
### Development

To build crystal files:

```
amber watch
```

To build assets:

```
npm run watch
```

### Production

To setup `AMBER_ENV`:

```shellsession
$ shards build src/<%= @name %>.cr
./<%= @name %>
```
export AMBER_ENV=production
```

To build a production release:

```
shards build --production --release <%= @name %>
```

To build production assets:

```
npm run release
```

To use encrypted enviroment settings see [documentation](https://github.com/amberframework/online-docs/blob/master/getting-started/cli/encrypt.md#encrypt-command)

## Docker Compose

This will start an instance of postgres, migrate the database,
This will start an instance of <%= @database == "pg" ? "postgres" : "mysql" %>, migrate the database,
and launch the site at http://localhost:3000

```shellsession
```
docker-compose up -d
```

To view the logs:

```shellsession
```
docker-compose logs -f
```

Note: The Docker images are compatible with Heroku.
> Note: The Docker images are compatible with Heroku.

## Contributing

1. Fork it ( https://github.com/[your-github-name]/your_project/fork )
1. Fork it ( https://github.com/<%= @github_name %>/<%= @name %>/fork )
2. Create your feature branch (git checkout -b my-new-feature)
3. Commit your changes (git commit -am 'Add some feature')
4. Push to the branch (git push origin my-new-feature)
5. Create a new Pull Request

## Contributors

- [your_github_name](https://github.com/your_github_name) your_name - creator, maintainer
- [<%= @github_name %>](https://github.com/<%= @github_name %>) <%= @author %> - creator, maintainer
6 changes: 3 additions & 3 deletions src/amber/cli/templates/app/shard.yml.ecr
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ name: <%= @name %>
version: 0.1.0

authors:
- Amber <amberframework.org>
- <%= @author %> <<%= @email %>>

crystal: <%= Crystal::VERSION %>

Expand All @@ -24,11 +24,11 @@ dependencies:
<% case @model when "crecto" -%>
crecto:
github: Crecto/crecto
version: ~> 0.7.1
version: ~> 0.8.1
<% else -%>
granite_orm:
github: amberframework/granite-orm
version: ~> 0.7.7
version: ~> 0.7.8
<% end -%>

quartz_mailer:
Expand Down

0 comments on commit 9cdc372

Please sign in to comment.