Skip to content

Commit 01f6872

Browse files
committed
feat(bin): support --typescript that create TypeScript project
1 parent 4bc1232 commit 01f6872

File tree

3 files changed

+19
-5
lines changed

3 files changed

+19
-5
lines changed

README.md

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ Create textlint rule with no configuration.
44

55
This command line tools generate textlint rule project files by one command.
66

7-
87
## Install
98

109
Install with [npm](https://www.npmjs.com/):
@@ -17,21 +16,23 @@ Install with [npm](https://www.npmjs.com/):
1716

1817
Usage of `create-textlint-rule` command.
1918

20-
$ create-textlint-rule --help
2119
Usage
2220
$ create-textlint-rule rule-name
2321

2422
Options
2523
--help Show help
2624
--yarn Use yarn for installing
25+
--typescript Create TypeScript project
2726
--yes Pass --yes all for initializing process
2827

2928
Examples
3029
# create textlint-rule-example directory and install
3130
$ create-textlint-rule example
3231
# install to current directory
3332
$ create-textlint-rule .
34-
33+
# create textlint-rule-example directory is based on TypeScript
34+
$ create-textlint-rule example --typescript
35+
3536
Create textlint rule project by following command:
3637

3738
```sh
@@ -40,7 +41,8 @@ $ create-textlint-rule no-todo
4041
```
4142

4243
You can start to develop textlint rule.
43-
(See [textlint-scripts](https://github.com/textlint/textlint-scripts "textlint-scripts") for more details.)
44+
45+
For more details, see [textlint-scripts](https://github.com/textlint/textlint-scripts "textlint-scripts").
4446

4547
### Build
4648

@@ -76,6 +78,9 @@ You can learn to create textlint rule.
7678
This Command line tools based on these project.
7779

7880
- [textlint/textlint-rule-template: This is TEMPLATE REPOSITORY for creating textlint rule.](https://github.com/textlint/textlint-rule-template)
81+
- JavaScript Template
82+
- [https://github.com/textlint/textlint-rule-template-ts#textlint-rule-template](https://github.com/textlint/textlint-rule-template-ts#textlint-rule-template)
83+
- TypeScript Template
7984
- [textlint/textlint-scripts: textlint npm-run-scripts CLI help to create textlint rule.](https://github.com/textlint/textlint-scripts)
8085
- [facebookincubator/create-react-app: Create React apps with no build configuration.](https://github.com/facebookincubator/create-react-app "facebookincubator/create-react-app: Create React apps with no build configuration.")
8186

bin/cmd.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,16 @@ const cli = meow(
1313
Options
1414
--help Show help
1515
--yarn Use yarn for installing
16+
--typescript Create TypeScript project
1617
--yes Pass --yes all for initializing process
1718
1819
Examples
1920
# create textlint-rule-example directory and install
2021
$ create-textlint-rule example
2122
# install to current directory
2223
$ create-textlint-rule .
24+
# create textlint-rule-example directory is based on TypeScript
25+
$ create-textlint-rule example --typescript
2326
`,
2427
{
2528
alias: {
@@ -45,6 +48,7 @@ if (cli.input.length === 0 || cli.flags.help) {
4548
cliHandler(cli.input[0], {
4649
yes: cli.flags.yes,
4750
yarn: cli.flags.yarn,
51+
typescript: cli.flags.typescript,
4852
cwd: process.cwd()
4953
})
5054
.then(() => {

lib/scripts/create-textlint-rule.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,15 @@ const chalk = require("chalk");
1111
* @param {{
1212
* yes: boolean
1313
* yarn: boolean
14+
* typescript: boolean
1415
* cwd: string
1516
* }} [options]
1617
* @returns {Promise}
1718
*/
1819
module.exports = function(projectName, options = {}) {
1920
const useYarn = options.yarn !== undefined;
2021
const useYes = options.yes !== undefined;
22+
const useTypeScript = options.typescript !== undefined;
2123
const isInitInCurrentDir = projectName === ".";
2224
const ruleName = isInitInCurrentDir
2325
? path.basename(options.cwd)
@@ -26,8 +28,11 @@ module.exports = function(projectName, options = {}) {
2628
throw new Error(`Current directory name should start with "textlint-rule-<rule-name>": ${ruleName}.`);
2729
}
2830
const ruleDir = isInitInCurrentDir ? options.cwd : path.join(options.cwd, ruleName);
31+
const gitRepositoryUrl = useTypeScript
32+
? "https://github.com/textlint/textlint-rule-template-ts.git"
33+
: "https://github.com/textlint/textlint-rule-template.git";
2934
return spawn(`git`, [
30-
"clone", "--depth=1", "https://github.com/textlint/textlint-rule-template.git",
35+
"clone", "--depth=1", gitRepositoryUrl,
3136
isInitInCurrentDir ? "." : ruleName
3237
], {
3338
stdio: "inherit"

0 commit comments

Comments
 (0)