wrec 0.31.4 → 0.31.6
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/package.json +4 -1
- package/scripts/scaffold.js +40 -0
- package/scripts/template.ts +20 -0
package/package.json
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
"name": "wrec",
|
|
3
3
|
"description": "a small library that greatly simplifies building web components",
|
|
4
4
|
"author": "R. Mark Volkmann",
|
|
5
|
-
"version": "0.31.
|
|
5
|
+
"version": "0.31.6",
|
|
6
6
|
"license": "MIT",
|
|
7
7
|
"repository": {
|
|
8
8
|
"type": "git",
|
|
@@ -30,12 +30,15 @@
|
|
|
30
30
|
},
|
|
31
31
|
"bin": {
|
|
32
32
|
"wrec-lint": "./scripts/lint.js",
|
|
33
|
+
"wrec-scaffold": "./scripts/scaffold.js",
|
|
33
34
|
"wrec-usedby": "./scripts/used-by.js"
|
|
34
35
|
},
|
|
35
36
|
"files": [
|
|
36
37
|
"dist",
|
|
37
38
|
"scripts/ast-utils.js",
|
|
38
39
|
"scripts/lint.js",
|
|
40
|
+
"scripts/scaffold.js",
|
|
41
|
+
"scripts/template.ts",
|
|
39
42
|
"scripts/used-by.js",
|
|
40
43
|
"README.md"
|
|
41
44
|
],
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
import fs from 'node:fs';
|
|
4
|
+
import path from 'node:path';
|
|
5
|
+
import {fileURLToPath} from 'node:url';
|
|
6
|
+
|
|
7
|
+
function fail(message) {
|
|
8
|
+
console.error(message);
|
|
9
|
+
process.exit(1);
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
function toClassName(tagName) {
|
|
13
|
+
return tagName
|
|
14
|
+
.split('-')
|
|
15
|
+
.filter(Boolean)
|
|
16
|
+
.map(part => part[0].toUpperCase() + part.slice(1))
|
|
17
|
+
.join('');
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
const [tagName] = process.argv.slice(2);
|
|
21
|
+
|
|
22
|
+
if (!tagName) fail('usage: npx wrec-scaffold {tag-name}');
|
|
23
|
+
if (!tagName.includes('-')) fail('tag name must contain at least one hyphen');
|
|
24
|
+
|
|
25
|
+
const className = toClassName(tagName);
|
|
26
|
+
const __filename = fileURLToPath(import.meta.url);
|
|
27
|
+
const __dirname = path.dirname(__filename);
|
|
28
|
+
const templatePath = path.join(__dirname, 'template.ts');
|
|
29
|
+
const outputPath = path.resolve(process.cwd(), `${tagName}.ts`);
|
|
30
|
+
|
|
31
|
+
if (fs.existsSync(outputPath)) {
|
|
32
|
+
fail(`file already exists: ${outputPath}`);
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
const template = fs.readFileSync(templatePath, 'utf8');
|
|
36
|
+
const output = template
|
|
37
|
+
.replaceAll('{class}', className)
|
|
38
|
+
.replaceAll('{tag}', tagName);
|
|
39
|
+
|
|
40
|
+
fs.writeFileSync(outputPath, output);
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import {css, html, Wrec} from 'wrec';
|
|
2
|
+
|
|
3
|
+
class {class} extends Wrec {
|
|
4
|
+
static properties = {
|
|
5
|
+
name: {type: String, value: 'World'},
|
|
6
|
+
};
|
|
7
|
+
|
|
8
|
+
static css = css`
|
|
9
|
+
p {
|
|
10
|
+
color: blue;
|
|
11
|
+
font-family: fantasy;
|
|
12
|
+
}
|
|
13
|
+
`;
|
|
14
|
+
|
|
15
|
+
static html = html`
|
|
16
|
+
<p>Hello, <span>this.name</span>!</p>
|
|
17
|
+
`;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
{class}.define('{tag}');
|