config2ts 2.1.2 → 2.1.4
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/config/data.csv +4 -4
- package/config/data.csv.ts +33 -33
- package/config/ini-file.ini +9 -9
- package/config/ini-file.ini.ts +8 -8
- package/config/no-id.csv +4 -4
- package/config/no-id.csv.ts +26 -26
- package/config/toml_file.toml +7 -7
- package/config/toml_file.toml.ts +7 -7
- package/config/total.ts +61 -61
- package/dist/config2ts.js +3 -2
- package/dist/main.js +4 -4
- package/package.json +2 -1
package/config/data.csv
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
id,name,bool,num
|
|
2
|
-
String,String,Boolean,Number
|
|
3
|
-
1,"xxx",1,111
|
|
4
|
-
2,"xxx",,222
|
|
1
|
+
id,name,bool,num
|
|
2
|
+
String,String,Boolean,Number
|
|
3
|
+
1,"xxx",1,111
|
|
4
|
+
2,"xxx",,222
|
|
5
5
|
3,333,,
|
package/config/data.csv.ts
CHANGED
|
@@ -1,34 +1,34 @@
|
|
|
1
|
-
export namespace DataCsv {
|
|
2
|
-
|
|
3
|
-
export interface Record {
|
|
4
|
-
id: string;
|
|
5
|
-
name: string;
|
|
6
|
-
bool: boolean;
|
|
7
|
-
num: number;
|
|
8
|
-
};
|
|
9
|
-
|
|
10
|
-
export const List: Record[] = [
|
|
11
|
-
{
|
|
12
|
-
"id": "1",
|
|
13
|
-
"name": "xxx",
|
|
14
|
-
"bool": true,
|
|
15
|
-
"num": 111
|
|
16
|
-
},
|
|
17
|
-
{
|
|
18
|
-
"id": "2",
|
|
19
|
-
"name": "xxx",
|
|
20
|
-
"bool": false,
|
|
21
|
-
"num": 222
|
|
22
|
-
},
|
|
23
|
-
{
|
|
24
|
-
"id": "3",
|
|
25
|
-
"name": "333",
|
|
26
|
-
"bool": false,
|
|
27
|
-
"num": 0
|
|
28
|
-
}
|
|
29
|
-
];
|
|
30
|
-
|
|
31
|
-
export const Map: { [id: string]: Record } = {};
|
|
32
|
-
for (const v of List) { Map[v.id] = v; };
|
|
33
|
-
|
|
1
|
+
export namespace DataCsv {
|
|
2
|
+
|
|
3
|
+
export interface Record {
|
|
4
|
+
id: string;
|
|
5
|
+
name: string;
|
|
6
|
+
bool: boolean;
|
|
7
|
+
num: number;
|
|
8
|
+
};
|
|
9
|
+
|
|
10
|
+
export const List: Record[] = [
|
|
11
|
+
{
|
|
12
|
+
"id": "1",
|
|
13
|
+
"name": "xxx",
|
|
14
|
+
"bool": true,
|
|
15
|
+
"num": 111
|
|
16
|
+
},
|
|
17
|
+
{
|
|
18
|
+
"id": "2",
|
|
19
|
+
"name": "xxx",
|
|
20
|
+
"bool": false,
|
|
21
|
+
"num": 222
|
|
22
|
+
},
|
|
23
|
+
{
|
|
24
|
+
"id": "3",
|
|
25
|
+
"name": "333",
|
|
26
|
+
"bool": false,
|
|
27
|
+
"num": 0
|
|
28
|
+
}
|
|
29
|
+
];
|
|
30
|
+
|
|
31
|
+
export const Map: { [id: string]: Record } = {};
|
|
32
|
+
for (const v of List) { Map[v.id] = v; };
|
|
33
|
+
|
|
34
34
|
};
|
package/config/ini-file.ini
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
num = 1
|
|
2
|
-
|
|
3
|
-
str = "string"
|
|
4
|
-
|
|
5
|
-
bool = true
|
|
6
|
-
|
|
7
|
-
[ItemType]
|
|
8
|
-
book = 1
|
|
9
|
-
fruit = 2
|
|
1
|
+
num = 1
|
|
2
|
+
|
|
3
|
+
str = "string"
|
|
4
|
+
|
|
5
|
+
bool = true
|
|
6
|
+
|
|
7
|
+
[ItemType]
|
|
8
|
+
book = 1
|
|
9
|
+
fruit = 2
|
package/config/ini-file.ini.ts
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
export const IniFileIni = {
|
|
2
|
-
"num": 1,
|
|
3
|
-
"str": "string",
|
|
4
|
-
"bool": true,
|
|
5
|
-
"ItemType": {
|
|
6
|
-
"book": 1,
|
|
7
|
-
"fruit": 2
|
|
8
|
-
}
|
|
1
|
+
export const IniFileIni = {
|
|
2
|
+
"num": 1,
|
|
3
|
+
"str": "string",
|
|
4
|
+
"bool": true,
|
|
5
|
+
"ItemType": {
|
|
6
|
+
"book": 1,
|
|
7
|
+
"fruit": 2
|
|
8
|
+
}
|
|
9
9
|
};
|
package/config/no-id.csv
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
name,bool,num
|
|
2
|
-
String,Boolean,Number
|
|
3
|
-
"xxx",1,111
|
|
4
|
-
"xxx",,222
|
|
1
|
+
name,bool,num
|
|
2
|
+
String,Boolean,Number
|
|
3
|
+
"xxx",1,111
|
|
4
|
+
"xxx",,222
|
|
5
5
|
333,,
|
package/config/no-id.csv.ts
CHANGED
|
@@ -1,27 +1,27 @@
|
|
|
1
|
-
export namespace NoIdCsv {
|
|
2
|
-
|
|
3
|
-
export interface Record {
|
|
4
|
-
name: string;
|
|
5
|
-
bool: boolean;
|
|
6
|
-
num: number;
|
|
7
|
-
};
|
|
8
|
-
|
|
9
|
-
export const List: Record[] = [
|
|
10
|
-
{
|
|
11
|
-
"name": "xxx",
|
|
12
|
-
"bool": true,
|
|
13
|
-
"num": 111
|
|
14
|
-
},
|
|
15
|
-
{
|
|
16
|
-
"name": "xxx",
|
|
17
|
-
"bool": false,
|
|
18
|
-
"num": 222
|
|
19
|
-
},
|
|
20
|
-
{
|
|
21
|
-
"name": "333",
|
|
22
|
-
"bool": false,
|
|
23
|
-
"num": 0
|
|
24
|
-
}
|
|
25
|
-
];
|
|
26
|
-
|
|
1
|
+
export namespace NoIdCsv {
|
|
2
|
+
|
|
3
|
+
export interface Record {
|
|
4
|
+
name: string;
|
|
5
|
+
bool: boolean;
|
|
6
|
+
num: number;
|
|
7
|
+
};
|
|
8
|
+
|
|
9
|
+
export const List: Record[] = [
|
|
10
|
+
{
|
|
11
|
+
"name": "xxx",
|
|
12
|
+
"bool": true,
|
|
13
|
+
"num": 111
|
|
14
|
+
},
|
|
15
|
+
{
|
|
16
|
+
"name": "xxx",
|
|
17
|
+
"bool": false,
|
|
18
|
+
"num": 222
|
|
19
|
+
},
|
|
20
|
+
{
|
|
21
|
+
"name": "333",
|
|
22
|
+
"bool": false,
|
|
23
|
+
"num": 0
|
|
24
|
+
}
|
|
25
|
+
];
|
|
26
|
+
|
|
27
27
|
};
|
package/config/toml_file.toml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
num = 1
|
|
2
|
-
|
|
3
|
-
str = "test"
|
|
4
|
-
|
|
5
|
-
[ItemType]
|
|
6
|
-
book = 1
|
|
7
|
-
fruit = 2
|
|
1
|
+
num = 1
|
|
2
|
+
|
|
3
|
+
str = "test"
|
|
4
|
+
|
|
5
|
+
[ItemType]
|
|
6
|
+
book = 1
|
|
7
|
+
fruit = 2
|
package/config/toml_file.toml.ts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
export const TomlFileToml = {
|
|
2
|
-
"num": 1,
|
|
3
|
-
"str": "test",
|
|
4
|
-
"ItemType": {
|
|
5
|
-
"book": 1,
|
|
6
|
-
"fruit": 2
|
|
7
|
-
}
|
|
1
|
+
export const TomlFileToml = {
|
|
2
|
+
"num": 1,
|
|
3
|
+
"str": "test",
|
|
4
|
+
"ItemType": {
|
|
5
|
+
"book": 1,
|
|
6
|
+
"fruit": 2
|
|
7
|
+
}
|
|
8
8
|
};
|
package/config/total.ts
CHANGED
|
@@ -1,62 +1,62 @@
|
|
|
1
|
-
export namespace DataCsv {
|
|
2
|
-
|
|
3
|
-
export interface Record {
|
|
4
|
-
id: string;
|
|
5
|
-
name: string;
|
|
6
|
-
bool: boolean;
|
|
7
|
-
num: number;
|
|
8
|
-
};
|
|
9
|
-
|
|
10
|
-
export const List: Record[] = [
|
|
11
|
-
{
|
|
12
|
-
"id": "1",
|
|
13
|
-
"name": "xxx",
|
|
14
|
-
"bool": true,
|
|
15
|
-
"num": 111
|
|
16
|
-
},
|
|
17
|
-
{
|
|
18
|
-
"id": "2",
|
|
19
|
-
"name": "xxx",
|
|
20
|
-
"bool": false,
|
|
21
|
-
"num": 222
|
|
22
|
-
},
|
|
23
|
-
{
|
|
24
|
-
"id": "3",
|
|
25
|
-
"name": "333",
|
|
26
|
-
"bool": false,
|
|
27
|
-
"num": 0
|
|
28
|
-
}
|
|
29
|
-
];
|
|
30
|
-
|
|
31
|
-
export const Map: { [id: string]: Record } = {};
|
|
32
|
-
for (const v of List) { Map[v.id] = v; };
|
|
33
|
-
|
|
34
|
-
};
|
|
35
|
-
|
|
36
|
-
export namespace NoIdCsv {
|
|
37
|
-
|
|
38
|
-
export interface Record {
|
|
39
|
-
name: string;
|
|
40
|
-
bool: boolean;
|
|
41
|
-
num: number;
|
|
42
|
-
};
|
|
43
|
-
|
|
44
|
-
export const List: Record[] = [
|
|
45
|
-
{
|
|
46
|
-
"name": "xxx",
|
|
47
|
-
"bool": true,
|
|
48
|
-
"num": 111
|
|
49
|
-
},
|
|
50
|
-
{
|
|
51
|
-
"name": "xxx",
|
|
52
|
-
"bool": false,
|
|
53
|
-
"num": 222
|
|
54
|
-
},
|
|
55
|
-
{
|
|
56
|
-
"name": "333",
|
|
57
|
-
"bool": false,
|
|
58
|
-
"num": 0
|
|
59
|
-
}
|
|
60
|
-
];
|
|
61
|
-
|
|
1
|
+
export namespace DataCsv {
|
|
2
|
+
|
|
3
|
+
export interface Record {
|
|
4
|
+
id: string;
|
|
5
|
+
name: string;
|
|
6
|
+
bool: boolean;
|
|
7
|
+
num: number;
|
|
8
|
+
};
|
|
9
|
+
|
|
10
|
+
export const List: Record[] = [
|
|
11
|
+
{
|
|
12
|
+
"id": "1",
|
|
13
|
+
"name": "xxx",
|
|
14
|
+
"bool": true,
|
|
15
|
+
"num": 111
|
|
16
|
+
},
|
|
17
|
+
{
|
|
18
|
+
"id": "2",
|
|
19
|
+
"name": "xxx",
|
|
20
|
+
"bool": false,
|
|
21
|
+
"num": 222
|
|
22
|
+
},
|
|
23
|
+
{
|
|
24
|
+
"id": "3",
|
|
25
|
+
"name": "333",
|
|
26
|
+
"bool": false,
|
|
27
|
+
"num": 0
|
|
28
|
+
}
|
|
29
|
+
];
|
|
30
|
+
|
|
31
|
+
export const Map: { [id: string]: Record } = {};
|
|
32
|
+
for (const v of List) { Map[v.id] = v; };
|
|
33
|
+
|
|
34
|
+
};
|
|
35
|
+
|
|
36
|
+
export namespace NoIdCsv {
|
|
37
|
+
|
|
38
|
+
export interface Record {
|
|
39
|
+
name: string;
|
|
40
|
+
bool: boolean;
|
|
41
|
+
num: number;
|
|
42
|
+
};
|
|
43
|
+
|
|
44
|
+
export const List: Record[] = [
|
|
45
|
+
{
|
|
46
|
+
"name": "xxx",
|
|
47
|
+
"bool": true,
|
|
48
|
+
"num": 111
|
|
49
|
+
},
|
|
50
|
+
{
|
|
51
|
+
"name": "xxx",
|
|
52
|
+
"bool": false,
|
|
53
|
+
"num": 222
|
|
54
|
+
},
|
|
55
|
+
{
|
|
56
|
+
"name": "333",
|
|
57
|
+
"bool": false,
|
|
58
|
+
"num": 0
|
|
59
|
+
}
|
|
60
|
+
];
|
|
61
|
+
|
|
62
62
|
};
|
package/dist/config2ts.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.GetValidFileList = exports.GetHeaderInfo = exports.GetTsStringFromFileList = exports.GetTsString = exports.Convert = void 0;
|
|
3
4
|
const path = require("path");
|
|
4
5
|
const fs = require("fs");
|
|
5
6
|
const d3 = require("d3");
|
|
@@ -53,8 +54,8 @@ function csv2ts(csvString, moduleName) {
|
|
|
53
54
|
// console.log(prettyFormat(result, op));
|
|
54
55
|
template += JSON.stringify(result, null, 4).replace(/\n/g, '\n ');
|
|
55
56
|
template += ';\n\n';
|
|
56
|
-
if (convert['id'] === '
|
|
57
|
-
template += ` export const Map: { [id:
|
|
57
|
+
if (convert['id'] === 'String') {
|
|
58
|
+
template += ` export const Map: { [id: string]: Record } = {};\n`;
|
|
58
59
|
template += ` for (const v of List) { Map[v.id] = v; };\n\n`;
|
|
59
60
|
}
|
|
60
61
|
template += "};";
|
package/dist/main.js
CHANGED
|
@@ -15,17 +15,17 @@ let outDir = program['outDir'] || dir;
|
|
|
15
15
|
let merge = program['merge'];
|
|
16
16
|
let fileList = fs.readdirSync(dir);
|
|
17
17
|
if (merge) {
|
|
18
|
-
fileList = config2ts_1.GetValidFileList(fileList).map((filename) => {
|
|
18
|
+
fileList = (0, config2ts_1.GetValidFileList)(fileList).map((filename) => {
|
|
19
19
|
return path.join(dir, filename);
|
|
20
20
|
});
|
|
21
21
|
let mergeFile = path.join(outDir, merge);
|
|
22
|
-
fs.writeFileSync(mergeFile, config2ts_1.GetHeaderInfo() + config2ts_1.GetTsStringFromFileList(fileList));
|
|
22
|
+
fs.writeFileSync(mergeFile, (0, config2ts_1.GetHeaderInfo)() + (0, config2ts_1.GetTsStringFromFileList)(fileList));
|
|
23
23
|
console.log(`config2ts, ${fileList.length} config files, merge into: ${mergeFile}`);
|
|
24
24
|
}
|
|
25
25
|
else {
|
|
26
|
-
config2ts_1.GetValidFileList(fileList).forEach((filename) => {
|
|
26
|
+
(0, config2ts_1.GetValidFileList)(fileList).forEach((filename) => {
|
|
27
27
|
let target = path.join(outDir, `${filename}.ts`);
|
|
28
|
-
fs.writeFileSync(target, config2ts_1.GetTsString(path.join(dir, filename)));
|
|
28
|
+
fs.writeFileSync(target, (0, config2ts_1.GetTsString)(path.join(dir, filename)));
|
|
29
29
|
console.log(`config2ts, convert: ${filename} , to: ${target}`);
|
|
30
30
|
});
|
|
31
31
|
console.log('config2ts convert done!');
|