Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More →
Socket
Sign inDemoInstall
Socket

builddocs

Package Overview
Dependencies
Maintainers
1
Versions
21
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

builddocs - npm Package Compare versions

Comparing version 0.2.1 to 0.3.0

templates/markdown/class.md

6

bin/builddocs.js

@@ -5,6 +5,6 @@ var fs = require("fs")

var name, main, templates, allowUnresolved = true, files = []
var name, main, templates, allowUnresolved = true, files = [], format = "html"
function help(status) {
console.log("Usage: builddocs --name <name> --main <main> [--templates <templatedir>]\n [--disallow-unresolved] [--help] <sourcefiles>")
console.log("Usage: builddocs --name <name> --main <main> [--templates <templatedir>]\n [--disallow-unresolved] [--help] [--format <format>] <sourcefiles>")
process.exit(status)

@@ -19,2 +19,3 @@ }

else if (arg == "--disallow-unresolved") allowUnresolved = false
else if (arg == "--format") format = process.argv[++i]
else if (arg.charAt(0) != "-") files.push(arg)

@@ -31,3 +32,4 @@ else help(arg == "--help" ? 0 : 1)

templates: templates,
format,
allowUnresolvedTypes: allowUnresolved
}))
{
"name": "builddocs",
"version": "0.2.1",
"version": "0.3.0",
"description": "Build documentation files from getdocs-commented source code",

@@ -5,0 +5,0 @@ "main": "src/builddocs.js",

@@ -1,5 +0,5 @@

var fs = require("fs")
var Mold = require("mold-template")
var read = exports.read = require("./read").read
var builtins = require("./builtins")
let fs = require("fs")
let Mold = require("mold-template")
let read = exports.read = require("./read").read
let builtins = require("./builtins")

@@ -11,26 +11,38 @@ exports.browserImports = require("./browser")

var mdOptions = {html: true}
if (config.markdownOptions) for (var prop in config.markdownOptions) mdOptions[prop] = config.markdownOptions[prop]
var markdown = require("markdown-it")(mdOptions).use(require("markdown-it-deflist"))
let format = config.format || "html"
let renderItem =
format == "html" ? name => '<div data-item="' + name + '"></div>' :
format == "markdown" ? (() => {
let mold = loadMarkdownTemplates(config, data)
return name => mold.defs.item({item: data.items[name], name}).replace(/[\n␤]{2}$/g, "\n")
})()
: null
var placed = Object.create(null)
var doc = markdown.render(fs.readFileSync(config.main, "utf8").replace(/(^|\n)@(\w+)(?=$|\n)/g, function(_, before, name, after) {
let placed = Object.create(null)
let main = fs.readFileSync(config.main, "utf8").replace(/(^|\n)@(\w+)(?=$|\n)/g, function(_, before, name) {
if (placed[name]) throw new Error("Item " + name + " is included in doc template twice")
if (!data.items[name]) throw new Error("Unknown item " + name + " included in doc template")
placed[name] = true
return before + before + '<div data-item="' + name + '"></div>\n'
}))
for (var name in data.items) if (!placed[name])
return before + renderItem(name)
})
for (let name in data.items) if (!placed[name])
throw new Error("Item " + name + " is missing from the doc template")
var mold = loadTemplates(markdown, config, data)
if (format == "markdown") {
return main.replace(/␤/g, "\n")
} else if (format == "html") {
let mdOptions = {html: true}
if (config.markdownOptions) for (let prop in config.markdownOptions) mdOptions[prop] = config.markdownOptions[prop]
let markdown = require("markdown-it")(mdOptions).use(require("markdown-it-deflist"))
let mold = loadHTMLTemplates(markdown, config, data)
return doc.replace(/<div data-item="([^"]+)"><\/div>/g, function(_, name) {
let item = data.items[name]
return mold.defs.item({item: item, name: name})
})
let doc = markdown.render(main)
return doc.replace(/<div data-item="([^"]+)"><\/div>/g, function(_, name) {
return mold.defs.item({item: data.items[name], name})
})
}
}
function prefix(config) {
var prefix = config.anchorPrefix
let prefix = config.anchorPrefix
if (prefix == null) prefix = config.name + "."

@@ -40,4 +52,12 @@ return prefix

function loadTemplates(markdown, config, data) {
var mold = new Mold(moldEnv(config, data))
function templateDir(mold, dir, ext) {
fs.readdirSync(dir).forEach(function(filename) {
let match = /^(.*?)\.(\w+)$/.exec(filename)
if (match && match[2] == ext && !(match[1] in mold.defs))
mold.bake(match[1], fs.readFileSync(dir + "/" + filename, "utf8").trim())
})
}
function loadHTMLTemplates(markdown, config, data) {
let mold = new Mold(moldEnv(config, data))
mold.defs.markdown = function(text) {

@@ -51,13 +71,17 @@ if (!text) return ""

function templateDir(dir) {
fs.readdirSync(dir).forEach(function(filename) {
var match = /^(.*?)\.html$/.exec(filename)
if (match && !(match[1] in mold.defs))
mold.bake(match[1], fs.readFileSync(dir + "/" + match[1] + ".html", "utf8").trim())
})
if (config.templates) templateDir(mold, config.templates, "html")
templateDir(mold, __dirname + "/../templates", "html")
return mold
}
function loadMarkdownTemplates(config, data) {
let mold = new Mold(moldEnv(config, data))
if (config.templates) templateDir(mold, config.templates, "md")
templateDir(mold, __dirname + "/../templates/markdown", "md")
mold.defs.indent = function({text, depth}) {
return text.trim().split("\n").map(line => /\S/.test(line) ? " ".repeat(depth) + line : "").join("\n")
}
if (config.templates) templateDir(config.templates)
templateDir(__dirname + "/../templates")
return mold

@@ -69,10 +93,10 @@ }

if (name.charAt(0) == '"') return false
var imports = config.imports, qualified = config.qualifiedImports
if (imports) for (var i = 0; i < imports.length; i++) {
var set = imports[i]
let imports = config.imports, qualified = config.qualifiedImports
if (imports) for (let i = 0; i < imports.length; i++) {
let set = imports[i]
if (Object.prototype.hasOwnProperty.call(set, name))
return set[name]
}
if (qualified) for (var pref in qualified) if (name.indexOf(pref + ".") == 0) {
var inner = name.slice(pref.length + 1)
if (qualified) for (let pref in qualified) if (name.indexOf(pref + ".") == 0) {
let inner = name.slice(pref.length + 1)
if (Object.prototype.hasOwnProperty.call(qualified[pref], inner))

@@ -85,6 +109,6 @@ return qualified[pref][inner]

function moldEnv(config, data) {
var env = {
let env = {
prefix: prefix(config),
linkType: function(type) {
var link = maybeLinkType(config, data, type.type)
let link = maybeLinkType(config, data, type.type)
if (!link && link !== false && !config.allowUnresolvedTypes)

@@ -96,5 +120,5 @@ throw new Error("Unknown type '" + type.type + "' at " + type.loc.file + ":" + type.loc.line)

if (type.description) return true
if (type.properties) for (var prop in type.properties)
if (type.properties) for (let prop in type.properties)
if (env.hasDescription(type.properties[prop])) return true
if (type.params) for (var i = 0; i < type.params.length; i++)
if (type.params) for (let i = 0; i < type.params.length; i++)
if (env.hasDescription(type.params[i])) return true

@@ -105,4 +129,4 @@ if (type.returns && type.returns.description) return true

}
if (config.env) for (var prop in config.env) env[prop] = config.env[prop]
if (config.env) for (let prop in config.env) env[prop] = config.env[prop]
return env
}

@@ -1,18 +0,17 @@

var fs = require("fs")
var glob = require("glob")
var getdocs = require("getdocs")
let fs = require("fs")
let glob = require("glob")
let getdocs = require("getdocs")
exports.read = function(config) {
var items = Object.create(null)
var files = config.files.split(" ").reduce(function(set, pat) {
let items = Object.create(null)
let files = config.files.split(" ").reduce(function(set, pat) {
return set.concat(glob.sync(pat))
}, [])
files.forEach(function(filename) {
last = null
var file = fs.readFileSync(filename, "utf8")
getdocs.gather(file, {filename: filename, items: items})
let file = fs.readFileSync(filename, "utf8")
getdocs.gather(file, {filename, items})
})
return {
items: items,
items,
all: gatherAll({properties: items}, Object.create(null))

@@ -25,5 +24,5 @@ }

if (Object.prototype.hasOwnProperty.call(obj, "constructor")) gatherAll(obj.constructor, target)
if (obj.properties) for (var prop in obj.properties) gatherAll(obj.properties[prop], target)
if (obj.staticProperties) for (var prop in obj.staticProperties) gatherAll(obj.staticProperties[prop], target)
if (obj.properties) for (let prop in obj.properties) gatherAll(obj.properties[prop], target)
if (obj.staticProperties) for (let prop in obj.staticProperties) gatherAll(obj.staticProperties[prop], target)
return target
}
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc