Skip to content

Commit

Permalink
Merge branch 'release/2.0.0'
Browse files Browse the repository at this point in the history
  • Loading branch information
homestar9 committed May 21, 2024
2 parents 1f13ac0 + a698c68 commit c849c75
Show file tree
Hide file tree
Showing 21 changed files with 106 additions and 118 deletions.
4 changes: 2 additions & 2 deletions ModuleConfig.cfc
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,9 @@ component {
*/
function configure(){
settings = {
"manifestPath" = "/includes/rev-manifest.json",
"manifestPath" = "/includes/mix-manifest.json",
"prependModuleRoot" = true,
"prependPath" = "",
"prependPath" = "/includes",
"modules": {}
};
}
Expand Down
2 changes: 1 addition & 1 deletion box.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name" : "mixr",
"version" : "1.0.1",
"version" : "2.0.0",
"author" : "Angry Sam Productions, Inc.",
"location":"ForgeboxStorage",
"homepage" : "https://github.com/homestar9/mixr",
Expand Down
4 changes: 4 additions & 0 deletions changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@ All notable changes to this project will be documented in this file.

----

## [2.0.0] => 2024-05-21

* **Breaking Change** - Updated default configuration to emulate Laravel Mix 6

## [1.0.0] => 2023-03-07

* First release
75 changes: 58 additions & 17 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,51 +22,77 @@ Configure Mixr in your Coldbox `config/Coldbox.cfc` file:

```js
moduleSettings = {
// default configuration designed to emulate Coldbox Elixir
// default configuration designed to emulate Laravel Mix 6
mixr: {
"manifestPath" = "/includes/rev-manifest.json",
"manifestPath" = "/includes/mix-manifest.json",
"prependModuleRoot" = true,
"prependPath" = "",
"prependPath" = "/includes",
"modules": {}
}
};
```

The above configuration will work in a ColdBox app that uses Laravel 6 to generate asset manifests. If you are using Coldbox Elixir, you will need to change the configuration to match the conventions of your asset bundler. See the [Upgrade Guide](#upgrade-guide) for more information.

For reference, a Laravel 6 Manifest file might look like this:

```js
{
"/css/app.css": "/css/app.css?id=123",
"/js/app.js": "/js/app.js?id=123"
}
```

The same manifest file might look like this when using Coldbox Elixir. You will need to update the default configuration if you are using Coldbox Elixir starting with Mixr version 2.0:

```js
{
"includes/js/app.js": "includes/js/app.123.js",
"includes/css/app.css": "includes/css/app.123.css"
}
```

## Upgrade Guide

### Upgrading from 1.x to 2.x

Version 2.0 introduces a **breaking change** where the configuration defaults have been changed to emulate Laravel Mix 6. If you are upgrading from 1.x to 2.x, and you use Coldbox Elixir, you will need to update your configuration (see examples for details)

## Settings

| Setting | Description | Default |
| --- | --- | --- |
| `manifestPath` | (string) The path from the root where your manifest file resides | /includes/rev-manifest.json |
| `manifestPath` | (string) The path from the root where your manifest file resides | /includes/mix-manifest.json |
| `prependModuleRoot` | (boolean) Whether or not to prepend the module root to the path | true |
| `prependPath` | (string) A path to prepend to the asset path | "" |
| `prependPath` | (string) A path to prepend to the asset path | /includes |
| `modules` | (struct) A struct of module names so you can pass along custom configs to submodules | {} |

## Submodule Settings

Sometimes a tracked or untracked submodule needs to use its own asset manifest file conventions. For example, if you use Laravel Mix in your main app, but you use Coldbox Elixir in a submodule, you can configure Mixr to use different settings for each submodule.

### Method 1: Configure Via ModuleConfig.cfc *(recommended)*
### Configure Via Submodule's ModuleConfig.cfc

Within the module's `ModuleConfig.cfc` file, add a `mixr` struct to the `configure()` method:
You can provide module-specific settings to Mixr, just in case some submodules use different conventions. To do this within a module's `ModuleConfig.cfc` file, add a `mixr` struct to the `configure()` method:

```js
function configure(){

// module settings - we are overriding mixr conventions in this module
// module settings - we are overriding mixr conventions in this module to emulate Coldbox Elixir
variables.settings = {
mixr: {
"manifestPath": "/includes/mix-manifest.json",
"manifestPath": "/includes/rev-manifest.json",
"prependModuleRoot": true,
"prependPath": "/includes"
"prependPath": ""
}
};

}
```

### Method 2: Configure Via Coldbox.cfc
### Configure Via Coldbox.cfc

You can also configure Mixr in your main `config/Coldbox.cfc` file. Add your module name to the `mixr.modules` in `moduleSettings` like this:
Alternatively, you can also configure Mixr in your main `config/Coldbox.cfc` file. Add any submodule to the `mixr.modules` in `moduleSettings` like this to override settings:

```js
moduleSettings = {
Expand All @@ -76,7 +102,7 @@ moduleSettings = {
"prependModuleRoot" = true,
"prependPath" = "",
"modules": {
// custom configuration for a submodule
// custom configuration for a submodule to emaulate Laravel Mix V6
"fooModule": {
"manifestPath": "/includes/mix-manifest.json",
"prependModuleRoot": true,
Expand Down Expand Up @@ -116,20 +142,26 @@ Mixr automatically attempts to figure out which module the request is coming fro

#### Coldbox Elixir

No need to change any defaults. It should work out of the box.

```js
// config/Coldbox.cfc
mixr = {
"manifestPath": "/includes/rev-manifest.json",
"prependModuleRoot": true,
"prependPath": "",
"modules": {}
}
```

#### Laravel Mix

No need to change any defaults. It should work out of the box. Here is the configuration, just in case you need to change it:

```js
// configure mixr to use laravel mix conventions
mixr = {
"manifestPath": "/includes/mix-manifest.json",
"prependModuleRoot": true,
"prependPath": "includes",
"prependPath": "/includes",
"modules": {}
}
```
Expand All @@ -155,7 +187,7 @@ mixr = {

## Why Mixr?

Why would this module be useful if Coldbox Elixir already exists?
Why Does Coldbox need another asset helper? Here are a few reasons why Mixr is a great choice for your Coldbox app:

- Coldbox Elixir is a great asset helper, but it is not flexible enough to work with other asset bundlers like Laravel Mix. Mixr is designed to work with any asset bundler that generates a manifest file.
- Mixr registers itself as a Coldbox helper method, so it can automatically detect which module you are in any time you call `mixr()`
Expand All @@ -170,3 +202,12 @@ Why would this module be useful if Coldbox Elixir already exists?
## About the Author:

This module was passionately developed by [Angry Sam Productions](https://www.angrysam.com), a web development company based in California. We believe creating and contributing open source software strenghens the development community and makes the world a better place. If you would like to learn more about our company or hire us for your next project, please [contact us](https://www.angrysam.com/).

## Running Tests

To run the tests, simply run the following command from the root of the project in Commandbox:
`start [email protected]` (or whichever server JSON you want to use)
`server open` (to open the server in your browser)
navigate to `/tests/runner.cfm` in your browser

```bash
2 changes: 1 addition & 1 deletion test-harness/box.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"private":true,
"description":"",
"dependencies":{
"coldbox":"^6.0.0"
"coldbox":"^7.0.0"
},
"devDependencies":{
"testbox":"*"
Expand Down
6 changes: 6 additions & 0 deletions test-harness/includes/mix-manifest.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"/css/app.css": "/css/app.213c217870ef7e339637e917bf414c9a.css",
"/js/app.js": "/js/app.af7cb9dae6959cced30cab1f1d77e101.js",
"/modules_app/login/css/app.css": "/modules_app/login/css/app.ccf9093ee5944030fbc7bc87116ed066.css",
"/modules_app/login/css/app.js": "/modules_app/login/js/app.402758792d65cdf17c2c5cf8b5fc2a70.js"
}
6 changes: 0 additions & 6 deletions test-harness/includes/rev-manifest.json

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
component {

// Module Properties
this.title = "laravel";
this.title = "elixir";
this.author = "";
this.webURL = "";
this.description = "";
this.version = "1.0.0";

// Module Entry Point
this.entryPoint = "/laravel";
this.entryPoint = "/elixir";
// Model Namespace
this.modelNamespace = "laravel";
this.modelNamespace = "elixir";
// CF Mapping
this.cfmapping = "laravel";
this.cfmapping = "elixir";
// Auto-map models
this.autoMapModels = true;
// Module Dependencies
Expand All @@ -21,16 +21,16 @@ component {
function configure(){

layoutSettings = {
defaultLayout = "Laravel.cfm"
defaultLayout = "elixir.cfm"
};

// module settings - stored in modules.name.settings
// Note: we are overriding mixr conventions in this module
variables.settings = {
mixr: {
"manifestPath": "/includes/mix-manifest.json",
"manifestPath": "/includes/rev-manifest.json",
"prependModuleRoot": true,
"prependPath": "/includes"
"prependPath": "/"
}
};

Expand Down
4 changes: 4 additions & 0 deletions test-harness/modules_app/elixir/includes/css/elixir.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
body {
background-color: green;
color: white;
}
1 change: 1 addition & 0 deletions test-harness/modules_app/elixir/includes/js/elixir.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
console.log( 'I am the elixir app' );
4 changes: 4 additions & 0 deletions test-harness/modules_app/elixir/includes/rev-manifest.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"includes/js/elixir.js": "includes/js/elixir.46ef92deb8e36cfa93b3e8a8c1bb6a4a.js",
"includes/css/elixir.css": "includes/css/elixir.46ef92deb8e36cfa93b3e8a8c1bb6a4a.css"
}
4 changes: 0 additions & 4 deletions test-harness/modules_app/laravel/includes/mix-manifest.json

This file was deleted.

4 changes: 4 additions & 0 deletions test-harness/modules_app/login/includes/mix-manifest.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"/css/login.css": "/css/login.28fc241b1431baefb2a9b4307ed9cff1.css",
"/js/login.js": "/js/login.fa8eaddc959b1c295a40593221b5ae03.js"
}
4 changes: 0 additions & 4 deletions test-harness/modules_app/login/includes/rev-manifest.json

This file was deleted.

3 changes: 3 additions & 0 deletions test-harness/tests/resources/mix-manifest.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"/tests/asset.js": "/tests/asset.js?id=97075299beff243f0162befb209c2391"
}
3 changes: 0 additions & 3 deletions test-harness/tests/resources/rev-manifest.json

This file was deleted.

7 changes: 4 additions & 3 deletions test-harness/tests/specs/unit/MixrTest.cfc
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
component extends="coldbox.system.testing.BaseModelTest" model="mixr.models.Mixr" {

variables._settings = {
"manifestPath": "/tests/resources/rev-manifest.json",
// custom settings for our tests
variables._settings = {
"manifestPath": "/tests/resources/mix-manifest.json",
"prependModuleRoot": false,
"prependPath": "",
"modules": {
Expand Down Expand Up @@ -43,7 +44,7 @@ component extends="coldbox.system.testing.BaseModelTest" model="mixr.models.Mixr

it( "Can return an asset from a manifest file", function(){
var result = model.get( "/tests/asset.js" );
expect( result ).toBe( "/tests/asset.123456.js" );
expect( result ).toBe( "/tests/asset.js?id=97075299beff243f0162befb209c2391" );
});

it( "Can return an asset from a custom manfest path", function(){
Expand Down
Loading

0 comments on commit c849c75

Please sign in to comment.