diff --git a/.crystal-version b/.crystal-version deleted file mode 100644 index 3eefcb9dd..000000000 --- a/.crystal-version +++ /dev/null @@ -1 +0,0 @@ -1.0.0 diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml deleted file mode 100644 index 71d82b97a..000000000 --- a/.github/workflows/ci.yml +++ /dev/null @@ -1,46 +0,0 @@ -on: - push: -jobs: - amber-spec: - - runs-on: ubuntu-latest - - container: - image: crystallang/crystal - - services: - redis: - image: redis - options: >- - --health-cmd "redis-cli ping" - --health-interval 10s - --health-timeout 5s - --health-retries 5 - ports: - - 6379:6379 - postgres: - image: postgres - env: - POSTGRES_PASSWORD: postgres - options: >- - --health-cmd pg_isready - --health-interval 10s - --health-timeout 5s - --health-retries 5 - ports: - - 5432:5432 - - steps: - - name: Update & install sqlite3 - run: apt update && apt install -y libsqlite3-dev redis - - - name: Download source - uses: actions/checkout@v3 - - - name: Install shards - run: shards install - - - name: Run tests - run: bin/amber_spec - env: - REDIS_URL: "redis://redis:6379" diff --git a/.github/workflows/docker-ci.yml b/.github/workflows/docker-ci.yml new file mode 100644 index 000000000..aa60866d6 --- /dev/null +++ b/.github/workflows/docker-ci.yml @@ -0,0 +1,26 @@ +name: Docker CI + +on: + push: + +jobs: + docker: + timeout-minutes: 10 + runs-on: ubuntu-latest + + steps: + - name: Checkout + uses: actions/checkout@v3 + + - name: Start containers + run: docker-compose up -d redis postgres + + - name: Build image + run: docker-compose build + + - name: Run tests + run: docker-compose run spec + + - name: Stop containers + if: always() + run: docker-compose down diff --git a/.gitignore b/.gitignore index 00904b16f..04295ec62 100644 --- a/.gitignore +++ b/.gitignore @@ -12,5 +12,4 @@ shard.lock package-lock.json node_modules /myapp -cli -cli.dwarf \ No newline at end of file +cli.dwarf diff --git a/.travis.yml b/.travis.yml deleted file mode 100644 index eeef6d5ac..000000000 --- a/.travis.yml +++ /dev/null @@ -1,34 +0,0 @@ -dist: xenial -sudo: required - -services: - - postgresql - - redis-server - - docker - -cache: - directories: - - bin - - lib - - .shards - -env: - - TEST_SUITE=./spec/build_spec_granite.cr - - TEST_SUITE=./spec/amber - -before-install: - - psql -U postgres -c "ALTER USER postgres WITH PASSWORD 'password';" - -script: - - docker build -t amber-test . - - docker run --rm amber-test /opt/amber/bin/ameba - - docker run --rm amber-test crystal tool format --check - - docker run --rm --network=host amber-test crystal spec $TEST_SUITE - -notifications: - webhooks: - urls: - - https://webhooks.gitter.im/e/aaf02221d4649d70b384 - on_success: change # options: [always|never|change] default: always - on_failure: always # options: [always|never|change] default: always - on_start: never # options: [always|never|change] default: always diff --git a/Dockerfile b/Dockerfile index a2101a5fe..bc8bdfc18 100644 --- a/Dockerfile +++ b/Dockerfile @@ -2,17 +2,13 @@ FROM crystallang/crystal:latest # Install Dependencies ARG DEBIAN_FRONTEND=noninteractive -RUN apt-get update -qq && apt-get install -y --no-install-recommends libpq-dev libsqlite3-dev libmysqlclient-dev libreadline-dev git curl vim netcat - -# Install Node -RUN curl -sL https://deb.nodesource.com/setup_14.x | bash - -RUN apt-get install -y nodejs +RUN apt-get update -qq && apt-get install -y libpq-dev libsqlite3-dev libmysqlclient-dev libreadline-dev curl vim WORKDIR /opt/amber # Build Amber ENV PATH /opt/amber/bin:$PATH COPY . /opt/amber -RUN shards build amber --ignore-crystal-version +RUN shards build amber CMD ["crystal", "spec"] diff --git a/assets/js/amber.min.js b/assets/js/amber.min.js deleted file mode 100644 index 9f01aa4fc..000000000 --- a/assets/js/amber.min.js +++ /dev/null @@ -1 +0,0 @@ -var Amber=function(t){var e={};function n(o){if(e[o])return e[o].exports;var i=e[o]={i:o,l:!1,exports:{}};return t[o].call(i.exports,i,i.exports,n),i.l=!0,i.exports}return n.m=t,n.c=e,n.d=function(t,e,o){n.o(t,e)||Object.defineProperty(t,e,{enumerable:!0,get:o})},n.r=function(t){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(t,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(t,"__esModule",{value:!0})},n.t=function(t,e){if(1&e&&(t=n(t)),8&e)return t;if(4&e&&"object"==typeof t&&t&&t.__esModule)return t;var o=Object.create(null);if(n.r(o),Object.defineProperty(o,"default",{enumerable:!0,value:t}),2&e&&"string"!=typeof t)for(var i in t)n.d(o,i,function(e){return t[e]}.bind(null,i));return o},n.n=function(t){var e=t&&t.__esModule?function(){return t.default}:function(){return t};return n.d(e,"a",e),e},n.o=function(t,e){return Object.prototype.hasOwnProperty.call(t,e)},n.p="",n(n.s=0)}([function(t,e,n){"use strict";function o(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}function i(t,e){for(var n=0;n100;var t}},{key:"_reconnect",value:function(){var t=this;clearTimeout(this.reconnectTimeout),this.reconnectTimeout=setTimeout((function(){t.reconnectTries++,t.connect(t.params),t._reconnect()}),this._reconnectInterval())}},{key:"_reconnectInterval",value:function(){return[1e3,2e3,5e3,1e4][this.reconnectTries]||1e4}},{key:"_poll",value:function(){var t=this;this.pollingTimeout=setTimeout((function(){t._connectionIsStale()?t._reconnect():t._poll()}),1e4)}},{key:"_startPolling",value:function(){clearTimeout(this.pollingTimeout),this._poll()}},{key:"_handlePing",value:function(){this.lastPing=u()}},{key:"_reset",value:function(){clearTimeout(this.reconnectTimeout),this.reconnectTries=0,this.attemptReconnect=!0,this._startPolling()}},{key:"connect",value:function(t){var e=this;this.params=t;var n={location:window.location.hostname,port:window.location.port,protocol:"https:"===window.location.protocol?"wss:":"ws:"};return t&&Object.assign(n,t),n.port&&(n.location+=":".concat(n.port)),new Promise((function(t,o){e.ws=new WebSocket("".concat(n.protocol,"//").concat(n.location).concat(e.endpoint)),e.ws.onmessage=function(t){e.handleMessage(t)},e.ws.onclose=function(){e.attemptReconnect&&e._reconnect()},e.ws.onopen=function(){e._reset(),t()}}))}},{key:"disconnect",value:function(){this.attemptReconnect=!1,clearTimeout(this.pollingTimeout),clearTimeout(this.reconnectTimeout),this.ws.close()}},{key:"channel",value:function(t){var e=new l(t,this);return this.channels.push(e),e}},{key:"handleMessage",value:function(t){if("ping"===t.data)return this._handlePing();var e=JSON.parse(t.data);this.channels.forEach((function(t){t.topic===e.topic&&t.handleMessage(e)}))}}]),t}();e.default={Channel:l,Socket:f},document.addEventListener("DOMContentLoaded",(function(){for(var t=document.querySelectorAll("a[data-method='delete']"),e=function(e){t[e].addEventListener("click",(function(n){n.preventDefault();var o=t[e].getAttribute("data-confirm")||"Are you sure?";if(confirm(o)){var i=document.createElement("form"),c=document.createElement("input");i.setAttribute("action",t[e].getAttribute("href")),i.setAttribute("method","POST"),c.setAttribute("type","hidden"),c.setAttribute("name","_method"),c.setAttribute("value","DELETE"),i.appendChild(c),document.body.appendChild(i),i.submit()}return!1}))},n=0;n 0.6.0 + slang: + github: jeromegn/slang + version: ~> 1.7.1 + liquid: github: dare892/liquid.cr branch: chore/bump-version-crystal1.0.0 @@ -58,10 +62,6 @@ dependencies: github: luckyframework/shell-table.cr version: ~> 0.9.3 - slang: - github: jeromegn/slang - version: ~> 1.7.1 - inflector: github: phoffer/inflector.cr version: ~> 1.0.0 diff --git a/spec/amber/cli/commands/database_spec.cr b/spec/amber/cli/commands/database_spec.cr index 21464f45b..99b4a16f8 100644 --- a/spec/amber/cli/commands/database_spec.cr +++ b/spec/amber/cli/commands/database_spec.cr @@ -7,58 +7,66 @@ include CLIFixtures module Amber::CLI describe "database" do - ENV["AMBER_ENV"] = "test" - describe "sqlite" do - context ENV["AMBER_ENV"] do - it "has connection settings in config/environments/env.yml" do - env_yml = prepare_test_app - env_yml["database_url"].should eq expected_db_url("sqlite3", env) - cleanup - end + it "has connection settings in config/environments/env.yml" do + db_url = ENV["DATABASE_URL"]? - it "does not create the database when db create" do - env_yml = prepare_test_app - db_filename = env_yml["database_url"].to_s.gsub("sqlite3:", "") - File.exists?(db_filename).should be_false - cleanup + if ENV["DATABASE_URL"]? + ENV.delete("DATABASE_URL") end + env_yml = prepare_test_app + env_yml["database_url"].should eq expected_db_url("sqlite3", env) + cleanup - it "creates the database when db migrate" do - env_yml = prepare_test_app - CLI.settings.database_url = env_yml["database_url"].to_s + unless ENV["DATABASE_URL"]? + ENV["DATABASE_URL"] = db_url + end + end - MainCommand.run ["generate", "model", "-y", "Post"] - MainCommand.run ["db", "migrate"] + it "creates and deletes the database when db migrate and drop" do + db_url = ENV["DATABASE_URL"]? - db_filename = CLI.settings.database_url.to_s.gsub("sqlite3:", "") - File.exists?(db_filename).should be_true - File.info(db_filename).size.should_not eq 0 - cleanup + if ENV["DATABASE_URL"]? + ENV.delete("DATABASE_URL") end - it "deletes the database when db drop" do - env_yml = prepare_test_app - CLI.settings.database_url = env_yml["database_url"].to_s + env_yml = prepare_test_app + CLI.settings.database_url = env_yml["database_url"].to_s + + MainCommand.run ["generate", "model", "-y", "Post"] + MainCommand.run ["db", "migrate"] + + db_filename = CLI.settings.database_url.to_s.gsub("sqlite3:", "") + File.exists?(db_filename).should be_true + File.info(db_filename).size.should_not eq 0 - MainCommand.run ["generate", "model", "-y", "Post"] - MainCommand.run ["db", "migrate"] - MainCommand.run ["db", "drop"] + MainCommand.run ["db", "drop"] - db_filename = CLI.settings.database_url.gsub("sqlite3:", "") - File.exists?(db_filename).should be_false - cleanup + db_filename = CLI.settings.database_url.gsub("sqlite3:", "") + File.exists?(db_filename).should be_false + cleanup + + unless ENV["DATABASE_URL"]? + ENV["DATABASE_URL"] = db_url end end end describe "postgres" do - context ENV["AMBER_ENV"] do - it "has #{ENV["AMBER_ENV"]} connection settings" do - scaffold_app("#{TESTING_APP}", "-d", "pg") - env_yml = environment_yml(ENV["AMBER_ENV"], "#{Dir.current}/config/environments/") - env_yml["database_url"].should eq expected_db_url("pg", env) - cleanup + it "has test connection settings" do + db_url = ENV["DATABASE_URL"]? + + if ENV["DATABASE_URL"]? + ENV.delete("DATABASE_URL") + end + + scaffold_app("#{TESTING_APP}", "-d", "pg") + env_yml = environment_yml("test", "#{Dir.current}/config/environments/") + env_yml["database_url"].should eq expected_db_url("pg", env) + cleanup + + unless ENV["DATABASE_URL"]? + ENV["DATABASE_URL"] = db_url end end end diff --git a/spec/amber/cli/commands/exec_spec.cr b/spec/amber/cli/commands/exec_spec.cr index 0debf8e59..64b9537af 100644 --- a/spec/amber/cli/commands/exec_spec.cr +++ b/spec/amber/cli/commands/exec_spec.cr @@ -39,9 +39,9 @@ module Amber::CLI it "executes a .cr file from the first command-line argument" do File.write "amber_exec_spec_test.cr", "puts([:a] + [:b])" MainCommand.run(["exec", "amber_exec_spec_test.cr", "-e", "tail"]) + File.delete("amber_exec_spec_test.cr") logs = `ls tmp/*_console_result.log`.strip.split(/\s/).sort File.read(logs.last?.to_s).should eq "[:a, :b]\n" - File.delete("amber_exec_spec_test.cr") end it "opens editor and executes .cr file on close" do diff --git a/spec/amber/cli/commands/init_spec.cr b/spec/amber/cli/commands/init_spec.cr index 24351f48d..94b17c851 100644 --- a/spec/amber/cli/commands/init_spec.cr +++ b/spec/amber/cli/commands/init_spec.cr @@ -42,53 +42,6 @@ module Amber::CLI cleanup end - it "amber new #{TESTING_APP} --minimal" do - ENV["AMBER_ENV"] = "test" - - scaffold_app(TESTING_APP, "--minimal") - camel_case = "PostComment" - snake_case = "post_comment" - class_definition_prefix = "class #{camel_case}" - spec_definition_prefix = "describe #{camel_case}" - - # "generates amber directory structure" do - minimal_folders = dirs(APP_TEMPLATE_PATH) - ["src/assets/javascripts", "src/assets/stylesheets", "config/webpack", - "public/js", "src/views/home"] - dirs("../." + TESTING_APP).sort.should eq minimal_folders.sort - # "follows naming conventions for all files and class names" do - [camel_case, snake_case].each do |arg| - MainCommand.run ["generate", "model", "-y", arg] - filename = snake_case - granite_table_name = "table #{snake_case}s" - src_filepath = "./src/models/#{filename}.cr" - spec_filepath = "./spec/models/#{filename}_spec.cr" - File.exists?(src_filepath).should be_true - File.exists?(spec_filepath).should be_true - File.read(src_filepath).should contain class_definition_prefix - File.read(src_filepath).should contain granite_table_name - File.read(spec_filepath).should contain spec_definition_prefix - File.delete(src_filepath) - File.delete(spec_filepath) - end - cleanup - end - - # This test fails because: - # [04:03:28 Generate | (INFO) Rendering App test_app in ./test_app from damianham/default - # 04:03:29 Generate | (ERROR) Could not find the recipe damianham/default : 404 Not Found - # 04:03:29 Generate | (INFO) Installing Dependencies - # Missing shard.yml. Please run 'shards init' - # Environment file not found for ./config/environments/production - - # context "-r recipe (damianham/default)" do - # it "generates amber directory structure" do - # puts Dir.current - # scaffold_app(TESTING_APP, "-r", "damianham/default") - # dirs("../../"+TESTING_APP).sort.should eq dirs(APP_TEMPLATE_PATH).sort - # cleanup - # end - # end - describe "Database settings" do %w(pg mysql sqlite).each do |db| it "generates #{db} correctly" do diff --git a/spec/amber/controller/render_spec.cr b/spec/amber/controller/render_spec.cr index bdef142f0..9428b19b9 100644 --- a/spec/amber/controller/render_spec.cr +++ b/spec/amber/controller/render_spec.cr @@ -29,11 +29,15 @@ module Amber::Controller RenderController.new(context).render_with_layout.should eq layout_with_template end - it "renders a form with a csrf tag" do - reuslt = RenderController.new(context).render_with_csrf - reuslt.should contain " Hash{ "build_commands" => [ "mkdir -p bin", @@ -60,20 +59,6 @@ module Amber::CLI ], }, } - add_npm_watch_options(options) - end - - def add_npm_watch_options(options) - return options if @minimal - options["npm"] = Hash{ - "build_commands" => [ - "npm install --loglevel=error", - ], - "run_commands" => [ - "npm run watch", - ], - } - options end def self.get_name diff --git a/src/amber/cli/generators.cr b/src/amber/cli/generators.cr index f6181160a..b7d1418ab 100644 --- a/src/amber/cli/generators.cr +++ b/src/amber/cli/generators.cr @@ -233,7 +233,7 @@ module Amber::CLI def generate_app(options) info "Rendering App #{name} in #{directory}" - App.new(name, options.d, options.t, options.minimal?).render(directory, list: true, interactive: !options.assume_yes?, color: options.no_color?) + App.new(name, options.d, options.t).render(directory, list: true, interactive: !options.assume_yes?, color: options.no_color?) unless options.no_deps? info "Installing Dependencies" Helpers.run("cd #{directory} && shards update") diff --git a/src/amber/cli/generators/app.cr b/src/amber/cli/generators/app.cr index 76540c92d..5be7c23d9 100644 --- a/src/amber/cli/generators/app.cr +++ b/src/amber/cli/generators/app.cr @@ -14,9 +14,8 @@ module Amber::CLI @author : String @email : String @github_name : String - @minimal : Bool - def initialize(@name, @database = "pg", @language = "slang", @minimal = false) + def initialize(@name, @database = "pg", @language = "slang") @db_url = "" @wait_for = "" @model = "granite" @@ -26,18 +25,6 @@ module Amber::CLI @github_name = fetch_github_name end - def filter(entries) - entries = entries.reject { |entry| entry.path.includes?("src/views") && !entry.path.includes?("#{@language}") } - filter_for_minimal(entries) - end - - def filter_for_minimal(entries) - return entries unless @minimal - filtered = entries.reject { |entry| entry.path.includes?(".js") || entry.path.includes?(".scss") || entry.path.includes?("package.json") || - entry.path.includes?("config/webpack") || entry.path.includes?("home_controller") } - filtered.reject { |entry| entry.path.includes?("src/views") && !entry.path.includes?("mailer") } - end - private def generate_database_name @name.gsub('-', '_') end @@ -46,6 +33,10 @@ module Amber::CLI system("which git >/dev/null") end + def filter(entries) + entries.reject { |entry| entry.path.includes?("src/views") && !entry.path.includes?("#{@language}") } + end + def fetch_author if which_git_command user_name = `git config --get user.name`.strip diff --git a/src/amber/cli/helpers/process_runner.cr b/src/amber/cli/helpers/process_runner.cr index 1b753a516..445491be4 100644 --- a/src/amber/cli/helpers/process_runner.cr +++ b/src/amber/cli/helpers/process_runner.cr @@ -105,11 +105,7 @@ module Sentry log task, "Terminating process..." end procs.each do |process| - {% if compare_versions(Crystal::VERSION, "0.35.0-0") >= 0 %} process.signal(:term) unless process.terminated? - {% else %} - process.kill unless process.terminated? - {% end %} end procs.clear end diff --git a/src/amber/cli/templates/api/controller/spec/controllers/spec_helper.cr.ecr b/src/amber/cli/templates/api/controller/spec/controllers/spec_helper.cr.ecr index cba784c4c..d47c991fb 100644 --- a/src/amber/cli/templates/api/controller/spec/controllers/spec_helper.cr.ecr +++ b/src/amber/cli/templates/api/controller/spec/controllers/spec_helper.cr.ecr @@ -1 +1,2 @@ require "../spec_helper" +require "../request_helper" diff --git a/src/amber/cli/templates/api/controller/spec/controllers/{{name}}_controller_spec.cr.ecr b/src/amber/cli/templates/api/controller/spec/controllers/{{name}}_controller_spec.cr.ecr index 3abce197d..9c92838e1 100644 --- a/src/amber/cli/templates/api/controller/spec/controllers/{{name}}_controller_spec.cr.ecr +++ b/src/amber/cli/templates/api/controller/spec/controllers/{{name}}_controller_spec.cr.ecr @@ -25,7 +25,8 @@ def <%= create_model_method %> model end -class <%= class_name %>ControllerTest < GarnetSpec::SystemTest +class <%= class_name %>ControllerTest + include RequestHelper getter handler : Amber::Pipe::Pipeline def initialize diff --git a/src/amber/cli/templates/app/.amber.yml.ecr b/src/amber/cli/templates/app/.amber.yml.ecr index 19319d926..100b05076 100644 --- a/src/amber/cli/templates/app/.amber.yml.ecr +++ b/src/amber/cli/templates/app/.amber.yml.ecr @@ -29,10 +29,3 @@ watch: - AMBER_ENV=test crystal spec include: - ./spec/**/*.cr -<%- unless @minimal -%> - npm: - build_commands: - - npm install --loglevel=error - run_commands: - - npm run watch -<%- end -%> diff --git a/src/amber/cli/templates/app/Dockerfile.ecr b/src/amber/cli/templates/app/Dockerfile.ecr index 0c2faeb15..2efcf16d3 100644 --- a/src/amber/cli/templates/app/Dockerfile.ecr +++ b/src/amber/cli/templates/app/Dockerfile.ecr @@ -7,6 +7,4 @@ RUN shards install COPY . /app -RUN rm -rf /app/node_modules - CMD amber watch diff --git a/src/amber/cli/templates/app/config/environments/development.yml.ecr b/src/amber/cli/templates/app/config/environments/development.yml.ecr index fc2fb35ee..787ede95c 100644 --- a/src/amber/cli/templates/app/config/environments/development.yml.ecr +++ b/src/amber/cli/templates/app/config/environments/development.yml.ecr @@ -19,7 +19,7 @@ redis_url: "redis://localhost:6379" when "mysql" -%> database_url: mysql://root@localhost:3306/<%= database_name %>_development <% when "pg" -%> -database_url: postgres://<%= `whoami`.strip("\n") -%>:@localhost:5432/<%= database_name %>_development +database_url: <%= "postgres://postgres:#{ENV["POSTGRES_PASSWORD"]? || "password"}@localhost:5432/#{database_name}_development" %> <% when "sqlite" -%> database_url: sqlite3:./db/<%= database_name %>_development.db <% else diff --git a/src/amber/cli/templates/app/config/environments/production.yml.ecr b/src/amber/cli/templates/app/config/environments/production.yml.ecr index dcf46ab28..e03c3d96c 100644 --- a/src/amber/cli/templates/app/config/environments/production.yml.ecr +++ b/src/amber/cli/templates/app/config/environments/production.yml.ecr @@ -19,7 +19,7 @@ redis_url: "redis://localhost:6379" when "mysql" -%> database_url: mysql://root@localhost:3306/<%= database_name %> <% when "pg" -%> -database_url: postgres://<%= `whoami`.strip("\n") %>:@localhost:5432/<%= database_name %> +database_url: <%= "postgres://postgres:#{ENV["POSTGRES_PASSWORD"]? || "password"}@localhost:5432/#{database_name}" %> <% when "sqlite" -%> database_url: sqlite3:./db/<%= database_name %>.db <% else diff --git a/src/amber/cli/templates/app/config/routes.cr.ecr b/src/amber/cli/templates/app/config/routes.cr.ecr index ad1783acb..f706e0630 100644 --- a/src/amber/cli/templates/app/config/routes.cr.ecr +++ b/src/amber/cli/templates/app/config/routes.cr.ecr @@ -28,9 +28,7 @@ Amber::Server.configure do end routes :web do -<% unless @minimal -%> get "/", HomeController, :index -<% end -%> end routes :api do diff --git a/src/amber/cli/templates/app/config/webpack/common.js b/src/amber/cli/templates/app/config/webpack/common.js deleted file mode 100644 index 3d018635a..000000000 --- a/src/amber/cli/templates/app/config/webpack/common.js +++ /dev/null @@ -1,71 +0,0 @@ -const webpack = require('webpack'); -const path = require('path'); -const MiniCssExtractPlugin = require('mini-css-extract-plugin'); -const { CleanWebpackPlugin } = require('clean-webpack-plugin'); -const HtmlWebpackPlugin = require('html-webpack-plugin'); - -let config = { - entry: { - main: path.resolve(__dirname, 'entry.js') - }, - output: { - filename: '[name].bundle.js', - path: path.resolve(__dirname, '../../public/dist'), - publicPath: '/dist' - }, - resolve: { - alias: { - amber: path.resolve(__dirname, '../../lib/amber/assets/js/amber.js') - } - }, - module: { - rules: [ - { - test: /\.(sass|scss|css)$/, - exclude: /node_modules/, - use: [ - MiniCssExtractPlugin.loader, - 'css-loader', - 'sass-loader' - ] - }, - { - test: /\.(png|svg|jpg|gif)$/, - exclude: /node_modules/, - use: [ - 'file-loader?name=/images/[name].[ext]' - ] - }, - { - test: /\.(woff|woff2|eot|ttf|otf)$/, - exclude: /node_modules/, - use: [ - 'file-loader?name=/[name].[ext]' - ] - }, - { - test: /\.js$/, - exclude: /node_modules/, - use: { - loader: 'babel-loader', - options: { - presets: ['@babel/preset-env'] - } - } - } - ] - }, - plugins: [ - new MiniCssExtractPlugin({ - filename: '[name].bundle.css' - }), - new CleanWebpackPlugin(), - new HtmlWebpackPlugin({ - title: 'Caching', - }), - ], - // For more info about webpack logs see: https://webpack.js.org/configuration/stats/ - stats: 'errors-only' -}; - -module.exports = config; diff --git a/src/amber/cli/templates/app/config/webpack/development.js b/src/amber/cli/templates/app/config/webpack/development.js deleted file mode 100644 index b50c903fd..000000000 --- a/src/amber/cli/templates/app/config/webpack/development.js +++ /dev/null @@ -1,8 +0,0 @@ -const webpack = require('webpack'); -const { merge } = require('webpack-merge'); -const common = require('./common.js'); - -module.exports = merge(common, { - mode: 'development', - devtool: 'inline-source-map' -}); diff --git a/src/amber/cli/templates/app/config/webpack/entry.js b/src/amber/cli/templates/app/config/webpack/entry.js deleted file mode 100644 index a8932490d..000000000 --- a/src/amber/cli/templates/app/config/webpack/entry.js +++ /dev/null @@ -1,10 +0,0 @@ -// This is the Webpack entrypoint and acts as a shim to load both the JavaScript -// and CSS source files into Webpack. It is mainly here to avoid requiring -// stylesheets from the javascripts asset directory and keep those concerns -// separate from each other within the src directory. -// -// This will be removed from Webpack 5 onward. -// See: https://github.com/webpack-contrib/mini-css-extract-plugin/issues/151 - -import '../../src/assets/javascripts/main.js'; -import '../../src/assets/stylesheets/main.scss'; diff --git a/src/amber/cli/templates/app/config/webpack/production.js b/src/amber/cli/templates/app/config/webpack/production.js deleted file mode 100644 index 4635aee93..000000000 --- a/src/amber/cli/templates/app/config/webpack/production.js +++ /dev/null @@ -1,10 +0,0 @@ -const webpack = require('webpack'); -const { merge } = require('webpack-merge'); -const common = require('./common.js'); - -module.exports = merge(common, { - mode: 'production', - optimization: { - minimize: true - } -}); diff --git a/src/amber/cli/templates/app/docker-compose.yml.ecr b/src/amber/cli/templates/app/docker-compose.yml.ecr index 9888cabe3..3d28f41fe 100644 --- a/src/amber/cli/templates/app/docker-compose.yml.ecr +++ b/src/amber/cli/templates/app/docker-compose.yml.ecr @@ -24,7 +24,6 @@ services: - db volumes: - .:/app - - nodes:/app/node_modules - shards:/app/lib migrate: @@ -51,7 +50,7 @@ services: - db:/var/lib/postgres/data <% elsif @database == "mysql" -%> db: - image: mysql:5.6 + image: mysql ports: - 3306:3306 environment: @@ -71,5 +70,4 @@ services: volumes: db: - nodes: shards: diff --git a/src/amber/cli/templates/app/package.json.ecr b/src/amber/cli/templates/app/package.json.ecr deleted file mode 100644 index fb430fd3b..000000000 --- a/src/amber/cli/templates/app/package.json.ecr +++ /dev/null @@ -1,40 +0,0 @@ -{ - "name": "<%= @name %>", - "version": "0.1.0", - "description": "<%= display_name %> with Amber", - "private": true, - "author": "<%= @author %>", - "license": "UNLICENSED", - "scripts": { - "build": "webpack --config config/webpack/development.js", - "watch": "webpack -w --config config/webpack/development.js", - "release": "webpack --mode production --config config/webpack/production.js", - "test": "echo \"No test specified\" && exit 1" - }, - "devDependencies": { - "@babel/core": "^7.14.0", - "@babel/preset-env": "^7.14.0", - "babel-loader": "^8.2.2", - "clean-webpack-plugin": "^3.0.0", - "css-loader": "^5.2.4", - "file-loader": "^6.2.0", - "html-webpack-plugin": "^5.3.1", - "mini-css-extract-plugin": "^1.6.0", - <% if `node -v`.matches?(/v14/) -%> - "node-sass": "^5.0.0", - "sass-loader": "^11.0.1", - <% else -%> - "node-sass": "^7.0.0", - "sass-loader": "^13.0.2", - <% end -%> - "webpack": "^5.36.2", - "webpack-cli": "^4.6.0", - "webpack-merge": "^5.7.3" - - }, - "dependencies": { - "bootstrap": "^4.2.1", - "jquery": "^3.3.1", - "popper.js": "^1.14.6" - } -} diff --git a/src/amber/cli/templates/app/public/css/main.css b/src/amber/cli/templates/app/public/css/main.css new file mode 100644 index 000000000..91b7d27a8 --- /dev/null +++ b/src/amber/cli/templates/app/public/css/main.css @@ -0,0 +1,7 @@ +.main { + padding-top: 20px; +} + +.bg-primary { + background-color: #f4994b !important +} diff --git a/src/amber/cli/templates/app/src/assets/fonts/.gitkeep b/src/amber/cli/templates/app/public/fonts/.gitkeep similarity index 100% rename from src/amber/cli/templates/app/src/assets/fonts/.gitkeep rename to src/amber/cli/templates/app/public/fonts/.gitkeep diff --git a/src/amber/cli/templates/app/src/assets/images/.gitkeep b/src/amber/cli/templates/app/public/img/.gitkeep similarity index 100% rename from src/amber/cli/templates/app/src/assets/images/.gitkeep rename to src/amber/cli/templates/app/public/img/.gitkeep diff --git a/src/amber/cli/templates/app/src/assets/images/logo.svg b/src/amber/cli/templates/app/public/img/logo.svg similarity index 100% rename from src/amber/cli/templates/app/src/assets/images/logo.svg rename to src/amber/cli/templates/app/public/img/logo.svg diff --git a/assets/js/amber.js b/src/amber/cli/templates/app/public/js/amber.js similarity index 100% rename from assets/js/amber.js rename to src/amber/cli/templates/app/public/js/amber.js diff --git a/src/amber/cli/templates/app/shard.yml.ecr b/src/amber/cli/templates/app/shard.yml.ecr index e2b349fad..39dfc80cb 100644 --- a/src/amber/cli/templates/app/shard.yml.ecr +++ b/src/amber/cli/templates/app/shard.yml.ecr @@ -52,9 +52,6 @@ dependencies: version: ~> 1.0.0 development_dependencies: - garnet_spec: - github: amberframework/garnet-spec - version: 0.4.1 ameba: github: crystal-ameba/ameba version: ~> 0.13.4 diff --git a/src/amber/cli/templates/app/spec/request_helper.cr.ecr b/src/amber/cli/templates/app/spec/request_helper.cr.ecr new file mode 100644 index 000000000..ca67a4bb9 --- /dev/null +++ b/src/amber/cli/templates/app/spec/request_helper.cr.ecr @@ -0,0 +1,30 @@ +require "http" + +module RequestHelper + macro included + {% http_read_verbs = %w(get head options trace connect) %} + {% http_write_verbs = %w(post put patch delete) %} + {% http_verbs = http_read_verbs + http_write_verbs %} + + {% for method in http_verbs %} + def {{method.id}}(path, headers : HTTP::Headers? = nil, body : String? = nil) + request = HTTP::Request.new("{{method.id}}".upcase, path, headers, body ) + {% if http_write_verbs.includes? method %} + request.headers["Content-Type"] ||= "application/x-www-form-urlencoded" + {% end %} + process_request(request) + end + {% end %} + end + + private def process_request(request) + io = IO::Memory.new + response = HTTP::Server::Response.new(io) + context = HTTP::Server::Context.new(request, response) + handler.call context + response.close + io.rewind + client_response = HTTP::Client::Response.from_io(io, decompress: false) + client_response + end +end diff --git a/src/amber/cli/templates/app/spec/spec_helper.cr.ecr b/src/amber/cli/templates/app/spec/spec_helper.cr.ecr index ddf80c3ce..5f3e24578 100644 --- a/src/amber/cli/templates/app/spec/spec_helper.cr.ecr +++ b/src/amber/cli/templates/app/spec/spec_helper.cr.ecr @@ -2,7 +2,6 @@ ENV["AMBER_ENV"] ||= "test" require "spec" require "micrate" -require "garnet_spec" require "../config/application" diff --git a/src/amber/cli/templates/app/src/assets/javascripts/main.js b/src/amber/cli/templates/app/src/assets/javascripts/main.js deleted file mode 100644 index 5ab02433f..000000000 --- a/src/amber/cli/templates/app/src/assets/javascripts/main.js +++ /dev/null @@ -1,3 +0,0 @@ -import 'bootstrap'; -import Amber from 'amber'; -import Logo from '../images/logo.svg'; diff --git a/src/amber/cli/templates/app/src/assets/stylesheets/main.scss b/src/amber/cli/templates/app/src/assets/stylesheets/main.scss deleted file mode 100644 index 55b23a64f..000000000 --- a/src/amber/cli/templates/app/src/assets/stylesheets/main.scss +++ /dev/null @@ -1,7 +0,0 @@ -$primary: #f4994b; - -@import '~bootstrap/scss/bootstrap'; - -.main { - padding-top: 20px; -} diff --git a/src/amber/cli/templates/app/src/controllers/application_controller.cr.ecr b/src/amber/cli/templates/app/src/controllers/application_controller.cr.ecr index 3ed2194ab..a9b2a7c6a 100644 --- a/src/amber/cli/templates/app/src/controllers/application_controller.cr.ecr +++ b/src/amber/cli/templates/app/src/controllers/application_controller.cr.ecr @@ -2,9 +2,5 @@ require "jasper_helpers" class ApplicationController < Amber::Controller::Base include JasperHelpers - <%- if @minimal -%> - LAYOUT = false - <%- else -%> LAYOUT = "application.<%= @language %>" - <%- end -%> end diff --git a/src/amber/cli/templates/app/src/views/home/index.ecr.ecr b/src/amber/cli/templates/app/src/views/home/index.ecr.ecr index 1525fc836..200cb15a2 100644 --- a/src/amber/cli/templates/app/src/views/home/index.ecr.ecr +++ b/src/amber/cli/templates/app/src/views/home/index.ecr.ecr @@ -4,7 +4,7 @@

