From adb7a3bbec8d12c7528c8402e5f5f96bc48ad2c6 Mon Sep 17 00:00:00 2001 From: Osmar Reyes Date: Mon, 8 Feb 2021 16:41:11 -0500 Subject: [PATCH 1/8] add base files --- src/metaflux-cli/run/index.js | 0 1 file changed, 0 insertions(+), 0 deletions(-) create mode 100644 src/metaflux-cli/run/index.js diff --git a/src/metaflux-cli/run/index.js b/src/metaflux-cli/run/index.js new file mode 100644 index 0000000..e69de29 From 4c45c790597d84531b578ea713efdf325dbc4725 Mon Sep 17 00:00:00 2001 From: Osmar Reyes Date: Mon, 8 Feb 2021 20:18:53 -0500 Subject: [PATCH 2/8] add logic for run subcommand --- src/metaflux-cli/index.js | 4 +++- src/metaflux-cli/run/index.js | 26 ++++++++++++++++++++++++++ 2 files changed, 29 insertions(+), 1 deletion(-) diff --git a/src/metaflux-cli/index.js b/src/metaflux-cli/index.js index 09beedd..a3d453b 100644 --- a/src/metaflux-cli/index.js +++ b/src/metaflux-cli/index.js @@ -1,7 +1,7 @@ (() => { const createSubCommand = require('./create'); const componentSubCommand = require('./component'); - + const runSubCommadn = require('./run'); function metafluxCli(program) { program.description('Complete Metaflux project manager, see the usage with metaflux-cli --help') @@ -10,6 +10,8 @@ createSubCommand(program); // Create new component sub-command componentSubCommand(program); + // create Run project sub-command + runSubCommadn(program); } module.exports = metafluxCli; diff --git a/src/metaflux-cli/run/index.js b/src/metaflux-cli/run/index.js index e69de29..b7e2a3e 100644 --- a/src/metaflux-cli/run/index.js +++ b/src/metaflux-cli/run/index.js @@ -0,0 +1,26 @@ +(() => { + const shell = require('shelljs'); + const fs = require('fs-extra'); + /** + * Start Dev server sub-command + */ + function run (program) { + const commandObject = program + commandObject.command('run') + .description('Run your project in Dev mode') + .action(async function () { + if(!fs.existsSync('node_modules/')) { + console.log('#>- Installing dependencies, this may take a couple of minutes'); + await shell.exec('npm install', { silent: true }); + console.log('#>- Done') + } + const {stdout} = shell.exec('npm start', { silent: true, async: true }); + console.log('#>- Start / watch Dev Server'); + stdout.on('data', (chunk) => { + console.log(chunk); + }); + }); + } + + module.exports = run; +})() From 078ae2539cd8a07c61f55e390b38a043e38f4737 Mon Sep 17 00:00:00 2001 From: Osmar Reyes Date: Mon, 8 Feb 2021 22:28:09 -0500 Subject: [PATCH 3/8] add --silent option --- src/metaflux-cli/run/index.js | 15 +++++++++++---- src/metaflux-cli/run/options.js | 7 +++++++ 2 files changed, 18 insertions(+), 4 deletions(-) create mode 100644 src/metaflux-cli/run/options.js diff --git a/src/metaflux-cli/run/index.js b/src/metaflux-cli/run/index.js index b7e2a3e..57be32e 100644 --- a/src/metaflux-cli/run/index.js +++ b/src/metaflux-cli/run/index.js @@ -1,24 +1,31 @@ (() => { const shell = require('shelljs'); const fs = require('fs-extra'); + const options = require('./options'); /** * Start Dev server sub-command */ function run (program) { const commandObject = program + options.forEach(option => { + commandObject.option(...option.command); + }); commandObject.command('run') .description('Run your project in Dev mode') .action(async function () { + const { silent } = commandObject; if(!fs.existsSync('node_modules/')) { console.log('#>- Installing dependencies, this may take a couple of minutes'); await shell.exec('npm install', { silent: true }); console.log('#>- Done') } const {stdout} = shell.exec('npm start', { silent: true, async: true }); - console.log('#>- Start / watch Dev Server'); - stdout.on('data', (chunk) => { - console.log(chunk); - }); + console.log('#>- Start / watch Dev Server you can end it with (ctrl + c)'); + if (!silent) { + stdout.on('data', (chunk) => { + console.log(chunk); + }); + } }); } diff --git a/src/metaflux-cli/run/options.js b/src/metaflux-cli/run/options.js new file mode 100644 index 0000000..32d506d --- /dev/null +++ b/src/metaflux-cli/run/options.js @@ -0,0 +1,7 @@ +// Options description +module.exports = [ + { + name: 'silent', + command: ['-s, --silent', 'Subcommad run will not display the watch info'] + } +] From 015ddc831e3e58e1af0946d1f95fd4b61787bfcf Mon Sep 17 00:00:00 2001 From: Osmar Reyes Date: Tue, 9 Feb 2021 00:10:41 -0500 Subject: [PATCH 4/8] add testing for new feature --- src/metaflux-cli/create/index.spec.js | 18 ++++++---------- src/metaflux-cli/index.spec.js | 7 +++++-- src/metaflux-cli/run/index.js | 9 ++------ src/metaflux-cli/run/index.spec.js | 30 +++++++++++++++++++++++++++ 4 files changed, 43 insertions(+), 21 deletions(-) create mode 100644 src/metaflux-cli/run/index.spec.js diff --git a/src/metaflux-cli/create/index.spec.js b/src/metaflux-cli/create/index.spec.js index 4d3a729..fa83947 100644 --- a/src/metaflux-cli/create/index.spec.js +++ b/src/metaflux-cli/create/index.spec.js @@ -2,30 +2,24 @@ const shell = require('shelljs'); const path = require('path'); const fs = require('fs-extra'); const file = require('./index'); -import commander from 'commander'; +//import commander from 'commander'; // go to the testing folder shell.cd('./unit_test_tmp/'); -jest.mock('commander') +//jest.mock('commander') -async function cli(args) { +async function cli(args = []) { // execute relative to this file - return await shell.exec(`node ${path.resolve('./index')} ${args.join(' ')}`); -} - -async function cli_2(args) { - program. - file(program) - return program + return await shell.exec(`node ${path.resolve('./index')} ${args.join(' ')}`, { silent: true }); } test('Create should add new folder', async () => { - await cli_2({ name: 'name' }) + await cli(['create', 'test_new_project']) const exists = fs.existsSync('./test_new_project'); expect(exists).toBe(true) }); test('Create should add new folder if dir', async () => { - const resp = await cli_2() + const resp = await cli() console.log(resp.code); expect(1).toBe(1) }); diff --git a/src/metaflux-cli/index.spec.js b/src/metaflux-cli/index.spec.js index a64485f..c638f6b 100644 --- a/src/metaflux-cli/index.spec.js +++ b/src/metaflux-cli/index.spec.js @@ -1,16 +1,19 @@ const shell = require('shelljs'); const path = require('path'); const fs = require('fs-extra'); - +// clean the testing folder +//shell.rm('-rf', './unit_test_tmp/'); +//shell.mkdir('./unit_test_tmp/'); // go to the testing folder shell.cd('./unit_test_tmp/'); async function cli(args) { // execute relative to this file - return await shell.exec(`node ${path.resolve('./index')} ${args.join(' ')}`); + return await shell.exec(`node ${path.resolve('./index')} ${args.join(' ')}`, { silent: true }); } test('If no args should exit with 1 code', async () => { const resp = await cli([]); expect(resp.code).toBe(1) }); + diff --git a/src/metaflux-cli/run/index.js b/src/metaflux-cli/run/index.js index 57be32e..de35471 100644 --- a/src/metaflux-cli/run/index.js +++ b/src/metaflux-cli/run/index.js @@ -5,7 +5,7 @@ /** * Start Dev server sub-command */ - function run (program) { + async function run (program) { const commandObject = program options.forEach(option => { commandObject.option(...option.command); @@ -19,13 +19,8 @@ await shell.exec('npm install', { silent: true }); console.log('#>- Done') } - const {stdout} = shell.exec('npm start', { silent: true, async: true }); console.log('#>- Start / watch Dev Server you can end it with (ctrl + c)'); - if (!silent) { - stdout.on('data', (chunk) => { - console.log(chunk); - }); - } + await shell.exec('npm start', { silent: silent }); }); } diff --git a/src/metaflux-cli/run/index.spec.js b/src/metaflux-cli/run/index.spec.js new file mode 100644 index 0000000..33b06bf --- /dev/null +++ b/src/metaflux-cli/run/index.spec.js @@ -0,0 +1,30 @@ +const shell = require('shelljs'); +const run = require('./index'); + +shell.cd('./unit_test_tmp/test_new_project/'); + +function cli(silent) { + // execute relative to this file + return run(Object.assign({}, process, { + option: function(param) { return this }, + description: function (param) { return this }, + action: (callable) => { + callable() + }, + command: function(param) { return this }, + silent + })) +} + + +it('Attempt 2', async (done) => { + const spy = jest.spyOn(console, 'log'); + cli(); + console.warn(spy.mock.calls); + expect(spy.mock.calls).toEqual([[ + "#>- Start / watch Dev Server you can end it with (ctrl + c)", + ]]); + setTimeout(() => { done() }, 5000) + //expect(process.exit).toHaveBeenCalledWith(0); +}); + From d2a29a1936921a83e0ebee59b45a3b6158f5860c Mon Sep 17 00:00:00 2001 From: Osmar Reyes Date: Thu, 11 Feb 2021 21:18:38 -0500 Subject: [PATCH 5/8] improve unit testing, now mocking dependencies --- package-lock.json | 180 ++++++----------------------- package.json | 11 +- src/metaflux-cli/run/index.js | 2 +- src/metaflux-cli/run/index.spec.js | 26 ++--- 4 files changed, 55 insertions(+), 164 deletions(-) diff --git a/package-lock.json b/package-lock.json index 61732dd..13d7c8a 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1104,11 +1104,6 @@ } } }, - "ansi-regex": { - "version": "4.1.0", - "resolved": "https://registry.npmjs.org/ansi-regex/-/ansi-regex-4.1.0.tgz", - "integrity": "sha512-1apePfXM1UOSqw0o9IiFAovVz9M5S1Dg+4TrDwfMewQ6p/rmMueb7tWZjQ1rx4Loy1ArBggoqGpfqqdI4rondg==" - }, "ansi-styles": { "version": "3.2.1", "resolved": "https://registry.npmjs.org/ansi-styles/-/ansi-styles-3.2.1.tgz", @@ -1472,7 +1467,8 @@ "camelcase": { "version": "5.3.1", "resolved": "https://registry.npmjs.org/camelcase/-/camelcase-5.3.1.tgz", - "integrity": "sha512-L28STB170nwWS63UjtlEOE3dldQApaJXZkOI1uMFfzf3rRuPegHaHesyee+YxQ+W6SvRDQV6UrdOdRiR153wJg==" + "integrity": "sha512-L28STB170nwWS63UjtlEOE3dldQApaJXZkOI1uMFfzf3rRuPegHaHesyee+YxQ+W6SvRDQV6UrdOdRiR153wJg==", + "dev": true }, "capture-exit": { "version": "2.0.0", @@ -1540,16 +1536,6 @@ } } }, - "cliui": { - "version": "5.0.0", - "resolved": "https://registry.npmjs.org/cliui/-/cliui-5.0.0.tgz", - "integrity": "sha512-PYeGSEmmHM6zvoef2w8TPzlrnNpXIjTipYK780YswmIP9vjxmd6Y2a3CB2Ks6/AU8NHjZugXvo8w3oWM2qnwXA==", - "requires": { - "string-width": "^3.1.0", - "strip-ansi": "^5.2.0", - "wrap-ansi": "^5.1.0" - } - }, "co": { "version": "4.6.0", "resolved": "https://registry.npmjs.org/co/-/co-4.6.0.tgz", @@ -1595,9 +1581,9 @@ } }, "commander": { - "version": "5.0.0", - "resolved": "https://registry.npmjs.org/commander/-/commander-5.0.0.tgz", - "integrity": "sha512-JrDGPAKjMGSP1G0DUoaceEJ3DZgAfr/q6X7FVk4+U5KxUSKviYGM2k6zWkfyyBHy5rAtzgYJFa1ro2O9PtoxwQ==" + "version": "7.0.0", + "resolved": "https://registry.npmjs.org/commander/-/commander-7.0.0.tgz", + "integrity": "sha512-ovx/7NkTrnPuIV8sqk/GjUIIM1+iUQeqA3ye2VNpq9sVoiZsooObWlQy+OPWGI17GDaEoybuAGJm6U8yC077BA==" }, "component-emitter": { "version": "1.3.0", @@ -1699,7 +1685,8 @@ "decamelize": { "version": "1.2.0", "resolved": "https://registry.npmjs.org/decamelize/-/decamelize-1.2.0.tgz", - "integrity": "sha1-9lNNFRSCabIDUue+4m9QH5oZEpA=" + "integrity": "sha1-9lNNFRSCabIDUue+4m9QH5oZEpA=", + "dev": true }, "decimal.js": { "version": "10.2.1", @@ -1817,11 +1804,6 @@ "integrity": "sha512-A8OG5SR/ij3SsJdWDJdkkSYUjQdCUx6APQXem0SaEePBSRg4eymGYwBkKo1Y6DU+af/Jn2dBQqDBvjnr9Vi8nQ==", "dev": true }, - "emoji-regex": { - "version": "7.0.3", - "resolved": "https://registry.npmjs.org/emoji-regex/-/emoji-regex-7.0.3.tgz", - "integrity": "sha512-CwBLREIQ7LvYFB0WyRvwhq5N5qPhc6PMjD6bYggFlI5YyDgl+0vxq5VHbMOFqLg7hfWzmu8T5Z1QofhmTIhItA==" - }, "end-of-stream": { "version": "1.4.4", "resolved": "https://registry.npmjs.org/end-of-stream/-/end-of-stream-1.4.4.tgz", @@ -2127,14 +2109,6 @@ "to-regex-range": "^5.0.1" } }, - "find-up": { - "version": "3.0.0", - "resolved": "https://registry.npmjs.org/find-up/-/find-up-3.0.0.tgz", - "integrity": "sha512-1yD6RmLI1XBfxugvORwlck6f75tYL+iR0jqwsOrOxMZyGYqUuDhJ0l4AXdO1iX/FTs9cBAMEk1gWSEx1kSbylg==", - "requires": { - "locate-path": "^3.0.0" - } - }, "for-in": { "version": "1.0.2", "resolved": "https://registry.npmjs.org/for-in/-/for-in-1.0.2.tgz", @@ -2168,14 +2142,14 @@ } }, "fs-extra": { - "version": "9.0.0", - "resolved": "https://registry.npmjs.org/fs-extra/-/fs-extra-9.0.0.tgz", - "integrity": "sha512-pmEYSk3vYsG/bF651KPUXZ+hvjpgWYw/Gc7W9NFUe3ZVLczKKWIij3IKpOrQcdw4TILtibFslZ0UmR8Vvzig4g==", + "version": "9.1.0", + "resolved": "https://registry.npmjs.org/fs-extra/-/fs-extra-9.1.0.tgz", + "integrity": "sha512-hcg3ZmepS30/7BSFqRvoo3DOMQu7IjqxO5nCDt+zM9XWjb33Wg7ziNT+Qvqbuc3+gWpzO02JubVyk2G4Zvo1OQ==", "requires": { "at-least-node": "^1.0.0", "graceful-fs": "^4.2.0", "jsonfile": "^6.0.1", - "universalify": "^1.0.0" + "universalify": "^2.0.0" } }, "fs.realpath": { @@ -2204,7 +2178,8 @@ "get-caller-file": { "version": "2.0.5", "resolved": "https://registry.npmjs.org/get-caller-file/-/get-caller-file-2.0.5.tgz", - "integrity": "sha512-DyFP3BM/3YHTQOCUL/w0OZHR0lpKeGrxotcHWcqNEdnltqFwXVfhEBQ94eIo34AfQpo0rGki4cyIiftY06h2Fg==" + "integrity": "sha512-DyFP3BM/3YHTQOCUL/w0OZHR0lpKeGrxotcHWcqNEdnltqFwXVfhEBQ94eIo34AfQpo0rGki4cyIiftY06h2Fg==", + "dev": true }, "get-package-type": { "version": "0.1.0", @@ -2256,9 +2231,9 @@ "dev": true }, "graceful-fs": { - "version": "4.2.3", - "resolved": "https://registry.npmjs.org/graceful-fs/-/graceful-fs-4.2.3.tgz", - "integrity": "sha512-a30VEBm4PEdx1dRB7MFK7BejejvCvBronbLjht+sHuGYj8PHs7M/5Z+rt5lw551vZ7yfTCj4Vuyy3mSJytDWRQ==" + "version": "4.2.6", + "resolved": "https://registry.npmjs.org/graceful-fs/-/graceful-fs-4.2.6.tgz", + "integrity": "sha512-nTnJ528pbqxYanhpDYsi4Rd8MAeaBA67+RZ10CM1m3bTAVFEDcd5AuA4a6W5YkGZ1iNXHzZz8T6TBKLeBuNriQ==" }, "gradient-string": { "version": "1.2.0", @@ -2546,11 +2521,6 @@ "integrity": "sha1-YrEQ4omkcUGOPsNqYX1HLjAd/Ik=", "dev": true }, - "is-fullwidth-code-point": { - "version": "2.0.0", - "resolved": "https://registry.npmjs.org/is-fullwidth-code-point/-/is-fullwidth-code-point-2.0.0.tgz", - "integrity": "sha1-o7MKXE8ZkYMWeqq5O+764937ZU8=" - }, "is-generator-fn": { "version": "2.1.0", "resolved": "https://registry.npmjs.org/is-generator-fn/-/is-generator-fn-2.1.0.tgz", @@ -4366,12 +4336,12 @@ } }, "jsonfile": { - "version": "6.0.1", - "resolved": "https://registry.npmjs.org/jsonfile/-/jsonfile-6.0.1.tgz", - "integrity": "sha512-jR2b5v7d2vIOust+w3wtFKZIfpC2pnRmFAhAC/BuweZFQR8qZzxH1OyrQ10HmdVYiXWkYUqPVsz91cG7EL2FBg==", + "version": "6.1.0", + "resolved": "https://registry.npmjs.org/jsonfile/-/jsonfile-6.1.0.tgz", + "integrity": "sha512-5dgndWOriYSm5cnYaJNhalLNDKOqFwyDB/rr1E9ZsGciGvKPs8R2xYGCacuf3z6K1YKDz182fd+fY3cn3pMqXQ==", "requires": { "graceful-fs": "^4.1.6", - "universalify": "^1.0.0" + "universalify": "^2.0.0" } }, "jsprim": { @@ -4420,15 +4390,6 @@ "integrity": "sha1-HADHQ7QzzQpOgHWPe2SldEDZ/wA=", "dev": true }, - "locate-path": { - "version": "3.0.0", - "resolved": "https://registry.npmjs.org/locate-path/-/locate-path-3.0.0.tgz", - "integrity": "sha512-7AO748wWnIhNqAuaty2ZWHkQHRSNfPVIsPIfwEOWO22AmaoVrWavlOcMR5nzTLNYvp36X220/maaRsrec1G65A==", - "requires": { - "p-locate": "^3.0.0", - "path-exists": "^3.0.0" - } - }, "lodash": { "version": "4.17.20", "resolved": "https://registry.npmjs.org/lodash/-/lodash-4.17.20.tgz", @@ -4784,22 +4745,16 @@ "version": "2.3.0", "resolved": "https://registry.npmjs.org/p-limit/-/p-limit-2.3.0.tgz", "integrity": "sha512-//88mFWSJx8lxCzwdAABTJL2MyWB12+eIY7MDL2SqLmAkeKU9qxRvWuSyTjm3FUmpBEMuFfckAIqEaVGUDxb6w==", + "dev": true, "requires": { "p-try": "^2.0.0" } }, - "p-locate": { - "version": "3.0.0", - "resolved": "https://registry.npmjs.org/p-locate/-/p-locate-3.0.0.tgz", - "integrity": "sha512-x+12w/To+4GFfgJhBEpiDcLozRJGegY+Ei7/z0tSLkMmxGZNybVMSfWj9aJn8Z5Fc7dBUNJOOVgPv2H7IwulSQ==", - "requires": { - "p-limit": "^2.0.0" - } - }, "p-try": { "version": "2.2.0", "resolved": "https://registry.npmjs.org/p-try/-/p-try-2.2.0.tgz", - "integrity": "sha512-R4nPAVTAU0B9D35/Gk3uJf/7XYbQcyohSKdvAxIRSNghFl4e71hVoGnBNQz9cWaXxO2I10KTC+3jMdvvoKw6dQ==" + "integrity": "sha512-R4nPAVTAU0B9D35/Gk3uJf/7XYbQcyohSKdvAxIRSNghFl4e71hVoGnBNQz9cWaXxO2I10KTC+3jMdvvoKw6dQ==", + "dev": true }, "parse-json": { "version": "5.1.0", @@ -4825,11 +4780,6 @@ "integrity": "sha1-s2PlXoAGym/iF4TS2yK9FdeRfxQ=", "dev": true }, - "path-exists": { - "version": "3.0.0", - "resolved": "https://registry.npmjs.org/path-exists/-/path-exists-3.0.0.tgz", - "integrity": "sha1-zg6+ql94yxiSXqfYENe1mwEP1RU=" - }, "path-is-absolute": { "version": "1.0.1", "resolved": "https://registry.npmjs.org/path-is-absolute/-/path-is-absolute-1.0.1.tgz", @@ -5196,12 +5146,14 @@ "require-directory": { "version": "2.1.1", "resolved": "https://registry.npmjs.org/require-directory/-/require-directory-2.1.1.tgz", - "integrity": "sha1-jGStX9MNqxyXbiNE/+f3kqam30I=" + "integrity": "sha1-jGStX9MNqxyXbiNE/+f3kqam30I=", + "dev": true }, "require-main-filename": { "version": "2.0.0", "resolved": "https://registry.npmjs.org/require-main-filename/-/require-main-filename-2.0.0.tgz", - "integrity": "sha512-NKN5kMDylKuldxYLSUfrbo5Tuzh4hd+2E8NPPX02mZtn1VuREQToYe/ZdlJy+J3uCpfaiGF05e7B8W0iXbQHmg==" + "integrity": "sha512-NKN5kMDylKuldxYLSUfrbo5Tuzh4hd+2E8NPPX02mZtn1VuREQToYe/ZdlJy+J3uCpfaiGF05e7B8W0iXbQHmg==", + "dev": true }, "resolve": { "version": "1.19.0", @@ -5434,7 +5386,8 @@ "set-blocking": { "version": "2.0.0", "resolved": "https://registry.npmjs.org/set-blocking/-/set-blocking-2.0.0.tgz", - "integrity": "sha1-BF+XgtARrppoA93TgrJDkrPYkPc=" + "integrity": "sha1-BF+XgtARrppoA93TgrJDkrPYkPc=", + "dev": true }, "set-value": { "version": "2.0.1", @@ -5491,14 +5444,6 @@ "dev": true, "optional": true }, - "showdown": { - "version": "1.9.1", - "resolved": "https://registry.npmjs.org/showdown/-/showdown-1.9.1.tgz", - "integrity": "sha512-9cGuS382HcvExtf5AHk7Cb4pAeQQ+h0eTr33V1mu+crYWV4KvWAw6el92bDrqGEk5d46Ai/fhbEUwqJ/mTCNEA==", - "requires": { - "yargs": "^14.2" - } - }, "signal-exit": { "version": "3.0.3", "resolved": "https://registry.npmjs.org/signal-exit/-/signal-exit-3.0.3.tgz", @@ -5815,24 +5760,6 @@ } } }, - "string-width": { - "version": "3.1.0", - "resolved": "https://registry.npmjs.org/string-width/-/string-width-3.1.0.tgz", - "integrity": "sha512-vafcv6KjVZKSgz06oM/H6GDBrAtz8vdhQakGjFIvNrHA6y3HCF1CInLy+QLq8dTJPQ1b+KDUqDFctkdRW44e1w==", - "requires": { - "emoji-regex": "^7.0.1", - "is-fullwidth-code-point": "^2.0.0", - "strip-ansi": "^5.1.0" - } - }, - "strip-ansi": { - "version": "5.2.0", - "resolved": "https://registry.npmjs.org/strip-ansi/-/strip-ansi-5.2.0.tgz", - "integrity": "sha512-DuRs1gKbBqsMKIZlrffwlug8MHkcnpjs5VPmL1PAh+mA30U0DTotfDZ0d2UUsXpPmPmMMJ6W773MaA3J+lbiWA==", - "requires": { - "ansi-regex": "^4.1.0" - } - }, "strip-bom": { "version": "4.0.0", "resolved": "https://registry.npmjs.org/strip-bom/-/strip-bom-4.0.0.tgz", @@ -6064,9 +5991,9 @@ } }, "universalify": { - "version": "1.0.0", - "resolved": "https://registry.npmjs.org/universalify/-/universalify-1.0.0.tgz", - "integrity": "sha512-rb6X1W158d7pRQBg5gkR8uPaSfiids68LTJQYOtEUhoJUWBdaQHsuT/EUduxXYxcrt4r5PJ4fuHW1MHT6p0qug==" + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/universalify/-/universalify-2.0.0.tgz", + "integrity": "sha512-hAZsKq7Yy11Zu1DE0OzWjw7nnLZmJZYTDZZyEFHZdUhV8FkH5MCfoU1XMaxXovpyW5nq5scPqq0ZDP9Zyl04oQ==" }, "unset-value": { "version": "1.0.0", @@ -6247,7 +6174,8 @@ "which-module": { "version": "2.0.0", "resolved": "https://registry.npmjs.org/which-module/-/which-module-2.0.0.tgz", - "integrity": "sha1-2e8H3Od7mQK4o6j6SzHD4/fm6Ho=" + "integrity": "sha1-2e8H3Od7mQK4o6j6SzHD4/fm6Ho=", + "dev": true }, "word-wrap": { "version": "1.2.3", @@ -6255,16 +6183,6 @@ "integrity": "sha512-Hz/mrNwitNRh/HUAtM/VT/5VH+ygD6DV7mYKZAtHOrbs8U7lvPS6xf7EJKMF0uW1KJCl0H701g3ZGus+muE5vQ==", "dev": true }, - "wrap-ansi": { - "version": "5.1.0", - "resolved": "https://registry.npmjs.org/wrap-ansi/-/wrap-ansi-5.1.0.tgz", - "integrity": "sha512-QC1/iN/2/RPVJ5jYK8BGttj5z83LmSKmvbvrXPNCLZSEb32KKVDJDl/MOt2N01qU2H/FkzEa9PKto1BqDjtd7Q==", - "requires": { - "ansi-styles": "^3.2.0", - "string-width": "^3.0.0", - "strip-ansi": "^5.0.0" - } - }, "wrappy": { "version": "1.0.2", "resolved": "https://registry.npmjs.org/wrappy/-/wrappy-1.0.2.tgz", @@ -6303,40 +6221,14 @@ "y18n": { "version": "4.0.0", "resolved": "https://registry.npmjs.org/y18n/-/y18n-4.0.0.tgz", - "integrity": "sha512-r9S/ZyXu/Xu9q1tYlpsLIsa3EeLXXk0VwlxqTcFRfg9EhMW+17kbt9G0NrgCmhGb5vT2hyhJZLfDGx+7+5Uj/w==" + "integrity": "sha512-r9S/ZyXu/Xu9q1tYlpsLIsa3EeLXXk0VwlxqTcFRfg9EhMW+17kbt9G0NrgCmhGb5vT2hyhJZLfDGx+7+5Uj/w==", + "dev": true }, "yallist": { "version": "4.0.0", "resolved": "https://registry.npmjs.org/yallist/-/yallist-4.0.0.tgz", "integrity": "sha512-3wdGidZyq5PB084XLES5TpOSRA3wjXAlIWMhum2kRcv/41Sn2emQ0dycQW4uZXLejwKvg6EsvbdlVL+FYEct7A==", "dev": true - }, - "yargs": { - "version": "14.2.3", - "resolved": "https://registry.npmjs.org/yargs/-/yargs-14.2.3.tgz", - "integrity": "sha512-ZbotRWhF+lkjijC/VhmOT9wSgyBQ7+zr13+YLkhfsSiTriYsMzkTUFP18pFhWwBeMa5gUc1MzbhrO6/VB7c9Xg==", - "requires": { - "cliui": "^5.0.0", - "decamelize": "^1.2.0", - "find-up": "^3.0.0", - "get-caller-file": "^2.0.1", - "require-directory": "^2.1.1", - "require-main-filename": "^2.0.0", - "set-blocking": "^2.0.0", - "string-width": "^3.0.0", - "which-module": "^2.0.0", - "y18n": "^4.0.0", - "yargs-parser": "^15.0.1" - } - }, - "yargs-parser": { - "version": "15.0.1", - "resolved": "https://registry.npmjs.org/yargs-parser/-/yargs-parser-15.0.1.tgz", - "integrity": "sha512-0OAMV2mAZQrs3FkNpDQcBk1x5HXb8X4twADss4S0Iuk+2dGnLOE/fRHrsYm542GduMveyA77OF4wrNJuanRCWw==", - "requires": { - "camelcase": "^5.0.0", - "decamelize": "^1.2.0" - } } } } diff --git a/package.json b/package.json index 02a7a7f..e77d4fb 100644 --- a/package.json +++ b/package.json @@ -33,15 +33,14 @@ "author": "", "license": "MIT", "bugs": { - "url": "https://github.com/rebelstackio/docstrap/issues" + "url": "https://github.com/rebelstackio/metaflux-cli/issues" }, - "homepage": "https://github.com/rebelstackio/docstrap#readme", + "homepage": "https://github.com/rebelstackio/metaflux-cli#readme", "dependencies": { - "commander": "^5.0.0", - "fs-extra": "^9.0.0", + "commander": "^7.0.0", + "fs-extra": "^9.1.0", "gradient-string": "^1.2.0", - "shelljs": "^0.8.4", - "showdown": "^1.9.1" + "shelljs": "^0.8.4" }, "devDependencies": { "jest": "^26.6.3" diff --git a/src/metaflux-cli/run/index.js b/src/metaflux-cli/run/index.js index de35471..69d8003 100644 --- a/src/metaflux-cli/run/index.js +++ b/src/metaflux-cli/run/index.js @@ -15,7 +15,7 @@ .action(async function () { const { silent } = commandObject; if(!fs.existsSync('node_modules/')) { - console.log('#>- Installing dependencies, this may take a couple of minutes'); + console.log('#>- Installing dependencies, this may take a couple of minutes...'); await shell.exec('npm install', { silent: true }); console.log('#>- Done') } diff --git a/src/metaflux-cli/run/index.spec.js b/src/metaflux-cli/run/index.spec.js index 33b06bf..a9db65d 100644 --- a/src/metaflux-cli/run/index.spec.js +++ b/src/metaflux-cli/run/index.spec.js @@ -1,7 +1,13 @@ -const shell = require('shelljs'); const run = require('./index'); +const shell = require('shelljs'); + +jest.mock('shelljs'); +shell.exec = jest.fn(); +const execMock = shell.exec; -shell.cd('./unit_test_tmp/test_new_project/'); +beforeEach(() => { + execMock.mockReset(); +}); function cli(silent) { // execute relative to this file @@ -16,15 +22,9 @@ function cli(silent) { })) } - -it('Attempt 2', async (done) => { - const spy = jest.spyOn(console, 'log'); - cli(); - console.warn(spy.mock.calls); - expect(spy.mock.calls).toEqual([[ - "#>- Start / watch Dev Server you can end it with (ctrl + c)", - ]]); - setTimeout(() => { done() }, 5000) - //expect(process.exit).toHaveBeenCalledWith(0); +it('should call npm start if dependencies are installed', () => { + cli(true); + //expect(resp).toEqual(null); + expect(execMock).toHaveBeenCalledTimes(1); + expect(execMock).toHaveBeenCalledWith('npm start', {"silent": true}); }); - From 28da9153fe1ea4a999e0f650de1b61fca77d7069 Mon Sep 17 00:00:00 2001 From: Osmar Reyes Date: Mon, 15 Feb 2021 19:43:55 -0500 Subject: [PATCH 6/8] add full testing / coverage to new feature --- src/metaflux-cli/run/index.spec.js | 26 ++++++++++++++++++++++++-- 1 file changed, 24 insertions(+), 2 deletions(-) diff --git a/src/metaflux-cli/run/index.spec.js b/src/metaflux-cli/run/index.spec.js index a9db65d..d1faf4f 100644 --- a/src/metaflux-cli/run/index.spec.js +++ b/src/metaflux-cli/run/index.spec.js @@ -1,12 +1,17 @@ const run = require('./index'); const shell = require('shelljs'); - +const fs = require('fs-extra'); +// mock dependencies jest.mock('shelljs'); +jest.mock('fs-extra'); shell.exec = jest.fn(); +fs.existsSync = jest.fn(); +const existsSync = fs.existsSync; const execMock = shell.exec; beforeEach(() => { execMock.mockReset(); + existsSync.mockReset(); }); function cli(silent) { @@ -23,8 +28,25 @@ function cli(silent) { } it('should call npm start if dependencies are installed', () => { + // this means it has node_modules folder; + existsSync.mockReturnValueOnce(true); + cli(true); - //expect(resp).toEqual(null); + expect(existsSync).toHaveBeenCalledTimes(1); + expect(existsSync).toHaveBeenCalledWith('node_modules/'); + /// expect(execMock).toHaveBeenCalledTimes(1); expect(execMock).toHaveBeenCalledWith('npm start', {"silent": true}); }); + +it('should call npm install if dependencies aren\'t installed', () => { + // this means it doesn't have node_modules folder; + existsSync.mockReturnValueOnce(false); + + cli(true); + expect(existsSync).toHaveBeenCalledTimes(1); + expect(existsSync).toHaveBeenCalledWith('node_modules/'); + /// + expect(execMock).toHaveBeenCalledTimes(1); + expect(execMock).toHaveBeenCalledWith('npm install', {"silent": true}); +}); From df76cfc8014c1acd896c4d860d2797a0d4530dba Mon Sep 17 00:00:00 2001 From: Osmar Reyes Date: Wed, 17 Feb 2021 15:51:11 -0500 Subject: [PATCH 7/8] add port flag to change the default port --- src/metaflux-cli/run/index.js | 8 ++++++-- src/metaflux-cli/run/options.js | 4 ++++ 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/src/metaflux-cli/run/index.js b/src/metaflux-cli/run/index.js index 69d8003..eb0034e 100644 --- a/src/metaflux-cli/run/index.js +++ b/src/metaflux-cli/run/index.js @@ -13,14 +13,18 @@ commandObject.command('run') .description('Run your project in Dev mode') .action(async function () { - const { silent } = commandObject; + const { silent, port } = commandObject; if(!fs.existsSync('node_modules/')) { console.log('#>- Installing dependencies, this may take a couple of minutes...'); await shell.exec('npm install', { silent: true }); console.log('#>- Done') } console.log('#>- Start / watch Dev Server you can end it with (ctrl + c)'); - await shell.exec('npm start', { silent: silent }); + if (!port) { + await shell.exec('./node_modules/.bin/webpack-dev-server --mode development', { silent: silent }); + } else { + await shell.exec(`./node_modules/.bin/webpack-dev-server --mode development --port ${port}`, { silent: silent }); + } }); } diff --git a/src/metaflux-cli/run/options.js b/src/metaflux-cli/run/options.js index 32d506d..9bc167c 100644 --- a/src/metaflux-cli/run/options.js +++ b/src/metaflux-cli/run/options.js @@ -3,5 +3,9 @@ module.exports = [ { name: 'silent', command: ['-s, --silent', 'Subcommad run will not display the watch info'] + }, + { + name: 'port', + command: ['-p, --port', 'set the port for subcommand run'] } ] From 5d4d9af72ebf60ef23e93350da746639d368a14f Mon Sep 17 00:00:00 2001 From: Osmar Reyes Date: Wed, 17 Feb 2021 17:58:27 -0500 Subject: [PATCH 8/8] add testing to port option --- src/metaflux-cli/run/index.js | 2 +- src/metaflux-cli/run/index.spec.js | 17 +++++++++++++---- src/metaflux-cli/run/options.js | 2 +- 3 files changed, 15 insertions(+), 6 deletions(-) diff --git a/src/metaflux-cli/run/index.js b/src/metaflux-cli/run/index.js index eb0034e..4e56c9c 100644 --- a/src/metaflux-cli/run/index.js +++ b/src/metaflux-cli/run/index.js @@ -12,7 +12,7 @@ }); commandObject.command('run') .description('Run your project in Dev mode') - .action(async function () { + .action(async () => { const { silent, port } = commandObject; if(!fs.existsSync('node_modules/')) { console.log('#>- Installing dependencies, this may take a couple of minutes...'); diff --git a/src/metaflux-cli/run/index.spec.js b/src/metaflux-cli/run/index.spec.js index d1faf4f..58f17c9 100644 --- a/src/metaflux-cli/run/index.spec.js +++ b/src/metaflux-cli/run/index.spec.js @@ -14,7 +14,7 @@ beforeEach(() => { existsSync.mockReset(); }); -function cli(silent) { +function cli(silent, port) { // execute relative to this file return run(Object.assign({}, process, { option: function(param) { return this }, @@ -23,11 +23,12 @@ function cli(silent) { callable() }, command: function(param) { return this }, - silent + silent, + port })) } -it('should call npm start if dependencies are installed', () => { +it('should call start webpack dev server if dependencies are installed', () => { // this means it has node_modules folder; existsSync.mockReturnValueOnce(true); @@ -36,7 +37,7 @@ it('should call npm start if dependencies are installed', () => { expect(existsSync).toHaveBeenCalledWith('node_modules/'); /// expect(execMock).toHaveBeenCalledTimes(1); - expect(execMock).toHaveBeenCalledWith('npm start', {"silent": true}); + expect(execMock).toHaveBeenCalledWith('./node_modules/.bin/webpack-dev-server --mode development', {"silent": true}); }); it('should call npm install if dependencies aren\'t installed', () => { @@ -50,3 +51,11 @@ it('should call npm install if dependencies aren\'t installed', () => { expect(execMock).toHaveBeenCalledTimes(1); expect(execMock).toHaveBeenCalledWith('npm install', {"silent": true}); }); + +it('if port is set should call start webpack dev server with port', () => { + // this means it has node_modules folder; + existsSync.mockReturnValueOnce(true); + cli(true, 4000); + expect(execMock).toHaveBeenCalledTimes(1); + expect(execMock).toHaveBeenCalledWith('./node_modules/.bin/webpack-dev-server --mode development --port 4000', {"silent": true}); +}) diff --git a/src/metaflux-cli/run/options.js b/src/metaflux-cli/run/options.js index 9bc167c..2f70489 100644 --- a/src/metaflux-cli/run/options.js +++ b/src/metaflux-cli/run/options.js @@ -6,6 +6,6 @@ module.exports = [ }, { name: 'port', - command: ['-p, --port', 'set the port for subcommand run'] + command: ['-p, --port ', 'set the port for subcommand run'] } ]