potassium 6.6.0 → 7.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (78) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +37 -0
  3. data/README.md +8 -1
  4. data/lib/potassium/assets/.circleci/config.yml.erb +31 -12
  5. data/lib/potassium/assets/.eslintrc.json +15 -8
  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/frontend/utils/case-converter.ts +39 -0
  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 -26
  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 +40 -32
  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/file_storage.rb +1 -1
  39. data/lib/potassium/recipes/front_end_vite.rb +153 -0
  40. data/lib/potassium/recipes/google_tag_manager.rb +19 -23
  41. data/lib/potassium/recipes/mjml.rb +1 -1
  42. data/lib/potassium/recipes/node.rb +1 -1
  43. data/lib/potassium/recipes/style.rb +4 -5
  44. data/lib/potassium/recipes/vue_admin.rb +7 -13
  45. data/lib/potassium/recipes/yarn.rb +1 -1
  46. data/lib/potassium/templates/application.rb +4 -8
  47. data/lib/potassium/version.rb +9 -9
  48. data/spec/features/api_spec.rb +2 -2
  49. data/spec/features/background_processor_spec.rb +2 -2
  50. data/spec/features/bullet_spec.rb +29 -0
  51. data/spec/features/ci_spec.rb +10 -4
  52. data/spec/features/coverage_spec.rb +7 -6
  53. data/spec/features/database_container_spec.rb +1 -1
  54. data/spec/features/database_spec.rb +1 -1
  55. data/spec/features/draper_spec.rb +1 -1
  56. data/spec/features/error_reporting_spec.rb +2 -2
  57. data/spec/features/file_storage_spec.rb +4 -4
  58. data/spec/features/google_tag_manager_spec.rb +1 -1
  59. data/spec/features/i18n_spec.rb +1 -1
  60. data/spec/features/mailer_spec.rb +1 -0
  61. data/spec/features/new_project_spec.rb +1 -1
  62. data/spec/features/power_types_spec.rb +1 -1
  63. data/spec/features/pundit_spec.rb +1 -1
  64. data/spec/features/schedule_spec.rb +1 -1
  65. data/spec/features/testing_spec.rb +0 -1
  66. data/spec/features/vue_admin_spec.rb +1 -1
  67. data/spec/front_end_vite_spec.rb +81 -0
  68. metadata +26 -16
  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 -256
  76. data/spec/features/front_end_spec.rb +0 -71
  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,11 +0,0 @@
