Skip to content

Commit e212884

Browse files
authored
Don't minify JS files on debug builds (#369)
Signed-off-by: Juan Cruz Viotti <jv@jviotti.com>
1 parent 0efdb43 commit e212884

File tree

5 files changed

+81
-21
lines changed

5 files changed

+81
-21
lines changed

CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,8 @@ if(REGISTRY_INDEX OR REGISTRY_SERVER)
3535
endif()
3636

3737
if(REGISTRY_INDEX)
38+
include(commands/esbuild)
39+
include(commands/redocly)
3840
add_subdirectory(src/configuration)
3941
add_subdirectory(src/resolver)
4042
add_subdirectory(src/index)

cmake/commands/esbuild.cmake

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
function(sourcemeta_esbuild_bundle)
2+
cmake_parse_arguments(SOURCEMETA_ESBUILD_BUNDLE "" "ENTRYPOINT;OUTPUT" "DEPENDS" ${ARGN})
3+
4+
if(NOT SOURCEMETA_ESBUILD_BUNDLE_ENTRYPOINT)
5+
message(FATAL_ERROR "You must pass the ENTRYPOINT option to ${CMAKE_CURRENT_FUNCTION}")
6+
endif()
7+
if(NOT SOURCEMETA_ESBUILD_BUNDLE_OUTPUT)
8+
message(FATAL_ERROR "You must pass the OUTPUT option to ${CMAKE_CURRENT_FUNCTION}")
9+
endif()
10+
11+
find_program(ESBUILD_BIN NAMES esbuild REQUIRED)
12+
13+
if(CMAKE_BUILD_TYPE STREQUAL "Release")
14+
set(ESBUILD_OPTIONS "--minify")
15+
else()
16+
set(ESBUILD_OPTIONS "")
17+
endif()
18+
19+
if(SOURCEMETA_ESBUILD_BUNDLE_DEPENDS)
20+
add_custom_command(
21+
OUTPUT "${SOURCEMETA_ESBUILD_BUNDLE_OUTPUT}"
22+
COMMAND "${ESBUILD_BIN}" --bundle "${SOURCEMETA_ESBUILD_BUNDLE_ENTRYPOINT}"
23+
--outfile="${SOURCEMETA_ESBUILD_BUNDLE_OUTPUT}"
24+
${ESBUILD_OPTIONS}
25+
DEPENDS "${SOURCEMETA_ESBUILD_BUNDLE_ENTRYPOINT}" ${SOURCEMETA_ESBUILD_BUNDLE_DEPENDS})
26+
else()
27+
add_custom_command(
28+
OUTPUT "${SOURCEMETA_ESBUILD_BUNDLE_OUTPUT}"
29+
COMMAND "${ESBUILD_BIN}" --bundle "${SOURCEMETA_ESBUILD_BUNDLE_ENTRYPOINT}"
30+
--outfile="${SOURCEMETA_ESBUILD_BUNDLE_OUTPUT}"
31+
${ESBUILD_OPTIONS}
32+
DEPENDS "${SOURCEMETA_ESBUILD_BUNDLE_ENTRYPOINT}")
33+
endif()
34+
endfunction()

cmake/commands/redocly.cmake

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
function(sourcemeta_redocly_openapi_to_html)
2+
cmake_parse_arguments(SOURCEMETA_REDOCLY_OPENAPI_TO_HTML "" "REDOCLY;INPUT;OUTPUT" "DEPENDS" ${ARGN})
3+
4+
if(NOT SOURCEMETA_REDOCLY_OPENAPI_TO_HTML_REDOCLY)
5+
message(FATAL_ERROR "You must pass the REDOCLY option to ${CMAKE_CURRENT_FUNCTION}")
6+
endif()
7+
8+
if(NOT SOURCEMETA_REDOCLY_OPENAPI_TO_HTML_INPUT)
9+
message(FATAL_ERROR "You must pass the INPUT option to ${CMAKE_CURRENT_FUNCTION}")
10+
endif()
11+
12+
if(NOT SOURCEMETA_REDOCLY_OPENAPI_TO_HTML_OUTPUT)
13+
message(FATAL_ERROR "You must pass the OUTPUT option to ${CMAKE_CURRENT_FUNCTION}")
14+
endif()
15+
16+
find_program(NODE_BIN NAMES node REQUIRED)
17+
18+
set(SOURCEMETA_REDOCLY_OPENAPI_TO_HTML_ALL_DEPS "${SOURCEMETA_REDOCLY_OPENAPI_TO_HTML_INPUT}")
19+
if(SOURCEMETA_REDOCLY_OPENAPI_TO_HTML_DEPENDS)
20+
list(APPEND SOURCEMETA_REDOCLY_OPENAPI_TO_HTML_ALL_DEPS ${SOURCEMETA_REDOCLY_OPENAPI_TO_HTML_DEPENDS})
21+
endif()
22+
23+
add_custom_command(
24+
OUTPUT "${SOURCEMETA_REDOCLY_OPENAPI_TO_HTML_OUTPUT}"
25+
COMMAND "${NODE_BIN}" "${SOURCEMETA_REDOCLY_OPENAPI_TO_HTML_REDOCLY}"
26+
build-docs --disableGoogleFont --output "${SOURCEMETA_REDOCLY_OPENAPI_TO_HTML_OUTPUT}"
27+
"${SOURCEMETA_REDOCLY_OPENAPI_TO_HTML_INPUT}"
28+
DEPENDS ${SOURCEMETA_REDOCLY_OPENAPI_TO_HTML_ALL_DEPS})
29+
endfunction()

