Commit 3435c706 authored by Jarrod's avatar Jarrod 💬

Initial commit

parents
Pipeline #102 failed with stages
in 1 second
# Dependency directory
# https://docs.npmjs.com/misc/faq#should-i-check-my-node-modules-folder-into-git
node_modules
coverage
.nyc_output
#!/usr/bin/env node
/**
* Module dependencies.
*/
var program = require('commander');
var pkg = require('./package.json');
var path = require('path');
var fs = require('fs');
/*
var NpmApi = require('npm-api');
var npm = new NpmApi();
var repo = npm.repo('micromatch');
repo.package()
.then(function(pkg) {
console.log(pkg);
}, function(err) {
console.error(err);
});
*/
program
.version(pkg.version, '-v, --version')
.name(pkg.name)
.usage('--output ./docs')
.description(pkg.description)
// .option('-i, --input <path>', 'Location of the machinepack (if not the current directory/node package)')
// .option('-o, --output <path>', 'Output directory', './mp-doc')
.option('-o, --output <path>', 'Output directory', 'TESTING')
.option('-f, --force', 'Clobber the output directory if it already exists')
.parse(process.argv);
var cwd = process.cwd();
var outDir = path.join(cwd, program.output);
// Check that `cwd` has machines defined in its `package.json`
let mpkgPath = path.join(cwd, 'package.json');
if (!fs.existsSync(mpkgPath)) {
console.error('Uh oh..');
console.error('I tried to find a `package.json` file in the current directory, but I canneh do it cap\'n!');
console.error('Are you sure you\'re running this script from the root of your machinepack project?');
process.exit(1);
}
let mpkg = require(path.join(cwd, 'package.json'));
// Load the machinepack
// Should it check the `machinepack` dependency version? :)
if (!mpkg || !mpkg.main || !mpkg.machinepack || !mpkg.machinepack.machineDir || !mpkg.machinepack.machines) {
console.error('Uh oh..');
console.error('I found a \'package.json\' file, but I can\'t find any machines...');
console.error('Are you sure you\'re running this script from the root of your machinepack project?');
process.exit(1);
}
let mpIndex = path.join(cwd, mpkg.main);
let mp = require(mpIndex);
if (!mp || !mp.toJSON()) {
console.error('Doesn\'t look like this is actually a machinepack...');
process.exit(1);
}
let jsonmp = mp.toJSON();
// TODO: isObject?|isEmpty?
if (!jsonmp.defs) {
console.error('Doesn\'t look like this is actually a machinepack,');
console.error('or there are no machines defined so why build docs for them?');
process.exit(1);
}
// Check that the output directory doesn't exist && --force wasn't specified
if (fs.existsSync(outDir)) {
if (!program.force) {
console.error('Uh oh..');
console.error(`Looks like the output directory '${program.output}' already exists.`);
console.error('I\'m gonna stop you right there, but if you\'re sure you wanna go ahead try again with the `--force` flag.');
process.exit(1);
} else {
// console.info(' * Cleaning existing directory \'' + program.output + '\'');
fs.rmdirSync(outDir);
}
}
// Make output directory
fs.mkdirSync(outDir);
require('./lib/pugify')(mpkg, mp, outDir, pkg);
/*
> mp.toJSON()
{ name: 'zh-cangjie',
version: '0.2.0',
description: 'Convert strings to/from cangjie chars (人弓火 -> ONF / ONF -> 人弓火) and convert chinese characters to/from cangjie (雨 -> 一中月卜/MLBY -> 雨)',
license: 'MIT',
customize: { arginStyle: 'serial', execStyle: 'natural' },
defs:
{ 'to-cangjie':
{ identity: 'to-cangjie',
friendlyName: 'To cangjie',
description: 'Convert an alpha string (MGILG) to cangjie chars (一土戈中土)',
sync: true,
inputs: [Object],
exits: [Object],
fn: [Function: fn],
implementationType: 'analog',
args: [Array] },
'from-cangjie':
{ identity: 'from-cangjie',
friendlyName: 'From cangjie',
description: 'Convert cangjie characters (一土戈中土) into alpha string (MGILG)',
sync: true,
inputs: [Object],
exits: [Object],
fn: [Function: fn],
implementationType: 'analog',
args: [Array] },
'for-character':
{ identity: 'for-character',
friendlyName: 'For Character',
description: 'Find the cangjie representation of a given 漢字',
sync: false,
inputs: [Object],
exits: [Object],
fn: [Function: fn],
implementationType: 'analog',
args: [Array] },
'find-characters':
{ identity: 'find-characters',
friendlyName: 'Find Characters',
description: 'Search for characters (雨) that match a given search query (ML)',
sync: false,
inputs: [Object],
exits: [Object],
fn: [Function: fn],
implementationType: 'analog',
args: [Array] } } }
*/
var pug = require('pug');
var path = require('path');
var fs = require('fs');
/*
* Generate and output files somewhere
* Can we add npm version/travis/gitlab/coverage badges somehow? That'd be cool
* can w use this? https://jenil.github.io/bulmaswatch/materia/
* maybe this is noicer https://jenil.github.io/bulmaswatch/minty/
*
* index.html (overview?)
* |__ mach1.html
* |__ mach2.html
* |__ mach3.html
* | |__ mach3.1.html?
* |__ mach4.html
* |__ LICENSE?
*/
module.exports = function(pkg, pack, outDir, mpdocpkg) {
let mp = pack.toJSON();
var packTpl = pug.compileFile(path.join(__dirname, '../templates/pack.pug'));
var machineTpl = pug.compileFile(path.join(__dirname, '../templates/machine.pug'));
// For each pack, run the templater and output the file somewhere
let index = packTpl({
pkg,
pack,
mp,
mpdoc: mpdocpkg
});
fs.writeFileSync(path.join(outDir, 'index.html'), index);
Object.keys(pack).forEach((key) => {
let def = pack[key].getDef();
let outfile = path.join(outDir, def.identity + '.html');
let compiled = machineTpl({
pkg,
pack,
mp,
method: key,
machine: def,
mpdoc: mpdocpkg
});
fs.writeFileSync(outfile, compiled);
});
// mp.defs.forEach(() => {
// console.log(machineTpl({
// machine
// }));
// });
};
This diff is collapsed.
{
"name": "mpdoc",
"version": "0.0.1",
"description": "Machinepack HTML documentation generator",
"homepage": "",
"main": "index.js",
"scripts": {
"test": "echo 'NO TESTS SPECIFIED' && exit 1"
},
"bin": {
"mpdoc": "index.js"
},
"keywords": [
"machinepack",
"documentation",
"jsdoc"
],
"author": "Jarrod Linahan",
"license": "WTFPL",
"dependencies": {
"commander": "^2.19.0",
"npm-api": "^0.4.12",
"pug": "^2.0.3"
}
}
This diff is collapsed.
doctype html
html
head
meta(charset='utf-8')
meta(name='viewport', content='width=device-width, initial-scale=1')
title= mp.name + ' ' + mp.version
link(rel='stylesheet', href='https://cdnjs.cloudflare.com/ajax/libs/bulma/0.7.2/css/bulma.min.css')
body
section.hero.is-info
.hero-body
.container
h1.title
a(href='./index.html')= mp.name
| &nbsp;
span.subtitle= mp.version
p= mp.description
section.container
.columns
.column.is-9s
section.section.content
block body
.column.is-3
aside.menu.section
p.menu-label Machines
ul.menu-list
li
a(href='./index.html')= mp.name
each key in Object.keys(pack)
li
a(href='./' + pack[key].getDef().identity + '.html')= '.' + key + '()'
section.footer
p.has-text-centered
| This page was generated by&nbsp;
a(href=mpdoc.homepage)= mpdoc.name
| &nbsp;v
= mpdoc.version
extends layout.pug
block body
//- pre
= JSON.stringify(mp, null, 4)
h2= '.' + method + '()'
p= machine.description
h2 Usage
h3 Inputs
each input, name in machine.inputs
h4
strong= name
| &nbsp;
i(style='font-weight: normal')= input.type
if input.description
p= input.description
if input.example
p
strong Example
p= JSON.stringify(input.example)
pre= JSON.stringify(input, null, 4)
h3 Exits
each exit, name in machine.exits
p
strong= name
pre= JSON.stringify(exit, null, 4)
pre= JSON.stringify(machine, null, 4)
h4 Source Code
pre= machine.fn
extends layout.pug
block body
//- pre
= JSON.stringify(mp, null, 4)
if !pkg.private
h2 Installation
pre
| npm install --save&nbsp;
= pkg.name
h2 Usage
h3 Methods
each key in Object.keys(pack)
p
a(href='./' + pack[key].getDef().identity + '.html')= '.' + key + '()'
| &nbsp;
= pack[key].getDef().description
//- pre= JSON.stringify(pack[key], null, 4)
if pkg.dependencies
h3 Dependencies
ul
each version, name in pkg.dependencies
li= name + ' ' + version
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment