Skip to content

Commit

Permalink
Add new options
Browse files Browse the repository at this point in the history
- mode to set the file mode for files that are written (444 is default).
- fileExt to set the file extension for written files ("" is default).
  • Loading branch information
phBalance committed Oct 7, 2019
1 parent 3739f29 commit 68f35a9
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 3 deletions.
4 changes: 4 additions & 0 deletions command_line.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ if(parsed.help) {
[--proxy behindThisProxy] Indicate that this server is behind this particular proxy.
[--public staticFileDirectory] Serve static files from this directory.
[--copyToDir directoryToPutRenderedFile] Generate a file for each page that is rendered.
[--fileExt extension] Add extension to all files that are generated. For instance, it might be useful to add ".html".
[--mode fileMode] Sets the file mode to be set when files are written.
boolean options need only be provided once with no additional tokens:
[--compress] Allows on the fly compression of reponses
Expand Down Expand Up @@ -65,6 +67,8 @@ parsed.port = parsed.port ? parseInt(parsed.port) : DEFAULT.PORT;
parsed.public = parsed.public && path.resolve(parsed.public);
parsed.headless = !parsed.headfull;
parsed.server = !parsed.noserver;
parsed.mode = parsed.mode || "444";
parsed.fileExt = parsed.fileExt || "";

try {
parsed.map = JSON.parse(parsed.map);
Expand Down
6 changes: 3 additions & 3 deletions ssr.js
Original file line number Diff line number Diff line change
Expand Up @@ -123,9 +123,9 @@ async function ssr(opts) {

// Save pages to file
if(opts.copyToDir) {
const writeOptions = {encoding: "utf8", mode: "400", flag: "w"};
const fileBase = opts.copyToDir + (fetchUrl.pathname === "/" ? "/index" : fetchUrl.pathname) + ".html";
console.debug(`saving files ${fileBase} (directory ${opts.copyToDir})`);
const writeOptions = {encoding: "utf8", mode: cmdline.mode, flag: "w"};
const fileBase = opts.copyToDir + (fetchUrl.pathname === "/" ? "/index" : fetchUrl.pathname) + cmdline.fileExt;
console.debug(`saving files with base: ${fileBase}`);
try {
await writeFilePromisified(fileBase, html, writeOptions);
await writeFilePromisified(fileBase + ".gz", gzippedHtml, writeOptions);
Expand Down

0 comments on commit 68f35a9

Please sign in to comment.