Skip to content

Commit 2b58c84

Browse files
Merge pull request #3 from dreamsicle-io/release/1.4.0-RC2
Release/1.4.0 rc2
2 parents b5c5a1d + 0ca0526 commit 2b58c84

14 files changed

+104
-18
lines changed

README.md

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ npx @dreamsicle.io/create-component [options] <name>
1212

1313
## Getting started
1414

15-
All that is necessary to start using the tool is a component name `name`, which corresponds to a pascal-cased string that will serve as the component name, and a relative `--path`/`-p` that contains a `_Template` directory.
15+
All that is necessary to start using the tool is a component name `name`, which corresponds to a pascal-cased string that will serve as the component name, and a relative `--path`/`-p` that contains a `_Template` directory (or other directory as specified by the `-t`/`--templateDir` option).
1616

1717
### 1. Install
1818

@@ -26,7 +26,7 @@ npm install --save-dev @dreamsicle.io/create-component
2626

2727
While it is possible to run this script directly, it is recommended that you add scripts to your `package.json` file in order to make using this tool easier and faster. The app structure isn't likely to change in any given project often, so this will help in making the usage more consistent.
2828

29-
The scripts `name` arg can be passed through to the script when running it through `npm`, therefore all that is recommended is to set up a script corresponding to each path that contains a `_Template` directory.
29+
The scripts `name` arg can be passed through to the script when running it through `npm`, therefore all that is recommended is to set up a script corresponding to each path that contains a `_Template` directory (or other directory as specified by the `-t`/`--templateDir` option).
3030

3131
**Setting up scripts is simple ― consider an application with the following structure:**
3232

@@ -55,6 +55,8 @@ The scripts `name` arg can be passed through to the script when running it throu
5555

5656
> **Note:** If your templates live outside of the directory you want them to be created in, use the `-o` or `--outputPath` option to set the output path.
5757
58+
> **Note:** If you want the template directory to have a different name than `_Template` for stylistic or conflict reasons, use the `-t`/`--templateDir` option.
59+
5860
### 3. Run the scripts
5961

