Skip to content

Commit 3c3f210

Browse files
authoredNov 20, 2022
fix(deps): update modules and make Pure ESM (#31)
BREAKING CHANGE: Require Node.js >=14.16
1 parent e960082 commit 3c3f210

File tree

7 files changed

+568
-598
lines changed

7 files changed

+568
-598
lines changed
 

Diff for: ‎README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ This command line tools generate textlint rule project files by one command.
88

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

11-
npm install create-textlint-rule -g
11+
npm install --global create-textlint-rule
1212
# Or
1313
npx create-textlint-rule
1414

Diff for: ‎bin/cmd.js

+13-10
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,13 @@
11
#!/usr/bin/env node
2-
"use strict";
3-
const meow = require("meow");
4-
const chalk = require("chalk");
5-
const updateNotifier = require("update-notifier");
6-
const pkg = require("../package.json");
7-
const cliHandler = require("../lib/cli-handler");
2+
import meow from "meow";
3+
import chalk from "chalk";
4+
import updateNotifier from "update-notifier";
5+
import cliHandler from "../lib/cli-handler.js";
6+
import { readFile } from "node:fs/promises";
7+
export const getPackageInfo = async () => {
8+
const pkg = await readFile(new URL("../package.json", import.meta.url));
9+
return JSON.parse(pkg);
10+
};
811
const cli = meow(
912
`
1013
Usage
@@ -25,9 +28,9 @@ const cli = meow(
2528
$ create-textlint-rule example --typescript
2629
`,
2730
{
28-
alias: {
29-
h: "help"
30-
}
31+
importMeta: import.meta,
32+
autoHelp: true,
33+
autoVersion: true
3134
}
3235
);
3336
/*
@@ -38,7 +41,7 @@ const cli = meow(
3841
}
3942
*/
4043
updateNotifier({
41-
pkg: pkg,
44+
pkg: await getPackageInfo(),
4245
updateCheckInterval: 1000 * 60 * 60 * 24 * 7
4346
}).notify();
4447

Diff for: ‎lib/cli-handler.js

+7-9
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,17 @@
1-
// MIT © 2016 azu
2-
"use strict";
3-
const path = require("path");
4-
const chalk = require("chalk");
5-
const createTextlintRule = require("./scripts/create-textlint-rule");
1+
import chalk from "chalk";
2+
import createTextlintRule from "./scripts/create-textlint-rule.js";
3+
64
/**
75
* @param {string} projectName
86
* @param {{
9-
* yes: boolean
10-
* yarn: boolean
7+
* yes: boolean,
8+
* yarn: boolean,
119
* cwd: string
1210
* }} options
1311
* @returns {Promise<any | never>}
1412
*/
15-
module.exports = function (projectName, options = {}) {
13+
export default function (projectName, options = {}) {
1614
return createTextlintRule(projectName, options).then(() => {
1715
console.log(chalk.green(`✔ Complete: Let's write textlint rule`));
1816
});
19-
};
17+
}

Diff for: ‎lib/scripts/create-textlint-rule.js

+9-11
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,20 @@
1-
// MIT © 2016 azu
2-
"use strict";
3-
const spawn = require("cross-spawn-promise");
4-
const path = require("path");
5-
const rimraf = require("rimraf");
6-
const chalk = require("chalk");
1+
import rimraf from "rimraf";
2+
import chalk from "chalk";
3+
import spawn from "cross-spawn-promise";
4+
import path from "node:path";
75

86
/**
97
* @see https://github.com/textlint/textlint-rule-template
108
* @param {string} projectName
119
* @param {{
12-
* yes: boolean
13-
* yarn: boolean
14-
* typescript: boolean
10+
* yes: boolean,
11+
* yarn: boolean,
12+
* typescript: boolean,
1513
* cwd: string
1614
* }} [options]
1715
* @returns {Promise}
1816
*/
19-
module.exports = function (projectName, options = {}) {
17+
export default function (projectName, options = {}) {
2018
const useYarn = options.yarn !== undefined;
2119
const useYes = options.yes !== undefined;
2220
const useTypeScript = options.typescript !== undefined;
@@ -71,4 +69,4 @@ module.exports = function (projectName, options = {}) {
7169
console.log(chalk.green(`Initialize your README!`));
7270
return spawn(`./node_modules/.bin/textlint-scripts`, ["init"], { stdio: "inherit" });
7371
});
74-
};
72+
}

Diff for: ‎package.json

