Skip to content

Commit

Permalink
feat(bin): support --typescript that create TypeScript project
Browse files Browse the repository at this point in the history
  • Loading branch information
azu committed Oct 20, 2019
1 parent 4bc1232 commit 01f6872
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 5 deletions.
13 changes: 9 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ Create textlint rule with no configuration.

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


## Install

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

Usage of `create-textlint-rule` command.

$ create-textlint-rule --help
Usage
$ create-textlint-rule rule-name

Options
--help Show help
--yarn Use yarn for installing
--typescript Create TypeScript project
--yes Pass --yes all for initializing process

Examples
# create textlint-rule-example directory and install
$ create-textlint-rule example
# install to current directory
$ create-textlint-rule .

# create textlint-rule-example directory is based on TypeScript
$ create-textlint-rule example --typescript

Create textlint rule project by following command:

```sh
Expand All @@ -40,7 +41,8 @@ $ create-textlint-rule no-todo
```

You can start to develop textlint rule.
(See [textlint-scripts](https://github.com/textlint/textlint-scripts "textlint-scripts") for more details.)

For more details, see [textlint-scripts](https://github.com/textlint/textlint-scripts "textlint-scripts").

### Build

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

- [textlint/textlint-rule-template: This is TEMPLATE REPOSITORY for creating textlint rule.](https://github.com/textlint/textlint-rule-template)
- JavaScript Template
- [https://github.com/textlint/textlint-rule-template-ts#textlint-rule-template](https://github.com/textlint/textlint-rule-template-ts#textlint-rule-template)
- TypeScript Template
- [textlint/textlint-scripts: textlint npm-run-scripts CLI help to create textlint rule.](https://github.com/textlint/textlint-scripts)
- [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.")

Expand Down
4 changes: 4 additions & 0 deletions bin/cmd.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,16 @@ const cli = meow(
Options
--help Show help
--yarn Use yarn for installing
--typescript Create TypeScript project
--yes Pass --yes all for initializing process
Examples
# create textlint-rule-example directory and install
$ create-textlint-rule example
# install to current directory
$ create-textlint-rule .
# create textlint-rule-example directory is based on TypeScript
$ create-textlint-rule example --typescript
`,
{
alias: {
Expand All @@ -45,6 +48,7 @@ if (cli.input.length === 0 || cli.flags.help) {
cliHandler(cli.input[0], {
yes: cli.flags.yes,
yarn: cli.flags.yarn,
typescript: cli.flags.typescript,
cwd: process.cwd()
})
.then(() => {
Expand Down
7 changes: 6 additions & 1 deletion lib/scripts/create-textlint-rule.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,15 @@ const chalk = require("chalk");
* @param {{
* yes: boolean
* yarn: boolean
* typescript: boolean
* cwd: string
* }} [options]
* @returns {Promise}
*/
module.exports = function(projectName, options = {}) {
const useYarn = options.yarn !== undefined;
const useYes = options.yes !== undefined;
const useTypeScript = options.typescript !== undefined;
const isInitInCurrentDir = projectName === ".";
const ruleName = isInitInCurrentDir
? path.basename(options.cwd)
Expand All @@ -26,8 +28,11 @@ module.exports = function(projectName, options = {}) {
throw new Error(`Current directory name should start with "textlint-rule-<rule-name>": ${ruleName}.`);
}
const ruleDir = isInitInCurrentDir ? options.cwd : path.join(options.cwd, ruleName);
const gitRepositoryUrl = useTypeScript
? "https://github.com/textlint/textlint-rule-template-ts.git"
: "https://github.com/textlint/textlint-rule-template.git";
return spawn(`git`, [
"clone", "--depth=1", "https://github.com/textlint/textlint-rule-template.git",
"clone", "--depth=1", gitRepositoryUrl,
isInitInCurrentDir ? "." : ruleName
], {
stdio: "inherit"
Expand Down

0 comments on commit 01f6872

Please sign in to comment.