Skip to content

Commit d968dbd

Browse files
committed
[cmd] Collect static files on admin command
Collects and installs static files when the 'admin' command is run. The UI static files are generated using 'yarn build'. Signed-off-by: Eva Millán <[email protected]>
1 parent d58eaf0 commit d968dbd

File tree

10 files changed

+45
-7
lines changed

10 files changed

+45
-7
lines changed

.gitignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,10 @@
33
*.pyo
44
build
55

6+
# Package files
7+
src/grimoirelab/core/static
8+
src/grimoirelab/core/templates
9+
610
# JavaScript files
711
node_modules
812
dist

pyproject.toml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,10 @@ packages = [
2121
{ include = "grimoirelab", from = "src" },
2222
]
2323

24+
exclude = [
25+
"grimoirelab/core/static"
26+
]
27+
2428
classifiers = [
2529
"Development Status :: 4 - Beta",
2630
"Intended Audience :: Developers",

src/grimoirelab/core/app/urls.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
"""GrimoireLab URL Configuration"""
22

33

4-
from django.urls import path, include
4+
from django.urls import path, include, re_path
5+
from django.views.generic import TemplateView
56

67
from grimoirelab.core.scheduler.urls import urlpatterns as sched_urlpatterns
78

89
urlpatterns = [
9-
path("scheduler/", include(sched_urlpatterns))
10+
path("scheduler/", include(sched_urlpatterns)),
11+
re_path(r'^(?!static|scheduler).*$', TemplateView.as_view(template_name="index.html"))
1012
]

src/grimoirelab/core/config/settings.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@
114114
TEMPLATES = [
115115
{
116116
'BACKEND': 'django.template.backends.django.DjangoTemplates',
117-
'DIRS': [],
117+
'DIRS': [BASE_DIR / 'templates'],
118118
'APP_DIRS': True,
119119
'OPTIONS': {
120120
'context_processors': [
@@ -225,7 +225,9 @@
225225
#
226226

227227
STATIC_URL = '/static/'
228-
228+
STATICFILES_DIRS = [
229+
BASE_DIR / 'templates/static'
230+
]
229231

230232
# UI static files will be copied to the next path when
231233
# 'collectstatic' is run.
@@ -234,6 +236,10 @@
234236

235237
STATIC_ROOT = os.path.join(BASE_DIR, 'static')
236238

239+
# MEDIA_URL is only needed when DEBUG is set to True.
240+
# Modify this URL if you want to run the server in developer mode.
241+
242+
MEDIA_URL = 'http://media.localhost/'
237243

238244
#
239245
# Default primary key field type

src/grimoirelab/core/runner/commands/admin.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ def _setup():
5454

5555
_create_database()
5656
_setup_database()
57+
_install_static_files()
5758

5859
click.secho("\nGrimoirelab configuration completed", fg='bright_cyan')
5960

@@ -98,6 +99,20 @@ def _setup_database(database: str = 'default'):
9899
click.echo()
99100

100101

102+
def _install_static_files():
103+
"""Collect static files and install them."""
104+
105+
click.secho('## GrimoireLab static files installation\n',
106+
fg='bright_cyan')
107+
108+
django.core.management.call_command('collectstatic',
109+
ignore=['admin', 'rest_framework'],
110+
clear=True,
111+
interactive=False)
112+
113+
click.echo()
114+
115+
101116
@admin.group()
102117
@click.pass_context
103118
def queues(ctx: Context):

ui/.eslintrc.cjs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,9 @@ require('@rushstack/eslint-patch/modern-module-resolution')
33

44
module.exports = {
55
root: true,
6+
env: {
7+
node: true
8+
},
69
extends: [
710
'plugin:vue/vue3-essential',
811
'plugin:vue/vue3-strongly-recommended',

ui/index.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
<html lang="en">
33
<head>
44
<meta charset="UTF-8">
5-
<link rel="icon" href="/favicon-grimoirelab.ico">
5+
<link rel="icon" href="./src/assets/favicon-grimoirelab.ico">
66
<meta name="viewport" content="width=device-width, initial-scale=1.0">
77
<title>GrimoireLab</title>
88
</head>

ui/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
"type": "module",
66
"scripts": {
77
"serve": "vite",
8-
"build": "vite build",
8+
"build": "vite build --emptyOutDir",
99
"preview": "vite preview",
1010
"test:unit": "vitest",
1111
"test:e2e": "start-server-and-test preview http://localhost:4173 'cypress run --e2e'",
File renamed without changes.

ui/vite.config.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { fileURLToPath, URL } from 'node:url'
2-
2+
import path from 'path'
33
import { defineConfig } from 'vite'
44
import vue from '@vitejs/plugin-vue'
55

@@ -10,5 +10,9 @@ export default defineConfig({
1010
alias: {
1111
'@': fileURLToPath(new URL('./src', import.meta.url))
1212
}
13+
},
14+
build: {
15+
assetsDir: 'static',
16+
outDir: path.resolve(__dirname, '../src/', 'grimoirelab', 'core', 'templates')
1317
}
1418
})

0 commit comments

Comments
 (0)