Skip to content

Commit

Permalink
feat(externs): Resolve externs from node_modules.
Browse files Browse the repository at this point in the history
  • Loading branch information
Kevin Schmidt committed Jan 4, 2018
1 parent dfe407e commit 3b3050a
Show file tree
Hide file tree
Showing 4 changed files with 87 additions and 12 deletions.
28 changes: 17 additions & 11 deletions .eslintrc.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,19 @@
module.exports = {
"extends": "opensphere",
"rules": {
"max-len": [
1,
120,
4,
{
"ignoreComments": true,
"ignoreUrls": true
}]
}
"extends": "google",
"parserOptions": {
"ecmaVersion": 6
},
"rules": {
// don't dangle commas
"comma-dangle": ["error", "never"],
// pre-ES6 engines need to be able to use objects as maps
"guard-for-in": "off",
// increase max line length
"max-len": ["error", { "code": 120 }],
// This is silly. Negated conditions are highly useful and often much more concise than
// their complements.
"no-negated-condition": "off",
// allow use of var
"no-var": "off"
}
};
26 changes: 26 additions & 0 deletions genconf.js
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,31 @@ const appendSourcesJsdoc = function(config) {
config.source.include = (config.source.include || []).concat(sources);
};

/**
* Resolves absolute paths for externs.
*
* @param {Object} config The JSDoc configuration object
*/
const resolveExterns = function(config) {
if (config.externs) {
config.externs = config.externs.map(function(externPath) {
var match = externPath.match(/(.*?)\/(.*)/);
if (match.length === 3) {
try {
var moduleName = match[1];
var modulePath = path.dirname(require.resolve(path.join(moduleName, 'package.json')));
if (modulePath) {
return path.join(modulePath, match[2]);
}
} catch (e) {
}
}

return externPath;
});
}
};

/**
* Merges the base JSDoc configuration with the project configuration.
* @param {string} inputPath Path to the project configuration
Expand Down Expand Up @@ -134,6 +159,7 @@ const processJsdocConf = function() {

// read sources from the manifest and add them to the config
appendSourcesDossier(config);
resolveExterns(config);
}

// write the config to the output path
Expand Down
42 changes: 42 additions & 0 deletions os-docs.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
#!/usr/bin/env node

'use strict';

const childProcess = require('child_process');
const Promise = require('bluebird');
const path = require('path');

const dossierJarPath = path.join(path.dirname(require.resolve('js-dossier/package.json')), 'dossier.jar');

let args;
if (process.argv.length < 3) {
console.error('Please provide the js-dossier arguments');
process.exit(1);
} else {
args = process.argv.slice(2);
}

const compile = function(args) {
return new Promise(function(resolve, reject) {
let javaArgs = ['-jar', dossierJarPath].concat(args);

const process = childProcess.spawn('java', javaArgs);
process.stdout.on('data', function(data) {
console.log(data.toString());
});

process.stderr.on('data', function(data) {
console.log(data.toString());
});

process.on('error', function(err) {
throw new Error('js-dossier failed: ' + (err.message || 'Unspecified error'));
});

process.on('exit', function(code) {
resolve();
});
});
};

compile(args);
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": "1.0.0",
"description": "Generates API documentation for Closure projects.",
"bin": {
"os-docs": "./os-docs.js",
"os-docs-gen-config": "./genconf.js"
},
"main": "genconf.js",
Expand Down Expand Up @@ -37,7 +38,7 @@
},
"config": {
"commitizen": {
"path": "node_modules/cz-conventional-changelog"
"path": "cz-conventional-changelog"
},
"validate-commit-msg": {
"helpMessage": "\nPlease fix your commit message (consider using 'npm i -g commitizen'). Well-formatted commit messages allow us to automate our changelog and npm releases.\n\nExamples:\n\"fix(copy-view): Fixed an error when resolving paths for view directories\"\n\"feat(gcc): Added support for defines\"\n\nIf you have installed commitizen, try running 'git cz'."
Expand Down

0 comments on commit 3b3050a

Please sign in to comment.