Skip to content
This repository has been archived by the owner on Dec 7, 2022. It is now read-only.

Commit

Permalink
Update v3.9.0
Browse files Browse the repository at this point in the history
Merge pull request #134 from joao-neves95/next
  • Loading branch information
joao-neves95 authored Nov 19, 2019
2 parents 73e48c3 + c1001f7 commit 30194ab
Show file tree
Hide file tree
Showing 32 changed files with 805 additions and 668 deletions.
36 changes: 32 additions & 4 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,35 @@

 

#### *v3.8.5 - 21/10/2019
#### *v3.9.0 - 19/11/2019

- Added support for optional custom source file configuration that overwrites the global merger configuration
(minfication for the moment).

- Fixed a bug on the imports parser, where the file extension had always to be `.js`.<br>
Now, it only defaults to `.js` in case there was no extension provided (like it is
stated on the docs: [README.md](https://github.com/joao-neves95/merger-js/blob/master/README.md#use)).<br>
With this fix, MergerJS can now merge any text files, for example HTML files.

- Fixed a bug on the `merger rm` command, where it was only possible to remove one file
and the program crashed if the user selected the "All" option on the source file selection.

- Fixed a bug on the `merger add` command, where if the user deleted its build file name input,
the name was set to ".js".

- Fixed a bug on the file path console output of the `merger build` command.<br/>
Example of the previous output: "path-to\js.system.collections\js.system.collections\distjs.system.collections.js"
Example of the fixed output: "path-to\js.system.collections\js.system.collections\dist\js.system.collections.js"

- Significant performance improvements.

- Big internal refactorings: Slowly migrating to the Node.js sync API and removed a lot of the "callback hell".

- Updated dependencies.

&nbsp;

#### v3.8.5 - 21/10/2019

- Refactored the import parser and made multiple optimisations.
- Updated dependencies.
Expand All @@ -13,7 +41,7 @@
#### v3.8.4 - 07/10/2019

- The output of `merger update` is now printed on the console.

&nbsp;

#### v3.8.3 - 06/10/2019
Expand Down Expand Up @@ -55,7 +83,7 @@

#### v3.7.1 - 04/05/2019

- Fixed a bug when importing from directories. It was importing relative to the header file instead of the directory of the
- Fixed a bug when importing from directories. It was importing relative to the header file instead of the directory of the
header file, like it used to (bug from last update).

&nbsp;
Expand Down Expand Up @@ -328,7 +356,7 @@
It is advised to reinstall merger-js:<br/>
1) "npm rm merger-js -g"<br/>
2) "npm i merger-js -g"

&nbsp;