+39-40
Original file line numberDiff line numberDiff line change
@@ -1,65 +1,64 @@
11
{
2-
"directories": {
3-
"test": "test"
4-
},
5-
"author": "azu",
6-
"license": "MIT",
7-
"files": [
8-
"bin/",
9-
"lib/"
10-
],
112
"name": "create-textlint-rule",
123
"version": "1.5.0",
134
"description": "Create textlint rule project with no configuration.",
14-
"main": "lib/create-textlint-rule.js",
15-
"bin": {
16-
"create-textlint-rule": "bin/cmd.js"
17-
},
18-
"scripts": {
19-
"test": "./test/test.sh",
20-
"format": "prettier --write \"**/*.{js,jsx,ts,tsx,css}\"",
21-
"prepare": "git config --local core.hooksPath .githooks"
22-
},
235
"keywords": [
246
"textlint",
257
"tools",
268
"development",
279
"rule"
2810
],
11+
"homepage": "https://github.com/textlint/create-textlint-rule",
12+
"bugs": {
13+
"url": "https://github.com/textlint/create-textlint-rule/issues"
14+
},
2915
"repository": {
3016
"type": "git",
3117
"url": "https://github.com/textlint/create-textlint-rule.git"
3218
},
33-
"bugs": {
34-
"url": "https://github.com/textlint/create-textlint-rule/issues"
19+
"license": "MIT",
20+
"author": "azu",
21+
"type": "module",
22+
"main": "lib/create-textlint-rule.js",
23+
"bin": {
24+
"create-textlint-rule": "bin/cmd.js"
3525
},
36-
"homepage": "https://github.com/textlint/create-textlint-rule",
37-
"dependencies": {
38-
"chalk": "^4.1.2",
39-
"cross-spawn": "^7.0.3",
40-
"cross-spawn-promise": "^0.10.2",
41-
"meow": "^7.1.1",
42-
"rimraf": "^3.0.2",
43-
"update-notifier": "^5.1.0"
26+
"directories": {
27+
"test": "test"
4428
},
45-
"devDependencies": {
46-
"lint-staged": "^13.0.3",
47-
"prettier": "^2.7.1"
29+
"files": [
30+
"bin/",
31+
"lib/"
32+
],
33+
"engines": {
34+
"node": ">=14.16"
35+
},
36+
"scripts": {
37+
"format": "prettier --write \"**/*.{js,jsx,ts,tsx,css}\"",
38+
"prepare": "git config --local core.hooksPath .githooks",
39+
"test": "./test/test.sh"
40+
},
41+
"lint-staged": {
42+
"*.{js,jsx,ts,tsx,css}": [
43+
"prettier --write"
44+
]
4845
},
4946
"prettier": {
50-
"singleQuote": false,
5147
"printWidth": 120,
48+
"singleQuote": false,
5249
"tabWidth": 4,
5350
"trailingComma": "none"
5451
},
55-
"husky": {
56-
"hooks": {
57-
"precommit": "lint-staged"
58-
}
52+
"dependencies": {
53+
"chalk": "^5.1.2",
54+
"cross-spawn": "^7.0.3",
55+
"cross-spawn-promise": "^0.10.2",
56+
"meow": "^11.0.0",
57+
"rimraf": "^3.0.2",
58+
"update-notifier": "^6.0.2"
5959
},
60-
"lint-staged": {
61-
"*.{js,jsx,ts,tsx,css}": [
62-
"prettier --write"
63-
]
60+
"devDependencies": {
61+
"lint-staged": "^13.0.3",
62+
"prettier": "^2.7.1"
6463
}
6564
}

Diff for: ‎test/test.sh

+8
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,17 @@ declare currentDir=$(cd $(dirname $0);pwd)
55
declare dirName=$(basename "${currentDir}")
66
declare parentDir=$(dirname "${currentDir}")
77
declare testRuleName="test-rule-name";
8+
# test for js
89
echo "Run: create-textlint-rule ${test-rule-name}"
910
cd ${currentDir}
1011
node ${parentDir}/bin/cmd.js "${testRuleName}" --yes
12+
ls "${currentDir}/textlint-rule-${testRuleName}/package.json" # check file
13+
rm -rf "${currentDir}/textlint-rule-${testRuleName}"
14+
# test for ts
15+
echo "Run: create-textlint-rule ${test-rule-name} --typescript"
16+
cd ${currentDir}
17+
node ${parentDir}/bin/cmd.js "${testRuleName}" --yes --typescript
18+
ls "${currentDir}/textlint-rule-${testRuleName}/package.json" # check file
1119
rm -rf "${currentDir}/textlint-rule-${testRuleName}"
1220
# test .
1321
echo "Run: create-textlint-rule ."

0 commit comments

Comments
 (0)