editorconfig 0.15.1 → 0.15.2
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/CHANGELOG.md +3 -0
- package/package.json +59 -59
- package/{dist/src → src}/cli.d.ts +0 -0
- package/{dist/src → src}/cli.js +0 -0
- package/{dist/src → src}/index.d.ts +0 -0
- package/{dist/src → src}/index.js +0 -0
- package/{dist/src → src}/lib/ini.d.ts +0 -0
- package/{dist/src → src}/lib/ini.js +0 -0
- package/.editorconfig +0 -17
- package/.gitattributes +0 -2
- package/.gitmodules +0 -4
- package/.travis.yml +0 -15
- package/CMakeLists.txt +0 -16
- package/dist/package.json +0 -59
- package/src/cli.ts +0 -47
- package/src/index.ts +0 -279
- package/src/lib/ini.ts +0 -66
- package/tests/.editorconfig +0 -11
- package/tests/.git +0 -1
- package/tests/CMakeLists.txt +0 -66
- package/tests/README.md +0 -37
- package/tests/cli/CMakeLists.txt +0 -49
- package/tests/cli/cli.in +0 -7
- package/tests/filetree/CMakeLists.txt +0 -81
- package/tests/filetree/parent_directory/parent_directory.in +0 -17
- package/tests/filetree/parent_directory.in +0 -16
- package/tests/filetree/path_separator.in +0 -15
- package/tests/filetree/root_file/root_file.in +0 -1
- package/tests/filetree/root_file.in +0 -4
- package/tests/filetree/root_mixed/root_file.in +0 -4
- package/tests/glob/CMakeLists.txt +0 -242
- package/tests/glob/braces.in +0 -63
- package/tests/glob/brackets.in +0 -47
- package/tests/glob/question.in +0 -7
- package/tests/glob/star.in +0 -9
- package/tests/glob/star_star.in +0 -15
- package/tests/glob/utf8char.in +0 -6
- package/tests/parser/CMakeLists.txt +0 -154
- package/tests/parser/basic.in +0 -16
- package/tests/parser/bom.in +0 -6
- package/tests/parser/comments.in +0 -58
- package/tests/parser/crlf.in +0 -6
- package/tests/parser/whitespace.in +0 -68
- package/tests/properties/CMakeLists.txt +0 -71
- package/tests/properties/indent_size_default.in +0 -11
- package/tests/properties/lowercase_names.in +0 -6
- package/tests/properties/lowercase_values.in +0 -15
- package/tests/properties/tab_width_default.in +0 -9
- package/tsconfig.json +0 -28
- package/tslint.json +0 -118
package/CHANGELOG.md
CHANGED
package/package.json
CHANGED
|
@@ -1,59 +1,59 @@
|
|
|
1
|
-
{
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
}
|
|
1
|
+
{
|
|
2
|
+
"name": "editorconfig",
|
|
3
|
+
"version": "0.15.2",
|
|
4
|
+
"description": "EditorConfig File Locator and Interpreter for Node.js",
|
|
5
|
+
"keywords": [
|
|
6
|
+
"editorconfig",
|
|
7
|
+
"core"
|
|
8
|
+
],
|
|
9
|
+
"main": "src/index.js",
|
|
10
|
+
"contributors": [
|
|
11
|
+
"Hong Xu (topbug.net)",
|
|
12
|
+
"Jed Mao (https://github.com/jedmao/)",
|
|
13
|
+
"Trey Hunner (http://treyhunner.com)"
|
|
14
|
+
],
|
|
15
|
+
"directories": {
|
|
16
|
+
"bin": "./bin",
|
|
17
|
+
"lib": "./lib"
|
|
18
|
+
},
|
|
19
|
+
"scripts": {
|
|
20
|
+
"clean": "rimraf dist",
|
|
21
|
+
"prebuild": "npm run clean",
|
|
22
|
+
"build": "tsc",
|
|
23
|
+
"pretest": "npm run lint && npm run build && npm run copy && cmake .",
|
|
24
|
+
"test": "ctest .",
|
|
25
|
+
"pretest:ci": "npm run pretest",
|
|
26
|
+
"test:ci": "ctest -VV --output-on-failure .",
|
|
27
|
+
"lint": "npm run eclint && npm run tslint",
|
|
28
|
+
"eclint": "eclint check --indent_size ignore \"src/**\"",
|
|
29
|
+
"tslint": "tslint --project tsconfig.json --exclude package.json",
|
|
30
|
+
"copy": "cpy .npmignore LICENSE README.md CHANGELOG.md dist && cpy bin/* dist/bin && cpy src/lib/fnmatch*.* dist/src/lib",
|
|
31
|
+
"prepub": "npm run lint && npm run build && npm run copy",
|
|
32
|
+
"pub": "npm publish ./dist"
|
|
33
|
+
},
|
|
34
|
+
"repository": {
|
|
35
|
+
"type": "git",
|
|
36
|
+
"url": "git://github.com/editorconfig/editorconfig-core-js.git"
|
|
37
|
+
},
|
|
38
|
+
"bugs": "https://github.com/editorconfig/editorconfig-core-js/issues",
|
|
39
|
+
"author": "EditorConfig Team",
|
|
40
|
+
"license": "MIT",
|
|
41
|
+
"dependencies": {
|
|
42
|
+
"@types/node": "^10.11.7",
|
|
43
|
+
"@types/semver": "^5.5.0",
|
|
44
|
+
"commander": "^2.19.0",
|
|
45
|
+
"lru-cache": "^4.1.3",
|
|
46
|
+
"semver": "^5.6.0",
|
|
47
|
+
"sigmund": "^1.0.1"
|
|
48
|
+
},
|
|
49
|
+
"devDependencies": {
|
|
50
|
+
"@types/mocha": "^5.2.5",
|
|
51
|
+
"cpy-cli": "^2.0.0",
|
|
52
|
+
"eclint": "^2.8.0",
|
|
53
|
+
"mocha": "^5.2.0",
|
|
54
|
+
"rimraf": "^2.6.2",
|
|
55
|
+
"should": "^13.2.3",
|
|
56
|
+
"tslint": "^5.11.0",
|
|
57
|
+
"typescript": "^3.1.3"
|
|
58
|
+
}
|
|
59
|
+
}
|
|
File without changes
|
package/{dist/src → src}/cli.js
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
package/.editorconfig
DELETED
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
; http://editorconfig.org
|
|
2
|
-
|
|
3
|
-
root = true
|
|
4
|
-
|
|
5
|
-
[*]
|
|
6
|
-
indent_style = space
|
|
7
|
-
indent_size = 2
|
|
8
|
-
end_of_line = lf
|
|
9
|
-
charset = utf-8
|
|
10
|
-
trim_trailing_whitespace = true
|
|
11
|
-
insert_final_newline = true
|
|
12
|
-
block_comment_start = /**
|
|
13
|
-
block_comment = *
|
|
14
|
-
block_comment_end = */
|
|
15
|
-
|
|
16
|
-
[*.md]
|
|
17
|
-
indent_size = 4
|
package/.gitattributes
DELETED
package/.gitmodules
DELETED
package/.travis.yml
DELETED
package/CMakeLists.txt
DELETED
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
# This file is used for testing only
|
|
2
|
-
|
|
3
|
-
# To perform the test, run `cmake .` at the root of the project tree followed
|
|
4
|
-
# by `ctest .`
|
|
5
|
-
|
|
6
|
-
cmake_minimum_required(VERSION 2.6)
|
|
7
|
-
|
|
8
|
-
# Do not check any compiler
|
|
9
|
-
project(editorconfig-core-js NONE)
|
|
10
|
-
|
|
11
|
-
set(NODE node CACHE STRING "Node.js command")
|
|
12
|
-
|
|
13
|
-
enable_testing()
|
|
14
|
-
|
|
15
|
-
set(EDITORCONFIG_CMD ${NODE} ${PROJECT_SOURCE_DIR}/dist/bin/editorconfig)
|
|
16
|
-
add_subdirectory(tests)
|
package/dist/package.json
DELETED
|
@@ -1,59 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "editorconfig",
|
|
3
|
-
"version": "0.15.1",
|
|
4
|
-
"description": "EditorConfig File Locator and Interpreter for Node.js",
|
|
5
|
-
"keywords": [
|
|
6
|
-
"editorconfig",
|
|
7
|
-
"core"
|
|
8
|
-
],
|
|
9
|
-
"main": "src/index.js",
|
|
10
|
-
"contributors": [
|
|
11
|
-
"Hong Xu (topbug.net)",
|
|
12
|
-
"Jed Mao (https://github.com/jedmao/)",
|
|
13
|
-
"Trey Hunner (http://treyhunner.com)"
|
|
14
|
-
],
|
|
15
|
-
"directories": {
|
|
16
|
-
"bin": "./bin",
|
|
17
|
-
"lib": "./lib"
|
|
18
|
-
},
|
|
19
|
-
"scripts": {
|
|
20
|
-
"clean": "rimraf dist",
|
|
21
|
-
"prebuild": "npm run clean",
|
|
22
|
-
"build": "tsc",
|
|
23
|
-
"pretest": "npm run lint && npm run build && npm run copy && cmake .",
|
|
24
|
-
"test": "ctest .",
|
|
25
|
-
"pretest:ci": "npm run pretest",
|
|
26
|
-
"test:ci": "ctest -VV --output-on-failure .",
|
|
27
|
-
"lint": "npm run eclint && npm run tslint",
|
|
28
|
-
"eclint": "eclint check --indent_size ignore \"src/**\"",
|
|
29
|
-
"tslint": "tslint --project tsconfig.json --exclude package.json",
|
|
30
|
-
"copy": "cpy .npmignore LICENSE README.md CHANGELOG.md dist && cpy bin/* dist/bin && cpy src/lib/fnmatch*.* dist/src/lib",
|
|
31
|
-
"prepub": "npm run lint && npm run build && npm run copy",
|
|
32
|
-
"pub": "npm publish ./dist"
|
|
33
|
-
},
|
|
34
|
-
"repository": {
|
|
35
|
-
"type": "git",
|
|
36
|
-
"url": "git://github.com/editorconfig/editorconfig-core-js.git"
|
|
37
|
-
},
|
|
38
|
-
"bugs": "https://github.com/editorconfig/editorconfig-core-js/issues",
|
|
39
|
-
"author": "EditorConfig Team",
|
|
40
|
-
"license": "MIT",
|
|
41
|
-
"dependencies": {
|
|
42
|
-
"@types/node": "^10.11.7",
|
|
43
|
-
"@types/semver": "^5.5.0",
|
|
44
|
-
"commander": "^2.19.0",
|
|
45
|
-
"lru-cache": "^4.1.3",
|
|
46
|
-
"semver": "^5.6.0",
|
|
47
|
-
"sigmund": "^1.0.1"
|
|
48
|
-
},
|
|
49
|
-
"devDependencies": {
|
|
50
|
-
"@types/mocha": "^5.2.5",
|
|
51
|
-
"cpy-cli": "^2.0.0",
|
|
52
|
-
"eclint": "^2.8.0",
|
|
53
|
-
"mocha": "^5.2.0",
|
|
54
|
-
"rimraf": "^2.6.2",
|
|
55
|
-
"should": "^13.2.3",
|
|
56
|
-
"tslint": "^5.11.0",
|
|
57
|
-
"typescript": "^3.1.3"
|
|
58
|
-
}
|
|
59
|
-
}
|
package/src/cli.ts
DELETED
|
@@ -1,47 +0,0 @@
|
|
|
1
|
-
// tslint:disable:no-console
|
|
2
|
-
import program from 'commander'
|
|
3
|
-
|
|
4
|
-
import * as editorconfig from './'
|
|
5
|
-
|
|
6
|
-
import pkg from '../package.json'
|
|
7
|
-
|
|
8
|
-
export default function cli(args: string[]) {
|
|
9
|
-
program.version('EditorConfig Node.js Core Version ' + pkg.version)
|
|
10
|
-
|
|
11
|
-
program
|
|
12
|
-
.usage([
|
|
13
|
-
'[OPTIONS] FILEPATH1 [FILEPATH2 FILEPATH3 ...]',
|
|
14
|
-
program._version,
|
|
15
|
-
'FILEPATH can be a hyphen (-) if you want path(s) to be read from stdin.',
|
|
16
|
-
].join('\n\n '))
|
|
17
|
-
.option('-f <path>', 'Specify conf filename other than \'.editorconfig\'')
|
|
18
|
-
.option('-b <version>', 'Specify version (used by devs to test compatibility)')
|
|
19
|
-
.option('-v, --version', 'Display version information')
|
|
20
|
-
.parse(args)
|
|
21
|
-
|
|
22
|
-
// Throw away the native -V flag in lieu of the one we've manually specified
|
|
23
|
-
// to adhere to testing requirements
|
|
24
|
-
program.options.shift()
|
|
25
|
-
|
|
26
|
-
const files = program.args
|
|
27
|
-
|
|
28
|
-
if (!files.length) {
|
|
29
|
-
program.help()
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
files
|
|
33
|
-
.map((filePath) => editorconfig.parse(filePath, {
|
|
34
|
-
config: program.F,
|
|
35
|
-
version: program.B,
|
|
36
|
-
}))
|
|
37
|
-
.forEach((parsing, i, { length }) => {
|
|
38
|
-
parsing.then((parsed) => {
|
|
39
|
-
if (length > 1) {
|
|
40
|
-
console.log(`[${files[i]}]`)
|
|
41
|
-
}
|
|
42
|
-
Object.keys(parsed).forEach((key) => {
|
|
43
|
-
console.log(`${key}=${parsed[key]}`)
|
|
44
|
-
})
|
|
45
|
-
})
|
|
46
|
-
})
|
|
47
|
-
}
|
package/src/index.ts
DELETED
|
@@ -1,279 +0,0 @@
|
|
|
1
|
-
import * as fs from 'fs'
|
|
2
|
-
import * as path from 'path'
|
|
3
|
-
import * as semver from 'semver'
|
|
4
|
-
|
|
5
|
-
import minimatch from './lib/fnmatch'
|
|
6
|
-
import { parseString, ParseStringResult } from './lib/ini'
|
|
7
|
-
|
|
8
|
-
export { parseString }
|
|
9
|
-
|
|
10
|
-
import pkg from '../package.json'
|
|
11
|
-
|
|
12
|
-
export interface KnownProps {
|
|
13
|
-
end_of_line?: 'lf' | 'crlf' | 'unset'
|
|
14
|
-
indent_style?: 'tab' | 'space' | 'unset'
|
|
15
|
-
indent_size?: number | 'tab' | 'unset'
|
|
16
|
-
insert_final_newline?: true | false | 'unset'
|
|
17
|
-
tab_width?: number | 'unset'
|
|
18
|
-
trim_trailing_whitespace?: true | false | 'unset'
|
|
19
|
-
charset?: string | 'unset'
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
export interface ECFile {
|
|
23
|
-
name: string
|
|
24
|
-
contents: string | Buffer
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
export interface FileConfig {
|
|
28
|
-
name: string
|
|
29
|
-
contents: ParseStringResult
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
export interface ParseOptions {
|
|
33
|
-
config?: string
|
|
34
|
-
version?: string
|
|
35
|
-
root?: string
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
const knownProps = {
|
|
39
|
-
end_of_line: true,
|
|
40
|
-
indent_style: true,
|
|
41
|
-
indent_size: true,
|
|
42
|
-
insert_final_newline: true,
|
|
43
|
-
trim_trailing_whitespace: true,
|
|
44
|
-
charset: true,
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
function fnmatch(filepath: string, glob: string) {
|
|
48
|
-
const matchOptions = { matchBase: true, dot: true, noext: true }
|
|
49
|
-
glob = glob.replace(/\*\*/g, '{*,**/**/**}')
|
|
50
|
-
return minimatch(filepath, glob, matchOptions)
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
function getConfigFileNames(filepath: string, options: ParseOptions) {
|
|
54
|
-
const paths = []
|
|
55
|
-
do {
|
|
56
|
-
filepath = path.dirname(filepath)
|
|
57
|
-
paths.push(path.join(filepath, options.config as string))
|
|
58
|
-
} while (filepath !== options.root)
|
|
59
|
-
return paths
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
function processMatches(matches: KnownProps, version: string) {
|
|
63
|
-
// Set indent_size to 'tab' if indent_size is unspecified and
|
|
64
|
-
// indent_style is set to 'tab'.
|
|
65
|
-
if (
|
|
66
|
-
'indent_style' in matches
|
|
67
|
-
&& matches.indent_style === 'tab'
|
|
68
|
-
&& !('indent_size' in matches)
|
|
69
|
-
&& semver.gte(version, '0.10.0')
|
|
70
|
-
) {
|
|
71
|
-
matches.indent_size = 'tab'
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
// Set tab_width to indent_size if indent_size is specified and
|
|
75
|
-
// tab_width is unspecified
|
|
76
|
-
if (
|
|
77
|
-
'indent_size' in matches
|
|
78
|
-
&& !('tab_width' in matches)
|
|
79
|
-
&& matches.indent_size !== 'tab'
|
|
80
|
-
) {
|
|
81
|
-
matches.tab_width = matches.indent_size
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
// Set indent_size to tab_width if indent_size is 'tab'
|
|
85
|
-
if (
|
|
86
|
-
'indent_size' in matches
|
|
87
|
-
&& 'tab_width' in matches
|
|
88
|
-
&& matches.indent_size === 'tab'
|
|
89
|
-
) {
|
|
90
|
-
matches.indent_size = matches.tab_width
|
|
91
|
-
}
|
|
92
|
-
|
|
93
|
-
return matches
|
|
94
|
-
}
|
|
95
|
-
|
|
96
|
-
function processOptions(options: ParseOptions = {}, filepath: string) {
|
|
97
|
-
return {
|
|
98
|
-
config: options.config || '.editorconfig',
|
|
99
|
-
version: options.version || pkg.version,
|
|
100
|
-
root: path.resolve(options.root || path.parse(filepath).root),
|
|
101
|
-
}
|
|
102
|
-
}
|
|
103
|
-
|
|
104
|
-
function buildFullGlob(pathPrefix: string, glob: string) {
|
|
105
|
-
switch (glob.indexOf('/')) {
|
|
106
|
-
case -1:
|
|
107
|
-
glob = '**/' + glob
|
|
108
|
-
break
|
|
109
|
-
case 0:
|
|
110
|
-
glob = glob.substring(1)
|
|
111
|
-
break
|
|
112
|
-
default:
|
|
113
|
-
break
|
|
114
|
-
}
|
|
115
|
-
return path.join(pathPrefix, glob)
|
|
116
|
-
}
|
|
117
|
-
|
|
118
|
-
function extendProps(props: {} = {}, options: {} = {}) {
|
|
119
|
-
for (const key in options) {
|
|
120
|
-
if (options.hasOwnProperty(key)) {
|
|
121
|
-
const value = options[key]
|
|
122
|
-
const key2 = key.toLowerCase()
|
|
123
|
-
let value2 = value
|
|
124
|
-
if (knownProps[key2]) {
|
|
125
|
-
value2 = value.toLowerCase()
|
|
126
|
-
}
|
|
127
|
-
try {
|
|
128
|
-
value2 = JSON.parse(value)
|
|
129
|
-
} catch (e) {}
|
|
130
|
-
if (typeof value === 'undefined' || value === null) {
|
|
131
|
-
// null and undefined are values specific to JSON (no special meaning
|
|
132
|
-
// in editorconfig) & should just be returned as regular strings.
|
|
133
|
-
value2 = String(value)
|
|
134
|
-
}
|
|
135
|
-
props[key2] = value2
|
|
136
|
-
}
|
|
137
|
-
}
|
|
138
|
-
return props
|
|
139
|
-
}
|
|
140
|
-
|
|
141
|
-
function parseFromConfigs(
|
|
142
|
-
configs: FileConfig[],
|
|
143
|
-
filepath: string,
|
|
144
|
-
options: ParseOptions,
|
|
145
|
-
) {
|
|
146
|
-
return processMatches(
|
|
147
|
-
configs
|
|
148
|
-
.reverse()
|
|
149
|
-
.reduce(
|
|
150
|
-
(matches: KnownProps, file) => {
|
|
151
|
-
const pathPrefix = path.dirname(file.name)
|
|
152
|
-
file.contents.forEach((section) => {
|
|
153
|
-
const glob = section[0]
|
|
154
|
-
const options2 = section[1]
|
|
155
|
-
if (!glob) {
|
|
156
|
-
return
|
|
157
|
-
}
|
|
158
|
-
const fullGlob = buildFullGlob(pathPrefix, glob)
|
|
159
|
-
if (!fnmatch(filepath, fullGlob)) {
|
|
160
|
-
return
|
|
161
|
-
}
|
|
162
|
-
matches = extendProps(matches, options2)
|
|
163
|
-
})
|
|
164
|
-
return matches
|
|
165
|
-
},
|
|
166
|
-
{},
|
|
167
|
-
),
|
|
168
|
-
options.version as string,
|
|
169
|
-
)
|
|
170
|
-
}
|
|
171
|
-
|
|
172
|
-
function getConfigsForFiles(files: ECFile[]) {
|
|
173
|
-
const configs = []
|
|
174
|
-
for (const i in files) {
|
|
175
|
-
if (files.hasOwnProperty(i)) {
|
|
176
|
-
const file = files[i]
|
|
177
|
-
const contents = parseString(file.contents as string)
|
|
178
|
-
configs.push({
|
|
179
|
-
name: file.name,
|
|
180
|
-
contents,
|
|
181
|
-
})
|
|
182
|
-
if ((contents[0][1].root || '').toLowerCase() === 'true') {
|
|
183
|
-
break
|
|
184
|
-
}
|
|
185
|
-
}
|
|
186
|
-
}
|
|
187
|
-
return configs
|
|
188
|
-
}
|
|
189
|
-
|
|
190
|
-
async function readConfigFiles(filepaths: string[]) {
|
|
191
|
-
return Promise.all(
|
|
192
|
-
filepaths.map((name) => new Promise((resolve) => {
|
|
193
|
-
fs.readFile(name, 'utf8', (err, data) => {
|
|
194
|
-
resolve({
|
|
195
|
-
name,
|
|
196
|
-
contents: err ? '' : data,
|
|
197
|
-
})
|
|
198
|
-
})
|
|
199
|
-
})),
|
|
200
|
-
)
|
|
201
|
-
}
|
|
202
|
-
|
|
203
|
-
function readConfigFilesSync(filepaths: string[]) {
|
|
204
|
-
const files: ECFile[] = []
|
|
205
|
-
let file: string | number | Buffer
|
|
206
|
-
filepaths.forEach((filepath) => {
|
|
207
|
-
try {
|
|
208
|
-
file = fs.readFileSync(filepath, 'utf8')
|
|
209
|
-
} catch (e) {
|
|
210
|
-
file = ''
|
|
211
|
-
}
|
|
212
|
-
files.push({
|
|
213
|
-
name: filepath,
|
|
214
|
-
contents: file,
|
|
215
|
-
})
|
|
216
|
-
})
|
|
217
|
-
return files
|
|
218
|
-
}
|
|
219
|
-
|
|
220
|
-
function opts(filepath: string, options: ParseOptions = {}): [
|
|
221
|
-
string,
|
|
222
|
-
ParseOptions
|
|
223
|
-
] {
|
|
224
|
-
const resolvedFilePath = path.resolve(filepath)
|
|
225
|
-
return [
|
|
226
|
-
resolvedFilePath,
|
|
227
|
-
processOptions(options, resolvedFilePath),
|
|
228
|
-
]
|
|
229
|
-
}
|
|
230
|
-
|
|
231
|
-
export async function parseFromFiles(
|
|
232
|
-
filepath: string,
|
|
233
|
-
files: Promise<ECFile[]>,
|
|
234
|
-
options: ParseOptions = {},
|
|
235
|
-
) {
|
|
236
|
-
const [resolvedFilePath, processedOptions] = opts(filepath, options)
|
|
237
|
-
return files.then(getConfigsForFiles)
|
|
238
|
-
.then((configs) => parseFromConfigs(
|
|
239
|
-
configs,
|
|
240
|
-
resolvedFilePath,
|
|
241
|
-
processedOptions,
|
|
242
|
-
))
|
|
243
|
-
}
|
|
244
|
-
|
|
245
|
-
export function parseFromFilesSync(
|
|
246
|
-
filepath: string,
|
|
247
|
-
files: ECFile[],
|
|
248
|
-
options: ParseOptions = {},
|
|
249
|
-
) {
|
|
250
|
-
const [resolvedFilePath, processedOptions] = opts(filepath, options)
|
|
251
|
-
return parseFromConfigs(
|
|
252
|
-
getConfigsForFiles(files),
|
|
253
|
-
resolvedFilePath,
|
|
254
|
-
processedOptions,
|
|
255
|
-
)
|
|
256
|
-
}
|
|
257
|
-
|
|
258
|
-
export async function parse(_filepath: string, _options: ParseOptions = {}) {
|
|
259
|
-
const [resolvedFilePath, processedOptions] = opts(_filepath, _options)
|
|
260
|
-
const filepaths = getConfigFileNames(resolvedFilePath, processedOptions)
|
|
261
|
-
return readConfigFiles(filepaths)
|
|
262
|
-
.then(getConfigsForFiles)
|
|
263
|
-
.then((configs) => parseFromConfigs(
|
|
264
|
-
configs,
|
|
265
|
-
resolvedFilePath,
|
|
266
|
-
processedOptions,
|
|
267
|
-
))
|
|
268
|
-
}
|
|
269
|
-
|
|
270
|
-
export function parseSync(_filepath: string, _options: ParseOptions = {}) {
|
|
271
|
-
const [resolvedFilePath, processedOptions] = opts(_filepath, _options)
|
|
272
|
-
const filepaths = getConfigFileNames(resolvedFilePath, processedOptions)
|
|
273
|
-
const files = readConfigFilesSync(filepaths)
|
|
274
|
-
return parseFromConfigs(
|
|
275
|
-
getConfigsForFiles(files),
|
|
276
|
-
resolvedFilePath,
|
|
277
|
-
processedOptions,
|
|
278
|
-
)
|
|
279
|
-
}
|
package/src/lib/ini.ts
DELETED
|
@@ -1,66 +0,0 @@
|
|
|
1
|
-
// Based on iniparser by shockie <https://npmjs.org/package/iniparser>
|
|
2
|
-
|
|
3
|
-
import * as fs from 'fs'
|
|
4
|
-
import { URL } from 'url'
|
|
5
|
-
|
|
6
|
-
/**
|
|
7
|
-
* define the possible values:
|
|
8
|
-
* section: [section]
|
|
9
|
-
* param: key=value
|
|
10
|
-
* comment: ;this is a comment
|
|
11
|
-
*/
|
|
12
|
-
const regex = {
|
|
13
|
-
section: /^\s*\[(([^#;]|\\#|\\;)+)\]\s*([#;].*)?$/,
|
|
14
|
-
param: /^\s*([\w\.\-\_]+)\s*[=:]\s*(.*?)\s*([#;].*)?$/,
|
|
15
|
-
comment: /^\s*[#;].*$/,
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
/**
|
|
19
|
-
* Parses an .ini file
|
|
20
|
-
* @param file The location of the .ini file
|
|
21
|
-
*/
|
|
22
|
-
export async function parse(file: string | number | Buffer | URL) {
|
|
23
|
-
return new Promise<ParseStringResult>(
|
|
24
|
-
(resolve, reject) => {
|
|
25
|
-
fs.readFile(file, 'utf8', (err, data) => {
|
|
26
|
-
if (err) {
|
|
27
|
-
reject(err)
|
|
28
|
-
return
|
|
29
|
-
}
|
|
30
|
-
resolve(parseString(data))
|
|
31
|
-
})
|
|
32
|
-
},
|
|
33
|
-
)
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
export function parseSync(file: string | number | Buffer | URL) {
|
|
37
|
-
return parseString(fs.readFileSync(file, 'utf8'))
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
export type SectionName = string | null
|
|
41
|
-
export interface SectionBody { [key: string]: string }
|
|
42
|
-
export type ParseStringResult = Array<[SectionName, SectionBody]>
|
|
43
|
-
|
|
44
|
-
export function parseString(data: string): ParseStringResult {
|
|
45
|
-
let sectionBody: SectionBody = {}
|
|
46
|
-
let sectionName: SectionName = null
|
|
47
|
-
const value: ParseStringResult = [[sectionName, sectionBody]]
|
|
48
|
-
const lines = data.split(/\r\n|\r|\n/)
|
|
49
|
-
lines.forEach((line) => {
|
|
50
|
-
let match: RegExpMatchArray | null
|
|
51
|
-
if (regex.comment.test(line)) {
|
|
52
|
-
return
|
|
53
|
-
}
|
|
54
|
-
if (regex.param.test(line)) {
|
|
55
|
-
match = line.match(regex.param)
|
|
56
|
-
sectionBody[(match as RegExpMatchArray)[1]] =
|
|
57
|
-
(match as RegExpMatchArray)[2]
|
|
58
|
-
} else if (regex.section.test(line)) {
|
|
59
|
-
match = line.match(regex.section)
|
|
60
|
-
sectionName = (match as RegExpMatchArray)[1]
|
|
61
|
-
sectionBody = {}
|
|
62
|
-
value.push([sectionName, sectionBody])
|
|
63
|
-
}
|
|
64
|
-
})
|
|
65
|
-
return value
|
|
66
|
-
}
|
package/tests/.editorconfig
DELETED
package/tests/.git
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
gitdir: ../.git/modules/tests
|