mirror of
https://github.com/jsdoc/jsdoc.git
synced 2025-12-08 19:46:11 +00:00
get rid of jsdoc/util/runtime (#1383); delint
This commit is contained in:
parent
2382490c7c
commit
a097e2f299
51
jsdoc.js
51
jsdoc.js
@ -1,38 +1,45 @@
|
||||
#!/usr/bin/env node
|
||||
/* global arguments, require: true */
|
||||
/* eslint strict: [2, "function"] */
|
||||
/* global require: true */
|
||||
/* eslint strict: ["error", "function"] */
|
||||
/**
|
||||
* @project jsdoc
|
||||
* @author Michael Mathews <micmath@gmail.com>
|
||||
* @license See LICENSE.md file included in this distribution.
|
||||
*/
|
||||
|
||||
// initialize the environment for the current JavaScript VM
|
||||
(function(args) {
|
||||
// initialize the environment for Node.js
|
||||
(function() {
|
||||
'use strict';
|
||||
|
||||
var path;
|
||||
var fs = require('fs');
|
||||
var path = require('path');
|
||||
|
||||
if (args[0] && typeof args[0] === 'object') {
|
||||
// we should be on Node.js
|
||||
args = [__dirname, process.cwd()];
|
||||
path = require('path');
|
||||
var env;
|
||||
var jsdocPath = __dirname;
|
||||
var pwd = process.cwd();
|
||||
|
||||
// Create a custom require method that adds `lib/jsdoc` and `node_modules` to the module
|
||||
// lookup path. This makes it possible to `require('jsdoc/foo')` from external templates and
|
||||
// plugins, and within JSDoc itself. It also allows external templates and plugins to
|
||||
// require JSDoc's module dependencies without installing them locally.
|
||||
require = require('requizzle')({
|
||||
requirePaths: {
|
||||
before: [path.join(__dirname, 'lib')],
|
||||
after: [path.join(__dirname, 'node_modules')]
|
||||
},
|
||||
infect: true
|
||||
});
|
||||
// Create a custom require method that adds `lib/jsdoc` and `node_modules` to the module
|
||||
// lookup path. This makes it possible to `require('jsdoc/foo')` from external templates and
|
||||
// plugins, and within JSDoc itself. It also allows external templates and plugins to
|
||||
// require JSDoc's module dependencies without installing them locally.
|
||||
require = require('requizzle')({
|
||||
requirePaths: {
|
||||
before: [path.join(__dirname, 'lib')],
|
||||
after: [path.join(__dirname, 'node_modules')]
|
||||
},
|
||||
infect: true
|
||||
});
|
||||
|
||||
// resolve the path if it's a symlink
|
||||
if ( fs.statSync(jsdocPath).isSymbolicLink() ) {
|
||||
jsdocPath = path.resolve( path.dirname(jsdocPath), fs.readlinkSync(jsdocPath) );
|
||||
}
|
||||
|
||||
require('./lib/jsdoc/util/runtime').initialize(args);
|
||||
})( Array.prototype.slice.call(arguments, 0) );
|
||||
env = require('./lib/jsdoc/env');
|
||||
env.dirname = jsdocPath;
|
||||
env.pwd = pwd;
|
||||
env.args = process.argv.slice(2);
|
||||
})();
|
||||
|
||||
/**
|
||||
* Data about the environment in which JSDoc is running, including the configuration settings that
|
||||
|
||||
@ -1,87 +0,0 @@
|
||||
/**
|
||||
* Helper functions to enable JSDoc to run on multiple JavaScript runtimes.
|
||||
*
|
||||
* @module jsdoc/util/runtime
|
||||
* @private
|
||||
*/
|
||||
'use strict';
|
||||
|
||||
var env = require('jsdoc/env');
|
||||
|
||||
// This string represents a directory name; do not modify it!
|
||||
/** @private */
|
||||
var NODE = exports.NODE = 'node';
|
||||
|
||||
/**
|
||||
* The JavaScript runtime that is executing JSDoc:
|
||||
*
|
||||
* + `module:jsdoc/util/runtime~NODE`: Node.js.
|
||||
*
|
||||
* @private
|
||||
*/
|
||||
var runtime = (function() {
|
||||
if (require && require.main && module) {
|
||||
return NODE;
|
||||
} else {
|
||||
// unknown runtime
|
||||
throw new Error('Unable to identify the current JavaScript runtime.');
|
||||
}
|
||||
})();
|
||||
|
||||
/**
|
||||
* Check whether Node.js is running JSDoc.
|
||||
* @return {boolean} Set to `true` if the current runtime is Node.js.
|
||||
*/
|
||||
exports.isNode = function() {
|
||||
return runtime === NODE;
|
||||
};
|
||||
|
||||
function initializeNode(args) {
|
||||
var fs = require('fs');
|
||||
var path = require('path');
|
||||
|
||||
var jsdocPath = args[0];
|
||||
var pwd = args[1];
|
||||
|
||||
// resolve the path if it's a symlink
|
||||
if ( fs.statSync(jsdocPath).isSymbolicLink() ) {
|
||||
jsdocPath = path.resolve( path.dirname(jsdocPath), fs.readlinkSync(jsdocPath) );
|
||||
}
|
||||
|
||||
env.dirname = jsdocPath;
|
||||
env.pwd = pwd;
|
||||
env.args = process.argv.slice(2);
|
||||
}
|
||||
|
||||
exports.initialize = function(args) {
|
||||
switch (runtime) {
|
||||
case NODE:
|
||||
initializeNode(args);
|
||||
break;
|
||||
default:
|
||||
throw new Error('Cannot initialize the unknown JavaScript runtime "' + runtime + '"!');
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Retrieve the identifier for the current JavaScript runtime.
|
||||
*
|
||||
* @private
|
||||
* @return {string} The runtime identifier.
|
||||
*/
|
||||
exports.getRuntime = function() {
|
||||
return runtime;
|
||||
};
|
||||
|
||||
/**
|
||||
* Get the require path for the runtime-specific implementation of a module.
|
||||
*
|
||||
* @param {string} partialPath - The partial path to the module. Use the same format as when calling
|
||||
* `require()`.
|
||||
* @return {object} The require path for the runtime-specific implementation of the module.
|
||||
*/
|
||||
exports.getModulePath = function(partialPath) {
|
||||
var path = require('path');
|
||||
|
||||
return path.join(env.dirname, runtime, partialPath);
|
||||
};
|
||||
@ -1,7 +1,7 @@
|
||||
{
|
||||
"name": "jsdoc",
|
||||
"version": "3.5.0-dev",
|
||||
"revision": "1499313126253",
|
||||
"revision": "1499320604033",
|
||||
"description": "An API documentation generator for JavaScript.",
|
||||
"keywords": [
|
||||
"documentation",
|
||||
|
||||
@ -2,7 +2,6 @@
|
||||
|
||||
var fs = require('jsdoc/fs');
|
||||
var path = require('jsdoc/path');
|
||||
var runtime = require('jsdoc/util/runtime');
|
||||
var klaw = require('klaw');
|
||||
|
||||
var specs = [];
|
||||
@ -10,7 +9,7 @@ var finalSpecs = [];
|
||||
|
||||
var createSpecObj = function(_path, root) {
|
||||
function relativePath() {
|
||||
return _path.replace(root, '').replace(/^[\/\\]/, '').replace(/\\/g, '/');
|
||||
return _path.replace(root, '').replace(/^[/\\]/, '').replace(/\\/g, '/');
|
||||
}
|
||||
|
||||
return {
|
||||
@ -19,13 +18,13 @@ var createSpecObj = function(_path, root) {
|
||||
},
|
||||
relativePath: relativePath,
|
||||
directory: function() {
|
||||
return _path.replace(/[\/\\][\s\w\.\-]*$/, '').replace(/\\/g, '/');
|
||||
return _path.replace(/[/\\][\s\w.-]*$/, '').replace(/\\/g, '/');
|
||||
},
|
||||
relativeDirectory: function() {
|
||||
return relativePath().replace(/[\/\\][\s\w\.\-]*$/, '').replace(/\\/g, '/');
|
||||
return relativePath().replace(/[/\\][\s\w.-]*$/, '').replace(/\\/g, '/');
|
||||
},
|
||||
filename: function() {
|
||||
return _path.replace(/^.*[\\\/]/, '');
|
||||
return _path.replace(/^.*[\\/]/, '');
|
||||
}
|
||||
};
|
||||
};
|
||||
@ -43,16 +42,12 @@ function addSpec(file, target) {
|
||||
function isValidSpec(file, matcher) {
|
||||
var result;
|
||||
|
||||
var skipPath = runtime.NODE;
|
||||
|
||||
// valid specs must...
|
||||
try {
|
||||
// ...be a file
|
||||
result = fs.statSync(file).isFile() &&
|
||||
// ...match the matcher
|
||||
matcher.test( path.basename(file) ) &&
|
||||
// ...be relevant to the current runtime
|
||||
file.indexOf('/' + skipPath + '/') === -1;
|
||||
matcher.test( path.basename(file) );
|
||||
}
|
||||
catch (e) {
|
||||
result = false;
|
||||
@ -76,24 +71,26 @@ function shouldLoad(file, matcher) {
|
||||
}
|
||||
|
||||
exports.load = function(loadpath, matcher, clear, callback) {
|
||||
var wannaBeSpecs = [];
|
||||
|
||||
if (clear === true) {
|
||||
clearSpecs();
|
||||
}
|
||||
|
||||
var wannaBeSpecs = [];
|
||||
klaw(loadpath)
|
||||
.on('data', function(spec) {
|
||||
wannaBeSpecs.push(spec.path);
|
||||
})
|
||||
.on('end', function() {
|
||||
for (var i = 0; i < wannaBeSpecs.length; i++) {
|
||||
var file = wannaBeSpecs[i];
|
||||
if ( shouldLoad(file, matcher) ) {
|
||||
addSpec(file);
|
||||
}
|
||||
}
|
||||
callback();
|
||||
});
|
||||
.on('data', function(spec) {
|
||||
wannaBeSpecs.push(spec.path);
|
||||
})
|
||||
.on('end', function() {
|
||||
for (var i = 0; i < wannaBeSpecs.length; i++) {
|
||||
var file = wannaBeSpecs[i];
|
||||
|
||||
if ( shouldLoad(file, matcher) ) {
|
||||
addSpec(file);
|
||||
}
|
||||
}
|
||||
callback();
|
||||
});
|
||||
};
|
||||
|
||||
exports.getSpecs = function() {
|
||||
|
||||
@ -1,29 +0,0 @@
|
||||
'use strict';
|
||||
|
||||
describe('jsdoc/util/runtime', function() {
|
||||
var runtime = require('jsdoc/util/runtime');
|
||||
var isNode;
|
||||
|
||||
it('should exist', function() {
|
||||
expect(runtime).toBeDefined();
|
||||
expect(typeof runtime).toEqual('object');
|
||||
});
|
||||
|
||||
it("should export a 'NODE' constant", function() {
|
||||
expect(runtime.NODE).toBeDefined();
|
||||
expect(typeof runtime.NODE).toEqual('string');
|
||||
});
|
||||
|
||||
it("should export an 'isNode' function", function() {
|
||||
expect(runtime.isNode).toBeDefined();
|
||||
expect(typeof runtime.isNode).toEqual('function');
|
||||
});
|
||||
|
||||
describe('isNode', function() {
|
||||
isNode = runtime.isNode();
|
||||
|
||||
it('should return a boolean', function() {
|
||||
expect(typeof isNode).toEqual('boolean');
|
||||
});
|
||||
});
|
||||
});
|
||||
Loading…
x
Reference in New Issue
Block a user