From 01f6872b67f49e5c834f3f240ed74fffdae29d1c Mon Sep 17 00:00:00 2001 From: azu Date: Sun, 20 Oct 2019 10:58:20 +0900 Subject: [PATCH] feat(bin): support --typescript that create TypeScript project --- README.md | 13 +++++++++---- bin/cmd.js | 4 ++++ lib/scripts/create-textlint-rule.js | 7 ++++++- 3 files changed, 19 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index e05061e..ff05aa9 100644 --- a/README.md +++ b/README.md @@ -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/): @@ -17,13 +16,13 @@ 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 @@ -31,7 +30,9 @@ Usage of `create-textlint-rule` command. $ 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 @@ -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 @@ -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.") diff --git a/bin/cmd.js b/bin/cmd.js index 2d61ebe..3f75fc5 100755 --- a/bin/cmd.js +++ b/bin/cmd.js @@ -13,6 +13,7 @@ const cli = meow( Options --help Show help --yarn Use yarn for installing + --typescript Create TypeScript project --yes Pass --yes all for initializing process Examples @@ -20,6 +21,8 @@ const cli = meow( $ 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: { @@ -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(() => { diff --git a/lib/scripts/create-textlint-rule.js b/lib/scripts/create-textlint-rule.js index 89557bf..841ce8f 100644 --- a/lib/scripts/create-textlint-rule.js +++ b/lib/scripts/create-textlint-rule.js @@ -11,6 +11,7 @@ const chalk = require("chalk"); * @param {{ * yes: boolean * yarn: boolean + * typescript: boolean * cwd: string * }} [options] * @returns {Promise} @@ -18,6 +19,7 @@ const chalk = require("chalk"); 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) @@ -26,8 +28,11 @@ module.exports = function(projectName, options = {}) { throw new Error(`Current directory name should start with "textlint-rule-": ${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"