potassium 6.7.0 → 7.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (78) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +23 -0
  3. data/README.md +8 -1
  4. data/lib/potassium/assets/.circleci/config.yml.erb +14 -8
  5. data/lib/potassium/assets/.eslintrc.json +13 -7
  6. data/lib/potassium/assets/.rubocop.yml +62 -1
  7. data/lib/potassium/assets/README.yml +3 -9
  8. data/lib/potassium/assets/app/frontend/active_admin/jquery.js +2 -0
  9. data/lib/potassium/assets/app/frontend/api/__mocks__/index.mock.ts +3 -0
  10. data/lib/potassium/assets/app/frontend/api/index.ts +63 -0
  11. data/lib/potassium/assets/app/frontend/css/application.css +3 -0
  12. data/lib/potassium/assets/app/frontend/entrypoints/active_admin.js +7 -0
  13. data/lib/potassium/assets/app/frontend/entrypoints/active_admin.scss +38 -0
  14. data/lib/potassium/assets/app/frontend/entrypoints/application.js +12 -0
  15. data/lib/potassium/assets/app/{javascript → frontend}/types/vue.d.ts +1 -0
  16. data/lib/potassium/assets/app/{javascript → frontend}/utils/case-converter.ts +2 -2
  17. data/lib/potassium/assets/app/frontend/utils/csrf-token.ts +9 -0
  18. data/lib/potassium/assets/bin/setup.erb +1 -1
  19. data/lib/potassium/assets/bin/update.erb +1 -1
  20. data/lib/potassium/assets/config/sentry.rb.erb +2 -10
  21. data/lib/potassium/assets/lib/dotenv_monkeypatch.rb +19 -0
  22. data/lib/potassium/assets/package.json +7 -0
  23. data/lib/potassium/assets/tailwind.config.js +14 -0
  24. data/lib/potassium/assets/testing/simplecov_config.rb +9 -1
  25. data/lib/potassium/assets/tsconfig.config.json +8 -0
  26. data/lib/potassium/assets/tsconfig.json +11 -27
  27. data/lib/potassium/assets/vite.config.ts +46 -0
  28. data/lib/potassium/cli_options.rb +6 -4
  29. data/lib/potassium/platanus_config.rb +1 -1
  30. data/lib/potassium/recipes/admin.rb +42 -72
  31. data/lib/potassium/recipes/background_processor.rb +1 -1
  32. data/lib/potassium/recipes/bullet.rb +41 -0
  33. data/lib/potassium/recipes/ci.rb +1 -0
  34. data/lib/potassium/recipes/cleanup.rb +0 -1
  35. data/lib/potassium/recipes/coverage.rb +4 -27
  36. data/lib/potassium/recipes/database_container.rb +1 -1
  37. data/lib/potassium/recipes/error_reporting.rb +2 -2
  38. data/lib/potassium/recipes/front_end_vite.rb +153 -0
  39. data/lib/potassium/recipes/google_tag_manager.rb +19 -23
  40. data/lib/potassium/recipes/mjml.rb +1 -1
  41. data/lib/potassium/recipes/node.rb +1 -1
  42. data/lib/potassium/recipes/style.rb +3 -5
  43. data/lib/potassium/recipes/vue_admin.rb +7 -13
  44. data/lib/potassium/recipes/yarn.rb +1 -1
  45. data/lib/potassium/templates/application.rb +4 -8
  46. data/lib/potassium/version.rb +6 -6
  47. data/spec/features/api_spec.rb +2 -2
  48. data/spec/features/background_processor_spec.rb +2 -2
  49. data/spec/features/bullet_spec.rb +29 -0
  50. data/spec/features/ci_spec.rb +10 -4
  51. data/spec/features/coverage_spec.rb +7 -6
  52. data/spec/features/database_container_spec.rb +1 -1
  53. data/spec/features/database_spec.rb +1 -1
  54. data/spec/features/draper_spec.rb +1 -1
  55. data/spec/features/error_reporting_spec.rb +2 -2
  56. data/spec/features/file_storage_spec.rb +4 -4
  57. data/spec/features/google_tag_manager_spec.rb +1 -1
  58. data/spec/features/i18n_spec.rb +1 -1
  59. data/spec/features/mailer_spec.rb +1 -0
  60. data/spec/features/new_project_spec.rb +1 -1
  61. data/spec/features/power_types_spec.rb +1 -1
  62. data/spec/features/pundit_spec.rb +1 -1
  63. data/spec/features/schedule_spec.rb +1 -1
  64. data/spec/features/testing_spec.rb +0 -1
  65. data/spec/features/vue_admin_spec.rb +1 -1
  66. data/spec/front_end_vite_spec.rb +81 -0
  67. metadata +26 -18
  68. data/lib/potassium/assets/app/javascript/api/index.ts +0 -55
  69. data/lib/potassium/assets/config/webpack/rules/css.js +0 -5
  70. data/lib/potassium/assets/config/webpack/rules/index.js +0 -11
  71. data/lib/potassium/assets/config/webpack/rules/jquery.js +0 -11
  72. data/lib/potassium/assets/config/webpack/rules/typescript.js +0 -32
  73. data/lib/potassium/assets/config/webpack/rules/vue.js +0 -19
  74. data/lib/potassium/assets/config/webpack/webpack.config.js +0 -4
  75. data/lib/potassium/recipes/front_end.rb +0 -270
  76. data/spec/features/front_end_spec.rb +0 -76
  77. /data/lib/potassium/assets/app/{javascript → frontend}/components/app.spec.ts +0 -0
  78. /data/lib/potassium/assets/app/{javascript → frontend}/components/app.vue +0 -0
