@awesomeness-js/utils 1.0.24 → 1.1.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/README.md +112 -86
- package/build/build.js +16 -11
- package/build/postBuild.js +8 -8
- package/eslint.config.js +90 -0
- package/index.js +108 -78
- package/package.json +26 -25
- package/schemas/schema1.js +5 -1
- package/schemas/schema2.js +5 -1
- package/schemas.js +3 -2
- package/src/build.js +88 -8
- package/src/clean/boolean.js +27 -17
- package/src/clean/integer.js +85 -69
- package/src/clean/number.js +103 -86
- package/src/clean/string.js +91 -67
- package/src/clean/timestamp.js +61 -45
- package/src/clean/uuid.js +38 -25
- package/src/collectImports.js +195 -0
- package/src/combineFiles.js +45 -36
- package/src/convertBytes.js +12 -7
- package/src/decrypt.js +17 -9
- package/src/each.js +26 -4
- package/src/eachAsync.js +35 -19
- package/src/encrypt.js +22 -17
- package/src/getAllFiles.js +56 -42
- package/src/ignoreFolder/ignoreMe.js +6 -2
- package/src/ignoreMe.js +4 -2
- package/src/isUUID.js +4 -0
- package/src/md5.js +5 -1
- package/src/password/check.js +7 -3
- package/src/password/hash.js +12 -7
- package/src/setLocalEnvs.js +16 -3
- package/src/shouldIgnore.js +99 -0
- package/src/thingType.js +62 -24
- package/src/toPennies.js +23 -5
- package/src/utils/buildExportsTree.js +45 -17
- package/src/utils/buildFileDataList.js +37 -18
- package/src/utils/clean.js +205 -120
- package/src/utils/extractJSDocComment.js +14 -7
- package/src/utils/generateFile.js +54 -18
- package/src/utils/generateFlatExportLines.js +40 -17
- package/src/utils/generateImportStatements.js +20 -8
- package/src/utils/generateNamedExports.js +55 -10
- package/src/utils/generateNamespaceCode.js +56 -24
- package/src/utils/generateNamespaceExportLines.js +27 -7
- package/src/utils/writeHotWrapper.js +42 -0
- package/src/uuid.js +9 -7
- package/src/validateSchema.js +95 -77
- package/test/collectImports.js +8 -0
- package/test/css/some.css +3 -0
- package/test/css/some.js +5 -0
- package/test/ignoreFolder/ignoreMe.js +3 -1
- package/test/ignoreFolder/ignoreMe2.js +3 -1
- package/test/ignoreFolder2/ignoreMe.js +6 -2
- package/test/js/abc.test.js +7 -3
- package/test/js/some.js +5 -0
- package/test/secret.test.js +1 -1
- package/tests/clean/array.test.js +122 -74
- package/tests/clean/boolean.test.js +18 -6
- package/tests/clean/integer.test.js +25 -9
- package/tests/clean/number.test.js +49 -13
- package/tests/clean/object.test.js +190 -119
- package/tests/clean/string.test.js +48 -17
- package/tests/clean/timestamp.test.js +12 -5
- package/tests/clean/uuid.test.js +13 -6
- package/tests/collectImports.test.js +66 -0
- package/tests/combineFiles.test.js +28 -26
- package/tests/convertBytes.test.js +8 -3
- package/tests/env.test.js +9 -3
- package/tests/example.test.js +7 -3
- package/tests/fileList.test.js +16 -12
- package/tests/hash-and-encrypt.test.js +13 -4
- package/tests/ignore.test.js +55 -0
- package/tests/md5.test.js +7 -2
- package/tests/namedExports.test.js +13 -0
- package/tests/uuid.test.js +10 -4
- package/tests/validateSchema.test.js +21 -9
- package/tsconfig.json +20 -16
- package/types/build.d.ts +5 -1
- package/types/collectImports.d.ts +6 -0
- package/types/index.d.ts +108 -78
- package/types/shouldIgnore.d.ts +1 -0
- package/types/utils/buildFileDataList.d.ts +5 -1
- package/types/utils/generateFile.d.ts +8 -1
- package/types/utils/generateFlatExportLines.d.ts +7 -1
- package/types/utils/generateImportStatements.d.ts +5 -1
- package/types/utils/generateNamedExports.d.ts +7 -1
- package/types/utils/generateNamespaceCode.d.ts +7 -1
- package/types/utils/generateNamespaceExportLines.d.ts +6 -1
- package/types/utils/writeHotWrapper.d.ts +4 -0
- package/src/utils/shouldIgnore.js +0 -43
|
@@ -1,19 +1,47 @@
|
|
|
1
1
|
export default function buildExportsTree(fileDataList) {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
2
|
+
|
|
3
|
+
const flatExports = [];
|
|
4
|
+
const nestedExports = {};
|
|
5
|
+
|
|
6
|
+
fileDataList.forEach(({
|
|
7
|
+
parts, functionName, importVarName, jsDocComment
|
|
8
|
+
}) => {
|
|
9
|
+
|
|
10
|
+
if (parts.length === 0) {
|
|
11
|
+
|
|
12
|
+
flatExports.push({
|
|
13
|
+
functionName,
|
|
14
|
+
importVarName,
|
|
15
|
+
jsDocComment
|
|
16
|
+
});
|
|
17
|
+
|
|
18
|
+
} else {
|
|
19
|
+
|
|
20
|
+
let current = nestedExports;
|
|
21
|
+
|
|
22
|
+
parts.forEach((part) => {
|
|
23
|
+
|
|
24
|
+
if (!current[part]) {
|
|
25
|
+
|
|
26
|
+
current[part] = {};
|
|
27
|
+
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
current = current[part];
|
|
31
|
+
|
|
32
|
+
});
|
|
33
|
+
current[functionName] = {
|
|
34
|
+
importVarName,
|
|
35
|
+
jsDocComment
|
|
36
|
+
};
|
|
37
|
+
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
});
|
|
41
|
+
|
|
42
|
+
return {
|
|
43
|
+
flatExports,
|
|
44
|
+
nestedExports
|
|
45
|
+
};
|
|
46
|
+
|
|
19
47
|
}
|
|
@@ -2,22 +2,41 @@ import getAllFiles from '../getAllFiles.js';
|
|
|
2
2
|
import extractJSDocComment from './extractJSDocComment.js';
|
|
3
3
|
import { join } from 'path';
|
|
4
4
|
|
|
5
|
-
export default function buildFileDataList(
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
5
|
+
export default function buildFileDataList({
|
|
6
|
+
src,
|
|
7
|
+
ignore,
|
|
8
|
+
includeComments
|
|
9
|
+
}) {
|
|
10
|
+
|
|
11
|
+
const allFiles = getAllFiles(src, {
|
|
12
|
+
ignore,
|
|
13
|
+
fileTypes: [ '.js' ]
|
|
14
|
+
});
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
return allFiles.map((file) => {
|
|
18
|
+
|
|
19
|
+
const normalizedFile = file.replace(/\\/g, '/');
|
|
20
|
+
const parts = normalizedFile.split('/');
|
|
21
|
+
const fileName = parts.pop();
|
|
22
|
+
const functionName = fileName.replace(/\.js$/, '');
|
|
23
|
+
const namespaceParts = parts;
|
|
24
|
+
const importVarName = namespaceParts.length > 0
|
|
25
|
+
? '_' + [ ...namespaceParts, functionName ].join('_')
|
|
26
|
+
: '_' + functionName;
|
|
27
|
+
const importPath = src + '/' + normalizedFile.replace(/\.js$/, '');
|
|
28
|
+
const jsDocComment = includeComments ? extractJSDocComment(join(src, normalizedFile)) : '';
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
return {
|
|
32
|
+
normalizedFile,
|
|
33
|
+
parts: namespaceParts,
|
|
34
|
+
functionName,
|
|
35
|
+
importVarName,
|
|
36
|
+
importPath,
|
|
37
|
+
jsDocComment
|
|
38
|
+
};
|
|
39
|
+
|
|
40
|
+
});
|
|
41
|
+
|
|
23
42
|
}
|
package/src/utils/clean.js
CHANGED
|
@@ -11,88 +11,135 @@ import cleanUUID from '../clean/uuid.js';
|
|
|
11
11
|
|
|
12
12
|
function cleanArray(arr, schema = {}){
|
|
13
13
|
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
14
|
+
try {
|
|
15
|
+
|
|
16
|
+
if(!Array.isArray(arr)) {
|
|
17
|
+
|
|
18
|
+
throw {
|
|
19
|
+
message: 'Input must be an array',
|
|
20
|
+
arr
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
}
|
|
22
24
|
|
|
23
|
-
|
|
25
|
+
validateSchema(schema);
|
|
24
26
|
|
|
25
|
-
|
|
27
|
+
const cleanArrayItems = [];
|
|
26
28
|
|
|
27
|
-
|
|
29
|
+
const supposedToBeType = schema.items.type;
|
|
28
30
|
|
|
29
|
-
|
|
31
|
+
arr.forEach( (item, key) => {
|
|
30
32
|
|
|
31
|
-
|
|
33
|
+
const itemType = thingType(item);
|
|
32
34
|
|
|
33
35
|
|
|
34
|
-
|
|
36
|
+
if(itemType !== supposedToBeType){
|
|
35
37
|
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
38
|
+
throw {
|
|
39
|
+
message: 'type invalid',
|
|
40
|
+
itemType,
|
|
41
|
+
supposedToBeType
|
|
42
|
+
};
|
|
41
43
|
|
|
42
|
-
|
|
44
|
+
}
|
|
43
45
|
|
|
44
|
-
|
|
46
|
+
let cleanedItem = item;
|
|
45
47
|
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
48
|
+
if(supposedToBeType === 'boolean'){
|
|
49
|
+
|
|
50
|
+
cleanedItem = cleanBoolean(item);
|
|
51
|
+
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
if(supposedToBeType === 'integer'){
|
|
55
|
+
|
|
56
|
+
cleanedItem = cleanInteger(item);
|
|
57
|
+
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
if(supposedToBeType === 'number'){
|
|
61
|
+
|
|
62
|
+
cleanedItem = cleanNumber(item);
|
|
63
|
+
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
if(supposedToBeType === 'string'){
|
|
67
|
+
|
|
68
|
+
cleanedItem = cleanString(item);
|
|
69
|
+
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
if(supposedToBeType === 'timestamp'){
|
|
73
|
+
|
|
74
|
+
cleanedItem = cleanTimestamp(item);
|
|
75
|
+
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
if(supposedToBeType === 'uuid'){
|
|
79
|
+
|
|
80
|
+
cleanedItem = cleanUUID(item);
|
|
81
|
+
|
|
82
|
+
}
|
|
52
83
|
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
84
|
+
if(supposedToBeType === 'array'){
|
|
85
|
+
|
|
86
|
+
cleanedItem = cleanArray(item, schema.items);
|
|
87
|
+
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
if(supposedToBeType === 'object'){
|
|
91
|
+
|
|
92
|
+
cleanedItem = cleanObject(item, schema.items);
|
|
93
|
+
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
if(cleanedItem === null){
|
|
97
|
+
|
|
98
|
+
if(schema.required === true){
|
|
99
|
+
|
|
100
|
+
throw {
|
|
101
|
+
message: 'required item is null',
|
|
102
|
+
item,
|
|
103
|
+
key
|
|
104
|
+
};
|
|
105
|
+
|
|
106
|
+
} else {
|
|
107
|
+
|
|
108
|
+
return; // skip this item if it's not required and is null
|
|
109
|
+
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
}
|
|
72
113
|
|
|
73
114
|
|
|
74
|
-
|
|
115
|
+
cleanArrayItems.push(cleanedItem);
|
|
75
116
|
|
|
76
|
-
|
|
117
|
+
});
|
|
77
118
|
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
119
|
+
if(cleanArrayItems.length === 0){
|
|
120
|
+
|
|
121
|
+
throw {
|
|
122
|
+
message: 'array is empty',
|
|
123
|
+
arr
|
|
124
|
+
};
|
|
125
|
+
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
return cleanArrayItems;
|
|
84
129
|
|
|
85
|
-
|
|
130
|
+
} catch (e) {
|
|
86
131
|
|
|
87
|
-
|
|
132
|
+
if(schema.required === true){
|
|
88
133
|
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
return null;
|
|
93
|
-
}
|
|
134
|
+
throw e;
|
|
135
|
+
|
|
136
|
+
} else {
|
|
94
137
|
|
|
95
|
-
|
|
138
|
+
return null;
|
|
139
|
+
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
}
|
|
96
143
|
|
|
97
144
|
|
|
98
145
|
|
|
@@ -101,83 +148,121 @@ function cleanArray(arr, schema = {}){
|
|
|
101
148
|
|
|
102
149
|
function cleanObject(obj, schema){
|
|
103
150
|
|
|
104
|
-
|
|
151
|
+
validateSchema(schema);
|
|
152
|
+
|
|
153
|
+
if(typeof obj !== 'object' || obj === null){
|
|
154
|
+
|
|
155
|
+
throw {
|
|
156
|
+
message: 'Clean Object - Input must be an object',
|
|
157
|
+
obj,
|
|
158
|
+
schema
|
|
159
|
+
};
|
|
160
|
+
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
let keysPassed = Object.keys(obj);
|
|
164
|
+
let keysSchema = Object.keys(schema.properties);
|
|
165
|
+
|
|
166
|
+
const origLength = keysPassed.length;
|
|
167
|
+
|
|
168
|
+
keysPassed = keysPassed.filter((key) => keysSchema.includes(key));
|
|
169
|
+
|
|
170
|
+
if(origLength !== keysPassed.length){
|
|
171
|
+
|
|
172
|
+
throw {
|
|
173
|
+
name: 'KeyError',
|
|
174
|
+
message: 'Object contains keys not in schema',
|
|
175
|
+
keysPassed,
|
|
176
|
+
keysSchema,
|
|
177
|
+
obj
|
|
178
|
+
};
|
|
179
|
+
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
const cleanObj = {};
|
|
183
|
+
|
|
184
|
+
// Iterate over the schema keys
|
|
185
|
+
each(obj, (value, key) => {
|
|
186
|
+
|
|
187
|
+
const valType = thingType(value);
|
|
188
|
+
const supposedToBeType = schema.properties[key].type;
|
|
189
|
+
|
|
190
|
+
if(valType !== supposedToBeType){
|
|
191
|
+
|
|
192
|
+
throw {
|
|
193
|
+
message: 'type invalid',
|
|
194
|
+
valType,
|
|
195
|
+
supposedToBeType,
|
|
196
|
+
key
|
|
197
|
+
};
|
|
198
|
+
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
let cleanedValue;
|
|
202
|
+
|
|
203
|
+
if(supposedToBeType === 'boolean'){
|
|
204
|
+
|
|
205
|
+
cleanedValue = cleanBoolean(value);
|
|
206
|
+
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
if(supposedToBeType === 'integer'){
|
|
210
|
+
|
|
211
|
+
cleanedValue = cleanInteger(value);
|
|
212
|
+
|
|
213
|
+
}
|
|
105
214
|
|
|
106
|
-
|
|
107
|
-
throw {
|
|
108
|
-
message: 'Clean Object - Input must be an object',
|
|
109
|
-
obj,
|
|
110
|
-
schema
|
|
111
|
-
};
|
|
112
|
-
}
|
|
215
|
+
if(supposedToBeType === 'number'){
|
|
113
216
|
|
|
114
|
-
|
|
115
|
-
let keysSchema = Object.keys(schema.properties);
|
|
217
|
+
cleanedValue = cleanNumber(value);
|
|
116
218
|
|
|
117
|
-
|
|
118
|
-
keysPassed = keysPassed.filter(key => keysSchema.includes(key));
|
|
219
|
+
}
|
|
119
220
|
|
|
120
|
-
|
|
121
|
-
throw {
|
|
122
|
-
name: 'KeyError',
|
|
123
|
-
message: 'Object contains keys not in schema',
|
|
124
|
-
keysPassed,
|
|
125
|
-
keysSchema,
|
|
126
|
-
obj
|
|
127
|
-
};
|
|
128
|
-
}
|
|
221
|
+
if(supposedToBeType === 'string'){
|
|
129
222
|
|
|
130
|
-
|
|
223
|
+
cleanedValue = cleanString(value);
|
|
131
224
|
|
|
132
|
-
|
|
133
|
-
each(obj, (value, key) => {
|
|
225
|
+
}
|
|
134
226
|
|
|
135
|
-
|
|
136
|
-
const supposedToBeType = schema.properties[key].type;
|
|
227
|
+
if(supposedToBeType === 'timestamp'){
|
|
137
228
|
|
|
138
|
-
|
|
229
|
+
cleanedValue = cleanTimestamp(value);
|
|
139
230
|
|
|
140
|
-
|
|
141
|
-
message: 'type invalid',
|
|
142
|
-
valType,
|
|
143
|
-
supposedToBeType,
|
|
144
|
-
key
|
|
145
|
-
};
|
|
231
|
+
}
|
|
146
232
|
|
|
147
|
-
|
|
233
|
+
if(supposedToBeType === 'uuid'){
|
|
148
234
|
|
|
149
|
-
|
|
235
|
+
cleanedValue = cleanUUID(value);
|
|
150
236
|
|
|
151
|
-
|
|
152
|
-
if(supposedToBeType === 'integer'){ cleanedValue = cleanInteger(value); }
|
|
153
|
-
if(supposedToBeType === 'number'){ cleanedValue = cleanNumber(value); }
|
|
154
|
-
if(supposedToBeType === 'string'){ cleanedValue = cleanString(value); }
|
|
155
|
-
if(supposedToBeType === 'timestamp'){ cleanedValue = cleanTimestamp(value); }
|
|
156
|
-
if(supposedToBeType === 'uuid'){ cleanedValue = cleanUUID(value); }
|
|
237
|
+
}
|
|
157
238
|
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
239
|
+
if(supposedToBeType === 'object'){
|
|
240
|
+
|
|
241
|
+
cleanedValue = cleanObject(value, schema.properties[key]);
|
|
242
|
+
|
|
243
|
+
}
|
|
161
244
|
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
245
|
+
if(supposedToBeType === 'array'){
|
|
246
|
+
|
|
247
|
+
cleanedValue = cleanArray(value, schema.properties[key]);
|
|
248
|
+
|
|
249
|
+
}
|
|
165
250
|
|
|
166
|
-
|
|
251
|
+
cleanObj[key] = cleanedValue;
|
|
167
252
|
|
|
168
|
-
|
|
253
|
+
});
|
|
169
254
|
|
|
170
|
-
|
|
255
|
+
return cleanObj;
|
|
171
256
|
|
|
172
257
|
}
|
|
173
258
|
|
|
174
259
|
export default {
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
260
|
+
array: cleanArray,
|
|
261
|
+
object: cleanObject,
|
|
262
|
+
boolean: cleanBoolean,
|
|
263
|
+
integer: cleanInteger,
|
|
264
|
+
number: cleanNumber,
|
|
265
|
+
string: cleanString,
|
|
266
|
+
timestamp: cleanTimestamp,
|
|
267
|
+
uuid: cleanUUID
|
|
183
268
|
};
|
|
@@ -1,11 +1,18 @@
|
|
|
1
1
|
import { readFileSync } from 'fs';
|
|
2
2
|
|
|
3
3
|
export default function extractJSDocComment(filePath) {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
4
|
+
|
|
5
|
+
const fileContent = readFileSync(filePath, 'utf8');
|
|
6
|
+
const match = fileContent.match(/\/\*\*([\s\S]*?)\*\//);
|
|
7
|
+
|
|
8
|
+
// If the match exists and doesn't contain an unresolved template placeholder, return it.
|
|
9
|
+
|
|
10
|
+
if (match && match[1] && !match[1].includes('${')) {
|
|
11
|
+
|
|
12
|
+
return `/**${match[1]}*/`;
|
|
13
|
+
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
return '';
|
|
17
|
+
|
|
11
18
|
}
|
|
@@ -5,30 +5,66 @@ import generateFlatExportLines from './generateFlatExportLines.js';
|
|
|
5
5
|
import generateNamespaceExportLines from './generateNamespaceExportLines.js';
|
|
6
6
|
import generateNamedExports from './generateNamedExports.js';
|
|
7
7
|
|
|
8
|
-
export default function generateFile(
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
8
|
+
export default function generateFile({
|
|
9
|
+
src,
|
|
10
|
+
exportRoots,
|
|
11
|
+
ignore,
|
|
12
|
+
includeComments,
|
|
13
|
+
dts,
|
|
14
|
+
useTabs = true
|
|
15
|
+
}) {
|
|
16
|
+
|
|
17
|
+
const fileDataList = buildFileDataList({
|
|
18
|
+
src,
|
|
19
|
+
ignore,
|
|
20
|
+
includeComments
|
|
21
|
+
});
|
|
22
|
+
const {
|
|
23
|
+
flatExports,
|
|
24
|
+
nestedExports
|
|
25
|
+
} = buildExportsTree(fileDataList);
|
|
26
|
+
const headerComment = `/**
|
|
12
27
|
* This file is auto-generated by the build script.
|
|
13
28
|
* It consolidates API ${dts ? 'type declarations' : 'functions'} for use in the application.
|
|
14
29
|
* Do not edit manually.
|
|
15
30
|
*/
|
|
16
31
|
`;
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
32
|
+
const importStatements = generateImportStatements({
|
|
33
|
+
fileDataList,
|
|
34
|
+
dts,
|
|
35
|
+
src
|
|
36
|
+
});
|
|
37
|
+
|
|
38
|
+
const flatExportLines = generateFlatExportLines({
|
|
39
|
+
flatExports,
|
|
40
|
+
exportRoots,
|
|
41
|
+
includeComments,
|
|
42
|
+
dts,
|
|
43
|
+
useTabs
|
|
44
|
+
});
|
|
45
|
+
|
|
46
|
+
const namespaceExportLines = generateNamespaceExportLines({
|
|
47
|
+
nestedExports,
|
|
48
|
+
includeComments,
|
|
49
|
+
dts,
|
|
50
|
+
useTabs
|
|
51
|
+
});
|
|
52
|
+
|
|
53
|
+
const defaultExportCode = dts
|
|
54
|
+
? `declare const _default: {\n${flatExportLines}${namespaceExportLines}};\n\nexport default _default;\n`
|
|
55
|
+
: `export default {\n${flatExportLines}${namespaceExportLines}};`;
|
|
56
|
+
|
|
57
|
+
const namedExports = generateNamedExports({
|
|
58
|
+
nestedExports,
|
|
59
|
+
flatExports,
|
|
60
|
+
exportRoots,
|
|
61
|
+
dts,
|
|
62
|
+
useTabs
|
|
63
|
+
});
|
|
64
|
+
|
|
65
|
+
return headerComment +
|
|
31
66
|
importStatements + '\n' +
|
|
32
67
|
namedExports + '\n' +
|
|
33
68
|
defaultExportCode;
|
|
69
|
+
|
|
34
70
|
}
|
|
@@ -1,18 +1,41 @@
|
|
|
1
|
-
export default function generateFlatExportLines(
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
1
|
+
export default function generateFlatExportLines({
|
|
2
|
+
flatExports,
|
|
3
|
+
exportRoots,
|
|
4
|
+
includeComments,
|
|
5
|
+
dts,
|
|
6
|
+
useTabs = true
|
|
7
|
+
}) {
|
|
8
|
+
|
|
9
|
+
let indentStyle = useTabs ? '\t' : ' ';
|
|
10
|
+
|
|
11
|
+
let lines = '';
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
if (exportRoots) {
|
|
15
|
+
|
|
16
|
+
flatExports.forEach(({
|
|
17
|
+
functionName, importVarName, jsDocComment
|
|
18
|
+
}) => {
|
|
19
|
+
|
|
20
|
+
if (includeComments && jsDocComment) {
|
|
21
|
+
|
|
22
|
+
const indentedComment = jsDocComment
|
|
23
|
+
.split('\n')
|
|
24
|
+
.map((line) => indentStyle + line)
|
|
25
|
+
.join('\n');
|
|
26
|
+
|
|
27
|
+
lines += indentedComment + '\n';
|
|
28
|
+
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
lines += dts
|
|
32
|
+
? `${indentStyle}${functionName}: typeof ${importVarName};\n`
|
|
33
|
+
: `${indentStyle}${functionName}: ${importVarName},\n`;
|
|
34
|
+
|
|
35
|
+
});
|
|
36
|
+
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
return lines;
|
|
40
|
+
|
|
18
41
|
}
|