Skip to content

Commit ac19162

Browse files
authored
[Node20] support newer versions of node and ESM (#1)
This hadn't been touched since April of 2021, and it's 2025 and I want to make some CLI's again, so I needed to update this template first. - Support Node20 and above LTS versions - update to use ECMAScript Modules - update deps to use the latest version as of today.
1 parent 3ac5498 commit ac19162

6 files changed

Lines changed: 41 additions & 33 deletions

File tree

.github/workflows/test-flow.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ jobs:
99

1010
strategy:
1111
matrix:
12-
node-version: [12.x, 14.x]
12+
node-version: [20.x, 22.x, 24.x] # only LTS versions
1313

1414
steps:
1515
- uses: actions/checkout@v2

cli.js

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,13 @@
11
#!/usr/bin/env node
2-
const { resolve } = require('path')
3-
const { Command } = require('commander');
4-
const getHandlers = require('./index')
5-
const pojoStick = require('pojo-stick')
6-
const pkg = require('./package.json')
2+
import { resolve } from 'path';
3+
import { Command } from 'commander';
4+
import getHandlers from './index.js';
5+
import pojoStick from 'pojo-stick';
6+
import { readFile } from 'fs/promises';
7+
8+
const pkg = JSON.parse(
9+
await readFile(new URL('./package.json', import.meta.url))
10+
);
711

812
;(async () => {
913
// persistent appData

index.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
const chalk = require('chalk');
2-
const { confirm, checkbox, text, select, number, password } = require('./lib/inputs')
1+
import chalk from 'chalk';
2+
import { confirm, checkbox, text, select, number, password } from './lib/inputs.js';
33

4-
module.exports = function getHandlers ({ appData }) {
4+
export default function getHandlers({ appData }) {
55

66
async function test (action, type, rest) {
77
appData.test = appData.test || { timesCalled: 0, lastCalledArgs: {} }

lib/inputs.js

Lines changed: 17 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
const inquirer = require('inquirer');
1+
import inquirer from 'inquirer';
22
const base = inquirer.createPromptModule();
33

44
const prompt = async ({ name = "__last_asked_question__", ...props } = {}) => {
@@ -24,21 +24,19 @@ const isNumber = (input) => {
2424
return true
2525
}
2626

27-
module.exports = {
28-
text: (message = '', options = {}) => prompt({ validate: notEmpty, ...options, type: 'input', message }),
29-
number: async (message = '', options = {}) => {
30-
const numText = await prompt({ validate: notEmpty, ...options, type: 'input', message, validate: isNumber })
31-
return Number(numText)
32-
},
33-
password: (message = '', options = {}) => prompt({ validate: notEmpty, ...options, type: 'password', message }),
34-
35-
checkbox: (label, choices = [], options = {}) => prompt({ validate: notEmpty, ...options, name: label, type: 'checkbox', choices }),
36-
select: (label, choices = [], options = {}) => prompt({ validate: notEmpty, ...options, name: label, type: 'list', choices }),
37-
38-
confirm: (message = '', defOption = false, options = {}) => prompt({ validate: notEmpty, ...options, default: defOption, type: 'confirm', message }),
39-
40-
validate: {
41-
isNumber,
42-
notEmpty,
43-
}
44-
}
27+
export const text = (message = '', options = {}) => prompt({ validate: notEmpty, ...options, type: 'input', message });
28+
export const number = async (message = '', options = {}) => {
29+
const numText = await prompt({ validate: notEmpty, ...options, type: 'input', message, validate: isNumber })
30+
return Number(numText)
31+
};
32+
export const password = (message = '', options = {}) => prompt({ validate: notEmpty, ...options, type: 'password', message });
33+
34+
export const checkbox = (label, choices = [], options = {}) => prompt({ validate: notEmpty, ...options, name: label, type: 'checkbox', choices });
35+
export const select = (label, choices = [], options = {}) => prompt({ validate: notEmpty, ...options, name: label, type: 'list', choices });
36+
37+
export const confirm = (message = '', defOption = false, options = {}) => prompt({ validate: notEmpty, ...options, default: defOption, type: 'confirm', message });
38+
39+
export const validate = {
40+
isNumber,
41+
notEmpty,
42+
};

package.json

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,19 @@
33
"version": "0.1.0",
44
"description": "__REPLACE_DESCRIPTION_WITH_MAKE_CMD__",
55
"main": "cli.js",
6+
"type": "module",
67
"repository": "https://github.com/kyle-west/__REPLACE_PACKAGE_NAME_WITH_MAKE_CMD__",
78
"author": "kyle-west",
89
"license": "UNLICENSED",
910
"private": true,
11+
"engines": {
12+
"node": ">=20.0.0"
13+
},
1014
"dependencies": {
11-
"chalk": "^4.1.0",
12-
"commander": "^6.1.0",
13-
"inquirer": "^7.3.3",
14-
"jest": "^26.6.3",
15+
"chalk": "^5.4.1",
16+
"commander": "^14.0.0",
17+
"inquirer": "^12.6.3",
18+
"jest": "^29.7.0",
1519
"pojo-stick": "^0.1.0"
1620
},
1721
"bin": {

test.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,3 @@
1-
test.todo('write tests')
1+
// Using ESM syntax, if this file needs proper test imports later
2+
// For now, just keeping the todo comment
3+
test.todo('write tests');

0 commit comments

Comments
 (0)