src/index/CMakeLists.txt

Lines changed: 15 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -58,19 +58,26 @@ install(TARGETS sourcemeta_registry_index
5858
RUNTIME DESTINATION "${CMAKE_INSTALL_BINDIR}"
5959
COMPONENT sourcemeta_registry)
6060

61-
# Generate JS
62-
find_program(ESBUILD_BIN NAMES esbuild REQUIRED)
63-
add_custom_command(OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/main.min.js"
64-
COMMAND "${ESBUILD_BIN}" --bundle
65-
"${CMAKE_CURRENT_SOURCE_DIR}/assets/main.js"
66-
--outfile="${CMAKE_CURRENT_BINARY_DIR}/main.min.js"
67-
--minify
61+
sourcemeta_esbuild_bundle(
62+
ENTRYPOINT "${CMAKE_CURRENT_SOURCE_DIR}/assets/main.js"
63+
OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/main.min.js"
6864
DEPENDS
6965
"${CMAKE_CURRENT_SOURCE_DIR}/assets/main.js"
7066
"${CMAKE_CURRENT_SOURCE_DIR}/assets/search.js"
7167
"${CMAKE_CURRENT_SOURCE_DIR}/assets/tabs.js"
7268
"${CMAKE_CURRENT_SOURCE_DIR}/assets/editor.js")
73-
target_sources(sourcemeta_registry_index PRIVATE "${CMAKE_CURRENT_BINARY_DIR}/main.min.js")
69+
target_sources(sourcemeta_registry_index
70+
PRIVATE "${CMAKE_CURRENT_BINARY_DIR}/main.min.js")
71+
72+
sourcemeta_redocly_openapi_to_html(
73+
REDOCLY "${PROJECT_SOURCE_DIR}/node_modules/@redocly/cli/bin/cli.js"
74+
INPUT "${PROJECT_SOURCE_DIR}/openapi/openapi.yaml"
75+
OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/openapi.html"
76+
DEPENDS
77+
"${PROJECT_SOURCE_DIR}/package.json"
78+
"${PROJECT_SOURCE_DIR}/package-lock.json")
79+
target_sources(sourcemeta_registry_index
80+
PRIVATE "${CMAKE_CURRENT_BINARY_DIR}/openapi.html")
7481

7582
# Generate CSS
7683
include(BootstrapFiles)
@@ -85,18 +92,6 @@ add_custom_command(OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/style.min.css"
8592
${BOOTSTRAP_SCSS_FILES})
8693
target_sources(sourcemeta_registry_index PRIVATE "${CMAKE_CURRENT_BINARY_DIR}/style.min.css")
8794

88-
# Generate OpenAPI docs
89-
find_program(NODE_BIN NAMES node REQUIRED)
90-
add_custom_command(OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/openapi.html"
91-
COMMAND "${NODE_BIN}" "${PROJECT_SOURCE_DIR}/node_modules/@redocly/cli/bin/cli.js"
92-
build-docs --disableGoogleFont --output "${CMAKE_CURRENT_BINARY_DIR}/openapi.html"
93-
"${PROJECT_SOURCE_DIR}/openapi/openapi.yaml"
94-
DEPENDS
95-
"${PROJECT_SOURCE_DIR}/openapi/openapi.yaml"
96-
"${PROJECT_SOURCE_DIR}/package.json"
97-
"${PROJECT_SOURCE_DIR}/package-lock.json")
98-
target_sources(sourcemeta_registry_index PRIVATE "${CMAKE_CURRENT_BINARY_DIR}/openapi.html")
99-
10095
# Generate static files
10196
set(REGISTRY_STATIC
10297
"${CMAKE_CURRENT_BINARY_DIR}/openapi.html"

src/index/assets/main.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ document.querySelectorAll('[data-sourcemeta-ui-editor-highlight]').forEach((elem
2424
const url = element.getAttribute('data-sourcemeta-ui-editor-highlight');
2525
const pointer = element.getAttribute('data-sourcemeta-ui-editor-highlight-pointer');
2626
if (EDITORS[url]) {
27-
const positions = await window.fetch(`${url}?positions=1`);
27+
const positions = await window.fetch(`/api/schemas/positions${url.replace(/\.json$/i, "")}`);
2828
if (!positions.ok) {
2929
throw new Error(positions.statusText);
3030
}

0 commit comments

Comments
 (0)