@jdeighan/coffee-utils 4.1.19 → 4.1.23
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +3 -3
- package/src/coffee_utils.coffee +0 -22
- package/src/coffee_utils.js +0 -25
- package/src/debug_utils.coffee +15 -4
- package/src/debug_utils.js +17 -6
- package/src/external.coffee +24 -0
- package/src/external.js +26 -0
package/package.json
CHANGED
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@jdeighan/coffee-utils",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "4.1.
|
|
4
|
+
"version": "4.1.23",
|
|
5
5
|
"description": "A set of utility functions for CoffeeScript",
|
|
6
6
|
"main": "coffee_utils.js",
|
|
7
7
|
"exports": {
|
|
8
8
|
".": "./src/coffee_utils.js",
|
|
9
|
+
"./external": "./src/external.js",
|
|
9
10
|
"./fs": "./src/fs_utils.js",
|
|
10
11
|
"./log": "./src/log_utils.js",
|
|
11
12
|
"./block": "./src/block_utils.js",
|
|
@@ -24,8 +25,7 @@
|
|
|
24
25
|
},
|
|
25
26
|
"scripts": {
|
|
26
27
|
"build": "cls && rm -f ./src/*.js && coffee -c ./src",
|
|
27
|
-
"
|
|
28
|
-
"pretest": "cls && coffee -c .",
|
|
28
|
+
"pretest": "cls && cielo -qfc ./test && coffee -c ./test",
|
|
29
29
|
"test": "ava ./test/*.test.js",
|
|
30
30
|
"prefinaltest": "npm run pretest",
|
|
31
31
|
"finaltest": "cross-env FINALTEST=yes ava ./test/*.test.js"
|
package/src/coffee_utils.coffee
CHANGED
|
@@ -1,24 +1,11 @@
|
|
|
1
1
|
# coffee_utils.coffee
|
|
2
2
|
|
|
3
|
-
import getline from 'readline-sync'
|
|
4
|
-
import {execSync} from 'child_process'
|
|
5
|
-
|
|
6
3
|
import {log} from '@jdeighan/coffee-utils/log'
|
|
7
4
|
|
|
8
5
|
export sep_dash = '-'.repeat(42)
|
|
9
6
|
export sep_eq = '='.repeat(42)
|
|
10
7
|
`export const undef = undefined`
|
|
11
8
|
|
|
12
|
-
# ---------------------------------------------------------------------------
|
|
13
|
-
# exec - run external commands
|
|
14
|
-
|
|
15
|
-
export exec = (cmd) ->
|
|
16
|
-
|
|
17
|
-
buffer = execSync cmd, {
|
|
18
|
-
windowsHide: true
|
|
19
|
-
}
|
|
20
|
-
return buffer.toString()
|
|
21
|
-
|
|
22
9
|
# ---------------------------------------------------------------------------
|
|
23
10
|
# pass - do nothing
|
|
24
11
|
|
|
@@ -261,15 +248,6 @@ export say = (x) ->
|
|
|
261
248
|
console.log x
|
|
262
249
|
return
|
|
263
250
|
|
|
264
|
-
# ---------------------------------------------------------------------------
|
|
265
|
-
# ask - ask a question
|
|
266
|
-
# later, on a web page, prompt the user for answer to question
|
|
267
|
-
|
|
268
|
-
export ask = (prompt) ->
|
|
269
|
-
|
|
270
|
-
answer = getline.question("{prompt}? ")
|
|
271
|
-
return answer
|
|
272
|
-
|
|
273
251
|
# ---------------------------------------------------------------------------
|
|
274
252
|
|
|
275
253
|
export titleLine = (title, char='=', padding=2, linelen=42) ->
|
package/src/coffee_utils.js
CHANGED
|
@@ -2,12 +2,6 @@
|
|
|
2
2
|
// coffee_utils.coffee
|
|
3
3
|
var commentRegExp;
|
|
4
4
|
|
|
5
|
-
import getline from 'readline-sync';
|
|
6
|
-
|
|
7
|
-
import {
|
|
8
|
-
execSync
|
|
9
|
-
} from 'child_process';
|
|
10
|
-
|
|
11
5
|
import {
|
|
12
6
|
log
|
|
13
7
|
} from '@jdeighan/coffee-utils/log';
|
|
@@ -18,16 +12,6 @@ export var sep_eq = '='.repeat(42);
|
|
|
18
12
|
|
|
19
13
|
export const undef = undefined;
|
|
20
14
|
|
|
21
|
-
// ---------------------------------------------------------------------------
|
|
22
|
-
// exec - run external commands
|
|
23
|
-
export var exec = function(cmd) {
|
|
24
|
-
var buffer;
|
|
25
|
-
buffer = execSync(cmd, {
|
|
26
|
-
windowsHide: true
|
|
27
|
-
});
|
|
28
|
-
return buffer.toString();
|
|
29
|
-
};
|
|
30
|
-
|
|
31
15
|
// ---------------------------------------------------------------------------
|
|
32
16
|
// pass - do nothing
|
|
33
17
|
export var pass = function() {};
|
|
@@ -265,15 +249,6 @@ export var say = function(x) {
|
|
|
265
249
|
}
|
|
266
250
|
};
|
|
267
251
|
|
|
268
|
-
// ---------------------------------------------------------------------------
|
|
269
|
-
// ask - ask a question
|
|
270
|
-
// later, on a web page, prompt the user for answer to question
|
|
271
|
-
export var ask = function(prompt) {
|
|
272
|
-
var answer;
|
|
273
|
-
answer = getline.question("{prompt}? ");
|
|
274
|
-
return answer;
|
|
275
|
-
};
|
|
276
|
-
|
|
277
252
|
// ---------------------------------------------------------------------------
|
|
278
253
|
export var titleLine = function(title, char = '=', padding = 2, linelen = 42) {
|
|
279
254
|
var nLeft, nRight, strLeft, strMiddle, strRight, titleLen;
|
package/src/debug_utils.coffee
CHANGED
|
@@ -33,7 +33,7 @@ export resetDebugging = (funcDoDebug=undef, funcDoLog=undef) ->
|
|
|
33
33
|
debugging = false
|
|
34
34
|
debugLevel = 0
|
|
35
35
|
stack.reset()
|
|
36
|
-
shouldDebug = (funcName) ->
|
|
36
|
+
shouldDebug = (funcName, curDebugging) -> curDebugging
|
|
37
37
|
shouldLog = (str) -> debugging
|
|
38
38
|
if funcDoDebug
|
|
39
39
|
setDebugging funcDoDebug, funcDoLog
|
|
@@ -49,8 +49,8 @@ export setDebugging = (funcDoDebug=undef, funcDoLog=undef) ->
|
|
|
49
49
|
debugging = false
|
|
50
50
|
lFuncNames = words(funcDoDebug)
|
|
51
51
|
assert isArray(lFuncNames), "words('#{funcDoDebug}') returned non-array"
|
|
52
|
-
shouldDebug = (funcName) ->
|
|
53
|
-
|
|
52
|
+
shouldDebug = (funcName, curDebugging) ->
|
|
53
|
+
curDebugging || funcMatch(funcName, lFuncNames)
|
|
54
54
|
else if isFunction(funcDoDebug)
|
|
55
55
|
shouldDebug = funcDoDebug
|
|
56
56
|
else
|
|
@@ -126,6 +126,17 @@ getPrefix = (level) ->
|
|
|
126
126
|
|
|
127
127
|
# ---------------------------------------------------------------------------
|
|
128
128
|
|
|
129
|
+
envSaysDebug = (curFunc) ->
|
|
130
|
+
|
|
131
|
+
if process.env.DEBUG_FUNC?
|
|
132
|
+
return curFunc == process.env.DEBUG_FUNC
|
|
133
|
+
else if process.env.DEBUG_FUNCS?
|
|
134
|
+
return process.env.DEBUG_FUNCS.split(',').indexOf(curFunc) > -1
|
|
135
|
+
else
|
|
136
|
+
return false
|
|
137
|
+
|
|
138
|
+
# ---------------------------------------------------------------------------
|
|
139
|
+
|
|
129
140
|
export debug = (lArgs...) ->
|
|
130
141
|
# --- either 1 or 2 args
|
|
131
142
|
|
|
@@ -158,7 +169,7 @@ export debug = (lArgs...) ->
|
|
|
158
169
|
entering = true
|
|
159
170
|
curFunc = lMatches[1]
|
|
160
171
|
stack.call(curFunc, curEnv())
|
|
161
|
-
debugging = shouldDebug(curFunc, debugging)
|
|
172
|
+
debugging = envSaysDebug(curFunc) || shouldDebug(curFunc, debugging)
|
|
162
173
|
else if (lMatches = str.match(///^
|
|
163
174
|
\s*
|
|
164
175
|
return
|
package/src/debug_utils.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
// Generated by CoffeeScript 2.6.1
|
|
2
2
|
// debug_utils.coffee
|
|
3
|
-
var arrow, arrowhead, corner, curEnv, debugLevel, getPrefix, hbar, indent, logger, reMethod, setEnv, shouldDebug, shouldLog, stack, stdLogger, stripArrow, vbar;
|
|
3
|
+
var arrow, arrowhead, corner, curEnv, debugLevel, envSaysDebug, getPrefix, hbar, indent, logger, reMethod, setEnv, shouldDebug, shouldLog, stack, stdLogger, stripArrow, vbar;
|
|
4
4
|
|
|
5
5
|
import {
|
|
6
6
|
assert,
|
|
@@ -63,8 +63,8 @@ export var resetDebugging = function(funcDoDebug = undef, funcDoLog = undef) {
|
|
|
63
63
|
debugging = false;
|
|
64
64
|
debugLevel = 0;
|
|
65
65
|
stack.reset();
|
|
66
|
-
shouldDebug = function(funcName) {
|
|
67
|
-
return
|
|
66
|
+
shouldDebug = function(funcName, curDebugging) {
|
|
67
|
+
return curDebugging;
|
|
68
68
|
};
|
|
69
69
|
shouldLog = function(str) {
|
|
70
70
|
return debugging;
|
|
@@ -83,8 +83,8 @@ export var setDebugging = function(funcDoDebug = undef, funcDoLog = undef) {
|
|
|
83
83
|
debugging = false;
|
|
84
84
|
lFuncNames = words(funcDoDebug);
|
|
85
85
|
assert(isArray(lFuncNames), `words('${funcDoDebug}') returned non-array`);
|
|
86
|
-
shouldDebug = function(funcName) {
|
|
87
|
-
return
|
|
86
|
+
shouldDebug = function(funcName, curDebugging) {
|
|
87
|
+
return curDebugging || funcMatch(funcName, lFuncNames);
|
|
88
88
|
};
|
|
89
89
|
} else if (isFunction(funcDoDebug)) {
|
|
90
90
|
shouldDebug = funcDoDebug;
|
|
@@ -153,6 +153,17 @@ getPrefix = function(level) {
|
|
|
153
153
|
return ' '.repeat(level);
|
|
154
154
|
};
|
|
155
155
|
|
|
156
|
+
// ---------------------------------------------------------------------------
|
|
157
|
+
envSaysDebug = function(curFunc) {
|
|
158
|
+
if (process.env.DEBUG_FUNC != null) {
|
|
159
|
+
return curFunc === process.env.DEBUG_FUNC;
|
|
160
|
+
} else if (process.env.DEBUG_FUNCS != null) {
|
|
161
|
+
return process.env.DEBUG_FUNCS.split(',').indexOf(curFunc) > -1;
|
|
162
|
+
} else {
|
|
163
|
+
return false;
|
|
164
|
+
}
|
|
165
|
+
};
|
|
166
|
+
|
|
156
167
|
// ---------------------------------------------------------------------------
|
|
157
168
|
export var debug = function(...lArgs) {
|
|
158
169
|
var curFunc, entering, hInfo, item, lMatches, nArgs, prefix, returning, str;
|
|
@@ -177,7 +188,7 @@ export var debug = function(...lArgs) {
|
|
|
177
188
|
entering = true;
|
|
178
189
|
curFunc = lMatches[1];
|
|
179
190
|
stack.call(curFunc, curEnv());
|
|
180
|
-
debugging = shouldDebug(curFunc, debugging);
|
|
191
|
+
debugging = envSaysDebug(curFunc) || shouldDebug(curFunc, debugging);
|
|
181
192
|
} else if ((lMatches = str.match(/^\s*return.+from\s+([A-Za-z_][A-Za-z0-9_\.]*)/))) {
|
|
182
193
|
returning = true;
|
|
183
194
|
curFunc = lMatches[1];
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
# external.coffee
|
|
2
|
+
|
|
3
|
+
import getline from 'readline-sync'
|
|
4
|
+
import {execSync} from 'child_process'
|
|
5
|
+
|
|
6
|
+
# ---------------------------------------------------------------------------
|
|
7
|
+
# exec - run external commands
|
|
8
|
+
|
|
9
|
+
export exec = (cmd) ->
|
|
10
|
+
|
|
11
|
+
buffer = execSync cmd, {
|
|
12
|
+
windowsHide: true
|
|
13
|
+
}
|
|
14
|
+
return buffer.toString()
|
|
15
|
+
|
|
16
|
+
# ---------------------------------------------------------------------------
|
|
17
|
+
# ask - ask a question
|
|
18
|
+
# later, on a web page, prompt the user for answer to question
|
|
19
|
+
|
|
20
|
+
export ask = (prompt) ->
|
|
21
|
+
|
|
22
|
+
answer = getline.question("{prompt}? ")
|
|
23
|
+
return answer
|
|
24
|
+
|
package/src/external.js
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
// Generated by CoffeeScript 2.6.1
|
|
2
|
+
// external.coffee
|
|
3
|
+
import getline from 'readline-sync';
|
|
4
|
+
|
|
5
|
+
import {
|
|
6
|
+
execSync
|
|
7
|
+
} from 'child_process';
|
|
8
|
+
|
|
9
|
+
// ---------------------------------------------------------------------------
|
|
10
|
+
// exec - run external commands
|
|
11
|
+
export var exec = function(cmd) {
|
|
12
|
+
var buffer;
|
|
13
|
+
buffer = execSync(cmd, {
|
|
14
|
+
windowsHide: true
|
|
15
|
+
});
|
|
16
|
+
return buffer.toString();
|
|
17
|
+
};
|
|
18
|
+
|
|
19
|
+
// ---------------------------------------------------------------------------
|
|
20
|
+
// ask - ask a question
|
|
21
|
+
// later, on a web page, prompt the user for answer to question
|
|
22
|
+
export var ask = function(prompt) {
|
|
23
|
+
var answer;
|
|
24
|
+
answer = getline.question("{prompt}? ");
|
|
25
|
+
return answer;
|
|
26
|
+
};
|