fscr 6.2.6 → 7.3.0
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/README.md +48 -30
- package/dist/index.js +502 -186
- package/dist/lib/auth/auth-conf.js +49 -45
- package/dist/lib/cache/README.md +341 -0
- package/dist/lib/cache/cli.js +152 -0
- package/dist/lib/cache/file-watcher.js +193 -0
- package/dist/lib/cache/index.js +422 -0
- package/dist/lib/cache/monitor.js +224 -0
- package/dist/lib/commands/doctor.js +225 -0
- package/dist/lib/completions/completion.js +342 -0
- package/dist/lib/completions/generator.js +152 -0
- package/dist/lib/completions/scripts/bash.sh +108 -0
- package/dist/lib/completions/scripts/fish.sh +105 -0
- package/dist/lib/completions/scripts/powershell.ps1 +168 -0
- package/dist/lib/completions/scripts/zsh.sh +124 -0
- package/dist/lib/diagnostics/cache.js +121 -0
- package/dist/lib/diagnostics/fileSystem.js +236 -0
- package/dist/lib/diagnostics/gitCheck.js +41 -0
- package/dist/lib/diagnostics/nodeVersion.js +68 -0
- package/dist/lib/diagnostics/packageManager.js +64 -0
- package/dist/lib/diagnostics/performance.js +141 -0
- package/dist/lib/encryption/decryptConfig.js +3 -2
- package/dist/lib/encryption/encryption.js +153 -113
- package/dist/lib/generators/generateFScripts.js +16 -13
- package/dist/lib/generators/generateToc.js +23 -14
- package/dist/lib/generators/index.js +1 -1
- package/dist/lib/git/pub.js +27 -17
- package/dist/lib/git/taskRunner.js +79 -69
- package/dist/lib/git/validateNotDev.js +65 -54
- package/dist/lib/optionList.js +69 -57
- package/dist/lib/parsers/parseScriptsMd.cached.js +208 -0
- package/dist/lib/parsers/parseScriptsMd.js +88 -79
- package/dist/lib/parsers/parseScriptsPackage.js +4 -3
- package/dist/lib/performance/cache.js +199 -0
- package/dist/lib/performance/lazy-loader.js +189 -0
- package/dist/lib/performance/monitor.js +303 -0
- package/dist/lib/plugins/deployment/index.js +113 -0
- package/dist/lib/plugins/hooks.js +17 -0
- package/dist/lib/plugins/loader.js +91 -0
- package/dist/lib/plugins/task-notifier/index.js +72 -0
- package/dist/lib/release/bump.js +50 -45
- package/dist/lib/release/commitWithMessage.js +80 -52
- package/dist/lib/release/publish.js +19 -14
- package/dist/lib/release/pushToGit.js +40 -31
- package/dist/lib/release/releasenotes.js +116 -97
- package/dist/lib/release/seeChangedFiles.js +68 -60
- package/dist/lib/release/sort.js +200 -116
- package/dist/lib/release/tree.js +161 -147
- package/dist/lib/release/validateNotDev.js +52 -44
- package/dist/lib/running/index.js +1 -1
- package/dist/lib/running/runCLICommand.js +41 -31
- package/dist/lib/running/runParallel.js +61 -59
- package/dist/lib/running/runSequence.js +55 -53
- package/dist/lib/startScripts.js +129 -114
- package/dist/lib/taskList.js +97 -90
- package/dist/lib/test-files/.fscripts.md +113 -0
- package/dist/lib/test-files/.fscripts.test.md +103 -0
- package/dist/lib/test-files/.fscriptsb.md +107 -0
- package/dist/lib/test-files/.mdtest.md +40 -0
- package/dist/lib/test-files/consoleSample.js +13 -9
- package/dist/lib/test-files/inputSample.js +17 -14
- package/dist/lib/test-files/testConsole.js +1 -1
- package/dist/lib/test-files/testInput.js +1 -1
- package/dist/lib/upgradePackages.js +56 -46
- package/dist/lib/utils/clear.js +16 -13
- package/dist/lib/utils/console.js +27 -21
- package/dist/lib/utils/encryption.js +55 -13
- package/dist/lib/utils/hash.js +128 -0
- package/dist/lib/utils/helpers.js +153 -142
- package/dist/lib/utils/index.js +1 -1
- package/dist/lib/utils/prompt.js +24 -29
- package/package.json +11 -29
package/dist/lib/release/sort.js
CHANGED
|
@@ -6,131 +6,215 @@ import path from "path";
|
|
|
6
6
|
import { fileURLToPath } from "url";
|
|
7
7
|
const __filename = fileURLToPath(import.meta.url);
|
|
8
8
|
const __dirname = path.dirname(__filename);
|
|
9
|
-
|
|
9
|
+
|
|
10
|
+
const sortOrder = [
|
|
11
|
+
"name",
|
|
12
|
+
"version",
|
|
13
|
+
"description",
|
|
14
|
+
"keywords",
|
|
15
|
+
"sideEffects",
|
|
16
|
+
"main",
|
|
17
|
+
"umd:main",
|
|
18
|
+
"unpkg",
|
|
19
|
+
"module",
|
|
20
|
+
"workspaces",
|
|
21
|
+
"scripts",
|
|
22
|
+
"betterScripts",
|
|
23
|
+
"fscripts",
|
|
24
|
+
"source",
|
|
25
|
+
"jsnext:main",
|
|
26
|
+
"browser",
|
|
27
|
+
"homepage",
|
|
28
|
+
"bugs",
|
|
29
|
+
"repository",
|
|
30
|
+
"private",
|
|
31
|
+
"license",
|
|
32
|
+
"author",
|
|
33
|
+
"contributors",
|
|
34
|
+
"files",
|
|
35
|
+
"types",
|
|
36
|
+
"typings",
|
|
37
|
+
"style",
|
|
38
|
+
"example",
|
|
39
|
+
"examplestyle",
|
|
40
|
+
"assets",
|
|
41
|
+
"bin",
|
|
42
|
+
"man",
|
|
43
|
+
"directories",
|
|
44
|
+
"husky",
|
|
45
|
+
"pre-commit",
|
|
46
|
+
"commitlint",
|
|
47
|
+
"lint-staged",
|
|
48
|
+
"config",
|
|
49
|
+
"nodemonConfig",
|
|
50
|
+
"browserify",
|
|
51
|
+
"babel",
|
|
52
|
+
"browserslist",
|
|
53
|
+
"xo",
|
|
54
|
+
"prettier",
|
|
55
|
+
"eslintConfig",
|
|
56
|
+
"eslintIgnore",
|
|
57
|
+
"stylelint",
|
|
58
|
+
"jest",
|
|
59
|
+
"dependencies",
|
|
60
|
+
"devDependencies",
|
|
61
|
+
"peerDependencies",
|
|
62
|
+
"bundledDependencies",
|
|
63
|
+
"bundleDependencies",
|
|
64
|
+
"optionalDependencies",
|
|
65
|
+
"flat",
|
|
66
|
+
"resolutions",
|
|
67
|
+
"engines",
|
|
68
|
+
"engineStrict",
|
|
69
|
+
"os",
|
|
70
|
+
"cpu",
|
|
71
|
+
"preferGlobal",
|
|
72
|
+
"publishConfig"
|
|
73
|
+
];
|
|
10
74
|
// See https://docs.npmjs.com/misc/scripts
|
|
11
|
-
const defaultNpmScripts = [
|
|
75
|
+
const defaultNpmScripts = [
|
|
76
|
+
"install",
|
|
77
|
+
"pack",
|
|
78
|
+
"prepare",
|
|
79
|
+
"publish",
|
|
80
|
+
"restart",
|
|
81
|
+
"shrinkwrap",
|
|
82
|
+
"start",
|
|
83
|
+
"stop",
|
|
84
|
+
"test",
|
|
85
|
+
"uninstall",
|
|
86
|
+
"version"
|
|
87
|
+
];
|
|
88
|
+
|
|
12
89
|
function sortPackageJson(packageJson, options = {}) {
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
90
|
+
const determinedSortOrder = options.sortOrder || sortOrder;
|
|
91
|
+
let wasString = false;
|
|
92
|
+
let hasWindowsNewlines = false;
|
|
93
|
+
let endCharacters = "";
|
|
94
|
+
let indentLevel = 2;
|
|
95
|
+
if (typeof packageJson === "string") {
|
|
96
|
+
wasString = true;
|
|
97
|
+
indentLevel = detectIndent(packageJson).indent;
|
|
98
|
+
if (packageJson.substr(-1) === "\n") {
|
|
99
|
+
endCharacters = "\n";
|
|
100
|
+
}
|
|
101
|
+
const newlineMatch = packageJson.match(/(\r?\n)/);
|
|
102
|
+
hasWindowsNewlines = (newlineMatch && newlineMatch[0]) === "\r\n";
|
|
103
|
+
packageJson = JSON.parse(packageJson);
|
|
23
104
|
}
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
105
|
+
|
|
106
|
+
const prefixedScriptRegex = /^(pre|post)(.)/;
|
|
107
|
+
const prefixableScripts = defaultNpmScripts.slice();
|
|
108
|
+
if (typeof packageJson.scripts === "object") {
|
|
109
|
+
Object.keys(packageJson.scripts).forEach(script => {
|
|
110
|
+
const prefixOmitted = script.replace(prefixedScriptRegex, "$2");
|
|
111
|
+
if (packageJson.scripts[prefixOmitted] && !prefixableScripts.includes(prefixOmitted)) {
|
|
112
|
+
prefixableScripts.push(prefixOmitted);
|
|
113
|
+
}
|
|
114
|
+
});
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
function sortSubKey(key, sortList, unique) {
|
|
118
|
+
if (Array.isArray(packageJson[key])) {
|
|
119
|
+
packageJson[key] = packageJson[key].sort();
|
|
120
|
+
if (unique) {
|
|
121
|
+
packageJson[key] = array_unique(packageJson[key]);
|
|
122
|
+
}
|
|
123
|
+
return;
|
|
124
|
+
}
|
|
125
|
+
if (typeof packageJson[key] === "object") {
|
|
126
|
+
packageJson[key] = sortObjectKeys(packageJson[key], sortList);
|
|
127
|
+
}
|
|
45
128
|
}
|
|
46
|
-
|
|
47
|
-
|
|
129
|
+
function toSortKey(script) {
|
|
130
|
+
const prefixOmitted = script.replace(prefixedScriptRegex, "$2");
|
|
131
|
+
if (prefixableScripts.includes(prefixOmitted)) {
|
|
132
|
+
return prefixOmitted;
|
|
133
|
+
}
|
|
134
|
+
return script;
|
|
48
135
|
}
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
136
|
+
/* b
|
|
137
|
+
* pre | * | post
|
|
138
|
+
* pre 0 | - | -
|
|
139
|
+
* a * + | 0 | -
|
|
140
|
+
* post + | + | 0
|
|
141
|
+
*/
|
|
142
|
+
function compareScriptKeys(a, b) {
|
|
143
|
+
if (a === b) return 0;
|
|
144
|
+
const aScript = toSortKey(a);
|
|
145
|
+
const bScript = toSortKey(b);
|
|
146
|
+
if (aScript === bScript) {
|
|
147
|
+
// pre* is always smaller; post* is always bigger
|
|
148
|
+
// Covers: pre* vs. *; pre* vs. post*; * vs. post*
|
|
149
|
+
if (a === `pre${aScript}` || b === `post${bScript}`) return -1;
|
|
150
|
+
// The rest is bigger: * vs. *pre; *post vs. *pre; *post vs. *
|
|
151
|
+
return 1;
|
|
152
|
+
}
|
|
153
|
+
return aScript < bScript ? -1 : 1;
|
|
54
154
|
}
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
/* b
|
|
58
|
-
* pre | * | post
|
|
59
|
-
* pre 0 | - | -
|
|
60
|
-
* a * + | 0 | -
|
|
61
|
-
* post + | + | 0
|
|
62
|
-
*/
|
|
63
|
-
function compareScriptKeys(a, b) {
|
|
64
|
-
if (a === b) return 0;
|
|
65
|
-
const aScript = toSortKey(a);
|
|
66
|
-
const bScript = toSortKey(b);
|
|
67
|
-
if (aScript === bScript) {
|
|
68
|
-
// pre* is always smaller; post* is always bigger
|
|
69
|
-
// Covers: pre* vs. *; pre* vs. post*; * vs. post*
|
|
70
|
-
if (a === `pre${aScript}` || b === `post${bScript}`) return -1;
|
|
71
|
-
// The rest is bigger: * vs. *pre; *post vs. *pre; *post vs. *
|
|
72
|
-
return 1;
|
|
155
|
+
function array_unique(array) {
|
|
156
|
+
return array.filter((el, index, arr) => index == arr.indexOf(el));
|
|
73
157
|
}
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
let result = JSON.stringify(packageJson, null, indentLevel) + endCharacters;
|
|
117
|
-
if (hasWindowsNewlines) {
|
|
118
|
-
result = result.replace(/\n/g, "\r\n");
|
|
158
|
+
sortSubKey("keywords", null, true);
|
|
159
|
+
sortSubKey("homepage");
|
|
160
|
+
sortSubKey("bugs", ["url", "email"]);
|
|
161
|
+
sortSubKey("license", ["type", "url"]);
|
|
162
|
+
sortSubKey("author", ["name", "email", "url"]);
|
|
163
|
+
sortSubKey("bin");
|
|
164
|
+
sortSubKey("man");
|
|
165
|
+
sortSubKey("directories", ["lib", "bin", "man", "doc", "example"]);
|
|
166
|
+
sortSubKey("repository", ["type", "url"]);
|
|
167
|
+
sortSubKey("scripts", compareScriptKeys);
|
|
168
|
+
sortSubKey("betterScripts", compareScriptKeys);
|
|
169
|
+
sortSubKey("commitlint");
|
|
170
|
+
sortSubKey("lint-staged");
|
|
171
|
+
sortSubKey("config");
|
|
172
|
+
sortSubKey("nodemonConfig");
|
|
173
|
+
sortSubKey("browserify");
|
|
174
|
+
sortSubKey("babel");
|
|
175
|
+
sortSubKey("eslintConfig");
|
|
176
|
+
sortSubKey("jest");
|
|
177
|
+
sortSubKey("xo");
|
|
178
|
+
sortSubKey("prettier");
|
|
179
|
+
sortSubKey("dependencies");
|
|
180
|
+
sortSubKey("devDependencies");
|
|
181
|
+
sortSubKey("peerDependencies");
|
|
182
|
+
sortSubKey("bundledDependencies");
|
|
183
|
+
sortSubKey("bundleDependencies");
|
|
184
|
+
sortSubKey("optionalDependencies");
|
|
185
|
+
sortSubKey("resolutions");
|
|
186
|
+
sortSubKey("engines");
|
|
187
|
+
sortSubKey("engineStrict");
|
|
188
|
+
sortSubKey("os");
|
|
189
|
+
sortSubKey("cpu");
|
|
190
|
+
sortSubKey("preferGlobal");
|
|
191
|
+
sortSubKey("private");
|
|
192
|
+
sortSubKey("publishConfig");
|
|
193
|
+
packageJson = sortObjectKeys(packageJson, determinedSortOrder);
|
|
194
|
+
if (wasString) {
|
|
195
|
+
let result = JSON.stringify(packageJson, null, indentLevel) + endCharacters;
|
|
196
|
+
if (hasWindowsNewlines) {
|
|
197
|
+
result = result.replace(/\n/g, "\r\n");
|
|
198
|
+
}
|
|
199
|
+
return result;
|
|
119
200
|
}
|
|
120
|
-
return
|
|
121
|
-
}
|
|
122
|
-
return packageJson;
|
|
201
|
+
return packageJson;
|
|
123
202
|
}
|
|
124
203
|
export default sortPackageJson;
|
|
125
204
|
export { sortPackageJson, sortOrder };
|
|
205
|
+
|
|
126
206
|
if (import.meta.url === `file://${process.argv[1]}`) {
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
207
|
+
|
|
208
|
+
const filesToProcess = process.argv[2]
|
|
209
|
+
? process.argv.slice(2)
|
|
210
|
+
: [`${process.cwd()}/package.json`];
|
|
211
|
+
|
|
212
|
+
filesToProcess.forEach(filePath => {
|
|
213
|
+
const packageJson = fs.readFileSync(filePath, "utf8");
|
|
214
|
+
const sorted = sortPackageJson(packageJson);
|
|
215
|
+
if (sorted !== packageJson) {
|
|
216
|
+
fs.writeFileSync(filePath, sorted, "utf8");
|
|
217
|
+
console.log(`${filePath} is sorted!`);
|
|
218
|
+
}
|
|
219
|
+
});
|
|
220
|
+
}
|
package/dist/lib/release/tree.js
CHANGED
|
@@ -1,163 +1,177 @@
|
|
|
1
1
|
import chalk from "chalk";
|
|
2
|
+
|
|
2
3
|
function isFunction(f) {
|
|
3
|
-
|
|
4
|
+
return Object.prototype.toString.call(f) === "[object Function]";
|
|
4
5
|
}
|
|
6
|
+
|
|
5
7
|
function isRegExp(r) {
|
|
6
|
-
|
|
8
|
+
return r instanceof RegExp;
|
|
7
9
|
}
|
|
10
|
+
|
|
8
11
|
function isObject(o) {
|
|
9
|
-
|
|
12
|
+
return !Array.isArray(o) && !isFunction(o) && !isRegExp(o) && o === new Object(o);
|
|
10
13
|
}
|
|
14
|
+
|
|
11
15
|
let reColorName = /^(black|red|green|yellow|blue|magenta|cyan|white|gray)$/;
|
|
12
16
|
function coloring(str, color, type) {
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
17
|
+
str = str + "";
|
|
18
|
+
if (typeof color === "function") {
|
|
19
|
+
return color(str);
|
|
20
|
+
} else if (reColorName.test(color)) {
|
|
21
|
+
if (type === "string") {
|
|
22
|
+
if (str === "Modified") {
|
|
23
|
+
return chalk.green(str);
|
|
24
|
+
} else if (str === "Deleted") {
|
|
25
|
+
return chalk.red(str);
|
|
26
|
+
} else {
|
|
27
|
+
return chalk.blue(str);
|
|
28
|
+
}
|
|
29
|
+
} else {
|
|
30
|
+
return chalk[color].bold.underline.white(str); //
|
|
31
|
+
}
|
|
25
32
|
} else {
|
|
26
|
-
|
|
33
|
+
return str;
|
|
27
34
|
}
|
|
28
|
-
} else {
|
|
29
|
-
return str;
|
|
30
|
-
}
|
|
31
35
|
}
|
|
36
|
+
|
|
32
37
|
let defaultColors = {
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
38
|
+
string: "yellow",
|
|
39
|
+
number: "red",
|
|
40
|
+
boolean: "blue",
|
|
41
|
+
infinity: "red",
|
|
42
|
+
nan: "cyan",
|
|
43
|
+
null: "cyan",
|
|
44
|
+
undefined: "gray",
|
|
45
|
+
regexp: "green",
|
|
46
|
+
key: "magenta",
|
|
47
|
+
object: "white",
|
|
48
|
+
array: "white"
|
|
44
49
|
};
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
options.symbol
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
50
|
+
|
|
51
|
+
export default function(json, options) {
|
|
52
|
+
options = options || {};
|
|
53
|
+
if (options.symbol === undefined) {
|
|
54
|
+
options.symbol = true;
|
|
55
|
+
}
|
|
56
|
+
options.padding = options.padding || 0;
|
|
57
|
+
options.markdown = options.markdown || false;
|
|
58
|
+
options.highlight = options.highlight || false;
|
|
59
|
+
options.colors = options.colors || {};
|
|
60
|
+
|
|
61
|
+
Object.keys(defaultColors).forEach(function(key) {
|
|
62
|
+
options.colors[key] = options.colors[key] || defaultColors[key];
|
|
63
|
+
});
|
|
64
|
+
|
|
65
|
+
let output = "";
|
|
66
|
+
let tree = function(o, depth, index, isLast, inArray, type) {
|
|
67
|
+
index = [].concat(index || []);
|
|
68
|
+
depth = depth || 0;
|
|
69
|
+
index[depth] = 0;
|
|
70
|
+
|
|
71
|
+
if (Array.isArray(o)) {
|
|
72
|
+
if (inArray) {
|
|
73
|
+
if (options.symbol) {
|
|
74
|
+
tree("[]", depth, index, isLast, 0, "array");
|
|
75
|
+
index[depth] = isLast ? 0 : 1;
|
|
76
|
+
} else {
|
|
77
|
+
depth--;
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
for (let i = 0, l = o.length; i < l; i++) {
|
|
81
|
+
tree(o[i], depth + 1, index, i === l - 1, 1);
|
|
82
|
+
}
|
|
83
|
+
} else if (isObject(o)) {
|
|
84
|
+
let keys = Object.keys(o);
|
|
85
|
+
if (inArray) {
|
|
86
|
+
// if (options.symbol) {
|
|
87
|
+
// tree("", depth, index, isLast, 0, "object");
|
|
88
|
+
index[depth] = isLast ? 0 : 1;
|
|
89
|
+
depth++;
|
|
90
|
+
// }
|
|
91
|
+
}
|
|
92
|
+
for (let i = 0, l = keys.length; i < l; i++) {
|
|
93
|
+
let lastFlg = inArray && !isLast && !options.symbol ? false : i === l - 1;
|
|
94
|
+
|
|
95
|
+
tree(keys[i], depth, index, lastFlg, 0, "key");
|
|
96
|
+
index[depth] = lastFlg ? 0 : 1;
|
|
97
|
+
tree(o[keys[i]], depth + 1, index, 1, 1);
|
|
98
|
+
}
|
|
67
99
|
} else {
|
|
68
|
-
|
|
100
|
+
index[depth] = isLast ? 3 : 2;
|
|
101
|
+
if (isFunction(o)) {
|
|
102
|
+
o = "Function";
|
|
103
|
+
type = "function";
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
if (options.markdown) {
|
|
107
|
+
output += markdownList(depth) + o + "\n";
|
|
108
|
+
} else {
|
|
109
|
+
output += format(index) + highlight(o, type) + "\n";
|
|
110
|
+
}
|
|
69
111
|
}
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
hi = "array";
|
|
137
|
-
} else if (type === "object") {
|
|
138
|
-
hi = "object";
|
|
139
|
-
} else if (data !== data) {
|
|
140
|
-
hi = "nan";
|
|
141
|
-
} else if (data === Infinity) {
|
|
142
|
-
hi = "infinity";
|
|
143
|
-
} else if (typeof data === "string") {
|
|
144
|
-
hi = "string";
|
|
145
|
-
} else if (typeof data === "number") {
|
|
146
|
-
hi = "number";
|
|
147
|
-
} else if (isRegExp(data)) {
|
|
148
|
-
hi = "regexp";
|
|
149
|
-
} else if (typeof data === "boolean") {
|
|
150
|
-
hi = "boolean";
|
|
151
|
-
} else if (data === null) {
|
|
152
|
-
hi = "null";
|
|
153
|
-
} else if (data === void 0) {
|
|
154
|
-
hi = "undefined";
|
|
155
|
-
} else {
|
|
156
|
-
return data;
|
|
157
|
-
}
|
|
158
|
-
return coloring(data, options.colors[hi], hi);
|
|
159
|
-
};
|
|
160
|
-
tree(json);
|
|
161
|
-
return output;
|
|
162
|
-
}
|
|
163
|
-
;
|
|
112
|
+
};
|
|
113
|
+
|
|
114
|
+
let format = function(index) {
|
|
115
|
+
let s = "";
|
|
116
|
+
let p = new Array(options.padding + 1).join(" ");
|
|
117
|
+
for (let i = 0, l = index.length; i < l; i++) {
|
|
118
|
+
switch (index[i]) {
|
|
119
|
+
case 1:
|
|
120
|
+
s += chalk.grey("┃");
|
|
121
|
+
break;
|
|
122
|
+
case 2:
|
|
123
|
+
s += chalk.grey("┣ ");
|
|
124
|
+
break;
|
|
125
|
+
case 3:
|
|
126
|
+
s += chalk.grey("┗");
|
|
127
|
+
break;
|
|
128
|
+
default:
|
|
129
|
+
s += chalk.grey("⌐");
|
|
130
|
+
}
|
|
131
|
+
if (i < l - 1) {
|
|
132
|
+
s += chalk.grey(p);
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
return s;
|
|
136
|
+
};
|
|
137
|
+
|
|
138
|
+
let markdownList = function(depth) {
|
|
139
|
+
return new Array(depth + 1).join(" ") + "+ ";
|
|
140
|
+
};
|
|
141
|
+
|
|
142
|
+
let highlight = function(data, type) {
|
|
143
|
+
let hi;
|
|
144
|
+
if (!options.highlight) {
|
|
145
|
+
return data;
|
|
146
|
+
}
|
|
147
|
+
if (type === "key") {
|
|
148
|
+
hi = "key";
|
|
149
|
+
} else if (type === "array") {
|
|
150
|
+
hi = "array";
|
|
151
|
+
} else if (type === "object") {
|
|
152
|
+
hi = "object";
|
|
153
|
+
} else if (data !== data) {
|
|
154
|
+
hi = "nan";
|
|
155
|
+
} else if (data === Infinity) {
|
|
156
|
+
hi = "infinity";
|
|
157
|
+
} else if (typeof data === "string") {
|
|
158
|
+
hi = "string";
|
|
159
|
+
} else if (typeof data === "number") {
|
|
160
|
+
hi = "number";
|
|
161
|
+
} else if (isRegExp(data)) {
|
|
162
|
+
hi = "regexp";
|
|
163
|
+
} else if (typeof data === "boolean") {
|
|
164
|
+
hi = "boolean";
|
|
165
|
+
} else if (data === null) {
|
|
166
|
+
hi = "null";
|
|
167
|
+
} else if (data === void 0) {
|
|
168
|
+
hi = "undefined";
|
|
169
|
+
} else {
|
|
170
|
+
return data;
|
|
171
|
+
}
|
|
172
|
+
return coloring(data, options.colors[hi], hi);
|
|
173
|
+
};
|
|
174
|
+
|
|
175
|
+
tree(json);
|
|
176
|
+
return output;
|
|
177
|
+
};
|