From ef1be4d95b77958dd586afa81919ba22aa22c86a Mon Sep 17 00:00:00 2001 From: kai zhu Date: Thu, 5 Oct 2017 15:59:13 +0800 Subject: [PATCH] [npm publish] - npm publish 2017.10.4 - add cli-help doc to README.md --- .travis.yml | 4 +- README.md | 76 +++++++++++++---------- lib.istanbul.js | 121 ++++++++++++++++++++++++------------- package.json | 6 +- test.js | 157 ++---------------------------------------------- 5 files changed, 135 insertions(+), 229 deletions(-) diff --git a/.travis.yml b/.travis.yml index d97b06493..18dc79cf9 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,14 +1,16 @@ before_install: # init xvfb # http://docs.travis-ci.com/user/gui-and-headless-browsers/ - - "export DISPLAY=:99.0 && sh -e /etc/init.d/xvfb start" + - export DISPLAY=:99.0 && sh -e /etc/init.d/xvfb start branches: only: - alpha - beta - cron - docker.base + - docker.electron - docker.latest + - docker.tmp - master - publish - task diff --git a/README.md b/README.md index bb33cea27..c1e1ca7e9 100644 --- a/README.md +++ b/README.md @@ -1,8 +1,13 @@ # istanbul-lite -this zero-dependency package will provide a browser-compatible version of the istanbul v0.4.5 coverage-tool +this zero-dependency package will provide a browser-compatible version of the istanbul (v0.4.5) coverage-tool + +# live demo +- [https://kaizhu256.github.io/node-istanbul-lite/build..beta..travis-ci.org/app](https://kaizhu256.github.io/node-istanbul-lite/build..beta..travis-ci.org/app) [![screenshot](https://kaizhu256.github.io/node-istanbul-lite/build/screenshot.deployGithub.browser.%252Fnode-istanbul-lite%252Fbuild%252Fapp.png)](https://kaizhu256.github.io/node-istanbul-lite/build..beta..travis-ci.org/app) + + [![travis-ci.org build-status](https://api.travis-ci.org/kaizhu256/node-istanbul-lite.svg)](https://travis-ci.org/kaizhu256/node-istanbul-lite) [![coverage](https://kaizhu256.github.io/node-istanbul-lite/build/coverage.badge.svg)](https://kaizhu256.github.io/node-istanbul-lite/build/coverage.html/index.html) [![snyk.io vulnerabilities](https://snyk.io/test/github/kaizhu256/node-istanbul-lite/badge.svg)](https://snyk.io/test/github/kaizhu256/node-istanbul-lite) [![NPM](https://nodei.co/npm/istanbul-lite.png?downloads=true)](https://www.npmjs.com/package/istanbul-lite) @@ -25,7 +30,6 @@ this zero-dependency package will provide a browser-compatible version of the is # table of contents 1. [cdn download](#cdn-download) -1. [live demo](#live-demo) 1. [documentation](#documentation) 1. [quickstart standalone app](#quickstart-standalone-app) 1. [quickstart example.js](#quickstart-examplejs) @@ -42,15 +46,11 @@ this zero-dependency package will provide a browser-compatible version of the is -# live demo -- [https://kaizhu256.github.io/node-istanbul-lite/build..beta..travis-ci.org/app](https://kaizhu256.github.io/node-istanbul-lite/build..beta..travis-ci.org/app) - -[![screenshot](https://kaizhu256.github.io/node-istanbul-lite/build/screenshot.deployGithub.browser.%252Fnode-istanbul-lite%252Fbuild%252Fapp.png)](https://kaizhu256.github.io/node-istanbul-lite/build..beta..travis-ci.org/app) - - - # documentation -#### apidoc +#### cli help +![screenshot](https://kaizhu256.github.io/node-istanbul-lite/build/screenshot.npmPackageCliHelp.svg) + +#### api doc - [https://kaizhu256.github.io/node-istanbul-lite/build..beta..travis-ci.org/apidoc.html](https://kaizhu256.github.io/node-istanbul-lite/build..beta..travis-ci.org/apidoc.html) [![apidoc](https://kaizhu256.github.io/node-istanbul-lite/build/screenshot.buildCi.browser.%252Ftmp%252Fbuild%252Fapidoc.html.png)](https://kaizhu256.github.io/node-istanbul-lite/build..beta..travis-ci.org/apidoc.html) @@ -58,18 +58,16 @@ this zero-dependency package will provide a browser-compatible version of the is #### todo - none -#### changelog for v2017.9.1 -- npm publish 2017.9.1 -- add cli help command -- normalize local.fs module hook -- update README.md +#### changelog for v2017.10.4 +- npm publish 2017.10.4 +- add cli-help doc to README.md - none #### this package requires - darwin or linux os #### additional info -- istanbul code derived from https://github.com/gotwarlost/istanbul/tree/v0.2.16 +- istanbul code derived from https://github.com/gotwarlost/istanbul/tree/v0.4.5 @@ -168,8 +166,7 @@ instruction - // init-after - // run browser js-env code - init-after + // run browser js-env code - init-test /* istanbul ignore next */ case 'browser': local.testRunBrowser = function (event) { @@ -277,7 +274,7 @@ instruction - // run node js-env code - init-after + // run node js-env code - init-test /* istanbul ignore next */ case 'node': // init exports @@ -351,7 +348,6 @@ textarea[readonly] {\n\ \n\ \n\ \n\ -\n\

