Skip to content

Commit 16b1f5a

Browse files
authored
feat!: convert to ESM (#180)
1 parent e2e8fc0 commit 16b1f5a

File tree

25 files changed

+2810
-4141
lines changed

25 files changed

+2810
-4141
lines changed

bin/index.js

+15-11
Original file line numberDiff line numberDiff line change
@@ -7,18 +7,22 @@
77
* found at http://www.apache.org/licenses/LICENSE-2.0.
88
*/
99

10-
const Command = require('commander').Command;
10+
import { Command } from 'commander';
11+
import chalk from 'chalk';
12+
import cmd from '../dist/cmd/index.js';
13+
import { createRequire } from 'module';
14+
import dotenv from 'dotenv';
15+
import figlet from 'figlet';
16+
import github from '../dist/github/index.js';
17+
import lerna from '../dist/lerna/index.js';
18+
import netlify from '../dist/netlify/index.js';
19+
import ora from 'ora';
20+
1121
const program = new Command();
12-
const chalk = require('chalk');
13-
const textSync = require('figlet').textSync;
14-
const spinner = require('ora')();
15-
const version = require('../package.json').version;
16-
const cmd = require('../dist/cmd');
17-
const github = require('../dist/github');
18-
const lerna = require('../dist/lerna');
19-
const netlify = require('../dist/netlify');
22+
const spinner = ora();
23+
const version = createRequire(import.meta.url)('../package.json').version;
2024

21-
require('dotenv').config();
25+
dotenv.config();
2226

2327
program
2428
.version(version)
@@ -38,7 +42,7 @@ program
3842
.addCommand(netlify.siteIdCommand(spinner))
3943
.addCommand(netlify.tokenCommand(spinner))
4044
.action(() => {
41-
console.log(chalk.hex('#5EAE91')(textSync('garden')));
45+
console.log(chalk.hex('#5EAE91')(figlet.textSync('garden')));
4246
console.log();
4347
program.help();
4448
})

package.json

+22-19
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
"bugs": {
1010
"url": "https://github.com/zendeskgarden/scripts/issues"
1111
},
12+
"type": "module",
1213
"main": "dist/index.js",
1314
"bin": {
1415
"garden": "bin/index.js"
@@ -20,7 +21,7 @@
2021
"scripts": {
2122
"build": "yarn tsc",
2223
"format": "prettier-package-json --write && yarn format:all --write",
23-
"format:all": "prettier --loglevel warn '**/*.{js,ts,json,md}' '!CHANGELOG.md' '!dist/**' '!.github/ISSUE_TEMPLATE.md'",
24+
"format:all": "prettier --log-level warn '**/*.{js,ts,json,md}' '!CHANGELOG.md' '!dist/**' '!.github/ISSUE_TEMPLATE.md'",
2425
"lint": "yarn lint:js && yarn lint:md",
2526
"lint:js": "eslint bin/ src/ --ext js,ts --max-warnings 0",
2627
"lint:md": "markdownlint README.md src/**/*.md",
@@ -33,25 +34,25 @@
3334
"dependencies": {
3435
"@octokit/request-error": "5.0.0",
3536
"@octokit/rest": "20.0.1",
36-
"chalk": "4.1.2",
37+
"chalk": "5.3.0",
3738
"commander": "11.0.0",
38-
"comment-parser": "1.3.1",
39+
"comment-parser": "1.4.0",
3940
"dotenv": "16.3.1",
40-
"execa": "5.1.1",
41+
"execa": "7.2.0",
4142
"figlet": "1.6.0",
4243
"fs-extra": "11.1.1",
4344
"gh-pages": "5.0.0",
44-
"globby": "11.1.0",
45-
"handlebars": "4.7.7",
45+
"globby": "13.2.2",
46+
"handlebars": "4.7.8",
4647
"handlebars-helpers": "0.10.0",
47-
"is-interactive": "1.0.0",
48+
"is-interactive": "2.0.0",
49+
"is-plain-object": "5.0.0",
4850
"klaw": "4.1.0",
4951
"lerna-changelog": "2.2.0",
5052
"lodash": "4.17.21",
51-
"netlify": "9.0.0",
52-
"netlify-cli": "9.16.7",
53-
"node-fetch": "2.6.12",
54-
"ora": "5.4.1",
53+
"netlify": "13.1.0",
54+
"netlify-cli": "15.10.0",
55+
"ora": "7.0.1",
5556
"pluralize": "8.0.0",
5657
"react-docgen-typescript": "2.2.2",
5758
"typescript": "5.1.6"
@@ -64,20 +65,19 @@
6465
"@types/gh-pages": "3.2.1",
6566
"@types/handlebars-helpers": "0.5.3",
6667
"@types/klaw": "3.0.3",
67-
"@types/lodash": "4.14.195",
68-
"@types/node": "18.16.19",
69-
"@types/node-fetch": "2.6.4",
68+
"@types/lodash": "4.14.196",
69+
"@types/node": "20.4.7",
7070
"@types/pluralize": "0.0.30",
71-
"@typescript-eslint/eslint-plugin": "6.1.0",
72-
"@typescript-eslint/parser": "6.1.0",
71+
"@typescript-eslint/eslint-plugin": "6.2.1",
72+
"@typescript-eslint/parser": "6.2.1",
7373
"@zendeskgarden/eslint-config": "34.0.0",
74-
"eslint": "8.45.0",
75-
"eslint-config-prettier": "8.8.0",
74+
"eslint": "8.46.0",
75+
"eslint-config-prettier": "8.10.0",
7676
"eslint-plugin-node": "11.1.0",
7777
"eslint-plugin-notice": "0.9.10",
7878
"husky": "8.0.3",
7979
"markdownlint-cli": "0.35.0",
80-
"prettier": "3.0.0",
80+
"prettier": "3.0.1",
8181
"prettier-package-json": "2.8.0",
8282
"standard-version": "9.5.0"
8383
},
@@ -87,6 +87,9 @@
8787
"tools",
8888
"zendesk"
8989
],
90+
"engines": {
91+
"node": ">=18.0.0"
92+
},
9093
"publishConfig": {
9194
"access": "public"
9295
}

src/cmd/docgen/index.ts

+11-7
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,18 @@
55
* found at http://www.apache.org/licenses/LICENSE-2.0.
66
*/
77

8+
import { GlobTask, globby } from 'globby';
89
import { ParserOptions, withCustomConfig, withDefaultConfig } from 'react-docgen-typescript';
9-
import commander, { Command } from 'commander';
10-
import { findConfigFile, sys } from 'typescript';
11-
import globby, { GlobbyOptions } from 'globby';
12-
import { handleErrorMessage, handleSuccessMessage, handleWarningMessage } from '../../utils';
10+
import {
11+
handleErrorMessage,
12+
handleSuccessMessage,
13+
handleWarningMessage
14+
} from '../../utils/index.js';
15+
import { Command } from 'commander';
1316
import { Ora } from 'ora';
1417
import { parse as parseComment } from 'comment-parser';
1518
import { resolve } from 'path';
19+
import ts from 'typescript';
1620

1721
type TAGS = Record<string, string>;
1822

@@ -74,7 +78,7 @@ export const execute = async (
7478
),
7579
shouldRemoveUndefinedFromOptional: true
7680
};
77-
const globbyOptions: GlobbyOptions = {
81+
const globbyOptions: GlobTask['options'] = {
7882
expandDirectories: {
7983
extensions: args.extensions || DEFAULT_EXTENSIONS
8084
},
@@ -84,7 +88,7 @@ export const execute = async (
8488
for await (const path of Array.isArray(args.paths) ? args.paths : [args.paths]) {
8589
const resolvedPath = resolve(path);
8690
/* eslint-disable-next-line @typescript-eslint/unbound-method */
87-
const tsconfigPath = findConfigFile(resolvedPath, sys.fileExists);
91+
const tsconfigPath = ts.findConfigFile(resolvedPath, ts.sys.fileExists);
8892
const parser = tsconfigPath
8993
? withCustomConfig(tsconfigPath, parserOptions)
9094
: withDefaultConfig(parserOptions);
@@ -152,7 +156,7 @@ export const execute = async (
152156
return retVal;
153157
};
154158

155-
export default (spinner: Ora): commander.Command => {
159+
export default (spinner: Ora): Command => {
156160
const command = new Command('cmd-docgen');
157161

158162
return command

src/cmd/du/index.ts

+7-5
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,11 @@
55
* found at http://www.apache.org/licenses/LICENSE-2.0.
66
*/
77

8-
import commander, { Command } from 'commander';
9-
import { handleErrorMessage, handleSuccessMessage } from '../../utils';
8+
import { dirname, resolve } from 'path';
9+
import { handleErrorMessage, handleSuccessMessage } from '../../utils/index.js';
10+
import { Command } from 'commander';
1011
import { Ora } from 'ora';
11-
import { resolve } from 'path';
12+
import { fileURLToPath } from 'url';
1213
import { default as walk } from 'klaw';
1314

1415
/**
@@ -23,7 +24,8 @@ export const execute = async (dir?: string, spinner?: Ora): Promise<number> => {
2324
let retVal = 0;
2425

2526
try {
26-
const root = resolve(dir || __dirname);
27+
const currentDir = dirname(fileURLToPath(import.meta.url));
28+
const root = resolve(dir || currentDir);
2729

2830
for await (const file of walk(root)) {
2931
if (file.path !== root) {
@@ -39,7 +41,7 @@ export const execute = async (dir?: string, spinner?: Ora): Promise<number> => {
3941
return retVal;
4042
};
4143

42-
export default (spinner: Ora): commander.Command => {
44+
export default (spinner: Ora): Command => {
4345
const command = new Command('cmd-du');
4446

4547
return command

src/cmd/index.ts

+6-2
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,9 @@
55
* found at http://www.apache.org/licenses/LICENSE-2.0.
66
*/
77

8-
export { default as docgenCommand, execute as docgen } from './docgen';
9-
export { default as duCommand, execute as du } from './du';
8+
import { execute as docgen, default as docgenCommand } from './docgen/index.js';
9+
import { execute as du, default as duCommand } from './du/index.js';
10+
11+
const commands = { docgenCommand, duCommand };
12+
13+
export { commands as default, docgen, docgenCommand, du, duCommand };

src/github/branch/index.ts

+4-4
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,10 @@
55
* found at http://www.apache.org/licenses/LICENSE-2.0.
66
*/
77

8-
import commander, { Command } from 'commander';
9-
import { handleErrorMessage, handleSuccessMessage } from '../../utils';
8+
import { handleErrorMessage, handleSuccessMessage } from '../../utils/index.js';
9+
import { Command } from 'commander';
1010
import { Ora } from 'ora';
11-
import execa from 'execa';
11+
import { execa } from 'execa';
1212

1313
/**
1414
* Execute the `github-branch` command.
@@ -46,7 +46,7 @@ export const execute = async (path?: string, spinner?: Ora): Promise<string | un
4646
return retVal;
4747
};
4848

49-
export default (spinner: Ora): commander.Command => {
49+
export default (spinner: Ora): Command => {
5050
const command = new Command('github-branch');
5151

5252
return command

src/github/commit/index.ts

+4-4
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,9 @@
55
* found at http://www.apache.org/licenses/LICENSE-2.0.
66
*/
77

8-
import commander, { Command } from 'commander';
9-
import { branch as getBranch, repository as getRepository, token as getToken } from '..';
10-
import { handleErrorMessage, handleSuccessMessage } from '../../utils';
8+
import { branch as getBranch, repository as getRepository, token as getToken } from '../index.js';
9+
import { handleErrorMessage, handleSuccessMessage } from '../../utils/index.js';
10+
import { Command } from 'commander';
1111
import { Octokit } from '@octokit/rest';
1212
import { Ora } from 'ora';
1313
import { RequestError } from '@octokit/request-error';
@@ -64,7 +64,7 @@ export const execute = async (args: IGitHubCommitArgs = {}): Promise<string | un
6464
return retVal;
6565
};
6666

67-
export default (spinner: Ora): commander.Command => {
67+
export default (spinner: Ora): Command => {
6868
const command = new Command('github-commit');
6969

7070
return command

src/github/deploy/index.ts

+5-5
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,12 @@
55
* found at http://www.apache.org/licenses/LICENSE-2.0.
66
*/
77

8-
import commander, { Command } from 'commander';
9-
import { commit as getCommit, repository as getRepository, token as getToken } from '..';
10-
import { handleErrorMessage, handleSuccessMessage } from '../../utils';
8+
import { commit as getCommit, repository as getRepository, token as getToken } from '../index.js';
9+
import { handleErrorMessage, handleSuccessMessage } from '../../utils/index.js';
10+
import { Command } from 'commander';
1111
import { Octokit } from '@octokit/rest';
1212
import { Ora } from 'ora';
13-
import execa from 'execa';
13+
import { execa } from 'execa';
1414

1515
interface IGitHubDeployArgs {
1616
command: (...args: unknown[]) => Promise<string | { url: string; logUrl: string } | undefined>;
@@ -93,7 +93,7 @@ export const execute = async (args: IGitHubDeployArgs): Promise<string | undefin
9393
return retVal;
9494
};
9595

96-
export default (spinner: Ora): commander.Command => {
96+
export default (spinner: Ora): Command => {
9797
const command = new Command('github-deploy');
9898

9999
return command

src/github/index.ts

+35-7
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,38 @@
55
* found at http://www.apache.org/licenses/LICENSE-2.0.
66
*/
77

8-
export { default as branchCommand, execute as branch } from './branch';
9-
export { default as commitCommand, execute as commit } from './commit';
10-
export { default as deployCommand, execute as deploy } from './deploy';
11-
export { default as pagesCommand, execute as pages } from './pages';
12-
export { default as releaseCommand, execute as release } from './release';
13-
export { default as repositoryCommand, execute as repository } from './repository';
14-
export { default as tokenCommand, execute as token } from './token';
8+
import { execute as branch, default as branchCommand } from './branch/index.js';
9+
import { execute as commit, default as commitCommand } from './commit/index.js';
10+
import { execute as deploy, default as deployCommand } from './deploy/index.js';
11+
import { execute as pages, default as pagesCommand } from './pages/index.js';
12+
import { execute as release, default as releaseCommand } from './release/index.js';
13+
import { execute as repository, default as repositoryCommand } from './repository/index.js';
14+
import { execute as token, default as tokenCommand } from './token/index.js';
15+
16+
const commands = {
17+
branchCommand,
18+
commitCommand,
19+
deployCommand,
20+
pagesCommand,
21+
releaseCommand,
22+
repositoryCommand,
23+
tokenCommand
24+
};
25+
26+
export {
27+
commands as default,
28+
branch,
29+
branchCommand,
30+
commit,
31+
commitCommand,
32+
deploy,
33+
deployCommand,
34+
pages,
35+
pagesCommand,
36+
release,
37+
releaseCommand,
38+
repository,
39+
repositoryCommand,
40+
token,
41+
tokenCommand
42+
};

src/github/pages/index.ts

+5-5
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,11 @@
66
*/
77

88
import { clean, publish } from 'gh-pages';
9-
import commander, { Command } from 'commander';
10-
import { repository as getRepository, token as getToken } from '..';
11-
import { handleErrorMessage, handleSuccessMessage } from '../../utils';
9+
import { repository as getRepository, token as getToken } from '../index.js';
10+
import { handleErrorMessage, handleSuccessMessage } from '../../utils/index.js';
11+
import { Command } from 'commander';
1212
import { Ora } from 'ora';
13-
import execa from 'execa';
13+
import { execa } from 'execa';
1414

1515
interface IGitHubPagesArgs {
1616
dir: string;
@@ -86,7 +86,7 @@ export const execute = async (args: IGitHubPagesArgs): Promise<string | undefine
8686
return retVal;
8787
};
8888

89-
export default (spinner: Ora): commander.Command => {
89+
export default (spinner: Ora): Command => {
9090
const command = new Command('github-pages');
9191

9292
return command

src/github/release/index.ts

+4-4
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,9 @@
55
* found at http://www.apache.org/licenses/LICENSE-2.0.
66
*/
77

8-
import commander, { Command } from 'commander';
9-
import { repository as getRepository, token as getToken } from '..';
10-
import { handleErrorMessage, handleSuccessMessage } from '../../utils';
8+
import { repository as getRepository, token as getToken } from '../index.js';
9+
import { handleErrorMessage, handleSuccessMessage } from '../../utils/index.js';
10+
import { Command } from 'commander';
1111
import { Octokit } from '@octokit/rest';
1212
import { Ora } from 'ora';
1313

@@ -61,7 +61,7 @@ export const execute = async (args: IGitHubReleaseArgs): Promise<string | undefi
6161
return retVal;
6262
};
6363

64-
export default (spinner: Ora): commander.Command => {
64+
export default (spinner: Ora): Command => {
6565
const command = new Command('github-release');
6666

6767
return command

0 commit comments

Comments
 (0)