Skip to content

Commit 0411f4b

Browse files
committed
Test Stuff
1 parent 579990c commit 0411f4b

File tree

4 files changed

+4789
-4647
lines changed

4 files changed

+4789
-4647
lines changed

examples/tools/batchGenerate.js

+32
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,38 @@ generateTemplateFilesBatch([
1616
dynamicReplacers: [
1717
{ slot: '__name__', slotValue: componentName },
1818
{ slot: '__scope__', slotValue: componentScope },
19+
{ slot: '__1scope__', slotValue: componentScope },
20+
{ slot: '__s2cope__', slotValue: componentScope },
21+
{ slot: '__sc2ope__', slotValue: componentScope },
22+
{ slot: '__sco2pe__', slotValue: componentScope },
23+
{ slot: '__scop2e__', slotValue: componentScope },
24+
{ slot: '__scope2__', slotValue: componentScope },
25+
{ slot: '__3scope__', slotValue: componentScope },
26+
{ slot: '__s3cope__', slotValue: componentScope },
27+
{ slot: '__sc3ope__', slotValue: componentScope },
28+
{ slot: '__sco3pe__', slotValue: componentScope },
29+
{ slot: '__scop3e__', slotValue: componentScope },
30+
{ slot: '__4scope__', slotValue: componentScope },
31+
{ slot: '__s4cope__', slotValue: componentScope },
32+
{ slot: '__sc4ope__', slotValue: componentScope },
33+
{ slot: '__sco44pe__', slotValue: componentScope },
34+
{ slot: '__scope4__', slotValue: componentScope },
35+
{ slot: '__s5cope__', slotValue: componentScope },
36+
{ slot: '__s52cope__', slotValue: componentScope },
37+
{ slot: '__sc5ope__', slotValue: componentScope },
38+
{ slot: '__sco25pe__', slotValue: componentScope },
39+
{ slot: '__sco6pe__', slotValue: componentScope },
40+
{ slot: '__sco35pe__', slotValue: componentScope },
41+
{ slot: '__sco5pe__', slotValue: componentScope },
42+
{ slot: '__sco1pe__', slotValue: componentScope },
43+
{ slot: '__s12cope__', slotValue: componentScope },
44+
{ slot: '__sc53ope__', slotValue: componentScope },
45+
{ slot: '__scfoape__', slotValue: componentScope },
46+
{ slot: '__scopasde__', slotValue: componentScope },
47+
{ slot: '__scosadfpe__', slotValue: componentScope },
48+
{ slot: '__scosadafpe__', slotValue: componentScope },
49+
{ slot: '__scofsdpe__', slotValue: componentScope },
50+
{ slot: '__scopfe__', slotValue: componentScope },
1951
],
2052
output: {
2153
path: `./src/component/__scope__(camelCase)`,

package.json

-105
This file was deleted.

src/GenerateTemplateFiles.ts

+42-6
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ import recursiveCopy from 'recursive-copy';
33
import pathExists from 'path-exists';
44
import through from 'through2';
55
import replaceString from 'replace-string';
6+
import trie from 'trie-prefix-tree';
7+
import trieToRegExp from 'trie-regex';
68
import StringUtility from './utilities/StringUtility';
79
import CaseConverterEnum from './constants/CaseConverterEnum';
810
import IConfigItem from './models/IConfigItem';
@@ -332,14 +334,21 @@ export default class GenerateTemplateFiles {
332334
// Create a function to apply the transformations in one go
333335
const regexEscape = (text: string) => text.replace(/([^a-zA-Z0-9_])/g, '\\$1');
334336
const replacerLookup: Record<string, string> = {};
335-
const replacerRegexBase = replacers
336-
.map((replacer: IReplacer) => {
337+
const replacerSlots: string[] = [];
338+
const regexTrie = trieToRegExp(trie(replacerSlots).tree());
339+
340+
console.log(regexTrie);
341+
342+
const replacerRegexBase = replacers.map((replacer: IReplacer) => {
337343
replacerLookup[replacer.slot] = replacer.slotValue;
344+
replacerSlots.push(replacer.slot)
338345
return regexEscape(replacer.slot);
339-
})
340-
.join('|');
346+
}).join('|');
347+
341348
const replacerRegex = new RegExp(`^${replacerRegexBase}$`, 'g');
342-
const replacer = (text: string) => text.replace(replacerRegex, (slot) => replacerLookup[slot]);
349+
const simpleReplacer = (text: string) => text.replace(replacerRegex, (slot) => replacerLookup[slot]);
350+
351+
const replacer = (text: string) => text.replace(regexTrie, (slot) => replacerLookup[slot]);
343352

344353
// Apply the transformations on all files recursively
345354
const recursiveCopyOptions: any = {
@@ -364,8 +373,35 @@ export default class GenerateTemplateFiles {
364373
},
365374
transform: (src: string, dest: string, stats: unknown) => {
366375
return through((chunk: any, enc: any, done: any) => {
367-
let output: string = replacer(chunk.toString());
376+
let output: string = ""
377+
378+
console.time(`new ${src}`)
379+
for(let i = 0; i < 100000; i++) {
380+
output = replacer(chunk.toString());
381+
}
382+
console.timeEnd(`new ${src}`)
383+
384+
385+
console.time(`simple ${src}`)
386+
for(let i = 0; i < 100000; i++) {
387+
output = simpleReplacer(chunk.toString());
388+
}
389+
console.timeEnd(`simple ${src}`)
390+
391+
392+
console.time(`orig ${src}`)
393+
for(let i = 0; i < 100000; i++) {
394+
replacers.forEach((replacer: IReplacer) => {
395+
output = replaceString(output, replacer.slot, replacer.slotValue);
396+
});
397+
}
398+
console.timeEnd(`orig ${src}`)
399+
400+
401+
368402
done(null, output);
403+
404+
369405
});
370406
},
371407
};

0 commit comments

Comments
 (0)