UNPKG

gitbook-start-github-rafadanipedro

Version:
44 lines (32 loc) 1.32 kB
'use strict'; Object.defineProperty(exports, "__esModule", { value: true }); exports.default = anadirTareaAlGulpfile; var _fs = require('fs'); var _fs2 = _interopRequireDefault(_fs); var _path = require('path'); var _path2 = _interopRequireDefault(_path); var _utils = require('./utils'); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } function anadirTareaAlGulpfile(plugin) { var gulpfile = void 0; try { gulpfile = _fs2.default.readFileSync(_path2.default.resolve(process.cwd(), 'gulpfile.babel.js')).toString(); } catch (err) { return console.error('No existe un gulpfile, así que no puedo añadir la tarea'); } var variable = plugin.replace(/-(.)/g, function (m) { return m[1].toUpperCase(); }); var taskName = variable.replace(/plugin./, function (m) { return m.slice(-1).toLowerCase(); }); gulpfile = gulpfile.replace(/(gitbook-install')/, '$1\n' + ('import * as ' + variable + ' from \'' + plugin + '\'')); gulpfile = gulpfile.replace(/(export const deploy.+)\)/, '$1, ' + taskName + ')'); gulpfile += (0, _utils.getTask)(taskName, variable); escribirGulpfile(gulpfile); } function escribirGulpfile(gulpfile) { _fs2.default.writeFileSync(_path2.default.resolve(process.cwd(), 'gulpfile.babel.js'), gulpfile); }