@ibyar/cli 2.0.1 → 2.1.0
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 +2 -0
- package/bin/cli.js +7 -5
- package/bin/cli.js.map +1 -1
- package/compiler/compiler.d.ts +2 -0
- package/compiler/compiler.d.ts.map +1 -1
- package/compiler/compiler.js +10 -0
- package/compiler/compiler.js.map +1 -1
- package/directives/directives.d.ts +3 -0
- package/directives/directives.d.ts.map +1 -0
- package/directives/directives.js +48 -0
- package/directives/directives.js.map +1 -0
- package/directives/register.d.ts +9 -0
- package/directives/register.d.ts.map +1 -0
- package/directives/register.js +87 -0
- package/directives/register.js.map +1 -0
- package/package.json +8 -7
- package/transformer/after-declarations-component copy.d.ts +9 -0
- package/transformer/after-declarations-component copy.d.ts.map +1 -0
- package/transformer/after-declarations-component copy.js +56 -0
- package/transformer/after-declarations-component copy.js.map +1 -0
- package/transformer/after-declarations-component.d.ts +0 -1
- package/transformer/after-declarations-component.d.ts.map +1 -1
- package/transformer/after-declarations-component.js +4 -9
- package/transformer/after-declarations-component.js.map +1 -1
- package/transformer/after-declarations-directie.d.ts +8 -0
- package/transformer/after-declarations-directie.d.ts.map +1 -0
- package/transformer/after-declarations-directie.js +26 -0
- package/transformer/after-declarations-directie.js.map +1 -0
- package/transformer/before-component copy.d.ts +9 -0
- package/transformer/before-component copy.d.ts.map +1 -0
- package/transformer/before-component copy.js +212 -0
- package/transformer/before-component copy.js.map +1 -0
- package/transformer/before-component.d.ts +0 -7
- package/transformer/before-component.d.ts.map +1 -1
- package/transformer/before-component.js +23 -65
- package/transformer/before-component.js.map +1 -1
- package/transformer/before-directive.d.ts +8 -0
- package/transformer/before-directive.d.ts.map +1 -0
- package/transformer/before-directive.js +94 -0
- package/transformer/before-directive.js.map +1 -0
- package/transformer/factory.d.ts +21 -1
- package/transformer/factory.d.ts.map +1 -1
- package/transformer/factory.js +43 -5
- package/transformer/factory.js.map +1 -1
- package/transformer/helpers.d.ts +80 -0
- package/transformer/helpers.d.ts.map +1 -0
- package/transformer/helpers.js +141 -0
- package/transformer/helpers.js.map +1 -0
- package/transformer/modules.d.ts +8 -8
- package/transformer/modules.d.ts.map +1 -1
- package/transformer/modules.js +6 -0
- package/transformer/modules.js.map +1 -1
- package/transformer/scan-directives.d.ts +22 -0
- package/transformer/scan-directives.d.ts.map +1 -0
- package/transformer/scan-directives.js +79 -0
- package/transformer/scan-directives.js.map +1 -0
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
import ts from 'typescript/lib/tsserverlibrary.js';
|
|
2
|
+
import { registerDirectiveCall } from '../directives/register.js';
|
|
3
|
+
function removeQuotations(string) {
|
|
4
|
+
return string.substring(1, string.length - 1);
|
|
5
|
+
}
|
|
6
|
+
function extractDirectives(alias, sourceFile) {
|
|
7
|
+
const type = alias.type;
|
|
8
|
+
if (!ts.isTupleTypeNode(type)) {
|
|
9
|
+
return;
|
|
10
|
+
}
|
|
11
|
+
type.elements.forEach(elm => {
|
|
12
|
+
if (!ts.isTypeLiteralNode(elm)) {
|
|
13
|
+
return;
|
|
14
|
+
}
|
|
15
|
+
const info = {};
|
|
16
|
+
elm.members.forEach(member => {
|
|
17
|
+
if (!ts.isPropertySignature(member)) {
|
|
18
|
+
return;
|
|
19
|
+
}
|
|
20
|
+
const name = member.name.getText(sourceFile);
|
|
21
|
+
if ((name === 'selector' || name === 'successor') && member.type && ts.isLiteralTypeNode(member.type)) {
|
|
22
|
+
const value = member.type.literal.getText(sourceFile);
|
|
23
|
+
info[name] = removeQuotations(value);
|
|
24
|
+
}
|
|
25
|
+
else if ((name === 'inputs' || name === 'outputs') && member.type && ts.isTupleTypeNode(member.type)) {
|
|
26
|
+
const value = [];
|
|
27
|
+
member.type.elements.forEach(item => {
|
|
28
|
+
if (!ts.isTypeLiteralNode(item)) {
|
|
29
|
+
return;
|
|
30
|
+
}
|
|
31
|
+
const itemObject = {};
|
|
32
|
+
item.members.forEach(property => {
|
|
33
|
+
if (!ts.isPropertySignature(property)) {
|
|
34
|
+
return;
|
|
35
|
+
}
|
|
36
|
+
const key = property.name.getText(sourceFile);
|
|
37
|
+
if ((key === 'name' || key == 'aliasName') && property.type && ts.isLiteralTypeNode(property.type)) {
|
|
38
|
+
const keyValue = property.type.literal.getText(sourceFile);
|
|
39
|
+
itemObject[key] = removeQuotations(keyValue);
|
|
40
|
+
}
|
|
41
|
+
});
|
|
42
|
+
value.push(itemObject);
|
|
43
|
+
});
|
|
44
|
+
info[name] = value;
|
|
45
|
+
}
|
|
46
|
+
});
|
|
47
|
+
if (!info.selector) {
|
|
48
|
+
return;
|
|
49
|
+
}
|
|
50
|
+
registerDirectiveCall(info);
|
|
51
|
+
});
|
|
52
|
+
}
|
|
53
|
+
/**
|
|
54
|
+
* search for `ɵɵ0Directives0ɵɵ` type
|
|
55
|
+
*
|
|
56
|
+
* example:
|
|
57
|
+
* ```ts
|
|
58
|
+
* export type ɵɵ0Directives0ɵɵ = [{
|
|
59
|
+
* selector: '*if';
|
|
60
|
+
* successor: '*else',
|
|
61
|
+
* inputs: [
|
|
62
|
+
* { name: 'ifCondition', aliasName: 'if' },
|
|
63
|
+
* { name: 'thenTemplateRef', aliasName: 'then' },
|
|
64
|
+
* { name: 'elseTemplateRef', aliasName: 'else' },
|
|
65
|
+
* ],
|
|
66
|
+
* outputs: [],
|
|
67
|
+
* }];
|
|
68
|
+
* ```
|
|
69
|
+
* @param program a ts program
|
|
70
|
+
* @returns a transformer factory of source file
|
|
71
|
+
*/
|
|
72
|
+
export function scanDirectivesTypeVisitor(sourceFile) {
|
|
73
|
+
ts.forEachChild(sourceFile, node => {
|
|
74
|
+
if (ts.isTypeAliasDeclaration(node) && node.name.getText(sourceFile) === 'ɵɵ0Directives0ɵɵ') {
|
|
75
|
+
extractDirectives(node, sourceFile);
|
|
76
|
+
}
|
|
77
|
+
});
|
|
78
|
+
}
|
|
79
|
+
//# sourceMappingURL=scan-directives.js.map
|
|
@@ -0,0 +1 @@
|
|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CAAC;YACpB,OAAO;QACR,CAAC;QACD,qBAAqB,CAAC,IAAI,CAAC,CAAC;IAC7B,CAAC,CAAC,CAAC;AAEJ,CAAC;AAED;;;;;;;;;;;;;;;;;;GAkBG;AACH,MAAM,UAAU,yBAAyB,CAAC,UAAyB;IAClE,EAAE,CAAC,YAAY,CAAC,UAAU,EAAE,IAAI,CAAC,EAAE;QAClC,IAAI,EAAE,CAAC,sBAAsB,CAAC,IAAI,CAAC,IAAI,IAAI,CAAC,IAAI,CAAC,OAAO,CAAC,UAAU,CAAC,KAAK,kBAAkB,EAAE,CAAC;YAC7F,iBAAiB,CAAC,IAAI,EAAE,UAAU,CAAC,CAAC;QACrC,CAAC;IACF,CAAC,CAAC,CAAC;AACJ,CAAC","sourcesContent":["import ts from 'typescript/lib/tsserverlibrary.js';\nimport { DirectiveInfo, registerDirectiveCall } from '../directives/register.js';\n\n\nfunction removeQuotations(string: string) {\n\treturn string.substring(1, string.length - 1);\n}\n\nfunction extractDirectives(alias: ts.TypeAliasDeclaration, sourceFile: ts.SourceFile) {\n\tconst type = alias.type;\n\tif (!ts.isTupleTypeNode(type)) {\n\t\treturn;\n\t}\n\ttype.elements.forEach(elm => {\n\t\tif (!ts.isTypeLiteralNode(elm)) {\n\t\t\treturn;\n\t\t}\n\t\tconst info = {} as DirectiveInfo;\n\t\telm.members.forEach(member => {\n\t\t\tif (!ts.isPropertySignature(member)) {\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tconst name = member.name.getText(sourceFile);\n\t\t\tif ((name === 'selector' || name === 'successor') && member.type && ts.isLiteralTypeNode(member.type)) {\n\t\t\t\tconst value = member.type.literal.getText(sourceFile);\n\t\t\t\tinfo[name] = removeQuotations(value);\n\t\t\t} else if ((name === 'inputs' || name === 'outputs') && member.type && ts.isTupleTypeNode(member.type)) {\n\t\t\t\ttype Item = { name: string, aliasName: string };\n\t\t\t\tconst value: Item[] = [];\n\t\t\t\tmember.type.elements.forEach(item => {\n\t\t\t\t\tif (!ts.isTypeLiteralNode(item)) {\n\t\t\t\t\t\treturn;\n\t\t\t\t\t}\n\t\t\t\t\tconst itemObject = {} as Item;\n\t\t\t\t\titem.members.forEach(property => {\n\t\t\t\t\t\tif (!ts.isPropertySignature(property)) {\n\t\t\t\t\t\t\treturn;\n\t\t\t\t\t\t}\n\t\t\t\t\t\tconst key = property.name.getText(sourceFile);\n\t\t\t\t\t\tif ((key === 'name' || key == 'aliasName') && property.type && ts.isLiteralTypeNode(property.type)) {\n\t\t\t\t\t\t\tconst keyValue = property.type.literal.getText(sourceFile);\n\t\t\t\t\t\t\titemObject[key] = removeQuotations(keyValue);\n\t\t\t\t\t\t}\n\t\t\t\t\t});\n\t\t\t\t\tvalue.push(itemObject);\n\t\t\t\t});\n\t\t\t\tinfo[name] = value;\n\t\t\t}\n\t\t});\n\t\tif (!info.selector) {\n\t\t\treturn;\n\t\t}\n\t\tregisterDirectiveCall(info);\n\t});\n\n}\n\n/**\n * search for `ɵɵ0Directives0ɵɵ` type\n * \n * example:\n * ```ts\n * export type ɵɵ0Directives0ɵɵ = [{\n * \tselector: '*if';\n * \tsuccessor: '*else',\n * \tinputs: [\n * \t\t{ name: 'ifCondition', aliasName: 'if' },\n * \t\t{ name: 'thenTemplateRef', aliasName: 'then' },\n * \t\t{ name: 'elseTemplateRef', aliasName: 'else' },\n * \t],\n * \toutputs: [],\n * }];\n * ```\n * @param program a ts program \n * @returns a transformer factory of source file\n */\nexport function scanDirectivesTypeVisitor(sourceFile: ts.SourceFile): void {\n\tts.forEachChild(sourceFile, node => {\n\t\tif (ts.isTypeAliasDeclaration(node) && node.name.getText(sourceFile) === 'ɵɵ0Directives0ɵɵ') {\n\t\t\textractDirectives(node, sourceFile);\n\t\t}\n\t});\n}\n"]}
|