Skip to content

Commit

Permalink
[npm publish] - npm publish 2020.5.31
Browse files Browse the repository at this point in the history
- replace process.cwd() with path.resolve()
- replace function fsReadFileOrEmptyStringSync with fsReadFileOrDefaultSync
- remove dependency to file lib.swgg.js
- istanbul - inline function templateRender
  • Loading branch information
kai.zhu committed Jun 2, 2020
1 parent 3298cfe commit e8708ea
Show file tree
Hide file tree
Showing 4 changed files with 926 additions and 724 deletions.
205 changes: 107 additions & 98 deletions README.md
@@ -1,5 +1,5 @@
# istanbul-lite
this zero-dependency package will provide a browser-compatible version of the istanbul (v0.4.5) coverage-tool, with a working web-demo
this zero-dependency package will provide browser-compatible version of istanbul coverage-tool (v0.4.5), with working web-demo

# live web 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)
Expand Down Expand Up @@ -55,15 +55,16 @@ this zero-dependency package will provide a browser-compatible version of the is
#### cli help
![screenshot](https://kaizhu256.github.io/node-istanbul-lite/build/screenshot.npmPackageCliHelp.svg)

#### changelog 2020.5.25
- npm publish 2020.5.25
- istanbul - rename __coverageCodeDict__ to __coverageInclude__
- istanbul - inline function coverageReportCreate
- remove excessive "the" from comments
- update build
#### changelog 2020.5.31
- npm publish 2020.5.31
- replace process.cwd() with path.resolve()
- replace function fsReadFileOrEmptyStringSync with fsReadFileOrDefaultSync
- remove dependency to file lib.swgg.js
- istanbul - inline function templateRender
- none

#### todo
- istanbul - inline function templateRender
- istanbul - remove filesUnderRoot subroutine
- none

Expand Down Expand Up @@ -121,9 +122,10 @@ instruction



/* istanbul instrument in package istanbul */
// assets.utility2.header.js - start
/* istanbul ignore next */
/* jslint utility2:true */
/* istanbul ignore next */
(function (globalThis) {
"use strict";
let consoleError;
Expand Down Expand Up @@ -207,9 +209,32 @@ instruction
}
return arg;
};
local.fsRmrfSync = function (dir) {
local.fsReadFileOrDefaultSync = function (pathname, type, dflt) {
/*
* this function will sync-read <pathname> with given <type> and <dflt>
*/
let fs;
// do nothing if module does not exist
try {
fs = require("fs");
} catch (ignore) {
return dflt;
}
pathname = require("path").resolve(pathname);
// try to read pathname
try {
return (
type === "json"
? JSON.parse(fs.readFileSync(pathname, "utf8"))
: fs.readFileSync(pathname, type)
);
} catch (ignore) {
return dflt;
}
};
local.fsRmrfSync = function (pathname) {
/*
* this function will sync "rm -rf" <dir>
* this function will sync "rm -rf" <pathname>
*/
let child_process;
// do nothing if module does not exist
Expand All @@ -218,46 +243,57 @@ instruction
} catch (ignore) {
return;
}
child_process.spawnSync("rm", [
"-rf", dir
], {
stdio: [
"ignore", 1, 2
]
});
pathname = require("path").resolve(pathname);
if (process.platform !== "win32") {
child_process.spawnSync("rm", [
"-rf", pathname
], {
stdio: [
"ignore", 1, 2
]
});
return;
}
try {
child_process.spawnSync("rd", [
"/s", "/q", pathname
], {
stdio: [
"ignore", 1, "ignore"
]
});
} catch (ignore) {}
};
local.fsWriteFileWithMkdirpSync = function (file, data) {
local.fsWriteFileWithMkdirpSync = function (pathname, data, msg) {
/*
* this function will sync write <data> to <file> with "mkdir -p"
* this function will sync write <data> to <pathname> with "mkdir -p"
*/
let fs;
let success;
// do nothing if module does not exist
try {
fs = require("fs");
} catch (ignore) {
return;
}
// try to write file
pathname = require("path").resolve(pathname);
// try to write pathname
try {
fs.writeFileSync(file, data);
return true;
fs.writeFileSync(pathname, data);
success = true;
} catch (ignore) {
// mkdir -p
fs.mkdirSync(require("path").dirname(file), {
fs.mkdirSync(require("path").dirname(pathname), {
recursive: true
});
// rewrite file
fs.writeFileSync(file, data);
return true;
// re-write pathname
fs.writeFileSync(pathname, data);
success = true;
}
};
local.functionOrNop = function (fnc) {
/*
* this function will if <fnc> exists,
* return <fnc>,
* else return <nop>
*/
return fnc || local.nop;
if (success && msg) {
console.error(msg.replace("{{pathname}}", pathname));
}
return success;
};
local.identity = function (val) {
/*
Expand All @@ -271,42 +307,33 @@ instruction
*/
return;
};
local.objectAssignDefault = function (target, source) {
local.objectAssignDefault = function (tgt = {}, src = {}, depth = 0) {
/*
* this function will if items from <target> are null, undefined, or "",
* then overwrite them with items from <source>
* this function will if items from <tgt> are null, undefined, or "",
* then overwrite them with items from <src>
*/
target = target || {};
Object.keys(source || {}).forEach(function (key) {
if (
target[key] === null
|| target[key] === undefined
|| target[key] === ""
) {
target[key] = target[key] || source[key];
}
});
return target;
};
local.querySelector = function (selectors) {
/*
* this function will return first dom-elem that match <selectors>
*/
return (
typeof document === "object" && document
&& typeof document.querySelector === "function"
&& document.querySelector(selectors)
) || {};
};
local.querySelectorAll = function (selectors) {
/*
* this function will return dom-elem-list that match <selectors>
*/
return (
typeof document === "object" && document
&& typeof document.querySelectorAll === "function"
&& Array.from(document.querySelectorAll(selectors))
) || [];
let recurse;
recurse = function (tgt, src, depth) {
Object.entries(src).forEach(function ([
key, bb
]) {
let aa;
aa = tgt[key];
if (aa === undefined || aa === null || aa === "") {
tgt[key] = bb;
return;
}
if (
depth !== 0
&& typeof aa === "object" && aa && !Array.isArray(aa)
&& typeof bb === "object" && bb && !Array.isArray(bb)
) {
recurse(aa, bb, depth - 1);
}
});
};
recurse(tgt, src, depth | 0);
return tgt;
};
// require builtin
if (!local.isBrowser) {
Expand Down Expand Up @@ -363,8 +390,8 @@ globalThis.local = local;



/* istanbul ignore next */
// run browser js-env code - init-test
/* istanbul ignore next */
(function () {
if (!local.isBrowser) {
return;
Expand All @@ -373,7 +400,7 @@ if (!local.isBrowser) {
["error", "log"].forEach(function (key) {
let elem;
let fnc;
elem = local.querySelector("#outputStdout1");
elem = document.querySelector("#outputStdout1");
if (!elem) {
return;
}
Expand Down Expand Up @@ -401,6 +428,7 @@ globalThis.domOnEventDelegateDict = local;


// run node js-env code - init-test
/* istanbul ignore next */
(function () {
if (local.isBrowser) {
return;
Expand All @@ -409,19 +437,6 @@ if (local.isBrowser) {
module.exports = local;
// init assetsDict
local.assetsDict = local.assetsDict || {};
[
"assets.swgg.swagger.json",
"assets.swgg.swagger.server.json"
].forEach(function (file) {
file = "/" + file;
local.assetsDict[file] = local.assetsDict[file] || "";
if (local.fs.existsSync(local.__dirname + file)) {
local.assetsDict[file] = local.fs.readFileSync(
local.__dirname + file,
"utf8"
);
}
});
/* jslint ignore:start */
local.assetsDict["/assets.index.template.html"] = '\
<!doctype html>\n\
Expand Down Expand Up @@ -590,7 +605,7 @@ pre {\n\
switch (gotoState) {\n\
// ajaxProgress - show\n\
case 1:\n\
// init <timerInterval> and <timerTimeout>\n\
// init timerInterval and timerTimeout\n\
if (!timerTimeout) {\n\
timeStart = Date.now();\n\
timerInterval = setInterval(opt, 2000, 1, onError);\n\
Expand Down Expand Up @@ -642,12 +657,12 @@ pre {\n\
+ (tmp - timeStart)\n\
+ " ms"\n\
);\n\
// cleanup <timerInterval> and <timerTimeout>\n\
// cleanup timerInterval and timerTimeout\n\
timeStart = tmp;\n\
clearInterval(timerInterval);\n\
timerInterval = null;\n\
timerInterval = undefined;\n\
clearTimeout(timerTimeout);\n\
timerTimeout = null;\n\
timerTimeout = undefined;\n\
// hide ajaxProgressBar\n\
styleBar.background = "transparent";\n\
// hide ajaxProgressModal\n\
Expand All @@ -670,7 +685,7 @@ pre {\n\
opt.cnt = 0;\n\
window.domOnEventAjaxProgressUpdate(2, onError);\n\
};\n\
// init <styleBar>\n\
// init styleBar\n\
styleBar = document.getElementById("domElementAjaxProgressBar1").style;\n\
styleBar0 = Object.assign({}, styleBar);\n\
Object.entries({\n\
Expand All @@ -687,7 +702,7 @@ pre {\n\
}).forEach(function (entry) {\n\
styleBar[entry[0]] = styleBar[entry[0]] || entry[1];\n\
});\n\
// init <styleModal>\n\
// init styleModal\n\
styleModal = document.getElementById("domElementAjaxProgressModal1") || {};\n\
styleModal = styleModal.style || {};\n\
styleModal0 = Object.assign({}, styleModal);\n\
Expand Down Expand Up @@ -969,7 +984,7 @@ utility2-comment -->\n\
local.assetsDict["/assets.istanbul.js"] = (
local.assetsDict["/assets.istanbul.js"]
|| local.fs.readFileSync(
local.__dirname + "/lib.istanbul.js",
local.path.resolve(local.__dirname + "/lib.istanbul.js"),
"utf8"
).replace((
/^#!\//
Expand Down Expand Up @@ -1047,18 +1062,12 @@ local.http.createServer(function (req, res) {
1. [https://kaizhu256.github.io/node-istanbul-lite/build/screenshot.buildCi.browser.%252Ftmp%252Fbuild%252Ftest-report.html.png](https://kaizhu256.github.io/node-istanbul-lite/build/screenshot.buildCi.browser.%252Ftmp%252Fbuild%252Ftest-report.html.png)
[![screenshot](https://kaizhu256.github.io/node-istanbul-lite/build/screenshot.buildCi.browser.%252Ftmp%252Fbuild%252Ftest-report.html.png)](https://kaizhu256.github.io/node-istanbul-lite/build/screenshot.buildCi.browser.%252Ftmp%252Fbuild%252Ftest-report.html.png)

1. [https://kaizhu256.github.io/node-istanbul-lite/build/screenshot.deployGithub.browser.%252Fnode-istanbul-lite%252Fbuild%252Fapp%252Fassets.swgg.html.png](https://kaizhu256.github.io/node-istanbul-lite/build/screenshot.deployGithub.browser.%252Fnode-istanbul-lite%252Fbuild%252Fapp%252Fassets.swgg.html.png)
[![screenshot](https://kaizhu256.github.io/node-istanbul-lite/build/screenshot.deployGithub.browser.%252Fnode-istanbul-lite%252Fbuild%252Fapp%252Fassets.swgg.html.png)](https://kaizhu256.github.io/node-istanbul-lite/build/screenshot.deployGithub.browser.%252Fnode-istanbul-lite%252Fbuild%252Fapp%252Fassets.swgg.html.png)

1. [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/screenshot.deployGithub.browser.%252Fnode-istanbul-lite%252Fbuild%252Fapp.png)
[![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/screenshot.deployGithub.browser.%252Fnode-istanbul-lite%252Fbuild%252Fapp.png)

1. [https://kaizhu256.github.io/node-istanbul-lite/build/screenshot.deployGithubTest.browser.%252Fnode-istanbul-lite%252Fbuild%252Fapp.png](https://kaizhu256.github.io/node-istanbul-lite/build/screenshot.deployGithubTest.browser.%252Fnode-istanbul-lite%252Fbuild%252Fapp.png)
[![screenshot](https://kaizhu256.github.io/node-istanbul-lite/build/screenshot.deployGithubTest.browser.%252Fnode-istanbul-lite%252Fbuild%252Fapp.png)](https://kaizhu256.github.io/node-istanbul-lite/build/screenshot.deployGithubTest.browser.%252Fnode-istanbul-lite%252Fbuild%252Fapp.png)

1. [https://kaizhu256.github.io/node-istanbul-lite/build/screenshot.deployHeroku.browser.%252Fassets.swgg.html.png](https://kaizhu256.github.io/node-istanbul-lite/build/screenshot.deployHeroku.browser.%252Fassets.swgg.html.png)
[![screenshot](https://kaizhu256.github.io/node-istanbul-lite/build/screenshot.deployHeroku.browser.%252Fassets.swgg.html.png)](https://kaizhu256.github.io/node-istanbul-lite/build/screenshot.deployHeroku.browser.%252Fassets.swgg.html.png)

1. [https://kaizhu256.github.io/node-istanbul-lite/build/screenshot.deployHeroku.browser.%252F.png](https://kaizhu256.github.io/node-istanbul-lite/build/screenshot.deployHeroku.browser.%252F.png)
[![screenshot](https://kaizhu256.github.io/node-istanbul-lite/build/screenshot.deployHeroku.browser.%252F.png)](https://kaizhu256.github.io/node-istanbul-lite/build/screenshot.deployHeroku.browser.%252F.png)

Expand All @@ -1083,7 +1092,7 @@ local.http.createServer(function (req, res) {
"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, with a working web-demo",
"description": "this zero-dependency package will provide browser-compatible version of istanbul coverage-tool (v0.4.5), with working web-demo",
"devDependencies": {
"electron-lite": "kaizhu256/node-electron-lite#alpha",
"utility2": "kaizhu256/node-utility2#alpha"
Expand Down Expand Up @@ -1121,7 +1130,7 @@ local.http.createServer(function (req, res) {
"test": "./npm_scripts.sh",
"utility2": "./npm_scripts.sh"
},
"version": "2020.5.25"
"version": "2020.5.31"
}
```

Expand Down

0 comments on commit e8708ea

Please sign in to comment.