From bccbbdd2611366f1f91847847c366b47480db74b Mon Sep 17 00:00:00 2001 From: pusher Date: Thu, 10 May 2018 07:22:09 -0300 Subject: [PATCH 1/3] refactor possibilities --- README.md | 2 ++ docs/img/tool2.jpg | Bin 0 -> 4586 bytes lib/builders.js | 32 ++++++++++++++++++++++++++------ lib/command.js | 12 ++---------- lib/i18n.js | 27 ++++++++++++++------------- lib/node.js | 2 +- lib/validators.js | 7 +++++-- test/builders.spec.js | 32 +++++++++++++++++++++++++++++++- test/validators.spec.js | 29 +++++++++++++++-------------- 9 files changed, 96 insertions(+), 47 deletions(-) create mode 100644 docs/img/tool2.jpg diff --git a/README.md b/README.md index bda43d3..4bdc618 100644 --- a/README.md +++ b/README.md @@ -149,6 +149,8 @@ Este comando (`e`) es un CLI que se ejecuta en el contexto donde es ejecutado, o A.k.a: `executor.json` +![](docs/img/tool2.jpg) + Toda la magia se configura desde este archivo. Como mencione antes **no es necesario un proyecto "node"**, esta tool sirve para cualquier tipo de proyecto en el que quieras tener atajos de comandos. ## Json structure diff --git a/docs/img/tool2.jpg b/docs/img/tool2.jpg new file mode 100644 index 0000000000000000000000000000000000000000..4a59e8996b6abf54c11950678343514cf280e4ff GIT binary patch literal 4586 zcmai12{@E%`+pf*5{)FKG-nWr8H2%0CXE?eS)yzaF~-`=Ff+^`)Tyjd6pCXh9N8+A zeM$DEWY3nu*s^s>$THvPROkG!>$|@HeO>Q!JPfWf-@bx;0Ty9 z9MIBcdN~q2iFAk)(bb)dfi70mKq2nV7^oG}SlQSMM|5*H@TU^b`kS01_5dR4=@OZSW@4brsLn2EbG+UUUz`yJ`eRcJ z1_Q=Wg;A)ka0Cj4f-9@QRaBHX2ql^yneNC`BGaUQTEG)&1gg6i-JL>)Y+H16qWI7; zP!7|-w?OhTHvVP!zebBh+TPc9G>vXf{D;PWMbpmtc@g2}L>k41N+5FJ(m$0svHRbS zwt*ZrXgr1BLn4ythIkB=GXryWcSfrqkji*K|3_E%f9j%fRH7rDLOn;JT>6>4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I6+R@wKN zTp4w@*a{`SFG0Lt=+Kx` { */ const buildShortcutCommand = (shortcuts, shortcut) => { shortcut = shortcut.split(' '); - let log = messages.shortcut.notFoundFirstShortcut, + let log = messages.shortcut.notFoundFirstShortcut.toTemplate({shortcut}) + buildShortcutPossibilities(shortcuts), command = _buildShortcutRecursive(shortcuts, shortcut, log); // this add final arguments to the command line @@ -116,6 +116,28 @@ const buildShortcutCommand = (shortcuts, shortcut) => { return command; }; +/** + * This build the possibilities to use for output to user + * + * @param shortcuts + * @returns {string} + */ +const buildShortcutPossibilities = (shortcuts) => { + let r = ''; + + if (shortcuts) { + let shortcutsMap = Object.keys(shortcuts).map(item => { + return `"${item}"`; + }); + + if (shortcutsMap.length > 0) { + r = messages.shortcut.withoutArgumentsPossibleValues.toTemplate({ shortcuts: shortcutsMap.join(', ') }); + } + } + + return r; +}; + /** * The recursive method to chain the shortcut with its templates * @@ -135,11 +157,8 @@ const _buildShortcutRecursive = (shortcuts, shortcut, log) => { let log = messages.shortcut.notFound.toTemplate({ key }); - log += Object.keys(found).map(v => { - return ` "${v}"`; - }).join(','); - return _buildShortcutRecursive(found, shortcut, log); + return _buildShortcutRecursive(found, shortcut, log + buildShortcutPossibilities(found)); } return found; @@ -149,5 +168,6 @@ const _buildShortcutRecursive = (shortcuts, shortcut, log) => { module.exports = { buildConfig, buildInterpolateVariables, - buildShortcutCommand + buildShortcutCommand, + buildShortcutPossibilities }; diff --git a/lib/command.js b/lib/command.js index 0b6e0ee..4d7f54b 100644 --- a/lib/command.js +++ b/lib/command.js @@ -1,6 +1,6 @@ const { validateAndBuildEnvironments, validateShortcut, validateShortcuts, validateTemplates, validateConfig } = require('./validators'); const { isTestRunning, setColors } = require('./utils'); -const { buildInterpolateVariables, buildShortcutCommand, buildConfig } = require('./builders'); +const { buildInterpolateVariables, buildShortcutCommand, buildConfig, buildShortcutPossibilities } = require('./builders'); const { getConfigFromCWD } = require('./node'); const { configDefault } = require('./defaults'); const { messages } = require('./i18n'); @@ -32,20 +32,12 @@ let buildCommandWithConfig = (shortcut, config) => { setColors(config.config); // validation tasks - let shortcutValid = validateShortcut(shortcut); + validateShortcut(shortcut, buildShortcutPossibilities(config.shortcuts)); validateConfig(config.config); config.environmentsRendered = validateAndBuildEnvironments(config.environments); validateTemplates(config.templates); validateShortcuts(config.shortcuts); - if(!shortcutValid) { - let shortcuts = Object.keys(config.shortcuts).map(item => { - return `"${item}"`; - }).join(', '); - - throw new Error(messages.shortcut.withoutArguments.toTemplate({shortcuts})); - } - // building tasks config.shortcutsRendered = buildInterpolateVariables(config); diff --git a/lib/i18n.js b/lib/i18n.js index f880fbe..d563ec4 100644 --- a/lib/i18n.js +++ b/lib/i18n.js @@ -15,28 +15,29 @@ const messages = { } }, environments: { - invalidFormat: '[environments] The attribute "environments" should be an array with strings or simple object {key: value}' + invalidFormat: 'The attribute "environments" should be an array with strings or simple object {key: value}' }, config: { notFound: '"${fileName}" not found on this folder. Have you read the docs? Don\'t be lazy https://github.com/crystian/executor', - used: '[config] Config file used: "${configFileName}"', - invalidFormat: '[config] An invalid structure on config attribute', - invalidJson: '[config] Invalid json format on your configuration file: ${jsonFile}', - isNotAString: '[config] An invalid type on configuration file: "configFile" should be a string' + used: 'Config file used: "${configFileName}"', + invalidFormat: 'An invalid structure on config attribute', + invalidJson: 'Invalid json format on your configuration file: ${jsonFile}', + isNotAString: 'An invalid type on configuration file: "configFile" should be a string' }, templates: { - notFound: '[template] Key "${template}" not found (remember the order is important!)', - invalidData: '[template] The configurations of templates are invalid, should be an object or string', - invalidFormat: '[template] Invalid format, remember should be a pair key value (both should be strings): "${key}": "${value}"' + notFound: 'Key "${template}" not found (remember the order is important!)', + invalidData: 'The configurations of templates are invalid, should be an object or string', + invalidFormat: 'Invalid format, remember should be a pair key value (both should be strings): "${key}": "${value}"' }, shortcuts: { - notFound: '[shortcuts] The attribute "shortcuts" should exist and should be an object no empty.', - shouldBeAnObject: '[shortcuts] The attribute "shortcuts" should be an object, and the last attribute on it should be a string.' + notFound: 'The attribute "shortcuts" should exist and should be an object no empty.', + shouldBeAnObject: 'The attribute "shortcuts" should be an object, and the last attribute on it should be a string.' }, shortcut: { - withoutArguments: '[argument] coff coff ... and the "shortcut"?\nPossible shortcuts configured: ${shortcuts}', - notFoundFirstShortcut: '[argument] The "shortcut" does not found, check your spelling or your configuration file', - notFound: '[argument] The sub-arguments from "${key}" does not match with your configuration file, for your key you have the following arguments: ' + withoutArguments: 'coff coff ... and the "shortcut"?', + withoutArgumentsPossibleValues: '\n\nShortcuts configured: ${shortcuts}', + notFoundFirstShortcut: 'The shortcut: "${shortcut}" not found', + notFound: 'The sub-arguments from "${key}" does not match with your configuration file.' } }; diff --git a/lib/node.js b/lib/node.js index 322e4d1..14d5c77 100644 --- a/lib/node.js +++ b/lib/node.js @@ -52,7 +52,7 @@ let getConfigFileName = (filePath) => { /* istanbul ignore if */ if (!isTestRunning()) { // it is ok, I can use "console.primary" because I don't have the configuration to finish with this - console.log('\x1b[37m%s\x1b[0m', `\n[${messages.app.name}]`, messages.config.used.toTemplate({configFileName})); + console.log('\x1b[37m%s\x1b[0m', `[${messages.app.name}]`, messages.config.used.toTemplate({configFileName})); } } diff --git a/lib/validators.js b/lib/validators.js index 18e53f9..8139cd4 100644 --- a/lib/validators.js +++ b/lib/validators.js @@ -5,9 +5,12 @@ const { messages } = require('./i18n'); * validate the input from the cli * * @param shortcut is the input from the user + * @param possibilities a string with possibilities to concatenate */ -const validateShortcut = (shortcut) => { - return !!(shortcut && shortcut !== '' && isString(shortcut)); +const validateShortcut = (shortcut, possibilities) => { + if (!(shortcut && shortcut !== '' && isString(shortcut))) { + throw new Error(messages.shortcut.withoutArguments + possibilities); + } }; diff --git a/test/builders.spec.js b/test/builders.spec.js index 98448c3..b0020ec 100644 --- a/test/builders.spec.js +++ b/test/builders.spec.js @@ -1,5 +1,5 @@ const { assert } = require('chai'); -const { buildConfig, buildInterpolateVariables, buildShortcutCommand } = require('../lib/builders'); +const { buildConfig, buildInterpolateVariables, buildShortcutCommand, buildShortcutPossibilities } = require('../lib/builders'); describe('buildConfig() results', function() { @@ -408,3 +408,33 @@ describe('buildShortcutCommand() results', function() { assert.sameMembers(r, ['branchBBAs']); }); }); + + +describe('buildShortcutPosibilities() results', function() { + it('should return a string without possibilities', ()=>{ + let r = buildShortcutPossibilities(); + assert.equal(r, ''); + }); + it('should return a string without possibilities', ()=>{ + let r = buildShortcutPossibilities({}); + assert.equal(r, ''); + }); + it('should return a string without possibilities', ()=>{ + let r = buildShortcutPossibilities(1); + assert.equal(r, ''); + }); + it('should return a string without possibilities', ()=>{ + let r = buildShortcutPossibilities([]); + assert.equal(r, ''); + }); + + it('should return a string with a possibility', ()=>{ + let r = buildShortcutPossibilities({key1: 'key1'}); + assert.include(r, '"key1"'); + }); + it('should return a string with two possibility', ()=>{ + let r = buildShortcutPossibilities({key1: 'key1', key2: 'key2'}); + assert.include(r, '"key1"'); + assert.include(r, '"key2"'); + }); +}); diff --git a/test/validators.spec.js b/test/validators.spec.js index 8c5bc5f..c60f883 100644 --- a/test/validators.spec.js +++ b/test/validators.spec.js @@ -3,26 +3,27 @@ const { validateAndBuildEnvironments, validateConfig, validateTemplates, validat describe('validateShortcut() throws', function() { + // throws - // does not throw - it('should return a false value by empty arguments', function() { - assert.doesNotThrow(() => { - let r = validateShortcut(); - assert.equal(r, false); + it('should throw an error by empty arguments', function() { + assert.throw(() => { + validateShortcut(); }); - assert.doesNotThrow(() => { - let r = validateShortcut({}); - assert.equal(r, false); + }); + it('should throw an error by invalid arguments', function() { + assert.throw(() => { + validateShortcut({}); }); - assert.doesNotThrow(() => { - let r = validateShortcut(''); - assert.equal(r, false); + assert.throw(() => { + validateShortcut(''); }); - assert.doesNotThrow(() => { - let r = validateShortcut([]); - assert.equal(r, false); + assert.throw(() => { + validateShortcut([]); }); }); + + // does not throw + it('should not throw an error: 1 level', function() { assert.doesNotThrow(() => { validateShortcut('branchA'); From 74dfede2fe7be4d04fe2109796603c28f3e4a231 Mon Sep 17 00:00:00 2001 From: pusher Date: Thu, 10 May 2018 07:41:37 -0300 Subject: [PATCH 2/3] interpolate moved from builders --- aexecutor.json | 6 ++ lib/builders.js | 86 --------------- lib/command.js | 5 +- lib/description.js | 18 ++++ lib/interpolate.js | 94 ++++++++++++++++ package.json | 4 +- test/builders.spec.js | 228 +-------------------------------------- test/description.spec.js | 24 +++++ test/interpolate.spec.js | 227 ++++++++++++++++++++++++++++++++++++++ yarn.lock | 186 ++------------------------------ 10 files changed, 386 insertions(+), 492 deletions(-) create mode 100644 aexecutor.json create mode 100644 lib/description.js create mode 100644 lib/interpolate.js create mode 100644 test/description.spec.js create mode 100644 test/interpolate.spec.js diff --git a/aexecutor.json b/aexecutor.json new file mode 100644 index 0000000..6a071d5 --- /dev/null +++ b/aexecutor.json @@ -0,0 +1,6 @@ +{ + "description": "", + "shortcuts": { + "ls": "ls -lha" + } +} diff --git a/lib/builders.js b/lib/builders.js index c79e664..38dca28 100644 --- a/lib/builders.js +++ b/lib/builders.js @@ -14,91 +14,6 @@ const buildConfig = (configDefault, config) => { }; -/** - * Interpolate all the inputs! - * - * Inputs in order: environment, predefined, template, shortcut - * And it allow to use nested object! (not for environment) - * - * Note: it can be changed to get better performance. - * - * @param config - * @returns {any} - */ -const buildInterpolateVariables = (config) => { - let shortcuts = config.shortcuts, - templates = config.templates || {}, - environments = config.environmentsRendered || [], - newShortcuts, newTemplates, newEnvironments; - - if (!shortcuts) { - throw new Error(messages.shortcuts.notFound); - } - - // copy structure to mutate in the easy way - newShortcuts = JSON.parse(JSON.stringify(shortcuts)); - newTemplates = JSON.parse(JSON.stringify(templates)); - - newEnvironments = _buildInterpolateEnvironmentVars(environments); - - // This is recursive and it is needed to pass on each stage - // to template - _buildInterpolateVariablesRecursive(newTemplates, newEnvironments); - _buildInterpolateVariablesRecursive(newTemplates, { predefined }); - _buildInterpolateVariablesRecursive(newTemplates, newTemplates); // yes to itself! - // to shortcuts - _buildInterpolateVariablesRecursive(newShortcuts, newEnvironments); - _buildInterpolateVariablesRecursive(newShortcuts, { predefined }); - _buildInterpolateVariablesRecursive(newShortcuts, newTemplates); - _buildInterpolateVariablesRecursive(newShortcuts, newShortcuts, true); // yes to itself! - - return newShortcuts; -}; - -/** - * It gets data from the external environment, and prepare it to use. - * - * @param environments - * @private - */ -const _buildInterpolateEnvironmentVars = (environments) => { - let environmentsToReturn = {}; - - environments.forEach(item => { - let key = Object.keys(item)[0]; - environmentsToReturn[key] = process.env[item[key]]; - }); - - return environmentsToReturn; -}; - -/** - * It does the magic recursively to replace the placeholders with values, even itself - * - * @param values are the data and you can use it so simple or you can mix with templates (by placeholders) - * @param templates are the reuse "snippet", you can use it on values and avoid to repeat your code! - * @param finalFlag at the final it will check if there are some placeholders without replaced - * @private - */ -const _buildInterpolateVariablesRecursive = (values, templates, finalFlag) => { - - Object.keys(values).forEach(item => { - - // be careful, it is a mutable object - if (isString(values[item])) { - values[item] = values[item].toTemplate(templates); - - if (finalFlag && values[item].match(/\${.+?}/g)) { - throw new Error(messages.templates.notFound.toTemplate({ template: values[item] })); - } - } else if (isObject(values[item]) && !isObjectEmpty(values[item])) { - _buildInterpolateVariablesRecursive(values[item], templates, finalFlag); - } else { - throw new Error(messages.templates.invalidFormat.toTemplate({ key: item, value: values[item] })); - } - }); -}; - /** * This build the command line joining all pieces recursively * @@ -167,7 +82,6 @@ const _buildShortcutRecursive = (shortcuts, shortcut, log) => { module.exports = { buildConfig, - buildInterpolateVariables, buildShortcutCommand, buildShortcutPossibilities }; diff --git a/lib/command.js b/lib/command.js index 4d7f54b..2f78ccc 100644 --- a/lib/command.js +++ b/lib/command.js @@ -1,7 +1,8 @@ const { validateAndBuildEnvironments, validateShortcut, validateShortcuts, validateTemplates, validateConfig } = require('./validators'); const { isTestRunning, setColors } = require('./utils'); -const { buildInterpolateVariables, buildShortcutCommand, buildConfig, buildShortcutPossibilities } = require('./builders'); +const { buildShortcutCommand, buildConfig, buildShortcutPossibilities } = require('./builders'); const { getConfigFromCWD } = require('./node'); +const { interpolateVariables } = require('./interpolate'); const { configDefault } = require('./defaults'); const { messages } = require('./i18n'); @@ -39,7 +40,7 @@ let buildCommandWithConfig = (shortcut, config) => { validateShortcuts(config.shortcuts); // building tasks - config.shortcutsRendered = buildInterpolateVariables(config); + config.shortcutsRendered = interpolateVariables(config); let command = buildShortcutCommand(config.shortcutsRendered, shortcut).join(' '); diff --git a/lib/description.js b/lib/description.js new file mode 100644 index 0000000..cb5eba1 --- /dev/null +++ b/lib/description.js @@ -0,0 +1,18 @@ +const { validateAndBuildEnvironments, validateShortcut, validateShortcuts, validateTemplates, validateConfig } = require('./validators'); +const { isTestRunning, setColors } = require('./utils'); +const { interpolateVariables, buildShortcutCommand, buildConfig } = require('./builders'); +const { getConfigFromCWD } = require('./node'); +const { configDefault } = require('./defaults'); +const { messages } = require('./i18n'); + + +let buildCommand = (shortcut) => { + return buildCommandWithConfig(shortcut, getConfigFromCWD()); +}; + + + +module.exports = { + buildCommand, + buildCommandWithConfig +}; diff --git a/lib/interpolate.js b/lib/interpolate.js new file mode 100644 index 0000000..51f622e --- /dev/null +++ b/lib/interpolate.js @@ -0,0 +1,94 @@ +const { isObject, isObjectEmpty, isString } = require('./utils'); +const { predefined } = require('./defaults'); +const { messages } = require('./i18n'); + + +/** + * Interpolate all the inputs! + * + * Inputs in order: environment, predefined, template, shortcut + * And it allow to use nested object! (not for environment) + * + * Note: it can be changed to get better performance. + * + * @param config + * @returns {any} + */ +const interpolateVariables = (config) => { + let shortcuts = config.shortcuts, + templates = config.templates || {}, + environments = config.environmentsRendered || [], + newShortcuts, newTemplates, newEnvironments; + + if (!shortcuts) { + throw new Error(messages.shortcuts.notFound); + } + + // copy structure to mutate in the easy way + newShortcuts = JSON.parse(JSON.stringify(shortcuts)); + newTemplates = JSON.parse(JSON.stringify(templates)); + + newEnvironments = _buildInterpolateEnvironmentVars(environments); + + // This is recursive and it is needed to pass on each stage + // to template + _buildInterpolateVariablesRecursive(newTemplates, newEnvironments); + _buildInterpolateVariablesRecursive(newTemplates, { predefined }); + _buildInterpolateVariablesRecursive(newTemplates, newTemplates); // yes to itself! + // to shortcuts + _buildInterpolateVariablesRecursive(newShortcuts, newEnvironments); + _buildInterpolateVariablesRecursive(newShortcuts, { predefined }); + _buildInterpolateVariablesRecursive(newShortcuts, newTemplates); + _buildInterpolateVariablesRecursive(newShortcuts, newShortcuts, true); // yes to itself! + + return newShortcuts; +}; + +/** + * It gets data from the external environment, and prepare it to use. + * + * @param environments + * @private + */ +const _buildInterpolateEnvironmentVars = (environments) => { + let environmentsToReturn = {}; + + environments.forEach(item => { + let key = Object.keys(item)[0]; + environmentsToReturn[key] = process.env[item[key]]; + }); + + return environmentsToReturn; +}; + +/** + * It does the magic recursively to replace the placeholders with values, even itself + * + * @param values are the data and you can use it so simple or you can mix with templates (by placeholders) + * @param templates are the reuse "snippet", you can use it on values and avoid to repeat your code! + * @param finalFlag at the final it will check if there are some placeholders without replaced + * @private + */ +const _buildInterpolateVariablesRecursive = (values, templates, finalFlag) => { + + Object.keys(values).forEach(item => { + + // be careful, it is a mutable object + if (isString(values[item])) { + values[item] = values[item].toTemplate(templates); + + if (finalFlag && values[item].match(/\${.+?}/g)) { + throw new Error(messages.templates.notFound.toTemplate({ template: values[item] })); + } + } else if (isObject(values[item]) && !isObjectEmpty(values[item])) { + _buildInterpolateVariablesRecursive(values[item], templates, finalFlag); + } else { + throw new Error(messages.templates.invalidFormat.toTemplate({ key: item, value: values[item] })); + } + }); +}; + + +module.exports = { + interpolateVariables +}; diff --git a/package.json b/package.json index 34ceada..aadd355 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "executor", - "version": "0.0.8-beta", + "version": "0.0.9-beta", "license": "MIT", "description": "A powerful short-cutter to your console for you and your team", "scripts": { @@ -14,7 +14,7 @@ "devDependencies": { "chai": "4.1.2", "mocha": "5.1.1", - "nyc": "11.7.1" + "nyc": "11.7.3" }, "nyc": { "include": [ diff --git a/test/builders.spec.js b/test/builders.spec.js index b0020ec..609a901 100644 --- a/test/builders.spec.js +++ b/test/builders.spec.js @@ -1,5 +1,5 @@ const { assert } = require('chai'); -const { buildConfig, buildInterpolateVariables, buildShortcutCommand, buildShortcutPossibilities } = require('../lib/builders'); +const { buildConfig, buildShortcutCommand, buildShortcutPossibilities } = require('../lib/builders'); describe('buildConfig() results', function() { @@ -58,232 +58,6 @@ describe('buildConfig() results', function() { }); -describe('buildInterpolateVariables() throws', function() { - - // throws - - it('should throw an error by invalid arguments', function() { - assert.throw(() => { - let templates = { key1: [] }; - let shortcuts = templates; - let config = { templates, shortcuts }; - - buildInterpolateVariables(config); - }); - assert.throw(() => { - let templates = { key1: 1 }; - let shortcuts = templates; - let config = { templates, shortcuts }; - - buildInterpolateVariables(config); - }); - assert.throw(() => { - let templates = { key1: null }; - let shortcuts = templates; - let config = { templates, shortcuts }; - - buildInterpolateVariables(config); - }); - assert.throw(() => { - let templates = { key1: {} }; - let shortcuts = templates; - let config = { templates, shortcuts }; - - buildInterpolateVariables(config); - }); - }); - - it('should throw an error by key not found', function() { - assert.throw(() => { - let templates = { key1: 'value1 ${keyNotFound}' }; - let shortcuts = templates; - let config = { templates, shortcuts }; - - buildInterpolateVariables(config); - }); - }); - - it('should throw an error by not shortcuts loaded', function() { - assert.throw(() => { - let templates = { key1: 'value1 ${keyNotFound}' }; - let shortcuts = null; - let config = { templates, shortcuts }; - - buildInterpolateVariables(config); - }); - }); - - // does not throw - - it('should not throw an error by correct arguments', function() { - assert.doesNotThrow(() => { - let templates = { key1: 'value1', key2: 'value2' }; - let shortcuts = templates; - let config = { templates, shortcuts }; - - let r = buildInterpolateVariables(config); - - buildInterpolateVariables(config); - }); - }); -}); - -describe('buildInterpolateVariables() results', function() { - - it('should return a simple string without interpolate: 1 variable, 1 level', function() { - let templates = { template1: 'value1' }; - let shortcuts = { short1: 'short1s' }; - let config = { templates, shortcuts }; - - let r = buildInterpolateVariables(config); - - assert.hasAllKeys(r, ['short1']); - assert.equal(r.short1, 'short1s'); - }); - it('should return a simple string without interpolate: 2 variables, 1 level', function() { - let templates = { key1: 'value1', key2: 'value2' }; - let shortcuts = templates; - let config = { templates, shortcuts }; - - let r = buildInterpolateVariables(config); - - assert.hasAllKeys(r, ['key1', 'key2']); - assert.equal(r.key1, 'value1'); - assert.equal(r.key2, 'value2'); - }); - it('should return a simple string without interpolate: 1 variables, 2 level', function() { - let templates = { branchA: { branchAA: 'branchAAs' } }; - let shortcuts = templates; - let config = { templates, shortcuts }; - - let r = buildInterpolateVariables(config); - - assert.hasAllKeys(r, ['branchA']); - assert.deepNestedPropertyVal(r, 'branchA.branchAA', 'branchAAs'); - }); - - it('should interpolate variables: 1 variable, 1 level', function() { - let templates = { branchA: 'branchAs', branchB: '${branchA} branchBs' }; - let shortcuts = templates; - let config = { templates, shortcuts }; - - let r = buildInterpolateVariables(config); - - assert.equal(config.templates.branchB, '${branchA} branchBs'); - assert.equal(r.branchB, 'branchAs branchBs'); - }); - it('should interpolate variables: 1 variable, 1 level, 2 times', function() { - let templates = { branchA: 'branchAs', branchB: '${branchA} branchBs ${branchA}' }; - let shortcuts = templates; - let config = { templates, shortcuts }; - - let r = buildInterpolateVariables(config); - - assert.equal(config.templates.branchB, '${branchA} branchBs ${branchA}'); - assert.equal(r.branchB, 'branchAs branchBs branchAs'); - }); - it('should interpolate variables: 1 variable, 2 level', function() { - let templates = { branchA: { branchAA: 'branchAAs' }, branchB: { branchBB: '${branchA.branchAA} branchBBs' } }; - let shortcuts = templates; - let config = { templates, shortcuts }; - - let r = buildInterpolateVariables(config); - - assert.equal(templates.branchB.branchBB, '${branchA.branchAA} branchBBs'); - assert.equal(r.branchB.branchBB, 'branchAAs branchBBs'); - }); - - it('should interpolate variables: 1 variable, different sources: 2 level', function() { - let templates = { branchA: { branchAA: 'branchAAs' }, branchB: { branchBB: 'branchBBs' } }; - let shortcuts = { branchC: { branchCC: 'branchCCs' }, branchD: { branchDD: '${branchB.branchBB} branchDDs' } }; - let config = { templates, shortcuts }; - - let r = buildInterpolateVariables(config); - - assert.equal(shortcuts.branchD.branchDD, '${branchB.branchBB} branchDDs'); - assert.equal(r.branchD.branchDD, 'branchBBs branchDDs'); - }); - - it('should interpolate variables: 3 variables, same source: 1 level', function() { - let templates = { key1: 'value1', key2: '${key1} and value2', key3: '${key2} and value3', key4: 'without template' }; - let shortcuts = templates; - let config = { templates, shortcuts }; - - let r = buildInterpolateVariables(config); - - assert.hasAllKeys(r, ['key1', 'key2', 'key3', 'key4']); - assert.equal(r.key1, 'value1'); - assert.equal(r.key2, 'value1 and value2'); - assert.equal(r.key3, 'value1 and value2 and value3'); - assert.equal(r.key4, 'without template'); - }); - - it('should interpolate variables: 2 variables, between template and shortcuts: 1 level', function() { - let templates = { template1: 'value1', template2: '${template1} value2' }; - let shortcuts = { short1: '${template1} and short1s', short2: '${template1} and ${template2} and short1s' }; - let config = { templates, shortcuts }; - - let r = buildInterpolateVariables(config); - - assert.hasAllKeys(r, ['short1', 'short2']); - assert.equal(r.short1, 'value1 and short1s'); - assert.equal(r.short2, 'value1 and value1 value2 and short1s'); - }); - it('should interpolate variables: 2 variables, between template and shortcuts and itself: 1 level', function() { - let templates = { template1: 'value1', template2: 'value2', template3: 'value3' }; - let shortcuts = { short1: '${template1} and short1s', short2: '${template2} and ${template3} and ${short1}' }; - let config = { templates, shortcuts }; - - let r = buildInterpolateVariables(config); - - assert.hasAllKeys(r, ['short1', 'short2']); - assert.equal(r.short1, 'value1 and short1s'); - assert.equal(r.short2, 'value2 and value3 and value1 and short1s'); - }); - - it('should interpolate variables: 1 variable: 4 level', function() { - let templates = { branchA: { branchAA: { branchAAA: { branchAAAA: 'four As' } } } }; - let shortcuts = { short1: '${branchA.branchAA.branchAAA.branchAAAA} found' }; - let config = { templates, shortcuts }; - - let r = buildInterpolateVariables(config); - - assert.hasAllKeys(r, ['short1']); - assert.equal(r.short1, 'four As found'); - }); - it('should interpolate variables: 1 variable, 1 itself: 4 level', function() { - let templates = { branchA: { branchAA: { branchAAA: { branchAAAA: 'four As' } } } }; - let shortcuts = { short1: '${branchA.branchAA.branchAAA.branchAAAA} found', short2: '${short1} from other short' }; - let config = { templates, shortcuts }; - - let r = buildInterpolateVariables(config); - - assert.hasAllKeys(r, ['short1', 'short2']); - assert.equal(r.short1, 'four As found'); - assert.equal(r.short2, 'four As found from other short'); - }); - it('should interpolate variables: complex 1', function() { - let templates = { - branchA: { branchAA: { branchAAA: { branchAAAA: 'four As' } } }, - branchB: { branchBB: { branchBBB: { branchBBBB: 'four Bs and ${branchA.branchAA.branchAAA.branchAAAA}' } } } - }; - let shortcuts = { - short1: '${branchA.branchAA.branchAAA.branchAAAA} found', - short2: '${short1} from other short', - short3: 'from template B ${branchB.branchBB.branchBBB.branchBBBB} and from shortcuts ${short1}' - }; - let config = { templates, shortcuts }; - - let r = buildInterpolateVariables(config); - - assert.hasAllKeys(r, ['short1', 'short2', 'short3']); - assert.equal(r.short1, 'four As found'); - assert.equal(r.short2, 'four As found from other short'); - assert.equal(r.short3, 'from template B four Bs and four As and from shortcuts four As found'); - }); -}); - - describe('buildShortcutCommand() throws', function() { // throws diff --git a/test/description.spec.js b/test/description.spec.js new file mode 100644 index 0000000..baf8471 --- /dev/null +++ b/test/description.spec.js @@ -0,0 +1,24 @@ +const { expect } = require('chai'); +const { assert } = require('chai'); +const { buildCommand, buildCommandWithConfig } = require('../lib/command'); +const path = require('path'); + +describe('setDescription() throws', function() { + + // throws + + it('should throw an error by invalid arguments', function() { + assert.throw(() => { + buildCommand(); + }); + assert.throw(() => { + buildCommand(''); + }); + assert.throw(() => { + buildCommand([]); + }); + assert.throw(() => { + buildCommand({}); + }); + }); +}); diff --git a/test/interpolate.spec.js b/test/interpolate.spec.js new file mode 100644 index 0000000..64e0043 --- /dev/null +++ b/test/interpolate.spec.js @@ -0,0 +1,227 @@ +const { assert } = require('chai'); +const { interpolateVariables } = require('../lib/interpolate'); + +describe('interpolateVariables() throws', function() { + + // throws + + it('should throw an error by invalid arguments', function() { + assert.throw(() => { + let templates = { key1: [] }; + let shortcuts = templates; + let config = { templates, shortcuts }; + + interpolateVariables(config); + }); + assert.throw(() => { + let templates = { key1: 1 }; + let shortcuts = templates; + let config = { templates, shortcuts }; + + interpolateVariables(config); + }); + assert.throw(() => { + let templates = { key1: null }; + let shortcuts = templates; + let config = { templates, shortcuts }; + + interpolateVariables(config); + }); + assert.throw(() => { + let templates = { key1: {} }; + let shortcuts = templates; + let config = { templates, shortcuts }; + + interpolateVariables(config); + }); + }); + + it('should throw an error by key not found', function() { + assert.throw(() => { + let templates = { key1: 'value1 ${keyNotFound}' }; + let shortcuts = templates; + let config = { templates, shortcuts }; + + interpolateVariables(config); + }); + }); + + it('should throw an error by not shortcuts loaded', function() { + assert.throw(() => { + let templates = { key1: 'value1 ${keyNotFound}' }; + let shortcuts = null; + let config = { templates, shortcuts }; + + interpolateVariables(config); + }); + }); + + // does not throw + + it('should not throw an error by correct arguments', function() { + assert.doesNotThrow(() => { + let templates = { key1: 'value1', key2: 'value2' }; + let shortcuts = templates; + let config = { templates, shortcuts }; + + let r = interpolateVariables(config); + + interpolateVariables(config); + }); + }); +}); + +describe('interpolateVariables() results', function() { + + it('should return a simple string without interpolate: 1 variable, 1 level', function() { + let templates = { template1: 'value1' }; + let shortcuts = { short1: 'short1s' }; + let config = { templates, shortcuts }; + + let r = interpolateVariables(config); + + assert.hasAllKeys(r, ['short1']); + assert.equal(r.short1, 'short1s'); + }); + it('should return a simple string without interpolate: 2 variables, 1 level', function() { + let templates = { key1: 'value1', key2: 'value2' }; + let shortcuts = templates; + let config = { templates, shortcuts }; + + let r = interpolateVariables(config); + + assert.hasAllKeys(r, ['key1', 'key2']); + assert.equal(r.key1, 'value1'); + assert.equal(r.key2, 'value2'); + }); + it('should return a simple string without interpolate: 1 variables, 2 level', function() { + let templates = { branchA: { branchAA: 'branchAAs' } }; + let shortcuts = templates; + let config = { templates, shortcuts }; + + let r = interpolateVariables(config); + + assert.hasAllKeys(r, ['branchA']); + assert.deepNestedPropertyVal(r, 'branchA.branchAA', 'branchAAs'); + }); + + it('should interpolate variables: 1 variable, 1 level', function() { + let templates = { branchA: 'branchAs', branchB: '${branchA} branchBs' }; + let shortcuts = templates; + let config = { templates, shortcuts }; + + let r = interpolateVariables(config); + + assert.equal(config.templates.branchB, '${branchA} branchBs'); + assert.equal(r.branchB, 'branchAs branchBs'); + }); + it('should interpolate variables: 1 variable, 1 level, 2 times', function() { + let templates = { branchA: 'branchAs', branchB: '${branchA} branchBs ${branchA}' }; + let shortcuts = templates; + let config = { templates, shortcuts }; + + let r = interpolateVariables(config); + + assert.equal(config.templates.branchB, '${branchA} branchBs ${branchA}'); + assert.equal(r.branchB, 'branchAs branchBs branchAs'); + }); + it('should interpolate variables: 1 variable, 2 level', function() { + let templates = { branchA: { branchAA: 'branchAAs' }, branchB: { branchBB: '${branchA.branchAA} branchBBs' } }; + let shortcuts = templates; + let config = { templates, shortcuts }; + + let r = interpolateVariables(config); + + assert.equal(templates.branchB.branchBB, '${branchA.branchAA} branchBBs'); + assert.equal(r.branchB.branchBB, 'branchAAs branchBBs'); + }); + + it('should interpolate variables: 1 variable, different sources: 2 level', function() { + let templates = { branchA: { branchAA: 'branchAAs' }, branchB: { branchBB: 'branchBBs' } }; + let shortcuts = { branchC: { branchCC: 'branchCCs' }, branchD: { branchDD: '${branchB.branchBB} branchDDs' } }; + let config = { templates, shortcuts }; + + let r = interpolateVariables(config); + + assert.equal(shortcuts.branchD.branchDD, '${branchB.branchBB} branchDDs'); + assert.equal(r.branchD.branchDD, 'branchBBs branchDDs'); + }); + + it('should interpolate variables: 3 variables, same source: 1 level', function() { + let templates = { key1: 'value1', key2: '${key1} and value2', key3: '${key2} and value3', key4: 'without template' }; + let shortcuts = templates; + let config = { templates, shortcuts }; + + let r = interpolateVariables(config); + + assert.hasAllKeys(r, ['key1', 'key2', 'key3', 'key4']); + assert.equal(r.key1, 'value1'); + assert.equal(r.key2, 'value1 and value2'); + assert.equal(r.key3, 'value1 and value2 and value3'); + assert.equal(r.key4, 'without template'); + }); + + it('should interpolate variables: 2 variables, between template and shortcuts: 1 level', function() { + let templates = { template1: 'value1', template2: '${template1} value2' }; + let shortcuts = { short1: '${template1} and short1s', short2: '${template1} and ${template2} and short1s' }; + let config = { templates, shortcuts }; + + let r = interpolateVariables(config); + + assert.hasAllKeys(r, ['short1', 'short2']); + assert.equal(r.short1, 'value1 and short1s'); + assert.equal(r.short2, 'value1 and value1 value2 and short1s'); + }); + it('should interpolate variables: 2 variables, between template and shortcuts and itself: 1 level', function() { + let templates = { template1: 'value1', template2: 'value2', template3: 'value3' }; + let shortcuts = { short1: '${template1} and short1s', short2: '${template2} and ${template3} and ${short1}' }; + let config = { templates, shortcuts }; + + let r = interpolateVariables(config); + + assert.hasAllKeys(r, ['short1', 'short2']); + assert.equal(r.short1, 'value1 and short1s'); + assert.equal(r.short2, 'value2 and value3 and value1 and short1s'); + }); + + it('should interpolate variables: 1 variable: 4 level', function() { + let templates = { branchA: { branchAA: { branchAAA: { branchAAAA: 'four As' } } } }; + let shortcuts = { short1: '${branchA.branchAA.branchAAA.branchAAAA} found' }; + let config = { templates, shortcuts }; + + let r = interpolateVariables(config); + + assert.hasAllKeys(r, ['short1']); + assert.equal(r.short1, 'four As found'); + }); + it('should interpolate variables: 1 variable, 1 itself: 4 level', function() { + let templates = { branchA: { branchAA: { branchAAA: { branchAAAA: 'four As' } } } }; + let shortcuts = { short1: '${branchA.branchAA.branchAAA.branchAAAA} found', short2: '${short1} from other short' }; + let config = { templates, shortcuts }; + + let r = interpolateVariables(config); + + assert.hasAllKeys(r, ['short1', 'short2']); + assert.equal(r.short1, 'four As found'); + assert.equal(r.short2, 'four As found from other short'); + }); + it('should interpolate variables: complex 1', function() { + let templates = { + branchA: { branchAA: { branchAAA: { branchAAAA: 'four As' } } }, + branchB: { branchBB: { branchBBB: { branchBBBB: 'four Bs and ${branchA.branchAA.branchAAA.branchAAAA}' } } } + }; + let shortcuts = { + short1: '${branchA.branchAA.branchAAA.branchAAAA} found', + short2: '${short1} from other short', + short3: 'from template B ${branchB.branchBB.branchBBB.branchBBBB} and from shortcuts ${short1}' + }; + let config = { templates, shortcuts }; + + let r = interpolateVariables(config); + + assert.hasAllKeys(r, ['short1', 'short2', 'short3']); + assert.equal(r.short1, 'four As found'); + assert.equal(r.short2, 'four As found from other short'); + assert.equal(r.short3, 'from template B four Bs and four As and from shortcuts four As found'); + }); +}); diff --git a/yarn.lock b/yarn.lock index 033fe8a..f317d8b 100644 --- a/yarn.lock +++ b/yarn.lock @@ -36,17 +36,11 @@ archy@^1.0.0: version "1.0.0" resolved "https://registry.npmjs.org/archy/-/archy-1.0.0.tgz#f9c8c13757cc1dd7bc379ac77b2c62a5c2868c40" -arr-diff@^2.0.0: - version "2.0.0" - resolved "https://registry.npmjs.org/arr-diff/-/arr-diff-2.0.0.tgz#8f3b827f955a8bd669697e4a4256ac3ceae356cf" - dependencies: - arr-flatten "^1.0.1" - arr-diff@^4.0.0: version "4.0.0" resolved "https://registry.npmjs.org/arr-diff/-/arr-diff-4.0.0.tgz#d6461074febfec71e7e15235761a329a5dc7c520" -arr-flatten@^1.0.1, arr-flatten@^1.1.0: +arr-flatten@^1.1.0: version "1.1.0" resolved "https://registry.npmjs.org/arr-flatten/-/arr-flatten-1.1.0.tgz#36048bbff4e7b47e136644316c99669ea5ae91f1" @@ -54,10 +48,6 @@ arr-union@^3.1.0: version "3.1.0" resolved "https://registry.npmjs.org/arr-union/-/arr-union-3.1.0.tgz#e39b09aea9def866a8f206e288af63919bae39c4" -array-unique@^0.2.1: - version "0.2.1" - resolved "https://registry.npmjs.org/array-unique/-/array-unique-0.2.1.tgz#a1d97ccafcbc2625cc70fadceb36a50c58b01a53" - array-unique@^0.3.2: version "0.3.2" resolved "https://registry.npmjs.org/array-unique/-/array-unique-0.3.2.tgz#a894b75d4bc4f6cd679ef3244a9fd8f46ae2d428" @@ -176,14 +166,6 @@ brace-expansion@^1.1.7: balanced-match "^1.0.0" concat-map "0.0.1" -braces@^1.8.2: - version "1.8.5" - resolved "https://registry.npmjs.org/braces/-/braces-1.8.5.tgz#ba77962e12dff969d6b76711e914b737857bf6a7" - dependencies: - expand-range "^1.8.1" - preserve "^0.2.0" - repeat-element "^1.1.2" - braces@^2.3.1: version "2.3.2" resolved "https://registry.npmjs.org/braces/-/braces-2.3.2.tgz#5979fd3f14cd531565e5fa2df1abfff1dfaee729" @@ -439,12 +421,6 @@ execa@^0.7.0: signal-exit "^3.0.0" strip-eof "^1.0.0" -expand-brackets@^0.1.4: - version "0.1.5" - resolved "https://registry.npmjs.org/expand-brackets/-/expand-brackets-0.1.5.tgz#df07284e342a807cd733ac5af72411e581d1177b" - dependencies: - is-posix-bracket "^0.1.0" - expand-brackets@^2.1.4: version "2.1.4" resolved "https://registry.npmjs.org/expand-brackets/-/expand-brackets-2.1.4.tgz#b77735e315ce30f6b6eff0f83b04151a22449622" @@ -457,12 +433,6 @@ expand-brackets@^2.1.4: snapdragon "^0.8.1" to-regex "^3.0.1" -expand-range@^1.8.1: - version "1.8.2" - resolved "https://registry.npmjs.org/expand-range/-/expand-range-1.8.2.tgz#a299effd335fe2721ebae8e257ec79644fc85337" - dependencies: - fill-range "^2.1.0" - extend-shallow@^2.0.1: version "2.0.1" resolved "https://registry.npmjs.org/extend-shallow/-/extend-shallow-2.0.1.tgz#51af7d614ad9a9f610ea1bafbb989d6b1c56890f" @@ -476,12 +446,6 @@ extend-shallow@^3.0.0, extend-shallow@^3.0.2: assign-symbols "^1.0.0" is-extendable "^1.0.1" -extglob@^0.3.1: - version "0.3.2" - resolved "https://registry.npmjs.org/extglob/-/extglob-0.3.2.tgz#2e18ff3d2f49ab2765cec9023f011daa8d8349a1" - dependencies: - is-extglob "^1.0.0" - extglob@^2.0.4: version "2.0.4" resolved "https://registry.npmjs.org/extglob/-/extglob-2.0.4.tgz#ad00fe4dc612a9232e8718711dc5cb5ab0285543" @@ -495,20 +459,6 @@ extglob@^2.0.4: snapdragon "^0.8.1" to-regex "^3.0.1" -filename-regex@^2.0.0: - version "2.0.1" - resolved "https://registry.npmjs.org/filename-regex/-/filename-regex-2.0.1.tgz#c1c4b9bee3e09725ddb106b75c1e301fe2f18b26" - -fill-range@^2.1.0: - version "2.2.3" - resolved "https://registry.npmjs.org/fill-range/-/fill-range-2.2.3.tgz#50b77dfd7e469bc7492470963699fe7a8485a723" - dependencies: - is-number "^2.1.0" - isobject "^2.0.0" - randomatic "^1.1.3" - repeat-element "^1.1.2" - repeat-string "^1.5.2" - fill-range@^4.0.0: version "4.0.0" resolved "https://registry.npmjs.org/fill-range/-/fill-range-4.0.0.tgz#d544811d428f98eb06a63dc402d2403c328c38f7" @@ -539,16 +489,10 @@ find-up@^2.1.0: dependencies: locate-path "^2.0.0" -for-in@^1.0.1, for-in@^1.0.2: +for-in@^1.0.2: version "1.0.2" resolved "https://registry.npmjs.org/for-in/-/for-in-1.0.2.tgz#81068d295a8142ec0ac726c6e2200c30fb6d5e80" -for-own@^0.1.4: - version "0.1.5" - resolved "https://registry.npmjs.org/for-own/-/for-own-0.1.5.tgz#5265c681a4f294dabbf17c9509b6763aa84510ce" - dependencies: - for-in "^1.0.1" - foreground-child@^1.5.3, foreground-child@^1.5.6: version "1.5.6" resolved "https://registry.npmjs.org/foreground-child/-/foreground-child-1.5.6.tgz#4fd71ad2dfde96789b980a5c0a295937cb2f5ce9" @@ -582,19 +526,6 @@ get-value@^2.0.3, get-value@^2.0.6: version "2.0.6" resolved "https://registry.npmjs.org/get-value/-/get-value-2.0.6.tgz#dc15ca1c672387ca76bd37ac0a395ba2042a2c28" -glob-base@^0.3.0: - version "0.3.0" - resolved "https://registry.npmjs.org/glob-base/-/glob-base-0.3.0.tgz#dbb164f6221b1c0b1ccf82aea328b497df0ea3c4" - dependencies: - glob-parent "^2.0.0" - is-glob "^2.0.0" - -glob-parent@^2.0.0: - version "2.0.0" - resolved "https://registry.npmjs.org/glob-parent/-/glob-parent-2.0.0.tgz#81383d72db054fcccf5336daa902f182f6edbb28" - dependencies: - is-glob "^2.0.0" - glob@7.1.2, glob@^7.0.5, glob@^7.0.6: version "7.1.2" resolved "https://registry.npmjs.org/glob/-/glob-7.1.2.tgz#c19c9df9a028702d678612384a6552404c636d15" @@ -756,16 +687,6 @@ is-descriptor@^1.0.0, is-descriptor@^1.0.2: is-data-descriptor "^1.0.0" kind-of "^6.0.2" -is-dotfile@^1.0.0: - version "1.0.3" - resolved "https://registry.npmjs.org/is-dotfile/-/is-dotfile-1.0.3.tgz#a6a2f32ffd2dfb04f5ca25ecd0f6b83cf798a1e1" - -is-equal-shallow@^0.1.3: - version "0.1.3" - resolved "https://registry.npmjs.org/is-equal-shallow/-/is-equal-shallow-0.1.3.tgz#2238098fc221de0bcfa5d9eac4c45d638aa1c534" - dependencies: - is-primitive "^2.0.0" - is-extendable@^0.1.0, is-extendable@^0.1.1: version "0.1.1" resolved "https://registry.npmjs.org/is-extendable/-/is-extendable-0.1.1.tgz#62b110e289a471418e3ec36a617d472e301dfc89" @@ -776,10 +697,6 @@ is-extendable@^1.0.1: dependencies: is-plain-object "^2.0.4" -is-extglob@^1.0.0: - version "1.0.0" - resolved "https://registry.npmjs.org/is-extglob/-/is-extglob-1.0.0.tgz#ac468177c4943405a092fc8f29760c6ffc6206c0" - is-finite@^1.0.0: version "1.0.2" resolved "https://registry.npmjs.org/is-finite/-/is-finite-1.0.2.tgz#cc6677695602be550ef11e8b4aa6305342b6d0aa" @@ -796,18 +713,6 @@ is-fullwidth-code-point@^2.0.0: version "2.0.0" resolved "https://registry.npmjs.org/is-fullwidth-code-point/-/is-fullwidth-code-point-2.0.0.tgz#a3b30a5c4f199183167aaab93beefae3ddfb654f" -is-glob@^2.0.0, is-glob@^2.0.1: - version "2.0.1" - resolved "https://registry.npmjs.org/is-glob/-/is-glob-2.0.1.tgz#d096f926a3ded5600f3fdfd91198cb0888c2d863" - dependencies: - is-extglob "^1.0.0" - -is-number@^2.1.0: - version "2.1.0" - resolved "https://registry.npmjs.org/is-number/-/is-number-2.1.0.tgz#01fcbbb393463a548f2f466cce16dece49db908f" - dependencies: - kind-of "^3.0.2" - is-number@^3.0.0: version "3.0.0" resolved "https://registry.npmjs.org/is-number/-/is-number-3.0.0.tgz#24fd6201a4782cf50561c810276afc7d12d71195" @@ -830,14 +735,6 @@ is-plain-object@^2.0.1, is-plain-object@^2.0.3, is-plain-object@^2.0.4: dependencies: isobject "^3.0.1" -is-posix-bracket@^0.1.0: - version "0.1.1" - resolved "https://registry.npmjs.org/is-posix-bracket/-/is-posix-bracket-0.1.1.tgz#3334dc79774368e92f016e6fbc0a88f5cd6e6bc4" - -is-primitive@^2.0.0: - version "2.0.0" - resolved "https://registry.npmjs.org/is-primitive/-/is-primitive-2.0.0.tgz#207bab91638499c07b2adf240a41a87210034575" - is-stream@^1.1.0: version "1.1.0" resolved "https://registry.npmjs.org/is-stream/-/is-stream-1.1.0.tgz#12d4a3dd4e68e0b79ceb8dbc84173ae80d91ca44" @@ -1017,31 +914,13 @@ mem@^1.1.0: dependencies: mimic-fn "^1.0.0" -merge-source-map@^1.0.2: +merge-source-map@^1.1.0: version "1.1.0" resolved "https://registry.npmjs.org/merge-source-map/-/merge-source-map-1.1.0.tgz#2fdde7e6020939f70906a68f2d7ae685e4c8c646" dependencies: source-map "^0.6.1" -micromatch@^2.3.11: - version "2.3.11" - resolved "https://registry.npmjs.org/micromatch/-/micromatch-2.3.11.tgz#86677c97d1720b363431d04d0d15293bd38c1565" - dependencies: - arr-diff "^2.0.0" - array-unique "^0.2.1" - braces "^1.8.2" - expand-brackets "^0.1.4" - extglob "^0.3.1" - filename-regex "^2.0.0" - is-extglob "^1.0.0" - is-glob "^2.0.1" - kind-of "^3.0.2" - normalize-path "^2.0.1" - object.omit "^2.0.0" - parse-glob "^3.0.4" - regex-cache "^0.4.2" - -micromatch@^3.1.8: +micromatch@^3.1.10, micromatch@^3.1.8: version "3.1.10" resolved "https://registry.npmjs.org/micromatch/-/micromatch-3.1.10.tgz#70859bc95c9840952f359a068a3fc49f9ecfac23" dependencies: @@ -1136,12 +1015,6 @@ normalize-package-data@^2.3.2: semver "2 || 3 || 4 || 5" validate-npm-package-license "^3.0.1" -normalize-path@^2.0.1: - version "2.1.1" - resolved "https://registry.npmjs.org/normalize-path/-/normalize-path-2.1.1.tgz#1ab28b556e198363a8c1a6f7e6fa20137fe6aed9" - dependencies: - remove-trailing-separator "^1.0.1" - npm-run-path@^2.0.0: version "2.0.2" resolved "https://registry.npmjs.org/npm-run-path/-/npm-run-path-2.0.2.tgz#35a9232dfa35d7067b4cb2ddf2357b1871536c5f" @@ -1152,9 +1025,9 @@ number-is-nan@^1.0.0: version "1.0.1" resolved "https://registry.npmjs.org/number-is-nan/-/number-is-nan-1.0.1.tgz#097b602b53422a522c1afb8790318336941a011d" -nyc@11.7.1: - version "11.7.1" - resolved "https://registry.npmjs.org/nyc/-/nyc-11.7.1.tgz#7cb0a422e501b88ff2c1634341dec2560299d67b" +nyc@11.7.3: + version "11.7.3" + resolved "https://registry.npmjs.org/nyc/-/nyc-11.7.3.tgz#164f4cfad84dee6d8f353824231d9dd683aa14ea" dependencies: archy "^1.0.0" arrify "^1.0.1" @@ -1173,11 +1046,11 @@ nyc@11.7.1: istanbul-lib-source-maps "^1.2.3" istanbul-reports "^1.4.0" md5-hex "^1.2.0" - merge-source-map "^1.0.2" - micromatch "^2.3.11" + merge-source-map "^1.1.0" + micromatch "^3.1.10" mkdirp "^0.5.0" resolve-from "^2.0.0" - rimraf "^2.5.4" + rimraf "^2.6.2" signal-exit "^3.0.1" spawn-wrap "^1.4.2" test-exclude "^4.2.0" @@ -1202,13 +1075,6 @@ object-visit@^1.0.0: dependencies: isobject "^3.0.0" -object.omit@^2.0.0: - version "2.0.1" - resolved "https://registry.npmjs.org/object.omit/-/object.omit-2.0.1.tgz#1a9c744829f39dbb858c76ca3579ae2a54ebd1fa" - dependencies: - for-own "^0.1.4" - is-extendable "^0.1.1" - object.pick@^1.3.0: version "1.3.0" resolved "https://registry.npmjs.org/object.pick/-/object.pick-1.3.0.tgz#87a10ac4c1694bd2e1cbf53591a66141fb5dd747" @@ -1260,15 +1126,6 @@ p-try@^1.0.0: version "1.0.0" resolved "https://registry.npmjs.org/p-try/-/p-try-1.0.0.tgz#cbc79cdbaf8fd4228e13f621f2b1a237c1b207b3" -parse-glob@^3.0.4: - version "3.0.4" - resolved "https://registry.npmjs.org/parse-glob/-/parse-glob-3.0.4.tgz#b2c376cfb11f35513badd173ef0bb6e3a388391c" - dependencies: - glob-base "^0.3.0" - is-dotfile "^1.0.0" - is-extglob "^1.0.0" - is-glob "^2.0.0" - parse-json@^2.2.0: version "2.2.0" resolved "https://registry.npmjs.org/parse-json/-/parse-json-2.2.0.tgz#f480f40434ef80741f8469099f8dea18f55a4dc9" @@ -1337,21 +1194,10 @@ posix-character-classes@^0.1.0: version "0.1.1" resolved "https://registry.npmjs.org/posix-character-classes/-/posix-character-classes-0.1.1.tgz#01eac0fe3b5af71a2a6c02feabb8c1fef7e00eab" -preserve@^0.2.0: - version "0.2.0" - resolved "https://registry.npmjs.org/preserve/-/preserve-0.2.0.tgz#815ed1f6ebc65926f865b310c0713bcb3315ce4b" - pseudomap@^1.0.2: version "1.0.2" resolved "https://registry.npmjs.org/pseudomap/-/pseudomap-1.0.2.tgz#f052a28da70e618917ef0a8ac34c1ae5a68286b3" -randomatic@^1.1.3: - version "1.1.7" - resolved "https://registry.npmjs.org/randomatic/-/randomatic-1.1.7.tgz#c7abe9cc8b87c0baa876b19fde83fd464797e38c" - dependencies: - is-number "^3.0.0" - kind-of "^4.0.0" - read-pkg-up@^1.0.1: version "1.0.1" resolved "https://registry.npmjs.org/read-pkg-up/-/read-pkg-up-1.0.1.tgz#9d63c13276c065918d57f002a57f40a1b643fb02" @@ -1371,12 +1217,6 @@ regenerator-runtime@^0.11.0: version "0.11.1" resolved "https://registry.npmjs.org/regenerator-runtime/-/regenerator-runtime-0.11.1.tgz#be05ad7f9bf7d22e056f9726cee5017fbf19e2e9" -regex-cache@^0.4.2: - version "0.4.4" - resolved "https://registry.npmjs.org/regex-cache/-/regex-cache-0.4.4.tgz#75bdc58a2a1496cec48a12835bc54c8d562336dd" - dependencies: - is-equal-shallow "^0.1.3" - regex-not@^1.0.0, regex-not@^1.0.2: version "1.0.2" resolved "https://registry.npmjs.org/regex-not/-/regex-not-1.0.2.tgz#1f4ece27e00b0b65e0247a6810e6a85d83a5752c" @@ -1384,10 +1224,6 @@ regex-not@^1.0.0, regex-not@^1.0.2: extend-shallow "^3.0.2" safe-regex "^1.1.0" -remove-trailing-separator@^1.0.1: - version "1.1.0" - resolved "https://registry.npmjs.org/remove-trailing-separator/-/remove-trailing-separator-1.1.0.tgz#c24bce2a283adad5bc3f58e0d48249b92379d8ef" - repeat-element@^1.1.2: version "1.1.2" resolved "https://registry.npmjs.org/repeat-element/-/repeat-element-1.1.2.tgz#ef089a178d1483baae4d93eb98b4f9e4e11d990a" @@ -1428,7 +1264,7 @@ right-align@^0.1.1: dependencies: align-text "^0.1.1" -rimraf@^2.5.4, rimraf@^2.6.1, rimraf@^2.6.2: +rimraf@^2.6.1, rimraf@^2.6.2: version "2.6.2" resolved "https://registry.npmjs.org/rimraf/-/rimraf-2.6.2.tgz#2ed8150d24a16ea8651e6d6ef0f47c4158ce7a36" dependencies: From c216d093c36097a19fb092d93dbaa17091a89b4a Mon Sep 17 00:00:00 2001 From: pusher Date: Thu, 10 May 2018 07:44:26 -0300 Subject: [PATCH 3/3] files removed --- aexecutor.json | 6 ------ lib/description.js | 18 ------------------ test/description.spec.js | 24 ------------------------ 3 files changed, 48 deletions(-) delete mode 100644 aexecutor.json delete mode 100644 lib/description.js delete mode 100644 test/description.spec.js diff --git a/aexecutor.json b/aexecutor.json deleted file mode 100644 index 6a071d5..0000000 --- a/aexecutor.json +++ /dev/null @@ -1,6 +0,0 @@ -{ - "description": "", - "shortcuts": { - "ls": "ls -lha" - } -} diff --git a/lib/description.js b/lib/description.js deleted file mode 100644 index cb5eba1..0000000 --- a/lib/description.js +++ /dev/null @@ -1,18 +0,0 @@ -const { validateAndBuildEnvironments, validateShortcut, validateShortcuts, validateTemplates, validateConfig } = require('./validators'); -const { isTestRunning, setColors } = require('./utils'); -const { interpolateVariables, buildShortcutCommand, buildConfig } = require('./builders'); -const { getConfigFromCWD } = require('./node'); -const { configDefault } = require('./defaults'); -const { messages } = require('./i18n'); - - -let buildCommand = (shortcut) => { - return buildCommandWithConfig(shortcut, getConfigFromCWD()); -}; - - - -module.exports = { - buildCommand, - buildCommandWithConfig -}; diff --git a/test/description.spec.js b/test/description.spec.js deleted file mode 100644 index baf8471..0000000 --- a/test/description.spec.js +++ /dev/null @@ -1,24 +0,0 @@ -const { expect } = require('chai'); -const { assert } = require('chai'); -const { buildCommand, buildCommandWithConfig } = require('../lib/command'); -const path = require('path'); - -describe('setDescription() throws', function() { - - // throws - - it('should throw an error by invalid arguments', function() { - assert.throw(() => { - buildCommand(); - }); - assert.throw(() => { - buildCommand(''); - }); - assert.throw(() => { - buildCommand([]); - }); - assert.throw(() => { - buildCommand({}); - }); - }); -});