@htmlplus/element 0.3.0 → 0.3.1

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.
Files changed (162) hide show
  1. package/README.md +4 -4
  2. package/package.json +8 -45
  3. package/dist/client/decorators/attributes.d.ts +0 -2
  4. package/dist/client/decorators/attributes.js +0 -13
  5. package/dist/client/decorators/bind.d.ts +0 -4
  6. package/dist/client/decorators/bind.js +0 -17
  7. package/dist/client/decorators/element.d.ts +0 -2
  8. package/dist/client/decorators/element.js +0 -49
  9. package/dist/client/decorators/event.d.ts +0 -21
  10. package/dist/client/decorators/event.js +0 -18
  11. package/dist/client/decorators/index.d.ts +0 -9
  12. package/dist/client/decorators/index.js +0 -9
  13. package/dist/client/decorators/listen.d.ts +0 -12
  14. package/dist/client/decorators/listen.js +0 -30
  15. package/dist/client/decorators/method.d.ts +0 -2
  16. package/dist/client/decorators/method.js +0 -12
  17. package/dist/client/decorators/property.d.ts +0 -12
  18. package/dist/client/decorators/property.js +0 -51
  19. package/dist/client/decorators/state.d.ts +0 -2
  20. package/dist/client/decorators/state.js +0 -32
  21. package/dist/client/decorators/watch.d.ts +0 -2
  22. package/dist/client/decorators/watch.js +0 -17
  23. package/dist/client/helpers/classes.d.ts +0 -1
  24. package/dist/client/helpers/classes.js +0 -62
  25. package/dist/client/helpers/direction.d.ts +0 -3
  26. package/dist/client/helpers/direction.js +0 -4
  27. package/dist/client/helpers/index.d.ts +0 -9
  28. package/dist/client/helpers/index.js +0 -9
  29. package/dist/client/helpers/is-rtl.d.ts +0 -2
  30. package/dist/client/helpers/is-rtl.js +0 -2
  31. package/dist/client/helpers/query-all.d.ts +0 -3
  32. package/dist/client/helpers/query-all.js +0 -5
  33. package/dist/client/helpers/query.d.ts +0 -3
  34. package/dist/client/helpers/query.js +0 -5
  35. package/dist/client/helpers/slots.d.ts +0 -6
  36. package/dist/client/helpers/slots.js +0 -15
  37. package/dist/client/helpers/styles.d.ts +0 -1
  38. package/dist/client/helpers/styles.js +0 -16
  39. package/dist/client/helpers/to-unit.d.ts +0 -1
  40. package/dist/client/helpers/to-unit.js +0 -7
  41. package/dist/client/index.d.ts +0 -3
  42. package/dist/client/index.js +0 -3
  43. package/dist/client/services/index.d.ts +0 -1
  44. package/dist/client/services/index.js +0 -1
  45. package/dist/client/services/link.d.ts +0 -4
  46. package/dist/client/services/link.js +0 -196
  47. package/dist/client/utils/append-to-method.d.ts +0 -2
  48. package/dist/client/utils/append-to-method.js +0 -7
  49. package/dist/client/utils/call.d.ts +0 -2
  50. package/dist/client/utils/call.js +0 -4
  51. package/dist/client/utils/define-property.d.ts +0 -1
  52. package/dist/client/utils/define-property.js +0 -1
  53. package/dist/client/utils/event.d.ts +0 -2
  54. package/dist/client/utils/event.js +0 -6
  55. package/dist/client/utils/get-members.d.ts +0 -2
  56. package/dist/client/utils/get-members.js +0 -5
  57. package/dist/client/utils/get-styles.d.ts +0 -2
  58. package/dist/client/utils/get-styles.js +0 -5
  59. package/dist/client/utils/host.d.ts +0 -2
  60. package/dist/client/utils/host.js +0 -4
  61. package/dist/client/utils/index.d.ts +0 -20
  62. package/dist/client/utils/index.js +0 -20
  63. package/dist/client/utils/is-event.d.ts +0 -1
  64. package/dist/client/utils/is-event.js +0 -3
  65. package/dist/client/utils/is-ready.d.ts +0 -2
  66. package/dist/client/utils/is-ready.js +0 -4
  67. package/dist/client/utils/is-server.d.ts +0 -1
  68. package/dist/client/utils/is-server.js +0 -3
  69. package/dist/client/utils/on-ready.d.ts +0 -2
  70. package/dist/client/utils/on-ready.js +0 -6
  71. package/dist/client/utils/parse-value.d.ts +0 -1
  72. package/dist/client/utils/parse-value.js +0 -15
  73. package/dist/client/utils/render.d.ts +0 -2
  74. package/dist/client/utils/render.js +0 -19
  75. package/dist/client/utils/request.d.ts +0 -2
  76. package/dist/client/utils/request.js +0 -28
  77. package/dist/client/utils/sync.d.ts +0 -1
  78. package/dist/client/utils/sync.js +0 -31
  79. package/dist/client/utils/task.d.ts +0 -6
  80. package/dist/client/utils/task.js +0 -37
  81. package/dist/client/utils/to-boolean.d.ts +0 -1
  82. package/dist/client/utils/to-boolean.js +0 -3
  83. package/dist/client/utils/to-event.d.ts +0 -1
  84. package/dist/client/utils/to-event.js +0 -3
  85. package/dist/client/utils/type-of.d.ts +0 -3
  86. package/dist/client/utils/type-of.js +0 -6
  87. package/dist/client/utils/update-attribute.d.ts +0 -1
  88. package/dist/client/utils/update-attribute.js +0 -7
  89. package/dist/compiler/compiler.d.ts +0 -7
  90. package/dist/compiler/compiler.js +0 -55
  91. package/dist/compiler/index.d.ts +0 -2
  92. package/dist/compiler/index.js +0 -2
  93. package/dist/compiler/plugins/componentDependencyResolver.d.ts +0 -5
  94. package/dist/compiler/plugins/componentDependencyResolver.js +0 -40
  95. package/dist/compiler/plugins/customElement.d.ts +0 -5
  96. package/dist/compiler/plugins/customElement.js +0 -138
  97. package/dist/compiler/plugins/customElementReact/customElementReact.d.ts +0 -12
  98. package/dist/compiler/plugins/customElementReact/customElementReact.js +0 -125
  99. package/dist/compiler/plugins/customElementReact/index.d.ts +0 -1
  100. package/dist/compiler/plugins/customElementReact/index.js +0 -1
  101. package/dist/compiler/plugins/customElementReact/templates/README.md.hbs +0 -1
  102. package/dist/compiler/plugins/customElementReact/templates/_.gitignore.hbs +0 -2
  103. package/dist/compiler/plugins/customElementReact/templates/package.json.hbs +0 -37
  104. package/dist/compiler/plugins/customElementReact/templates/rollup.config.js.hbs +0 -21
  105. package/dist/compiler/plugins/customElementReact/templates/src/components/index.ts.hbs +0 -17
  106. package/dist/compiler/plugins/customElementReact/templates/src/components/{{fileName}}.compact.ts.hbs +0 -18
  107. package/dist/compiler/plugins/customElementReact/templates/src/components/{{fileName}}.ts.hbs +0 -26
  108. package/dist/compiler/plugins/customElementReact/templates/src/index.ts.hbs +0 -1
  109. package/dist/compiler/plugins/customElementReact/templates/src/proxy.ts.hbs +0 -278
  110. package/dist/compiler/plugins/customElementReact/templates/tsconfig.json.hbs +0 -17
  111. package/dist/compiler/plugins/docs.d.ts +0 -11
  112. package/dist/compiler/plugins/docs.js +0 -320
  113. package/dist/compiler/plugins/extract.d.ts +0 -8
  114. package/dist/compiler/plugins/extract.js +0 -70
  115. package/dist/compiler/plugins/index.d.ts +0 -7
  116. package/dist/compiler/plugins/index.js +0 -7
  117. package/dist/compiler/plugins/parse.d.ts +0 -5
  118. package/dist/compiler/plugins/parse.js +0 -16
  119. package/dist/compiler/plugins/read.d.ts +0 -5
  120. package/dist/compiler/plugins/read.js +0 -13
  121. package/dist/compiler/plugins/style.d.ts +0 -12
  122. package/dist/compiler/plugins/style.js +0 -42
  123. package/dist/compiler/plugins/validate.d.ts +0 -5
  124. package/dist/compiler/plugins/validate.js +0 -40
  125. package/dist/compiler/plugins/vscode.d.ts +0 -11
  126. package/dist/compiler/plugins/vscode.js +0 -83
  127. package/dist/compiler/utils/__dirname.d.ts +0 -1
  128. package/dist/compiler/utils/__dirname.js +0 -5
  129. package/dist/compiler/utils/get-initializer.d.ts +0 -2
  130. package/dist/compiler/utils/get-initializer.js +0 -10
  131. package/dist/compiler/utils/get-tags.d.ts +0 -6
  132. package/dist/compiler/utils/get-tags.js +0 -34
  133. package/dist/compiler/utils/get-type.d.ts +0 -2
  134. package/dist/compiler/utils/get-type.js +0 -69
  135. package/dist/compiler/utils/has-decorator.d.ts +0 -1
  136. package/dist/compiler/utils/has-decorator.js +0 -5
  137. package/dist/compiler/utils/index.d.ts +0 -10
  138. package/dist/compiler/utils/index.js +0 -10
  139. package/dist/compiler/utils/is-directory-empty.d.ts +0 -1
  140. package/dist/compiler/utils/is-directory-empty.js +0 -10
  141. package/dist/compiler/utils/print-type.d.ts +0 -1
  142. package/dist/compiler/utils/print-type.js +0 -69
  143. package/dist/compiler/utils/print.d.ts +0 -2
  144. package/dist/compiler/utils/print.js +0 -5
  145. package/dist/compiler/utils/render-template.d.ts +0 -1
  146. package/dist/compiler/utils/render-template.js +0 -25
  147. package/dist/compiler/utils/visitor.d.ts +0 -2
  148. package/dist/compiler/utils/visitor.js +0 -5
  149. package/dist/constants/index.d.ts +0 -23
  150. package/dist/constants/index.js +0 -29
  151. package/dist/runtime/index.d.ts +0 -1
  152. package/dist/runtime/index.js +0 -4
  153. package/dist/types/context.d.ts +0 -32
  154. package/dist/types/context.js +0 -1
  155. package/dist/types/global.d.ts +0 -4
  156. package/dist/types/global.js +0 -1
  157. package/dist/types/index.d.ts +0 -4
  158. package/dist/types/index.js +0 -4
  159. package/dist/types/plugin.d.ts +0 -9
  160. package/dist/types/plugin.js +0 -1
  161. package/dist/types/plus-element.d.ts +0 -2
  162. package/dist/types/plus-element.js +0 -1
