Commit Graph

86 Commits

Author SHA1 Message Date
Chauncey McAskill
5010560ee3 Improve HTTPS/Proxy URL support in watch.js
Added logic to prepend "https://" to the proxy URL if missing.
2022-03-23 13:13:46 -04:00
Chauncey McAskill
0cfb3fbc7d Add support for loconfig.local.json
If a 'loconfig.local.json' file is present (ignored by git), its settings will be merged with those in 'loconfig.json'. Useful for customizing localhost development (see example below).

Added:
- Utility 'config.js' to prepare build settings.
- Function 'merge()' for recursively merging objects and concatenating arrays.

Example:

```json
{
    "paths": {
        "url": "yourlocal.dev"
    },
    "server": {
        "open": true,
        "https": {
            "key": "~/.config/valet/Certificates/{% paths.url %}.key",
            "cert": "~/.config/valet/Certificates/{% paths.url %}.crt"
        }
    }
}
```
2022-03-22 16:40:51 -04:00
Chauncey McAskill
86f88c3f14 Refactor watch.js
Switched to BrowserSync's recommended post-2.0.0 syntax.

Organized logic into functions for easier reading.

Add support for customizing the BrowserSync server from 'loconfig.json'.

Example:

```json
"server": {
    "open": true,
    "https": {
        "key": "~/.config/valet/Certificates/{% paths.url %}.key",
        "cert": "~/.config/valet/Certificates/{% paths.url %}.crt"
    }
}
```
2022-03-22 16:33:19 -04:00
Chauncey McAskill
48bd911804 Refactor template.js
Added:
- Function `resolve()` to process any template tags (in a string) in objects and arrays.

Changed:
- Renamed function `template()` to `resolveValue()`.
- Replaced default export `resolveValue()` with new function `resolve()`.
2022-03-22 16:33:19 -04:00
Chauncey McAskill
d49d3eabb2 Add file comment to notification.js 2022-03-22 16:32:24 -04:00
Chauncey McAskill
757c26c772 Fix glob.js file comment 2022-02-15 09:16:03 -05:00
Chauncey McAskill
5e07473396 Make glob optional in concats.js
Added:
- Condition to process includes with glob if it's available.

Changed:
- Utility 'glob.js' to not throw an error if a glob function is unavailable.
2022-02-08 15:18:18 -05:00
Chauncey McAskill
c9056b27d8 Add support for removing duplicates in concats.js
Added:
- Argument `concatOptions` to `concatFiles()` function to customize concatenation.
- Option 'removeDuplicates' to `concatOptions` to remove duplicate paths from the array of globbed paths. Defaults to `true`.

The 'removeDuplicates' is useful for customizing the order of files to concatenate, in which globbing will usually sort paths alphabetically.

This option is convenient when the installed glob library does not support removing duplicates on their own (feature supported in 'fast-glob' and 'glob').

Example:

```
/assets/scripts/vendors/a.js
/assets/scripts/vendors/b.js
/assets/scripts/vendors/c.js
/assets/scripts/vendors/d.js
```

```json
"concats": [
    {
        "includes": [
            "{% paths.scripts.src %}/vendors/c.js",
            "{% paths.scripts.src %}/vendors/*.js"
        ],
        "outfile": "{% paths.scripts.dest %}/vendors.js"
    }
]
```
2022-02-08 14:46:34 -05:00
Chauncey McAskill
38a6c73d2f Add support for customizing glob in concats.js
Added:
- Argument `globOptions` to `concatFiles()` function to customize glob library.
2022-02-08 14:40:00 -05:00
Chauncey McAskill
1e7e90c8aa Add support for custom task labels
If ever the basename from the outfile or outdir is an insufficient description.

Example:

```json
"concats": [
    {
        "label": "third-parties",
        "includes": [
            "{% paths.scripts.src %}/vendors/*.js"
        ],
        "outfile": "{% paths.scripts.dest %}/vendors.js"
    }
]
```
2021-12-17 10:39:35 -05:00
Chauncey McAskill
47007cddaf Fix glob.js
Amends 8dec2c69fe

Fixed:
- Forgot to rename all occurrences of 'modules' with 'candidates'.
2021-12-03 15:10:21 -05:00
Chauncey McAskill
5dd3fa843f Add support for watching multiple view paths
Added routine to convert `paths.views` into an array.

Supports a single path as a string, a map of paths, or a list of paths:

```json
"views": "./views/boilerplate/template"
```

```json
"views": {
    "src": "./views/boilerplate/template"
}
```

