Skip to content

Commit 9062123

Browse files
author
James Goldie
committed
Handle Rollup command line args better
1 parent 2768233 commit 9062123

File tree

3 files changed

+49
-53
lines changed

3 files changed

+49
-53
lines changed

_extensions/sverto/rollup.config.js

Lines changed: 49 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -9,64 +9,62 @@ const path = require('node:path')
99
const production = !process.env.ROLLUP_WATCH;
1010

1111

12-
/* get svelte input paths (split by :) from cmd line arg */
12+
/* export an array of rollup configs - one for each input svelte file - using
13+
additional command line args supplied from lua */
14+
export default cmd => {
1315

14-
const svelteInputPaths = process.argv
15-
.filter(d => d.startsWith("--svelte-in-paths="))
16-
.map(d => d.replace("--svelte-in-paths=", ""))
17-
.join(":")
18-
.split(":")
19-
.filter(d => d != "")
16+
const svelteInputPaths =
17+
cmd["svelte-in-paths"].split(":").filter(d => d != "")
2018

21-
// if no svelte paths, bail out early
22-
if (svelteInputPaths == undefined || svelteInputPaths.length == 0) {
23-
console.log("No Svelte filtes found; skipping Svelte compilation")
24-
Deno.exit(0)
25-
}
26-
27-
/* get quarto render dir from cmd line arg */
19+
// if no svelte paths, bail out early
20+
if (svelteInputPaths == undefined || svelteInputPaths.length == 0) {
21+
console.log("No Svelte filtes found; skipping Svelte compilation")
22+
process.exit(0)
23+
}
2824

29-
let quartoRenderPath = process.argv
30-
.filter(d => d.startsWith("--quarto-out-path="))
31-
.map(d => d.replace("--quarto-out-path=", ""))
25+
/* get quarto render dir from cmd line arg */
26+
const quartoRenderPath = cmd["quarto-out-path"]
27+
if (quartoRenderPath == undefined) {
28+
console.error(
29+
"Error: supply a --quarto-out-path. Please report this to " +
30+
"the Sverto developer.")
31+
process.exit(1)
32+
}
3233

33-
if (quartoRenderPath == undefined || quartoRenderPath.length != 1) {
34-
console.error("There should be 1 --quarto-out-path argument.")
35-
}
36-
quartoRenderPath = quartoRenderPath[0]
34+
return svelteInputPaths.map(
3735

38-
/* export an array of rollup configs: one for each input svelte file */
39-
export default svelteInputPaths.map(
36+
svelteFile => ({
37+
input: svelteFile,
38+
output: {
39+
format: "es",
40+
dir: path.join(
41+
quartoRenderPath,
42+
path.dirname(svelteFile)),
43+
sourcemap: true
44+
},
45+
plugins: [
46+
svelte({
47+
// css is added to the js bundle instead
48+
emitCss: false,
49+
compilerOptions: {
50+
// required for ojs reactivity
51+
accessors: true,
52+
dev: !production,
53+
}
54+
}),
55+
resolve({
56+
browser: true,
57+
dedupe: ["svelte"]
58+
}),
59+
commonjs(),
60+
production && terser()
61+
]
62+
})
63+
64+
)
4065

41-
svelteFile => ({
42-
input: svelteFile,
43-
output: {
44-
format: "es",
45-
dir: path.join(
46-
quartoRenderPath,
47-
path.dirname(svelteFile)),
48-
sourcemap: true
49-
},
50-
plugins: [
51-
svelte({
52-
// css is added to the js bundle instead
53-
emitCss: false,
54-
compilerOptions: {
55-
// required for ojs reactivity
56-
accessors: true,
57-
dev: !production,
58-
}
59-
}),
60-
resolve({
61-
browser: true,
62-
dedupe: ["svelte"]
63-
}),
64-
commonjs(),
65-
production && terser()
66-
]
67-
})
66+
}
6867

69-
)
7068

7169

7270

_extensions/sverto/sverto-prerender.lua

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,6 @@ cmd =
133133
get_cmd_prefix() ..
134134
"npm run build " ..
135135
rollup_config .. " -- " ..
136-
-- "--silent " ..
137136
'--quarto-out-path="' .. os.getenv("QUARTO_PROJECT_OUTPUT_DIR") .. '" ' ..
138137
'--svelte-in-paths="' .. svelte_path_string .. '"'
139138

_extensions/sverto/sverto.lua

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,6 @@ function inject_svelte_and_compile(m)
9898
else
9999
local svelteCommand =
100100
"npm run build rollup.config.js -- " ..
101-
-- "--silent " ..
102101
'--quarto-out-path="./" ' ..
103102
'--svelte-in-paths="' .. sveltePaths .. '"'
104103
local svelteResult = os.execute(svelteCommand)

0 commit comments

Comments
 (0)