1
- const webpack = require('webpack');
2
-
3
- module.exports = {
4
- plugins: [
5
- new webpack.ProvidePlugin({
6
- $: 'jquery',
7
- jQuery: 'jquery',
8
- "window.jQuery":"jquery"
9
- })
10
- ],
11
- }
@@ -1,32 +0,0 @@
1
- const ForkTsCheckerWebpackPlugin = require('fork-ts-checker-webpack-plugin');
2
-
3
- module.exports = {
4
- module: {
5
- rules: [
6
- {
7
- test: /\.ts$/,
8
- loader: 'ts-loader',
9
- exclude: /node_modules/,
10
- options: {
11
- appendTsSuffixTo: [/\.vue$/],
12
- transpileOnly: true,
13
- },
14
- },
15
- ],
16
- },
17
- resolve: {
18
- extensions: ['.ts'],
19
- },
20
- plugins: [
21
- new ForkTsCheckerWebpackPlugin({
22
- typescript: {
23
- extensions: {
24
- vue: {
25
- enabled: true,
26
- compiler: '@vue/compiler-sfc',
27
- },
28
- },
29
- },
30
- }),
31
- ],
32
- };
@@ -1,19 +0,0 @@
1
- const { VueLoaderPlugin } = require('vue-loader')
2
-
3
- module.exports = {
4
- module: {
5
- rules: [
6
- {
7
- test: /\.vue$/,
8
- loader: 'vue-loader'
9
- }
10
- ]
11
- },
12
- plugins: [new VueLoaderPlugin()],
13
- resolve: {
14
- extensions: ['.vue'],
15
- alias: {
16
- 'vue$': 'vue/dist/vue.esm-bundler.js',
17
- }
18
- },
19
- }
@@ -1,4 +0,0 @@
1
- const { webpackConfig, merge } = require('shakapacker');
2
- const { vueConfig, cssConfig, jQueryConfig, typescriptConfig } = require('./rules');
3
-
4
- module.exports = merge(typescriptConfig, cssConfig, jQueryConfig, webpackConfig);
@@ -1,256 +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
- VUE_JEST_VERSION = Potassium::VUE_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
- add_readme_header :webpack
39
- end
40
- end
41
-
42
- def install
43
- ask
44
- create
45
- end
46
-
47
- def installed?
48
- package_file = 'package.json'
49
- return false unless file_exist?(package_file)
50
-
51
- package_content = read_file(package_file)
52
- package_content.include?("\"vue\"")
53
- end
54
-
55
- def copy_webpack_rules
56
- copy_file '../assets/config/webpack/webpack.config.js',
57
- 'config/webpack/webpack.config.js',
58
- force: true
59
- copy_file '../assets/config/webpack/rules/index.js', 'config/webpack/rules/index.js'
60
- copy_file '../assets/config/webpack/rules/css.js', 'config/webpack/rules/css.js'
61
- copy_file '../assets/config/webpack/rules/vue.js', 'config/webpack/rules/vue.js'
62
- copy_file '../assets/config/webpack/rules/jquery.js', 'config/webpack/rules/jquery.js'
63
- copy_file '../assets/config/webpack/rules/typescript.js', 'config/webpack/rules/typescript.js'
64
- end
65
-
66
- def add_assets_path
67
- gsub_file(
68
- 'config/webpacker.yml',
69
- 'additional_paths: []',
70
- "additional_paths: ['app/assets']"
71
- )
72
- end
73
-
74
- def setup_typescript
75
- run "bin/yarn add typescript fork-ts-checker-webpack-plugin ts-loader @types/node"
76
- copy_file '../assets/tsconfig.json', 'tsconfig.json'
77
- end
78
-
79
- def setup_vue_with_compiler_build
80
- application_js = 'app/javascript/application.js'
81
- create_file application_js, application_js_content, force: true
82
-
83
- layout_file = "app/views/layouts/application.html.erb"
84
- insert_into_file(
85
- layout_file,
86
- "<div id=\"vue-app\">\n <app></app>\n ",
87
- before: "<%= yield %>"
88
- )
89
- insert_into_file layout_file, "\n </div>", after: "<%= yield %>"
90
- end
91
-
92
- def add_responsive_meta_tag
93
- tag = "\n <meta name=\"viewport\" content=\"width=device-width, initial-scale=1\">\n"
94
- layout_file = "app/views/layouts/application.html.erb"
95
- insert_into_file layout_file, tag, after: "<%= csrf_meta_tags %>"
96
- end
97
-
98
- def setup_tailwind
99
- run "bin/yarn add css-loader style-loader mini-css-extract-plugin @types/tailwindcss "\
100
- "css-minimizer-webpack-plugin postcss@#{POSTCSS_VERSION} postcss-loader "\
101
- "tailwindcss@#{TAILWINDCSS_VERSION} autoprefixer@#{AUTOPREFIXER_VERSION} sass sass-loader "\
102
- "eslint-plugin-tailwindcss"
103
- run "npx tailwindcss init -p"
104
- setup_client_css
105
- remove_server_css_requires
106
- setup_tailwind_requirements
107
- end
108
-
109
- def setup_jest
110
- run "bin/yarn add jest @vue/vue3-jest@#{VUE_JEST_VERSION} babel-jest "\
111
- "@vue/test-utils@#{VUE_TEST_UTILS_VERSION} ts-jest"
112
- json_file = File.read(Pathname.new("package.json"))
113
- js_package = JSON.parse(json_file)
114
- js_package = js_package.merge(jest_config)
115
- json_string = JSON.pretty_generate(js_package)
116
- create_file 'package.json', json_string, force: true
117
-
118
- copy_file '../assets/app/javascript/components/app.spec.ts',
119
- 'app/javascript/components/app.spec.ts'
120
- end
121
-
122
- def setup_vue
123
- run "bin/yarn add vue@#{VUE_VERSION} vue-loader@#{VUE_LOADER_VERSION} "\
124
- "babel-preset-typescript-vue3"
125
- gsub_file(
126
- 'config/webpack/webpack.config.js',
127
- ' merge(typescriptConfig, cssConfig, jQueryConfig, webpackConfig);',
128
- ' merge(vueConfig, typescriptConfig, cssConfig, jQueryConfig, webpackConfig);'
129
- )
130
- copy_file '../assets/app/javascript/components/app.vue', 'app/javascript/components/app.vue'
131
- copy_file '../assets/app/javascript/types/vue.d.ts', 'app/javascript/types/vue.d.ts'
132
- setup_vue_with_compiler_build
133
- recipe = self
134
- run_action(:setup_jest) do
135
- recipe.setup_jest
136
- end
137
- end
138
-
139
- private
140
-
141
- def frameworks(framework)
142
- frameworks = {
143
- vue: "vue",
144
- none: nil
145
- }
146
- frameworks[framework]
147
- end
148
-
149
- def setup_client_css
150
- application_css = 'app/javascript/css/application.css'
151
- create_file application_css, "", force: true
152
-
153
- stylesheet_pack_tag = "\n <%= stylesheet_pack_tag 'application' %>\n "
154
- layout_file = "app/views/layouts/application.html.erb"
155
- insert_into_file layout_file, stylesheet_pack_tag, before: "</head>"
156
-
157
- application_js = 'app/javascript/application.js'
158
- if get(:front_end) != :vue
159
- create_file application_js, "import './css/application.css';\n", force: true
160
- else
161
- insert_into_file(
162
- application_js,
163
- "\nimport './css/application.css';",
164
- after: "import App from './components/app.vue';"
165
- )
166
- end
167
- end
168
-
169
- def setup_tailwind_requirements
170
- application_css = 'app/javascript/css/application.css'
171
- insert_into_file application_css, tailwind_client_css
172
-
173
- tailwind_config = 'tailwind.config.js'
174
- create_file tailwind_config, tailwind_config_content, force: true
175
- end
176
-
177
- def remove_server_css_requires
178
- assets_css_file = 'app/assets/stylesheets/application.css'
179
- gsub_file(assets_css_file, " *= require_tree .\n *= require_self\n", "")
180
- end
181
-
182
- def application_js_content
183
- <<~JS
184
- import { createApp } from 'vue';
185
- import App from './components/app.vue';
186
-
187
- document.addEventListener('DOMContentLoaded', () => {
188
- const app = createApp({
189
- components: { App },
190
- });
191
- app.mount('#vue-app');
192
-
193
- return app;
194
- });
195
- JS
196
- end
197
-
198
- def tailwind_client_css
199
- <<~CSS
200
- @tailwind base;
201
- @tailwind components;
202
- @tailwind utilities;
203
- CSS
204
- end
205
-
206
- def tailwind_config_content
207
- <<~JS
208
- /* eslint-disable no-undef */
209
- module.exports = {
210
- theme: {
211
- extend: {},
212
- },
213
- variants: {},
214
- plugins: [],
215
- content: [
216
- './app/**/*.html',
217
- './app/**/*.vue',
218
- './app/**/*.js',
219
- './app/**/*.erb',
220
- ],
221
- };
222
- JS
223
- end
224
-
225
- def jest_config
226
- {
227
- "scripts": {
228
- "test": "jest",
229
- "test:watch": "jest --watch"
230
- },
231
- "jest": {
232
- "roots": [
233
- "app/javascript"
234
- ],
235
- "moduleDirectories": [
236
- "node_modules",
237
- "app/javascript"
238
- ],
239
- "moduleNameMapper": {
240
- "^@/(.*)$": "app/javascript/$1"
241
- },
242
- "moduleFileExtensions": [
243
- "js",
244
- "ts",
245
- "json",
246
- "vue"
247
- ],
248
- "transform": {
249
- "^.+\\.ts$": "ts-jest",
250
- ".*\\.(vue)$": "@vue/vue3-jest"
251
- },
252
- "testEnvironment": "jsdom"
253
- }
254
- }
255
- end
256
- end
@@ -1,71 +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
- end
71
- end