Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 10 additions & 9 deletions bin/lts.js
Original file line number Diff line number Diff line change
@@ -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();

Expand All @@ -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',
Expand Down Expand Up @@ -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);
17 changes: 7 additions & 10 deletions lib/index.js
Original file line number Diff line number Diff line change
@@ -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 {
Expand Down Expand Up @@ -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 });
Expand Down Expand Up @@ -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;
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -19,7 +20,7 @@
"lts": "bin/lts.js"
},
"engines": {
"node": ">=4.0.0"
"node": ">=20"
},
"dependencies": {
"bossy": "3.0.4",
Expand Down