gulp-typedoc
Advanced tools
Comparing version 2.0.3 to 2.1.0
46
index.js
@@ -1,15 +0,15 @@ | ||
// Copyright (c) 2015 Rogier Schouten <rogier.schouten@gmail.com> | ||
// License: ICS | ||
// Copyright (c) 2015 Rogier Schouten <github@workingcode.ninja> | ||
// License: ISC | ||
"use strict"; | ||
var es = require("event-stream"); | ||
var gutil = require("gulp-util"); | ||
var PluginError = gutil.PluginError; | ||
var typedocModule = require("typedoc"); | ||
const es = require("event-stream"); | ||
const gutil = require("gulp-util"); | ||
const PluginError = gutil.PluginError; | ||
const typedocModule = require("typedoc"); | ||
var PLUGIN_NAME = "gulp-typedoc"; | ||
const PLUGIN_NAME = "gulp-typedoc"; | ||
function typedoc(options) { | ||
var files = []; | ||
const files = []; | ||
options = options || {}; | ||
@@ -21,3 +21,3 @@ | ||
// end of stream, start typedoc | ||
var stream = this; | ||
const stream = this; | ||
@@ -33,25 +33,27 @@ if (files.length === 0) { | ||
// leaving the 'out' or 'version' option in causes typedoc error for some reason | ||
var out = options.out; | ||
const out = options.out; | ||
delete options.out; | ||
var json = options.json; | ||
const json = options.json; | ||
delete options.json; | ||
var version = options.version; | ||
const version = options.version; | ||
delete options.version; | ||
// reduce console logging | ||
options.logger = function(message, level, newline) { | ||
if (level === 3) { | ||
gutil.log(gutil.colors.red(message)); | ||
} | ||
if (!options.logger) { | ||
// reduce console logging | ||
options.logger = function(message, level, newline) { | ||
if (level === 3) { | ||
gutil.log(gutil.colors.red(message)); | ||
} | ||
}; | ||
} | ||
// typedoc instance | ||
var app = new typedocModule.Application(options); | ||
const app = new typedocModule.Application(options); | ||
if (version) { | ||
if (version && options.logger !== "none") { | ||
gutil.log(app.toString()); | ||
} | ||
try { | ||
var src = app.expandInputFiles(files); | ||
var project = app.convert(src); | ||
const src = app.expandInputFiles(files); | ||
const project = app.convert(src); | ||
if (project) { | ||
@@ -79,3 +81,3 @@ if (out) app.generateDocs(project, out); | ||
}); | ||
}; | ||
} | ||
@@ -82,0 +84,0 @@ module.exports = typedoc; |
{ | ||
"name": "gulp-typedoc", | ||
"version": "2.0.3", | ||
"version": "2.1.0", | ||
"description": "Gulp plugin for the TypeDoc typescript documentation tool.", | ||
@@ -11,3 +11,3 @@ "repository": { | ||
"scripts": { | ||
"test": "node test/test.js" | ||
"test": "mocha test/test.js" | ||
}, | ||
@@ -27,6 +27,10 @@ "keywords": [ | ||
"event-stream": "^3.3.4", | ||
"gulp-util": "^3.0.8" | ||
"gulp-util": "^3.0.8", | ||
"typedoc": "^0.8.0" | ||
}, | ||
"devDependencies": { | ||
"chai": "^4.1.2", | ||
"fs-extra": "^4.0.1", | ||
"gulp": "^3.9.1", | ||
"mocha": "^3.5.0", | ||
"rimraf": "^2.6.1" | ||
@@ -33,0 +37,0 @@ }, |
# Gulp-TypeDoc | ||
[](http://badge.fury.io/js/gulp-typedoc) | ||
[](https://nodei.co/npm/gulp-typedoc/) | ||
[](https://nodei.co/npm/gulp-typedoc/) | ||
## Synopsis | ||
Gulp plugin to execute the TypeDoc tool by Sebastian Lenz | ||
@@ -29,2 +23,4 @@ http://typedoc.org | ||
By default, the plugin will output log messages from TypeDoc. Specify `logger: 'none'` to suppress TypeDoc logging altogether. | ||
## Code Example | ||
@@ -61,2 +57,6 @@ | ||
### 2.1.0 | ||
* Add support for `logger` option. | ||
### 2.0.3 | ||
@@ -113,2 +113,3 @@ | ||
* Pascal Berger | ||
* Pedro Batista | ||
@@ -115,0 +116,0 @@ ## License |
161
test/test.js
@@ -1,18 +0,151 @@ | ||
#!node | ||
// Copyright (c) 2015 Rogier Schouten <github@workingcode.ninja> | ||
// License: ISC | ||
var assert = require("assert"); | ||
var child_process = require("child_process"); | ||
var fs = require("fs"); | ||
var path = require("path"); | ||
"use strict"; | ||
var winExt = /^win/.test(process.platform)?".cmd":""; | ||
var executable = path.join(__dirname, "..", "node_modules", ".bin", "gulp" + winExt); | ||
var args = ["--gulpfile", path.join(__dirname, "gulpfile.js")]; | ||
const chai = require("chai"); | ||
const expect = chai.expect; | ||
const child_process = require("child_process"); | ||
const fse = require("fs-extra"); | ||
const path = require("path"); | ||
const rimraf = require("rimraf"); | ||
const util = require("util"); | ||
child = child_process.spawn(path.resolve(executable), args, { | ||
stdio: "inherit", | ||
env: process.env | ||
}).on("exit", function(code) { | ||
assert(code == 0, "gulp returned nonzero exit code"); | ||
assert(fs.existsSync(path.join(__dirname, "out", "index.html")), "output documentation does not exist"); | ||
const primraf = util.promisify(rimraf); | ||
const WIN_EXT = /^win/.test(process.platform)?".cmd" : ""; | ||
const GULP_PATH = path.resolve(path.join(__dirname, "..", "node_modules", ".bin", "gulp" + WIN_EXT)); | ||
const DATA_DIR = path.join(__dirname, "data"); | ||
const TEST_DIR = path.join(__dirname, "test"); | ||
/** | ||
* Run gulp against TEST_DIR/gulpfile.js | ||
* @returns {stderr, stdout} | ||
*/ | ||
function run() { | ||
return new Promise((resolve, reject) => { | ||
const child = child_process.spawn(path.resolve(GULP_PATH), ["--gulpfile", "gulpfile.js"], { | ||
env: process.env, | ||
cwd: TEST_DIR | ||
}); | ||
let stdout = ""; | ||
let stderr = ""; | ||
child.stdout.on("data", (data) => { | ||
// console.log(data.toString()); | ||
stdout += data; | ||
}); | ||
child.stderr.on("data", (data) => { | ||
// console.error(data.toString()); | ||
stderr += data; | ||
}); | ||
child.on("exit", (code) => { | ||
if (code !== 0) { | ||
reject(new Error(util.format("non-zero exit code %d; stdout: %s, stderr: %s", code, stdout, stderr))); | ||
} else { | ||
resolve({ stdout, stderr }); | ||
} | ||
}); | ||
}); | ||
} | ||
function gulpfile(typedocOpts) { | ||
return ` | ||
const gulp = require("gulp"); | ||
const gulpTypeDoc = require("${path.relative(TEST_DIR, path.join(__dirname, "..", "index.js")).replace(/\\/g, "/")}"); | ||
// Workaround: directly calling process.exit() has corner cases where | ||
// the console.log statements are not flushed (namely if stdout is piped | ||
// instead of goes to a terminal). | ||
const exitCode = 0; | ||
process.on("exit", function() { | ||
if (exitCode != 0) process.exit(exitCode); | ||
}); | ||
// Generic error handling function | ||
// This is needed because Gulp always returns exit code 0 | ||
// unless an exception is thrown which gives a useless stack trace. | ||
function trapError(e) { | ||
if (e.plugin && e.message) { | ||
// it is a gulp plugin error | ||
console.log("Error in plugin: " + e.plugin); | ||
console.log(e.message); | ||
} | ||
else { | ||
// some other error | ||
gutil.log(e); | ||
} | ||
exitCode++; | ||
} | ||
gulp.task("default", () => { | ||
return gulp | ||
.src(["src/*.ts"]) | ||
.pipe(gulpTypeDoc(${JSON.stringify(typedocOpts)})) | ||
.on("error", trapError) // make exit code non-zero | ||
; | ||
}); | ||
`; | ||
} | ||
describe("gulp-typedoc", function() { | ||
this.timeout(60E3); | ||
beforeEach(async () => { | ||
await primraf(TEST_DIR); | ||
await fse.mkdir(TEST_DIR); | ||
await fse.mkdir(path.join(TEST_DIR, "src")); | ||
await fse.copy(path.join(DATA_DIR, "myutil.ts"), path.join(TEST_DIR, "src", "myutil.ts")) | ||
}); | ||
afterEach(async () => { | ||
await primraf(TEST_DIR); | ||
}); | ||
it("should create a .html file", async () => { | ||
const g = gulpfile({ | ||
version: true, | ||
module: "commonjs", | ||
out: "./out", | ||
json: "./out/test.json", | ||
name: "gulp-typedoc-test", | ||
target: "es5", | ||
includeDeclarations: true | ||
}); | ||
await fse.writeFile(path.join(TEST_DIR, "gulpfile.js"), g); | ||
await run(); | ||
const exists = await fse.exists(path.join(TEST_DIR, "out", "index.html")); | ||
expect(exists).to.equal(true); | ||
}); | ||
it("should enable typedoc logging when nothing specified", async () => { | ||
const g = gulpfile({ | ||
version: true, | ||
module: "commonjs", | ||
out: "./out", | ||
json: "./out/test.json", | ||
name: "gulp-typedoc-test", | ||
target: "es5", | ||
includeDeclarations: true | ||
}); | ||
await fse.writeFile(path.join(TEST_DIR, "gulpfile.js"), g); | ||
const {stdout, stderr} = await run(); | ||
expect(stdout).to.contain("Using TypeScript"); | ||
}); | ||
it("should disable typedoc logging when logger 'none' specified", async () => { | ||
const g = gulpfile({ | ||
version: true, | ||
module: "commonjs", | ||
out: "./out", | ||
json: "./out/test.json", | ||
name: "gulp-typedoc-test", | ||
target: "es5", | ||
logger: "none", | ||
includeDeclarations: true | ||
}); | ||
await fse.writeFile(path.join(TEST_DIR, "gulpfile.js"), g); | ||
const {stdout, stderr} = await run(); | ||
expect(stdout).to.not.contain("Using TypeScript"); | ||
}); | ||
}); | ||
Sorry, the diff of this file is not supported yet
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
Filesystem access
Supply chain riskAccesses the file system, and could potentially read sensitive data.
Found 1 instance in 1 package
Filesystem access
Supply chain riskAccesses the file system, and could potentially read sensitive data.
Found 1 instance in 1 package
10674
219
116
4
5
7
2
+ Addedtypedoc@^0.8.0
+ Added@types/fs-extra@4.0.15(transitive)
+ Added@types/glob@8.1.0(transitive)
+ Added@types/handlebars@4.1.0(transitive)
+ Added@types/highlight.js@9.12.4(transitive)
+ Added@types/lodash@4.17.16(transitive)
+ Added@types/marked@0.0.28(transitive)
+ Added@types/minimatch@2.0.295.1.2(transitive)
+ Added@types/node@22.13.9(transitive)
+ Added@types/shelljs@0.7.9(transitive)
+ Addedbrace-expansion@1.1.11(transitive)
+ Addedconcat-map@0.0.1(transitive)
+ Addedfs-extra@4.0.3(transitive)
+ Addedfs.realpath@1.0.0(transitive)
+ Addedfunction-bind@1.1.2(transitive)
+ Addedglob@7.2.3(transitive)
+ Addedgraceful-fs@4.2.11(transitive)
+ Addedhandlebars@4.7.8(transitive)
+ Addedhasown@2.0.2(transitive)
+ Addedhighlight.js@9.18.5(transitive)
+ Addedinflight@1.0.6(transitive)
+ Addedinterpret@1.4.0(transitive)
+ Addedis-core-module@2.16.1(transitive)
+ Addedjsonfile@4.0.0(transitive)
+ Addedlodash@4.17.21(transitive)
+ Addedmarked@0.3.19(transitive)
+ Addedminimatch@3.1.2(transitive)
+ Addedneo-async@2.6.2(transitive)
+ Addedonce@1.4.0(transitive)
+ Addedpath-is-absolute@1.0.1(transitive)
+ Addedpath-parse@1.0.7(transitive)
+ Addedprogress@2.0.3(transitive)
+ Addedrechoir@0.6.2(transitive)
+ Addedresolve@1.22.10(transitive)
+ Addedshelljs@0.7.8(transitive)
+ Addedsource-map@0.6.1(transitive)
+ Addedsupports-preserve-symlinks-flag@1.0.0(transitive)
+ Addedtypedoc@0.8.0(transitive)
+ Addedtypedoc-default-themes@0.5.0(transitive)
+ Addedtypescript@2.4.1(transitive)
+ Addeduglify-js@3.19.3(transitive)
+ Addedundici-types@6.20.0(transitive)
+ Addeduniversalify@0.1.2(transitive)
+ Addedwordwrap@1.0.0(transitive)
+ Addedwrappy@1.0.2(transitive)
- Removed@gerrit0/mini-shiki@1.27.2(transitive)
- Removed@shikijs/engine-oniguruma@1.29.2(transitive)
- Removed@shikijs/types@1.29.2(transitive)
- Removed@shikijs/vscode-textmate@10.0.2(transitive)
- Removed@types/hast@3.0.4(transitive)
- Removed@types/unist@3.0.3(transitive)
- Removedargparse@2.0.1(transitive)
- Removedbrace-expansion@2.0.1(transitive)
- Removedentities@4.5.0(transitive)
- Removedlinkify-it@5.0.0(transitive)
- Removedlunr@2.3.9(transitive)
- Removedmarkdown-it@14.1.0(transitive)
- Removedmdurl@2.0.0(transitive)
- Removedminimatch@9.0.5(transitive)
- Removedpunycode.js@2.3.1(transitive)
- Removedtypedoc@0.27.9(transitive)
- Removedtypescript@5.8.2(transitive)
- Removeduc.micro@2.1.0(transitive)
- Removedyaml@2.7.0(transitive)