Thank you for trying out the Amber Framework. We are working hard to provide a super fast and reliable framework that provides all the productivity tools you are used to without sacrificing the speed.

diff --git a/src/amber/cli/templates/app/src/views/home/index.slang.ecr b/src/amber/cli/templates/app/src/views/home/index.slang.ecr index a7080da73..737981685 100644 --- a/src/amber/cli/templates/app/src/views/home/index.slang.ecr +++ b/src/amber/cli/templates/app/src/views/home/index.slang.ecr @@ -5,4 +5,4 @@ .list-group a.list-group-item.list-group-item-action target="_blank" href="https://docs.amberframework.org" Getting Started with Amber Framework a.list-group-item.list-group-item-action target="_blank" href="https://github.com/veelenga/awesome-crystal" List of Awesome Crystal projects and shards - a.list-grouo-item.list-group-item-action target="_blank" href="https://discord.gg/vwvP5zakSn" Join the Amber Discord! + a.list-group-item.list-group-item-action target="_blank" href="https://discord.gg/vwvP5zakSn" Join the Amber Discord! diff --git a/src/amber/cli/templates/app/src/views/layouts/application.ecr.ecr b/src/amber/cli/templates/app/src/views/layouts/application.ecr.ecr index dc13a7574..fe092e60c 100644 --- a/src/amber/cli/templates/app/src/views/layouts/application.ecr.ecr +++ b/src/amber/cli/templates/app/src/views/layouts/application.ecr.ecr @@ -5,7 +5,8 @@ - + + @@ -14,7 +15,7 @@