\n\ \n\ return 'the greatest app in the world!'; case 'npm_package_name': return 'istanbul-lite'; - case 'npm_package_nameAlias': + case 'npm_package_nameLib': return 'istanbul'; case 'npm_package_version': return '0.0.1'; @@ -490,7 +505,7 @@ utility2-comment -->\n\ return match0; } }); - // run the cli + // init cli if (module !== require.main || local.global.utility2_rollup) { break; } @@ -571,9 +586,6 @@ utility2-comment -->\n\ 1. [https://kaizhu256.github.io/node-istanbul-lite/build/screenshot.npmTest.browser.%252F.png](https://kaizhu256.github.io/node-istanbul-lite/build/screenshot.npmTest.browser.%252F.png) [![screenshot](https://kaizhu256.github.io/node-istanbul-lite/build/screenshot.npmTest.browser.%252F.png)](https://kaizhu256.github.io/node-istanbul-lite/build/screenshot.npmTest.browser.%252F.png) -1. [https://kaizhu256.github.io/node-istanbul-lite/build/screenshot.npmTestPublished.browser.%252F.png](https://kaizhu256.github.io/node-istanbul-lite/build/screenshot.npmTestPublished.browser.%252F.png) -[![screenshot](https://kaizhu256.github.io/node-istanbul-lite/build/screenshot.npmTestPublished.browser.%252F.png)](https://kaizhu256.github.io/node-istanbul-lite/build/screenshot.npmTestPublished.browser.%252F.png) - 1. [https://kaizhu256.github.io/node-istanbul-lite/build/screenshot.testExampleJs.browser.%252F.png](https://kaizhu256.github.io/node-istanbul-lite/build/screenshot.testExampleJs.browser.%252F.png) [![screenshot](https://kaizhu256.github.io/node-istanbul-lite/build/screenshot.testExampleJs.browser.%252F.png)](https://kaizhu256.github.io/node-istanbul-lite/build/screenshot.testExampleJs.browser.%252F.png) @@ -589,7 +601,7 @@ utility2-comment -->\n\ "bin": { "istanbul-lite": "lib.istanbul.js" }, - "description": "this zero-dependency package will provide a browser-compatible version of the istanbul v0.4.5 coverage-tool", + "description": "this zero-dependency package will provide a browser-compatible version of the istanbul (v0.4.5) coverage-tool", "devDependencies": { "electron-lite": "kaizhu256/node-electron-lite#alpha", "utility2": "kaizhu256/node-utility2#alpha" @@ -606,7 +618,7 @@ utility2-comment -->\n\ "license": "MIT", "main": "lib.istanbul.js", "name": "istanbul-lite", - "nameAlias": "istanbul", + "nameLib": "istanbul", "nameOriginal": "istanbul-lite", "os": [ "darwin", @@ -624,7 +636,7 @@ utility2-comment -->\n\ "start": "PORT=${PORT:-8080} utility2 start test.js", "test": "PORT=$(utility2 shServerPortRandom) utility2 test test.js" }, - "version": "2017.9.1" + "version": "2017.10.4" } ``` diff --git a/lib.istanbul.js b/lib.istanbul.js index a30e179b2..1a57145d8 100755 --- a/lib.istanbul.js +++ b/lib.istanbul.js @@ -67,12 +67,18 @@ // run shared js-env code - function-before /* istanbul ignore next */ (function () { - local.cliInit = function () { + local.cliRun = function (fnc) { /* - * this function will init the cli + * this function will run the cli */ - local.cliDict = local.cliDict || {}; - local.cliDict['--eval'] = local.cliDict['-e'] = function () { + var nop; + nop = function () { + /* + * this function will do nothing + */ + return; + }; + local.cliDict._eval = local.cliDict._eval || function () { /* * code * eval code @@ -80,51 +86,86 @@ local.global.local = local; require('vm').runInThisContext(process.argv[3]); }; - local.cliDict['--help'] = local.cliDict['-h'] = local.cliDict.help = function () { + local.cliDict['--eval'] = local.cliDict['--eval'] || local.cliDict._eval; + local.cliDict['-e'] = local.cliDict['-e'] || local.cliDict._eval; + local.cliDict._help = local.cliDict._help || function () { /* * [none] - * print this help-text + * print help */ - var element, result, lengthList; - result = [['[command]', '[arguments]', '[description]']]; + var element, result, lengthList, sortDict; + sortDict = {}; + result = [['[command]', '[args]', '[description]', -1]]; lengthList = [result[0][0].length, result[0][1].length]; - Object.keys(local.cliDict).sort().forEach(function (key) { + Object.keys(local.cliDict).sort().forEach(function (key, ii) { + if (key[0] === '_' && key !== '_default') { + return; + } + sortDict[local.cliDict[key].toString()] = + sortDict[local.cliDict[key].toString()] || (ii + 1); element = (/\n +\*(.*)\n +\*(.*)/).exec(local.cliDict[key].toString()); // coverage-hack - ignore else-statement - local.nop(local.global.__coverage__ && (function () { + nop(local.global.__coverage__ && (function () { element = element || ['', '', '']; }())); - element = [key + ' ', element[1].trim() + ' ', element[2].trim() + ' ']; + element = [ + key.replace('_default', '[none]') + ' ', + element[1].trim() + ' ', + element[2].trim(), + (sortDict[local.cliDict[key].toString()] << 8) + ii + ]; result.push(element); lengthList.forEach(function (length, jj) { lengthList[jj] = Math.max(element[jj].length, length); }); }); - console.log('usage: ' + __filename + ' [command] [arguments]\n'); - console.log(result.map(function (element, ii) { + result.sort(function (aa, bb) { + return aa[3] < bb[3] + ? -1 + : 1; + }); + console.log('usage: ' + __filename + ' [command] [args]'); + console.log('example: ' + __filename + ' --eval ' + + '"console.log(\'hello world\')"\n'); + result.forEach(function (element, ii) { lengthList.forEach(function (length, jj) { while (element[jj].length < length) { element[jj] += '-'; } }); - element = element.join('-- '); + element = element.slice(0, 3).join('---- '); if (ii === 0) { element = element.replace((/-/g), ' '); } - return element; - }).join('\n')); + console.log(element); + }); }; - // coverage-hack - ignore else-statement - local.nop(typeof local.replStart === 'function' && (function () { - local.cliDict['--interactive'] = local.cliDict['-i'] = function () { - /* - * [none] - * start interactive-mode - */ - local.global.local = local; - local.replStart(); - }; - }())); + local.cliDict['--help'] = local.cliDict['--help'] || local.cliDict._help; + local.cliDict['-h'] = local.cliDict['-h'] || local.cliDict._help; + local.cliDict._default = local.cliDict._default || local.cliDict._help; + local.cliDict.help = local.cliDict.help || local.cliDict._help; + local.cliDict._interactive = local.cliDict._interactive || function () { + /* + * [none] + * start interactive-mode + */ + local.global.local = local; + local.replStart(); + }; + if (local.replStart) { + local.cliDict['--interactive'] = local.cliDict['--interactive'] || + local.cliDict._interactive; + local.cliDict['-i'] = local.cliDict['-i'] || local.cliDict._interactive; + } + // run fnc() + fnc = fnc || function () { + if (local.cliDict[process.argv[2]]) { + local.cliDict[process.argv[2]](); + return; + } + local.cliDict._default(); + }; + fnc(); }; local.fsWriteFileWithMkdirpSync = function (file, data) { @@ -354,14 +395,14 @@ local.instrumentInPackage = function (code, file) { /* * this function will instrument the code - * only if the macro /\* istanbul instrument in package $npm_package_nameAlias *\/ + * only if the macro /\* istanbul instrument in package $npm_package_nameLib *\/ * exists in the code */ return process.env.npm_config_mode_coverage && code.indexOf('/* istanbul ignore all */\n') < 0 && ( process.env.npm_config_mode_coverage === 'all' || code.indexOf('/* istanbul instrument in package ' + - process.env.npm_package_nameAlias + ' */\n') >= 0 || + process.env.npm_package_nameLib + ' */\n') >= 0 || code.indexOf('/* istanbul instrument in package ' + process.env.npm_config_mode_coverage + ' */\n') >= 0 ) @@ -2597,11 +2638,11 @@ local.templateCoverageBadgeSvg = // run node js-env code - init-after /* istanbul ignore next */ case 'node': - // run the cli + // init cli if (module !== local.require.main || local.global.utility2_rollup) { break; } - local.cliInit(); + local.cliDict = {}; local.cliDict.cover = function () { /* * script @@ -2610,13 +2651,13 @@ local.templateCoverageBadgeSvg = var tmp; try { tmp = JSON.parse(local.fs.readFileSync('package.json', 'utf8')); - process.env.npm_package_nameAlias = process.env.npm_package_nameAlias || - tmp.nameAlias || + process.env.npm_package_nameLib = process.env.npm_package_nameLib || + tmp.nameLib || tmp.name.replace((/-/g), '_'); } catch (ignore) { } process.env.npm_config_mode_coverage = process.env.npm_config_mode_coverage || - process.env.npm_package_nameAlias || + process.env.npm_package_nameLib || 'all'; // add coverage hook to require local._istanbul_moduleExtensionsJs = local._istanbul_module._extensions['.js']; @@ -2642,7 +2683,7 @@ local.templateCoverageBadgeSvg = process.on('exit', function () { local.coverageReportCreate({ coverage: local.global.__coverage__ }); }); - // re-run the cli + // re-init cli local._istanbul_module.runMain(); }; local.cliDict.instrument = function () { @@ -2660,23 +2701,21 @@ local.templateCoverageBadgeSvg = local.cliDict.test = function () { /* * script - * run and cover the script if $npm_config_mode_coverage is set + * run and cover the script if env var $npm_config_mode_coverage is set */ if (process.env.npm_config_mode_coverage) { process.argv[2] = 'cover'; - // re-run the cli + // re-init cli local.cliDict[process.argv[2]](); return; } // init process.argv process.argv.splice(1, 2); process.argv[1] = local.path.resolve(process.cwd(), process.argv[1]); - // re-run the cli + // re-init cli local._istanbul_module.runMain(); }; - if (local.cliDict[process.argv[2]]) { - local.cliDict[process.argv[2]](); - } + local.cliRun(); break; } }()); diff --git a/package.json b/package.json index 31b8d03e9..bb0bf82af 100644 --- a/package.json +++ b/package.json @@ -3,7 +3,7 @@ "bin": { "istanbul-lite": "lib.istanbul.js" }, - "description": "this zero-dependency package will provide a browser-compatible version of the istanbul v0.4.5 coverage-tool", + "description": "this zero-dependency package will provide a browser-compatible version of the istanbul (v0.4.5) coverage-tool", "devDependencies": { "electron-lite": "kaizhu256/node-electron-lite#alpha", "utility2": "kaizhu256/node-utility2#alpha" @@ -20,7 +20,7 @@ "license": "MIT", "main": "lib.istanbul.js", "name": "istanbul-lite", - "nameAlias": "istanbul", + "nameLib": "istanbul", "nameOriginal": "istanbul-lite", "os": [ "darwin", @@ -38,5 +38,5 @@ "start": "PORT=${PORT:-8080} utility2 start test.js", "test": "PORT=$(utility2 shServerPortRandom) utility2 test test.js" }, - "version": "2017.9.1" + "version": "2017.10.4" } diff --git a/test.js b/test.js index e370e9c32..7708c1c65 100644 --- a/test.js +++ b/test.js @@ -37,22 +37,11 @@ local.global = local.modeJs === 'browser' ? window : global; - switch (local.modeJs) { - // re-init local from window.local - case 'browser': - local = local.global.utility2.objectSetDefault( - local.global.utility2_rollup || local.global.local, - local.global.utility2 - ); - break; - // re-init local from example.js - case 'node': - local = (local.global.utility2_rollup || - require('utility2')).requireReadme(); - break; - } - // init exports - local.global.local = local; + // re-init local + local = local.global.local = (local.global.utility2 || + require('utility2')).requireReadme(); + // init test + local.testRunInit(local); }()); @@ -599,12 +588,6 @@ factorial(100) - // run browser js-env code - function - case 'browser': - break; - - - // run node js-env code - function case 'node': local.testCase_istanbulCoverageMerge_default = function (options, onError) { @@ -659,134 +642,4 @@ local.assertJsonEqual(options.coverage1, }; break; } - - - - // run shared js-env code - init-after - (function () { - return; - }()); - switch (local.modeJs) { - - - - // run browser js-env code - init-after - /* istanbul ignore next */ - case 'browser': - local.testCase_browser_nullCase = local.testCase_browser_nullCase || function ( - options, - onError - ) { - /* - * this function will test browser's null-case handling-behavior - */ - onError(null, options); - }; - - local.utility2.ajaxForwardProxyUrlTest = local.utility2.ajaxForwardProxyUrlTest || - function (url, location) { - /* - * this function will test if the url requires forward-proxy - */ - // jslint-hack - local.nop(url); - return local.env.npm_package_nameAlias && (/\bgithub.io$/).test(location.host) - ? 'https://h1-' + local.env.npm_package_nameAlias + '-alpha.herokuapp.com' - : location.protocol + '//' + location.host; - }; - - // run tests - if (local.modeTest && document.querySelector('#testRunButton1')) { - document.querySelector('#testRunButton1').click(); - } - break; - - - - // run node js-env code - init-after - /* istanbul ignore next */ - case 'node': - local.testCase_buildApidoc_default = local.testCase_buildApidoc_default || function ( - options, - onError - ) { - /* - * this function will test buildApidoc's default handling-behavior - */ - options = { modulePathList: module.paths }; - local.buildApidoc(options, onError); - }; - - local.testCase_buildApp_default = local.testCase_buildApp_default || function ( - options, - onError - ) { - /* - * this function will test buildApp's default handling-behavior - */ - local.testCase_buildReadme_default(options, local.onErrorThrow); - local.testCase_buildLib_default(options, local.onErrorThrow); - local.testCase_buildTest_default(options, local.onErrorThrow); - local.testCase_buildCustomOrg_default(options, local.onErrorThrow); - options = []; - local.buildApp(options, onError); - }; - - local.testCase_buildCustomOrg_default = local.testCase_buildCustomOrg_default || - function (options, onError) { - /* - * this function will test buildCustomOrg's default handling-behavior - */ - options = {}; - local.buildCustomOrg(options, onError); - }; - - local.testCase_buildLib_default = local.testCase_buildLib_default || function ( - options, - onError - ) { - /* - * this function will test buildLib's default handling-behavior - */ - options = {}; - local.buildLib(options, onError); - }; - - local.testCase_buildReadme_default = local.testCase_buildReadme_default || function ( - options, - onError - ) { - /* - * this function will test buildReadme's default handling-behavior - */ - options = {}; - local.buildReadme(options, onError); - }; - - local.testCase_buildTest_default = local.testCase_buildTest_default || function ( - options, - onError - ) { - /* - * this function will test buildTest's default handling-behavior - */ - options = {}; - local.buildTest(options, onError); - }; - - local.testCase_webpage_default = local.testCase_webpage_default || function ( - options, - onError - ) { - /* - * this function will test webpage's default handling-behavior - */ - options = { modeCoverageMerge: true, url: local.serverLocalHost + '?modeTest=1' }; - local.browserTest(options, onError); - }; - - // run test-server - local.testRunServer(local); - break; - } }());