UNPKG

chordsong

Version:

ChordSong is a simple text format for the notation of lyrics with guitar chords, and an application that renders them to portable HTML pages.

38 lines 2.13 kB
#!/usr/bin/env node "use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); const fs_1 = require("fs"); const commander_1 = require("commander"); const index_1 = __importDefault(require("./index")); const path_1 = require("path"); const pkgJson = JSON.parse((0, fs_1.readFileSync)((0, path_1.join)(__dirname, '../package.json'), 'utf8')); commander_1.program.showHelpAfterError(); commander_1.program.version(pkgJson.version, '-v, --version', 'output the current version'); commander_1.program.showHelpAfterError(); commander_1.program.arguments('<inputfile>'); commander_1.program.option('-o, --output <outputfile>', 'set the output file name. If omitted the output filename is the input one with the extension switched to .html'); commander_1.program.option('-r, --render-mode <mode>', 'select default render mode. Either \'chordName\' or \'diagram\'', 'chordName'); commander_1.program.option('-t, --theme <theme>', 'force using a user-provided theme instead of the default one. Generate a directory at ./themes/<theme> with files 00-fonts.css, 01-theme.css, 02-diagram.css, and index.html. You may take themes/default dir as reference.', 'default'); commander_1.program.parse(process.argv); console.log(commander_1.program.args); const inputFile = commander_1.program.args[0]; const options = commander_1.program.opts(); let outputFile = options.output; if (outputFile === undefined) { const pos = inputFile.lastIndexOf('.'); outputFile = inputFile.substr(0, pos < 0 ? inputFile.length : pos) + '.html'; } if (options.renderMode !== 'diagram' && options.renderMode !== 'chordName') { commander_1.program.help(); } const text = (0, fs_1.readFileSync)(inputFile, 'utf8'); const renderedSong = (0, index_1.default)(text, options.renderMode, options.theme); (0, fs_1.writeFile)(outputFile, renderedSong, 'utf8', (err) => { if (err != null) throw err; console.log('Output saved to ' + outputFile); }); //# sourceMappingURL=chordsong.js.map