@htmlplus/element 0.3.1 → 0.4.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 -2
- package/client/decorators/attributes.d.ts +2 -0
- package/client/decorators/attributes.js +13 -0
- package/client/decorators/bind.d.ts +4 -0
- package/client/decorators/bind.js +17 -0
- package/client/decorators/element.d.ts +2 -0
- package/client/decorators/element.js +53 -0
- package/client/decorators/event.d.ts +21 -0
- package/client/decorators/event.js +17 -0
- package/client/decorators/index.d.ts +9 -0
- package/client/decorators/index.js +9 -0
- package/client/decorators/listen.d.ts +12 -0
- package/client/decorators/listen.js +31 -0
- package/client/decorators/method.d.ts +2 -0
- package/client/decorators/method.js +11 -0
- package/client/decorators/property.d.ts +8 -0
- package/client/decorators/property.js +45 -0
- package/client/decorators/state.d.ts +2 -0
- package/client/decorators/state.js +23 -0
- package/client/decorators/watch.d.ts +8 -0
- package/client/decorators/watch.js +34 -0
- package/client/helpers/classes.d.ts +1 -0
- package/client/helpers/classes.js +62 -0
- package/client/helpers/direction.d.ts +3 -0
- package/client/helpers/direction.js +4 -0
- package/client/helpers/index.d.ts +9 -0
- package/client/helpers/index.js +9 -0
- package/client/helpers/isRTL.d.ts +2 -0
- package/client/helpers/isRTL.js +2 -0
- package/client/helpers/query.d.ts +3 -0
- package/client/helpers/query.js +5 -0
- package/client/helpers/queryAll.d.ts +3 -0
- package/client/helpers/queryAll.js +5 -0
- package/client/helpers/slots.d.ts +6 -0
- package/client/helpers/slots.js +15 -0
- package/client/helpers/styles.d.ts +1 -0
- package/client/helpers/styles.js +17 -0
- package/client/helpers/toUnit.d.ts +1 -0
- package/client/helpers/toUnit.js +7 -0
- package/client/index.d.ts +3 -0
- package/client/index.js +3 -0
- package/client/services/index.d.ts +1 -0
- package/client/services/index.js +1 -0
- package/client/services/link.d.ts +4 -0
- package/client/services/link.js +196 -0
- package/client/utils/appendToMethod.d.ts +2 -0
- package/client/utils/appendToMethod.js +7 -0
- package/client/utils/call.d.ts +2 -0
- package/client/utils/call.js +4 -0
- package/client/utils/defineProperty.d.ts +1 -0
- package/client/utils/defineProperty.js +1 -0
- package/client/utils/event.d.ts +5 -0
- package/client/utils/event.js +9 -0
- package/client/utils/getMembers.d.ts +2 -0
- package/client/utils/getMembers.js +5 -0
- package/client/utils/getStyles.d.ts +2 -0
- package/client/utils/getStyles.js +5 -0
- package/client/utils/host.d.ts +2 -0
- package/client/utils/host.js +4 -0
- package/client/utils/index.d.ts +17 -0
- package/client/utils/index.js +17 -0
- package/client/utils/isEvent.d.ts +1 -0
- package/client/utils/isEvent.js +3 -0
- package/client/utils/isServer.d.ts +1 -0
- package/client/utils/isServer.js +3 -0
- package/client/utils/parseValue.d.ts +1 -0
- package/client/utils/parseValue.js +15 -0
- package/client/utils/request.d.ts +4 -0
- package/client/utils/request.js +38 -0
- package/client/utils/sync.d.ts +1 -0
- package/client/utils/sync.js +31 -0
- package/client/utils/task.d.ts +6 -0
- package/client/utils/task.js +37 -0
- package/client/utils/toBoolean.d.ts +1 -0
- package/client/utils/toBoolean.js +3 -0
- package/client/utils/toEvent.d.ts +1 -0
- package/client/utils/toEvent.js +3 -0
- package/client/utils/typeOf.d.ts +3 -0
- package/client/utils/typeOf.js +6 -0
- package/client/utils/updateAttribute.d.ts +1 -0
- package/client/utils/updateAttribute.js +7 -0
- package/client/vendor/uhtml.d.ts +22 -0
- package/client/vendor/uhtml.js +700 -0
- package/compiler/compiler.d.ts +7 -0
- package/compiler/compiler.js +72 -0
- package/compiler/index.d.ts +2 -0
- package/compiler/index.js +2 -0
- package/compiler/plugins/customElement.d.ts +8 -0
- package/compiler/plugins/customElement.js +157 -0
- package/compiler/plugins/customElementReact/customElementReact.d.ts +12 -0
- package/compiler/plugins/customElementReact/customElementReact.js +129 -0
- package/compiler/plugins/customElementReact/index.d.ts +1 -0
- package/compiler/plugins/customElementReact/index.js +1 -0
- package/compiler/plugins/customElementReact/templates/README.md.hbs +1 -0
- package/compiler/plugins/customElementReact/templates/_.gitignore.hbs +2 -0
- package/compiler/plugins/customElementReact/templates/package.json.hbs +37 -0
- package/compiler/plugins/customElementReact/templates/rollup.config.js.hbs +21 -0
- package/compiler/plugins/customElementReact/templates/src/components/index.ts.hbs +17 -0
- package/compiler/plugins/customElementReact/templates/src/components/{{fileName}}.compact.ts.hbs +18 -0
- package/compiler/plugins/customElementReact/templates/src/components/{{fileName}}.ts.hbs +26 -0
- package/compiler/plugins/customElementReact/templates/src/index.ts.hbs +1 -0
- package/compiler/plugins/customElementReact/templates/src/proxy.ts.hbs +278 -0
- package/compiler/plugins/customElementReact/templates/tsconfig.json.hbs +17 -0
- package/compiler/plugins/document.d.ts +10 -0
- package/compiler/plugins/document.js +254 -0
- package/compiler/plugins/external.d.ts +9 -0
- package/compiler/plugins/external.js +25 -0
- package/compiler/plugins/extract.d.ts +8 -0
- package/compiler/plugins/extract.js +62 -0
- package/compiler/plugins/index.d.ts +9 -0
- package/compiler/plugins/index.js +9 -0
- package/compiler/plugins/parse.d.ts +5 -0
- package/compiler/plugins/parse.js +16 -0
- package/compiler/plugins/read.d.ts +5 -0
- package/compiler/plugins/read.js +13 -0
- package/compiler/plugins/style.d.ts +10 -0
- package/compiler/plugins/style.js +36 -0
- package/compiler/plugins/validate.d.ts +5 -0
- package/compiler/plugins/validate.js +40 -0
- package/compiler/plugins/vscode.d.ts +11 -0
- package/compiler/plugins/vscode.js +83 -0
- package/compiler/utils/__dirname.d.ts +1 -0
- package/compiler/utils/__dirname.js +5 -0
- package/compiler/utils/getInitializer.d.ts +2 -0
- package/compiler/utils/getInitializer.js +10 -0
- package/compiler/utils/getType.d.ts +2 -0
- package/compiler/utils/getType.js +69 -0
- package/compiler/utils/getTypeReference.d.ts +2 -0
- package/compiler/utils/getTypeReference.js +33 -0
- package/compiler/utils/hasDecorator.d.ts +1 -0
- package/compiler/utils/hasDecorator.js +5 -0
- package/compiler/utils/index.d.ts +11 -0
- package/compiler/utils/index.js +11 -0
- package/compiler/utils/isDirectoryEmpty.d.ts +1 -0
- package/compiler/utils/isDirectoryEmpty.js +10 -0
- package/compiler/utils/print.d.ts +2 -0
- package/compiler/utils/print.js +5 -0
- package/compiler/utils/printType.d.ts +1 -0
- package/compiler/utils/printType.js +69 -0
- package/compiler/utils/renderTemplate.d.ts +1 -0
- package/compiler/utils/renderTemplate.js +25 -0
- package/compiler/utils/tags.d.ts +13 -0
- package/compiler/utils/tags.js +53 -0
- package/compiler/utils/visitor.d.ts +2 -0
- package/compiler/utils/visitor.js +5 -0
- package/constants/index.d.ts +22 -0
- package/constants/index.js +28 -0
- package/package.json +14 -17
- package/types/context.d.ts +38 -0
- package/types/context.js +1 -0
- package/types/global.d.ts +4 -0
- package/types/global.js +1 -0
- package/types/index.d.ts +4 -0
- package/types/index.js +4 -0
- package/types/plugin.d.ts +10 -0
- package/types/plugin.js +1 -0
- package/types/plusElement.d.ts +2 -0
- package/types/plusElement.js +1 -0
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { parse as parser } from '@babel/parser';
|
|
2
|
+
export const parse = () => {
|
|
3
|
+
const name = 'parse';
|
|
4
|
+
const next = (context) => {
|
|
5
|
+
if (!!context.fileAST)
|
|
6
|
+
return;
|
|
7
|
+
context.fileAST = parser(context.fileContent, {
|
|
8
|
+
allowImportExportEverywhere: true,
|
|
9
|
+
plugins: ['jsx', 'typescript', 'decorators-legacy']
|
|
10
|
+
});
|
|
11
|
+
};
|
|
12
|
+
return {
|
|
13
|
+
name,
|
|
14
|
+
next
|
|
15
|
+
};
|
|
16
|
+
};
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { Context } from '../../types/index.js';
|
|
2
|
+
export declare type StyleOptions = {
|
|
3
|
+
extensions?: Array<string>;
|
|
4
|
+
directory?: (context: Context) => string;
|
|
5
|
+
filename?: (context: Context) => string;
|
|
6
|
+
};
|
|
7
|
+
export declare const style: (options: StyleOptions) => {
|
|
8
|
+
name: string;
|
|
9
|
+
next: (context: Context) => void;
|
|
10
|
+
};
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import t from '@babel/types';
|
|
2
|
+
import fs from 'fs';
|
|
3
|
+
import path from 'path';
|
|
4
|
+
import * as CONSTANTS from '../../constants/index.js';
|
|
5
|
+
const defaults = {
|
|
6
|
+
extensions: ['scss', 'css'],
|
|
7
|
+
directory(context) {
|
|
8
|
+
return context.directoryPath;
|
|
9
|
+
},
|
|
10
|
+
filename(context) {
|
|
11
|
+
return context.fileName;
|
|
12
|
+
}
|
|
13
|
+
};
|
|
14
|
+
export const style = (options) => {
|
|
15
|
+
const name = 'style';
|
|
16
|
+
options = Object.assign(Object.assign({}, defaults), options);
|
|
17
|
+
const next = (context) => {
|
|
18
|
+
const filename = options.filename(context);
|
|
19
|
+
const directory = options.directory(context);
|
|
20
|
+
for (let extension of options.extensions) {
|
|
21
|
+
const stylePath = path.join(directory, `${filename}.${extension}`);
|
|
22
|
+
if (!fs.existsSync(stylePath))
|
|
23
|
+
continue;
|
|
24
|
+
context.stylePath = stylePath;
|
|
25
|
+
break;
|
|
26
|
+
}
|
|
27
|
+
if (!context.stylePath)
|
|
28
|
+
return;
|
|
29
|
+
context.fileAST.program.body.unshift(t.importDeclaration([t.importDefaultSpecifier(t.identifier('AUTO_IMPORT_STYLE'))], t.stringLiteral(context.stylePath)));
|
|
30
|
+
context.class.body.body.unshift(t.classProperty(t.identifier(CONSTANTS.STATIC_STYLES), t.identifier('AUTO_IMPORT_STYLE'), undefined, null, undefined, true));
|
|
31
|
+
};
|
|
32
|
+
return {
|
|
33
|
+
name,
|
|
34
|
+
next
|
|
35
|
+
};
|
|
36
|
+
};
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import * as CONSTANTS from '../../constants/index.js';
|
|
2
|
+
import { hasDecorator, visitor } from '../utils/index.js';
|
|
3
|
+
export const validate = () => {
|
|
4
|
+
const name = 'validate';
|
|
5
|
+
const next = (context) => {
|
|
6
|
+
let hasValidImport;
|
|
7
|
+
visitor(context.fileAST, {
|
|
8
|
+
ImportDeclaration(path) {
|
|
9
|
+
var _a;
|
|
10
|
+
if (((_a = path.node.source) === null || _a === void 0 ? void 0 : _a.value) !== CONSTANTS.PACKAGE_NAME)
|
|
11
|
+
return;
|
|
12
|
+
for (const specifier of path.node.specifiers) {
|
|
13
|
+
if (specifier.imported.name !== CONSTANTS.DECORATOR_ELEMENT)
|
|
14
|
+
continue;
|
|
15
|
+
hasValidImport = true;
|
|
16
|
+
path.stop();
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
});
|
|
20
|
+
let hasValidExport;
|
|
21
|
+
visitor(context.fileAST, {
|
|
22
|
+
ExportNamedDeclaration(path) {
|
|
23
|
+
if (hasValidExport) {
|
|
24
|
+
hasValidExport = false;
|
|
25
|
+
return path.stop();
|
|
26
|
+
}
|
|
27
|
+
if (path.node.declaration.type !== 'ClassDeclaration')
|
|
28
|
+
return;
|
|
29
|
+
if (!hasDecorator(path.node.declaration, CONSTANTS.DECORATOR_ELEMENT))
|
|
30
|
+
return;
|
|
31
|
+
hasValidExport = true;
|
|
32
|
+
}
|
|
33
|
+
});
|
|
34
|
+
context.isInvalid = !hasValidImport || !hasValidExport;
|
|
35
|
+
};
|
|
36
|
+
return {
|
|
37
|
+
name,
|
|
38
|
+
next
|
|
39
|
+
};
|
|
40
|
+
};
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { Context } from '../../types/index.js';
|
|
2
|
+
export interface VscodeOptions {
|
|
3
|
+
dist: string;
|
|
4
|
+
prefix: string;
|
|
5
|
+
}
|
|
6
|
+
export declare const vscode: (options: VscodeOptions) => {
|
|
7
|
+
name: string;
|
|
8
|
+
start: (global: any) => void;
|
|
9
|
+
next: (context: Context, global: any) => void;
|
|
10
|
+
finish: (global: any) => void;
|
|
11
|
+
};
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
import { paramCase } from 'change-case';
|
|
2
|
+
import fs from 'fs';
|
|
3
|
+
import path from 'path';
|
|
4
|
+
import { getTags, getType, printType } from '../utils/index.js';
|
|
5
|
+
export const vscode = (options) => {
|
|
6
|
+
const name = 'vscode';
|
|
7
|
+
const start = (global) => {
|
|
8
|
+
global.vscode = {
|
|
9
|
+
version: 1.1,
|
|
10
|
+
tags: []
|
|
11
|
+
};
|
|
12
|
+
};
|
|
13
|
+
const next = (context, global) => {
|
|
14
|
+
const readme = (() => {
|
|
15
|
+
try {
|
|
16
|
+
const source = path.resolve(context.directoryPath || '', `${context.fileName}.md`);
|
|
17
|
+
return fs.readFileSync(source, 'utf8');
|
|
18
|
+
}
|
|
19
|
+
catch (_a) { }
|
|
20
|
+
})();
|
|
21
|
+
const description = (() => {
|
|
22
|
+
const content = readme || '';
|
|
23
|
+
if (!content.startsWith('# '))
|
|
24
|
+
return '';
|
|
25
|
+
const sections = content.split('\n');
|
|
26
|
+
for (let i = 1; i < sections.length; i++) {
|
|
27
|
+
const section = sections[i].trim();
|
|
28
|
+
if (!section)
|
|
29
|
+
continue;
|
|
30
|
+
return section;
|
|
31
|
+
}
|
|
32
|
+
return '';
|
|
33
|
+
})();
|
|
34
|
+
const properties = (context.classProperties || []).map((property) => {
|
|
35
|
+
var _a;
|
|
36
|
+
const name = paramCase(property.key['name']);
|
|
37
|
+
const description = (_a = getTags(property).find((tag) => !tag.key)) === null || _a === void 0 ? void 0 : _a.value;
|
|
38
|
+
const attribute = {
|
|
39
|
+
name,
|
|
40
|
+
description
|
|
41
|
+
};
|
|
42
|
+
// TODO
|
|
43
|
+
let { members = [] } = (() => {
|
|
44
|
+
const ast = getType(context.fileAST, (property.typeAnnotation || {})['typeAnnotation'], {
|
|
45
|
+
directory: context.directoryPath
|
|
46
|
+
});
|
|
47
|
+
return printType(ast);
|
|
48
|
+
})();
|
|
49
|
+
// TODO
|
|
50
|
+
members = members.filter((member) => member.key !== member.type).map((member) => ({ name: member.key }));
|
|
51
|
+
if (members.length)
|
|
52
|
+
attribute.values = members;
|
|
53
|
+
return attribute;
|
|
54
|
+
});
|
|
55
|
+
global.vscode.tags.push({
|
|
56
|
+
name: context.componentKey,
|
|
57
|
+
description: {
|
|
58
|
+
kind: 'markdown',
|
|
59
|
+
value: description
|
|
60
|
+
},
|
|
61
|
+
attributes: properties,
|
|
62
|
+
references: [
|
|
63
|
+
{
|
|
64
|
+
name: 'Source code',
|
|
65
|
+
url: `https://github.com/htmlplus/core/tree/main/src/components/${context.directoryName}/${context.fileName}.tsx`
|
|
66
|
+
}
|
|
67
|
+
]
|
|
68
|
+
});
|
|
69
|
+
};
|
|
70
|
+
const finish = (global) => {
|
|
71
|
+
global.vscode.tags = global.vscode.tags.sort((a, b) => (a.name > b.name ? 1 : -1));
|
|
72
|
+
// TODO
|
|
73
|
+
// fs.ensureDirSync(path.dirname(options.dist));
|
|
74
|
+
// TODO
|
|
75
|
+
// fs.writeJSONSync(options.dist, global.vscode, { replacer: null, spaces: 2 });
|
|
76
|
+
};
|
|
77
|
+
return {
|
|
78
|
+
name,
|
|
79
|
+
start,
|
|
80
|
+
next,
|
|
81
|
+
finish
|
|
82
|
+
};
|
|
83
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const __dirname: (url: string | URL) => string;
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
import { parse } from '@babel/parser';
|
|
2
|
+
import fs from 'fs';
|
|
3
|
+
import { dirname, resolve } from 'path';
|
|
4
|
+
import { visitor } from './visitor.js';
|
|
5
|
+
// TODO: return type
|
|
6
|
+
export const getType = (file, node, options) => {
|
|
7
|
+
if (!node)
|
|
8
|
+
return node;
|
|
9
|
+
if (node.type != 'TSTypeReference')
|
|
10
|
+
return node;
|
|
11
|
+
const { directory } = options;
|
|
12
|
+
let result;
|
|
13
|
+
visitor(file, {
|
|
14
|
+
ClassDeclaration(path) {
|
|
15
|
+
if (path.node.id.name != node.typeName.name)
|
|
16
|
+
return;
|
|
17
|
+
result = path.node;
|
|
18
|
+
path.stop();
|
|
19
|
+
},
|
|
20
|
+
ImportDeclaration(path) {
|
|
21
|
+
for (const specifier of path.node.specifiers) {
|
|
22
|
+
const alias = specifier.local.name;
|
|
23
|
+
if (alias != node.typeName.name)
|
|
24
|
+
continue;
|
|
25
|
+
let key;
|
|
26
|
+
switch (specifier.type) {
|
|
27
|
+
case 'ImportNamespaceSpecifier':
|
|
28
|
+
key = '*';
|
|
29
|
+
break;
|
|
30
|
+
case 'ImportDefaultSpecifier':
|
|
31
|
+
key = 'default';
|
|
32
|
+
break;
|
|
33
|
+
case 'ImportSpecifier':
|
|
34
|
+
key = specifier.imported.name;
|
|
35
|
+
break;
|
|
36
|
+
}
|
|
37
|
+
try {
|
|
38
|
+
const filePath = resolve(directory, path.node.source.value + '.ts');
|
|
39
|
+
path.$ast =
|
|
40
|
+
path.$ast ||
|
|
41
|
+
parse(fs.readFileSync(filePath, 'utf8'), {
|
|
42
|
+
allowImportExportEverywhere: true,
|
|
43
|
+
plugins: ['typescript'],
|
|
44
|
+
ranges: false
|
|
45
|
+
});
|
|
46
|
+
result = getType(path.$ast, node, {
|
|
47
|
+
directory: dirname(filePath)
|
|
48
|
+
});
|
|
49
|
+
}
|
|
50
|
+
catch (_a) { }
|
|
51
|
+
path.stop();
|
|
52
|
+
break;
|
|
53
|
+
}
|
|
54
|
+
},
|
|
55
|
+
TSInterfaceDeclaration(path) {
|
|
56
|
+
if (path.node.id.name != node.typeName.name)
|
|
57
|
+
return;
|
|
58
|
+
result = path.node;
|
|
59
|
+
path.stop();
|
|
60
|
+
},
|
|
61
|
+
TSTypeAliasDeclaration(path) {
|
|
62
|
+
if (path.node.id.name != node.typeName.name)
|
|
63
|
+
return;
|
|
64
|
+
result = path.node;
|
|
65
|
+
path.stop();
|
|
66
|
+
}
|
|
67
|
+
});
|
|
68
|
+
return result || node;
|
|
69
|
+
};
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { visitor } from './visitor.js';
|
|
2
|
+
export const getTypeReference = (file, node) => {
|
|
3
|
+
if (!node)
|
|
4
|
+
return;
|
|
5
|
+
if (node.type != 'TSTypeReference')
|
|
6
|
+
return;
|
|
7
|
+
let result;
|
|
8
|
+
visitor(file, {
|
|
9
|
+
ImportDeclaration(path) {
|
|
10
|
+
for (const specifier of path.node.specifiers) {
|
|
11
|
+
const alias = specifier.local.name;
|
|
12
|
+
if (alias != node.typeName['name'])
|
|
13
|
+
continue;
|
|
14
|
+
let key;
|
|
15
|
+
switch (specifier.type) {
|
|
16
|
+
case 'ImportNamespaceSpecifier':
|
|
17
|
+
key = '*';
|
|
18
|
+
break;
|
|
19
|
+
case 'ImportDefaultSpecifier':
|
|
20
|
+
key = 'default';
|
|
21
|
+
break;
|
|
22
|
+
case 'ImportSpecifier':
|
|
23
|
+
key = specifier.imported.name;
|
|
24
|
+
break;
|
|
25
|
+
}
|
|
26
|
+
result = path.node.source.value;
|
|
27
|
+
path.stop();
|
|
28
|
+
break;
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
});
|
|
32
|
+
return result;
|
|
33
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const hasDecorator: (node: any, name: string) => boolean;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
export * from './__dirname.js';
|
|
2
|
+
export * from './getInitializer.js';
|
|
3
|
+
export * from './getType.js';
|
|
4
|
+
export * from './getTypeReference.js';
|
|
5
|
+
export * from './hasDecorator.js';
|
|
6
|
+
export * from './isDirectoryEmpty.js';
|
|
7
|
+
export * from './printType.js';
|
|
8
|
+
export * from './print.js';
|
|
9
|
+
export * from './renderTemplate.js';
|
|
10
|
+
export * from './tags.js';
|
|
11
|
+
export * from './visitor.js';
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
export * from './__dirname.js';
|
|
2
|
+
export * from './getInitializer.js';
|
|
3
|
+
export * from './getType.js';
|
|
4
|
+
export * from './getTypeReference.js';
|
|
5
|
+
export * from './hasDecorator.js';
|
|
6
|
+
export * from './isDirectoryEmpty.js';
|
|
7
|
+
export * from './printType.js';
|
|
8
|
+
export * from './print.js';
|
|
9
|
+
export * from './renderTemplate.js';
|
|
10
|
+
export * from './tags.js';
|
|
11
|
+
export * from './visitor.js';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const isDirectoryEmpty: (directory: string) => boolean;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const printType: (ast: any) => any;
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
import { print } from './print.js';
|
|
2
|
+
// TODO
|
|
3
|
+
// args types
|
|
4
|
+
// return type
|
|
5
|
+
// components\grid-item\grid-item.types.ts
|
|
6
|
+
// components\portal\portal.tsx
|
|
7
|
+
export const printType = (ast) => {
|
|
8
|
+
if (!ast)
|
|
9
|
+
return ast;
|
|
10
|
+
let result = {};
|
|
11
|
+
switch (ast.type) {
|
|
12
|
+
case 'BooleanLiteral':
|
|
13
|
+
case 'NumericLiteral':
|
|
14
|
+
case 'StringLiteral': {
|
|
15
|
+
result.key = ast.value;
|
|
16
|
+
result.type = ast.type.replace('Literal', '').toLowerCase();
|
|
17
|
+
break;
|
|
18
|
+
}
|
|
19
|
+
case 'TSBooleanKeyword':
|
|
20
|
+
case 'TSNumberKeyword':
|
|
21
|
+
case 'TSStringKeyword': {
|
|
22
|
+
const type = ast.type.replace('TS', '').replace('Keyword', '').toLowerCase();
|
|
23
|
+
result.key = type;
|
|
24
|
+
result.type = type;
|
|
25
|
+
break;
|
|
26
|
+
}
|
|
27
|
+
case 'TSAnyKeyword': {
|
|
28
|
+
result.type = 'any';
|
|
29
|
+
break;
|
|
30
|
+
}
|
|
31
|
+
case 'TSArrayType': {
|
|
32
|
+
const type = print(ast.elementType) + '[]';
|
|
33
|
+
result.key = type;
|
|
34
|
+
result.type = type;
|
|
35
|
+
break;
|
|
36
|
+
}
|
|
37
|
+
case 'TSInterfaceDeclaration': {
|
|
38
|
+
result.type = ast.id.name;
|
|
39
|
+
result.members = ast.body.body.map((body) => printType(body));
|
|
40
|
+
break;
|
|
41
|
+
}
|
|
42
|
+
case 'TSLiteralType': {
|
|
43
|
+
result = printType(ast.literal);
|
|
44
|
+
break;
|
|
45
|
+
}
|
|
46
|
+
case 'TSPropertySignature': {
|
|
47
|
+
const { typeAnnotation } = ast;
|
|
48
|
+
result.key = ast.key.name;
|
|
49
|
+
if (typeAnnotation && typeAnnotation.typeAnnotation)
|
|
50
|
+
result.type = printType(ast.typeAnnotation.typeAnnotation).type;
|
|
51
|
+
break;
|
|
52
|
+
}
|
|
53
|
+
case 'TSTypeAliasDeclaration': {
|
|
54
|
+
result = printType(ast.typeAnnotation);
|
|
55
|
+
break;
|
|
56
|
+
}
|
|
57
|
+
case 'TSTypeReference': {
|
|
58
|
+
result.key = ast.typeName.name;
|
|
59
|
+
result.type = ast.typeName.name;
|
|
60
|
+
break;
|
|
61
|
+
}
|
|
62
|
+
case 'TSUnionType': {
|
|
63
|
+
result.type = print(ast);
|
|
64
|
+
result.members = ast.types.map((type) => printType(type));
|
|
65
|
+
break;
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
return result;
|
|
69
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const renderTemplate: (source: string | Array<string>, destination: string, options?: any) => (context: any) => void;
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import glob from 'fast-glob';
|
|
2
|
+
import fs from 'fs';
|
|
3
|
+
import handlebars from 'handlebars';
|
|
4
|
+
import path from 'path';
|
|
5
|
+
export const renderTemplate = (source, destination, options) => (context) => {
|
|
6
|
+
const files = glob.sync(source, options);
|
|
7
|
+
for (const file of files) {
|
|
8
|
+
const from = path.resolve((options === null || options === void 0 ? void 0 : options.cwd) || '', file);
|
|
9
|
+
const to = path.join(destination, path
|
|
10
|
+
.normalize(file)
|
|
11
|
+
.split(path.sep)
|
|
12
|
+
.slice(1)
|
|
13
|
+
.map((section) => handlebars.compile(section)(context))
|
|
14
|
+
.join(path.sep)
|
|
15
|
+
.replace('_.', '.')
|
|
16
|
+
.replace('.hbs', ''));
|
|
17
|
+
const directory = path.dirname(to);
|
|
18
|
+
const raw = fs.readFileSync(from, 'utf8');
|
|
19
|
+
const template = handlebars.compile(raw)(context);
|
|
20
|
+
if (!fs.existsSync(directory)) {
|
|
21
|
+
fs.mkdirSync(directory, { recursive: true });
|
|
22
|
+
}
|
|
23
|
+
fs.writeFileSync(to, template, 'utf8');
|
|
24
|
+
}
|
|
25
|
+
};
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { Node } from '@babel/types';
|
|
2
|
+
export interface Tag {
|
|
3
|
+
key?: string;
|
|
4
|
+
value?: string;
|
|
5
|
+
}
|
|
6
|
+
export interface TagParsed {
|
|
7
|
+
name?: string;
|
|
8
|
+
description?: string;
|
|
9
|
+
}
|
|
10
|
+
export declare const getTag: (node: Node, key?: string | undefined) => Tag | undefined;
|
|
11
|
+
export declare const getTags: (node: Node, filter?: string | undefined) => Array<Tag>;
|
|
12
|
+
export declare const hasTag: (node: Node, name: string) => Boolean;
|
|
13
|
+
export declare const parseTag: (tag: Tag, spliter?: string) => TagParsed;
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
export const getTag = (node, key) => {
|
|
2
|
+
return getTags(node, key).pop();
|
|
3
|
+
};
|
|
4
|
+
export const getTags = (node, filter) => {
|
|
5
|
+
var _a;
|
|
6
|
+
let tags = (_a = node['tags']) !== null && _a !== void 0 ? _a : [];
|
|
7
|
+
if (!node['tags']) {
|
|
8
|
+
const lines = [];
|
|
9
|
+
const comments = (node.leadingComments || [])
|
|
10
|
+
.slice(-1)
|
|
11
|
+
.map((comment) => comment.value)
|
|
12
|
+
.join('\r\n')
|
|
13
|
+
.split('\r\n');
|
|
14
|
+
for (const comment of comments) {
|
|
15
|
+
let line = comment.trimStart();
|
|
16
|
+
if (line.startsWith('*'))
|
|
17
|
+
line = line.slice(1);
|
|
18
|
+
if (!line)
|
|
19
|
+
continue;
|
|
20
|
+
const isTag = line.trim().startsWith('@');
|
|
21
|
+
if (isTag || !lines.length)
|
|
22
|
+
lines.push(line);
|
|
23
|
+
else
|
|
24
|
+
lines[lines.length - 1] += line;
|
|
25
|
+
}
|
|
26
|
+
for (const line of lines) {
|
|
27
|
+
let value = line.trim();
|
|
28
|
+
if (!value.startsWith('@')) {
|
|
29
|
+
tags.push({ value });
|
|
30
|
+
continue;
|
|
31
|
+
}
|
|
32
|
+
const sections = value.split(' ');
|
|
33
|
+
const key = sections[0].slice(1);
|
|
34
|
+
value = sections.slice(1).join(' ').trim();
|
|
35
|
+
tags.push({ key, value });
|
|
36
|
+
}
|
|
37
|
+
node['tags'] = tags;
|
|
38
|
+
}
|
|
39
|
+
return tags.filter((tag) => !filter || filter === tag.key);
|
|
40
|
+
};
|
|
41
|
+
export const hasTag = (node, name) => {
|
|
42
|
+
return getTags(node).some((tag) => tag.key === name);
|
|
43
|
+
};
|
|
44
|
+
export const parseTag = (tag, spliter = '-') => {
|
|
45
|
+
var _a, _b;
|
|
46
|
+
const sections = ((_a = tag.value) === null || _a === void 0 ? void 0 : _a.split(spliter)) || [];
|
|
47
|
+
const name = (_b = sections[0]) === null || _b === void 0 ? void 0 : _b.trim();
|
|
48
|
+
const description = sections.slice(1).join(spliter).trim();
|
|
49
|
+
return {
|
|
50
|
+
name,
|
|
51
|
+
description
|
|
52
|
+
};
|
|
53
|
+
};
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
export declare const PACKAGE_NAME = "@htmlplus/element";
|
|
2
|
+
export declare const API_HOST = "$host$";
|
|
3
|
+
export declare const API_READY = "$ready$";
|
|
4
|
+
export declare const DECORATOR_ELEMENT = "Element";
|
|
5
|
+
export declare const DECORATOR_EVENT = "Event";
|
|
6
|
+
export declare const DECORATOR_PROPERTY = "Property";
|
|
7
|
+
export declare const DECORATOR_STATE = "State";
|
|
8
|
+
export declare const DECORATOR_METHOD = "Method";
|
|
9
|
+
export declare const LIFECYCLE_ADOPTED = "adoptedCallback";
|
|
10
|
+
export declare const LIFECYCLE_CONNECTED = "connectedCallback";
|
|
11
|
+
export declare const LIFECYCLE_DISCONNECTED = "disconnectedCallback";
|
|
12
|
+
export declare const LIFECYCLE_LOADED = "loadedCallback";
|
|
13
|
+
export declare const LIFECYCLE_UPDATE = "updateCallback";
|
|
14
|
+
export declare const LIFECYCLE_UPDATED = "updatedCallback";
|
|
15
|
+
export declare const METHOD_RENDER = "render";
|
|
16
|
+
export declare const STATIC_MEMBERS = "members";
|
|
17
|
+
export declare const STATIC_STYLES = "styles";
|
|
18
|
+
export declare const TYPE_BOOLEAN = "boolean";
|
|
19
|
+
export declare const TYPE_DATE = "date";
|
|
20
|
+
export declare const TYPE_FUNCTION = "function";
|
|
21
|
+
export declare const TYPE_STRING = "string";
|
|
22
|
+
export declare const TYPE_NUMBER = "number";
|