Skip to content

Commit 22366b9

Browse files
committed
chore: let Webpack to manage DateUtils.js
This makes possible to use Jest for JavaScript unit tests. The public URL of DateUtils.js has been changed from /public/js/$VERSION/DateUtils.min.js to /public/js/$VERSION/utils/DateUtils.min.js and technically old cached code might search by the old location but as this file wasn't available to anonymous users, the chances are extremely low. Part of #1484
1 parent 8cc1d40 commit 22366b9

File tree

5 files changed

+19
-13
lines changed

5 files changed

+19
-13
lines changed

src/main/javascript/DateUtils.js src/main/frontend/src/utils/DateUtils.js

+2
Original file line numberDiff line numberDiff line change
@@ -16,3 +16,5 @@ var DateUtils = {
1616
}
1717

1818
}
19+
20+
window.DateUtils = DateUtils;

src/test/javascript/DateUtilsSpec.js src/main/frontend/src/utils/DateUtils.test.js

+2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import './DateUtils.js'
2+
13
describe('DateUtils.formatDateToDdMmYyyy()', function() {
24

35
it('should return a string in a format dd.mm.yyyy', function() {

src/main/frontend/webpack.config.js

+13-11
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,25 @@
11
const path = require('path');
22
const webpack = require('webpack');
33

4-
const SRC_DIR = './src/components/';
5-
64
// @todo #1455 Remove export of components to window
75
module.exports = {
86
mode: 'production',
97
entry: {
10-
AddCatalogNumbersForm: SRC_DIR + 'AddCatalogNumbersForm.js',
11-
AddCatalogPriceForm: SRC_DIR + 'AddCatalogPriceForm.js',
12-
AddCommentForm: SRC_DIR + 'AddCommentForm.js',
13-
AddReleaseYearForm: SRC_DIR + 'AddReleaseYearForm.js',
14-
HideImageForm: SRC_DIR + 'HideImageForm.js',
15-
SeriesSaleImportForm: SRC_DIR + 'SeriesSaleImportForm.js',
16-
SeriesSalesList: SRC_DIR + 'SeriesSalesList.js',
17-
SimilarSeriesForm: SRC_DIR + 'SimilarSeriesForm.js'
8+
'utils/DateUtils': './src/utils/DateUtils.js',
9+
10+
'components/AddCatalogNumbersForm': './src/components/AddCatalogNumbersForm.js',
11+
'components/AddCatalogPriceForm': './src/components/AddCatalogPriceForm.js',
12+
'components/AddCommentForm': './src/components/AddCommentForm.js',
13+
'components/AddReleaseYearForm': './src/components/AddReleaseYearForm.js',
14+
'components/HideImageForm': './src/components/HideImageForm.js',
15+
'components/SeriesSaleImportForm': './src/components/SeriesSaleImportForm.js',
16+
'components/SeriesSalesList': './src/components/SeriesSalesList.js',
17+
'components/SimilarSeriesForm': './src/components/SimilarSeriesForm.js'
1818
},
1919
output: {
20-
path: path.resolve(__dirname, '../../../target/classes/js/components'),
20+
// As we can't have a dynamic output path, we've included a subdirectory in entry names. See:
21+
// https://stackoverflow.com/questions/35903246/how-to-create-multiple-output-paths-in-webpack-config
22+
path: path.resolve(__dirname, '../../../target/classes/js'),
2123
filename: '[name].min.js'
2224
},
2325
module: {

src/main/java/ru/mystamps/web/feature/site/ResourceUrl.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ public final class ResourceUrl {
3737
// CheckStyle: ignore LineLength for next 17 lines
3838
private static final String CATALOG_UTILS_JS = "/public/js/" + RESOURCES_VERSION + "/CatalogUtils.min.js";
3939
private static final String COLLECTION_INFO_JS = "/public/js/" + RESOURCES_VERSION + "/collection/info.min.js";
40-
private static final String DATE_UTILS_JS = "/public/js/" + RESOURCES_VERSION + "/DateUtils.min.js";
40+
private static final String DATE_UTILS_JS = "/public/js/" + RESOURCES_VERSION + "/utils/DateUtils.min.js";
4141
private static final String MAIN_CSS = "/static/" + RESOURCES_VERSION + "/styles/main.min.css";
4242
private static final String PARTICIPANT_ADD_JS = "/public/js/" + RESOURCES_VERSION + "/participant/add.min.js";
4343
private static final String SERIES_ADD_JS = "/public/js/" + RESOURCES_VERSION + "/series/add.min.js";

src/main/webapp/WEB-INF/views/series/info.html

+1-1
Original file line numberDiff line numberDiff line change
@@ -878,7 +878,7 @@ <h5 th:text="#{t_add_info_who_selling_series}">Add info about selling/buying thi
878878
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.4.1/js/bootstrap.min.js" th:src="${BOOTSTRAP_JS}"></script>
879879

880880
<script sec:authorize="hasAnyAuthority('VIEW_SERIES_SALES', 'IMPORT_SERIES_SALES')"
881-
src="../../../../javascript/DateUtils.js"
881+
src="../../../../../../target/classes/js/utils/DateUtils.min.js"
882882
th:src="${DATE_UTILS_JS}"></script>
883883

884884
<script sec:authorize="hasAuthority('VIEW_SERIES_SALES')"

0 commit comments

Comments
 (0)