@ibyar/cli 0.8.2-dev.20221008
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/LICENSE +21 -0
- package/README.md +96 -0
- package/bin/cli.d.ts +1 -0
- package/bin/cli.js +13 -0
- package/bin/cli.js.map +1 -0
- package/compiler/compiler.d.ts +6 -0
- package/compiler/compiler.js +50 -0
- package/compiler/compiler.js.map +1 -0
- package/elements/tags.d.ts +10 -0
- package/elements/tags.js +122 -0
- package/elements/tags.js.map +1 -0
- package/index.d.ts +5 -0
- package/index.js +6 -0
- package/index.js.map +1 -0
- package/package.json +70 -0
- package/transformer/after-declarations-component.d.ts +8 -0
- package/transformer/after-declarations-component.js +56 -0
- package/transformer/after-declarations-component.js.map +1 -0
- package/transformer/before-component.d.ts +14 -0
- package/transformer/before-component.js +226 -0
- package/transformer/before-component.js.map +1 -0
- package/transformer/factory.d.ts +35 -0
- package/transformer/factory.js +124 -0
- package/transformer/factory.js.map +1 -0
- package/transformer/modules.d.ts +42 -0
- package/transformer/modules.js +47 -0
- package/transformer/modules.js.map +1 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2020-2022 @ibyar/cli
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
# Ibyar CLI
|
|
2
|
+
|
|
3
|
+
[![NPM Version][npm-image]][npm-url]
|
|
4
|
+
[![NPM Downloads][downloads-image]][downloads-url]
|
|
5
|
+
[![LICENSE][license-img]][license-url]
|
|
6
|
+
[![lerna][lerna-img]][lerna-url]
|
|
7
|
+
![GitHub contributors][contributors]
|
|
8
|
+
|
|
9
|
+
[npm-image]: https://img.shields.io/npm/v/@ibyar/cli.svg?logo=npm&logoColor=fff&label=NPM+package&color=limegreen
|
|
10
|
+
[npm-url]: https://npmjs.org/package/@ibyar/cli
|
|
11
|
+
[downloads-image]: https://img.shields.io/npm/dt/@ibyar/cli
|
|
12
|
+
[downloads-url]: https://npmjs.org/package/@ibyar/cli
|
|
13
|
+
[license-img]: https://img.shields.io/github/license/ibyar/cli
|
|
14
|
+
[license-url]: https://github.com/ibyar/cli/blob/master/LICENSE
|
|
15
|
+
[lerna-img]: https://img.shields.io/badge/maintained%20with-lerna-cc00ff.svg
|
|
16
|
+
[lerna-url]: https://lerna.js.org/
|
|
17
|
+
[contributors]: https://img.shields.io/github/contributors/ibyar/cli
|
|
18
|
+
|
|
19
|
+
The Ibyar/Aurora CLI tool.
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
## `Install`
|
|
23
|
+
|
|
24
|
+
``` bash
|
|
25
|
+
npm i --save @ibyar/cli
|
|
26
|
+
```
|
|
27
|
+
|
|
28
|
+
``` bash
|
|
29
|
+
yarn add @ibyar/cli
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
The Ibyar CLI has a typescript transformer to generate a definitions for you component
|
|
34
|
+
|
|
35
|
+
```ts
|
|
36
|
+
import { Component, EventEmitter, Input, Output } from '@ibyar/aurora';
|
|
37
|
+
|
|
38
|
+
|
|
39
|
+
@Component({
|
|
40
|
+
selector: 'person-edit',
|
|
41
|
+
template: `<form #form>
|
|
42
|
+
<input if="show" type="text" [(value)]="person.name" />
|
|
43
|
+
<input type="number" [(value)]="person.age" />
|
|
44
|
+
<input type="button" (click)="printPerson()" value="Save" />
|
|
45
|
+
</form>`
|
|
46
|
+
})
|
|
47
|
+
export class PersonEdit {
|
|
48
|
+
@Input()
|
|
49
|
+
person: Person;
|
|
50
|
+
|
|
51
|
+
@Input()
|
|
52
|
+
show = true;
|
|
53
|
+
|
|
54
|
+
@Output()
|
|
55
|
+
save = new EventEmitter<Person>();
|
|
56
|
+
|
|
57
|
+
printPerson() {
|
|
58
|
+
console.log(this.person);
|
|
59
|
+
this.save.emit(this.person);
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
```
|
|
64
|
+
|
|
65
|
+
will generate the view class and add it to the definition files
|
|
66
|
+
|
|
67
|
+
```ts
|
|
68
|
+
import { EventEmitter } from '@ibyar/aurora';
|
|
69
|
+
|
|
70
|
+
export declare class PersonEdit {
|
|
71
|
+
static readonly HTMLPersonEditElement: ConstructorOfView<HTMLPersonEditElement>;
|
|
72
|
+
person: Person;
|
|
73
|
+
show: boolean;
|
|
74
|
+
save: EventEmitter<Person>;
|
|
75
|
+
printPerson(): void;
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
import { BaseComponent, ConstructorOfView } from "@ibyar/core";
|
|
79
|
+
|
|
80
|
+
declare class HTMLPersonEditElement extends HTMLElement {
|
|
81
|
+
public static observedAttributes: "person" | "show" | "onSave"[];
|
|
82
|
+
public person: Person;
|
|
83
|
+
public show: true;
|
|
84
|
+
public onSave: EventEmitter<Person>;
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
declare interface HTMLPersonEditElement extends BaseComponent<PersonEdit> {}
|
|
88
|
+
|
|
89
|
+
declare global {
|
|
90
|
+
interface HTMLElementTagNameMap {
|
|
91
|
+
["person-edit"]: HTMLPersonEditElement;
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
|
|
96
|
+
```
|
package/bin/cli.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
package/bin/cli.js
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
"use strict";
|
|
3
|
+
if (process.argv.includes('-b') || process.argv.includes('--build')) {
|
|
4
|
+
import('../compiler/compiler.js').then(module => {
|
|
5
|
+
if (process.argv.includes('-w') || process.argv.includes('--watch')) {
|
|
6
|
+
module.compileAndWatchArgs();
|
|
7
|
+
}
|
|
8
|
+
else {
|
|
9
|
+
module.compileArgs();
|
|
10
|
+
}
|
|
11
|
+
});
|
|
12
|
+
}
|
|
13
|
+
//# sourceMappingURL=cli.js.map
|
package/bin/cli.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"cli.js","sourceRoot":"","sources":["../../../src/cli/bin/cli.ts"],"names":[],"mappings":";;AAGA,IAAI,OAAO,CAAC,IAAI,CAAC,QAAQ,CAAC,IAAI,CAAC,IAAI,OAAO,CAAC,IAAI,CAAC,QAAQ,CAAC,SAAS,CAAC,EAAE;IACpE,MAAM,CAAC,yBAAyB,CAAC,CAAC,IAAI,CAAC,MAAM,CAAC,EAAE;QAC/C,IAAI,OAAO,CAAC,IAAI,CAAC,QAAQ,CAAC,IAAI,CAAC,IAAI,OAAO,CAAC,IAAI,CAAC,QAAQ,CAAC,SAAS,CAAC,EAAE;YACpE,MAAM,CAAC,mBAAmB,EAAE,CAAC;SAC7B;aAAM;YACN,MAAM,CAAC,WAAW,EAAE,CAAC;SACrB;IACF,CAAC,CAAC,CAAC;CACH","sourcesContent":["#!/usr/bin/env node\n\n\nif (process.argv.includes('-b') || process.argv.includes('--build')) {\n\timport('../compiler/compiler.js').then(module => {\n\t\tif (process.argv.includes('-w') || process.argv.includes('--watch')) {\n\t\t\tmodule.compileAndWatchArgs();\n\t\t} else {\n\t\t\tmodule.compileArgs();\n\t\t}\n\t});\n}\n"]}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import ts from 'typescript/lib/tsserverlibrary.js';
|
|
2
|
+
export declare function emitProgram(program: ts.Program): void;
|
|
3
|
+
export declare function compileFiles(files: readonly string[], options: ts.CompilerOptions): void;
|
|
4
|
+
export declare function compileAndWatchFiles(configPath: string, cmd: ts.ParsedCommandLine): void;
|
|
5
|
+
export declare function compileArgs(): void;
|
|
6
|
+
export declare function compileAndWatchArgs(): void;
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import ts from 'typescript/lib/tsserverlibrary.js';
|
|
2
|
+
import { afterDeclarationsCompileComponentOptions } from '../transformer/after-declarations-component.js';
|
|
3
|
+
import { beforeCompileComponentOptions } from '../transformer/before-component.js';
|
|
4
|
+
export function emitProgram(program) {
|
|
5
|
+
program.emit(undefined, undefined, undefined, undefined, {
|
|
6
|
+
before: [
|
|
7
|
+
beforeCompileComponentOptions(program),
|
|
8
|
+
],
|
|
9
|
+
after: [],
|
|
10
|
+
afterDeclarations: [
|
|
11
|
+
afterDeclarationsCompileComponentOptions(program),
|
|
12
|
+
],
|
|
13
|
+
});
|
|
14
|
+
}
|
|
15
|
+
export function compileFiles(files, options) {
|
|
16
|
+
const host = ts.createCompilerHost(options);
|
|
17
|
+
const program = ts.createProgram(files, options, host);
|
|
18
|
+
emitProgram(program);
|
|
19
|
+
}
|
|
20
|
+
export function compileAndWatchFiles(configPath, cmd) {
|
|
21
|
+
const host = ts.createWatchCompilerHost(configPath, cmd.options, ts.sys);
|
|
22
|
+
const programFactory = ts.createWatchProgram(host);
|
|
23
|
+
const programBuilder = programFactory.getProgram();
|
|
24
|
+
const program = programBuilder.getProgram();
|
|
25
|
+
emitProgram(program);
|
|
26
|
+
}
|
|
27
|
+
function getConfigPath() {
|
|
28
|
+
const configPath = ts.findConfigFile('./', /*searchPath*/ ts.sys.fileExists, 'tsconfig.json');
|
|
29
|
+
if (!configPath) {
|
|
30
|
+
throw new Error("Could not find a valid 'tsconfig.json'.");
|
|
31
|
+
}
|
|
32
|
+
return configPath;
|
|
33
|
+
}
|
|
34
|
+
export function compileArgs() {
|
|
35
|
+
const configPath = getConfigPath();
|
|
36
|
+
const cmd = ts.getParsedCommandLineOfConfigFile(configPath, {}, ts.sys);
|
|
37
|
+
if (!cmd) {
|
|
38
|
+
return;
|
|
39
|
+
}
|
|
40
|
+
compileFiles(cmd.fileNames, cmd.options);
|
|
41
|
+
}
|
|
42
|
+
export function compileAndWatchArgs() {
|
|
43
|
+
const configPath = getConfigPath();
|
|
44
|
+
const cmd = ts.getParsedCommandLineOfConfigFile(configPath, {}, ts.sys);
|
|
45
|
+
if (!cmd) {
|
|
46
|
+
return;
|
|
47
|
+
}
|
|
48
|
+
compileAndWatchFiles(configPath, cmd);
|
|
49
|
+
}
|
|
50
|
+
//# sourceMappingURL=compiler.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"compiler.js","sourceRoot":"","sources":["../../../src/cli/compiler/compiler.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,mCAAmC,CAAC;AACnD,OAAO,EAAE,wCAAwC,EAAE,MAAM,gDAAgD,CAAC;AAC1G,OAAO,EAAE,6BAA6B,EAAE,MAAM,oCAAoC,CAAC;AAGnF,MAAM,UAAU,WAAW,CAAC,OAAmB;IAC9C,OAAO,CAAC,IAAI,CAAC,SAAS,EAAE,SAAS,EAAE,SAAS,EAAE,SAAS,EAAE;QACxD,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AU,CAAC,CAAC;IAC/E,IAAI,CAAC,GAAG,EAAE;QACT,OAAO;KACP;IACD,YAAY,CAAC,GAAG,CAAC,SAAS,EAAE,GAAG,CAAC,OAAO,CAAC,CAAC;AAC1C,CAAC;AAED,MAAM,UAAU,mBAAmB;IAClC,MAAM,UAAU,GAAG,aAAa,EAAE,CAAC;IACnC,MAAM,GAAG,GAAG,EAAE,CAAC,gCAAgC,CAAC,UAAU,EAAE,EAAE,EAAE,EAAE,CAAC,GAAU,CAAC,CAAC;IAC/E,IAAI,CAAC,GAAG,EAAE;QACT,OAAO;KACP;IACD,oBAAoB,CAAC,UAAU,EAAE,GAAG,CAAC,CAAC;AACvC,CAAC","sourcesContent":["import ts from 'typescript/lib/tsserverlibrary.js';\nimport { afterDeclarationsCompileComponentOptions } from '../transformer/after-declarations-component.js';\nimport { beforeCompileComponentOptions } from '../transformer/before-component.js';\n\n\nexport function emitProgram(program: ts.Program) {\n\tprogram.emit(undefined, undefined, undefined, undefined, {\n\t\tbefore: [\n\t\t\tbeforeCompileComponentOptions(program),\n\t\t],\n\t\tafter: [],\n\t\tafterDeclarations: [\n\t\t\tafterDeclarationsCompileComponentOptions(program) as ts.TransformerFactory<ts.SourceFile | ts.Bundle>,\n\t\t],\n\t});\n}\n\nexport function compileFiles(files: readonly string[], options: ts.CompilerOptions) {\n\tconst host = ts.createCompilerHost(options);\n\tconst program = ts.createProgram(files, options, host);\n\temitProgram(program);\n}\n\nexport function compileAndWatchFiles(configPath: string, cmd: ts.ParsedCommandLine) {\n\tconst host = ts.createWatchCompilerHost(configPath, cmd.options, ts.sys);\n\tconst programFactory = ts.createWatchProgram(host);\n\tconst programBuilder = programFactory.getProgram();\n\tconst program = programBuilder.getProgram();\n\temitProgram(program);\n}\n\n\nfunction getConfigPath() {\n\tconst configPath = ts.findConfigFile(\n\t\t'./',\t\t\t/*searchPath*/\n\t\tts.sys.fileExists,\n\t\t'tsconfig.json'\n\t);\n\tif (!configPath) {\n\t\tthrow new Error(\"Could not find a valid 'tsconfig.json'.\");\n\t}\n\treturn configPath;\n}\n\nexport function compileArgs() {\n\tconst configPath = getConfigPath();\n\tconst cmd = ts.getParsedCommandLineOfConfigFile(configPath, {}, ts.sys as any);\n\tif (!cmd) {\n\t\treturn;\n\t}\n\tcompileFiles(cmd.fileNames, cmd.options);\n}\n\nexport function compileAndWatchArgs() {\n\tconst configPath = getConfigPath();\n\tconst cmd = ts.getParsedCommandLineOfConfigFile(configPath, {}, ts.sys as any);\n\tif (!cmd) {\n\t\treturn;\n\t}\n\tcompileAndWatchFiles(configPath, cmd);\n}\n"]}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
declare type SelectorType = {
|
|
2
|
+
selector?: string;
|
|
3
|
+
type: string;
|
|
4
|
+
};
|
|
5
|
+
/**
|
|
6
|
+
* see https://html.spec.whatwg.org/multipage/indices.html#element-interfaces
|
|
7
|
+
*/
|
|
8
|
+
export declare const SelectorTypes: SelectorType[];
|
|
9
|
+
export declare function getExtendsTypeBySelector(selector?: string): string;
|
|
10
|
+
export {};
|
package/elements/tags.js
ADDED
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* see https://html.spec.whatwg.org/multipage/indices.html#element-interfaces
|
|
3
|
+
*/
|
|
4
|
+
export const SelectorTypes = [
|
|
5
|
+
{ selector: undefined, type: 'HTMLElement' },
|
|
6
|
+
{ selector: 'a', type: 'HTMLAnchorElement' },
|
|
7
|
+
{ selector: 'abbr', type: 'HTMLElement' },
|
|
8
|
+
{ selector: 'address', type: 'HTMLElement' },
|
|
9
|
+
{ selector: 'area', type: 'HTMLAreaElement' },
|
|
10
|
+
{ selector: 'article', type: 'HTMLElement' },
|
|
11
|
+
{ selector: 'aside', type: 'HTMLElement' },
|
|
12
|
+
{ selector: 'audio', type: 'HTMLAudioElement' },
|
|
13
|
+
{ selector: 'b', type: 'HTMLElement' },
|
|
14
|
+
{ selector: 'base', type: 'HTMLBaseElement' },
|
|
15
|
+
{ selector: 'bdi', type: 'HTMLElement' },
|
|
16
|
+
{ selector: 'bdo', type: 'HTMLElement' },
|
|
17
|
+
{ selector: 'blockquote', type: 'HTMLQuoteElement' },
|
|
18
|
+
{ selector: 'body', type: 'HTMLBodyElement' },
|
|
19
|
+
{ selector: 'br', type: 'HTMLBRElement' },
|
|
20
|
+
{ selector: 'button', type: 'HTMLButtonElement' },
|
|
21
|
+
{ selector: 'canvas', type: 'HTMLCanvasElement' },
|
|
22
|
+
{ selector: 'caption', type: 'HTMLTableCaptionElement' },
|
|
23
|
+
{ selector: 'cite', type: 'HTMLElement' },
|
|
24
|
+
{ selector: 'code', type: 'HTMLElement' },
|
|
25
|
+
{ selector: 'col', type: 'HTMLTableColElement' },
|
|
26
|
+
{ selector: 'colgroup', type: 'HTMLTableColElement' },
|
|
27
|
+
{ selector: 'data', type: 'HTMLDataElement' },
|
|
28
|
+
{ selector: 'datalist', type: 'HTMLDataListElement' },
|
|
29
|
+
{ selector: 'dd', type: 'HTMLElement' },
|
|
30
|
+
{ selector: 'del', type: 'HTMLModElement' },
|
|
31
|
+
{ selector: 'details', type: 'HTMLDetailsElement' },
|
|
32
|
+
{ selector: 'dfn', type: 'HTMLElement' },
|
|
33
|
+
// { name: 'dialog', classRef: window.HTMLDialogElement || 'HTMLElement' },
|
|
34
|
+
{ selector: 'div', type: 'HTMLDivElement' },
|
|
35
|
+
{ selector: 'dl', type: 'HTMLDListElement' },
|
|
36
|
+
{ selector: 'dt', type: 'HTMLElement' },
|
|
37
|
+
{ selector: 'em', type: 'HTMLElement' },
|
|
38
|
+
{ selector: 'embed', type: 'HTMLEmbedElement' },
|
|
39
|
+
{ selector: 'fieldset', type: 'HTMLFieldSetElement' },
|
|
40
|
+
{ selector: 'figcaption', type: 'HTMLElement' },
|
|
41
|
+
{ selector: 'figure', type: 'HTMLElement' },
|
|
42
|
+
{ selector: 'footer', type: 'HTMLElement' },
|
|
43
|
+
{ selector: 'form', type: 'HTMLFormElement' },
|
|
44
|
+
{ selector: 'h1', type: 'HTMLHeadingElement' },
|
|
45
|
+
{ selector: 'h2', type: 'HTMLHeadingElement' },
|
|
46
|
+
{ selector: 'h3', type: 'HTMLHeadingElement' },
|
|
47
|
+
{ selector: 'h4', type: 'HTMLHeadingElement' },
|
|
48
|
+
{ selector: 'h5', type: 'HTMLHeadingElement' },
|
|
49
|
+
{ selector: 'h6', type: 'HTMLHeadingElement' },
|
|
50
|
+
{ selector: 'head', type: 'HTMLHeadElement' },
|
|
51
|
+
{ selector: 'header', type: 'HTMLElement' },
|
|
52
|
+
{ selector: 'hgroup', type: 'HTMLElement' },
|
|
53
|
+
{ selector: 'hr', type: 'HTMLHRElement' },
|
|
54
|
+
{ selector: 'html', type: 'HTMLHtmlElement' },
|
|
55
|
+
{ selector: 'i', type: 'HTMLElement' },
|
|
56
|
+
{ selector: 'iframe', type: 'HTMLIFrameElement' },
|
|
57
|
+
{ selector: 'img', type: 'HTMLImageElement' },
|
|
58
|
+
{ selector: 'input', type: 'HTMLInputElement' },
|
|
59
|
+
{ selector: 'ins', type: 'HTMLModElement' },
|
|
60
|
+
{ selector: 'kbd', type: 'HTMLElement' },
|
|
61
|
+
{ selector: 'label', type: 'HTMLLabelElement' },
|
|
62
|
+
{ selector: 'legend', type: 'HTMLLegendElement' },
|
|
63
|
+
{ selector: 'li', type: 'HTMLLIElement' },
|
|
64
|
+
{ selector: 'link', type: 'HTMLLinkElement' },
|
|
65
|
+
{ selector: 'main', type: 'HTMLElement' },
|
|
66
|
+
{ selector: 'map', type: 'HTMLMapElement' },
|
|
67
|
+
{ selector: 'mark', type: 'HTMLElement' },
|
|
68
|
+
{ selector: 'menu', type: 'HTMLMenuElement' },
|
|
69
|
+
{ selector: 'meta', type: 'HTMLMetaElement' },
|
|
70
|
+
{ selector: 'meter', type: 'HTMLMeterElement' },
|
|
71
|
+
{ selector: 'nav', type: 'HTMLElement' },
|
|
72
|
+
{ selector: 'noscript', type: 'HTMLElement' },
|
|
73
|
+
{ selector: 'object', type: 'HTMLObjectElement' },
|
|
74
|
+
{ selector: 'ol', type: 'HTMLOListElement' },
|
|
75
|
+
{ selector: 'optgroup', type: 'HTMLOptGroupElement' },
|
|
76
|
+
{ selector: 'option', type: 'HTMLOptionElement' },
|
|
77
|
+
{ selector: 'output', type: 'HTMLOutputElement' },
|
|
78
|
+
{ selector: 'p', type: 'HTMLParagraphElement' },
|
|
79
|
+
{ selector: 'param', type: 'HTMLParamElement' },
|
|
80
|
+
{ selector: 'picture', type: 'HTMLPictureElement' },
|
|
81
|
+
{ selector: 'pre', type: 'HTMLPreElement' },
|
|
82
|
+
{ selector: 'progress', type: 'HTMLProgressElement' },
|
|
83
|
+
{ selector: 'q', type: 'HTMLQuoteElement' },
|
|
84
|
+
{ selector: 'rp', type: 'HTMLElement' },
|
|
85
|
+
{ selector: 'rt', type: 'HTMLElement' },
|
|
86
|
+
{ selector: 'ruby', type: 'HTMLElement' },
|
|
87
|
+
{ selector: 's', type: 'HTMLElement' },
|
|
88
|
+
{ selector: 'samp', type: 'HTMLElement' },
|
|
89
|
+
{ selector: 'script', type: 'HTMLScriptElement' },
|
|
90
|
+
{ selector: 'section', type: 'HTMLElement' },
|
|
91
|
+
{ selector: 'select', type: 'HTMLSelectElement' },
|
|
92
|
+
{ selector: 'slot', type: 'HTMLSlotElement' },
|
|
93
|
+
{ selector: 'small', type: 'HTMLElement' },
|
|
94
|
+
{ selector: 'source', type: 'HTMLSourceElement' },
|
|
95
|
+
{ selector: 'span', type: 'HTMLSpanElement' },
|
|
96
|
+
{ selector: 'strong', type: 'HTMLElement' },
|
|
97
|
+
{ selector: 'style', type: 'HTMLStyleElement' },
|
|
98
|
+
{ selector: 'sub', type: 'HTMLElement' },
|
|
99
|
+
{ selector: 'summary', type: 'HTMLElement' },
|
|
100
|
+
{ selector: 'sup', type: 'HTMLElement' },
|
|
101
|
+
{ selector: 'table', type: 'HTMLTableElement' },
|
|
102
|
+
{ selector: 'tbody', type: 'HTMLTableSectionElement' },
|
|
103
|
+
{ selector: 'td', type: 'HTMLTableCellElement' },
|
|
104
|
+
{ selector: 'template', type: 'HTMLTemplateElement' },
|
|
105
|
+
{ selector: 'textarea', type: 'HTMLTextAreaElement' },
|
|
106
|
+
{ selector: 'tfoot', type: 'HTMLTableSectionElement' },
|
|
107
|
+
{ selector: 'th', type: 'HTMLTableCellElement' },
|
|
108
|
+
{ selector: 'thead', type: 'HTMLTableSectionElement' },
|
|
109
|
+
{ selector: 'time', type: 'HTMLTimeElement' },
|
|
110
|
+
{ selector: 'title', type: 'HTMLTitleElement' },
|
|
111
|
+
{ selector: 'tr', type: 'HTMLTableRowElement' },
|
|
112
|
+
{ selector: 'track', type: 'HTMLTrackElement' },
|
|
113
|
+
{ selector: 'u', type: 'HTMLElement' },
|
|
114
|
+
{ selector: 'ul', type: 'HTMLUListElement' },
|
|
115
|
+
{ selector: 'var', type: 'HTMLElement' },
|
|
116
|
+
{ selector: 'video', type: 'HTMLVideoElement' },
|
|
117
|
+
{ selector: 'wbr', type: 'HTMLElement' },
|
|
118
|
+
];
|
|
119
|
+
export function getExtendsTypeBySelector(selector) {
|
|
120
|
+
return SelectorTypes.find(typeRef => typeRef.selector === selector)?.type ?? 'HTMLElement';
|
|
121
|
+
}
|
|
122
|
+
//# sourceMappingURL=tags.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"tags.js","sourceRoot":"","sources":["../../../src/cli/elements/tags.ts"],"names":[],"mappings":"AAGA;;GAEG;AACH,MAAM,CAAC,MAAM,aAAa,GAAmB;IAC5C,EAAE,QAAQ,EAAE,SAAS,EAAE,IAAI,EAAE,aAAa,EAAE;IAC5C,EAAE,QAAQ,EAAE,GAAG,EAAE,IAAI,EAAE,mBAAmB,EAAE;IAC5C,EAAE,QAAQ,EAAE,MAAM,EAAE,IAAI,EAAE,aAAa,EAAE;IACzC,EAAE,QAAQ,EAAE,SAAS,EAAE,IAAI,EAAE,aAAa,EAAE;IAC5C,EAAE,QAAQ,EAAE,MAAM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IACtD,EAAE,QAAQ,EAAE,IAAI,EAAE,IAAI,EAAE,sBAAsB,EAAE;IAChD,EAAE,QAAQ,EAAE,OAAO,EAAE,IAAI,EAAE,yBAAyB,EAAE;IACtD,EAAE,QAAQ,EAAE,MAAM,EAAE,IAAI,EAAE,iBAAiB,EAAE;IAC7C,EAAE,QAAQ,EAAE,OAAO,EAAE,IAAI,EAAE,kBAAkB,EAAE;IAC/C,EAAE,QAAQ,EAAE,IAAI,EAAE,IAAI,EAAE,qBAAqB,EAAE;IAC/C,EAAE,QAAQ,EAAE,OAAO,EAAE,IAAI,EAAE,kBAAkB,EAAE;IAC/C,EAAE,QAAQ,EAAE,GAAG,EAAE,IAAI,EAAE,aAAa,EAAE;IACtC,EAAE,QAAQ,EAAE,IAAI,EAAE,IAAI,EAAE,kBAAkB,EAAE;IAC5C,EAAE,QAAQ,EAAE,KAAK,EAAE,IAAI,EAAE,aAAa,EAAE;IACxC,EAAE,QAAQ,EAAE,OAAO,EAAE,IAAI,EAAE,kBAAkB,EAAE;IAC/C,EAAE,QAAQ,EAAE,KAAK,EAAE,IAAI,EAAE,aAAa,EAAE;CACxC,CAAC;AAGF,MAAM,UAAU,wBAAwB,CAAC,QAAiB;IACzD,OAAO,aAAa,CAAC,IAAI,CAAC,OAAO,CAAC,EAAE,CAAC,OAAO,CAAC,QAAQ,KAAK,QAAQ,CAAC,EAAE,IAAI,IAAI,aAAa,CAAC;AAC5F,CAAC","sourcesContent":["\ntype SelectorType = { selector?: string, type: string };\n\n/**\n * see https://html.spec.whatwg.org/multipage/indices.html#element-interfaces\n */\nexport const SelectorTypes: SelectorType[] = [\n\t{ selector: undefined, type: 'HTMLElement' },\n\t{ selector: 'a', type: 'HTMLAnchorElement' },\n\t{ selector: 'abbr', type: 'HTMLElement' },\n\t{ selector: 'address', type: 'HTMLElement' },\n\t{ selector: 'area', type: 'HTMLAreaElement' },\n\t{ selector: 'article', type: 'HTMLElement' },\n\t{ selector: 'aside', type: 'HTMLElement' },\n\t{ selector: 'audio', type: 'HTMLAudioElement' },\n\t{ selector: 'b', type: 'HTMLElement' },\n\t{ selector: 'base', type: 'HTMLBaseElement' },\n\t{ selector: 'bdi', type: 'HTMLElement' },\n\t{ selector: 'bdo', type: 'HTMLElement' },\n\t{ selector: 'blockquote', type: 'HTMLQuoteElement' },\n\t{ selector: 'body', type: 'HTMLBodyElement' },\n\t{ selector: 'br', type: 'HTMLBRElement' },\n\t{ selector: 'button', type: 'HTMLButtonElement' },\n\t{ selector: 'canvas', type: 'HTMLCanvasElement' },\n\t{ selector: 'caption', type: 'HTMLTableCaptionElement' },\n\t{ selector: 'cite', type: 'HTMLElement' },\n\t{ selector: 'code', type: 'HTMLElement' },\n\t{ selector: 'col', type: 'HTMLTableColElement' },\n\t{ selector: 'colgroup', type: 'HTMLTableColElement' },\n\t{ selector: 'data', type: 'HTMLDataElement' },\n\t{ selector: 'datalist', type: 'HTMLDataListElement' },\n\t{ selector: 'dd', type: 'HTMLElement' },\n\t{ selector: 'del', type: 'HTMLModElement' },\n\t{ selector: 'details', type: 'HTMLDetailsElement' },\n\t{ selector: 'dfn', type: 'HTMLElement' },\n\t// { name: 'dialog', classRef: window.HTMLDialogElement || 'HTMLElement' },\n\t{ selector: 'div', type: 'HTMLDivElement' },\n\t{ selector: 'dl', type: 'HTMLDListElement' },\n\t{ selector: 'dt', type: 'HTMLElement' },\n\t{ selector: 'em', type: 'HTMLElement' },\n\t{ selector: 'embed', type: 'HTMLEmbedElement' },\n\t{ selector: 'fieldset', type: 'HTMLFieldSetElement' },\n\t{ selector: 'figcaption', type: 'HTMLElement' },\n\t{ selector: 'figure', type: 'HTMLElement' },\n\t{ selector: 'footer', type: 'HTMLElement' },\n\t{ selector: 'form', type: 'HTMLFormElement' },\n\t{ selector: 'h1', type: 'HTMLHeadingElement' },\n\t{ selector: 'h2', type: 'HTMLHeadingElement' },\n\t{ selector: 'h3', type: 'HTMLHeadingElement' },\n\t{ selector: 'h4', type: 'HTMLHeadingElement' },\n\t{ selector: 'h5', type: 'HTMLHeadingElement' },\n\t{ selector: 'h6', type: 'HTMLHeadingElement' },\n\t{ selector: 'head', type: 'HTMLHeadElement' },\n\t{ selector: 'header', type: 'HTMLElement' },\n\t{ selector: 'hgroup', type: 'HTMLElement' },\n\t{ selector: 'hr', type: 'HTMLHRElement' },\n\t{ selector: 'html', type: 'HTMLHtmlElement' },\n\t{ selector: 'i', type: 'HTMLElement' },\n\t{ selector: 'iframe', type: 'HTMLIFrameElement' },\n\t{ selector: 'img', type: 'HTMLImageElement' },\n\t{ selector: 'input', type: 'HTMLInputElement' },\n\t{ selector: 'ins', type: 'HTMLModElement' },\n\t{ selector: 'kbd', type: 'HTMLElement' },\n\t{ selector: 'label', type: 'HTMLLabelElement' },\n\t{ selector: 'legend', type: 'HTMLLegendElement' },\n\t{ selector: 'li', type: 'HTMLLIElement' },\n\t{ selector: 'link', type: 'HTMLLinkElement' },\n\t{ selector: 'main', type: 'HTMLElement' },\n\t{ selector: 'map', type: 'HTMLMapElement' },\n\t{ selector: 'mark', type: 'HTMLElement' },\n\t{ selector: 'menu', type: 'HTMLMenuElement' },\n\t{ selector: 'meta', type: 'HTMLMetaElement' },\n\t{ selector: 'meter', type: 'HTMLMeterElement' },\n\t{ selector: 'nav', type: 'HTMLElement' },\n\t{ selector: 'noscript', type: 'HTMLElement' },\n\t{ selector: 'object', type: 'HTMLObjectElement' },\n\t{ selector: 'ol', type: 'HTMLOListElement' },\n\t{ selector: 'optgroup', type: 'HTMLOptGroupElement' },\n\t{ selector: 'option', type: 'HTMLOptionElement' },\n\t{ selector: 'output', type: 'HTMLOutputElement' },\n\t{ selector: 'p', type: 'HTMLParagraphElement' },\n\t{ selector: 'param', type: 'HTMLParamElement' },\n\t{ selector: 'picture', type: 'HTMLPictureElement' },\n\t{ selector: 'pre', type: 'HTMLPreElement' },\n\t{ selector: 'progress', type: 'HTMLProgressElement' },\n\t{ selector: 'q', type: 'HTMLQuoteElement' },\n\t{ selector: 'rp', type: 'HTMLElement' },\n\t{ selector: 'rt', type: 'HTMLElement' },\n\t{ selector: 'ruby', type: 'HTMLElement' },\n\t{ selector: 's', type: 'HTMLElement' },\n\t{ selector: 'samp', type: 'HTMLElement' },\n\t{ selector: 'script', type: 'HTMLScriptElement' },\n\t{ selector: 'section', type: 'HTMLElement' },\n\t{ selector: 'select', type: 'HTMLSelectElement' },\n\t{ selector: 'slot', type: 'HTMLSlotElement' },\n\t{ selector: 'small', type: 'HTMLElement' },\n\t{ selector: 'source', type: 'HTMLSourceElement' },\n\t{ selector: 'span', type: 'HTMLSpanElement' },\n\t{ selector: 'strong', type: 'HTMLElement' },\n\t{ selector: 'style', type: 'HTMLStyleElement' },\n\t{ selector: 'sub', type: 'HTMLElement' },\n\t{ selector: 'summary', type: 'HTMLElement' },\n\t{ selector: 'sup', type: 'HTMLElement' },\n\t{ selector: 'table', type: 'HTMLTableElement' },\n\t{ selector: 'tbody', type: 'HTMLTableSectionElement' },\n\t{ selector: 'td', type: 'HTMLTableCellElement' },\n\t{ selector: 'template', type: 'HTMLTemplateElement' },\n\t{ selector: 'textarea', type: 'HTMLTextAreaElement' },\n\t{ selector: 'tfoot', type: 'HTMLTableSectionElement' },\n\t{ selector: 'th', type: 'HTMLTableCellElement' },\n\t{ selector: 'thead', type: 'HTMLTableSectionElement' },\n\t{ selector: 'time', type: 'HTMLTimeElement' },\n\t{ selector: 'title', type: 'HTMLTitleElement' },\n\t{ selector: 'tr', type: 'HTMLTableRowElement' },\n\t{ selector: 'track', type: 'HTMLTrackElement' },\n\t{ selector: 'u', type: 'HTMLElement' },\n\t{ selector: 'ul', type: 'HTMLUListElement' },\n\t{ selector: 'var', type: 'HTMLElement' },\n\t{ selector: 'video', type: 'HTMLVideoElement' },\n\t{ selector: 'wbr', type: 'HTMLElement' },\n];\n\n\nexport function getExtendsTypeBySelector(selector?: string) {\n\treturn SelectorTypes.find(typeRef => typeRef.selector === selector)?.type ?? 'HTMLElement';\n}\n"]}
|
package/index.d.ts
ADDED
package/index.js
ADDED
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
export * from './transformer/factory.js';
|
|
2
|
+
export * from './transformer/before-component.js';
|
|
3
|
+
export * from './transformer/after-declarations-component.js';
|
|
4
|
+
export * from './compiler/compiler.js';
|
|
5
|
+
export * from './elements/tags.js';
|
|
6
|
+
//# sourceMappingURL=index.js.map
|
package/index.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/cli/index.ts"],"names":[],"mappings":"AAAA,cAAc,0BAA0B,CAAC;AACzC,cAAc,mCAAmC,CAAC;AAClD,cAAc,+CAA+C,CAAC;AAG9D,cAAc,wBAAwB,CAAC;AAEvC,cAAc,oBAAoB,CAAC","sourcesContent":["export * from './transformer/factory.js';\nexport * from './transformer/before-component.js';\nexport * from './transformer/after-declarations-component.js';\n\n\nexport * from './compiler/compiler.js';\n\nexport * from './elements/tags.js';\n"]}
|
package/package.json
ADDED
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@ibyar/cli",
|
|
3
|
+
"version": "0.8.2-dev.20221008",
|
|
4
|
+
"description": "The Ibyar/Aurora CLI tool",
|
|
5
|
+
"license": "MIT",
|
|
6
|
+
"homepage": "https://github.com/ibyar/aurora",
|
|
7
|
+
"repository": {
|
|
8
|
+
"type": "git",
|
|
9
|
+
"url": "https://github.com/ibyar/aurora.git",
|
|
10
|
+
"directory": "packages/cli"
|
|
11
|
+
},
|
|
12
|
+
"main": "./index.js",
|
|
13
|
+
"module": "./index.js",
|
|
14
|
+
"types": "./index.d.ts",
|
|
15
|
+
"type": "module",
|
|
16
|
+
"exports": {
|
|
17
|
+
".": "./index.js"
|
|
18
|
+
},
|
|
19
|
+
"bin": {
|
|
20
|
+
"ibyar": "./bin/cli.js"
|
|
21
|
+
},
|
|
22
|
+
"files": [
|
|
23
|
+
"*"
|
|
24
|
+
],
|
|
25
|
+
"publishConfig": {
|
|
26
|
+
"access": "public"
|
|
27
|
+
},
|
|
28
|
+
"dependencies": {
|
|
29
|
+
"@ibyar/core": "^0.8.2-dev.20221008",
|
|
30
|
+
"@ibyar/directives": "^0.8.2-dev.20221008",
|
|
31
|
+
"@ibyar/elements": "^0.8.2-dev.20221008",
|
|
32
|
+
"@ibyar/expressions": "^0.8.2-dev.20221008",
|
|
33
|
+
"@ibyar/pipes": "^0.8.2-dev.20221008",
|
|
34
|
+
"reflect-metadata": "^0.1.13",
|
|
35
|
+
"tslib": "^2.4.0",
|
|
36
|
+
"typescript": "^4.8.4"
|
|
37
|
+
},
|
|
38
|
+
"scripts": {
|
|
39
|
+
"build": "tsc --build --verbose"
|
|
40
|
+
},
|
|
41
|
+
"keywords": [
|
|
42
|
+
"cli",
|
|
43
|
+
"aurora",
|
|
44
|
+
"ibyar",
|
|
45
|
+
"custom-elements",
|
|
46
|
+
"dependency-injection",
|
|
47
|
+
"reflect-metadata",
|
|
48
|
+
"services",
|
|
49
|
+
"component",
|
|
50
|
+
"directive",
|
|
51
|
+
"pipes",
|
|
52
|
+
"forms",
|
|
53
|
+
"template-syntax",
|
|
54
|
+
"template-expression",
|
|
55
|
+
"http-client",
|
|
56
|
+
"http",
|
|
57
|
+
"html-parser",
|
|
58
|
+
"parser",
|
|
59
|
+
"jsx",
|
|
60
|
+
"jsx-factory",
|
|
61
|
+
"routers",
|
|
62
|
+
"js-parser",
|
|
63
|
+
"elements-info",
|
|
64
|
+
"element",
|
|
65
|
+
"interceptor",
|
|
66
|
+
"shadow-dom",
|
|
67
|
+
"typescript"
|
|
68
|
+
],
|
|
69
|
+
"gitHead": "abe877ef8e4d4914a0b9bc12dc88154ba9f0b2b9"
|
|
70
|
+
}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import ts from 'typescript/lib/tsserverlibrary.js';
|
|
2
|
+
/**
|
|
3
|
+
* search for `@Component({})` and update definition files
|
|
4
|
+
* @param program a ts program
|
|
5
|
+
* @returns a transformer factory of source file
|
|
6
|
+
*/
|
|
7
|
+
export declare function afterDeclarationsCompileComponentOptions(program: ts.Program): ts.TransformerFactory<ts.SourceFile>;
|
|
8
|
+
export default afterDeclarationsCompileComponentOptions;
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import ts from 'typescript/lib/tsserverlibrary.js';
|
|
2
|
+
import { createStaticPropertyViewType, updateModule } from './factory.js';
|
|
3
|
+
import { moduleManger } from './modules.js';
|
|
4
|
+
/**
|
|
5
|
+
* search for `@Component({})` and update definition files
|
|
6
|
+
* @param program a ts program
|
|
7
|
+
* @returns a transformer factory of source file
|
|
8
|
+
*/
|
|
9
|
+
export function afterDeclarationsCompileComponentOptions(program) {
|
|
10
|
+
const typeChecker = program.getTypeChecker();
|
|
11
|
+
return (context) => {
|
|
12
|
+
return sourceFile => {
|
|
13
|
+
const moduleInfo = moduleManger.get(sourceFile.fileName);
|
|
14
|
+
moduleManger.delete(sourceFile.fileName);
|
|
15
|
+
if (!moduleInfo) {
|
|
16
|
+
return sourceFile;
|
|
17
|
+
}
|
|
18
|
+
else if (moduleInfo.skip || !moduleInfo.classes) {
|
|
19
|
+
return sourceFile;
|
|
20
|
+
}
|
|
21
|
+
const classes = moduleInfo.classes;
|
|
22
|
+
const sourceViewInfos = classes.flatMap(c => c.views);
|
|
23
|
+
const updateSourceFile = ts.visitNode(sourceFile, (node) => {
|
|
24
|
+
return ts.visitEachChild(node, (childNode) => {
|
|
25
|
+
if (!ts.isClassDeclaration(childNode)) {
|
|
26
|
+
return childNode;
|
|
27
|
+
}
|
|
28
|
+
const info = classes.find(c => c.name === childNode.name?.getText());
|
|
29
|
+
if (!info) {
|
|
30
|
+
return childNode;
|
|
31
|
+
}
|
|
32
|
+
const viewInfos = info.views;
|
|
33
|
+
const staticMembers = viewInfos.map(viewInfo => ts.factory.createPropertyDeclaration([
|
|
34
|
+
ts.factory.createModifier(ts.SyntaxKind.StaticKeyword),
|
|
35
|
+
ts.factory.createModifier(ts.SyntaxKind.ReadonlyKeyword)
|
|
36
|
+
], viewInfo.viewName, undefined, createStaticPropertyViewType(viewInfo.viewName), undefined)).map(staticMember => ts.setTextRange(staticMember, childNode));
|
|
37
|
+
return ts.factory.updateClassDeclaration(childNode, childNode.modifiers, childNode.name, childNode.typeParameters, childNode.heritageClauses, [...staticMembers, ...childNode.members.slice()]);
|
|
38
|
+
}, context);
|
|
39
|
+
});
|
|
40
|
+
if (sourceViewInfos.length) {
|
|
41
|
+
const statements = updateSourceFile.statements?.slice() ?? [];
|
|
42
|
+
// statements.push(createConstructorOfViewInterfaceDeclaration());
|
|
43
|
+
// const interfaces = sourceViewInfos.map(info => {
|
|
44
|
+
// return ts.setTextRange(info.interFaceType, updateSourceFile);
|
|
45
|
+
// });
|
|
46
|
+
// statements.push(...interfaces);
|
|
47
|
+
// statements.push(...updateGlobalHTMLElementTagNameMap(sourceViewInfos.map(v => ({ tagName: v.selector, viewName: v.viewName }))));
|
|
48
|
+
statements.push(...updateModule(classes));
|
|
49
|
+
return ts.factory.updateSourceFile(sourceFile, statements, updateSourceFile.isDeclarationFile, updateSourceFile.typeReferenceDirectives, updateSourceFile.referencedFiles, updateSourceFile.hasNoDefaultLib, updateSourceFile.libReferenceDirectives);
|
|
50
|
+
}
|
|
51
|
+
return updateSourceFile;
|
|
52
|
+
};
|
|
53
|
+
};
|
|
54
|
+
}
|
|
55
|
+
export default afterDeclarationsCompileComponentOptions;
|
|
56
|
+
//# sourceMappingURL=after-declarations-component.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"after-declarations-component.js","sourceRoot":"","sources":["../../../src/cli/transformer/after-declarations-component.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,mCAAmC,CAAC;AACnD,OAAO,EAAE,4BAA4B,EAAE,YAAY,EAAE,MAAM,cAAc,CAAC;AAC1E,OAAO,EAAE,YAAY,EAAY,MAAM,cAAc,CAAC;AAGtD;;;;GAIG;AACH,MAAM,UAAU,wCAAwC,CAAC,OAAmB;IA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,wCAAwC,CAAC","sourcesContent":["import ts from 'typescript/lib/tsserverlibrary.js';\nimport { createStaticPropertyViewType, updateModule } from './factory.js';\nimport { moduleManger, ViewInfo } from './modules.js';\n\n\n/**\n * search for `@Component({})` and update definition files\n * @param program a ts program \n * @returns a transformer factory of source file\n */\nexport function afterDeclarationsCompileComponentOptions(program: ts.Program): ts.TransformerFactory<ts.SourceFile> {\n\tconst typeChecker = program.getTypeChecker();\n\treturn (context: ts.TransformationContext): ts.Transformer<ts.SourceFile> => {\n\t\treturn sourceFile => {\n\t\t\tconst moduleInfo = moduleManger.get(sourceFile.fileName);\n\t\t\tmoduleManger.delete(sourceFile.fileName);\n\t\t\tif (!moduleInfo) {\n\t\t\t\treturn sourceFile;\n\t\t\t} else if (moduleInfo.skip || !moduleInfo.classes) {\n\t\t\t\treturn sourceFile;\n\t\t\t}\n\n\t\t\tconst classes = moduleInfo.classes;\n\n\t\t\tconst sourceViewInfos: ViewInfo[] = classes.flatMap(c => c.views);\n\t\t\tconst updateSourceFile = ts.visitNode(sourceFile, (node: ts.Node) => {\n\t\t\t\treturn ts.visitEachChild(node, (childNode) => {\n\t\t\t\t\tif (!ts.isClassDeclaration(childNode)) {\n\t\t\t\t\t\treturn childNode;\n\t\t\t\t\t}\n\t\t\t\t\tconst info = classes.find(c => c.name === childNode.name?.getText());\n\n\t\t\t\t\tif (!info) {\n\t\t\t\t\t\treturn childNode;\n\t\t\t\t\t}\n\t\t\t\t\tconst viewInfos: ViewInfo[] = info.views;\n\t\t\t\t\tconst staticMembers = viewInfos.map(viewInfo => ts.factory.createPropertyDeclaration(\n\t\t\t\t\t\t[\n\t\t\t\t\t\t\tts.factory.createModifier(ts.SyntaxKind.StaticKeyword),\n\t\t\t\t\t\t\tts.factory.createModifier(ts.SyntaxKind.ReadonlyKeyword)\n\t\t\t\t\t\t],\n\t\t\t\t\t\tviewInfo.viewName,\n\t\t\t\t\t\tundefined,\n\t\t\t\t\t\tcreateStaticPropertyViewType(viewInfo.viewName),\n\t\t\t\t\t\tundefined,\n\t\t\t\t\t)).map(staticMember => ts.setTextRange(staticMember, childNode));\n\t\t\t\t\treturn ts.factory.updateClassDeclaration(\n\t\t\t\t\t\tchildNode,\n\t\t\t\t\t\tchildNode.modifiers,\n\t\t\t\t\t\tchildNode.name,\n\t\t\t\t\t\tchildNode.typeParameters,\n\t\t\t\t\t\tchildNode.heritageClauses,\n\t\t\t\t\t\t[...staticMembers, ...childNode.members.slice()],\n\t\t\t\t\t);\n\t\t\t\t}, context);\n\t\t\t});\n\t\t\tif (sourceViewInfos.length) {\n\t\t\t\tconst statements = updateSourceFile.statements?.slice() ?? [];\n\t\t\t\t// statements.push(createConstructorOfViewInterfaceDeclaration());\n\t\t\t\t// const interfaces = sourceViewInfos.map(info => {\n\t\t\t\t// \treturn ts.setTextRange(info.interFaceType, updateSourceFile);\n\t\t\t\t// });\n\t\t\t\t// statements.push(...interfaces);\n\t\t\t\t// statements.push(...updateGlobalHTMLElementTagNameMap(sourceViewInfos.map(v => ({ tagName: v.selector, viewName: v.viewName }))));\n\t\t\t\tstatements.push(...updateModule(classes));\n\t\t\t\treturn ts.factory.updateSourceFile(\n\t\t\t\t\tsourceFile,\n\t\t\t\t\tstatements,\n\t\t\t\t\tupdateSourceFile.isDeclarationFile,\n\t\t\t\t\tupdateSourceFile.typeReferenceDirectives,\n\t\t\t\t\tupdateSourceFile.referencedFiles,\n\t\t\t\t\tupdateSourceFile.hasNoDefaultLib,\n\t\t\t\t\tupdateSourceFile.libReferenceDirectives,\n\t\t\t\t);\n\t\t\t}\n\t\t\treturn updateSourceFile;\n\t\t};\n\t};\n}\n\nexport default afterDeclarationsCompileComponentOptions;\n"]}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import ts from 'typescript/lib/tsserverlibrary.js';
|
|
2
|
+
import { InputOutputTypeInfo } from './modules.js';
|
|
3
|
+
/**
|
|
4
|
+
* search for `@Component({})` and precompile the source code
|
|
5
|
+
* @param program a ts program
|
|
6
|
+
* @returns a transformer factory of source file
|
|
7
|
+
*/
|
|
8
|
+
export declare function beforeCompileComponentOptions(program: ts.Program): ts.TransformerFactory<ts.SourceFile>;
|
|
9
|
+
export declare function isInputDecorator(decorator: ts.Decorator): boolean;
|
|
10
|
+
export declare function isOutputDecorator(decorator: ts.Decorator): boolean;
|
|
11
|
+
export declare function getMapByDecorator(classNode: ts.ClassDeclaration, checker: ts.TypeChecker, decoratorFilter: ((decorator: ts.Decorator) => boolean)): InputOutputTypeInfo;
|
|
12
|
+
export declare function getInputs(classNode: ts.ClassDeclaration, checker: ts.TypeChecker): InputOutputTypeInfo;
|
|
13
|
+
export declare function getOutputs(classNode: ts.ClassDeclaration, checker: ts.TypeChecker): InputOutputTypeInfo;
|
|
14
|
+
export default beforeCompileComponentOptions;
|
|
@@ -0,0 +1,226 @@
|
|
|
1
|
+
import ts from 'typescript/lib/tsserverlibrary.js';
|
|
2
|
+
import { buildExpressionNodes } from '@ibyar/core/node';
|
|
3
|
+
import { htmlParser } from '@ibyar/elements/node';
|
|
4
|
+
import { getExtendsTypeBySelector } from '../elements/tags.js';
|
|
5
|
+
import { convertToProperties, createConstructorOfViewInterfaceDeclaration, createInterfaceType, createStaticPropertyViewType } from './factory.js';
|
|
6
|
+
import { moduleManger } from './modules.js';
|
|
7
|
+
/**
|
|
8
|
+
* search for `@Component({})` and precompile the source code
|
|
9
|
+
* @param program a ts program
|
|
10
|
+
* @returns a transformer factory of source file
|
|
11
|
+
*/
|
|
12
|
+
export function beforeCompileComponentOptions(program) {
|
|
13
|
+
const typeChecker = program.getTypeChecker();
|
|
14
|
+
return (context) => {
|
|
15
|
+
return sourceFile => {
|
|
16
|
+
let visitSourceFile = false;
|
|
17
|
+
let componentPropertyName;
|
|
18
|
+
for (const statement of sourceFile.statements) {
|
|
19
|
+
if (ts.isImportDeclaration(statement)) {
|
|
20
|
+
const modulePath = statement.moduleSpecifier.getText();
|
|
21
|
+
if (statement.importClause && modulePath.includes('@ibyar/aurora') || modulePath.includes('@ibyar/core')) {
|
|
22
|
+
statement.importClause?.namedBindings?.forEachChild(importSpecifier => {
|
|
23
|
+
if (visitSourceFile) {
|
|
24
|
+
return;
|
|
25
|
+
}
|
|
26
|
+
if (ts.isImportSpecifier(importSpecifier)) {
|
|
27
|
+
if (importSpecifier.propertyName?.getText() === 'Component') {
|
|
28
|
+
visitSourceFile = true;
|
|
29
|
+
componentPropertyName = importSpecifier.name.getText();
|
|
30
|
+
}
|
|
31
|
+
else if (importSpecifier.name.getText() === 'Component') {
|
|
32
|
+
visitSourceFile = true;
|
|
33
|
+
componentPropertyName = importSpecifier.name.getText();
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
});
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
if (visitSourceFile) {
|
|
40
|
+
break;
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
if (!visitSourceFile) {
|
|
44
|
+
moduleManger.add({ path: sourceFile.fileName, skip: true });
|
|
45
|
+
return sourceFile;
|
|
46
|
+
}
|
|
47
|
+
const classes = [];
|
|
48
|
+
const updateSourceFile = ts.visitNode(sourceFile, (node) => {
|
|
49
|
+
return ts.visitEachChild(node, (childNode) => {
|
|
50
|
+
let decoratorArguments;
|
|
51
|
+
if (ts.isClassDeclaration(childNode)) {
|
|
52
|
+
const decorators = ts.getDecorators(childNode);
|
|
53
|
+
if (!decorators || decorators.length === 0) {
|
|
54
|
+
return childNode;
|
|
55
|
+
}
|
|
56
|
+
const isComponentDecorator = (decorator) => {
|
|
57
|
+
return ts.isCallExpression(decorator.expression)
|
|
58
|
+
&& decorator.expression.expression.getText() === componentPropertyName;
|
|
59
|
+
};
|
|
60
|
+
const hasComponentDecorator = decorators.some(isComponentDecorator);
|
|
61
|
+
if (!hasComponentDecorator) {
|
|
62
|
+
return childNode;
|
|
63
|
+
}
|
|
64
|
+
const viewInfos = [];
|
|
65
|
+
const modifiers = childNode.modifiers?.map(modifier => {
|
|
66
|
+
if (!ts.isDecorator(modifier)) {
|
|
67
|
+
return modifier;
|
|
68
|
+
}
|
|
69
|
+
if (!isComponentDecorator(modifier)) {
|
|
70
|
+
return modifier;
|
|
71
|
+
}
|
|
72
|
+
const updateDecoratorOptions = (option) => {
|
|
73
|
+
const selectorProperty = option.properties
|
|
74
|
+
.find(prop => prop.name?.getText() === 'selector');
|
|
75
|
+
if (!selectorProperty) {
|
|
76
|
+
console.error(`Component missing selector name: ${childNode.name?.getText()}`);
|
|
77
|
+
return option;
|
|
78
|
+
}
|
|
79
|
+
const initializer = selectorProperty.initializer.getText();
|
|
80
|
+
const selector = initializer.substring(1, initializer.length - 1);
|
|
81
|
+
const viewName = `HTML${selector.split('-')
|
|
82
|
+
.map(name => name.replace(/^\w/, char => char.toUpperCase()))
|
|
83
|
+
.join('')}Element`;
|
|
84
|
+
const extendProperty = option.properties.find(prop => prop.name?.getText() === 'extend');
|
|
85
|
+
const extend = extendProperty?.initializer.getText().substring(1, extendProperty?.initializer.getText().length - 1);
|
|
86
|
+
const extendsType = getExtendsTypeBySelector(extend);
|
|
87
|
+
const formAssociatedProperty = option.properties.find(prop => prop.name?.getText() === 'formAssociated');
|
|
88
|
+
const formAssociated = formAssociatedProperty?.initializer.getText().substring(1, formAssociatedProperty?.initializer.getText().length - 1);
|
|
89
|
+
viewInfos.push({
|
|
90
|
+
selector,
|
|
91
|
+
viewName,
|
|
92
|
+
extendsType,
|
|
93
|
+
interFaceType: createInterfaceType(viewName, extendsType),
|
|
94
|
+
formAssociated: 'true' == formAssociated,
|
|
95
|
+
});
|
|
96
|
+
const stylesProperty = option.properties.find(prop => prop.name?.getText() === 'styles');
|
|
97
|
+
const styles = stylesProperty?.initializer.getText().substring(1, stylesProperty?.initializer.getText().length - 1);
|
|
98
|
+
const template = option.properties.find(prop => prop.name?.getText() === 'template');
|
|
99
|
+
if (template && ts.isPropertyAssignment(template) && ts.isStringLiteralLike(template.initializer)) {
|
|
100
|
+
const text = template?.initializer.getText().substring(1, template?.initializer.getText().length - 1);
|
|
101
|
+
const html = styles
|
|
102
|
+
? `<style>${styles}</style>${text}`
|
|
103
|
+
: text;
|
|
104
|
+
const domNode = htmlParser.toDomRootNode(html);
|
|
105
|
+
buildExpressionNodes(domNode);
|
|
106
|
+
const serialized = JSON.stringify(domNode);
|
|
107
|
+
const json = JSON.parse(serialized);
|
|
108
|
+
const name = ts.factory.createIdentifier('compiledTemplate');
|
|
109
|
+
const initializer = ts.factory.createObjectLiteralExpression(convertToProperties(json));
|
|
110
|
+
const update = ts.factory.updatePropertyAssignment(template, name, initializer);
|
|
111
|
+
decoratorArguments = option.properties.map(prop => {
|
|
112
|
+
if (template === prop) {
|
|
113
|
+
return update;
|
|
114
|
+
}
|
|
115
|
+
return prop;
|
|
116
|
+
}).filter(prop => {
|
|
117
|
+
if (prop.name?.getText(sourceFile) === 'styles') {
|
|
118
|
+
return false;
|
|
119
|
+
}
|
|
120
|
+
return true;
|
|
121
|
+
});
|
|
122
|
+
return ts.factory.updateObjectLiteralExpression(option, decoratorArguments);
|
|
123
|
+
}
|
|
124
|
+
return option;
|
|
125
|
+
// options.properties.filter((prop: ts.PropertyAssignment) => {
|
|
126
|
+
// switch (prop.name.getText()) {
|
|
127
|
+
// case 'template':
|
|
128
|
+
// case 'templateUrl':
|
|
129
|
+
// case 'styles':
|
|
130
|
+
// return true;
|
|
131
|
+
// default: return false;
|
|
132
|
+
// }
|
|
133
|
+
// })
|
|
134
|
+
};
|
|
135
|
+
const decoratorCall = modifier.expression;
|
|
136
|
+
const options = decoratorCall.arguments[0];
|
|
137
|
+
let argumentsOption;
|
|
138
|
+
if (ts.isArrayLiteralExpression(options)) {
|
|
139
|
+
const elements = options.elements.map(element => {
|
|
140
|
+
if (ts.isObjectLiteralExpression(element)) {
|
|
141
|
+
return updateDecoratorOptions(element);
|
|
142
|
+
}
|
|
143
|
+
return element;
|
|
144
|
+
});
|
|
145
|
+
argumentsOption = ts.factory.updateArrayLiteralExpression(options, elements);
|
|
146
|
+
}
|
|
147
|
+
else if (ts.isObjectLiteralExpression(options)) {
|
|
148
|
+
argumentsOption = updateDecoratorOptions(options);
|
|
149
|
+
}
|
|
150
|
+
if (argumentsOption) {
|
|
151
|
+
return ts.factory.updateDecorator(modifier, ts.factory.updateCallExpression(decoratorCall, decoratorCall.expression, decoratorCall.typeArguments, [argumentsOption]));
|
|
152
|
+
}
|
|
153
|
+
return modifier;
|
|
154
|
+
});
|
|
155
|
+
classes.push({
|
|
156
|
+
name: childNode.name?.getText() ?? '',
|
|
157
|
+
views: viewInfos,
|
|
158
|
+
inputs: getInputs(childNode, typeChecker),
|
|
159
|
+
outputs: getOutputs(childNode, typeChecker),
|
|
160
|
+
});
|
|
161
|
+
const staticMembers = viewInfos.map(viewInfo => ts.factory.createPropertyDeclaration([
|
|
162
|
+
ts.factory.createModifier(ts.SyntaxKind.StaticKeyword),
|
|
163
|
+
ts.factory.createModifier(ts.SyntaxKind.ReadonlyKeyword)
|
|
164
|
+
], viewInfo.viewName, undefined, createStaticPropertyViewType(viewInfo.viewName), undefined));
|
|
165
|
+
return ts.factory.updateClassDeclaration(childNode, modifiers ? ts.factory.createNodeArray(modifiers) : void 0, childNode.name, childNode.typeParameters, childNode.heritageClauses, [...staticMembers, ...childNode.members.slice()]);
|
|
166
|
+
}
|
|
167
|
+
return childNode;
|
|
168
|
+
}, context);
|
|
169
|
+
});
|
|
170
|
+
if (classes.length) {
|
|
171
|
+
moduleManger.add({ path: sourceFile.fileName, classes });
|
|
172
|
+
const statements = updateSourceFile.statements?.slice() ?? [];
|
|
173
|
+
statements.push(createConstructorOfViewInterfaceDeclaration());
|
|
174
|
+
const interfaces = classes.flatMap(s => s.views).map(info => {
|
|
175
|
+
return ts.setTextRange(info.interFaceType, updateSourceFile);
|
|
176
|
+
});
|
|
177
|
+
statements.push(...interfaces);
|
|
178
|
+
return ts.factory.updateSourceFile(sourceFile, statements, updateSourceFile.isDeclarationFile, updateSourceFile.typeReferenceDirectives, updateSourceFile.referencedFiles, updateSourceFile.hasNoDefaultLib, updateSourceFile.libReferenceDirectives);
|
|
179
|
+
}
|
|
180
|
+
moduleManger.add({ path: sourceFile.fileName, skip: true });
|
|
181
|
+
return updateSourceFile;
|
|
182
|
+
};
|
|
183
|
+
};
|
|
184
|
+
}
|
|
185
|
+
export function isInputDecorator(decorator) {
|
|
186
|
+
return ts.isCallExpression(decorator.expression) && (decorator.expression.expression.getText() === 'Input'
|
|
187
|
+
|| decorator.expression.expression.getText() === 'FormValue');
|
|
188
|
+
}
|
|
189
|
+
export function isOutputDecorator(decorator) {
|
|
190
|
+
return ts.isCallExpression(decorator.expression) && decorator.expression.expression.getText() === 'Output';
|
|
191
|
+
}
|
|
192
|
+
export function getMapByDecorator(classNode, checker, decoratorFilter) {
|
|
193
|
+
const map = {};
|
|
194
|
+
classNode.members.forEach(member => {
|
|
195
|
+
if (!ts.isPropertyDeclaration(member)) {
|
|
196
|
+
return;
|
|
197
|
+
}
|
|
198
|
+
const decorators = ts.getDecorators(member);
|
|
199
|
+
if (!decorators) {
|
|
200
|
+
return;
|
|
201
|
+
}
|
|
202
|
+
const inputDecorators = decorators.filter(decoratorFilter);
|
|
203
|
+
if (!inputDecorators.length) {
|
|
204
|
+
return;
|
|
205
|
+
}
|
|
206
|
+
let inputType = member.type?.getText();
|
|
207
|
+
if (!inputType && member.initializer) {
|
|
208
|
+
inputType = checker.typeToString(checker.getTypeAtLocation(member.initializer), member.initializer, undefined);
|
|
209
|
+
}
|
|
210
|
+
inputDecorators.forEach(input => {
|
|
211
|
+
const decoratorCall = input.expression;
|
|
212
|
+
const aliasName = decoratorCall.arguments[0];
|
|
213
|
+
const inputName = aliasName ? aliasName.text : member.name.getText();
|
|
214
|
+
map[inputName] = inputType;
|
|
215
|
+
});
|
|
216
|
+
});
|
|
217
|
+
return map;
|
|
218
|
+
}
|
|
219
|
+
export function getInputs(classNode, checker) {
|
|
220
|
+
return getMapByDecorator(classNode, checker, isInputDecorator);
|
|
221
|
+
}
|
|
222
|
+
export function getOutputs(classNode, checker) {
|
|
223
|
+
return getMapByDecorator(classNode, checker, isOutputDecorator);
|
|
224
|
+
}
|
|
225
|
+
export default beforeCompileComponentOptions;
|
|
226
|
+
//# sourceMappingURL=before-component.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"before-component.js","sourceRoot":"","sources":["../../../src/cli/transformer/before-component.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,mCAAmC,CAAC;AACnD,OAAO,EAAE,oBAAoB,EAAE,MAAM,kBAAkB,CAAC;AACxD,OAAO,EAAE,UAAU,EAAE,MAAM,sBAAsB,CAAC;AAClD,OAAO,EAAE,wBAAwB,EAAE,MAAM,qBAAqB,CAAC;AAC/D,OAAO,EACN,mBAAmB,EAAE,2CAA2C,EAChE,mBAAmB,EAAE,4BAA4B,EACjD,MAAM,cAAc,CAAC;AACtB,OAAO,EAAE,YAAY,EAA4C,MAAM,cAAc,CAAC;AAEtF;;;;GAIG;AACH,MAAM,UAAU,6BAA6B,CAAC,OAAmB;IAChE,MAAM,WAAW,GAAG,OAAO,CAAC,cAAc,EAAE,CAAC;IAC7C,OAAO,CAAC,OAAiC,EAAiC,EAAE;QAC3E,OAAO,UAAU,CAAC,EAAE;YACnB,IAAI,eAAe,GAAG,KAAK,CAAC;YAC5B,IAAI,qBAA6B,CAAC;YAClC,KAAK,MAAM,SAAS,IAAI,UAAU,CAAC,UAAU,EAAE;gBAC9C,IAAI,EAAE,CAAC,mBAAmB,CAAC,SAAS,CAAC,EAAE;oBACtC,MAAM,UAAU,GAAG,SAAS,CAAC,eAAe,CAAC,OAAO,EAAE,CAAC;oBACvD,IAAI,SAAS,CAAC,YAAY,IAAI,UAAU,CAAC,QAAQ,CAAC,eAAe,CAAC,IAAI,UAAU,CAAC,QAAQ,CAAC,aAAa,CAAC,EAAE;wBACzG,SAAS,CAAC,YAAY,EAAE,aAAa,EAAE,YAAY,CAAC,eAAe,CAAC,EAAE;4BACrE,IAAI,eAAe,EAAE;gCAC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AC;YACrE,MAAM,SAAS,GAAG,SAAS,CAAC,CAAC,CAAC,SAAS,CAAC,IAAI,CAAC,CAAC,CAAC,MAAM,CAAC,IAAI,CAAC,OAAO,EAAE,CAAC;YACrE,GAAG,CAAC,SAAS,CAAC,GAAG,SAAS,CAAC;QAC5B,CAAC,CAAC,CAAC;IACJ,CAAC,CAAC,CAAA;IACF,OAAO,GAAG,CAAC;AACZ,CAAC;AAED,MAAM,UAAU,SAAS,CAAC,SAA8B,EAAE,OAAuB;IAEhF,OAAO,iBAAiB,CAAC,SAAS,EAAE,OAAO,EAAE,gBAAgB,CAAC,CAAC;AAChE,CAAC;AAED,MAAM,UAAU,UAAU,CAAC,SAA8B,EAAE,OAAuB;IACjF,OAAO,iBAAiB,CAAC,SAAS,EAAE,OAAO,EAAE,iBAAiB,CAAC,CAAC;AACjE,CAAC;AAED,eAAe,6BAA6B,CAAC","sourcesContent":["import ts from 'typescript/lib/tsserverlibrary.js';\nimport { buildExpressionNodes } from '@ibyar/core/node';\nimport { htmlParser } from '@ibyar/elements/node';\nimport { getExtendsTypeBySelector } from '../elements/tags.js';\nimport {\n\tconvertToProperties, createConstructorOfViewInterfaceDeclaration,\n\tcreateInterfaceType, createStaticPropertyViewType\n} from './factory.js';\nimport { moduleManger, ViewInfo, ClassInfo, InputOutputTypeInfo } from './modules.js';\n\n/**\n * search for `@Component({})` and precompile the source code\n * @param program a ts program \n * @returns a transformer factory of source file\n */\nexport function beforeCompileComponentOptions(program: ts.Program): ts.TransformerFactory<ts.SourceFile> {\n\tconst typeChecker = program.getTypeChecker();\n\treturn (context: ts.TransformationContext): ts.Transformer<ts.SourceFile> => {\n\t\treturn sourceFile => {\n\t\t\tlet visitSourceFile = false;\n\t\t\tlet componentPropertyName: string;\n\t\t\tfor (const statement of sourceFile.statements) {\n\t\t\t\tif (ts.isImportDeclaration(statement)) {\n\t\t\t\t\tconst modulePath = statement.moduleSpecifier.getText();\n\t\t\t\t\tif (statement.importClause && modulePath.includes('@ibyar/aurora') || modulePath.includes('@ibyar/core')) {\n\t\t\t\t\t\tstatement.importClause?.namedBindings?.forEachChild(importSpecifier => {\n\t\t\t\t\t\t\tif (visitSourceFile) {\n\t\t\t\t\t\t\t\treturn;\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\tif (ts.isImportSpecifier(importSpecifier)) {\n\t\t\t\t\t\t\t\tif (importSpecifier.propertyName?.getText() === 'Component') {\n\t\t\t\t\t\t\t\t\tvisitSourceFile = true;\n\t\t\t\t\t\t\t\t\tcomponentPropertyName = importSpecifier.name.getText();\n\t\t\t\t\t\t\t\t} else if (importSpecifier.name.getText() === 'Component') {\n\t\t\t\t\t\t\t\t\tvisitSourceFile = true;\n\t\t\t\t\t\t\t\t\tcomponentPropertyName = importSpecifier.name.getText();\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t});\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\tif (visitSourceFile) {\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t}\n\t\t\tif (!visitSourceFile) {\n\t\t\t\tmoduleManger.add({ path: sourceFile.fileName, skip: true });\n\t\t\t\treturn sourceFile;\n\t\t\t}\n\n\t\t\tconst classes: ClassInfo[] = [];\n\t\t\tconst updateSourceFile = ts.visitNode(sourceFile, (node: ts.Node) => {\n\t\t\t\treturn ts.visitEachChild(node, (childNode) => {\n\t\t\t\t\tlet decoratorArguments: ts.ObjectLiteralElementLike[] | undefined;\n\t\t\t\t\tif (ts.isClassDeclaration(childNode)) {\n\t\t\t\t\t\tconst decorators = ts.getDecorators(childNode);\n\t\t\t\t\t\tif (!decorators || decorators.length === 0) {\n\t\t\t\t\t\t\treturn childNode;\n\t\t\t\t\t\t}\n\t\t\t\t\t\tconst isComponentDecorator = (decorator: ts.Decorator): boolean => {\n\t\t\t\t\t\t\treturn ts.isCallExpression(decorator.expression)\n\t\t\t\t\t\t\t\t&& decorator.expression.expression.getText() === componentPropertyName;\n\t\t\t\t\t\t};\n\t\t\t\t\t\tconst hasComponentDecorator = decorators.some(isComponentDecorator);\n\t\t\t\t\t\tif (!hasComponentDecorator) {\n\t\t\t\t\t\t\treturn childNode;\n\t\t\t\t\t\t}\n\n\t\t\t\t\t\tconst viewInfos: ViewInfo[] = [];\n\t\t\t\t\t\tconst modifiers = childNode.modifiers?.map(modifier => {\n\t\t\t\t\t\t\tif (!ts.isDecorator(modifier)) {\n\t\t\t\t\t\t\t\treturn modifier;\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\tif (!isComponentDecorator(modifier)) {\n\t\t\t\t\t\t\t\treturn modifier;\n\t\t\t\t\t\t\t}\n\n\t\t\t\t\t\t\tconst updateDecoratorOptions = (option: ts.ObjectLiteralExpression) => {\n\t\t\t\t\t\t\t\tconst selectorProperty = option.properties\n\t\t\t\t\t\t\t\t\t.find(prop => prop.name?.getText() === 'selector') as ts.PropertyAssignment | undefined;\n\n\t\t\t\t\t\t\t\tif (!selectorProperty) {\n\t\t\t\t\t\t\t\t\tconsole.error(`Component missing selector name: ${childNode.name?.getText()}`);\n\t\t\t\t\t\t\t\t\treturn option;\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\tconst initializer = selectorProperty.initializer.getText();\n\t\t\t\t\t\t\t\tconst selector = initializer.substring(1, initializer.length - 1);\n\t\t\t\t\t\t\t\tconst viewName = `HTML${selector.split('-')\n\t\t\t\t\t\t\t\t\t.map(name => name.replace(/^\\w/, char => char.toUpperCase()))\n\t\t\t\t\t\t\t\t\t.join('')}Element`;\n\n\n\t\t\t\t\t\t\t\tconst extendProperty = option.properties.find(prop => prop.name?.getText() === 'extend') as ts.PropertyAssignment | undefined;\n\t\t\t\t\t\t\t\tconst extend = extendProperty?.initializer.getText().substring(1, extendProperty?.initializer.getText().length - 1);\n\t\t\t\t\t\t\t\tconst extendsType = getExtendsTypeBySelector(extend);\n\n\t\t\t\t\t\t\t\tconst formAssociatedProperty = option.properties.find(prop => prop.name?.getText() === 'formAssociated') as ts.PropertyAssignment | undefined;\n\t\t\t\t\t\t\t\tconst formAssociated = formAssociatedProperty?.initializer.getText().substring(1, formAssociatedProperty?.initializer.getText().length - 1);\n\n\t\t\t\t\t\t\t\tviewInfos.push({\n\t\t\t\t\t\t\t\t\tselector,\n\t\t\t\t\t\t\t\t\tviewName,\n\t\t\t\t\t\t\t\t\textendsType,\n\t\t\t\t\t\t\t\t\tinterFaceType: createInterfaceType(viewName, extendsType),\n\t\t\t\t\t\t\t\t\tformAssociated: 'true' == formAssociated,\n\t\t\t\t\t\t\t\t});\n\n\t\t\t\t\t\t\t\tconst stylesProperty = option.properties.find(prop => prop.name?.getText() === 'styles') as ts.PropertyAssignment | undefined;\n\t\t\t\t\t\t\t\tconst styles = stylesProperty?.initializer.getText().substring(1, stylesProperty?.initializer.getText().length - 1);\n\n\t\t\t\t\t\t\t\tconst template = option.properties.find(prop => prop.name?.getText() === 'template');\n\t\t\t\t\t\t\t\tif (template && ts.isPropertyAssignment(template) && ts.isStringLiteralLike(template.initializer)) {\n\t\t\t\t\t\t\t\t\tconst text = template?.initializer.getText().substring(1, template?.initializer.getText().length - 1);\n\t\t\t\t\t\t\t\t\tconst html = styles\n\t\t\t\t\t\t\t\t\t\t? `<style>${styles}</style>${text}`\n\t\t\t\t\t\t\t\t\t\t: text;\n\t\t\t\t\t\t\t\t\tconst domNode = htmlParser.toDomRootNode(html);\n\t\t\t\t\t\t\t\t\tbuildExpressionNodes(domNode);\n\t\t\t\t\t\t\t\t\tconst serialized = JSON.stringify(domNode);\n\t\t\t\t\t\t\t\t\tconst json = JSON.parse(serialized);\n\t\t\t\t\t\t\t\t\tconst name = ts.factory.createIdentifier('compiledTemplate');\n\t\t\t\t\t\t\t\t\tconst initializer = ts.factory.createObjectLiteralExpression(convertToProperties(json));\n\t\t\t\t\t\t\t\t\tconst update = ts.factory.updatePropertyAssignment(template, name, initializer);\n\t\t\t\t\t\t\t\t\tdecoratorArguments = option.properties.map(prop => {\n\t\t\t\t\t\t\t\t\t\tif (template === prop) {\n\t\t\t\t\t\t\t\t\t\t\treturn update;\n\t\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\t\treturn prop;\n\t\t\t\t\t\t\t\t\t}).filter(prop => {\n\t\t\t\t\t\t\t\t\t\tif (prop.name?.getText(sourceFile) === 'styles') {\n\t\t\t\t\t\t\t\t\t\t\treturn false;\n\t\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\t\treturn true;\n\t\t\t\t\t\t\t\t\t});\n\t\t\t\t\t\t\t\t\treturn ts.factory.updateObjectLiteralExpression(option, decoratorArguments);\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\treturn option;\n\n\t\t\t\t\t\t\t\t// options.properties.filter((prop: ts.PropertyAssignment) => {\n\t\t\t\t\t\t\t\t// \tswitch (prop.name.getText()) {\n\t\t\t\t\t\t\t\t// \t\tcase 'template':\n\t\t\t\t\t\t\t\t// \t\tcase 'templateUrl':\n\t\t\t\t\t\t\t\t// \t\tcase 'styles':\n\t\t\t\t\t\t\t\t// \t\t\treturn true;\n\t\t\t\t\t\t\t\t// \t\tdefault: return false;\n\t\t\t\t\t\t\t\t// \t}\n\t\t\t\t\t\t\t\t// })\n\t\t\t\t\t\t\t};\n\t\t\t\t\t\t\tconst decoratorCall = modifier.expression as ts.CallExpression;\n\t\t\t\t\t\t\tconst options = decoratorCall.arguments[0];\n\t\t\t\t\t\t\tlet argumentsOption: ts.Expression | undefined;\n\t\t\t\t\t\t\tif (ts.isArrayLiteralExpression(options)) {\n\t\t\t\t\t\t\t\tconst elements: ts.Expression[] = options.elements.map(element => {\n\t\t\t\t\t\t\t\t\tif (ts.isObjectLiteralExpression(element)) {\n\t\t\t\t\t\t\t\t\t\treturn updateDecoratorOptions(element);\n\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\treturn element;\n\t\t\t\t\t\t\t\t});\n\t\t\t\t\t\t\t\targumentsOption = ts.factory.updateArrayLiteralExpression(options, elements);\n\t\t\t\t\t\t\t} else if (ts.isObjectLiteralExpression(options)) {\n\t\t\t\t\t\t\t\targumentsOption = updateDecoratorOptions(options);\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\tif (argumentsOption) {\n\t\t\t\t\t\t\t\treturn ts.factory.updateDecorator(\n\t\t\t\t\t\t\t\t\tmodifier,\n\t\t\t\t\t\t\t\t\tts.factory.updateCallExpression(\n\t\t\t\t\t\t\t\t\t\tdecoratorCall,\n\t\t\t\t\t\t\t\t\t\tdecoratorCall.expression,\n\t\t\t\t\t\t\t\t\t\tdecoratorCall.typeArguments,\n\t\t\t\t\t\t\t\t\t\t[argumentsOption]\n\t\t\t\t\t\t\t\t\t)\n\t\t\t\t\t\t\t\t);\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\treturn modifier;\n\t\t\t\t\t\t});\n\n\t\t\t\t\t\tclasses.push({\n\t\t\t\t\t\t\tname: childNode.name?.getText() ?? '',\n\t\t\t\t\t\t\tviews: viewInfos,\n\t\t\t\t\t\t\tinputs: getInputs(childNode, typeChecker),\n\t\t\t\t\t\t\toutputs: getOutputs(childNode, typeChecker),\n\t\t\t\t\t\t});\n\t\t\t\t\t\tconst staticMembers = viewInfos.map(\n\t\t\t\t\t\t\tviewInfo => ts.factory.createPropertyDeclaration(\n\t\t\t\t\t\t\t\t[\n\t\t\t\t\t\t\t\t\tts.factory.createModifier(ts.SyntaxKind.StaticKeyword),\n\t\t\t\t\t\t\t\t\tts.factory.createModifier(ts.SyntaxKind.ReadonlyKeyword)\n\t\t\t\t\t\t\t\t],\n\t\t\t\t\t\t\t\tviewInfo.viewName,\n\t\t\t\t\t\t\t\tundefined,\n\t\t\t\t\t\t\t\tcreateStaticPropertyViewType(viewInfo.viewName),\n\t\t\t\t\t\t\t\tundefined,\n\t\t\t\t\t\t\t)\n\t\t\t\t\t\t);\n\t\t\t\t\t\treturn ts.factory.updateClassDeclaration(\n\t\t\t\t\t\t\tchildNode,\n\t\t\t\t\t\t\tmodifiers ? ts.factory.createNodeArray(modifiers) : void 0,\n\t\t\t\t\t\t\tchildNode.name,\n\t\t\t\t\t\t\tchildNode.typeParameters,\n\t\t\t\t\t\t\tchildNode.heritageClauses,\n\t\t\t\t\t\t\t[...staticMembers, ...childNode.members.slice()],\n\t\t\t\t\t\t);\n\t\t\t\t\t}\n\t\t\t\t\treturn childNode;\n\t\t\t\t}, context);\n\t\t\t});\n\t\t\tif (classes.length) {\n\t\t\t\tmoduleManger.add({ path: sourceFile.fileName, classes });\n\t\t\t\tconst statements = updateSourceFile.statements?.slice() ?? [];\n\t\t\t\tstatements.push(createConstructorOfViewInterfaceDeclaration());\n\t\t\t\tconst interfaces = classes.flatMap(s => s.views).map(info => {\n\t\t\t\t\treturn ts.setTextRange(info.interFaceType, updateSourceFile);\n\t\t\t\t});\n\t\t\t\tstatements.push(...interfaces);\n\t\t\t\treturn ts.factory.updateSourceFile(\n\t\t\t\t\tsourceFile,\n\t\t\t\t\tstatements,\n\t\t\t\t\tupdateSourceFile.isDeclarationFile,\n\t\t\t\t\tupdateSourceFile.typeReferenceDirectives,\n\t\t\t\t\tupdateSourceFile.referencedFiles,\n\t\t\t\t\tupdateSourceFile.hasNoDefaultLib,\n\t\t\t\t\tupdateSourceFile.libReferenceDirectives,\n\t\t\t\t);\n\t\t\t}\n\t\t\tmoduleManger.add({ path: sourceFile.fileName, skip: true });\n\t\t\treturn updateSourceFile;\n\t\t};\n\t};\n}\n\nexport function isInputDecorator(decorator: ts.Decorator): boolean {\n\treturn ts.isCallExpression(decorator.expression) && (\n\t\tdecorator.expression.expression.getText() === 'Input'\n\t\t|| decorator.expression.expression.getText() === 'FormValue'\n\t);\n}\n\nexport function isOutputDecorator(decorator: ts.Decorator): boolean {\n\treturn ts.isCallExpression(decorator.expression) && decorator.expression.expression.getText() === 'Output';\n}\n\nexport function getMapByDecorator(classNode: ts.ClassDeclaration, checker: ts.TypeChecker, decoratorFilter: ((decorator: ts.Decorator) => boolean)): InputOutputTypeInfo {\n\n\tconst map: InputOutputTypeInfo = {};\n\tclassNode.members.forEach(member => {\n\t\tif (!ts.isPropertyDeclaration(member)) {\n\t\t\treturn;\n\t\t}\n\t\tconst decorators = ts.getDecorators(member);\n\t\tif (!decorators) {\n\t\t\treturn;\n\t\t}\n\t\tconst inputDecorators = decorators.filter(decoratorFilter);\n\t\tif (!inputDecorators.length) {\n\t\t\treturn;\n\t\t}\n\t\tlet inputType = member.type?.getText();\n\t\tif (!inputType && member.initializer) {\n\t\t\tinputType = checker.typeToString(checker.getTypeAtLocation(member.initializer), member.initializer, undefined);\n\t\t}\n\t\tinputDecorators.forEach(input => {\n\t\t\tconst decoratorCall = input.expression as ts.CallExpression;\n\t\t\tconst aliasName = decoratorCall.arguments[0] as ts.StringLiteralLike;\n\t\t\tconst inputName = aliasName ? aliasName.text : member.name.getText();\n\t\t\tmap[inputName] = inputType;\n\t\t});\n\t})\n\treturn map;\n}\n\nexport function getInputs(classNode: ts.ClassDeclaration, checker: ts.TypeChecker): InputOutputTypeInfo {\n\n\treturn getMapByDecorator(classNode, checker, isInputDecorator);\n}\n\nexport function getOutputs(classNode: ts.ClassDeclaration, checker: ts.TypeChecker): InputOutputTypeInfo {\n\treturn getMapByDecorator(classNode, checker, isOutputDecorator);\n}\n\nexport default beforeCompileComponentOptions;\n"]}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import ts from 'typescript/lib/tsserverlibrary.js';
|
|
2
|
+
import { ClassInfo } from './modules.js';
|
|
3
|
+
export declare function convertToProperties(json: {
|
|
4
|
+
[key: string]: any;
|
|
5
|
+
}): ts.ObjectLiteralElementLike[];
|
|
6
|
+
export declare function createProperty(name: string, value: any): ts.ObjectLiteralElementLike;
|
|
7
|
+
export declare function createInitializer(value: any): ts.Expression;
|
|
8
|
+
export declare function createInterfaceType(viewName: string, extendsType: string): ts.InterfaceDeclaration;
|
|
9
|
+
export declare function createTypeLiteral(typeName: string): ts.TypeLiteralNode;
|
|
10
|
+
/**
|
|
11
|
+
* create view constructor interface of Type `T`
|
|
12
|
+
*
|
|
13
|
+
* ```ts
|
|
14
|
+
* interface ConstructorOfView<T> {
|
|
15
|
+
* new(): T;
|
|
16
|
+
* readonly prototype: T;
|
|
17
|
+
* }
|
|
18
|
+
* ```
|
|
19
|
+
*/
|
|
20
|
+
export declare function createConstructorOfViewInterfaceDeclaration(): ts.InterfaceDeclaration;
|
|
21
|
+
export declare function createStaticPropertyViewType(typeName: string): ts.TypeReferenceNode;
|
|
22
|
+
export declare function generateStatements(sourceText: string, scriptTarget?: ts.ScriptTarget, scriptKind?: ts.ScriptKind): ts.NodeArray<ts.Statement>;
|
|
23
|
+
export declare function generateNode<T = ts.Node>(sourceText: string, scriptTarget?: ts.ScriptTarget, scriptKind?: ts.ScriptKind): T;
|
|
24
|
+
/**
|
|
25
|
+
* declare global {
|
|
26
|
+
interface HTMLElementTagNameMap {
|
|
27
|
+
'user-view': HTMLUserViewElement;
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
*/
|
|
31
|
+
export declare function updateGlobalHTMLElementTagNameMap(views: {
|
|
32
|
+
tagName: string;
|
|
33
|
+
viewName: string;
|
|
34
|
+
}[]): ts.NodeArray<ts.Statement>;
|
|
35
|
+
export declare function updateModule(classes: ClassInfo[]): ts.NodeArray<ts.Statement>;
|
|
@@ -0,0 +1,124 @@
|
|
|
1
|
+
import ts from 'typescript/lib/tsserverlibrary.js';
|
|
2
|
+
import { ToCamelCase } from '@ibyar/core/node.js';
|
|
3
|
+
export function convertToProperties(json) {
|
|
4
|
+
const keys = Object.keys(json);
|
|
5
|
+
return keys.map(key => createProperty(key, json[key]));
|
|
6
|
+
}
|
|
7
|
+
export function createProperty(name, value) {
|
|
8
|
+
return ts.factory.createPropertyAssignment(name, createInitializer(value));
|
|
9
|
+
}
|
|
10
|
+
export function createInitializer(value) {
|
|
11
|
+
if (Array.isArray(value)) {
|
|
12
|
+
const elements = value.map(createInitializer);
|
|
13
|
+
return ts.factory.createArrayLiteralExpression(elements);
|
|
14
|
+
}
|
|
15
|
+
switch (typeof value) {
|
|
16
|
+
case 'string': return ts.factory.createStringLiteral(value);
|
|
17
|
+
case 'number': return ts.factory.createNumericLiteral(value);
|
|
18
|
+
case 'bigint': return ts.factory.createBigIntLiteral(value.toString());
|
|
19
|
+
case 'boolean': return value ? ts.factory.createTrue() : ts.factory.createFalse();
|
|
20
|
+
case 'object':
|
|
21
|
+
{
|
|
22
|
+
if (!value) {
|
|
23
|
+
return ts.factory.createNull();
|
|
24
|
+
}
|
|
25
|
+
const properties = convertToProperties(value);
|
|
26
|
+
return ts.factory.createObjectLiteralExpression(properties);
|
|
27
|
+
}
|
|
28
|
+
;
|
|
29
|
+
}
|
|
30
|
+
return ts.factory.createNull();
|
|
31
|
+
}
|
|
32
|
+
export function createInterfaceType(viewName, extendsType) {
|
|
33
|
+
const identifier = ts.factory.createIdentifier(extendsType);
|
|
34
|
+
const expressionWithTypeArguments = ts.factory.createExpressionWithTypeArguments(identifier, undefined);
|
|
35
|
+
const heritageClause = ts.factory.createHeritageClause(ts.SyntaxKind.ExtendsKeyword, [expressionWithTypeArguments]);
|
|
36
|
+
return ts.factory.createInterfaceDeclaration(undefined, viewName, undefined, [heritageClause], []);
|
|
37
|
+
// const exportModifier: ts.ModifierSyntaxKind = ts.SyntaxKind.ExportKeyword;
|
|
38
|
+
// const modifier = ts.factory.createModifier(exportModifier);
|
|
39
|
+
// return ts.factory.createInterfaceDeclaration([modifier], viewName, undefined, [heritageClause], []);
|
|
40
|
+
}
|
|
41
|
+
export function createTypeLiteral(typeName) {
|
|
42
|
+
const members = [
|
|
43
|
+
ts.factory.createConstructSignature(undefined, [], ts.factory.createTypeReferenceNode(typeName)),
|
|
44
|
+
ts.factory.createPropertySignature([ts.factory.createModifier(ts.SyntaxKind.ReadonlyKeyword)], 'prototype', undefined, ts.factory.createTypeReferenceNode(typeName)),
|
|
45
|
+
];
|
|
46
|
+
return ts.factory.createTypeLiteralNode(members);
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* create view constructor interface of Type `T`
|
|
50
|
+
*
|
|
51
|
+
* ```ts
|
|
52
|
+
* interface ConstructorOfView<T> {
|
|
53
|
+
* new(): T;
|
|
54
|
+
* readonly prototype: T;
|
|
55
|
+
* }
|
|
56
|
+
* ```
|
|
57
|
+
*/
|
|
58
|
+
export function createConstructorOfViewInterfaceDeclaration() {
|
|
59
|
+
const typeParameter = ts.factory.createTypeParameterDeclaration(undefined, 'T');
|
|
60
|
+
const members = [
|
|
61
|
+
ts.factory.createConstructSignature(undefined, [], ts.factory.createTypeReferenceNode('T')),
|
|
62
|
+
ts.factory.createPropertySignature([ts.factory.createModifier(ts.SyntaxKind.ReadonlyKeyword)], 'prototype', undefined, ts.factory.createTypeReferenceNode('T')),
|
|
63
|
+
];
|
|
64
|
+
return ts.factory.createInterfaceDeclaration(undefined, 'ConstructorOfView', [typeParameter], undefined, members);
|
|
65
|
+
}
|
|
66
|
+
export function createStaticPropertyViewType(typeName) {
|
|
67
|
+
const typeArgument = ts.factory.createTypeReferenceNode(typeName);
|
|
68
|
+
return ts.factory.createTypeReferenceNode('ConstructorOfView', [typeArgument]);
|
|
69
|
+
}
|
|
70
|
+
export function generateStatements(sourceText, scriptTarget = ts.ScriptTarget.ES2020, scriptKind = ts.ScriptKind.TS) {
|
|
71
|
+
return ts.createSourceFile('temp', sourceText, scriptTarget, false, scriptKind).statements;
|
|
72
|
+
}
|
|
73
|
+
export function generateNode(sourceText, scriptTarget = ts.ScriptTarget.ES2020, scriptKind = ts.ScriptKind.TS) {
|
|
74
|
+
return generateStatements(sourceText, scriptTarget, scriptKind)[0];
|
|
75
|
+
}
|
|
76
|
+
/**
|
|
77
|
+
* declare global {
|
|
78
|
+
interface HTMLElementTagNameMap {
|
|
79
|
+
'user-view': HTMLUserViewElement;
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
*/
|
|
83
|
+
export function updateGlobalHTMLElementTagNameMap(views) {
|
|
84
|
+
const sourceCode = `
|
|
85
|
+
declare global {
|
|
86
|
+
interface HTMLElementTagNameMap {
|
|
87
|
+
${views.map(view => `['${view.tagName}']: ${view.viewName};`).join('\n')}
|
|
88
|
+
}
|
|
89
|
+
}`;
|
|
90
|
+
return generateStatements(sourceCode);
|
|
91
|
+
}
|
|
92
|
+
export function updateModule(classes) {
|
|
93
|
+
const viewClassDeclarations = classes.map(c => {
|
|
94
|
+
const inputs = Object.keys(c.inputs);
|
|
95
|
+
const outputs = Object.keys(c.outputs).map(output => 'on' + ToCamelCase(output));
|
|
96
|
+
const attributes = [...inputs, ...outputs].map(s => `'${s}'`).join(' | ');
|
|
97
|
+
const interfaceBody = `
|
|
98
|
+
public static observedAttributes: ${attributes}[];
|
|
99
|
+
|
|
100
|
+
${inputs.map(input => `public ${input}: ${c.inputs[input]};`).join('\n')}
|
|
101
|
+
|
|
102
|
+
${Object.keys(c.outputs).map(output => `public on${ToCamelCase(output)}: ${c.outputs[output]};`).join('\n')}
|
|
103
|
+
|
|
104
|
+
`;
|
|
105
|
+
// need to fix @FormValue type;
|
|
106
|
+
return c.views.map(view => `
|
|
107
|
+
declare class ${view.viewName} extends ${view.extendsType} {
|
|
108
|
+
${interfaceBody.trim()}
|
|
109
|
+
}
|
|
110
|
+
declare interface ${view.viewName} extends ${view.formAssociated ? `BaseFormAssociatedComponent<${c.name}>, ` : ''}BaseComponent<${c.name}> {}
|
|
111
|
+
`);
|
|
112
|
+
});
|
|
113
|
+
const views = classes.flatMap(c => c.views.map(v => ({ tagName: v.selector, viewName: v.viewName })));
|
|
114
|
+
const sourceCode = `
|
|
115
|
+
import { BaseComponent, BaseFormAssociatedComponent, ConstructorOfView } from '@ibyar/core';
|
|
116
|
+
${viewClassDeclarations.join('\n')}
|
|
117
|
+
declare global {
|
|
118
|
+
interface HTMLElementTagNameMap {
|
|
119
|
+
${views.map(view => `['${view.tagName}']: ${view.viewName};`).join('\n')}
|
|
120
|
+
}
|
|
121
|
+
}`;
|
|
122
|
+
return generateStatements(sourceCode);
|
|
123
|
+
}
|
|
124
|
+
//# sourceMappingURL=factory.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"factory.js","sourceRoot":"","sources":["../../../src/cli/transformer/factory.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,mCAAmC,CAAC;AACnD,OAAO,EAAE,WAAW,EAAE,MAAM,qBAAqB,CAAC;AAIlD,MAAM,UAAU,mBAAmB,CAAC,IAA4B;IAC/D,MAAM,IAAI,GAAG,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;IAC/B,OAAO,IAAI,CAAC,GAAG,CAAC,GAAG,CAAC,EAAE,CAAC,cAAc,CAAC,GAAG,EAAE,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC;AACxD,CAAC;AAED,MAAM,UAAU,cAAc,CAAC,IAAY,EAAE,KAAU;IACtD,OAAO,EAAE,CAAC,OAAO,CAAC,wBAAwB,CAAC,IAAI,EAAE,iBAAiB,CAAC,KAAK,CAAC,CAAC,CAAC;AAC5E,CAAC;AAED,MAAM,UAAU,iBAAiB,CAAC,KAAU;IAC3C,IAAI,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,EAAE;QACzB,MAAM,QAAQ,GAAG,KAAK,CAAC,GAAG,CAAC,iBAAiB,CAAC,CAAC;QAC9C,OAAO,EAAE,CAAC,OAAO,CAAC,4BAA4B,CAAC,QAAQ,CAAC,CAAC;KACzD;IACD,QAAQ,OAAO,KAAK,EAAE;QACrB,KAAK,QAAQ,CAAC,CAAC,OAAO,EAAE,CAAC,OAAO,CAAC,mBAAmB,CAAC,KAAK,CAAC,CAAC;QAC5D,KAAK,QAAQ,CAAC,CAAC,OAAO,EAAE,CAAC,OAAO,CAAC,oBAAoB,CAAC,KAAK,CAAC,CAAC;QAC7D,KAAK,QAAQ,CAAC,CAAC,OAAO,EAAE,CAAC,OAAO,CAAC,mBAAmB,CAAC,KAAK,CAAC,QAAQ,EAAE,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IAAI,CAAC,QAAQ,GAAG,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC;;IAExE,CAAC;IACJ,OAAO,kBAAkB,CAAC,UAAU,CAAC,CAAC;AACvC,CAAC","sourcesContent":["import ts from 'typescript/lib/tsserverlibrary.js';\nimport { ToCamelCase } from '@ibyar/core/node.js';\nimport { ClassInfo } from './modules.js';\n\n\nexport function convertToProperties(json: { [key: string]: any }): ts.ObjectLiteralElementLike[] {\n\tconst keys = Object.keys(json);\n\treturn keys.map(key => createProperty(key, json[key]));\n}\n\nexport function createProperty(name: string, value: any): ts.ObjectLiteralElementLike {\n\treturn ts.factory.createPropertyAssignment(name, createInitializer(value));\n}\n\nexport function createInitializer(value: any): ts.Expression {\n\tif (Array.isArray(value)) {\n\t\tconst elements = value.map(createInitializer);\n\t\treturn ts.factory.createArrayLiteralExpression(elements);\n\t}\n\tswitch (typeof value) {\n\t\tcase 'string': return ts.factory.createStringLiteral(value);\n\t\tcase 'number': return ts.factory.createNumericLiteral(value);\n\t\tcase 'bigint': return ts.factory.createBigIntLiteral(value.toString());\n\t\tcase 'boolean': return value ? ts.factory.createTrue() : ts.factory.createFalse();\n\t\tcase 'object': {\n\t\t\tif (!value) {\n\t\t\t\treturn ts.factory.createNull();\n\t\t\t}\n\t\t\tconst properties = convertToProperties(value);\n\t\t\treturn ts.factory.createObjectLiteralExpression(properties);\n\t\t};\n\t}\n\treturn ts.factory.createNull();\n}\n\n\nexport function createInterfaceType(viewName: string, extendsType: string) {\n\tconst identifier = ts.factory.createIdentifier(extendsType);\n\tconst expressionWithTypeArguments = ts.factory.createExpressionWithTypeArguments(identifier, undefined);\n\tconst heritageClause = ts.factory.createHeritageClause(ts.SyntaxKind.ExtendsKeyword, [expressionWithTypeArguments]);\n\treturn ts.factory.createInterfaceDeclaration(undefined, viewName, undefined, [heritageClause], []);\n\t// const exportModifier: ts.ModifierSyntaxKind = ts.SyntaxKind.ExportKeyword;\n\t// const modifier = ts.factory.createModifier(exportModifier);\n\t// return ts.factory.createInterfaceDeclaration([modifier], viewName, undefined, [heritageClause], []);\n}\n\nexport function createTypeLiteral(typeName: string) {\n\tconst members: ts.TypeElement[] = [\n\t\tts.factory.createConstructSignature(undefined, [], ts.factory.createTypeReferenceNode(typeName)),\n\t\tts.factory.createPropertySignature(\n\t\t\t[ts.factory.createModifier(ts.SyntaxKind.ReadonlyKeyword)],\n\t\t\t'prototype',\n\t\t\tundefined,\n\t\t\tts.factory.createTypeReferenceNode(typeName)\n\t\t),\n\t];\n\treturn ts.factory.createTypeLiteralNode(members);\n}\n\n/**\n * create view constructor interface of Type `T`\n * \n * ```ts\n * interface ConstructorOfView<T> {\n * \tnew(): T;\n * \treadonly prototype: T;\n * }\n * ```\n */\nexport function createConstructorOfViewInterfaceDeclaration() {\n\tconst typeParameter = ts.factory.createTypeParameterDeclaration(undefined, 'T');\n\tconst members: ts.TypeElement[] = [\n\t\tts.factory.createConstructSignature(undefined, [], ts.factory.createTypeReferenceNode('T')),\n\t\tts.factory.createPropertySignature(\n\t\t\t[ts.factory.createModifier(ts.SyntaxKind.ReadonlyKeyword)],\n\t\t\t'prototype',\n\t\t\tundefined,\n\t\t\tts.factory.createTypeReferenceNode('T')\n\t\t),\n\t];\n\treturn ts.factory.createInterfaceDeclaration(undefined, 'ConstructorOfView', [typeParameter], undefined, members);\n}\n\nexport function createStaticPropertyViewType(typeName: string) {\n\tconst typeArgument = ts.factory.createTypeReferenceNode(typeName);\n\treturn ts.factory.createTypeReferenceNode('ConstructorOfView', [typeArgument]);\n}\n\n\nexport function generateStatements(sourceText: string, scriptTarget = ts.ScriptTarget.ES2020, scriptKind = ts.ScriptKind.TS): ts.NodeArray<ts.Statement> {\n\treturn ts.createSourceFile('temp', sourceText, scriptTarget, false, scriptKind).statements;\n}\n\nexport function generateNode<T = ts.Node>(sourceText: string, scriptTarget = ts.ScriptTarget.ES2020, scriptKind = ts.ScriptKind.TS): T {\n\treturn generateStatements(sourceText, scriptTarget, scriptKind)[0] as T;\n}\n\n/**\n * declare global {\n\tinterface HTMLElementTagNameMap {\n\t\t'user-view': HTMLUserViewElement;\n\t}\n}\n */\n\nexport function updateGlobalHTMLElementTagNameMap(views: { tagName: string, viewName: string }[]): ts.NodeArray<ts.Statement> {\n\tconst sourceCode = `\n\t\tdeclare global {\n\t\t\tinterface HTMLElementTagNameMap {\n\t\t\t\t${views.map(view => `['${view.tagName}']: ${view.viewName};`).join('\\n')}\n\t\t\t}\n\t\t}`;\n\treturn generateStatements(sourceCode);\n}\n\nexport function updateModule(classes: ClassInfo[]): ts.NodeArray<ts.Statement> {\n\n\tconst viewClassDeclarations = classes.map(c => {\n\t\tconst inputs = Object.keys(c.inputs);\n\t\tconst outputs = Object.keys(c.outputs).map(output => 'on' + ToCamelCase(output));\n\t\tconst attributes = [...inputs, ...outputs].map(s => `'${s}'`).join(' | ');\n\t\tconst interfaceBody = `\n\t\t\tpublic static observedAttributes: ${attributes}[];\n\n\t\t\t${inputs.map(input => `public ${input}: ${c.inputs[input]};`).join('\\n')}\n\n\t\t\t${Object.keys(c.outputs).map(output => `public on${ToCamelCase(output)}: ${c.outputs[output]};`).join('\\n')}\n\t\t\t\n\t\t`;\n\t\t// need to fix @FormValue type;\n\t\treturn c.views.map(view => `\n\t\t\tdeclare class ${view.viewName} extends ${view.extendsType} {\n\t\t\t\t${interfaceBody.trim()}\n\t\t\t}\n\t\t\tdeclare interface ${view.viewName} extends ${view.formAssociated ? `BaseFormAssociatedComponent<${c.name}>, ` : ''}BaseComponent<${c.name}> {}\n\t\t`);\n\t});\n\tconst views = classes.flatMap(c => c.views.map(v => ({ tagName: v.selector, viewName: v.viewName })));\n\tconst sourceCode = `\n\t\timport { BaseComponent, BaseFormAssociatedComponent, ConstructorOfView } from '@ibyar/core';\n\t\t${viewClassDeclarations.join('\\n')}\n\t\tdeclare global {\n\t\t\tinterface HTMLElementTagNameMap {\n\t\t\t\t${views.map(view => `['${view.tagName}']: ${view.viewName};`).join('\\n')}\n\t\t\t}\n\t\t}`;\n\treturn generateStatements(sourceCode);\n}"]}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
export declare type ViewInfo = {
|
|
2
|
+
selector: string;
|
|
3
|
+
extendsType: string;
|
|
4
|
+
viewName: string;
|
|
5
|
+
interFaceType: ts.InterfaceDeclaration;
|
|
6
|
+
formAssociated: boolean;
|
|
7
|
+
};
|
|
8
|
+
export declare type InputOutputTypeInfo = {
|
|
9
|
+
[name: string]: string | undefined;
|
|
10
|
+
};
|
|
11
|
+
export declare type ClassInfo = {
|
|
12
|
+
name: string;
|
|
13
|
+
views: ViewInfo[];
|
|
14
|
+
inputs: InputOutputTypeInfo;
|
|
15
|
+
outputs: InputOutputTypeInfo;
|
|
16
|
+
};
|
|
17
|
+
export declare type ModuleInfo = {
|
|
18
|
+
path: string;
|
|
19
|
+
skip: true;
|
|
20
|
+
} | {
|
|
21
|
+
path: string;
|
|
22
|
+
skip?: false;
|
|
23
|
+
classes?: ClassInfo[];
|
|
24
|
+
};
|
|
25
|
+
declare class ModuleManger implements Map<string, ModuleInfo> {
|
|
26
|
+
[Symbol.iterator](): IterableIterator<[string, ModuleInfo]>;
|
|
27
|
+
[Symbol.toStringTag]: string;
|
|
28
|
+
get size(): number;
|
|
29
|
+
private map;
|
|
30
|
+
add(info: ModuleInfo): void;
|
|
31
|
+
clear(): void;
|
|
32
|
+
delete(key: string): boolean;
|
|
33
|
+
forEach(callbackfn: (value: ModuleInfo, key: string, map: Map<string, ModuleInfo>) => void, thisArg?: any): void;
|
|
34
|
+
get(key: string): ModuleInfo | undefined;
|
|
35
|
+
has(key: string): boolean;
|
|
36
|
+
set(key: string, value: ModuleInfo): this;
|
|
37
|
+
entries(): IterableIterator<[string, ModuleInfo]>;
|
|
38
|
+
keys(): IterableIterator<string>;
|
|
39
|
+
values(): IterableIterator<ModuleInfo>;
|
|
40
|
+
}
|
|
41
|
+
export declare const moduleManger: ModuleManger;
|
|
42
|
+
export {};
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
var _a;
|
|
2
|
+
class ModuleManger {
|
|
3
|
+
constructor() {
|
|
4
|
+
this[_a] = 'Module Info';
|
|
5
|
+
this.map = new Map();
|
|
6
|
+
}
|
|
7
|
+
[Symbol.iterator]() {
|
|
8
|
+
return this.map[Symbol.iterator]();
|
|
9
|
+
}
|
|
10
|
+
get size() {
|
|
11
|
+
return this.map.size;
|
|
12
|
+
}
|
|
13
|
+
add(info) {
|
|
14
|
+
this.map.set(info.path, info);
|
|
15
|
+
}
|
|
16
|
+
clear() {
|
|
17
|
+
this.map.clear();
|
|
18
|
+
}
|
|
19
|
+
delete(key) {
|
|
20
|
+
return this.map.delete(key);
|
|
21
|
+
}
|
|
22
|
+
forEach(callbackfn, thisArg) {
|
|
23
|
+
this.map.forEach(callbackfn, thisArg);
|
|
24
|
+
}
|
|
25
|
+
get(key) {
|
|
26
|
+
return this.map.get(key);
|
|
27
|
+
}
|
|
28
|
+
has(key) {
|
|
29
|
+
return this.map.has(key);
|
|
30
|
+
}
|
|
31
|
+
set(key, value) {
|
|
32
|
+
this.map.set(key, value);
|
|
33
|
+
return this;
|
|
34
|
+
}
|
|
35
|
+
entries() {
|
|
36
|
+
return this.map.entries();
|
|
37
|
+
}
|
|
38
|
+
keys() {
|
|
39
|
+
return this.map.keys();
|
|
40
|
+
}
|
|
41
|
+
values() {
|
|
42
|
+
return this.map.values();
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
_a = Symbol.toStringTag;
|
|
46
|
+
export const moduleManger = new ModuleManger();
|
|
47
|
+
//# sourceMappingURL=modules.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"modules.js","sourceRoot":"","sources":["../../../src/cli/transformer/modules.ts"],"names":[],"mappings":";AAsBA,MAAM,YAAY;IAAlB;QAIC,QAAoB,GAAW,aAAa,CAAC;QAMrC,QAAG,GAAG,IAAI,GAAG,EAAsB,CAAC;IAiC7C,CAAC;IA1CA,CAAC,MAAM,CAAC,QAAQ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I,YAAY,EAAE,CAAC","sourcesContent":["\nexport type ViewInfo = {\n\tselector: string;\n\textendsType: string;\n\tviewName: string;\n\tinterFaceType: ts.InterfaceDeclaration;\n\tformAssociated: boolean;\n};\n\nexport type InputOutputTypeInfo = { [name: string]: string | undefined };\n\nexport type ClassInfo = {\n\tname: string,\n\tviews: ViewInfo[];\n\tinputs: InputOutputTypeInfo;\n\toutputs: InputOutputTypeInfo;\n};\n\nexport type ModuleInfo =\n\t| { path: string; skip: true; }\n\t| { path: string; skip?: false; classes?: ClassInfo[]; }\n\nclass ModuleManger implements Map<string, ModuleInfo> {\n\t[Symbol.iterator](): IterableIterator<[string, ModuleInfo]> {\n\t\treturn this.map[Symbol.iterator]();\n\t}\n\t[Symbol.toStringTag]: string = 'Module Info';\n\n\tget size(): number {\n\t\treturn this.map.size;\n\t}\n\n\tprivate map = new Map<string, ModuleInfo>();\n\n\tadd(info: ModuleInfo) {\n\t\tthis.map.set(info.path, info);\n\t}\n\tclear(): void {\n\t\tthis.map.clear();\n\t}\n\tdelete(key: string): boolean {\n\t\treturn this.map.delete(key);\n\t}\n\tforEach(callbackfn: (value: ModuleInfo, key: string, map: Map<string, ModuleInfo>) => void, thisArg?: any): void {\n\t\tthis.map.forEach(callbackfn, thisArg);\n\t}\n\tget(key: string): ModuleInfo | undefined {\n\t\treturn this.map.get(key);\n\t}\n\thas(key: string): boolean {\n\t\treturn this.map.has(key);\n\t}\n\tset(key: string, value: ModuleInfo): this {\n\t\tthis.map.set(key, value);\n\t\treturn this;\n\t}\n\tentries(): IterableIterator<[string, ModuleInfo]> {\n\t\treturn this.map.entries();\n\t}\n\tkeys(): IterableIterator<string> {\n\t\treturn this.map.keys();\n\t}\n\tvalues(): IterableIterator<ModuleInfo> {\n\t\treturn this.map.values();\n\t}\n}\n\nexport const moduleManger = new ModuleManger();\n"]}
|