Skip to content

Commit e33e13a

Browse files
committedSep 21, 2021
increased printWidth to make code more readable
1 parent b73835c commit e33e13a

12 files changed

+94
-203
lines changed
 

‎.prettierrc

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"tabWidth": 2,
3+
"useTabs": false,
4+
"printWidth": 160
5+
}

‎src/generator.ts

+9-14
Original file line numberDiff line numberDiff line change
@@ -7,19 +7,16 @@ export const generator = (files: Array<File>, outputPath: string): void => {
77
// scope will be html only for now
88
let json = Object();
99
for (const file of files) {
10-
let component = Object(), inputs = "", index = 1;
10+
let component = Object(),
11+
inputs = "",
12+
index = 1;
1113
component.scope = "html";
1214
component.prefix = file.prefix;
1315
for (let input of file.inputs) {
14-
if (input.type?.indexOf('|') != -1 && input.type) {
15-
inputs +=
16-
` [${input.inputName}]=\"$\{${index}\|${input.type.replace(/(\s)\|(\s)/g, ',')
17-
.replace(/'/g, '')}\|\}\"`;
18-
}
19-
else {
20-
inputs += input.type === "string" ?
21-
` ${input.inputName}=` :
22-
` [${input.inputName}]=`;
16+
if (input.type?.indexOf("|") != -1 && input.type) {
17+
inputs += ` [${input.inputName}]=\"$\{${index}\|${input.type.replace(/(\s)\|(\s)/g, ",").replace(/'/g, "")}\|\}\"`;
18+
} else {
19+
inputs += input.type === "string" ? ` ${input.inputName}=` : ` [${input.inputName}]=`;
2320
inputs += `\"$${index}\"`;
2421
}
2522
++index;
@@ -30,11 +27,9 @@ export const generator = (files: Array<File>, outputPath: string): void => {
3027
outputs += ` (${output.outputName})=\"$${index}\"`;
3128
++index;
3229
}
33-
component.body = [
34-
`<${file.prefix}` + inputs + outputs + `></${file.prefix}>`,
35-
];
30+
component.body = [`<${file.prefix}` + inputs + outputs + `></${file.prefix}>`];
3631
json[file.componentName] = {
37-
...component
32+
...component,
3833
};
3934
}
4035
const dir = path.join(outputPath, "/out.code-snippets");

‎src/index.ts

+1-4
Original file line numberDiff line numberDiff line change
@@ -65,10 +65,7 @@ export const run = async (args: string[]) => {
6565

6666
process.env.ROOT_PROJECT_PATH = config.workingDir || path.posix.resolve();
6767

68-
let candidateFilePaths: Array<string> = walker.walker(
69-
process.env.ROOT_PROJECT_PATH as string,
70-
[]
71-
);
68+
let candidateFilePaths: Array<string> = walker.walker(process.env.ROOT_PROJECT_PATH as string, []);
7269
let fileData: Array<File> = parser.parser(candidateFilePaths);
7370
generator.generator(fileData, config.outputDir as string);
7471
};

‎src/parser.ts

+20-58
Original file line numberDiff line numberDiff line change
@@ -26,17 +26,12 @@ export const parser = (filePaths: Array<string>): Array<File> => {
2626
containsComponentDef = true;
2727
}
2828

29-
if (
30-
!containsComponentDef &&
31-
file?.match(/@Input/g) == null &&
32-
file?.match(/@Output/g) == null
33-
) {
29+
if (!containsComponentDef && file?.match(/@Input/g) == null && file?.match(/@Output/g) == null) {
3430
logger.log("No component, Inputs or Outputs defined in this file");
3531
continue;
3632
}
3733

38-
let fileNameData: Array<string> =
39-
file?.match(REGEX_SELECTORS.componentSelector) || [];
34+
let fileNameData: Array<string> = file?.match(REGEX_SELECTORS.componentSelector) || [];
4035
if (fileNameData.length === 0) {
4136
logger.warn("Component tag not defined by any class.");
4237
continue;
@@ -50,12 +45,9 @@ export const parser = (filePaths: Array<string>): Array<File> => {
5045
let selector = "";
5146
if (containsComponentDef) {
5247
// match returns a string not an array
53-
let componentSelectorData: Array<string> =
54-
file?.match(REGEX_SELECTORS.componentHTMLselector) || [];
48+
let componentSelectorData: Array<string> = file?.match(REGEX_SELECTORS.componentHTMLselector) || [];
5549
if (componentSelectorData.length === 0) {
56-
logger.warn(
57-
"Component doesn't define any selector but contains @Component anotation."
58-
);
50+
logger.warn("Component doesn't define any selector but contains @Component anotation.");
5951
continue;
6052
}
6153
componentSelectorData[0].replace(/(\s+)/g, " ");
@@ -66,17 +58,11 @@ export const parser = (filePaths: Array<string>): Array<File> => {
6658
// notice we ignore the default value of the input in the regex
6759
// Input() foo: 'type1' | 'type2'
6860
let inputs: Array<Input> = [];
69-
let inputsData: Array<string> =
70-
file?.match(REGEX_SELECTORS.regularInputLiteralTypeSelector) || [];
61+
let inputsData: Array<string> = file?.match(REGEX_SELECTORS.regularInputLiteralTypeSelector) || [];
7162
for (let input of inputsData) {
7263
logger.log("inputs parsed:", inputsData);
7364
let tmp: Array<string> = input.replace(/(\s)+/g, " ").split(" ");
74-
let type = tmp
75-
.slice(2, tmp.length)
76-
.join()
77-
.replace(/\"/g, "'")
78-
.replace(";", "")
79-
.replace(/,/g, "");
65+
let type = tmp.slice(2, tmp.length).join().replace(/\"/g, "'").replace(";", "").replace(/,/g, "");
8066
inputs.push({
8167
inputName: tmp[1].replace(":", ""),
8268
type,
@@ -86,8 +72,7 @@ export const parser = (filePaths: Array<string>): Array<File> => {
8672

8773
// @Input() variableName: type; and @Input() variableName: number = 9;
8874
inputsData = [];
89-
inputsData =
90-
file?.match(REGEX_SELECTORS.regularInputWithTypeSelector) || [];
75+
inputsData = file?.match(REGEX_SELECTORS.regularInputWithTypeSelector) || [];
9176
for (let input of inputsData) {
9277
let tmp: Array<string> = input.replace(/(\s+)/g, " ").split(" ");
9378
inputs.push({
@@ -99,12 +84,10 @@ export const parser = (filePaths: Array<string>): Array<File> => {
9984

10085
inputsData = [];
10186
// @Input('inputName') varName: type; and @Input("inputName") varName: type
102-
inputsData =
103-
file?.match(REGEX_SELECTORS.customNameInputWithTypeSelector) || [];
87+
inputsData = file?.match(REGEX_SELECTORS.customNameInputWithTypeSelector) || [];
10488
for (let input of inputsData) {
10589
let tmp: Array<string> = input.replace(/(\s+)/g, " ").split(" ");
106-
const inputName = (tmp[0].match(/('|")[a-zA-Z0-9-_]+('|")/g) ||
107-
[])[0].replace(/'|"/g, "");
90+
const inputName = (tmp[0].match(/('|")[a-zA-Z0-9-_]+('|")/g) || [])[0].replace(/'|"/g, "");
10891
inputs.push({
10992
inputName,
11093
type: tmp[2].replace(";", ""),
@@ -115,13 +98,10 @@ export const parser = (filePaths: Array<string>): Array<File> => {
11598
// @Input('inputNameC') varName = 'adv';
11699
// @Input("inputNameD") varName = 2354;
117100
inputsData = [];
118-
inputsData =
119-
file?.match(REGEX_SELECTORS.setterInputCustomNameSelector) || [];
101+
inputsData = file?.match(REGEX_SELECTORS.setterInputCustomNameSelector) || [];
120102
for (let input of inputsData) {
121103
let tmp: Array<string> = input.replace(/(\s+)/g, " ").split(" ");
122-
const inputName = (tmp[0].match(/('|")[a-zA-Z0-9-_]+('|")/g) || [
123-
"",
124-
])[0].replace(/'|"/g, "");
104+
const inputName = (tmp[0].match(/('|")[a-zA-Z0-9-_]+('|")/g) || [""])[0].replace(/'|"/g, "");
125105
inputs.push({
126106
inputName,
127107
type: undefined,
@@ -158,8 +138,7 @@ export const parser = (filePaths: Array<string>): Array<File> => {
158138

159139
//@Input() set foo(value: 'type1' | 'type2') {}
160140
inputsData = [];
161-
inputsData =
162-
file?.match(REGEX_SELECTORS.setterInputLiteralTypeSelector) || [];
141+
inputsData = file?.match(REGEX_SELECTORS.setterInputLiteralTypeSelector) || [];
163142
for (let input of inputsData) {
164143
let tmp: Array<string> = input.replace(/(\s+)/g, " ").split(" ");
165144
const inputName = tmp[2].replace(/(\s+)/g, "").split("(")[0];
@@ -195,16 +174,12 @@ export const parser = (filePaths: Array<string>): Array<File> => {
195174

196175
let outputs: Array<Output> = [];
197176
// only @Output() buttonClick: EventEmitter<any> = new EventEmitter(); for now
198-
let outputsData: Array<string> =
199-
file?.match(REGEX_SELECTORS.regularOutputSelector) || [];
177+
let outputsData: Array<string> = file?.match(REGEX_SELECTORS.regularOutputSelector) || [];
200178
for (let output of outputsData) {
201179
let tmp: Array<string> = output.replace(/(\s+)/g, " ").split(" ");
202180
outputs.push({
203181
outputName: tmp[1].replace(":", ""),
204-
type: tmp[2]
205-
.substr(tmp[2].indexOf("<"), tmp[2].indexOf(">"))
206-
.replace(">", "")
207-
.replace("<", ""),
182+
type: tmp[2].substr(tmp[2].indexOf("<"), tmp[2].indexOf(">")).replace(">", "").replace("<", ""),
208183
});
209184
}
210185
file = file.replace(REGEX_SELECTORS.regularOutputSelector, "");
@@ -213,20 +188,13 @@ export const parser = (filePaths: Array<string>): Array<File> => {
213188
let extendedClassPath;
214189
if (file?.match(REGEX_SELECTORS.extendedClassSelector)) {
215190
// we should see if the extended class is in tmp and if not extract the inputs defined inside
216-
let matchExtendedClass: Array<string> =
217-
file?.match(REGEX_SELECTORS.extendedClassSelector) || [];
191+
let matchExtendedClass: Array<string> = file?.match(REGEX_SELECTORS.extendedClassSelector) || [];
218192
// resolve the path of the class
219-
let extendedClass: string = matchExtendedClass[0]
220-
.replace(/(\s+)/g, " ")
221-
.split(" ")[4];
193+
let extendedClass: string = matchExtendedClass[0].replace(/(\s+)/g, " ").split(" ")[4];
222194
logger.log("extendedClassName:", extendedClass);
223-
let matchExtendedClassPath: Array<string> =
224-
file?.match(REGEX_SELECTORS.extendedClassPathSelector) || [];
195+
let matchExtendedClassPath: Array<string> = file?.match(REGEX_SELECTORS.extendedClassPathSelector) || [];
225196

226-
extendedClassPath = pathResolver.resolve(
227-
filePath,
228-
matchExtendedClassPath[0]
229-
);
197+
extendedClassPath = pathResolver.resolve(filePath, matchExtendedClassPath[0]);
230198

231199
logger.log("path:", extendedClassPath);
232200
}
@@ -264,14 +232,8 @@ export const parser = (filePaths: Array<string>): Array<File> => {
264232
if (result[i].extendedClassFilepath) {
265233
for (let j = 0; j < tmp.length; ++j) {
266234
if (result[i].extendedClassFilepath === tmp[j].fileLocation) {
267-
result[i].inputs = [
268-
...result[i].inputs,
269-
...(tmp[j].inputs as []),
270-
] as Input[];
271-
result[i].outputs = [
272-
...result[i].outputs,
273-
...(tmp[j].outputs as []),
274-
] as Output[];
235+
result[i].inputs = [...result[i].inputs, ...(tmp[j].inputs as [])] as Input[];
236+
result[i].outputs = [...result[i].outputs, ...(tmp[j].outputs as [])] as Output[];
275237
break;
276238
}
277239
}

‎src/shared/logger.ts

+5-6
Original file line numberDiff line numberDiff line change
@@ -12,26 +12,25 @@ let debuggerEnabled = false;
1212

1313
export const enableDebugger = () => {
1414
debuggerEnabled = true;
15-
}
15+
};
1616

1717
export const disableDebugger = () => {
1818
debuggerEnabled = false;
19-
}
19+
};
2020

2121
export const log = (message: string, args?: any[] | any) => {
22-
if (!debuggerEnabled) return;
22+
if (!debuggerEnabled) return;
2323

2424
console.log(logPrefix + message, args);
2525
};
2626

2727
export const warn = (message: string, args?: any[] | any) => {
28-
if (!debuggerEnabled) return;
28+
if (!debuggerEnabled) return;
2929

3030
console.log(warnPrefix + message, args);
3131
};
3232

3333
export const err = (message: string, args?: any[] | any) => {
34-
3534
console.log(errorPrefix + message, args);
3635
process.exit();
3736
};
@@ -41,4 +40,4 @@ export default {
4140
warn,
4241
err,
4342
enableDebugger,
44-
};
43+
};

‎src/utils/path-resolver.ts

+5-18
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,7 @@ let tsconfigFile: {
1212
* @param {string} importExpr The expression used to import the base class
1313
* @returns {string} An absolute path to the imported file
1414
*/
15-
export const resolve = (
16-
filePath: string,
17-
importExpr: string
18-
): string | null => {
15+
export const resolve = (filePath: string, importExpr: string): string | null => {
1916
/**
2017
* @param {string} importExpr The expression used to import the class in the file
2118
* @returns {string} The the path in the import expression
@@ -48,30 +45,20 @@ export const resolve = (
4845
let compilerOptionsPathsKey = pathToFile.substr(0, pathToFile.indexOf("/")),
4946
compilerOptionsPathsValue: Array<string> = [""];
5047
if (compilerOptionsPathsKey + "/*" in tsconfigFile?.compilerOptions.paths) {
51-
compilerOptionsPathsValue =
52-
tsconfigFile?.compilerOptions.paths[compilerOptionsPathsKey + "/*"];
48+
compilerOptionsPathsValue = tsconfigFile?.compilerOptions.paths[compilerOptionsPathsKey + "/*"];
5349
} // TODO: else throw an exception
5450

55-
compilerOptionsPathsValue[0] = compilerOptionsPathsValue[0].replace(
56-
"/*",
57-
""
58-
);
51+
compilerOptionsPathsValue[0] = compilerOptionsPathsValue[0].replace("/*", "");
5952

6053
// Notice that by calling path.join with a relative path of the base
6154
// path from ComponentClassPath and the full path of the file resolves into the
6255
// full path of the base path
6356
resolvedPath = path.join(
6457
path.posix.resolve(),
65-
pathToFile
66-
.replace(compilerOptionsPathsKey, compilerOptionsPathsValue[0])
67-
.replace(/(\s+)/g, " ")
68-
.replace(/"/g, "") + ".ts"
58+
pathToFile.replace(compilerOptionsPathsKey, compilerOptionsPathsValue[0]).replace(/(\s+)/g, " ").replace(/"/g, "") + ".ts"
6959
);
7060
} else {
71-
resolvedPath = path.join(
72-
path.dirname(filePath),
73-
pathToFile.replace(/(\s+)/g, " ").replace(/"/g, "") + ".ts"
74-
);
61+
resolvedPath = path.join(path.dirname(filePath), pathToFile.replace(/(\s+)/g, " ").replace(/"/g, "") + ".ts");
7562
}
7663

7764
// TODO: Throw an error if the function is unable to resolve the path

‎src/utils/regexSelectors.ts

+9-18
Original file line numberDiff line numberDiff line change
@@ -6,34 +6,25 @@ export const REGEX_SELECTORS = {
66
// @Input() variableName; and @Input() variableName
77
regularInputSelector: /@Input\(\)(\s+)[a-zA-Z0-9-_]+(;|)/g,
88
// @Input() variableName: type; and @Input() variableName: number = 9;
9-
regularInputWithTypeSelector:
10-
/@Input\(\)(\s+)[a-zA-Z0-9-_]+:(\s+)[a-zA-Z0-9-_]+((;|)|(\s+)[a-zA-Z0-9-_]+(\s+)=(\s+)[a-zA-Z0-9-_]+(;|))/g,
9+
regularInputWithTypeSelector: /@Input\(\)(\s+)[a-zA-Z0-9-_]+:(\s+)[a-zA-Z0-9-_]+((;|)|(\s+)[a-zA-Z0-9-_]+(\s+)=(\s+)[a-zA-Z0-9-_]+(;|))/g,
1110
// @Input('inputName') varName: type; and @Input("inputName") varName: type
12-
customNameInputWithTypeSelector:
13-
/@Input\(('|")[a-zA-Z0-9-_]+('|")\)(\s+)[a-zA-Z0-9-_]+:(\s+)[a-zA-Z0-9-_]+\;/g,
14-
regularInputLiteralTypeSelector:
15-
/@Input\(\)(\s+)[a-zA-Z0-9-_]+:((\s+)(('|")[a-zA-Z0-9-_]+('|")((\s+)\|)))+(\s+)('|")[a-zA-Z0-9-_]+('|")(;|:|)/g,
11+
customNameInputWithTypeSelector: /@Input\(('|")[a-zA-Z0-9-_]+('|")\)(\s+)[a-zA-Z0-9-_]+:(\s+)[a-zA-Z0-9-_]+\;/g,
12+
regularInputLiteralTypeSelector: /@Input\(\)(\s+)[a-zA-Z0-9-_]+:((\s+)(('|")[a-zA-Z0-9-_]+('|")((\s+)\|)))+(\s+)('|")[a-zA-Z0-9-_]+('|")(;|:|)/g,
1613
//@Input() set foo(value) {}
17-
setterInputSelector:
18-
/@Input\(\)(\s+)set(\s+)[a-zA-Z0-9-_]+\([a-zA-Z0-9-_]+\)(\s+)/g,
14+
setterInputSelector: /@Input\(\)(\s+)set(\s+)[a-zA-Z0-9-_]+\([a-zA-Z0-9-_]+\)(\s+)/g,
1915
//@Input() set foo(value: type) {}
20-
setterInputWithTypeSelector:
21-
/@Input\(\)(\s+)set(\s+)[a-zA-Z0-9-_]+\([a-zA-Z0-9-_]+:(\s+)[a-zA-Z0-9-_]+\)(\s+)/g,
16+
setterInputWithTypeSelector: /@Input\(\)(\s+)set(\s+)[a-zA-Z0-9-_]+\([a-zA-Z0-9-_]+:(\s+)[a-zA-Z0-9-_]+\)(\s+)/g,
2217
// @Input('inputNameC') varName = 'adv';
23-
setterInputCustomNameSelector:
24-
/@Input\(("|')[a-zA-Z0-9-_]+("|')\)(\s+)[a-zA-Z0-9-_]+(\s+)=(\s+)[A-Za-z0-9"']+(;|)/g,
18+
setterInputCustomNameSelector: /@Input\(("|')[a-zA-Z0-9-_]+("|')\)(\s+)[a-zA-Z0-9-_]+(\s+)=(\s+)[A-Za-z0-9"']+(;|)/g,
2519
//@Input() set foo(value: 'type1' | 'type2') {}
2620
setterInputLiteralTypeSelector:
2721
/@Input\(\)(\s+)set(\s+)[a-zA-Z0-9-_]+\([a-zA-Z0-9-_]+:((\s+)('|")[a-zA-Z0-9-_]+('|")(\s+)\|)+(\s)('|")[a-zA-Z0-9-_]+('|")\)/g,
2822

2923
// outputs
3024
// @Output() buttonClick: EventEmitter<any> = new EventEmitter()
31-
regularOutputSelector:
32-
/@Output\(\)(\s+)[a-zA-Z0-9-_]+:(\s+)EventEmitter<[a-zA-Z0-9-_]+>(\s+)=(\s+)new(\s+)EventEmitter\(\);/g,
25+
regularOutputSelector: /@Output\(\)(\s+)[a-zA-Z0-9-_]+:(\s+)EventEmitter<[a-zA-Z0-9-_]+>(\s+)=(\s+)new(\s+)EventEmitter\(\);/g,
3326

3427
// other
35-
extendedClassSelector:
36-
/export(\s+)class(\s+)[a-zA-Z0-9-_]+(\s+)extends(\s+)[a-zA-Z0-9-_]+/g,
37-
extendedClassPathSelector:
38-
/import(\s+){(\s+)[a-zA-Z0-9-_]+(\s+)}(\s+)from(\s+)[\/\@A-Za-z0-9."'_-]+/g,
28+
extendedClassSelector: /export(\s+)class(\s+)[a-zA-Z0-9-_]+(\s+)extends(\s+)[a-zA-Z0-9-_]+/g,
29+
extendedClassPathSelector: /import(\s+){(\s+)[a-zA-Z0-9-_]+(\s+)}(\s+)from(\s+)[\/\@A-Za-z0-9."'_-]+/g,
3930
};

‎src/walker.ts

+2-9
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,7 @@ const fs = require("fs");
55
const path = require("path");
66

77
// TODO: Parse files synchronously
8-
export const walker = (
9-
root: string,
10-
filesExploredPath: Array<string>
11-
): Array<string> => {
8+
export const walker = (root: string, filesExploredPath: Array<string>): Array<string> => {
129
let pendingDir: Array<string> = [root];
1310

1411
while (pendingDir.length > 0) {
@@ -25,11 +22,7 @@ export const walker = (
2522
if (file.isFile() && file.name.endsWith(".ts")) {
2623
logger.log("Candidate file to contain component definition:", file.name);
2724
filesExploredPath.push(path.join(currentDir, file.name));
28-
} else if (
29-
file.isDirectory() &&
30-
file.name != "node_modules" &&
31-
file.name != ".git"
32-
) {
25+
} else if (file.isDirectory() && file.name != "node_modules" && file.name != ".git") {
3326
pendingDir.push(path.join(currentDir, file.name));
3427
}
3528
}

‎tests/generator.test.ts

+26-31
Original file line numberDiff line numberDiff line change
@@ -3,37 +3,32 @@ const fs = require("fs");
33
const path = require("path");
44

55
test("JSON file generation", async () => {
6-
generator.generator([
7-
{
8-
componentName: "MainComponent",
9-
prefix: "app-main",
10-
inputs: [
11-
{ inputName: "appName", type: "MediaModel" },
12-
{ inputName: "var", type: "'type1' | 'type2'" },
13-
{ inputName: "foo", type: "TypeError" },
14-
{ inputName: "fooStr", type: "string" },
15-
],
16-
outputs: [
17-
{ outputName: "buttonClick", type: "any" },
18-
{ outputName: "fooVar", type: "number" },
19-
],
20-
fileLocation: path.join(
21-
path.posix.resolve(),
22-
"/tests/fixtures/parser/main.component.ts"
23-
),
24-
extendedClassFilepath: undefined
25-
}
26-
], path.join(path.posix.resolve(), "/out"));
27-
const expectedResult = '{"MainComponent": { "scope": "html", "prefix": "app-main", "body": [ "<app-main [appName]="$1" [var]="${2|type1,type2|}" [foo]="$3" fooStr="$4" (buttonClick)="$5" (fooVar)="$6"></app-main>" ] } }'.replace(
28-
/\s/g,
29-
""
6+
generator.generator(
7+
[
8+
{
9+
componentName: "MainComponent",
10+
prefix: "app-main",
11+
inputs: [
12+
{ inputName: "appName", type: "MediaModel" },
13+
{ inputName: "var", type: "'type1' | 'type2'" },
14+
{ inputName: "foo", type: "TypeError" },
15+
{ inputName: "fooStr", type: "string" },
16+
],
17+
outputs: [
18+
{ outputName: "buttonClick", type: "any" },
19+
{ outputName: "fooVar", type: "number" },
20+
],
21+
fileLocation: path.join(path.posix.resolve(), "/tests/fixtures/parser/main.component.ts"),
22+
extendedClassFilepath: undefined,
23+
},
24+
],
25+
path.join(path.posix.resolve(), "/out")
3026
);
31-
const data = fs
32-
.readFileSync(
33-
path.join(path.posix.resolve(), "/out/out.code-snippets"),
34-
"utf-8"
35-
)
36-
.replace(/\s+/g, "")
37-
.replace(/\\/g, "");
27+
const expectedResult =
28+
'{"MainComponent": { "scope": "html", "prefix": "app-main", "body": [ "<app-main [appName]="$1" [var]="${2|type1,type2|}" [foo]="$3" fooStr="$4" (buttonClick)="$5" (fooVar)="$6"></app-main>" ] } }'.replace(
29+
/\s/g,
30+
""
31+
);
32+
const data = fs.readFileSync(path.join(path.posix.resolve(), "/out/out.code-snippets"), "utf-8").replace(/\s+/g, "").replace(/\\/g, "");
3833
expect(data).toEqual(expectedResult);
3934
});

‎tests/index.test.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,5 @@ const fs = require("fs");
33
const path = require("path");
44

55
test("End to end test", async () => {
6-
// TODO
6+
// TODO
77
});

‎tests/parser.test.ts

+10-38
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,8 @@ test("Parses the contents of the candidate files and returns an array of File ty
55
const result = [
66
{
77
componentName: "MainComponent",
8-
extendedClassFilepath: path.join(
9-
path.posix.resolve(),
10-
"/tests/fixtures/parser/base.component.ts"
11-
),
12-
fileLocation: path.join(
13-
path.posix.resolve(),
14-
"/tests/fixtures/parser/main.component.ts"
15-
),
8+
extendedClassFilepath: path.join(path.posix.resolve(), "/tests/fixtures/parser/base.component.ts"),
9+
fileLocation: path.join(path.posix.resolve(), "/tests/fixtures/parser/main.component.ts"),
1610
inputs: [
1711
{
1812
inputName: "literalType1",
@@ -102,36 +96,20 @@ test("Parses the contents of the candidate files and returns an array of File ty
10296
];
10397
expect(
10498
parser.parser([
105-
path.join(
106-
path.posix.resolve(),
107-
"/tests/fixtures/parser/main.component.ts"
108-
),
109-
path.join(
110-
path.posix.resolve(),
111-
"/tests/fixtures/parser/base.component.ts"
112-
),
113-
path.join(
114-
path.posix.resolve(),
115-
"/tests/fixtures/parser/component.module.ts"
116-
),
99+
path.join(path.posix.resolve(), "/tests/fixtures/parser/main.component.ts"),
100+
path.join(path.posix.resolve(), "/tests/fixtures/parser/base.component.ts"),
101+
path.join(path.posix.resolve(), "/tests/fixtures/parser/component.module.ts"),
117102
])
118103
).toStrictEqual(result);
119104
});
120105

121106
test("Tests the parser when de file is imported using the @ special keyword path defined in tsconfig.json", async () => {
122-
process.env.ROOT_PROJECT_PATH =
123-
"C:/Users/roger/oos/angular-vs-snippets/tests/fixtures/parser";
107+
process.env.ROOT_PROJECT_PATH = "C:/Users/roger/oos/angular-vs-snippets/tests/fixtures/parser";
124108
const result = [
125109
{
126110
componentName: "SpecialPathComponent",
127-
extendedClassFilepath: path.join(
128-
path.posix.resolve(),
129-
"/tests/fixtures/parser/special-path-tsconfig/special-base.component.ts"
130-
),
131-
fileLocation: path.join(
132-
path.posix.resolve(),
133-
"/tests/fixtures/parser/special-path-tsconfig/special-path.component.ts"
134-
),
111+
extendedClassFilepath: path.join(path.posix.resolve(), "/tests/fixtures/parser/special-path-tsconfig/special-base.component.ts"),
112+
fileLocation: path.join(path.posix.resolve(), "/tests/fixtures/parser/special-path-tsconfig/special-path.component.ts"),
135113
inputs: [
136114
{
137115
inputName: "inputInChildClass",
@@ -148,14 +126,8 @@ test("Tests the parser when de file is imported using the @ special keyword path
148126
];
149127
expect(
150128
parser.parser([
151-
path.join(
152-
path.posix.resolve(),
153-
"/tests/fixtures/parser/special-path-tsconfig/special-base.component.ts"
154-
),
155-
path.join(
156-
path.posix.resolve(),
157-
"/tests/fixtures/parser/special-path-tsconfig/special-path.component.ts"
158-
),
129+
path.join(path.posix.resolve(), "/tests/fixtures/parser/special-path-tsconfig/special-base.component.ts"),
130+
path.join(path.posix.resolve(), "/tests/fixtures/parser/special-path-tsconfig/special-path.component.ts"),
159131
])
160132
).toStrictEqual(result);
161133
});

‎tests/walker.test.ts

+1-6
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,7 @@ import * as walker from "../src/walker";
33
const path = require("path");
44

55
test("Inspects /tests/fixtures/ts-files with walker function", () => {
6-
expect(
7-
walker.walker(
8-
path.join(path.posix.resolve(), "tests/fixtures/ts-files"),
9-
[]
10-
)
11-
).toStrictEqual([
6+
expect(walker.walker(path.join(path.posix.resolve(), "tests/fixtures/ts-files"), [])).toStrictEqual([
127
path.join(path.posix.resolve(), "/tests/fixtures/ts-files/foo.ts"),
138
path.join(path.posix.resolve(), "/tests/fixtures/ts-files/index.ts"),
149
]);

0 commit comments

Comments
 (0)
Please sign in to comment.