Skip to content

Commit

Permalink
fix(deps): update modules and make Pure ESM (#31)
Browse files Browse the repository at this point in the history
BREAKING CHANGE: Require Node.js >=14.16
  • Loading branch information
azu authored Nov 20, 2022
1 parent e960082 commit 3c3f210
Show file tree
Hide file tree
Showing 7 changed files with 568 additions and 598 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ This command line tools generate textlint rule project files by one command.

Install with [npm](https://www.npmjs.com/):

npm install create-textlint-rule -g
npm install --global create-textlint-rule
# Or
npx create-textlint-rule

Expand Down
23 changes: 13 additions & 10 deletions bin/cmd.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
#!/usr/bin/env node
"use strict";
const meow = require("meow");
const chalk = require("chalk");
const updateNotifier = require("update-notifier");
const pkg = require("../package.json");
const cliHandler = require("../lib/cli-handler");
import meow from "meow";
import chalk from "chalk";
import updateNotifier from "update-notifier";
import cliHandler from "../lib/cli-handler.js";
import { readFile } from "node:fs/promises";
export const getPackageInfo = async () => {
const pkg = await readFile(new URL("../package.json", import.meta.url));
return JSON.parse(pkg);
};
const cli = meow(
`
Usage
Expand All @@ -25,9 +28,9 @@ const cli = meow(
$ create-textlint-rule example --typescript
`,
{
alias: {
h: "help"
}
importMeta: import.meta,
autoHelp: true,
autoVersion: true
}
);
/*
Expand All @@ -38,7 +41,7 @@ const cli = meow(
}
*/
updateNotifier({
pkg: pkg,
pkg: await getPackageInfo(),
updateCheckInterval: 1000 * 60 * 60 * 24 * 7
}).notify();

Expand Down
16 changes: 7 additions & 9 deletions lib/cli-handler.js
Original file line number Diff line number Diff line change
@@ -1,19 +1,17 @@
// MIT © 2016 azu
"use strict";
const path = require("path");
const chalk = require("chalk");
const createTextlintRule = require("./scripts/create-textlint-rule");
import chalk from "chalk";
import createTextlintRule from "./scripts/create-textlint-rule.js";

/**
* @param {string} projectName
* @param {{
* yes: boolean
* yarn: boolean
* yes: boolean,
* yarn: boolean,
* cwd: string
* }} options
* @returns {Promise<any | never>}
*/
module.exports = function (projectName, options = {}) {
export default function (projectName, options = {}) {
return createTextlintRule(projectName, options).then(() => {
console.log(chalk.green(`✔ Complete: Let's write textlint rule`));
});
};
}
20 changes: 9 additions & 11 deletions lib/scripts/create-textlint-rule.js
Original file line number Diff line number Diff line change
@@ -1,22 +1,20 @@
// MIT © 2016 azu
"use strict";
const spawn = require("cross-spawn-promise");
const path = require("path");
const rimraf = require("rimraf");
const chalk = require("chalk");
import rimraf from "rimraf";
import chalk from "chalk";
import spawn from "cross-spawn-promise";
import path from "node:path";

/**
* @see https://github.com/textlint/textlint-rule-template
* @param {string} projectName
* @param {{
* yes: boolean
* yarn: boolean
* typescript: boolean
* yes: boolean,
* yarn: boolean,
* typescript: boolean,
* cwd: string
* }} [options]
* @returns {Promise}
*/
module.exports = function (projectName, options = {}) {
export default function (projectName, options = {}) {
const useYarn = options.yarn !== undefined;
const useYes = options.yes !== undefined;
const useTypeScript = options.typescript !== undefined;
Expand Down Expand Up @@ -71,4 +69,4 @@ module.exports = function (projectName, options = {}) {
console.log(chalk.green(`Initialize your README!`));
return spawn(`./node_modules/.bin/textlint-scripts`, ["init"], { stdio: "inherit" });
});
};
}
79 changes: 39 additions & 40 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,65 +1,64 @@
{
"directories": {
"test": "test"
},
"author": "azu",
"license": "MIT",
"files": [
"bin/",
"lib/"
],
"name": "create-textlint-rule",
"version": "1.5.0",
"description": "Create textlint rule project with no configuration.",
"main": "lib/create-textlint-rule.js",
"bin": {
"create-textlint-rule": "bin/cmd.js"
},
"scripts": {
"test": "./test/test.sh",
"format": "prettier --write \"**/*.{js,jsx,ts,tsx,css}\"",
"prepare": "git config --local core.hooksPath .githooks"
},
"keywords": [
"textlint",
"tools",
"development",
"rule"
],
"homepage": "https://github.com/textlint/create-textlint-rule",
"bugs": {
"url": "https://github.com/textlint/create-textlint-rule/issues"
},
"repository": {
"type": "git",
"url": "https://github.com/textlint/create-textlint-rule.git"
},
"bugs": {
"url": "https://github.com/textlint/create-textlint-rule/issues"
"license": "MIT",
"author": "azu",
"type": "module",
"main": "lib/create-textlint-rule.js",
"bin": {
"create-textlint-rule": "bin/cmd.js"
},
"homepage": "https://github.com/textlint/create-textlint-rule",
"dependencies": {
"chalk": "^4.1.2",
"cross-spawn": "^7.0.3",
"cross-spawn-promise": "^0.10.2",
"meow": "^7.1.1",
"rimraf": "^3.0.2",
"update-notifier": "^5.1.0"
"directories": {
"test": "test"
},
"devDependencies": {
"lint-staged": "^13.0.3",
"prettier": "^2.7.1"
"files": [
"bin/",
"lib/"
],
"engines": {
"node": ">=14.16"
},
"scripts": {
"format": "prettier --write \"**/*.{js,jsx,ts,tsx,css}\"",
"prepare": "git config --local core.hooksPath .githooks",
"test": "./test/test.sh"
},
"lint-staged": {
"*.{js,jsx,ts,tsx,css}": [
"prettier --write"
]
},
"prettier": {
"singleQuote": false,
"printWidth": 120,
"singleQuote": false,
"tabWidth": 4,
"trailingComma": "none"
},
"husky": {
"hooks": {
"precommit": "lint-staged"
}
"dependencies": {
"chalk": "^5.1.2",
"cross-spawn": "^7.0.3",
"cross-spawn-promise": "^0.10.2",
"meow": "^11.0.0",
"rimraf": "^3.0.2",
"update-notifier": "^6.0.2"
},
"lint-staged": {
"*.{js,jsx,ts,tsx,css}": [
"prettier --write"
]
"devDependencies": {
"lint-staged": "^13.0.3",
"prettier": "^2.7.1"
}
}
8 changes: 8 additions & 0 deletions test/test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,17 @@ declare currentDir=$(cd $(dirname $0);pwd)
declare dirName=$(basename "${currentDir}")
declare parentDir=$(dirname "${currentDir}")
declare testRuleName="test-rule-name";
# test for js
echo "Run: create-textlint-rule ${test-rule-name}"
cd ${currentDir}
node ${parentDir}/bin/cmd.js "${testRuleName}" --yes
ls "${currentDir}/textlint-rule-${testRuleName}/package.json" # check file
rm -rf "${currentDir}/textlint-rule-${testRuleName}"
# test for ts
echo "Run: create-textlint-rule ${test-rule-name} --typescript"
cd ${currentDir}
node ${parentDir}/bin/cmd.js "${testRuleName}" --yes --typescript
ls "${currentDir}/textlint-rule-${testRuleName}/package.json" # check file
rm -rf "${currentDir}/textlint-rule-${testRuleName}"
# test .
echo "Run: create-textlint-rule ."
Expand Down
Loading

0 comments on commit 3c3f210

Please sign in to comment.