UNPKG

zapier-platform-cli

Version:

The CLI for apps in the Zapier Developer Platform.

86 lines (66 loc) 2.96 kB
#!/usr/bin/env node 'use strict'; var fs = require('fs'); var path = require('path'); var _ = require('lodash'); var toc = require('markdown-toc'); var litdoc = require('litdoc'); var commands = require('../commands'); var block = function block(str) { return '> ' + str.split('\n').join('\n> '); }; var LAMBDA_VERSION = require('../constants').LAMBDA_VERSION; // Takes all the cmd.docs and puts them into a big md file. var generateCliMarkdown = function generateCliMarkdown() { return _.orderBy(Object.keys(commands)).filter(function (name) { return !commands[name].hide; }).map(function (name) { var command = commands[name]; return (' ## ' + name + '\n\n ' + block(command.help) + '\n\n **Usage:** `' + (command.usage || command.example) + '`\n\n ' + command.docs + '\n ').trim(); }).join('\n\n\n'); }; // Writes out a big markdown file for the cli. var writeCliDocs = function writeCliDocs() { var _ref = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {}, markdownPath = _ref.markdownPath; var docs = generateCliMarkdown(); fs.writeFileSync(markdownPath, '# Zapier CLI Reference\n\nThese are the generated docs for all Zapier platform CLI commands.\n\nYou can install the CLI with `npm install -g zapier-platform-cli`.\n\n' + '```' + 'bash\n$ npm install -g zapier-platform-cli\n' + '```' + '\n\n# Commands\n\n' + docs + '\n'); }; // replaces line with file contents if line has [insert-file:xxx] var maybeInsertSnippet = function maybeInsertSnippet(line) { var m = line.match(/\[insert-file:(.+)\]/); if (m) { var file = path.resolve(__dirname, '../..', m[1]); return fs.readFileSync(file, 'utf8'); } return line; }; var fillLambdaVersion = function fillLambdaVersion(line) { return line.replace(/LAMBDA_VERSION/g, LAMBDA_VERSION); }; // Inserts code snippets from README-source.md into README.md var buildReadme = function buildReadme() { var readmeSrc = path.resolve(__dirname, '../../README-source.md'); var readmeDst = path.resolve(__dirname, '../../README.md'); var lines = fs.readFileSync(readmeSrc, 'utf8').split('\n'); var newLines = lines.map(maybeInsertSnippet).map(fillLambdaVersion).join('\n'); var tocInstered = toc.insert(newLines); fs.writeFileSync(readmeDst, '<!-- GENERATED! ONLY EDIT `README-source.md` -->\n\n' + tocInstered); }; buildReadme(); writeCliDocs({ markdownPath: './docs/cli.md' }); litdoc({ title: 'Zapier Platform CLI Documentation', markdownPath: path.join(__dirname, '../../README.md'), outputPath: path.join(__dirname, '../../docs/index.html'), templatePath: path.join(__dirname, '../../docs/template.jst') }); // TODO: toc(../../docs/README.md) to ../../README.md litdoc({ title: 'Zapier Platform CLI Reference', markdownPath: path.join(__dirname, '../../docs/cli.md'), outputPath: path.join(__dirname, '../../docs/cli.html'), templatePath: path.join(__dirname, '../../docs/template.jst') });