@createjs/docs
Version:
Documentation generator for CreateJS.
45 lines (41 loc) • 1.53 kB
JavaScript
import gulp from "gulp";
import zip from "gulp-zip";
import fs from "fs";
// if the package is in node_modules, it's compiling docs for a single lib
// else, it's compiling docs for all libs
const inNodeModules = /node_modules/.test(process.cwd());
const base = inNodeModules ? "../../../" : "./";
const pkg = JSON.parse(fs.readFileSync(`${base}package.json`, { encoding: 'utf8' }));
// docs folder
const docs = `${base}docs/`;
const index = `${docs}index.md`;
let indexFound = true;
try { fs.accessSync(index); } catch (e) { indexFound = false; }
// files to read for documentation, everything inside the src folder
const files = [];
if (inNodeModules) { files.push(`${base}src/`); }
else { ["core", "easeljs", "tweenjs", "preloadjs", "soundjs"].forEach(lib => files.push(`./node_modules/@createjs/${lib}/src/`)); }
// jsdoc config
// http://usejsdoc.org/about-configuring-jsdoc.html
const conf = {
tags: {
allowUnknownTags: ["codepen", "chainable"]
},
source: {
include: files
},
plugins: [
"./node_modules/jsdoc-export-default-interop/dist/index"
],
opts: {
template: "./template2/",
readme: indexFound ? index : undefined,
destination: `${docs}${pkg.version}/`,
recurse: true,
verbose: true
}
};
// write jsdoc config file
gulp.task("write-conf", cb => fs.writeFile("./conf.json", JSON.stringify(conf), cb));
// zip generated docs for easy sharing
gulp.task("zip", () => gulp.src(`${conf.opts.destination}**/*`).pipe(zip("archive.zip")).pipe(gulp.dest(docs)));