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

Commit

Permalink
Patch v3.8.5
Browse files Browse the repository at this point in the history
Merge pull request #121 from joao-neves95/next
  • Loading branch information
joao-neves95 authored Oct 21, 2019
2 parents d67ee47 + ca984a6 commit 7ea6aba
Show file tree
Hide file tree
Showing 25 changed files with 978 additions and 580 deletions.
535 changes: 267 additions & 268 deletions .gitignore

Large diffs are not rendered by default.

10 changes: 9 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,15 @@

 

#### *v3.8.4 - 07/10/2019
#### *v3.8.5 - 21/10/2019

- Refactored the import parser and made multiple optimisations.
- Updated dependencies.
- Added more testing.

 

#### v3.8.4 - 07/10/2019

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

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.4**
**v3.8.5**
18 changes: 18 additions & 0 deletions enums/importType.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
/*
* 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".
*
*/


const ImportType = Object.freeze( {
Unknown: -1,
RelativePath: 1,
NodeModules: 2,
SpecificURL: 3,
GitHub: 4
} );

module.exports = ImportType;
10 changes: 9 additions & 1 deletion enums/promptResponseType.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,12 @@
const promptResponseType = Object.freeze( {
/*
* 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".
*
*/

const promptResponseType = Object.freeze( {
Afirmative: 'Yes',
Negative: 'No'
} );
Expand Down
47 changes: 31 additions & 16 deletions enums/tokenType.js
Original file line number Diff line number Diff line change
@@ -1,25 +1,40 @@
const StaticClass = require( '../models/staticClassBase' );
/*
* 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".
*
*/

const StaticClass = require( '../models/staticClassBase' );

class TokenType extends StaticClass {
constructor() {
super( 'TokenType' );
}

static get token_push() { return '<<' }
static get token_DIR() { return `${TokenType.token_push}DIR` }
static get token_DIRECTORY() { return `${TokenType.token_push}DIRECTORY` }
static get token_dir() { return `${TokenType.token_push}dir` }
static get token_directory() { return `${TokenType.token_push}directory` }
static get token_GH() { return `${TokenType.token_push}GH` }
static get token_gh() { return `${TokenType.token_push}gh` }
static get token_github() { return `${TokenType.token_push}github` }
static get token_GITHUB() { return `${TokenType.token_push}GITHUB` }
static get token_importPath_simbol() { return "@" }
static get token_importPath() { return `${TokenType.token_importPath_simbol}import` }
static get token_importNodeModules_simbol() { return "$" }
static get token_importNodeModules() { return `${TokenType.token_importNodeModules_simbol}import` }
static get token_importUrl_simbol() { return "%" }
static get token_importUrl() { return `${TokenType.token_importUrl_simbol}import` }
static get importPath_simbol() { return '@'; }
static get importPath() { return `${TokenType.importPath_simbol}import`; }

static get importNodeModules_simbol() { return '$'; }
static get importNodeModules() { return `${TokenType.importNodeModules_simbol}import`; }

static get importUrl_simbol() { return '%'; }
static get doubleImportUrl_simbol() { return TokenType.importUrl_simbol + TokenType.importUrl_simbol; }
static get importUrl() { return `${TokenType.importUrl_simbol}import`; }

static get push_symbol() { return '<<'; }

static get push_DIR() { return `${TokenType.push_symbol}DIR`; }
static get push_DIRECTORY() { return `${TokenType.push_symbol}DIRECTORY`; }
static get push_dir() { return `${TokenType.push_symbol}dir`; }
static get push_directory() { return `${TokenType.push_symbol}directory`; }

static get push_GH() { return `${TokenType.push_symbol}GH`; }
static get push_gh() { return `${TokenType.push_symbol}gh`; }
static get push_github() { return `${TokenType.push_symbol}github`; }
static get push_GITHUB() { return `${TokenType.push_symbol}GITHUB`; }

}

module.exports = Object.freeze( TokenType );
8 changes: 8 additions & 0 deletions merger-js.sln.licenseheader
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
extensions: .js
/*
* 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".
*
*/
18 changes: 18 additions & 0 deletions models/configKeysEnum.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
/*
* 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".
*
*/

const configKeys = Object.freeze( {
minify: 'uglify',
autoBuild: 'autoBuild',
notifs: 'notifications',
updateOnLaunch: 'updateOnLaunch',
lastUpdateCheck: 'lastUpdateCheck',
nodeModulesPath: 'nodeModulesPath'
} );

module.exports = configKeys;
57 changes: 57 additions & 0 deletions models/parsedLineModel.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
/*
* 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".
*
*/

const ImportType = require( '../enums/importType' );

class ParsedLine {

constructor() {
/**
* @type { boolean }
*/
this.isComment = null;

/**
* @type { boolean }
*/
this.isDir = false;

/** ImportType enum
* @type { number } ImportType enum
*/
this.importType = ImportType.Unknown;

/**
* @type { boolean }
*/
this.forceInstall = false;

/**
* @type { string | null }
*/
this.path = null;

/**
* @type { string | null }
*/
this.directory = null;

/**
* @type { string | null }
*/
this.branchName = null;

/**
* @type { boolean | null }
**/
this.isGithubNewSyntax = null;
}

}

module.exports = ParsedLine;
14 changes: 14 additions & 0 deletions models/promptResponseType.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
/*
* 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".
*
*/

const promptResponseType = Object.freeze( {
Afirmative: 'Yes',
Negative: 'No'
} );

module.exports = promptResponseType;
10 changes: 9 additions & 1 deletion models/staticClassBase.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,12 @@
module.exports = class StaticClass {
/*
* 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".
*
*/

module.exports = class StaticClass {
/**
* Throws an Error when instantiated.
*
Expand Down
134 changes: 134 additions & 0 deletions modules/buildModules/importLineParser.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,134 @@
/*
* 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".
*
*/

const Utils = require( '../utils' );
const TokenType = require( '../../enums/tokenType' );
const ImportType = require( '../../enums/importType' );
const ParsedLine = require( '../../models/parsedLineModel' );

class ImportLineParser {

constructor() {
throw new Error( 'Can not intantiate a static class' );
}

/**
*
* @param { string } line
*
* @return { ParsedLine }
*/
static parse( line ) {
const parsedLine = new ParsedLine();
parsedLine.isComment = line.trimStart().startsWith( '//' );

line = line.replace( /\s/g, '' );

if ( !parsedLine.isComment ) {
return parsedLine;
}

// #region IMPORT FROM RELATIVE PATH OR DIRECTORY

if ( line.startsWith( TokenType.importPath, 2 ) || line.startsWith( TokenType.importPath_simbol, 2 ) ) {
parsedLine.importType = ImportType.RelativePath;
line = Utils.removeImportFromInput( line );

// #endregion IMPORT FROM RELATIVE PATH OR DIRECTORY

// #region IMPORT FROM node_modules

} else if ( line.startsWith( TokenType.importNodeModules, 2 ) || line.startsWith( TokenType.importNodeModules_simbol, 2 ) ) {
parsedLine.importType = ImportType.NodeModules;
line = Utils.removeImportFromInput( line );

// #endregion IMPORT FROM node_modules

// #region IMPORT FROM AN URL

} else if ( line.startsWith( TokenType.importUrl, 2 ) || line.startsWith( TokenType.importUrl_simbol, 2 ) || line.startsWith( TokenType.doubleImportUrl_simbol, 2 ) ) {
parsedLine.forceInstall = line.startsWith( TokenType.doubleImportUrl_simbol, 2 );
line = Utils.removeImportFromInput( line );

// #region GITHUB SYNTAX DEFENITION COMMENTS

// SINTAX:
// // %import<<GH::{branch} '{user}/{repo}/{pathToFile}.js'
// // %import<<GH::{branch}<<DIR '{user}/{repo}/{pathToFile}.js'
// // %import<<GH::master<<DIR '{user}/{repo}/{pathToFile}.js'
// DEPRECATED SYNTAX: // %import<<GH '{user}/{repo}/{branch}/{pathToFile}.js'

// #endregion GITHUB SYNTAX DEFENITION COMMENTS

// #region IMPORT FROM GITHUB

if ( line.startsWith( TokenType.push_gh ) ||
line.startsWith( TokenType.push_GH ) ||
line.startsWith( TokenType.push_github ) ||
line.startsWith( TokenType.push_GITHUB )
) {
parsedLine.importType = ImportType.GitHub;
parsedLine.branchName = 'master';

line = Utils.removeGithubTokenFromImport( line );

if ( line.startsWith( '::' ) ) {
parsedLine.branchName = '';
line = line.replace( /::/g, '' );

for ( let i = 0; i < line.length; ++i ) {
if ( line[i] === '<' || line[i] === "'" || line[i] === ' ' )
break;

parsedLine.branchName += line[i];
}

parsedLine.isGithubNewSyntax = true;
line = line.substring( parsedLine.branchName.length );

} else {
parsedLine.isGithubNewSyntax = false;
}


// #endregion IMPORT FROM GITHUB

// #region IMPORT FROM A SPECIFIC URL

} else {
parsedLine.importType = ImportType.SpecificURL;
}

// #endregion IMPORT FROM A SPECIFIC URL

// #endregion IMPORT FROM AN URL

} else {
parsedLine.importType = ImportType.Unknown;
}

parsedLine.isDir = ImportLineParser.__pathIsDir( line );

if ( parsedLine.isDir ) {
line = Utils.removeDirTokenFromImport( line );
}

parsedLine.path = Utils.cleanImportFileInput( line );
return parsedLine;
}

static __pathIsDir( line ) {
return line.startsWith( TokenType.push_dir ) ||
line.startsWith( TokenType.push_DIR ) ||
line.startsWith( TokenType.push_directory ) ||
line.startsWith( TokenType.push_DIRECTORY );
}

}

module.exports = ImportLineParser;
Loading

0 comments on commit 7ea6aba

Please sign in to comment.