6062
Given the scripts created in step #2 above, run them as follows ― being sure to provide a component name after the script name. These commands will clone the `_Template` directory in each of the corresponding project directories and will perform replacements both on the file names themselves as well as on the text content within the files.
@@ -82,7 +84,9 @@ The following table documents which text nodes will be operated on when the `_Te
8284
| `_version` | The root package's version | `1.0.0` | ✔️ ||
8385
| `_date` | The date as `m/d/yyyy` | `3/23/2022` | ✔️ ||
8486

85-
> **Note:** Version 2.0.0 will provide an API for adding custom replacements to the script.
87+
> **Note:** The `_Template` and `_template` replacements are not affected by the `-t`/`--templateDir` option.
88+
89+
> **Coming soon:** Version 2.0.0 will provide an API for adding custom replacements to the script.
8690
8791
## Logging
8892

@@ -114,17 +118,18 @@ npx @dreamsicle.io/create-component --help
114118
**The above would ouput the following help information:**
115119

116120
```
117-
Usage: npx @dreamsicle.io/create-component [options] <name>
121+
Usage: @dreamsicle.io/create-component [options] <name>
118122
119123
Create a templated component structure.
120124
121125
Arguments:
122-
name The name of the component
126+
name The name of the component
123127
124128
Options:
125-
-V, --version output the version number
126-
-p, --path <path> The relative path where the template to be used lives
127-
-o, --outputPath [path] The relative path where the component should be placed, if different from the template path
128-
-v, --verbose Output extra information to the console (default: false)
129-
-h, --help display help for command
129+
-V, --version output the version number
130+
-p, --path <string> The relative path where the template to be used lives
131+
-o, --outputPath [string] The relative path where the component should be placed, if different from the template path
132+
-t, --templateDir <string> The name of the template directory (default: "_Template")
133+
-v, --verbose Output extra information to the console (default: false)
134+
-h, --help display help for command
130135
```
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
// @ts-nocheck
2+
3+
import React from 'react';
4+
import classNames from 'classnames';
5+
import './_Template.scss';
6+
7+
export interface Props {
8+
id?: string;
9+
className?: string;
10+
children?: React.ReactNode;
11+
}
12+
13+
export interface State {}
14+
15+
/**
16+
* Components / _Template
17+
*
18+
* Describe the custom `_Template` component's use cases here.
19+
* Include what it does, why it was developed, and why
20+
* it's awesome.
21+
*
22+
* @since _version Added by the `create-component` script on `_date`
23+
*/
24+
class _Template extends React.Component<Props, State> {
25+
static defaultProps: Props = {};
26+
27+
constructor(props: Props) {
28+
super(props);
29+
this.state = {};
30+
}
31+
32+
render() {
33+
const { id, className, children } = this.props;
34+
const {} = this.state;
35+
const containerClass = classNames('_Template', className);
36+
return (
37+
<div id={id} className={containerClass}>
38+
<h3>
39+
Hello from the <code>_Template</code> component.
40+
</h3>
41+
{children}
42+
</div>
43+
);
44+
}
45+
}
46+
47+
export default _Template;
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
// @ts-nocheck
2+
3+
/**
4+
* This is a test `_Template` util functions file.
5+
*
6+
* @since _version Added on `_date`
7+
*/
8+
export function _TemplateUtil() {
9+
console.log(`Hello from the _Template utils file!`);
10+
}

examples/components/_Template/_Template.scss

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
// @ts-nocheck
2+
13
@import '../../mixins';
24

35
._Template {

examples/components/_Template/_Template.stories.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
// @ts-nocheck
2+
13
import React from 'react';
24
import { ComponentStory, ComponentMeta } from '@storybook/react';
35
import _Template from './_Template';

examples/components/_Template/_Template.test.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
// @ts-nocheck
2+
13
import React from 'react';
24
import { render } from '@testing-library/react';
35
import _Template from './_Template';

examples/components/_Template/_Template.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
// @ts-nocheck
2+
13
import React from 'react';
24
import classNames from 'classnames';
35
import './_Template.scss';

examples/components/_Template/unmodified.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
// @ts-nocheck
2+
13
/**
24
* This tests an unmodified file.
35
*/

examples/components/_Template/utils/_Template.utils.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
// @ts-nocheck
2+
13
/**
24
* This is a test `_Template` util class file.
35
*

examples/components/_Template/utils/_template-utils.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
// @ts-nocheck
2+
13
/**
24
* This is a test `_Template` util functions file.
35
*

examples/components/_Template/utils/nested-unmodified.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
// @ts-nocheck
2+
13
/**
24
* This tests a nested unmodified file.
35
*/

index.js

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import zod from 'zod';
1313
* @typedef {object} Options
1414
* @property {string} path
1515
* @property {string} outputPath
16+
* @property {string} templateDir
1617
* @property {boolean} verbose
1718
*/
1819

@@ -99,7 +100,7 @@ let options;
99100
const program = new Command();
100101
program
101102
.version(pkg.version)
102-
.name('npx @dreamsicle.io/create-component')
103+
.name('@dreamsicle.io/create-component')
103104
.description('Create a templated component structure.')
104105
// Construct arguments.
105106
.argument(
@@ -112,19 +113,27 @@ program
112113
)
113114
// Construct options.
114115
.option(
115-
'-p, --path <path>',
116+
'-p, --path <string>',
116117
'The relative path where the template to be used lives',
117118
(value) => {
118119
return zod.string().trim().safeParse(value).data || '';
119120
}
120121
)
121122
.option(
122-
'-o, --outputPath [path]',
123+
'-o, --outputPath [string]',
123124
'The relative path where the component should be placed, if different from the template path',
124125
(value) => {
125126
return zod.string().trim().safeParse(value).data || '';
126127
}
127128
)
129+
.option(
130+
'-t, --templateDir <string>',
131+
'The name of the template directory',
132+
(value) => {
133+
return zod.string().trim().safeParse(value).data || '';
134+
},
135+
'_Template'
136+
)
128137
.option(
129138
'-v, --verbose',
130139
'Output extra information to the console',
@@ -135,7 +144,7 @@ program
135144
// Initialize args and options.
136145
options = { ...opts };
137146
componentName = name;
138-
srcPath = path.resolve(options.path, '_Template');
147+
srcPath = path.resolve(options.path, options.templateDir);
139148
tmpPath = path.resolve(tmpDirPath, componentName);
140149
destPath = path.resolve(options.outputPath || options.path, componentName);
141150
// Run creation.
@@ -254,7 +263,6 @@ function validate() {
254263
}
255264
// Check if the component directory already exists.
256265
if (fs.existsSync(destPath)) {
257-
258266
throw new Error(`There is already a directory at "${path.relative(cwd, destPath)}"`);
259267
}
260268
}

package-lock.json

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@dreamsicle.io/create-component",
3-
"version": "2.0.0",
3+
"version": "1.4.0",
44
"type": "module",
55
"main": "index.js",
66
"license": "MIT",

0 commit comments

Comments
 (0)