@@ -1,270 +0,0 @@
1
- class Recipes::FrontEnd < Rails::AppBuilder
2
- VUE_LOADER_VERSION = Potassium::VUE_LOADER_VERSION
3
- VUE_VERSION = Potassium::VUE_VERSION
4
- VUE_TEST_UTILS_VERSION = Potassium::VUE_TEST_UTILS_VERSION
5
- POSTCSS_VERSION = Potassium::POSTCSS_VERSION
6
- TAILWINDCSS_VERSION = Potassium::TAILWINDCSS_VERSION
7
- AUTOPREFIXER_VERSION = Potassium::AUTOPREFIXER_VERSION
8
- JEST_VERSION = Potassium::JEST_VERSION
9
-
10
- def ask
11
- frameworks = {
12
- vue: "Vue",
13
- none: "None"
14
- }
15
-
16
- framework = answer(:front_end) do
17
- frameworks.keys[
18
- Ask.list("Which front-end framework are you going to use?", frameworks.values)
19
- ]
20
- end
21
- set :front_end, framework.to_sym
22
- end
23
-
24
- def create
25
- gather_gem('shakapacker', '~> 6.2.0')
26
- recipe = self
27
- after(:gem_install, wrap_in_action: :webpacker_install) do
28
- run "rails webpacker:install"
29
- end
30
- after(:webpacker_install) do
31
- value = get(:front_end)
32
- recipe.copy_webpack_rules
33
- recipe.add_assets_path
34
- recipe.setup_typescript
35
- recipe.setup_vue if value == :vue
36
- recipe.add_responsive_meta_tag
37
- recipe.setup_tailwind
38
- recipe.setup_api_client
39
- add_readme_header :webpack
40
- end
41
- end
42
-
43
- def install
44
- ask
45
- create
46
- end
47
-
48
- def installed?
49
- package_file = 'package.json'
50
- return false unless file_exist?(package_file)
51
-
52
- package_content = read_file(package_file)
53
- package_content.include?("\"vue\"")
54
- end
55
-
56
- def copy_webpack_rules
57
- copy_file '../assets/config/webpack/webpack.config.js',
58
- 'config/webpack/webpack.config.js',
59
- force: true
60
- copy_file '../assets/config/webpack/rules/index.js', 'config/webpack/rules/index.js'
61
- copy_file '../assets/config/webpack/rules/css.js', 'config/webpack/rules/css.js'
62
- copy_file '../assets/config/webpack/rules/vue.js', 'config/webpack/rules/vue.js'
63
- copy_file '../assets/config/webpack/rules/jquery.js', 'config/webpack/rules/jquery.js'
64
- copy_file '../assets/config/webpack/rules/typescript.js', 'config/webpack/rules/typescript.js'
65
- end
66
-
67
- def add_assets_path
68
- gsub_file(
69
- 'config/webpacker.yml',
70
- 'additional_paths: []',
71
- "additional_paths: ['app/assets']"
72
- )
73
- end
74
-
75
- def setup_typescript
76
- run "bin/yarn add typescript fork-ts-checker-webpack-plugin ts-loader @types/node"
77
- copy_file '../assets/tsconfig.json', 'tsconfig.json'
78
- end
79
-
80
- def setup_vue_with_compiler_build
81
- application_js = 'app/javascript/application.js'
82
- create_file application_js, application_js_content, force: true
83
-
84
- layout_file = "app/views/layouts/application.html.erb"
85
- insert_into_file(
86
- layout_file,
87
- "<div id=\"vue-app\">\n <app></app>\n ",
88
- before: "<%= yield %>"
89
- )
90
- insert_into_file layout_file, "\n </div>", after: "<%= yield %>"
91
- end
92
-
93
- def add_responsive_meta_tag
94
- tag = "\n <meta name=\"viewport\" content=\"width=device-width, initial-scale=1\">\n"
95
- layout_file = "app/views/layouts/application.html.erb"
96
- insert_into_file layout_file, tag, after: "<%= csrf_meta_tags %>"
97
- end
98
-
99
- def setup_tailwind
100
- run "bin/yarn add css-loader style-loader mini-css-extract-plugin @types/tailwindcss "\
101
- "css-minimizer-webpack-plugin postcss@#{POSTCSS_VERSION} postcss-loader "\
102
- "tailwindcss@#{TAILWINDCSS_VERSION} autoprefixer@#{AUTOPREFIXER_VERSION} sass sass-loader "\
103
- "eslint-plugin-tailwindcss"
104
- run "npx tailwindcss init -p"
105
- setup_client_css
106
- remove_server_css_requires
107
- setup_tailwind_requirements
108
- end
109
-
110
- def setup_jest
111
- run "bin/yarn add jest@#{JEST_VERSION} @vue/vue3-jest@#{JEST_VERSION} "\
112
- "babel-jest@#{JEST_VERSION} @vue/test-utils@#{VUE_TEST_UTILS_VERSION} ts-jest@#{JEST_VERSION} "\
113
- "jest-environment-jsdom@#{JEST_VERSION} --dev"
114
- run "bin/yarn add @types/jest@#{JEST_VERSION}"
115
- json_file = File.read(Pathname.new("package.json"))
116
- js_package = JSON.parse(json_file)
117
- js_package = js_package.merge(jest_config)
118
- json_string = JSON.pretty_generate(js_package)
119
- create_file 'package.json', json_string, force: true
120
-
121
- copy_file '../assets/app/javascript/components/app.spec.ts',
122
- 'app/javascript/components/app.spec.ts'
123
- end
124
-
125
- def setup_vue
126
- run "bin/yarn add vue@#{VUE_VERSION} vue-loader@#{VUE_LOADER_VERSION} "\
127
- "babel-preset-typescript-vue3 @types/humps"
128
- run "bin/yarn add vue-tsc --dev"
129
- gsub_file(
130
- 'config/webpack/webpack.config.js',
131
- ' merge(typescriptConfig, cssConfig, jQueryConfig, webpackConfig);',
132
- ' merge(vueConfig, typescriptConfig, cssConfig, jQueryConfig, webpackConfig);'
133
- )
134
- copy_file '../assets/app/javascript/components/app.vue', 'app/javascript/components/app.vue'
135
- copy_file '../assets/app/javascript/types/vue.d.ts', 'app/javascript/types/vue.d.ts'
136
- setup_vue_with_compiler_build
137
- recipe = self
138
- run_action(:setup_jest) do
139
- recipe.setup_jest
140
- end
141
- end
142
-
143
- def setup_api_client
144
- run "bin/yarn add axios humps"
145
- copy_file '../assets/app/javascript/api/index.ts', 'app/javascript/api/index.ts'
146
- copy_file '../assets/app/javascript/utils/case-converter.ts',
147
- 'app/javascript/utils/case-converter.ts'
148
- end
149
-
150
- private
151
-
152
- def frameworks(framework)
153
- frameworks = {
154
- vue: "vue",
155
- none: nil
156
- }
157
- frameworks[framework]
158
- end
159
-
160
- def setup_client_css
161
- application_css = 'app/javascript/css/application.css'
162
- create_file application_css, "", force: true
163
-
164
- stylesheet_pack_tag = "\n <%= stylesheet_pack_tag 'application' %>\n "
165
- layout_file = "app/views/layouts/application.html.erb"
166
- insert_into_file layout_file, stylesheet_pack_tag, before: "</head>"
167
-
168
- application_js = 'app/javascript/application.js'
169
- if get(:front_end) != :vue
170
- create_file application_js, "import './css/application.css';\n", force: true
171
- else
172
- insert_into_file(
173
- application_js,
174
- "\nimport './css/application.css';",
175
- after: "import App from './components/app.vue';"
176
- )
177
- end
178
- end
179
-
180
- def setup_tailwind_requirements
181
- application_css = 'app/javascript/css/application.css'
182
- insert_into_file application_css, tailwind_client_css
183
-
184
- tailwind_config = 'tailwind.config.js'
185
- create_file tailwind_config, tailwind_config_content, force: true
186
- end
187
-
188
- def remove_server_css_requires
189
- assets_css_file = 'app/assets/stylesheets/application.css'
190
- gsub_file(assets_css_file, " *= require_tree .\n *= require_self\n", "")
191
- end
192
-
193
- def application_js_content
194
- <<~JS
195
- import { createApp } from 'vue';
196
- import App from './components/app.vue';
197
-
198
- document.addEventListener('DOMContentLoaded', () => {
199
- const app = createApp({
200
- components: { App },
201
- });
202
- app.mount('#vue-app');
203
-
204
- return app;
205
- });
206
- JS
207
- end
208
-
209
- def tailwind_client_css
210
- <<~CSS
211
- @tailwind base;
212
- @tailwind components;
213
- @tailwind utilities;
214
- CSS
215
- end
216
-
217
- def tailwind_config_content
218
- <<~JS
219
- /* eslint-disable no-undef */
220
- module.exports = {
221
- theme: {
222
- extend: {},
223
- },
224
- variants: {},
225
- plugins: [],
226
- content: [
227
- './app/**/*.html',
228
- './app/**/*.vue',
229
- './app/**/*.js',
230
- './app/**/*.erb',
231
- ],
232
- };
233
- JS
234
- end
235
-
236
- def jest_config
237
- {
238
- "scripts": {
239
- "test": "jest",
240
- "test:watch": "jest --watch"
241
- },
242
- "jest": {
243
- "roots": [
244
- "app/javascript"
245
- ],
246
- "moduleDirectories": [
247
- "node_modules",
248
- "app/javascript"
249
- ],
250
- "moduleNameMapper": {
251
- "^@/(.*)$": "app/javascript/$1"
252
- },
253
- "testEnvironmentOptions": {
254
- "customExportConditions": ["node", "node-addons"]
255
- },
256
- "moduleFileExtensions": [
257
- "js",
258
- "ts",
259
- "json",
260
- "vue"
261
- ],
262
- "transform": {
263
- "^.+\\.ts$": "ts-jest",
264
- ".*\\.(vue)$": "@vue/vue3-jest"
265
- },
266
- "testEnvironment": "jsdom"
267
- }
268
- }
269
- end
270
- end
@@ -1,76 +0,0 @@
1
- require "spec_helper"
2
-
3
- RSpec.describe "Front end" do
4
- before :all do
5
- drop_dummy_database
6
- remove_project_directory
7
- end
8
-
9
- let(:application_css_path) { "#{project_path}/app/javascript/css/application.css" }
10
- let(:gemfile) { IO.read("#{project_path}/Gemfile") }
11
- let(:node_modules_file) { IO.read("#{project_path}/package.json") }
12
- let(:application_js_file) { IO.read("#{project_path}/app/javascript/application.js") }
13
- let(:layout_file) { IO.read("#{project_path}/app/views/layouts/application.html.erb") }
14
- let(:application_css_file) { IO.read(application_css_path) }
15
- let(:tailwind_config_file) { IO.read("#{project_path}/tailwind.config.js") }
16
- let(:rails_css_file) { IO.read("#{project_path}/app/assets/stylesheets/application.css") }
17
-
18
- it "creates a project without a front end framework" do
19
- remove_project_directory
20
- create_dummy_project("front_end" => "None")
21
- expect(gemfile).to include('shakapacker')
22
- end
23
-
24
- def expect_to_have_tailwind_package_versions
25
- expect(node_modules_file).to include("\"tailwindcss\": \"^3\"")
26
- expect(node_modules_file).to include("\"autoprefixer\": \"^10\"")
27
- expect(node_modules_file).to include("\"postcss\": \"^8\"")
28
- end
29
-
30
- context "with vue" do
31
- before(:all) do
32
- remove_project_directory
33
- create_dummy_project("front_end" => "vue")
34
- end
35
-
36
- it "creates a project with vue as frontend framework" do
37
- expect(gemfile).to include('shakapacker')
38
- expect(node_modules_file).to include("\"vue\"")
39
- expect(application_js_file).to include('vue')
40
- expect(application_js_file).to include("app.mount('#vue-app')")
41
- expect(layout_file).to include('id="vue-app"')
42
- end
43
-
44
- it "creates a project with only one js pack tag" do
45
- expect(layout_file.scan("javascript_pack_tag").length).to eq(1)
46
- end
47
-
48
- it "creates a vue project with client css" do
49
- expect(application_js_file).to include("import './css/application.css';")
50
- expect(layout_file).to include("<%= stylesheet_pack_tag 'application' %>")
51
- expect(rails_css_file).not_to include('*= require_tree', '*= require_self')
52
- end
53
-
54
- it "creates a vue project with tailwindcss" do
55
- expect(node_modules_file).to include("\"tailwindcss\"")
56
- expect(application_css_file).to include(
57
- "@tailwind base;",
58
- "@tailwind components;"
59
- )
60
- expect(tailwind_config_file).to include('module.exports')
61
- end
62
-
63
- it 'includes correct packages for tailwind, postcss and autoprefixer compatibility build' do
64
- expect_to_have_tailwind_package_versions
65
- end
66
-
67
- it 'includes correct version of vue-loader in package' do
68
- expect(node_modules_file).to include("\"vue-loader\": \"#{Potassium::VUE_LOADER_VERSION}\"")
69
- end
70
-
71
- it 'includes correct packages for basic api client' do
72
- expect(node_modules_file).to include("\"axios\"")
73
- expect(node_modules_file).to include("\"humps\"")
74
- end
75
- end
76
- end