diff --git a/bin/lts.js b/bin/lts.js index 1edcbf9..10220b9 100644 --- a/bin/lts.js +++ b/bin/lts.js @@ -1,8 +1,9 @@ #!/usr/bin/env node 'use strict'; -const Path = require('path'); -const Bossy = require('bossy'); -const Lib = require('../lib'); +import { resolve } from 'node:path'; +import Bossy from 'bossy'; +import { create } from '../lib/index.js'; + const now = new Date(); const oneYearFromNow = new Date(); @@ -15,7 +16,7 @@ const cliArgs = { type: 'string', require: false, multiple: false, - default: Path.resolve(__dirname, '..', 'lts.json') + default: resolve(__dirname, '..', 'lts.json') }, 's': { description: 'Query start date', @@ -91,15 +92,15 @@ if (args instanceof Error) { } const options = { - data: require(args.data), + data: await import(args.data), queryStart: new Date(args.start), queryEnd: new Date(args.end), - html: args.html ? Path.resolve(args.html) : null, - svg: args.svg ? Path.resolve(args.svg) : null, - png: args.png ? Path.resolve(args.png) : null, + html: args.html ? resolve(args.html) : null, + svg: args.svg ? resolve(args.svg) : null, + png: args.png ? resolve(args.png) : null, animate: args.animate, excludeMain: args.excludeMain, projectName: args.projectName }; -Lib.create(options); +create(options); diff --git a/lib/index.js b/lib/index.js index ca212ad..4dcbf18 100644 --- a/lib/index.js +++ b/lib/index.js @@ -1,7 +1,7 @@ 'use strict'; -const Fs = require('fs'); -const D3 = require('d3'); -const D3Node = require('d3-node'); +import { writeFileSync } from 'node:fs'; +import D3 from 'd3'; +import D3Node from 'd3-node'; const styles = ` .current { @@ -91,8 +91,7 @@ function parseInput (data, queryStart, queryEnd, excludeMain, projectName) { return output; } - -function create (options) { +export function create (options) { const { queryStart, queryEnd, html, svg: svgFile, png, animate, excludeMain, projectName, margin: marginInput } = options; const data = parseInput(options.data, queryStart, queryEnd, excludeMain, projectName); const d3n = new D3Node({ svgStyles: styles, d3Module: D3 }); @@ -207,18 +206,16 @@ function create (options) { }); if (typeof html === 'string') { - Fs.writeFileSync(html, d3n.html()); + writeFileSync(html, d3n.html()); } if (typeof svgFile === 'string') { - Fs.writeFileSync(svgFile, d3n.svgString()); + writeFileSync(svgFile, d3n.svgString()); } if (typeof png === 'string') { const Svg2png = require('svg2png'); // Load this lazily. - Fs.writeFileSync(png, Svg2png.sync(Buffer.from(d3n.svgString()))); + writeFileSync(png, Svg2png.sync(Buffer.from(d3n.svgString()))); } } - -module.exports.create = create; diff --git a/package.json b/package.json index 7829b90..9e1d299 100644 --- a/package.json +++ b/package.json @@ -3,6 +3,7 @@ "version": "2.0.0", "description": "Generate the Node.js LTS schedule", "main": "lib/index.js", + "type": "module", "homepage": "https://github.com/nodejs/lts-schedule", "repository": { "type": "git", @@ -19,7 +20,7 @@ "lts": "bin/lts.js" }, "engines": { - "node": ">=4.0.0" + "node": ">=20" }, "dependencies": { "bossy": "3.0.4",