Skip to content

Commit

Permalink
Fix a few things I screwed up trying to fix the merge conflicts + sup…
Browse files Browse the repository at this point in the history
…port Node.js v18
  • Loading branch information
webpro committed Nov 5, 2023
1 parent 7c49612 commit 6f6b961
Show file tree
Hide file tree
Showing 6 changed files with 22 additions and 39 deletions.
4 changes: 3 additions & 1 deletion bin/reveal-md.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,12 @@ import open from 'open';
import startServer from '../lib/server.js';
import writeStatic from '../lib/static.js';
import exportPDF from '../lib/print.js';
import pkg from '../package.json' assert { type: 'json' };
import { loadJSON } from '../lib/util.js';

const __dirname = new URL('.', import.meta.url).pathname;

const pkg = loadJSON(path.join(__dirname, '../package.json'));

const alias = {
h: 'help',
s: 'separator',
Expand Down
40 changes: 7 additions & 33 deletions lib/config.js
Original file line number Diff line number Diff line change
@@ -1,44 +1,20 @@
import path from 'node:path';
import { createRequire } from 'node:module';
import _ from 'lodash';
import { readFileSync } from 'node:fs';
import { readFile } from 'node:fs/promises';
import * as fs from 'fs-extra';
import parseArgs from 'yargs-parser';
import url from 'node:url';
import { globSync } from 'glob';
import defaultsJson from './defaults.json' assert { type: 'json' };
import { isDirectory, isFile, isAbsoluteURL, tryReadJson5Configs } from './util.js';
import { isDirectory, isFile, isAbsoluteURL, tryReadJson5Configs, loadJSON } from './util.js';

const __filename = new URL('', import.meta.url).pathname;
const __dirname = new URL('.', import.meta.url).pathname;
const require = createRequire(import.meta.url);

export const defaults = defaultsJson;
const __dirname = new URL('.', import.meta.url).pathname;

let localConfig = undefined;
try {
localConfig = JSON.parse(readFileSync(path.join(process.cwd(), 'reveal-md.json')));
} catch (e) {
if (e.code !== 'ENOENT') {
console.log(e);
}
}

let revealConfig = undefined;
try {
revealConfig = JSON.parse(readFileSync(path.join(process.cwd(), 'reveal.json')));
} catch (e) {
if (e.code !== 'ENOENT') {
console.log(e);
}
}

export const revealBasePath = path.resolve(new URL(import.meta.resolve('reveal.js')).pathname, '..', '..');
export const highlightThemePath = path.resolve(
new URL(import.meta.resolve('highlight.js')).pathname,
'..',
'..',
'styles'
);
export const defaults = loadJSON(path.join(__dirname, 'defaults.json'));
export const revealBasePath = path.join(require.resolve('reveal.js'), '..', '..');
export const highlightThemePath = path.resolve(require.resolve('highlight.js'), '..', '..', 'styles');

const localConfig = tryReadJson5Configs(
path.join(process.cwd(), 'reveal-md.json5'),
Expand All @@ -49,8 +25,6 @@ const revealConfig = tryReadJson5Configs(
path.join(process.cwd(), 'reveal.json')
);

const revealBasePath = path.resolve(require.resolve('reveal.js'), '..', '..');

const alias = {
h: 'help',
v: 'version',
Expand Down
6 changes: 5 additions & 1 deletion lib/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,13 @@ export const getFilePaths = (workingDir, globPattern) => {
});
};


export const isAbsoluteURL = path => path.indexOf('://') > 0 || path.indexOf('//') === 0;

export const loadJSON = filePath => {
const data = fs.readFileSync(filePath, 'utf8');
return JSON.parse(data);
};

export const tryReadJson5Configs = (...possibleConfigFiles) => {
for (const configFile of possibleConfigFiles) {
try {
Expand Down
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,6 @@
"release-it": "16.2.1"
},
"engines": {
"node": ">=20"
"node": ">=18"
}
}
7 changes: 5 additions & 2 deletions test/program.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,14 @@ import path from 'path';
import { readFile } from 'node:fs/promises';
import { exec as _exec } from 'node:child_process';
import { promisify } from 'node:util';
import pkg from '../package.json' assert { type: 'json' };
import { loadJSON } from '../lib/util.js';

const __dirname = new URL('.', import.meta.url).pathname;

const pkg = loadJSON(path.join(__dirname, '../package.json'));

const exec = promisify(_exec);

const __dirname = new URL('.', import.meta.url).pathname;
const inspect_brk = process.env.VSCODE_DEBUGGING === 'true' ? '--inspect-brk' : '';
const reveal_md = `node ${inspect_brk} ${path.join(__dirname, '../bin', 'reveal-md.js')}`;

Expand Down

0 comments on commit 6f6b961

Please sign in to comment.