@htmlplus/element 0.4.3 → 0.4.5
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/compiler/plugins/{external.d.ts → assets.d.ts} +3 -3
- package/compiler/plugins/assets.js +26 -0
- package/compiler/plugins/customElement.js +66 -34
- package/compiler/plugins/customElementReact/customElementReact.js +10 -9
- package/compiler/plugins/customElementReact/templates/src/components/{{fileName}}.ts.hbs +1 -1
- package/compiler/plugins/document.d.ts +2 -4
- package/compiler/plugins/document.js +219 -226
- package/compiler/plugins/extract.js +7 -6
- package/compiler/plugins/index.d.ts +2 -1
- package/compiler/plugins/index.js +2 -1
- package/compiler/plugins/parse.js +1 -4
- package/compiler/plugins/read.js +4 -8
- package/compiler/plugins/style.d.ts +1 -3
- package/compiler/plugins/style.js +19 -21
- package/compiler/plugins/validate.js +1 -4
- package/compiler/plugins/visualStudioCode.d.ts +8 -0
- package/compiler/plugins/visualStudioCode.js +28 -0
- package/compiler/plugins/webTypes.d.ts +11 -0
- package/compiler/plugins/webTypes.js +79 -0
- package/compiler/utils/addDependency.d.ts +2 -0
- package/compiler/utils/addDependency.js +41 -0
- package/compiler/utils/getType.js +1 -1
- package/compiler/utils/index.d.ts +1 -0
- package/compiler/utils/index.js +1 -0
- package/compiler/utils/isDirectoryEmpty.js +1 -1
- package/compiler/utils/renderTemplate.js +2 -4
- package/constants/index.d.ts +1 -0
- package/constants/index.js +2 -0
- package/package.json +1 -2
- package/types/context.d.ts +1 -0
- package/compiler/plugins/external.js +0 -25
- package/compiler/plugins/vscode.d.ts +0 -11
- package/compiler/plugins/vscode.js +0 -83
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
const defaults = {};
|
|
2
|
+
export const visualStudioCode = (options) => {
|
|
3
|
+
const name = 'visualStudioCode';
|
|
4
|
+
options = Object.assign({}, defaults, options);
|
|
5
|
+
const finish = (global) => {
|
|
6
|
+
// TODO
|
|
7
|
+
// {
|
|
8
|
+
// version: 1.1,
|
|
9
|
+
// tags: [
|
|
10
|
+
// {
|
|
11
|
+
// name: context.componentKey,
|
|
12
|
+
// description: {
|
|
13
|
+
// kind: 'markdown',
|
|
14
|
+
// value: description
|
|
15
|
+
// },
|
|
16
|
+
// attributes: properties,
|
|
17
|
+
// references: [
|
|
18
|
+
// {
|
|
19
|
+
// name: 'Source code',
|
|
20
|
+
// url: `https://github.com/htmlplus/core/tree/main/src/components/${context.directoryName}/${context.fileName}.tsx`
|
|
21
|
+
// }
|
|
22
|
+
// ]
|
|
23
|
+
// }
|
|
24
|
+
// ]
|
|
25
|
+
// };
|
|
26
|
+
};
|
|
27
|
+
return { name, finish };
|
|
28
|
+
};
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { Global } from '../../types/index.js';
|
|
2
|
+
export interface WebTypesOptions {
|
|
3
|
+
destination: string;
|
|
4
|
+
packageName: string;
|
|
5
|
+
packageVersion: string;
|
|
6
|
+
docUrl: () => string;
|
|
7
|
+
}
|
|
8
|
+
export declare const webTypes: (options: WebTypesOptions) => {
|
|
9
|
+
name: string;
|
|
10
|
+
finish: (global: Global) => void;
|
|
11
|
+
};
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
import { camelCase, paramCase } from 'change-case';
|
|
2
|
+
import fs from 'fs-extra';
|
|
3
|
+
import path from 'path';
|
|
4
|
+
import { getTags, print } from '../utils/index.js';
|
|
5
|
+
const defaults = {};
|
|
6
|
+
export const webTypes = (options) => {
|
|
7
|
+
const name = 'webTypes';
|
|
8
|
+
options = Object.assign({}, defaults, options);
|
|
9
|
+
const finish = (global) => {
|
|
10
|
+
const json = {
|
|
11
|
+
'$schema': 'http://json.schemastore.org/web-types',
|
|
12
|
+
'name': options.packageName,
|
|
13
|
+
'version': options.packageVersion,
|
|
14
|
+
'description-markup': 'markdown',
|
|
15
|
+
'framework-config': {
|
|
16
|
+
'enable-when': {
|
|
17
|
+
'node-packages': [options.packageName]
|
|
18
|
+
}
|
|
19
|
+
},
|
|
20
|
+
'contributions': {
|
|
21
|
+
html: {
|
|
22
|
+
elements: global.contexts
|
|
23
|
+
.sort((a, b) => ((a.componentTag || '') > (b.componentTag || '') ? 1 : -1))
|
|
24
|
+
.map((context) => {
|
|
25
|
+
var _a, _b;
|
|
26
|
+
return ({
|
|
27
|
+
'name': context.componentTag,
|
|
28
|
+
'description': '',
|
|
29
|
+
'doc-url': options.docUrl(),
|
|
30
|
+
'js': {
|
|
31
|
+
properties: [
|
|
32
|
+
...(context.classProperties || []).map((property) => {
|
|
33
|
+
var _a, _b;
|
|
34
|
+
return ({
|
|
35
|
+
name: camelCase(property.key['name']),
|
|
36
|
+
description: (_a = getTags(property).find((tag) => !tag.key)) === null || _a === void 0 ? void 0 : _a.value,
|
|
37
|
+
value: {
|
|
38
|
+
type: print((_b = property.typeAnnotation) === null || _b === void 0 ? void 0 : _b['typeAnnotation'])
|
|
39
|
+
}
|
|
40
|
+
});
|
|
41
|
+
}),
|
|
42
|
+
...(context.classMethods || []).map((method) => {
|
|
43
|
+
var _a;
|
|
44
|
+
return ({
|
|
45
|
+
name: camelCase(method.key['name']),
|
|
46
|
+
description: (_a = getTags(method).find((tag) => !tag.key)) === null || _a === void 0 ? void 0 : _a.value,
|
|
47
|
+
value: {}
|
|
48
|
+
});
|
|
49
|
+
})
|
|
50
|
+
],
|
|
51
|
+
events: (_a = context.classEvents) === null || _a === void 0 ? void 0 : _a.map((event) => {
|
|
52
|
+
var _a;
|
|
53
|
+
return ({
|
|
54
|
+
name: paramCase(event.key['name']),
|
|
55
|
+
description: (_a = getTags(event).find((tag) => !tag.key)) === null || _a === void 0 ? void 0 : _a.value
|
|
56
|
+
});
|
|
57
|
+
})
|
|
58
|
+
},
|
|
59
|
+
'attributes': (_b = context.classProperties) === null || _b === void 0 ? void 0 : _b.map((property) => {
|
|
60
|
+
var _a, _b;
|
|
61
|
+
return ({
|
|
62
|
+
name: paramCase(property.key['name']),
|
|
63
|
+
description: (_a = getTags(property).find((tag) => !tag.key)) === null || _a === void 0 ? void 0 : _a.value,
|
|
64
|
+
value: {
|
|
65
|
+
type: print((_b = property.typeAnnotation) === null || _b === void 0 ? void 0 : _b['typeAnnotation'])
|
|
66
|
+
}
|
|
67
|
+
});
|
|
68
|
+
})
|
|
69
|
+
});
|
|
70
|
+
})
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
};
|
|
74
|
+
const dirname = path.dirname(options.destination);
|
|
75
|
+
fs.ensureDirSync(dirname);
|
|
76
|
+
fs.writeJSONSync(options.destination, json, { encoding: 'utf8', spaces: 2 });
|
|
77
|
+
};
|
|
78
|
+
return { name, finish };
|
|
79
|
+
};
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import t from '@babel/types';
|
|
2
|
+
import { visitor } from './visitor.js';
|
|
3
|
+
export const addDependency = (file, source, imported, local, isDefault) => {
|
|
4
|
+
let node;
|
|
5
|
+
visitor(file, {
|
|
6
|
+
ImportDeclaration(path) {
|
|
7
|
+
if (path.node.source.value != source)
|
|
8
|
+
return;
|
|
9
|
+
node = path.node;
|
|
10
|
+
}
|
|
11
|
+
});
|
|
12
|
+
let specifier = node === null || node === void 0 ? void 0 : node.specifiers.find((specifier) => {
|
|
13
|
+
var _a;
|
|
14
|
+
if (isDefault) {
|
|
15
|
+
return specifier.type == 'ImportDefaultSpecifier';
|
|
16
|
+
}
|
|
17
|
+
else {
|
|
18
|
+
return ((_a = specifier.imported) === null || _a === void 0 ? void 0 : _a.name) == imported;
|
|
19
|
+
}
|
|
20
|
+
});
|
|
21
|
+
if (specifier)
|
|
22
|
+
return specifier.local.name;
|
|
23
|
+
if (isDefault) {
|
|
24
|
+
specifier = t.importDefaultSpecifier(t.identifier(imported));
|
|
25
|
+
}
|
|
26
|
+
else {
|
|
27
|
+
specifier = t.importSpecifier(t.identifier(local !== null && local !== void 0 ? local : imported), t.identifier(imported));
|
|
28
|
+
}
|
|
29
|
+
if (node) {
|
|
30
|
+
if (isDefault) {
|
|
31
|
+
node.specifiers.unshift(specifier);
|
|
32
|
+
}
|
|
33
|
+
else {
|
|
34
|
+
node.specifiers.push(specifier);
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
else {
|
|
38
|
+
file.program.body.unshift(t.importDeclaration([specifier], t.stringLiteral(source)));
|
|
39
|
+
}
|
|
40
|
+
return isDefault ? imported : local !== null && local !== void 0 ? local : imported;
|
|
41
|
+
};
|
package/compiler/utils/index.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import glob from 'fast-glob';
|
|
2
|
-
import fs from 'fs';
|
|
2
|
+
import fs from 'fs-extra';
|
|
3
3
|
import handlebars from 'handlebars';
|
|
4
4
|
import path from 'path';
|
|
5
5
|
export const renderTemplate = (source, destination, options) => (context) => {
|
|
@@ -17,9 +17,7 @@ export const renderTemplate = (source, destination, options) => (context) => {
|
|
|
17
17
|
const directory = path.dirname(to);
|
|
18
18
|
const raw = fs.readFileSync(from, 'utf8');
|
|
19
19
|
const template = handlebars.compile(raw)(context);
|
|
20
|
-
|
|
21
|
-
fs.mkdirSync(directory, { recursive: true });
|
|
22
|
-
}
|
|
20
|
+
fs.ensureDirSync(directory);
|
|
23
21
|
fs.writeFileSync(to, template, 'utf8');
|
|
24
22
|
}
|
|
25
23
|
};
|
package/constants/index.d.ts
CHANGED
package/constants/index.js
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@htmlplus/element",
|
|
3
|
-
"version": "0.4.
|
|
3
|
+
"version": "0.4.5",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"author": "Masood Abdolian <m.abdolian@gmail.com>",
|
|
6
6
|
"description": "Compiler of HTMLPlus",
|
|
@@ -41,7 +41,6 @@
|
|
|
41
41
|
"fast-glob": "^3.2.11",
|
|
42
42
|
"fs-extra": "^10.1.0",
|
|
43
43
|
"handlebars": "^4.7.7",
|
|
44
|
-
"listr2": "^5.0.1",
|
|
45
44
|
"ora": "^6.1.2",
|
|
46
45
|
"typescript": "^4.7.4"
|
|
47
46
|
},
|
package/types/context.d.ts
CHANGED
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
import fs from 'fs-extra';
|
|
2
|
-
import path from 'path';
|
|
3
|
-
const defaults = {
|
|
4
|
-
source(context) {
|
|
5
|
-
return path.join(context.directoryPath, 'external');
|
|
6
|
-
},
|
|
7
|
-
destination(context) {
|
|
8
|
-
return '';
|
|
9
|
-
}
|
|
10
|
-
};
|
|
11
|
-
export const external = (options) => {
|
|
12
|
-
const name = 'external';
|
|
13
|
-
options = Object.assign(Object.assign({}, defaults), options);
|
|
14
|
-
const next = (context) => {
|
|
15
|
-
var _a;
|
|
16
|
-
const source = (_a = options.source) === null || _a === void 0 ? void 0 : _a.call(options, context);
|
|
17
|
-
if (!source || !fs.existsSync(source))
|
|
18
|
-
return;
|
|
19
|
-
fs.copySync(source, options.destination(context));
|
|
20
|
-
};
|
|
21
|
-
return {
|
|
22
|
-
name,
|
|
23
|
-
next
|
|
24
|
-
};
|
|
25
|
-
};
|
|
@@ -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
|
-
};
|