-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(scripts): support current dir(.)
``` $ npm init textlint-rule . ```
- Loading branch information
Showing
6 changed files
with
510 additions
and
321 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,19 @@ | ||
// MIT © 2016 azu | ||
"use strict"; | ||
const chalk = require('chalk'); | ||
const path = require("path"); | ||
const chalk = require("chalk"); | ||
const createTextlintRule = require("./scripts/create-textlint-rule"); | ||
module.exports = function(projectName, flags) { | ||
const ruleName = `textlint-rule-${projectName.replace(/^textlint-rule-/, '')}`; | ||
return createTextlintRule(ruleName, flags).then(() => { | ||
console.log(chalk.green(`✔ Complete: Let's create textlint rule`)); | ||
/** | ||
* @param {string} projectName | ||
* @param {{ | ||
* yes: boolean | ||
* yarn: boolean | ||
* cwd: string | ||
* }} options | ||
* @returns {Promise<any | never>} | ||
*/ | ||
module.exports = function(projectName, options = {}) { | ||
return createTextlintRule(projectName, options).then(() => { | ||
console.log(chalk.green(`✔ Complete: Let's write textlint rule`)); | ||
}); | ||
}; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,65 +1,65 @@ | ||
// MIT © 2016 azu | ||
"use strict"; | ||
const spawn = require('cross-spawn-promise'); | ||
const spawn = require("cross-spawn-promise"); | ||
const path = require("path"); | ||
const rimraf = require("rimraf"); | ||
const chalk = require('chalk'); | ||
const chalk = require("chalk"); | ||
|
||
/** | ||
* @see https://github.com/textlint/textlint-rule-template | ||
* @param {string} ruleName | ||
* @param {Object} [options] | ||
* @param {string} projectName | ||
* @param {{ | ||
* yes: boolean | ||
* yarn: boolean | ||
* cwd: string | ||
* }} [options] | ||
* @returns {Promise} | ||
*/ | ||
module.exports = function(ruleName, options = {}) { | ||
module.exports = function(projectName, options = {}) { | ||
const useYarn = options.yarn !== undefined; | ||
const useYes = options.yes !== undefined; | ||
const cwd = process.cwd(); | ||
const ruleDir = path.join(cwd, ruleName); | ||
const isInitInCurrentDir = projectName === "."; | ||
const ruleName = isInitInCurrentDir | ||
? path.dirname(projectName) | ||
: `textlint-rule-${projectName.replace(/^textlint-rule-/, "")}`; | ||
const ruleDir = isInitInCurrentDir ? options.cwd : path.join(options.cwd, ruleName); | ||
return spawn(`git`, [ | ||
"clone", | ||
"--depth=1", | ||
"https://github.com/textlint/textlint-rule-template.git", | ||
ruleName | ||
], {stdio: 'inherit'}).then(() => { | ||
console.log(chalk.green(`cd ${ruleDir}`)); | ||
process.chdir(ruleDir); | ||
}).then(() => { | ||
const gitDir = path.join(ruleDir, ".git"); | ||
rimraf.sync(gitDir) | ||
}).then(() => { | ||
const README = path.join(ruleDir, "README.md"); | ||
rimraf.sync(README); | ||
}).then(() => { | ||
return spawn("git", [ | ||
"init" | ||
], {stdio: 'inherit'}); | ||
}).then(() => { | ||
console.log(chalk.green(`Input information about your textlint rule`)); | ||
return spawn("npm", | ||
["init"].concat(useYes ? ["--yes"] : []), | ||
{stdio: 'inherit'}); | ||
}).then(() => { | ||
console.log(chalk.green(`Wait... Installing npm packages for development`)); | ||
if (useYarn) { | ||
return spawn("yarn", | ||
[ | ||
"install" | ||
], | ||
{stdio: 'inherit'}); | ||
|
||
} else { | ||
return spawn("npm", | ||
[ | ||
"install" | ||
], | ||
{stdio: 'inherit'}); | ||
|
||
} | ||
}).then(() => { | ||
console.log(chalk.green(`Setup your README!`)); | ||
return spawn(`./node_modules/.bin/textlint-scripts`, [ | ||
"init" | ||
], {stdio: 'inherit'}); | ||
}); | ||
}; | ||
"clone", "--depth=1", "https://github.com/textlint/textlint-rule-template.git", | ||
isInitInCurrentDir ? "." : ruleName | ||
], { | ||
stdio: "inherit" | ||
}) | ||
.then(() => { | ||
if (!isInitInCurrentDir) { | ||
console.log(chalk.green(`cd ${ruleDir}`)); | ||
process.chdir(ruleDir); | ||
} | ||
}) | ||
.then(() => { | ||
const gitDir = path.join(ruleDir, ".git"); | ||
rimraf.sync(gitDir); | ||
}) | ||
.then(() => { | ||
const README = path.join(ruleDir, "README.md"); | ||
rimraf.sync(README); | ||
}) | ||
.then(() => { | ||
return spawn("git", ["init"], { stdio: "inherit" }); | ||
}) | ||
.then(() => { | ||
console.log(chalk.green(`Input information about your textlint rule`)); | ||
return spawn("npm", ["init"].concat(useYes ? ["--yes"] : []), { stdio: "inherit" }); | ||
}) | ||
.then(() => { | ||
console.log(chalk.green(`Wait... Installing npm packages for development`)); | ||
if (useYarn) { | ||
return spawn("yarn", ["install"], { stdio: "inherit" }); | ||
} else { | ||
return spawn("npm", ["install"], { stdio: "inherit" }); | ||
} | ||
}) | ||
.then(() => { | ||
console.log(chalk.green(`Initialize your README!`)); | ||
return spawn(`./node_modules/.bin/textlint-scripts`, ["init"], { stdio: "inherit" }); | ||
}); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,17 @@ | ||
#!/bin/bash | ||
set -eux | ||
# test rule-name | ||
declare currentDir=$(cd $(dirname $0);pwd) | ||
declare dirName=$(basename "${currentDir}") | ||
declare parentDir=$(dirname "${currentDir}") | ||
declare testRuleName="test-rule-name"; | ||
# test | ||
echo "Run: create-textlint-rule ${test-rule-name}" | ||
cd ${currentDir} | ||
node ${parentDir}/bin/cmd.js "${testRuleName}" --yes | ||
rm -rf "${currentDir}/textlint-rule-${testRuleName}" | ||
# test . | ||
echo "Run: create-textlint-rule ." | ||
mkdir "textlint-rule-${testRuleName}" | ||
cd "textlint-rule-${testRuleName}" | ||
node ${parentDir}/bin/cmd.js "." --yes | ||
rm -rf "${currentDir}/textlint-rule-${testRuleName}" |
Oops, something went wrong.