```json
"views": [
    "./views/boilerplate/template"
]
```
2021-12-03 11:55:35 -05:00
Chauncey McAskill
a5623d3122 Improve comments in watch.js 2021-12-03 11:52:27 -05:00
Chauncey McAskill
67e1fae8f4 Update block comment in styles.js 2021-11-03 17:08:38 -04:00
Chauncey McAskill
a95fe4523c Update postcss.js
Remove extraneous `null` assignment on optional exports.
2021-11-03 16:50:08 -04:00
Chauncey McAskill
eadc414329 Fix merging of default options for PostCSS
Amends 9e3d304654
2021-11-03 16:16:08 -04:00
Chauncey McAskill
9e3d304654 Add support for task options
Added support for customizing processors in `scripts.js` (esbuild), `styles.js` (node-sass, postcss, autoprefixer), and `svgs.js` (svg-mixer), via arguments for the exported task functions.

Added:
- Constants to decouple shared default options, options for development, and options for production.
- Constants to export default options for development and production as an array of arguments to pass to task functions.

Changed:
- watch.js to apply development args to tasks
2021-11-03 10:49:35 -04:00
Chauncey McAskill
6ded72bc79 Refactor postcss.js
Moved creation of Processor from utility file to styles.js to allow for future customization of `postcss` and `autoprefixer`.
2021-11-03 10:49:35 -04:00
Chauncey McAskill
b55e625457 Improve notification.js
Added:
- Support for passing a callback to node-notifier.
- Shorter timeout on notifications (~12 s → ~5 s).
2021-10-12 16:12:29 -04:00
Chauncey McAskill
25ef6675af Fix syntax of styles.js
Amends 7df0481d05
2021-10-12 16:04:29 -04:00
Chauncey McAskill
7df0481d05 Change writeFile promises in styles.js
Await results of `writeFile()` calls for easier readability of operations.
2021-10-12 12:52:36 -04:00
Chauncey McAskill
99e1b3fa93 Change tasks to be the default exports 2021-09-21 17:53:46 -04:00
Chauncey McAskill
548b2c604b Fix messages in styles.js
Fixed:
- Expected file extension from `outfile` for variable `name`.
- Expected structure of `err` in main catch (`err.formatted` is only available when thrown by node-sass).
- Context of error messages when writing final CSS and source map to disk.
2021-09-21 17:53:46 -04:00
Chauncey McAskill
ec9228a337 Refactor glob.js
Added function `importGlob()` to enclose operations and improve error handling.
2021-09-21 17:52:32 -04:00
Chauncey McAskill
8dec2c69fe Improve syntax of glob.js
Changed:
- Renamed variables for clarity.

Fixed:
- Block comment for `createArrayableGlob()`.
2021-09-21 17:52:17 -04:00
Chauncey McAskill
1a2cc7b6ac Fix bad paths in watch.js
Amends d4ded2a64e

Fixed:
- Invalid paths to watch.

Changed:
- Replaced risky string concatenation with Node.js' `path.join()` function.
2021-09-20 17:29:41 -04:00
Chauncey McAskill
d4ded2a64e Refactor build tasks and config file
Changed:
- Renamed 'mconfig.json' to 'loconfig.json'.
- Renamed 'concat.js' to 'concats.js' to represent flexible functionality.
- loconfig.json: Base paths are nested under "paths".
- loconfig.json: Paths for tasks are nested under "tasks".
- Refactored each task to process corresponding entries under "tasks" in 'loconfig.json'.
- watch.js: Changed concats watch to use task's includes.

Added:
- tiny-glob v0.2.9
- Utility 'glob.js' to use dynamic imports to fetch an available glob function from node modules.
- Utility 'template.js' to provide a function to render template tags (`{% ... %}`) in tasks.
- concats.js: Support for concatenating groupes of files.
- scripts.js: Support for ESBuild's "outdir" option.
2021-09-18 01:16:44 -04:00
Chauncey McAskill
589ec99135 Move tasks to a dedicated directory
Moved concat.js, scripts.js, styles.js, svgs.js to 'build/tasks/' directory.
2021-09-18 01:16:44 -04:00
Chauncey McAskill
84286fef66 Improve notification.js
Added:
- Block comment
- Support for additional node-notifier properties.
2021-09-18 01:16:44 -04:00
Chauncey McAskill
6e50bc202d Refactor styles.js
Changed:
- Replaced "fs" callback API with "fs/promises" promise API to centralize catching of errors and easier readability of file.
- Prefixed "fs/promises" with 'node:' URI scheme to target Node.js builtin modules.
- Promisified `sass.render`.
2021-09-18 01:16:44 -04:00
Chauncey McAskill
91109c5221 Refactor concat.js
Changed:
- Replaced "fs" callback API with "fs/promises" promise API to centralize catching of errors and easier readability of file.
- Prefixed "fs/promises" with 'node:' URI scheme to target Node.js builtin modules.
2021-09-18 01:16:44 -04:00
Chauncey McAskill
834c6165b0 Refactor postcss.js
Decoupled import routine from final export to provide a shared instance of the PostCSS processor and for easier readability of file.
2021-09-18 01:16:44 -04:00
Chauncey McAskill
ffece71aac Improve message.js
Added:
- Types "notice" and "warning".
- Support for all but the "waiting" message type to stop a timer.

