Comparing version 3.10.2 to 3.10.3
@@ -5,4 +5,11 @@ # CHANGELOG | ||
#### *v3.10.2 - 11/06/2020 | ||
#### *v3.10.3 - 13/06/2020 | ||
- Performance improvements. | ||
- Big internal refactorings in preparation for the upcoming UMD module creation. | ||
| ||
#### v3.10.2 - 11/06/2020 | ||
- Fixed the `merger set` command, which was due to a bug added with the help command. | ||
@@ -9,0 +16,0 @@ |
@@ -12,10 +12,6 @@ #!/usr/bin/env node | ||
'use strict'; | ||
const path = require('path'); | ||
const chokidar = require('chokidar'); | ||
const mergerCLI = require('./modules/mergerCLI'); | ||
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 Compiler = require( './modules/buildModules/compiler' ); | ||
@@ -37,32 +33,9 @@ // #region PROGRAM | ||
async.eachSeries( sourceFiles, async ( sourceFile, Callback ) => { | ||
await Config.setCustomConfig( sourceFile.source ); | ||
const buildOrder = await parseImports( sourceFile.source ); | ||
for (let i = 0; i < sourceFiles.length; ++i) { | ||
Config.setCustomConfig( sourceFiles[i].source ); | ||
await Compiler.run( sourceFiles[i] ); | ||
} | ||
// Execute one time builds: | ||
if ( !global.config.autoBuild ) { | ||
await build( sourceFile, buildOrder ); | ||
return Callback(); | ||
// 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; | ||
} ); | ||
} ); | ||
// #endregion |
@@ -53,2 +53,7 @@ /* | ||
this.isGithubNewSyntax = null; | ||
/** | ||
* @type { string | null } | ||
*/ | ||
this.headerFilePath = null; | ||
} | ||
@@ -55,0 +60,0 @@ |
@@ -14,33 +14,26 @@ /* | ||
/** | ||
* | ||
* @param { string } allCode Code input. | ||
* | ||
* @param { Function } callback (string) | ||
* Minifies JavaScript code, if the minification setting is set. | ||
* | ||
* @param { object } allCode Code input. | ||
* @returns { string } | ||
*/ | ||
module.exports = ( allCode, callback ) => { | ||
if ( global.config.uglify ) { | ||
let minifiedCode = uglify.minify( allCode, global.minifyOptions ); | ||
module.exports = ( allCode ) => { | ||
if ( !global.config.uglify ) { | ||
return Object.values( allCode ).join( '' ); | ||
} | ||
if ( minifiedCode.error ) { | ||
let err = minifiedCode.error; | ||
notify( `Build error on the file ${err.filename}, line ${err.line}, col ${err.col}.`, err.message ); | ||
const minifiedCode = uglify.minify( allCode, global.minifyOptions ); | ||
return console.error( ' Error:\n ', err ); | ||
} | ||
if ( minifiedCode.error ) { | ||
const err = minifiedCode.error; | ||
notify( `Build error on the file ${err.filename}, line ${err.line}, col ${err.col}.`, err.message ); | ||
if ( global.minifyOptions.warnings && minifiedCode.warnings ) { | ||
console.warn( '\n Warnings: \n ', minifiedCode.warnings ); | ||
} | ||
return console.error( ' Error:\n ', err ); | ||
} | ||
return callback( minifiedCode.code ); | ||
if ( global.minifyOptions.warnings && minifiedCode.warnings ) { | ||
console.warn( '\n Warnings: \n ', minifiedCode.warnings ); | ||
} | ||
} else { | ||
let nonMinifiedCode = ''; | ||
for ( let fileName in allCode ) { | ||
nonMinifiedCode += allCode[fileName]; | ||
} | ||
return callback( nonMinifiedCode ); | ||
} | ||
return minifiedCode.code; | ||
}; |
{ | ||
"name": "merger-js", | ||
"displayName": "MergerJS", | ||
"version": "3.10.2", | ||
"version": "3.10.3", | ||
"description": "Yet another simple cross-platform CLI build tool to bundle JavaScript files, with a custom file import syntax, ES8+ minification, auto build capabilities, and native OS notifications.", | ||
@@ -27,3 +27,3 @@ "readme": "https://github.com/joao-neves95/merger-js/blob/master/README.md", | ||
"engines": { | ||
"node": ">=10.0.0", | ||
"node": ">=12.0.0", | ||
"npm": ">=6.4.0" | ||
@@ -44,3 +44,2 @@ }, | ||
"line-by-line": "^0.1.6", | ||
"neo-async": "^2.5.1", | ||
"node-notifier": "^6.0.0", | ||
@@ -47,0 +46,0 @@ "uglify-es": "^3.3.10" |
159
README.md
# MergerJS | ||
[![npm](https://img.shields.io/npm/v/merger-js.svg)](https://www.npmjs.com/package/merger-js) | ||
[![LICENSE](https://img.shields.io/npm/l/merger-js.svg)](https://github.com/joao-neves95/merger-js/blob/master/LICENSE.md)<br/> | ||
[![LICENSE](https://img.shields.io/npm/l/merger-js.svg)](https://github.com/joao-neves95/merger-js/blob/master/LICENSE.md)\ | ||
[![GitHub stars](https://img.shields.io/github/stars/joao-neves95/merger-js.svg?label=star&style=social)](https://github.com/joao-neves95/merger-js) | ||
@@ -13,37 +13,38 @@ | ||
**NPM:** [LINK](https://www.npmjs.com/package/merger-js)<br/> | ||
**GitHub:** [LINK](https://github.com/joao-neves95/merger-js)<br/> | ||
**License:** [GPLv3](https://github.com/joao-neves95/merger-js/blob/master/LICENSE.md)<br/> | ||
**Changelog:** [LINK](https://github.com/joao-neves95/merger-js/blob/master/CHANGELOG.md)<br/> | ||
**Dependencies:**<br/> | ||
├── [uglify-es](https://www.npmjs.com/package/uglify-es)<br/> | ||
├── [neo-async](https://github.com/suguru03/neo-async)<br/> | ||
├── [chokidar](https://github.com/paulmillr/chokidar)<br/> | ||
├── [commander](https://github.com/tj/commander.js)<br/> | ||
├── [inquirer](https://github.com/SBoudrias/Inquirer.js)<br/> | ||
├── [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/> | ||
**NPM:** [LINK](https://www.npmjs.com/package/merger-js)\ | ||
**GitHub:** [LINK](https://github.com/joao-neves95/merger-js)\ | ||
**License:** [GPLv3](https://github.com/joao-neves95/merger-js/blob/master/LICENSE.md)\ | ||
**Changelog:** [LINK](https://github.com/joao-neves95/merger-js/blob/master/CHANGELOG.md)\ | ||
**Dependencies:**\ | ||
├── [uglify-es](https://www.npmjs.com/package/uglify-es)\ | ||
├── [chokidar](https://github.com/paulmillr/chokidar)\ | ||
├── [commander](https://github.com/tj/commander.js)\ | ||
├── [inquirer](https://github.com/SBoudrias/Inquirer.js)\ | ||
├── [node-notifier](https://github.com/mikaelbr/node-notifier)\ | ||
├── [chalk](https://github.com/chalk/chalk)\ | ||
├── [line-by-line](https://github.com/Osterjour/line-by-line)\ | ||
├── [is-text-path](https://github.com/sindresorhus/is-text-path)\ | ||
├── [js.system.collections](https://github.com/joao-neves95/js.system.collections)\ | ||
<br/> | ||
| ||
--- | ||
<br/> | ||
| ||
## Features | ||
- [x] **Command Line Interface (CLI)** | ||
- [x] **Merge multiple JS files into one** | ||
- [x] **Support for multiple source/header files** | ||
- [x] **Use @import comments on a source file to specify the build order** | ||
- [x] **Minification, supporting ES6+** (optional) | ||
- [x] **Auto builds on file changes** (optional) | ||
- [x] **Native OS build notifications** (optional) | ||
- [x] **Import an entire directory** (use ```@import<<DIR 'directoryName/'```) | ||
- [x] **Import a file or directory from the node_modules folder** (use ```$import 'file-name'```) | ||
- [x] **Import a file from an URL** (use ```%import 'url'```) | ||
- [x] **Import a file or directory from a GitHub repository** (use ```%import<<github::{branch-name} '{userName}/{repositoryName}/{pathToFile}.js'```) | ||
- [x] **Command Line Interface (CLI)** | ||
- [x] **Merge multiple JS files into one** | ||
- [x] **Support for multiple source/header files** | ||
- [x] **Use @import comments on a source file to specify the build order** | ||
- [x] **Minification, supporting ES6+** (optional) | ||
- [x] **Auto builds on file changes** (optional) | ||
- [x] **Native OS build notifications** (optional) | ||
- [x] **Import an entire directory** (use ```@import<<DIR 'directoryName/'```) | ||
- [x] **Import a file or directory from the node_modules folder** (use ```$import 'file-name'```) | ||
- [x] **Import a file from an URL** (use ```%import 'url'```) | ||
- [x] **Import a file or directory from a GitHub repository** (use ```%import<<github::{branch-name} '{userName}/{repositoryName}/{pathToFile}.js'```) | ||
- [ ] **Create UMD modules** | ||
| ||
@@ -53,9 +54,8 @@ | ||
For the latest version of the README, always refer to the MergerJS GitHub repository's master branch:<br/> | ||
For the latest version of the README, always refer to the MergerJS GitHub repository's master branch:\ | ||
https://github.com/joao-neves95/merger-js/blob/master/README.md | ||
### 1) Node.js | ||
You will need [Node.js](https://nodejs.org/en/) version 10+ installed to run merger. | ||
You will need [Node.js](https://nodejs.org/en/) version 12+ installed to run merger. | ||
@@ -78,7 +78,7 @@ ### 2) Install merger with NPM | ||
## Use: | ||
## Use | ||
1) Make a header file - the source file; the first file to be merged - containing, on the top, | ||
comments importing the files in the order you want them to be built, from the first to the | ||
last just like in a browser.<br/> | ||
last just like in a browser.\ | ||
@@ -105,14 +105,10 @@ Example: | ||
- The import of the header file (source file) is optional; | ||
- You can import files from different directories relative to the same source file.<br/> | ||
- You can import files from different directories relative to the same source file.\ | ||
Example: ```// @import '../otherFolder/someFile'``` | ||
| ||
2) Run ```merger init``` on the root of your project:<br/> | ||
2) Run ```merger init``` on the root of your project:\ | ||
This will set up the configuration model as well as some global configurations (minification, auto builds on file changes, | ||
native OS notifications).<br/> | ||
native OS notifications).\ | ||
You can alter them later through the CLI with the "merger set" command (learn more below in the "Commands" section). | ||
| ||
3) Run ```merger add``` to add a new source file (header file) to your merger configuration file (learn more below in the "Commands" section). | ||
@@ -124,28 +120,28 @@ | ||
## Import Syntax: | ||
## Import Syntax | ||
- ```// @import 'relativePathToTheFile'``` or ```// @'relativePathToTheFile'```:<br/> | ||
Using an ```@``` token on an import statement imports a file relative to the header file.<br/> | ||
- ```// @import 'relativePathToTheFile'``` or ```// @'relativePathToTheFile'```:\ | ||
Using an ```@``` token on an import statement imports a file relative to the header file.\ | ||
* Pushing (```<<```) ```dir```, ```DIR```, ```directory``` or ```DIRECTORY``` into ```@import```, imports an entire directory.<br/> | ||
Note that using this method, the files are not compiled in any specific order.<br/> | ||
* Pushing (```<<```) ```dir```, ```DIR```, ```directory``` or ```DIRECTORY``` into ```@import```, imports an entire directory.\ | ||
Note that using this method, the files are not compiled in any specific order.\ | ||
E.g.: ``` // @import<<dir '../otherDirectory/'``` ```// @<<DIR 'someDirectoryHere/'``` | ||
- ```// $import 'pathRelativeToNodeModules'``` or ```// $'node_modules_file'```:<br/> | ||
- ```// $import 'pathRelativeToNodeModules'``` or ```// $'node_modules_file'```:\ | ||
Using a ```$``` token imports relative to the "node_modules" directory. | ||
* Pushing (```<<```) ```dir```, ```DIR```, ```directory``` or ```DIRECTORY``` into ```$import```, imports an entire directory from node_modules.<br/> | ||
Note that using this method, the files are not compiled in any specific order.<br/> | ||
* Pushing (```<<```) ```dir```, ```DIR```, ```directory``` or ```DIRECTORY``` into ```$import```, imports an entire directory from node_modules.\ | ||
Note that using this method, the files are not compiled in any specific order.\ | ||
E.g.: ``` // $import<<dir '../otherDirectory/'``` ```// $<<DIR 'someDirectoryHere/'``` | ||
- ```// %import 'https://specificUrl.com/file.min.js'``` or ```// %'https://specificUrl.com/file.min.js'```:<br/> | ||
Using a ```%``` token imports a file from a specific URL. The file is downloaded and stored in node_modules in the first time and later fetch from there in order to not download the file in each build.<br/> | ||
- ```// %import 'https://specificUrl.com/file.min.js'``` or ```// %'https://specificUrl.com/file.min.js'```:\ | ||
Using a ```%``` token imports a file from a specific URL. The file is downloaded and stored in node_modules in the first time and later fetch from there in order to not download the file in each build.\ | ||
* Adding a double ```%%``` token forces the download on every build (good for updates). Valid for specific URLs and GitHub.<br/> | ||
E.g.: `// %%'https://code.jquery.com/jquery-3.4.1.min.js'`<br/> | ||
* Adding a double ```%%``` token forces the download on every build (good for updates). Valid for specific URLs and GitHub.\ | ||
E.g.: `// %%'https://code.jquery.com/jquery-3.4.1.min.js'`\ | ||
* Pushing (`<<`) `GH`, `gh`, `github` or `GITHUB` into `%import`, imports a file from a GitHub repository.<br/> | ||
If the branch name is not provided, it is defaulted to the "master" branch.<br/> | ||
* Pushing (`<<`) `GH`, `gh`, `github` or `GITHUB` into `%import`, imports a file from a GitHub repository.\ | ||
If the branch name is not provided, it is defaulted to the "master" branch.\ | ||
E.g.:<br> | ||
`// %import<<GH::{branch} '{user}/{repository}/{pathToFile}.js'`<br/> | ||
`// %import<<GH::{branch} '{user}/{repository}/{pathToFile}.js'`\ | ||
`// %<<github::v4-dev '/twbs/bootstrap/dist/js/bootstrap.min.js'` | ||
@@ -155,7 +151,7 @@ | ||
* MergerJS still supports the previous GitHub import syntax for files, where the branch is specified directly on the path, to avoid breaking changes (not supported on directories). This syntax should be considered as deprecated.<br/> | ||
* MergerJS still supports the previous GitHub import syntax for files, where the branch is specified directly on the path, to avoid breaking changes (not supported on directories). This syntax should be considered as deprecated.\ | ||
E.g.: `// %<<github '/twbs/bootstrap/v4-dev/dist/js/bootstrap.min.js'` | ||
* Pushing (`<<`) `dir`, `DIR`, `directory` or `DIRECTORY` into `%import<<github`, imports an entire directory from GitHub.<br/> | ||
Note that using this method, the files are not compiled in any specific order.<br/> | ||
* Pushing (`<<`) `dir`, `DIR`, `directory` or `DIRECTORY` into `%import<<github`, imports an entire directory from GitHub.\ | ||
Note that using this method, the files are not compiled in any specific order.\ | ||
E.g.: `// %%import<<GH::master<<dir 'twbs/bootstrap/dist/js'` | ||
@@ -166,16 +162,23 @@ | ||
<!-- | ||
## UMD Module Syntax: | ||
## UMD Module Syntax | ||
### Namespaces | ||
- ` // #module::UMD ` <br/> | ||
- Add this to an header file to tell MergerJS that you want to create a UMD module namespace with all the inner files bundled into it as multiple sub-modules. | ||
### Namespace | ||
- ` // #module::UMD ` \ | ||
- Add this to an header file to tell MergerJS that you want to create a UMD module namespace and later add inner files bundled into it as modules. | ||
- The namespace will be called the same as your build file name. | ||
- Keep in mind that compiling an header file into an UMD module will take more time than simply bundling multiple files together, | ||
because every file will have to be parsed. | ||
### Modules | ||
- ` // #export 'myModuleName' ` (optional) <br/> | ||
- Add this to override the module name of the class inside a file.<br /> | ||
- If you do not specify a module name, MergerJS will default it to the name of the file. | ||
- **Every inner file (module) must be comprised of a single <u>class</u>.** | ||
MergerJS will automatically export it. | ||
- **MergerJS only supports exporting classes as modules.** Simply define a <u>class</u> on each file (i.e.: not an object, or a function). | ||
- ` // #export ` or ` // #export 'myCustomModuleName' ` \ | ||
- MergerJS will default the module name to the name of the file. | ||
- Optionally, you can add a custom name to your export, to override the module name of the class inside a file. | ||
- **Every file (module) must be comprised of a <u>single</u> class, object or function.** | ||
MergerJS will automatically export the first one it sees. | ||
- ` // #require 'myCustomModuleName' ` | ||
- This is what you'll need to use in order to require another module on your namespace. | ||
- You'll need to use the file name, or custom module name, of the module you require. | ||
| ||
@@ -190,4 +193,4 @@ --> | ||
- ```merger add```: Add a new source file to the merger config file.<br/> | ||
You should run this command on the directory where the source file you want to add is located.<br/> | ||
- ```merger add```: Add a new source file to the merger config file.\ | ||
You should run this command on the directory where the source file you want to add is located.\ | ||
MergerJS will give you the directory path, you input the source file name (the extension names are | ||
@@ -197,11 +200,11 @@ optional), or a relative path to that directory, and MergerJS will locate the configuration file in | ||
- ```merger rm```: <br/> | ||
Remove a source file from the merger-config file.<br/> | ||
- ```merger rm```: \ | ||
Remove a source file from the merger-config file.\ | ||
You can run this command anywhere within your project (after the configuration file). | ||
MergerJS will give you all your files within your configuration file and you remove one just by selecting it. | ||
- ```merger``` or ```merger build```: <br/> | ||
- ```merger``` or ```merger build```: \ | ||
Execute the build with the configuration you gave it on the merger-config.json file.<br> | ||
You can run it anywhere within your project's folder. | ||
- ```merger auto```, ```merger build -a``` or ```merger build --auto```: <br/> | ||
- ```merger auto```, ```merger build -a``` or ```merger build --auto```: \ | ||
Execute an automatic build session. You can do this, for example, when you have auto builds turned off and | ||
@@ -214,3 +217,3 @@ you don't want to change that. | ||
- ```merger set <configuration> <value>```: <br/> | ||
- ```merger set <configuration> <value>```: \ | ||
Edit a configuration key on the merger-config file. You can run it anywhere within your project's folder. <br> | ||
@@ -222,3 +225,3 @@ At the moment you can pass: | ||
- The \<configuration\> ```updateonlaunch``` or ```updtonlnch``` and the \<value\> ```-t``` / ```--true``` or ```-f``` / ```--false``` to set the update on lauch time to true or false (on/off). | ||
MergerJS will check for updates once per week. <br/> | ||
MergerJS will check for updates once per week. \ | ||
Examples: | ||
@@ -231,3 +234,3 @@ - ```merger set minify -f``` | ||
- ` merger fix-config-paths `: Fixes the paths of the configuration file, in case the location of the project changes (e.g.: different computer).<br/> | ||
- ` merger fix-config-paths `: Fixes the paths of the configuration file, in case the location of the project changes (e.g.: different computer).\ | ||
At this moment, this command only works on Windows. | ||
@@ -234,0 +237,0 @@ |
@@ -1,2 +0,2 @@ | ||
## MergerJS JavaScript Style Guide | ||
## MergerJS JavaScript Style Guide | ||
@@ -8,12 +8,15 @@ | ||
All files **must** start with the **MergerJS** copyright information as a comment, | ||
with the exception of the ***merger.js*** file which must start with | ||
`#!/usr/bin/env node` before the copyrigth information. | ||
with the exception of the ***merger.js*** file which must start with the shebang `#!/usr/bin/env node` before the copyright information.\ | ||
The license headers **must** be followed by `'use strict'`; | ||
### Naming: | ||
### Naming | ||
Filenames must be [`camelCase`](https://en.wikipedia.org/wiki/Camel_case). | ||
### Encoding: | ||
### Encoding | ||
[UTF-8](https://en.wikipedia.org/wiki/UTF-8) | ||
### Whitespace: | ||
### Whitespace | ||
- Use **spaces**, not tabs. | ||
@@ -27,6 +30,8 @@ - Lines ([line breaks](https://en.wikipedia.org/wiki/Newline)) should end in `LF` characters (UNIX) | ||
## Identation: | ||
## Identation | ||
Use two (2) spaces. | ||
## Semicollons: | ||
## Semicollons | ||
All expresions **must** end with a semicollon. | ||
@@ -44,20 +49,26 @@ | ||
### Variables and Contants: | ||
### Variables and Constants | ||
- `const` | ||
Constant names **must** have the `PASCAL_ALL_CAPS` style. | ||
In case their are constant variables from function call values, they *must* have the `camelCase` style. | ||
- `const`\ | ||
Static constant values **must** have the `PASCAL_ALL_CAPS` style.\ | ||
In case they are constant value variables from function calls, they **must** have the `camelCase` style.\ | ||
If you don't expect the value to change, always opt to use `const`. | ||
- `let` | ||
- `let`\ | ||
Variables **must** have the `camelCase` style. | ||
- Variables and constants **should** have JSDoc | ||
- `var`\ | ||
**Never** use `var`. | ||
Variables and constants **should** have JSDoc type definitions | ||
([Official specification](https://jsdoc.app/index.html), | ||
[Wikipedia](https://en.wikipedia.org/wiki/JSDoc)) documentation, when suited, | ||
or if you this it will improve the readability of the code (I.e: type). | ||
[Wikipedia](https://en.wikipedia.org/wiki/JSDoc)) documentation when suited, | ||
or if you think it will improve the readability or development of the code. | ||
### String: | ||
You **should** use single quotes ` const MESSAGE = 'Hello World!'; `. | ||
### String | ||
### Spacing: | ||
You **must** use single quotes ` const MESSAGE = 'Hello World!'; `. | ||
### Spacing | ||
You **must** insert a space after opening and before closing non-empty parenthesis. | ||
@@ -71,4 +82,5 @@ | ||
### Braces: | ||
Braces **must** be used in all controll structures (i.e. if, else, for, do, while, as well as any others), | ||
### Braces | ||
Braces **must** be used in all control structures (i.e. if, else, for, do, while, as well as any others), | ||
even if the body contains only a single statement. | ||
@@ -84,3 +96,4 @@ | ||
### Conditionals: | ||
### Conditionals | ||
The `else` statement **must** be separated by an extra line break. | ||
@@ -99,13 +112,20 @@ | ||
### Classes: | ||
### Classes | ||
- Classes **must** have `PascalCase` as naming style. | ||
- Properties **must** have `camelCase` naming style. | ||
- Private properties (properties that will be used only by that class) | ||
**must** start with four (4) undescores characters in their name | ||
(see example in "Functions"). | ||
- Methods and properties **must** have `camelCase` naming style. | ||
- Private methods and properties (methods and properties that will be used only by that class), | ||
**must** start with four (4) undescores characters in their name. | ||
- Always prefer using classes instead of functions. | ||
- Most classes will be static, so those **must** inherit from `models/staticClassBase.js`. | ||
- Methods **must** have JSDoc | ||
([Official specification](https://jsdoc.app/index.html), [Wikipedia](https://en.wikipedia.org/wiki/JSDoc)) documentation. | ||
### Functions | ||
- Functions **must** have the `camelCase` naming convention. | ||
- If it's a module, try to create a class instead, but, if it makes sense, do use a function. | ||
- Do **NOT** create constructor functions, use well structured classes instead. | ||
- Functions names **must** have the `camelCase` naming convention. | ||
- Private functions (internal functions in a class or module) | ||
**should** start with four (4) undescores characters in their name: | ||
**must** start with four (4) undescores characters in their name: | ||
@@ -112,0 +132,0 @@ `const ____privateFunction = ...` |
@@ -11,4 +11,6 @@ /* | ||
const fs = require( 'fs' ); | ||
const parseImports = require( '../../modules/buildModules/parseImports' ); | ||
const FileParserParams = require( '../../models/fileParserParams' ); | ||
const parseFile = require( '../../modules/buildModules/parseFile' ); | ||
const Utils = require( '../../modules/utils' ); | ||
const DATA_DIR_PATH = path.join( __dirname, path.normalize( '../data' ) ); | ||
@@ -18,5 +20,6 @@ const HEADER_FILES_DIR_PATH = path.join( DATA_DIR_PATH, '/headerFiles' ); | ||
describe( 'ParseImports', () => { | ||
let originalTimeout; | ||
let fileParserParams; | ||
let originalTimeout; | ||
describe( 'parseFile', () => { | ||
@@ -29,61 +32,62 @@ beforeAll( () => { | ||
fileParserParams = new FileParserParams( null ); | ||
} ); | ||
it( 'Should parse file path imports, relative to the header file.', () => { | ||
it( 'Should parse file path imports, relative to the header file.', async () => { | ||
fileParserParams.filePath = path.join( HEADER_FILES_DIR_PATH, 'relativeFilePaths.header.js' ); | ||
const buildOrder = await parseFile( fileParserParams ); | ||
parseImports( path.join( HEADER_FILES_DIR_PATH, 'relativeFilePaths.header.js' ), ( buildOrder ) => { | ||
expect( buildOrder ).not.toBeNull(); | ||
expect( buildOrder ).toBeDefined(); | ||
expect( buildOrder ).toEqual( jasmine.arrayContaining( | ||
[ | ||
'relativeFilePaths.header.js', | ||
path.normalize( '../mockImports.js' ), | ||
path.normalize( '../../tests.js' ), | ||
path.normalize( '../../spec/utils_spec.js' ) | ||
] | ||
) ); | ||
} ); | ||
expect( buildOrder ).not.toBeNull(); | ||
expect( buildOrder ).toBeDefined(); | ||
expect( buildOrder ).toEqual( jasmine.arrayContaining( [ | ||
'relativeFilePaths.header.js', | ||
path.normalize( '../mockImports.js' ), | ||
path.normalize( '../../tests.js' ), | ||
path.normalize( '../../spec/utils_spec.js' ) | ||
] | ||
) ); | ||
} ); | ||
it( 'Should parse relative directories path imports, relative to the header file', () => { | ||
it( 'Should parse relative directories path imports, relative to the header file', async () => { | ||
fileParserParams.filePath = path.join( HEADER_FILES_DIR_PATH, 'relativeDirPaths.header.js' ); | ||
const buildOrder = await parseFile( fileParserParams ); | ||
parseImports( path.join( HEADER_FILES_DIR_PATH, 'relativeDirPaths.header.js' ), ( buildOrder ) => { | ||
expect( buildOrder ).not.toBeNull(); | ||
expect( buildOrder ).toBeDefined(); | ||
expect( buildOrder ).toEqual( jasmine.arrayContaining( | ||
[ | ||
path.normalize( 'relativeDirPaths.header.js' ), | ||
path.normalize( '../node_modules/randomFile1.js' ), | ||
path.normalize( '../node_modules/randomFile2.js' ), | ||
path.normalize( '../node_modules/randomFile3.js' ), | ||
path.normalize( '../node_modules/randomDir1/randomFile1.js' ), | ||
path.normalize( '../node_modules/randomDir1/randomFile2.js' ), | ||
path.normalize( '../node_modules/randomDir1/randomFile3.js' ) | ||
] | ||
) ); | ||
} ); | ||
expect( buildOrder ).not.toBeNull(); | ||
expect( buildOrder ).toBeDefined(); | ||
expect( buildOrder ).toEqual( jasmine.arrayContaining( [ | ||
path.normalize( 'relativeDirPaths.header.js' ), | ||
path.normalize( '../node_modules/randomFile1.js' ), | ||
path.normalize( '../node_modules/randomFile2.js' ), | ||
path.normalize( '../node_modules/randomFile3.js' ), | ||
path.normalize( '../node_modules/randomDir1/randomFile1.js' ), | ||
path.normalize( '../node_modules/randomDir1/randomFile2.js' ), | ||
path.normalize( '../node_modules/randomDir1/randomFile3.js' ) | ||
] | ||
) ); | ||
} ); | ||
it( 'Should parse file paths relative to the node_modules folder.', () => { | ||
it( 'Should parse file paths relative to the node_modules folder.', async () => { | ||
fileParserParams.filePath = path.join( HEADER_FILES_DIR_PATH, 'nodeModulesFilePaths.header.js' ); | ||
const buildOrder = await parseFile( fileParserParams ); | ||
parseImports( path.join( HEADER_FILES_DIR_PATH, 'nodeModulesFilePaths.header.js' ), ( buildOrder ) => { | ||
expect( buildOrder ).not.toBeNull(); | ||
expect( buildOrder ).toBeDefined(); | ||
expect( buildOrder ).toEqual( jasmine.arrayContaining( | ||
[ | ||
'nodeModulesFilePaths.header.js', | ||
path.join( NODE_MODULES_PATH, 'randomFile1.js' ), | ||
path.join( NODE_MODULES_PATH, 'randomFile2.js' ), | ||
path.join( NODE_MODULES_PATH, 'randomDir1/randomFile1.js' ), | ||
path.join( NODE_MODULES_PATH, 'randomFile3.js' ) | ||
] | ||
) ); | ||
expect( buildOrder ).not.toBeNull(); | ||
expect( buildOrder ).toBeDefined(); | ||
expect( buildOrder[3] ).toEqual( path.join( NODE_MODULES_PATH, 'randomDir1/randomFile1.js' ) ); | ||
} ); | ||
expect( buildOrder ).toEqual( jasmine.arrayContaining( [ | ||
'nodeModulesFilePaths.header.js', | ||
path.join( NODE_MODULES_PATH, 'randomFile1.js' ), | ||
path.join( NODE_MODULES_PATH, 'randomFile2.js' ), | ||
path.join( NODE_MODULES_PATH, 'randomDir1/randomFile1.js' ), | ||
path.join( NODE_MODULES_PATH, 'randomFile3.js' ) | ||
] | ||
) ); | ||
expect( buildOrder[3] ).toEqual( path.join( NODE_MODULES_PATH, 'randomDir1/randomFile1.js' ) ); | ||
} ); | ||
it( 'Should parse a URL file import, download the file and cache it in the node_modules folder.', async () => { | ||
it( 'Should parse an URL file import, download the file and cache it in the node_modules folder.', async () => { | ||
const filePath = path.join( NODE_MODULES_PATH, 'jquery.min.js' ); | ||
await __parseImportsUrlsTest( 'specificUrlPaths.header.js', [filePath] ); | ||
await __parseFileUrlsTest( 'specificUrlPaths.header.js', [filePath] ); | ||
await Utils.deleteFile( filePath ); | ||
@@ -93,3 +97,3 @@ } ); | ||
it( 'Should parse a GitHub file path, download it and cache it into the node_modules folder.', async () => { | ||
await ____removeBootsrapFolder( await __parseImportsUrlsTest( | ||
await ____removeBootsrapFolder( await __parseFileUrlsTest( | ||
'githubFilePath.header.js', | ||
@@ -106,4 +110,3 @@ [path.join( NODE_MODULES_PATH, 'twbs@bootstrap/dist/js/bootstrap.min.js' )] | ||
await __parseImportsUrlsTest( headerFilePath, | ||
[ | ||
await __parseFileUrlsTest( headerFilePath, [ | ||
path.join( NODE_MODULES_PATH, 'twbs@bootstrap/dist/js/bootstrap.js' ), | ||
@@ -118,3 +121,4 @@ path.join( NODE_MODULES_PATH, 'twbs@bootstrap/dist/js/bootstrap.min.js' ), | ||
const buildOrder = await parseImports( path.join( HEADER_FILES_DIR_PATH, headerFilePath ) ); | ||
fileParserParams.filePath = path.join( HEADER_FILES_DIR_PATH, headerFilePath ); | ||
const buildOrder = await parseFile( fileParserParams ); | ||
@@ -125,3 +129,3 @@ const stats = await Utils.fsStat( buildOrder[1] ); | ||
expect( stats.mtimeMs ).toEqual( stats.ctimeMs ); | ||
const allFileNames = await Utils.readDir( cacheFolderPath ); | ||
@@ -131,3 +135,3 @@ allFileNames.forEach( ( item, i ) => { | ||
} ); | ||
await ____removeBootsrapFolder( allFileNames ); | ||
@@ -147,68 +151,67 @@ } | ||
* Checks if the files exists to confirm if it was successfull. | ||
* | ||
* | ||
* @param { string } headerFile The header file path, with all the imports. | ||
* @param { string[] } downloadedFilePaths The path location where the downloaded file should be. | ||
* | ||
* | ||
* @return { Promise<string[] | Error> } | ||
*/ | ||
const __parseImportsUrlsTest = ( headerFile, downloadedFilePaths ) => { | ||
return new Promise( ( _resolve, _reject ) => { | ||
const __parseFileUrlsTest = ( headerFile, downloadedFilePaths ) => { | ||
return new Promise( async ( _resolve, _reject ) => { | ||
parseImports( path.join( HEADER_FILES_DIR_PATH, headerFile ), async ( buildOrder ) => { | ||
const expectedOutput = [headerFile].concat( downloadedFilePaths ); | ||
expect( buildOrder ).not.toBeNull(); | ||
expect( buildOrder ).toBeDefined(); | ||
expect( buildOrder ).toEqual( jasmine.arrayContaining( expectedOutput ) ); | ||
fileParserParams.filePath = path.join( HEADER_FILES_DIR_PATH, headerFile ); | ||
const buildOrder = await parseFile( fileParserParams ); | ||
const expectedOutput = [headerFile].concat( downloadedFilePaths ); | ||
expect( buildOrder ).not.toBeNull(); | ||
expect( buildOrder ).toBeDefined(); | ||
expect( buildOrder ).toEqual( jasmine.arrayContaining( expectedOutput ) ); | ||
let downloadSuccessful = false; | ||
let downloadFileError = null; | ||
let currentLink = ''; | ||
let downloadSuccessful = false; | ||
let downloadFileError = null; | ||
let currentLink = ''; | ||
try { | ||
for ( let i = 0; i < downloadedFilePaths.length; ++i ) { | ||
currentLink = downloadedFilePaths[i]; | ||
downloadSuccessful = await Utils.fileExists( downloadedFilePaths[i] ); | ||
try { | ||
for ( let i = 0; i < downloadedFilePaths.length; ++i ) { | ||
currentLink = downloadedFilePaths[i]; | ||
downloadSuccessful = await Utils.fileExists( downloadedFilePaths[i] ); | ||
if ( !downloadSuccessful ) { | ||
break; | ||
} | ||
if ( !downloadSuccessful ) { | ||
break; | ||
} | ||
} catch ( e ) { | ||
downloadSuccessful = false; | ||
downloadFileError = e; | ||
} | ||
expect( downloadSuccessful ).toEqual( true, `ParseImports > URL file import > URL: ${currentLink} ; Download file : FAILED, Error:\n ${downloadFileError}` ); | ||
} catch ( e ) { | ||
downloadSuccessful = false; | ||
downloadFileError = e; | ||
} | ||
if ( downloadSuccessful ) { | ||
expect( downloadSuccessful ).toEqual( true, `parseFile > URL file import > URL: ${currentLink} ; Download file : FAILED, Error:\n ${downloadFileError}` ); | ||
const ____validateFileAsync = ( downloadedFilePath ) => { | ||
return new Promise( ( _res, _rej ) => { | ||
if ( downloadSuccessful ) { | ||
fs.readFile( downloadedFilePath, 'utf8', ( err, data ) => { | ||
if ( err ) | ||
return _rej( err ); | ||
const ____validateFileAsync = ( downloadedFilePath ) => { | ||
return new Promise( ( _res, _rej ) => { | ||
expect( data ).not.toBeNull(); | ||
expect( data ).toBeDefined(); | ||
expect( data ).not.toEqual( '404: Not Found\n' ); | ||
expect( data.length ).toBeGreaterThan( 50 ); | ||
fs.readFile( downloadedFilePath, 'utf8', ( err, data ) => { | ||
if ( err ) | ||
return _rej( err ); | ||
return _res(); | ||
} ); | ||
expect( data ).not.toBeNull(); | ||
expect( data ).toBeDefined(); | ||
expect( data ).not.toEqual( '404: Not Found\n' ); | ||
expect( data.length ).toBeGreaterThan( 50 ); | ||
return _res(); | ||
} ); | ||
}; | ||
for ( let i = 0; i < downloadedFilePaths.length; ++i ) { | ||
await ____validateFileAsync( downloadedFilePaths[i] ); | ||
} | ||
} ); | ||
}; | ||
return _resolve( downloadedFilePaths ); | ||
for ( let i = 0; i < downloadedFilePaths.length; ++i ) { | ||
await ____validateFileAsync( downloadedFilePaths[i] ); | ||
} | ||
return _reject( downloadFileError ); | ||
} ); | ||
return _resolve( downloadedFilePaths ); | ||
} | ||
return _reject( downloadFileError ); | ||
} ); | ||
@@ -230,3 +233,3 @@ }; | ||
if ( err || errr || errrr ) { | ||
console.error( 'ParseImports > URL file import > (delete downloaded file) : FAILED, Error:' ); | ||
console.error( 'parseFile > URL file import > (delete downloaded file) : FAILED, Error:' ); | ||
console.error( err || errr || errrr ); | ||
@@ -233,0 +236,0 @@ return _rej( err || errr || errrr ); |
# Current Branch Version | ||
**v3.10.2** | ||
**v3.10.3** |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Minified code
QualityThis package contains minified code. This may be harmless in some cases where minified code is included in packaged libraries, however packages on npm should not minify code.
Found 1 instance in 1 package
9
67
0
299
180113
2671
- Removedneo-async@^2.5.1
- Removedneo-async@2.6.2(transitive)