UNPKG

gitbook-start-github-rafadanipedro

Version:
69 lines (52 loc) 2.26 kB
'use strict'; Object.defineProperty(exports, "__esModule", { value: true }); var _child_process = require('child_process'); var _path = require('path'); var _path2 = _interopRequireDefault(_path); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } function _asyncToGenerator(fn) { return function () { var gen = fn.apply(this, arguments); return new Promise(function (resolve, reject) { function step(key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { return Promise.resolve(value).then(function (value) { step("next", value); }, function (err) { step("throw", err); }); } } return step("next"); }); }; } exports.default = function () { var _ref = _asyncToGenerator(regeneratorRuntime.mark(function _callee(nombrelibro) { return regeneratorRuntime.wrap(function _callee$(_context) { while (1) { switch (_context.prev = _context.next) { case 0: process.chdir(nombrelibro); console.log("Instalando plugins libro y generando..."); _context.next = 4; return gitbookSpawn('install'); case 4: _context.next = 6; return gitbookSpawn('build', '.', './gh-pages'); case 6: process.chdir('..'); case 7: case 'end': return _context.stop(); } } }, _callee, this); })); function generateGitbook(_x) { return _ref.apply(this, arguments); } return generateGitbook; }(); function gitbookSpawn() { for (var _len = arguments.length, params = Array(_len), _key = 0; _key < _len; _key++) { params[_key] = arguments[_key]; } return new Promise(function (res, rej) { var gitbookRuta = _path2.default.resolve(__dirname, '../..', 'node_modules/gitbook-cli/bin/gitbook.js'); console.log('Llamando a gitbook-cli desde ' + gitbookRuta); var gb = (0, _child_process.spawn)('node', [gitbookRuta].concat(params)); gb.stdout.on('data', function (data) { return process.stdout.write(data.toString()); }); gb.on('close', function (code) { return code ? rej() : res(); }); }); }