Changed:
- Improved colors of message types.
- Improved handling of PostCSS errors in styles.js.
2021-09-18 01:16:44 -04:00
Chauncey McAskill
454ae64d07 Make postcss optional in styles.js
Added:
- Utility 'postcss.js' to use dynamic imports to fetch PostCSS and Autoprefixer, if available, and build the Processor object.
- Function `saveStylesheet()` in 'styles.js' to decouple the writing of CSS files and source maps.
- Condition to process with PostCSS if it's available.
2021-09-18 01:16:44 -04:00
Chauncey McAskill
7479444572 Change tasks to async functions 2021-09-18 01:16:44 -04:00
Chauncey McAskill
b46fb31dfe Fix logic for PostCSS processing
Amends 3874d9c451674a9b4f76239a17b4cbf50cbdb9d3

The `fs.access()` condition is unnecessary and won't work if a CSS stylesheet does not exist.
2021-09-18 01:16:44 -04:00
Chauncey McAskill
23e55d6340 Move notification.js to utils directory 2021-09-18 01:16:44 -04:00
Chauncey McAskill
70827b0a7d Add semi-colon to exported functions 2021-09-18 01:16:44 -04:00
Chauncey McAskill
8cff91aa68 Fix syntax typo in concat.js
Amends a55e6e523db4b4c932d214d3e204fa29d9c0e58f
2021-09-18 01:16:44 -04:00
Chauncey McAskill
b24014d8b1 Add autoprefixer and postcss
Added:
- autoprefixer v10.3.4
- postcss v8.3.6

Changed:
- Node Sass options to pass source map to PostCSS.
2021-09-18 01:16:44 -04:00
Chauncey McAskill
e9e0e5784e Refactor build tasks
Decouple static "main" keys in mconfig.json and refactor tasks to support many output files.

Added:
- scripts.js: Array of output files (such as 'app.js') to iterate over to bundle JS files.
- styles.js: Array of input files (such as 'main.css' and 'critical.css') to iterate over to compile Sass files.
- svgs.js: Array of output files (such as 'sprite.svg') to iterate over to compile SVG spritesheets.

Changed:
- mconfig.json: Decouple entry points to individual tasks to allow for more flexibility in projects.
- concat.js: Refactor function to use promises to build list of JS files to concatenate.
- message.js: Replace if statements with switch for improved readability.
- message.js: If timerID provided with "waiting" type, log time.
- watch.js: Change CSS and JS reload watch paths to include all files.
- Sorted imports by path.
2021-09-18 01:16:44 -04:00
Chauncey McAskill
8b4d758443 Fix comments and variable in watch.js
Amends 14d9f47fe0

Fixed:
- Location of comments.
- Variable `serverConfig` to `const`.
2021-09-16 14:01:21 -04:00
Chauncey McAskill
e51c717a3c Renamed BrowserSync variable "bs" to "server" 2021-09-16 13:55:29 -04:00
Chauncey McAskill
0267bc6ebd Revert "proxy" back to "url" for BrowserSync
Amends 14d9f47fe0
2021-09-16 13:54:49 -04:00
Chauncey McAskill
4a5d821965 Merge pull request #90 from MouseEatsCat/master
Remove default proxy
2021-09-16 13:48:38 -04:00
Chauncey McAskill
5cc8a75866 Update NPM dependencies
Added:
- esbuild v0.8.16 → v0.12.28
- kleur v4.1.3 → v4.1.4
- locomotive-scroll v4.0.4 → v4.1.2
- node-notifier v8.0.1 → v10.0.0
- node-sass v5.0.0 → v6.0.1

Removed:
- fs
2021-09-14 18:27:03 -04:00
Michel Descoteaux
14d9f47fe0 Remove default proxy 2021-06-28 21:33:10 -04:00
Quentin Hocdé
e687e52cd2 Update build/styles.js
Co-authored-by: Chauncey McAskill <chauncey@locomotive.ca>
2021-03-05 09:27:47 -05:00
Quentin Hocdé
3cf62e80f7 Update build/styles.js
Co-authored-by: Chauncey McAskill <chauncey@locomotive.ca>
2021-03-05 09:27:37 -05:00
Quentin Hocdé
a6efa6bcb1 Update build/styles.js
Co-authored-by: Chauncey McAskill <chauncey@locomotive.ca>
2021-03-05 09:27:25 -05:00