From ad166fba4c39092af3468f692cdb324c30e85aba Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Javi=20Mart=C3=ADn?= Date: Sat, 22 Jul 2023 03:22:08 +0200 Subject: [PATCH] Setup NPM with an empty package.json file Note that, even if we're excluding the `node_modules/` folder from version control, we aren't adding it to Capistrano's shared folders because, when `node_modules` is a symbolic link, NPM removes it when running `npm install`. --- .dockerignore | 1 + .github/workflows/tests.yml | 3 +++ .gitignore | 1 + .gitlab-ci.yml | 1 + Dockerfile | 3 +++ bin/setup | 3 +++ config/application.rb | 1 + package-lock.json | 10 ++++++++++ package.json | 3 +++ 9 files changed, 26 insertions(+) create mode 100644 package-lock.json create mode 100644 package.json diff --git a/.dockerignore b/.dockerignore index 8c75b254c..c9b8c5bec 100644 --- a/.dockerignore +++ b/.dockerignore @@ -24,6 +24,7 @@ public/tenants/*/sitemap.xml public/assets/ public/machine_learning/data/ public/tenants/*/machine_learning/data/ +node_modules/ # Bundler config, cache and gemsets **/.bundle/ diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 57cb41e4a..8b35ff2d9 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -42,7 +42,10 @@ jobs: - name: Setup NPM uses: actions/setup-node@v3 with: + cache: "npm" node-version-file: ".node-version" + - name: Install node packages + run: npm clean-install - name: Copy secrets and database files run: for i in config/*.example; do cp "$i" "${i/.example}"; done - name: Setup database diff --git a/.gitignore b/.gitignore index 28d1c676c..ee42703e8 100644 --- a/.gitignore +++ b/.gitignore @@ -26,6 +26,7 @@ tmp/ /public/assets/ /public/machine_learning/data/ /public/tenants/*/machine_learning/data/ +/node_modules/ # Bundler config, cache and gemsets .bundle/ diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index f0253b5ec..ffa5da70f 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -23,6 +23,7 @@ tests: - bundle --without development - bundle exec rake db:setup - bundle exec rake assets:precompile > /dev/null 2>&1 + - npm clean-install - bin/knapsack_pro_rspec artifacts: when: on_failure diff --git a/Dockerfile b/Dockerfile index a3bfa8450..d2a08ad54 100644 --- a/Dockerfile +++ b/Dockerfile @@ -51,6 +51,9 @@ RUN curl -sL https://github.com/nodenv/node-build/archive/master.tar.gz | tar xz COPY Gemfile* ./ RUN bundle install +COPY package* ./ +RUN npm install + # Copy the Rails application into place COPY . . diff --git a/bin/setup b/bin/setup index 0fa8d7173..025afb7d7 100755 --- a/bin/setup +++ b/bin/setup @@ -17,6 +17,9 @@ FileUtils.chdir APP_ROOT do system! "gem install bundler --conservative" system("bundle check") || system!("bundle install") + # Install JavaScript dependencies + system!("npm install") + puts "\n== Copying sample files ==" unless File.exist?("config/database.yml") FileUtils.cp "config/database.yml.example", "config/database.yml" diff --git a/config/application.rb b/config/application.rb index 039211877..41571981c 100644 --- a/config/application.rb +++ b/config/application.rb @@ -117,6 +117,7 @@ module Consul config.assets.paths << Rails.root.join("app", "assets", "fonts") config.assets.paths << Rails.root.join("vendor", "assets", "fonts") + config.assets.paths << Rails.root.join("node_modules") # Add lib to the autoload path config.autoload_paths << Rails.root.join("lib") diff --git a/package-lock.json b/package-lock.json new file mode 100644 index 000000000..40dc9185a --- /dev/null +++ b/package-lock.json @@ -0,0 +1,10 @@ +{ + "name": "consuldemocracy", + "lockfileVersion": 3, + "requires": true, + "packages": { + "": { + "name": "consuldemocracy" + } + } +} diff --git a/package.json b/package.json new file mode 100644 index 000000000..2a38b2ee1 --- /dev/null +++ b/package.json @@ -0,0 +1,3 @@ +{ + "name": "consuldemocracy" +}