@@ -1,70 +0,0 @@
1
- import * as t from '@babel/types';
2
- import { pascalCase, paramCase } from 'change-case';
3
- import path from 'path';
4
- import * as CONSTANTS from '../../constants/index.js';
5
- import { hasDecorator, visitor } from '../utils/index.js';
6
- export const extract = (options) => {
7
- const name = 'extract';
8
- const next = (context) => {
9
- var _a, _b;
10
- visitor(context.fileAST, {
11
- ClassDeclaration: {
12
- exit(path) {
13
- var _a, _b;
14
- context.class = path.node;
15
- context.classMembers = ((_b = (_a = context.class) === null || _a === void 0 ? void 0 : _a.body) === null || _b === void 0 ? void 0 : _b.body) || [];
16
- path.skip();
17
- }
18
- },
19
- Decorator(path) {
20
- var _a;
21
- const name = (_a = path.node.expression.callee) === null || _a === void 0 ? void 0 : _a.name;
22
- // TODO
23
- if (CONSTANTS.DECORATOR_ELEMENT == name) {
24
- const [argument] = path.node.expression.arguments;
25
- if (argument) {
26
- context.componentTag = argument === null || argument === void 0 ? void 0 : argument.value;
27
- return;
28
- }
29
- context.componentTag = paramCase(path.parent.id.name);
30
- if (options === null || options === void 0 ? void 0 : options.prefix)
31
- context.componentTag = options.prefix + '-' + context.componentTag;
32
- path.replaceWith(t.decorator(t.callExpression(t.identifier(name), [
33
- t.stringLiteral(context.componentTag),
34
- ...path.node.expression.arguments.slice(1)
35
- ])));
36
- return;
37
- }
38
- }
39
- });
40
- context.directoryPath = path.dirname(context.filePath);
41
- context.directoryName = path.basename(context.directoryPath);
42
- context.fileExtension = path.extname(context.filePath);
43
- context.fileName = path.basename(context.filePath, context.fileExtension);
44
- context.className = (_b = (_a = context.class) === null || _a === void 0 ? void 0 : _a.id) === null || _b === void 0 ? void 0 : _b.name;
45
- // TODO
46
- // context.componentKey = paramCase(context.className);
47
- context.componentClassName = pascalCase(context.componentTag.split('-').slice(1).join('-'));
48
- context.componentInterfaceName = `HTML${context.componentClassName}Element`;
49
- // TODO
50
- // const componentClassName = "DialogBody"; [OK]
51
- // const componentInterfaceName = "HTMLDialogBodyElement"; [OK]
52
- // const componentTag = "plus-dialog-body"; [OK]
53
- // const componentClassNameInCategory = "Body"; [RAW]
54
- // const componentKey = "dialog-body-1"; [RAW]
55
- // const fileName = "dialogBodyNew"; [OK]
56
- // const className = "DialogBody1"; [OK]
57
- // const category = "Dialog"; [RAW]
58
- context.classEvents = (context.classMembers || []).filter((member) => hasDecorator(member, CONSTANTS.DECORATOR_EVENT));
59
- context.classMethods = (context.classMembers || []).filter((member) => hasDecorator(member, CONSTANTS.DECORATOR_METHOD));
60
- context.classProperties = (context.classMembers || []).filter((member) => hasDecorator(member, CONSTANTS.DECORATOR_PROPERTY));
61
- context.classStates = (context.classMembers || []).filter((member) => hasDecorator(member, CONSTANTS.DECORATOR_STATE));
62
- context.classHasMount = (context.classMembers || []).some((member) => member['key'].name == CONSTANTS.LIFECYCLE_CONNECTED);
63
- context.classHasUnmount = (context.classMembers || []).some((member) => member['key'].name == CONSTANTS.LIFECYCLE_DISCONNECTED);
64
- context.classRender = (context.classMembers || []).find((member) => member['key'].name == CONSTANTS.METHOD_RENDER);
65
- };
66
- return {
67
- name,
68
- next
69
- };
70
- };
@@ -1,7 +0,0 @@
1
- export * from './customElementReact/index.js';
2
- export * from './customElement.js';
3
- export * from './extract.js';
4
- export * from './parse.js';
5
- export * from './read.js';
6
- export * from './style.js';
7
- export * from './validate.js';
@@ -1,7 +0,0 @@
1
- export * from './customElementReact/index.js';
2
- export * from './customElement.js';
3
- export * from './extract.js';
4
- export * from './parse.js';
5
- export * from './read.js';
6
- export * from './style.js';
7
- export * from './validate.js';
@@ -1,5 +0,0 @@
1
- import { Context } from '../../types/index.js';
2
- export declare const parse: () => {
3
- name: string;
4
- next: (context: Context) => void;
5
- };
@@ -1,16 +0,0 @@
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
- };
@@ -1,5 +0,0 @@
1
- import { Context } from '../../types/index.js';
2
- export declare const read: () => {
3
- name: string;
4
- next: (context: Context) => void;
5
- };
@@ -1,13 +0,0 @@
1
- import fs from 'fs';
2
- export const read = () => {
3
- const name = 'read';
4
- const next = (context) => {
5
- if (!!context.fileContent)
6
- return;
7
- context.fileContent = fs.readFileSync(context.filePath, 'utf8');
8
- };
9
- return {
10
- name,
11
- next
12
- };
13
- };
@@ -1,12 +0,0 @@
1
- import { Options } from 'sass';
2
- import { Context } from '../../types/index.js';
3
- export declare type StyleOptions = {
4
- extensions?: Array<'scss' | 'css'>;
5
- directory?: (context: Context) => string;
6
- filename?: (context: Context) => string;
7
- sass?: Options<'sync'>;
8
- };
9
- export declare const style: (options: StyleOptions) => {
10
- name: string;
11
- next: (context: Context) => void;
12
- };
@@ -1,42 +0,0 @@
1
- import t from '@babel/types';
2
- import fs from 'fs';
3
- import path from 'path';
4
- import core from 'sass';
5
- import * as CONSTANTS from '../../constants/index.js';
6
- const defaults = {
7
- extensions: ['scss', 'css'],
8
- directory(context) {
9
- return context.directoryPath;
10
- },
11
- filename(context) {
12
- return context.fileName;
13
- }
14
- };
15
- export const style = (options) => {
16
- const name = 'style';
17
- options = Object.assign(Object.assign({}, defaults), options);
18
- const next = (context) => {
19
- const filename = options.filename(context);
20
- const directory = options.directory(context);
21
- for (let extension of options.extensions) {
22
- const stylePath = path.join(directory, `${filename}.${extension}`);
23
- if (!fs.existsSync(stylePath))
24
- continue;
25
- context.stylePath = stylePath;
26
- break;
27
- }
28
- if (!context.stylePath)
29
- return;
30
- const { css, loadedUrls } = core.compile(context.stylePath, Object.assign(Object.assign({}, (options.sass || {})), { style: 'compressed' }));
31
- context.styleParsed = css.toString();
32
- // TODO loadedUrls;
33
- context.styleDependencies = [];
34
- if (!context.styleParsed)
35
- return;
36
- context.class.body.body.unshift(t.classProperty(t.identifier(CONSTANTS.STATIC_STYLES), t.stringLiteral(context.styleParsed), undefined, null, undefined, true));
37
- };
38
- return {
39
- name,
40
- next
41
- };
42
- };
@@ -1,5 +0,0 @@
1
- import { Context } from '../../types/index.js';
2
- export declare const validate: () => {
3
- name: string;
4
- next: (context: Context) => void;
5
- };
@@ -1,40 +0,0 @@
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
- };
@@ -1,11 +0,0 @@
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
- };
@@ -1,83 +0,0 @@
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
- };
@@ -1 +0,0 @@
1
- export declare const __dirname: (url: string | URL) => string;
@@ -1,5 +0,0 @@
1
- import { dirname } from 'path';
2
- import { fileURLToPath } from 'url';
3
- export const __dirname = (url) => {
4
- return dirname(fileURLToPath(url));
5
- };
@@ -1,2 +0,0 @@
1
- import { Expression } from '@babel/types';
2
- export declare const getInitializer: (node: Expression) => any;
@@ -1,10 +0,0 @@
1
- // TODO: return type
2
- export const getInitializer = (node) => {
3
- if (!node)
4
- return node;
5
- const value = node;
6
- if (!value)
7
- return;
8
- const extra = value.extra || {};
9
- return extra.raw || value['value'];
10
- };
@@ -1,6 +0,0 @@
1
- import { Node } from '@babel/types';
2
- export interface Tag {
3
- key?: string;
4
- value?: string;
5
- }
6
- export declare const getTags: (node?: Node | undefined) => Array<Tag>;
@@ -1,34 +0,0 @@
1
- export const getTags = (node) => {
2
- if (!node)
3
- return [];
4
- const tags = [];
5
- const lines = [];
6
- const comments = (node.leadingComments || [])
7
- .map((comment) => comment.value)
8
- .join('\r\n')
9
- .split('\r\n');
10
- for (const comment of comments) {
11
- let line = comment.trimLeft();
12
- if (line.startsWith('*'))
13
- line = line.slice(1);
14
- if (!line)
15
- continue;
16
- const isTag = line.trim().startsWith('@');
17
- if (isTag || !lines.length)
18
- lines.push(line);
19
- else
20
- lines[lines.length - 1] += line;
21
- }
22
- for (const line of lines) {
23
- let value = line.trim();
24
- if (!value.startsWith('@')) {
25
- tags.push({ value });
26
- continue;
27
- }
28
- const sections = value.split(' ');
29
- const key = sections[0].slice(1);
30
- value = sections.slice(1).join(' ').trim();
31
- tags.push({ key, value });
32
- }
33
- return tags;
34
- };
@@ -1,2 +0,0 @@
1
- import { File } from '@babel/types';
2
- export declare const getType: (file: File, node: any, options: any) => any;
@@ -1,69 +0,0 @@
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
- };
@@ -1 +0,0 @@
1
- export declare const hasDecorator: (node: any, name: string) => boolean;
@@ -1,5 +0,0 @@
1
- export const hasDecorator = (node, name) => {
2
- if (!node.decorators)
3
- return false;
4
- return !!node.decorators.some((decorator) => { var _a; return ((_a = decorator.expression.callee) === null || _a === void 0 ? void 0 : _a.name) == name; });
5
- };
@@ -1,10 +0,0 @@
1
- export * from './__dirname.js';
2
- export * from './get-initializer.js';
3
- export * from './get-tags.js';
4
- export * from './get-type.js';
5
- export * from './has-decorator.js';
6
- export * from './is-directory-empty.js';
7
- export * from './print-type.js';
8
- export * from './print.js';
9
- export * from './render-template.js';
10
- export * from './visitor.js';
@@ -1,10 +0,0 @@
1
- export * from './__dirname.js';
2
- export * from './get-initializer.js';
3
- export * from './get-tags.js';
4
- export * from './get-type.js';
5
- export * from './has-decorator.js';
6
- export * from './is-directory-empty.js';
7
- export * from './print-type.js';
8
- export * from './print.js';
9
- export * from './render-template.js';
10
- export * from './visitor.js';
@@ -1 +0,0 @@
1
- export declare const isDirectoryEmpty: (directory: string) => boolean;
@@ -1,10 +0,0 @@
1
- import fs from 'fs';
2
- export const isDirectoryEmpty = (directory) => {
3
- try {
4
- const files = fs.readdirSync(directory);
5
- return !files.length;
6
- }
7
- catch (_a) {
8
- return true;
9
- }
10
- };
@@ -1 +0,0 @@
1
- export declare const printType: (ast: any) => any;
@@ -1,69 +0,0 @@
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
- };
@@ -1,2 +0,0 @@
1
- import { Node } from '@babel/types';
2
- export declare const print: (ast: Node) => string;
@@ -1,5 +0,0 @@
1
- import generator from '@babel/generator';
2
- // TODO: add options
3
- export const print = (ast) => {
4
- return (generator.default || generator)(ast, { decoratorsBeforeExport: true }).code;
5
- };
@@ -1 +0,0 @@
1
- export declare const renderTemplate: (source: string | Array<string>, destination: string, options?: any) => (context: any) => void;
@@ -1,25 +0,0 @@
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
- };
@@ -1,2 +0,0 @@
1
- import { Node } from '@babel/types';
2
- export declare const visitor: (ast: Node, options: any) => void;
@@ -1,5 +0,0 @@
1
- import traverse from '@babel/traverse';
2
- // TODO: options type
3
- export const visitor = (ast, options) => {
4
- (traverse.default || traverse)(ast, options);
5
- };