@jdeighan/coffee-utils 4.0.13 → 4.0.17
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 +1 -1
- package/src/UnitTester.coffee +8 -9
- package/src/UnitTester.js +1 -2
- package/src/block_utils.coffee +3 -4
- package/src/block_utils.js +1 -2
- package/src/coffee_utils.coffee +22 -15
- package/src/coffee_utils.js +8 -3
- package/src/debug_utils.coffee +3 -5
- package/src/debug_utils.js +1 -2
- package/src/fs_utils.coffee +60 -47
- package/src/fs_utils.js +66 -57
- package/src/indent_utils.coffee +2 -4
- package/src/indent_utils.js +2 -3
- package/src/log_utils.coffee +9 -12
- package/src/log_utils.js +2 -5
- package/src/private_env.coffee +1 -1
- package/src/private_env.js +4 -2
package/package.json
CHANGED
package/src/UnitTester.coffee
CHANGED
@@ -1,10 +1,9 @@
|
|
1
1
|
# UnitTester.coffee
|
2
2
|
|
3
|
-
import assert from 'assert'
|
4
3
|
import test from 'ava'
|
5
4
|
|
6
5
|
import {
|
7
|
-
undef, pass, error, croak,
|
6
|
+
assert, undef, pass, error, croak,
|
8
7
|
isString, isFunction, isInteger, isArray,
|
9
8
|
} from '@jdeighan/coffee-utils'
|
10
9
|
import {blockToArray} from '@jdeighan/coffee-utils/block'
|
@@ -103,7 +102,7 @@ export class UnitTester
|
|
103
102
|
|
104
103
|
fails: (lineNum, func, expected) ->
|
105
104
|
|
106
|
-
assert
|
105
|
+
assert ! expected?, "UnitTester: fails doesn't allow expected"
|
107
106
|
assert isFunction(func), "UnitTester: fails requires a function"
|
108
107
|
|
109
108
|
# --- disable logging
|
@@ -123,7 +122,7 @@ export class UnitTester
|
|
123
122
|
|
124
123
|
succeeds: (lineNum, func, expected) ->
|
125
124
|
|
126
|
-
assert
|
125
|
+
assert ! expected?, "UnitTester: succeeds doesn't allow expected"
|
127
126
|
assert isFunction(func), "UnitTester: succeeds requires a function"
|
128
127
|
try
|
129
128
|
func()
|
@@ -137,8 +136,8 @@ export class UnitTester
|
|
137
136
|
# ........................................................................
|
138
137
|
|
139
138
|
same_list: (lineNum, list, expected) ->
|
140
|
-
assert
|
141
|
-
assert
|
139
|
+
assert ! list? || isArray(list), "UnitTester: not an array"
|
140
|
+
assert ! expected? || isArray(expected),
|
142
141
|
"UnitTester: expected is not an array"
|
143
142
|
|
144
143
|
@setWhichTest 'deepEqual'
|
@@ -148,8 +147,8 @@ export class UnitTester
|
|
148
147
|
# ........................................................................
|
149
148
|
|
150
149
|
not_same_list: (lineNum, list, expected) ->
|
151
|
-
assert
|
152
|
-
assert
|
150
|
+
assert ! list? || isArray(list), "UnitTester: not an array"
|
151
|
+
assert ! expected? || isArray(expected),
|
153
152
|
"UnitTester: expected is not an array"
|
154
153
|
|
155
154
|
@setWhichTest 'notDeepEqual'
|
@@ -182,7 +181,7 @@ export class UnitTester
|
|
182
181
|
if (lineNum < 0) && process.env.FINALTEST
|
183
182
|
error "Negative line numbers not allowed in FINALTEST"
|
184
183
|
|
185
|
-
if
|
184
|
+
if ! @testing || (@maxLineNum && (lineNum > @maxLineNum))
|
186
185
|
return
|
187
186
|
|
188
187
|
if lineNum < -100000
|
package/src/UnitTester.js
CHANGED
package/src/block_utils.coffee
CHANGED
@@ -1,11 +1,10 @@
|
|
1
1
|
# block_utils.coffee
|
2
2
|
|
3
|
-
import assert from 'assert'
|
4
3
|
import fs from 'fs'
|
5
4
|
import readline from 'readline'
|
6
5
|
|
7
6
|
import {
|
8
|
-
isEmpty, isString, nonEmpty, error, isComment, rtrim,
|
7
|
+
assert, isEmpty, isString, nonEmpty, error, isComment, rtrim,
|
9
8
|
} from '@jdeighan/coffee-utils'
|
10
9
|
import {log} from '@jdeighan/coffee-utils/log'
|
11
10
|
|
@@ -139,7 +138,7 @@ export forEachBlock = (filepath, func, regexp = /^-{16,}$/) ->
|
|
139
138
|
return
|
140
139
|
|
141
140
|
await forEachLine filepath, callback
|
142
|
-
if
|
141
|
+
if ! earlyExit
|
143
142
|
func(lLines.join('\n'), firstLineNum)
|
144
143
|
return
|
145
144
|
|
@@ -174,7 +173,7 @@ export forEachSetOfBlocks = (filepath, func,
|
|
174
173
|
return
|
175
174
|
|
176
175
|
await forEachLine filepath, callback
|
177
|
-
if
|
176
|
+
if ! earlyExit
|
178
177
|
lBlocks.push(lLines.join('\n'))
|
179
178
|
func(lBlocks, firstLineNum)
|
180
179
|
return
|
package/src/block_utils.js
CHANGED
package/src/coffee_utils.coffee
CHANGED
@@ -1,7 +1,5 @@
|
|
1
1
|
# coffee_utils.coffee
|
2
2
|
|
3
|
-
import assert from 'assert'
|
4
|
-
|
5
3
|
import {log} from '@jdeighan/coffee-utils/log'
|
6
4
|
|
7
5
|
export sep_dash = '-'.repeat(42)
|
@@ -20,6 +18,15 @@ export error = (message) ->
|
|
20
18
|
|
21
19
|
throw new Error(message)
|
22
20
|
|
21
|
+
# ---------------------------------------------------------------------------
|
22
|
+
# assert - mimic nodejs's assert
|
23
|
+
|
24
|
+
export assert = (cond, msg) ->
|
25
|
+
|
26
|
+
if ! cond
|
27
|
+
error(msg)
|
28
|
+
return
|
29
|
+
|
23
30
|
# ---------------------------------------------------------------------------
|
24
31
|
# croak - throws an error after possibly printing useful info
|
25
32
|
|
@@ -75,10 +82,10 @@ export isNumber = (x) ->
|
|
75
82
|
export isObject = (x) ->
|
76
83
|
|
77
84
|
return (typeof x == 'object') \
|
78
|
-
&&
|
79
|
-
&&
|
80
|
-
&&
|
81
|
-
&&
|
85
|
+
&& ! isString(x) \
|
86
|
+
&& ! isArray(x) \
|
87
|
+
&& ! isHash(x) \
|
88
|
+
&& ! isNumber(x)
|
82
89
|
|
83
90
|
# ---------------------------------------------------------------------------
|
84
91
|
|
@@ -98,7 +105,7 @@ export isHash = (x) ->
|
|
98
105
|
|
99
106
|
export isEmpty = (x) ->
|
100
107
|
|
101
|
-
if
|
108
|
+
if ! x?
|
102
109
|
return true
|
103
110
|
if isString(x)
|
104
111
|
return x.match(/^\s*$/)
|
@@ -115,10 +122,10 @@ export isEmpty = (x) ->
|
|
115
122
|
|
116
123
|
export nonEmpty = (x) ->
|
117
124
|
|
118
|
-
if
|
125
|
+
if ! x?
|
119
126
|
return false
|
120
127
|
if isString(x)
|
121
|
-
return
|
128
|
+
return ! x.match(/^\s*$/)
|
122
129
|
if isArray(x)
|
123
130
|
return x.length > 0
|
124
131
|
if isHash(x)
|
@@ -153,10 +160,10 @@ export words = (str) ->
|
|
153
160
|
|
154
161
|
export isArrayOfHashes = (lItems) ->
|
155
162
|
|
156
|
-
if
|
163
|
+
if ! isArray(lItems)
|
157
164
|
return false
|
158
165
|
for item in lItems
|
159
|
-
if
|
166
|
+
if ! isHash(item)
|
160
167
|
return false
|
161
168
|
return true
|
162
169
|
|
@@ -164,10 +171,10 @@ export isArrayOfHashes = (lItems) ->
|
|
164
171
|
|
165
172
|
export isArrayOfStrings = (lItems) ->
|
166
173
|
|
167
|
-
if
|
174
|
+
if ! isArray(lItems)
|
168
175
|
return false
|
169
176
|
for item in lItems
|
170
|
-
if
|
177
|
+
if ! isString(item)
|
171
178
|
return false
|
172
179
|
return true
|
173
180
|
|
@@ -223,7 +230,7 @@ export ask = (prompt) ->
|
|
223
230
|
export titleLine = (title, char='=', padding=2, linelen=42) ->
|
224
231
|
# --- used in logger
|
225
232
|
|
226
|
-
if
|
233
|
+
if ! title
|
227
234
|
return char.repeat(linelen)
|
228
235
|
|
229
236
|
titleLen = title.length + 2 * padding
|
@@ -272,7 +279,7 @@ export deepCopy = (obj) ->
|
|
272
279
|
|
273
280
|
export escapeStr = (str) ->
|
274
281
|
|
275
|
-
if
|
282
|
+
if ! str?
|
276
283
|
return 'undef'
|
277
284
|
if typeof str != 'string'
|
278
285
|
croak "escapeStr(): not a string", str, 'STRING'
|
package/src/coffee_utils.js
CHANGED
@@ -2,8 +2,6 @@
|
|
2
2
|
// coffee_utils.coffee
|
3
3
|
var commentRegExp;
|
4
4
|
|
5
|
-
import assert from 'assert';
|
6
|
-
|
7
5
|
import {
|
8
6
|
log
|
9
7
|
} from '@jdeighan/coffee-utils/log';
|
@@ -24,6 +22,14 @@ export var error = function(message) {
|
|
24
22
|
throw new Error(message);
|
25
23
|
};
|
26
24
|
|
25
|
+
// ---------------------------------------------------------------------------
|
26
|
+
// assert - mimic nodejs's assert
|
27
|
+
export var assert = function(cond, msg) {
|
28
|
+
if (!cond) {
|
29
|
+
error(msg);
|
30
|
+
}
|
31
|
+
};
|
32
|
+
|
27
33
|
// ---------------------------------------------------------------------------
|
28
34
|
// croak - throws an error after possibly printing useful info
|
29
35
|
export var croak = function(err, label, obj) {
|
@@ -225,7 +231,6 @@ export var ask = function(prompt) {
|
|
225
231
|
// ---------------------------------------------------------------------------
|
226
232
|
export var titleLine = function(title, char = '=', padding = 2, linelen = 42) {
|
227
233
|
var nLeft, nRight, strLeft, strMiddle, strRight, titleLen;
|
228
|
-
// --- used in logger
|
229
234
|
if (!title) {
|
230
235
|
return char.repeat(linelen);
|
231
236
|
}
|
package/src/debug_utils.coffee
CHANGED
@@ -1,9 +1,7 @@
|
|
1
1
|
# debug_utils.coffee
|
2
2
|
|
3
|
-
import assert from 'assert'
|
4
|
-
|
5
3
|
import {
|
6
|
-
undef, error, croak, warn, words, isString, isFunction,
|
4
|
+
assert, undef, error, croak, warn, words, isString, isFunction,
|
7
5
|
oneline, escapeStr, isNumber, isArray,
|
8
6
|
} from '@jdeighan/coffee-utils'
|
9
7
|
import {blockToArray} from '@jdeighan/coffee-utils/block'
|
@@ -148,7 +146,7 @@ export debug = (lArgs...) ->
|
|
148
146
|
if entering && lDebugFuncs && funcMatch(curFunc)
|
149
147
|
setDebugging true
|
150
148
|
|
151
|
-
if debugging && (
|
149
|
+
if debugging && (! ifMatches? || str.match(ifMatches))
|
152
150
|
|
153
151
|
# --- set the prefix, i.e. indentation to use
|
154
152
|
if returning
|
@@ -202,7 +200,7 @@ export funcMatch = (curFunc) ->
|
|
202
200
|
# ---------------------------------------------------------------------------
|
203
201
|
|
204
202
|
export checkTrace = (block) ->
|
205
|
-
# --- export only to allow unit tests
|
203
|
+
# --- export only to allow unit tests
|
206
204
|
|
207
205
|
lStack = []
|
208
206
|
|
package/src/debug_utils.js
CHANGED
@@ -2,9 +2,8 @@
|
|
2
2
|
// debug_utils.coffee
|
3
3
|
var arrow, arrowhead, corner, debugLevel, getPrefix, hbar, ifMatches, indent, lDebugFuncs, lDebugStack, reMethod, restoreDebugEnv, saveDebugEnv, stripArrow, vbar;
|
4
4
|
|
5
|
-
import assert from 'assert';
|
6
|
-
|
7
5
|
import {
|
6
|
+
assert,
|
8
7
|
undef,
|
9
8
|
error,
|
10
9
|
croak,
|
package/src/fs_utils.coffee
CHANGED
@@ -1,12 +1,11 @@
|
|
1
1
|
# fs_utils.coffee
|
2
2
|
|
3
|
-
import assert from 'assert'
|
4
3
|
import pathlib from 'path'
|
5
4
|
import urllib from 'url'
|
6
5
|
import fs from 'fs'
|
7
6
|
|
8
7
|
import {
|
9
|
-
undef, pass, rtrim, error, nonEmpty,
|
8
|
+
assert, undef, pass, rtrim, error, nonEmpty,
|
10
9
|
isRegExp, isFunction, croak,
|
11
10
|
} from '@jdeighan/coffee-utils'
|
12
11
|
import {log} from '@jdeighan/coffee-utils/log'
|
@@ -14,47 +13,22 @@ import {debug} from '@jdeighan/coffee-utils/debug'
|
|
14
13
|
|
15
14
|
# ---------------------------------------------------------------------------
|
16
15
|
|
17
|
-
export
|
18
|
-
# --- returns {
|
19
|
-
# dir
|
20
|
-
# filename # only this is guaranteed to be set
|
21
|
-
# stub
|
22
|
-
# ext
|
23
|
-
# }
|
16
|
+
export isFile = (fullpath) ->
|
24
17
|
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
fullpath: mkpath(dir, hInfo.base)
|
40
|
-
filename: hInfo.base
|
41
|
-
stub: hInfo.name
|
42
|
-
ext: hInfo.ext
|
43
|
-
}
|
44
|
-
else
|
45
|
-
return {
|
46
|
-
dir: mkpath(hInfo.dir) # change \ to /
|
47
|
-
filename: hInfo.base
|
48
|
-
stub: hInfo.name
|
49
|
-
ext: hInfo.ext
|
50
|
-
}
|
51
|
-
catch err
|
52
|
-
debug "return '#{err.message} from parseSource()"
|
53
|
-
return {
|
54
|
-
filename: source
|
55
|
-
stub: source
|
56
|
-
error: err.message
|
57
|
-
}
|
18
|
+
return fs.lstatSync(fullpath).isFile()
|
19
|
+
|
20
|
+
# ---------------------------------------------------------------------------
|
21
|
+
|
22
|
+
export isDir = (fullpath) ->
|
23
|
+
|
24
|
+
return fs.lstatSync(fullpath).isDirectory()
|
25
|
+
|
26
|
+
# ---------------------------------------------------------------------------
|
27
|
+
|
28
|
+
export isSimpleFileName = (path) ->
|
29
|
+
|
30
|
+
h = pathlib.parse(path)
|
31
|
+
return ! h.root && ! h.dir && h.base
|
58
32
|
|
59
33
|
# ---------------------------------------------------------------------------
|
60
34
|
# mydir() - pass argument `import.meta.url` and it will return
|
@@ -62,7 +36,6 @@ export parseSource = (source) ->
|
|
62
36
|
|
63
37
|
export mydir = (url) ->
|
64
38
|
|
65
|
-
# dir = pathlib.dirname(urllib.fileURLToPath(url.replace(/\@/g, '%40')))
|
66
39
|
dir = pathlib.dirname(urllib.fileURLToPath(url))
|
67
40
|
return mkpath(dir)
|
68
41
|
|
@@ -121,10 +94,7 @@ export barf = (filepath, contents) ->
|
|
121
94
|
|
122
95
|
debug "enter barf('#{filepath}')", contents
|
123
96
|
contents = rtrim(contents) + "\n"
|
124
|
-
|
125
|
-
fs.writeFileSync(filepath, contents, {encoding: 'utf8'})
|
126
|
-
catch err
|
127
|
-
log "barf(): write failed: #{err.message}"
|
97
|
+
fs.writeFileSync(filepath, contents, {encoding: 'utf8'})
|
128
98
|
debug "return from barf()"
|
129
99
|
return
|
130
100
|
|
@@ -274,3 +244,46 @@ export shortenPath = (path) ->
|
|
274
244
|
else
|
275
245
|
return str
|
276
246
|
|
247
|
+
# ---------------------------------------------------------------------------
|
248
|
+
|
249
|
+
export parseSource = (source) ->
|
250
|
+
# --- returns {
|
251
|
+
# dir
|
252
|
+
# filename # only this is guaranteed to be set
|
253
|
+
# stub
|
254
|
+
# ext
|
255
|
+
# }
|
256
|
+
|
257
|
+
debug "enter parseSource()"
|
258
|
+
if source == 'unit test'
|
259
|
+
debug "return 'unit test' from parseSource()"
|
260
|
+
return {
|
261
|
+
filename: 'unit test'
|
262
|
+
stub: 'unit test'
|
263
|
+
}
|
264
|
+
try
|
265
|
+
hInfo = pathlib.parse(source)
|
266
|
+
debug "return from parseSource()", hInfo
|
267
|
+
if hInfo.root
|
268
|
+
dir = mkpath(hInfo.dir) # change \ to /
|
269
|
+
return {
|
270
|
+
dir: dir
|
271
|
+
fullpath: mkpath(dir, hInfo.base)
|
272
|
+
filename: hInfo.base
|
273
|
+
stub: hInfo.name
|
274
|
+
ext: hInfo.ext
|
275
|
+
}
|
276
|
+
else
|
277
|
+
return {
|
278
|
+
dir: mkpath(hInfo.dir) # change \ to /
|
279
|
+
filename: hInfo.base
|
280
|
+
stub: hInfo.name
|
281
|
+
ext: hInfo.ext
|
282
|
+
}
|
283
|
+
catch err
|
284
|
+
debug "return '#{err.message} from parseSource()"
|
285
|
+
return {
|
286
|
+
filename: source
|
287
|
+
stub: source
|
288
|
+
error: err.message
|
289
|
+
}
|
package/src/fs_utils.js
CHANGED
@@ -2,8 +2,6 @@
|
|
2
2
|
// fs_utils.coffee
|
3
3
|
var withUnderScore;
|
4
4
|
|
5
|
-
import assert from 'assert';
|
6
|
-
|
7
5
|
import pathlib from 'path';
|
8
6
|
|
9
7
|
import urllib from 'url';
|
@@ -11,6 +9,7 @@ import urllib from 'url';
|
|
11
9
|
import fs from 'fs';
|
12
10
|
|
13
11
|
import {
|
12
|
+
assert,
|
14
13
|
undef,
|
15
14
|
pass,
|
16
15
|
rtrim,
|
@@ -30,51 +29,20 @@ import {
|
|
30
29
|
} from '@jdeighan/coffee-utils/debug';
|
31
30
|
|
32
31
|
// ---------------------------------------------------------------------------
|
33
|
-
export var
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
};
|
48
|
-
}
|
49
|
-
try {
|
50
|
-
hInfo = pathlib.parse(source);
|
51
|
-
debug("return from parseSource()", hInfo);
|
52
|
-
if (hInfo.root) {
|
53
|
-
dir = mkpath(hInfo.dir); // change \ to /
|
54
|
-
return {
|
55
|
-
dir: dir,
|
56
|
-
fullpath: mkpath(dir, hInfo.base),
|
57
|
-
filename: hInfo.base,
|
58
|
-
stub: hInfo.name,
|
59
|
-
ext: hInfo.ext
|
60
|
-
};
|
61
|
-
} else {
|
62
|
-
return {
|
63
|
-
dir: mkpath(hInfo.dir), // change \ to /
|
64
|
-
filename: hInfo.base,
|
65
|
-
stub: hInfo.name,
|
66
|
-
ext: hInfo.ext
|
67
|
-
};
|
68
|
-
}
|
69
|
-
} catch (error1) {
|
70
|
-
err = error1;
|
71
|
-
debug(`return '${err.message} from parseSource()`);
|
72
|
-
return {
|
73
|
-
filename: source,
|
74
|
-
stub: source,
|
75
|
-
error: err.message
|
76
|
-
};
|
77
|
-
}
|
32
|
+
export var isFile = function(fullpath) {
|
33
|
+
return fs.lstatSync(fullpath).isFile();
|
34
|
+
};
|
35
|
+
|
36
|
+
// ---------------------------------------------------------------------------
|
37
|
+
export var isDir = function(fullpath) {
|
38
|
+
return fs.lstatSync(fullpath).isDirectory();
|
39
|
+
};
|
40
|
+
|
41
|
+
// ---------------------------------------------------------------------------
|
42
|
+
export var isSimpleFileName = function(path) {
|
43
|
+
var h;
|
44
|
+
h = pathlib.parse(path);
|
45
|
+
return !h.root && !h.dir && h.base;
|
78
46
|
};
|
79
47
|
|
80
48
|
// ---------------------------------------------------------------------------
|
@@ -82,7 +50,6 @@ export var parseSource = function(source) {
|
|
82
50
|
// the directory your file is in
|
83
51
|
export var mydir = function(url) {
|
84
52
|
var dir;
|
85
|
-
// dir = pathlib.dirname(urllib.fileURLToPath(url.replace(/\@/g, '%40')))
|
86
53
|
dir = pathlib.dirname(urllib.fileURLToPath(url));
|
87
54
|
return mkpath(dir);
|
88
55
|
};
|
@@ -140,17 +107,11 @@ export var slurp = function(filepath) {
|
|
140
107
|
// ---------------------------------------------------------------------------
|
141
108
|
// barf - write a string to a file
|
142
109
|
export var barf = function(filepath, contents) {
|
143
|
-
var err;
|
144
110
|
debug(`enter barf('${filepath}')`, contents);
|
145
111
|
contents = rtrim(contents) + "\n";
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
});
|
150
|
-
} catch (error1) {
|
151
|
-
err = error1;
|
152
|
-
log(`barf(): write failed: ${err.message}`);
|
153
|
-
}
|
112
|
+
fs.writeFileSync(filepath, contents, {
|
113
|
+
encoding: 'utf8'
|
114
|
+
});
|
154
115
|
debug("return from barf()");
|
155
116
|
};
|
156
117
|
|
@@ -325,3 +286,51 @@ export var shortenPath = function(path) {
|
|
325
286
|
return str;
|
326
287
|
}
|
327
288
|
};
|
289
|
+
|
290
|
+
// ---------------------------------------------------------------------------
|
291
|
+
export var parseSource = function(source) {
|
292
|
+
var dir, err, hInfo;
|
293
|
+
// --- returns {
|
294
|
+
// dir
|
295
|
+
// filename # only this is guaranteed to be set
|
296
|
+
// stub
|
297
|
+
// ext
|
298
|
+
// }
|
299
|
+
debug("enter parseSource()");
|
300
|
+
if (source === 'unit test') {
|
301
|
+
debug("return 'unit test' from parseSource()");
|
302
|
+
return {
|
303
|
+
filename: 'unit test',
|
304
|
+
stub: 'unit test'
|
305
|
+
};
|
306
|
+
}
|
307
|
+
try {
|
308
|
+
hInfo = pathlib.parse(source);
|
309
|
+
debug("return from parseSource()", hInfo);
|
310
|
+
if (hInfo.root) {
|
311
|
+
dir = mkpath(hInfo.dir); // change \ to /
|
312
|
+
return {
|
313
|
+
dir: dir,
|
314
|
+
fullpath: mkpath(dir, hInfo.base),
|
315
|
+
filename: hInfo.base,
|
316
|
+
stub: hInfo.name,
|
317
|
+
ext: hInfo.ext
|
318
|
+
};
|
319
|
+
} else {
|
320
|
+
return {
|
321
|
+
dir: mkpath(hInfo.dir), // change \ to /
|
322
|
+
filename: hInfo.base,
|
323
|
+
stub: hInfo.name,
|
324
|
+
ext: hInfo.ext
|
325
|
+
};
|
326
|
+
}
|
327
|
+
} catch (error1) {
|
328
|
+
err = error1;
|
329
|
+
debug(`return '${err.message} from parseSource()`);
|
330
|
+
return {
|
331
|
+
filename: source,
|
332
|
+
stub: source,
|
333
|
+
error: err.message
|
334
|
+
};
|
335
|
+
}
|
336
|
+
};
|
package/src/indent_utils.coffee
CHANGED
@@ -1,9 +1,7 @@
|
|
1
1
|
# indent_utils.coffee
|
2
2
|
|
3
|
-
import assert from 'assert'
|
4
|
-
|
5
3
|
import {
|
6
|
-
undef, error, escapeStr,
|
4
|
+
assert, undef, error, escapeStr,
|
7
5
|
OL, isInteger, isString, isArray, isEmpty, rtrim,
|
8
6
|
} from '@jdeighan/coffee-utils'
|
9
7
|
import {arrayToBlock, blockToArray} from '@jdeighan/coffee-utils/block'
|
@@ -124,7 +122,7 @@ export tabify = (str, numSpaces=undef) ->
|
|
124
122
|
n = prefix.length
|
125
123
|
if (prefix.indexOf('\t') != -1)
|
126
124
|
error "tabify(): leading TAB characters not allowed"
|
127
|
-
if
|
125
|
+
if ! numSpaces?
|
128
126
|
numSpaces = n
|
129
127
|
if (n % numSpaces != 0)
|
130
128
|
error "tabify(): Invalid # of leading space chars"
|
package/src/indent_utils.js
CHANGED
package/src/log_utils.coffee
CHANGED
@@ -1,10 +1,9 @@
|
|
1
1
|
# log_utils.coffee
|
2
2
|
|
3
|
-
import assert from 'assert'
|
4
3
|
import yaml from 'js-yaml'
|
5
4
|
|
6
5
|
import {
|
7
|
-
undef, isNumber, isString, isHash, isFunction, escapeStr,
|
6
|
+
assert, undef, isNumber, isString, isHash, isFunction, escapeStr,
|
8
7
|
} from '@jdeighan/coffee-utils'
|
9
8
|
import {blockToArray} from '@jdeighan/coffee-utils/block'
|
10
9
|
import {tabify} from '@jdeighan/coffee-utils/indent'
|
@@ -17,15 +16,13 @@ logger = console.log # for strings
|
|
17
16
|
export tamlStringify = (obj) ->
|
18
17
|
|
19
18
|
str = yaml.dump(obj, {
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
19
|
+
skipInvalid: true
|
20
|
+
indent: 1
|
21
|
+
sortKeys: false
|
22
|
+
lineWidth: -1
|
23
|
+
})
|
25
24
|
str = "---\n" + tabify(str)
|
26
|
-
str = str.replace(/\t/g, ' ') #
|
27
|
-
# has no way of adjusting display
|
28
|
-
# of TAB chars
|
25
|
+
str = str.replace(/\t/g, ' ') # fr***ing Windows Terminal
|
29
26
|
return str
|
30
27
|
|
31
28
|
# ---------------------------------------------------------------------------
|
@@ -108,9 +105,9 @@ export log = (lArgs...) ->
|
|
108
105
|
else
|
109
106
|
prefix = itemPrefix = ''
|
110
107
|
|
111
|
-
if (
|
108
|
+
if (! logItem)
|
112
109
|
logger "#{prefix}#{str}"
|
113
|
-
else if
|
110
|
+
else if ! item?
|
114
111
|
logger "#{prefix}#{str} = undef"
|
115
112
|
else if isNumber(item)
|
116
113
|
logger "#{prefix}#{str} = #{item}"
|
package/src/log_utils.js
CHANGED
@@ -2,11 +2,10 @@
|
|
2
2
|
// log_utils.coffee
|
3
3
|
var logger, maxOneLine;
|
4
4
|
|
5
|
-
import assert from 'assert';
|
6
|
-
|
7
5
|
import yaml from 'js-yaml';
|
8
6
|
|
9
7
|
import {
|
8
|
+
assert,
|
10
9
|
undef,
|
11
10
|
isNumber,
|
12
11
|
isString,
|
@@ -37,9 +36,7 @@ export var tamlStringify = function(obj) {
|
|
37
36
|
lineWidth: -1
|
38
37
|
});
|
39
38
|
str = "---\n" + tabify(str);
|
40
|
-
str = str.replace(/\t/g, ' '); //
|
41
|
-
// has no way of adjusting display
|
42
|
-
// of TAB chars
|
39
|
+
str = str.replace(/\t/g, ' '); // fr***ing Windows Terminal
|
43
40
|
return str;
|
44
41
|
};
|
45
42
|
|
package/src/private_env.coffee
CHANGED