Skip to content

Commit 06b338d

Browse files
add plop for new components
1 parent ee2fa72 commit 06b338d

File tree

7 files changed

+123
-0
lines changed

7 files changed

+123
-0
lines changed

package.json

+1
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
"husky": "^0.13.4",
3535
"lerna": "^2.0.0-rc.5",
3636
"lint-staged": "^3.6.1",
37+
"plop": "^1.8.0",
3738
"preact": "^8.1.0",
3839
"preact-compat": "^3.16.0",
3940
"prettier": "^1.4.4",

packages/plop-pack-ocode/index.js

+64
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
const fs = require("fs");
2+
3+
/**
4+
* Ensures package names are namespaced into @ocode
5+
*/
6+
function normalizePackageName(str) {
7+
if (str.startsWith("@ocode")) {
8+
return str;
9+
} else {
10+
return `@ocode/${str}`;
11+
}
12+
}
13+
14+
module.exports = function(plop) {
15+
// create your generators here
16+
plop.setGenerator("new-component", {
17+
description: "scaffold a new preact component with @ocode constants",
18+
prompts: [
19+
{
20+
type: "input",
21+
name: "name",
22+
message: "What is the naem of this component?",
23+
validate: function(value) {
24+
const desiredPackageName = value;
25+
if (/.+/.test(desiredPackageName)) {
26+
const packages = fs.readdirSync("./packages");
27+
if (packages.includes(desiredPackageName)) {
28+
return "name conflicts with existing package";
29+
}
30+
return true;
31+
}
32+
return "name is required";
33+
}
34+
}, {
35+
type: "input",
36+
name: "description",
37+
message: "What does this component do?",
38+
validate: function(value) {
39+
if (/.+/.test(value)) {
40+
return true;
41+
}
42+
return "description is required";
43+
}
44+
}
45+
],
46+
actions: [
47+
{
48+
type: "add",
49+
path: "packages/{{dashCase name}}/package.json",
50+
templateFile: "templates/package.json.tpl"
51+
},
52+
{
53+
type: "add",
54+
path: "packages/{{dashCase name}}/src/index.js",
55+
templateFile: "templates/index.js.tpl"
56+
},
57+
{
58+
type: "add",
59+
path: "packages/{{dashCase name}}/stories.js",
60+
templateFile: "templates/stories.js.tpl"
61+
}
62+
]
63+
});
64+
};

packages/plop-pack-ocode/package.json

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{
2+
"name": "@ocode/plop-pack-ocode",
3+
"version": "1.0.0",
4+
"description": "Scaffolding for new packages in this repo",
5+
"main": "index.js",
6+
"author": "Chris Biscardi <[email protected]",
7+
"license": "MIT"
8+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
import { css } from "fam";
2+
import { h, Component } from "preact";
3+
// import { buttons, sizes } from "@ocode/constants/lib/buttons";
4+
5+
const CSS = css({
6+
fontFamily: "system"
7+
});
8+
9+
export default class {{pascalCase name}} extends Component {
10+
render(props) {
11+
return (
12+
<div class={CSS} {...props}>
13+
{children}
14+
</div>
15+
);
16+
}
17+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
{
2+
"name": "@ocode/{{name}}",
3+
"version": "1.0.0",
4+
"description": "{{description}}",
5+
"main": "lib/index.js",
6+
"author": "Chris Biscardi <[email protected]",
7+
"license": "MIT",
8+
"scripts": {
9+
"build": "babel src --out-dir lib --source-maps"
10+
},
11+
"dependencies": {
12+
"@ocode/constants": "*"
13+
}
14+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import { h, render, Component } from "preact";
2+
3+
// Tell Babel to transform JSX into h() calls:
4+
/** @jsx h */
5+
6+
import { storiesOf } from "@storybook/react";
7+
import { action } from "@storybook/addon-actions";
8+
import {{pascalCase name}} from ".";
9+
import { css } from "fam";
10+
11+
storiesOf("{{pascalCase name}}", module).add("usage", () =>
12+
<div>
13+
<h1>Variants</h1>
14+
<{{pascalCase name}}>Stuff?</{{pascalCase name}}>
15+
</div>
16+
);

plopfile.js

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
module.exports = function(plop) {
2+
plop.load('./packages/plop-pack-ocode');
3+
}

0 commit comments

Comments
 (0)