#### v2.0.5/6/7 (Hotfixes) - 09/04/2018
Expand Down
65 changes: 36 additions & 29 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
├── [node-notifier](https://github.com/mikaelbr/node-notifier)<br/>
├── [chalk](https://github.com/chalk/chalk)<br/>
├── [line-by-line](https://github.com/Osterjour/line-by-line)<br/>
├── [is-text-path](https://github.com/sindresorhus/is-text-path)<br/>
├── [js.system.collections](https://github.com/joao-neves95/js.system.collections)<br/>

<br/>
Expand Down Expand Up @@ -199,32 +200,42 @@ npm install merger-js -g

&nbsp;

## Example of a File Structure
## Custom Source File Configuration
Since v3.9.0, it is possible to have custom source file configuration that overwrites the global
configuration.</br>
This is useful, for example, if you have multiple source files and want that only some file be
minified or not.

In the moment, there is no CLI command to edit custom source file configurations, so you will have
to do it by hand. Just add a config object to your source file object.</br>
In the moment there is only the minification (`uglify`) option.

Example (`merger-config.json`):

```json
(...)
"sourceFiles": [
{
"source": "path-to\\js.system.collections\\js.system.collections.header.js",
"output": {
"path": "path-to\\js.system.collections\\dist",
"name": "js.system.collections.js"
}
},
{
"source": "path-to\\js.system.collections\\js.system.collections.header.js",
"output": {
"path": "path-to\\js.system.collections\\dist",
"name": "js.system.collections.min.js"
},
"config": {
"uglify": true
}
}
]
(...)

|-- root/</br>

>|-- **merger-config.json**</br>
>|-- package.json</br>
>|-- .env</br>
>|-- node_modules/</br>
>|-- (...)</br>

>|-- server/</br>
>>|-- (...)</br>

>|-- client/</br>

>>|-- css</br>
>>>|-- (...)</br>

>>|-- js</br>
>>>|-- mergerBuildFile.js</br>
>>>|-- src</br>
>>>>|-- sourceFile.header.js (the header file containing all the imports; the first file to be build)</br>
>>>>|-- utilities.js</br>
>>>>|-- someView.js</br>
>>>>|-- someModel.js</br>
>>>>|-- someController.js</br>
```

&nbsp;

Expand All @@ -244,10 +255,6 @@ Merger uses [SemVer](https://semver.org/) for versioning. You can read the chang

See the style guide here: [merger-js/STYLE-GUIDE.md](https://github.com/joao-neves95/merger-js/blob/master/STYLE-GUIDE.md)

Since version 3.6.5, every asynchronous function should make exclusive use of promises and the async/await syntax,
avoiding multiple callback chaining (I.e.: "callback hell"), unless using a callback instead of a promise does make
sense and does not contribute to a more confusing code.

&nbsp;

## Motivation
Expand Down
2 changes: 1 addition & 1 deletion VERSION.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
# Current Branch Version

**v3.8.5**
**v3.9.0**
1 change: 0 additions & 1 deletion enums/importType.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
*
*/


const ImportType = Object.freeze( {
Unknown: -1,
RelativePath: 1,
Expand Down
2 changes: 1 addition & 1 deletion enums/promptResponseType.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/*
/*
* Copyright (c) 2018-2019 João Pedro Martins Neves - All Rights Reserved.
*
* MergerJS (merger-js) is licensed under the MIT license, located in
Expand Down
77 changes: 35 additions & 42 deletions merger.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
#!/usr/bin/env node


/*
* Copyright (c) 2018-2019 João Pedro Martins Neves - All Rights Reserved.
*
Expand All @@ -13,61 +12,55 @@
const path = require('path');
const chokidar = require('chokidar');
const mergerCLI = require('./modules/mergerCLI');
const config = require('./modules/config');
const Config = require('./modules/config');
const async = require( './node_modules/neo-async' );
const selectSourceFile = require('./modules/CLIModules/selectSourceFilePrompt');
const parseImports = require( './modules/buildModules/parseImports' );
const build = require( './modules/buildModules/build' );
const sourceFileModel = require( './models/sourceFileModel' );

// #region PROGRAM

mergerCLI( ( newConfig ) => {
config( newConfig, () => {

selectSourceFile( ( sourceFile ) => {
/** @type { sourceFileModel[] } */
let files = [sourceFile];
mergerCLI( async ( newConfig ) => {
await Config.init( newConfig );
let sourceFiles = await selectSourceFile();

// If "sourceFile" is Array it means that the user chose the "All" (files) option in selectSourceFile().
if (Array.isArray(sourceFile)) {
files = sourceFile;
// Execute a one time build only.
global.config.autoBuild = false;
}
// If "sourceFiles" is Array it means that the user chose the "All" (sourceFiles) option in selectSourceFile().
if ( Array.isArray( sourceFiles ) ) {
// Execute a one time build only.
global.config.autoBuild = false;

async.eachSeries( files, ( file, Callback ) => {
} else {
sourceFiles = [sourceFiles];
}

parseImports( file.source, async ( buildOrder ) => {
// Execute one time builds:
if ( !global.config.autoBuild ) {
await build( file, buildOrder );
return Callback();
}
async.eachSeries( sourceFiles, async ( sourceFile, Callback ) => {
await Config.setCustomConfig( sourceFile.source );
const buildOrder = await parseImports( sourceFile.source );

// Execute an auto builds (with file watcher):
else {
const whatcher = chokidar.watch( buildOrder, { persistent: true, cwd: path.dirname( file.source ) } );
// Execute one time builds:
if ( !global.config.autoBuild ) {
await build( sourceFile, buildOrder );
return Callback();

whatcher
.on( 'ready', async () => {
console.info( ' Inicial scan complete. Ready to build on changes...' );
await build( file, buildOrder );
return Callback();
})
.on('error', err => console.error('Auto build error: ', err))
.on( 'change', async ( path, stats ) => {
await build(file, null);
});
}
});
// Execute an auto build session (with file watcher):
} else {
const whatcher = chokidar.watch( buildOrder, { persistent: true, cwd: path.dirname( sourceFile.source ) } );
whatcher
.on( 'ready', async () => {
console.info( ' Inicial scan complete. Ready to build on changes...' );
await build( sourceFile, buildOrder );
return Callback();
} )
.on( 'error', err => console.error( 'Auto build error: ', err ) )
.on( 'change', async ( path, stats ) => {
await build( sourceFile, null );
} );
}

}, (err) => {
if (err) throw err;
});
}, ( err ) => {
if ( err ) throw err;
} );

});
});
} );

// #endregion
18 changes: 0 additions & 18 deletions models/configKeysEnum.js

This file was deleted.

19 changes: 19 additions & 0 deletions models/sourceFileConfigBase.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
/*
* Copyright (c) 2018-2019 João Pedro Martins Neves - All Rights Reserved.
*
* MergerJS (merger-js) is licensed under the MIT license, located in
* the root of this project, under the name "LICENSE.md".
*
*/

'use string';

class SourceFileConfigBase {

constructor( uglify ) {
this.uglify = uglify === undefined || uglify === null ? true : uglify;
}

}

module.exports = SourceFileConfigBase;
8 changes: 8 additions & 0 deletions models/sourceFileModel.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
*/

'use strict';
const SourceFileConfigBase = require( './sourceFileConfigBase' );

class SourceFileModel {
constructor() {
Expand All @@ -16,6 +17,13 @@ class SourceFileModel {
path: '',
name: ''
};

/**
* type { SourceFileConfigBase | null }
*
* @type { SourceFileConfigBase | null }
*/
this.config = null;
}
}

Expand Down
10 changes: 8 additions & 2 deletions models/userConfigModel.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,22 +8,28 @@

'use strict';
const newTimestamp = require( '../modules/newTimestamp' ).completeLocale;
const SourceFileConfigBase = require( './sourceFileConfigBase' );
const SourceFileModel = require( './sourceFileModel' );

class UserConfig {
class UserConfig extends SourceFileConfigBase {
constructor (uglify, autoBuild, notifications) {
super( uglify );

this.mergerJsLinks = {
npm: 'https://www.npmjs.com/package/merger-js',
github: 'https://github.com/joao-neves95/merger-js',
readme: 'https://github.com/joao-neves95/merger-js/blob/master/README.md',
changelog: 'https://github.com/joao-neves95/merger-js/blob/master/CHANGELOG.md'
};

this.uglify = uglify === undefined || uglify === null ? true : uglify;
this.autoBuild = autoBuild === undefined || autoBuild === null ? false : autoBuild;
this.notifications = notifications === undefined || notifications === null ? true : notifications;

this.updateOnLaunch = true;
this.lastUpdateCheck = newTimestamp();
this.nodeModulesPath = "";

/** @type { SourceFileModel[] } */
this.sourceFiles = [];
}
}
Expand Down
Loading

0 comments on commit 30194ab

Please sign in to comment.