Modules all the way
This commit is contained in:
+24
-18
@@ -1,11 +1,16 @@
|
||||
const fse = require('fs-extra');
|
||||
const path = require('path');
|
||||
const spawn = require('child_process').spawn;
|
||||
const walk = require('walk').walk;
|
||||
const isWindows = process.platform.indexOf('win') === 0;
|
||||
import esMain from 'es-main';
|
||||
import fse from 'fs-extra';
|
||||
import path from 'path';
|
||||
import {dirname} from 'path';
|
||||
import {fileURLToPath} from 'url';
|
||||
import {spawn} from 'child_process';
|
||||
import {walk} from 'walk';
|
||||
|
||||
const sourceDir = path.join(__dirname, '..', 'src');
|
||||
const infoPath = path.join(__dirname, '..', 'build', 'info.json');
|
||||
const isWindows = process.platform.indexOf('win') === 0;
|
||||
const baseDir = dirname(fileURLToPath(import.meta.url));
|
||||
|
||||
const sourceDir = path.join(baseDir, '..', 'src');
|
||||
const infoPath = path.join(baseDir, '..', 'build', 'info.json');
|
||||
|
||||
/**
|
||||
* Get checked path of a binary.
|
||||
@@ -17,9 +22,15 @@ function getBinaryPath(binaryName) {
|
||||
binaryName += '.cmd';
|
||||
}
|
||||
|
||||
const jsdocResolved = require.resolve('jsdoc/jsdoc.js');
|
||||
const jsdocResolved = path.join(
|
||||
baseDir,
|
||||
'..',
|
||||
'node_modules',
|
||||
'jsdoc',
|
||||
'jsdoc.js'
|
||||
);
|
||||
const expectedPaths = [
|
||||
path.join(__dirname, '..', 'node_modules', '.bin', binaryName),
|
||||
path.join(baseDir, '..', 'node_modules', '.bin', binaryName),
|
||||
path.resolve(
|
||||
path.join(path.dirname(jsdocResolved), '..', '.bin', binaryName)
|
||||
),
|
||||
@@ -40,7 +51,7 @@ function getBinaryPath(binaryName) {
|
||||
const jsdoc = getBinaryPath('jsdoc');
|
||||
|
||||
const jsdocConfig = path.join(
|
||||
__dirname,
|
||||
baseDir,
|
||||
'..',
|
||||
'config',
|
||||
'jsdoc',
|
||||
@@ -120,7 +131,7 @@ function spawnJSDoc(paths) {
|
||||
return new Promise((resolve, reject) => {
|
||||
let output = '';
|
||||
let errors = '';
|
||||
const cwd = path.join(__dirname, '..');
|
||||
const cwd = path.join(baseDir, '..');
|
||||
const child = spawn(jsdoc, ['-c', jsdocConfig].concat(paths), {cwd: cwd});
|
||||
|
||||
child.stdout.on('data', (data) => {
|
||||
@@ -162,7 +173,7 @@ async function write(info) {
|
||||
* Generate info from the sources.
|
||||
* @return {Promise<Error>} Resolves with the info object.
|
||||
*/
|
||||
async function main() {
|
||||
export default async function main() {
|
||||
const paths = await getPaths();
|
||||
return await spawnJSDoc(paths);
|
||||
}
|
||||
@@ -170,15 +181,10 @@ async function main() {
|
||||
/**
|
||||
* If running this module directly, generate and write out the info.json file.
|
||||
*/
|
||||
if (require.main === module) {
|
||||
if (esMain(import.meta)) {
|
||||
main()
|
||||
.then(write)
|
||||
.catch((err) => {
|
||||
process.stderr.write(`${err.message}\n`, () => process.exit(1));
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Export main function.
|
||||
*/
|
||||
module.exports = main;
|
||||
|
||||
Reference in New Issue
Block a user