Skip to content

Commit

Permalink
Merge pull request #1184 from kethinov/ssr-work
Browse files Browse the repository at this point in the history
0.21.0
  • Loading branch information
kethinov authored Aug 3, 2022
2 parents a4f9a28 + 6b31630 commit 4e1fdee
Show file tree
Hide file tree
Showing 18 changed files with 776 additions and 196 deletions.
13 changes: 12 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,16 @@

## Next version

- Put your changes here...

## 0.21.0

- Breaking: `htmlMinifier` param renamed and expanded to `html`. You will need to update your Roosevelt config.
- Added feature `html.sourcePath`, `html.models`, and `html.output` which lets you generate static HTML pages from the your statics directory by compiling them with a view engine and depositing the output to the public folder at start time.
- Fixed issue with `symlinks` that would cause symlinking to a file rather than a directory to fail in Windows.
- Some error message copyediting.
- Some minor refactoring and documentation fixes.
- Various dependencies updated.

## 0.20.1

Expand All @@ -12,7 +21,9 @@

## 0.20.0

- Renamed `generateFolderStructure` to `makeBuildArtifacts`.
- Breaking: Renamed `generateFolderStructure` to `makeBuildArtifacts`.
- Various dependencies updated.
- Breaking: Among them, `formidable` was updated which is a breaking change for any app that takes file uploads as [property names in req.files have been renamed](https://github.com/node-formidable/formidable/blob/master/CHANGELOG.md#200), most notably `file.path` is now `file.filepath` and `file.name` is now `file.originalname`.
- Removed `checkDependencies`.

## 0.19.14
Expand Down
146 changes: 87 additions & 59 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -534,15 +534,15 @@ Resolves to:
- `viewEngine`: What templating engine to use, formatted as *[String]* `"fileExtension: nodeModule"`.
- Default: *[String]* `"none"`.
- Default: *[String]* `"none"`.
- Will be set to `"html: teddy"` in apps generated with [generator-roosevelt](https://github.com/rooseveltframework/generator-roosevelt).
- Will be set to `"html: teddy"` in apps generated with [generator-roosevelt](https://github.com/rooseveltframework/generator-roosevelt).
- Also by default when using the generator, the module [teddy](https://github.com/rooseveltframework/teddy) is marked as a dependency in `package.json`.
- Also by default when using the generator, the module [teddy](https://github.com/rooseveltframework/teddy) is marked as a dependency in `package.json`.
- To use multiple templating systems, supply an array of engines to use in the same string format. Each engine you use must also be marked as a dependency in your app's `package.json`. Whichever engine you supply first with this parameter will be considered the default.
- To use multiple templating systems, supply an array of engines to use in the same string format. Each engine you use must also be marked as a dependency in your app's `package.json`. Whichever engine you supply first with this parameter will be considered the default.
- Example configuration using multiple templating systems: *[Object]*
- Example configuration using multiple templating systems: *[Object]*
```json
{
Expand Down Expand Up @@ -588,30 +588,56 @@ Resolves to:
- Default: *[String]* `"statics"`.
- `htmlMinifier`: How you want Roosevelt to minify your HTML:
- `html`: How you want Roosevelt to handle HTML:
- `sourcePath`: Subdirectory within `staticsRoot` where your static HTML files are located. By default this folder will not be made public, but is instead meant to store unminified / unprocessed HTML template source files which will be rendered, minified, and written to the `public` folder when the app is started.
- `models`: Data to pass to templates by file path / file name.
- Example:
```json
{
"models": {
"index.html": {
"some": "data"
},
"subdirectory/otherFile.html": {
"someOther": "data"
}
}
}
```
- `enable`: *[Boolean]* Whether or not to minify HTML.
- `output`: Subdirectory within `publicFolder` where parsed and minified HTML files will be written to.
- Note: Can also be disabled by the `minify` param.
- `minifier`: How you want Roosevelt to minify your HTML:
- Note: Minification is automatically disabled in development mode.
- `enable`: *[Boolean]* Whether or not to minify HTML.
- `exceptionRoutes`: *[Array]* List of controller routes that will skip minification entirely. Set to `false` to minify all URLs.
- Note: Can also be disabled by the `minify` param.
- `options`: *[Object]* Parameters to supply to [html-minifier](https://github.com/kangax/html-minifier#options-quick-reference)'s API.
- Note: Minification is automatically disabled in development mode.
- `exceptionRoutes`: *[Array]* List of controller routes that will skip minification entirely. Set to `false` to minify all URLs.
- `options`: *[Object]* Parameters to supply to [html-minifier](https://github.com/kangax/html-minifier#options-quick-reference)'s API.
- Default: *[Object]*
```json
{
"enable": true,
"exceptionRoutes": false,
"options": {
"removeComments": true,
"collapseWhitespace": true,
"collapseBooleanAttributes": true,
"removeAttributeQuotes": true,
"removeEmptyAttributes": true
"sourcePath": "pages",
"models": {}
"output": "",
"minifier": {
"enable": true,
"exceptionRoutes": false,
"options": {
"removeComments": true,
"collapseWhitespace": true,
"collapseBooleanAttributes": true,
"removeAttributeQuotes": true,
"removeEmptyAttributes": true
}
}
}
```
Expand All @@ -635,60 +661,60 @@ Resolves to:
- `minifier`: *[Object]* Params pertaining to CSS minifcation.
- `enable`: *[Boolean]* Whether or not to minify CSS.
- Note: Can also be disabled by the `minify` param.
- Note: Can also be disabled by the `minify` param.
- `options`: *[Object]* Parameters to pass to the CSS minifier [clean-css](https://www.npmjs.com/package/clean-css), a list of which can be found in the [clean-css docs](https://github.com/jakubpawlowicz/clean-css#constructor-options).
- `options`: *[Object]* Parameters to pass to the CSS minifier [clean-css](https://www.npmjs.com/package/clean-css), a list of which can be found in the [clean-css docs](https://github.com/jakubpawlowicz/clean-css#constructor-options).
- `allowlist`: Array of CSS files to allowlist for compiling. Leave undefined to compile all files. Supply a `:` character after each file name to delimit an alternate file path and/or file name for the minified file.
- `allowlist`: Array of CSS files to allowlist for compiling. Leave undefined to compile all files. Supply a `:` character after each file name to delimit an alternate file path and/or file name for the minified file.
- Example array member: *[String]* `example.less:example.min.css` (compiles `example.less` into `example.min.css`).
- Example array member: *[String]* `example.less:example.min.css` (compiles `example.less` into `example.min.css`).
- `output`: Subdirectory within `publicFolder` where compiled CSS files will be written to.
- `output`: Subdirectory within `publicFolder` where compiled CSS files will be written to.
- `versionFile`: If enabled, Roosevelt will create a CSS file which declares a CSS variable containing your app's version number from `package.json`. Enable this option by supplying an object with the member variables `fileName` and `varName`. Versioning your static files is useful for resetting your users' browser cache when you release a new version of your app.
- `versionFile`: If enabled, Roosevelt will create a CSS file which declares a CSS variable containing your app's version number from `package.json`. Enable this option by supplying an object with the member variables `fileName` and `varName`. Versioning your static files is useful for resetting your users' browser cache when you release a new version of your app.
- Default: `null`.
- Default: `null`.
- Example usage (with LESS): *[Object]*
- Example usage (with LESS): *[Object]*
```json
{
"fileName": "_version.less",
"varName": "appVersion"
}
```
```json
{
"fileName": "_version.less",
"varName": "appVersion"
}
```
- Assuming the default Roosevelt configuration otherwise, this will result in a file `statics/css/_version.less` with the following content:
- Assuming the default Roosevelt configuration otherwise, this will result in a file `statics/css/_version.less` with the following content:
```less
/* do not edit; generated automatically by Roosevelt */ @appVersion: '0.1.0';
```
```less
/* do not edit; generated automatically by Roosevelt */ @appVersion: '0.1.0';
```
- Some things to note:
- Some things to note:
- If there is already a file there with that name, this will overwrite it, so be careful!
- If there is already a file there with that name, this will overwrite it, so be careful!
- It's generally a good idea to add this file to `.gitignore`, since it is a build artifact.
- It's generally a good idea to add this file to `.gitignore`, since it is a build artifact.
- Default: *[Object]*
- Default: *[Object]*
```json
{
"sourcePath": "css",
"compiler": {
"enable" : false,
"module": "less",
"options": {}
},
"minifier": {
"enable": true,
"options": {}
},
"allowlist": null,
"output": "css",
"versionFile": null
}
```
```json
{
"sourcePath": "css",
"compiler": {
"enable" : false,
"module": "less",
"options": {}
},
"minifier": {
"enable": true,
"options": {}
},
"allowlist": null,
"output": "css",
"versionFile": null
}
```
- `js`: *[Object]* How you want Roosevelt to handle module bundling and minifying your frontend JS:
Expand Down Expand Up @@ -848,7 +874,7 @@ Resolves to:
- `minifyOptions`: *[Object]* Parameters to supply to [html-minifier](https://github.com/kangax/html-minifier#options-quick-reference)'s API.
- Uses the params you set in `htmlMinifier.options` if empty.
- Uses the params you set in `html.minifier.options` if empty.
- Default: *[Object]*
Expand Down Expand Up @@ -1181,8 +1207,10 @@ Roosevelt supplies several variables to Express that you may find handy. Access
| `controllersPath` | Full path on the file system to where your app's controllers folder is located. |
| `staticsRoot` | Full path on the file system to where your app's statics folder is located. |
| `publicFolder` | Full path on the file system to where your app's public folder is located. |
| `htmlPath` | Full path on the file system to where your app's HTML static page source files are located. |
| `cssPath` | Full path on the file system to where your app's CSS source files are located. |
| `jsPath` | Full path on the file system to where your app's JS source files are located. |
| `htmlRenderedOutput` | Full path on the file system to where your app's rendered and minified staic HTML files are located. |
| `cssCompiledOutput` | Full path on the file system to where your app's minified CSS files are located. |
| `clientViewsBundledOutput` | Full path on the file system to where your app's client-exposed views folder is located. |
| `env` | Either `development` or `production`. |
Expand Down
21 changes: 13 additions & 8 deletions lib/defaults/config.json
Original file line number Diff line number Diff line change
Expand Up @@ -66,14 +66,19 @@
},
"routePrefix": null,
"staticsRoot": "statics",
"htmlMinifier": {
"enable": true,
"exceptionRoutes": false,
"options": {
"collapseWhitespace": true,
"collapseBooleanAttributes": true,
"removeAttributeQuotes": true,
"removeEmptyAttributes": true
"html": {
"sourcePath": "pages",
"models": {},
"output": "",
"minifier": {
"enable": true,
"exceptionRoutes": false,
"options": {
"collapseWhitespace": true,
"collapseBooleanAttributes": true,
"removeAttributeQuotes": true,
"removeEmptyAttributes": true
}
}
},
"css": {
Expand Down
10 changes: 7 additions & 3 deletions lib/generateSymlinks.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
const fs = require('fs-extra')
const path = require('path')
const process = require('process')

module.exports = app => {
const params = app.get('params')
const appName = app.get('appName')
const fsr = require('./tools/fsr')(app)
const logger = app.get('logger')
const publicDir = params.publicFolder

// generate public and statics directories
fsr.ensureDirSync(publicDir)
fsr.ensureDirSync(params.publicFolder)
fsr.ensureDirSync(params.staticsRoot)

// process symlinks
Expand All @@ -28,7 +28,11 @@ module.exports = app => {
logger.error(`Symlink destination "${dest}" is already a file that exists. Skipping symlink creation.`)
}
} else {
fs.ensureSymlinkSync(source, dest, 'junction')
if (process.platform === 'win32' && !fs.lstatSync(source).isDirectory()) {
fs.ensureLinkSync(source, dest)
} else {
fs.ensureSymlinkSync(source, dest, 'junction')
}
logger.info('📁', `${appName} making new symlink `.cyan + `${dest}`.yellow + (' pointing to ').cyan + `${source}`.yellow)
}
} else {
Expand Down
2 changes: 1 addition & 1 deletion lib/htmlMinifier.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// html minifier

module.exports = function (app) {
const params = app.get('params').htmlMinifier
const params = app.get('params').html.minifier
const options = params.options
const minify = require('html-minifier').minify

Expand Down
Loading

0 comments on commit 4e1fdee

Please sign in to comment.