UNPKG

generator-verdaccio-plugin

Version:
125 lines (122 loc) 4.97 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.default = void 0; var _chalk = _interopRequireDefault(require("chalk")); var _lodash = _interopRequireDefault(require("lodash")); var _path = require("path"); var _yeomanGenerator = _interopRequireDefault(require("yeoman-generator")); var _yosay = _interopRequireDefault(require("yosay")); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } class PluginGenerator extends _yeomanGenerator.default { projectName = 'verdaccio-'; destinationPathName = 'verdaccio-'; constructor(args, opts) { super(args, opts); this.props = {}; } prompting() { this.log((0, _yosay.default)(`Welcome to ${_chalk.default.red('generator-verdaccio-plugin')} plugin generator!`)); const prompts = [{ type: 'list', name: 'pluginType', require: true, message: 'What kind of plugin you want to create?', store: true, choices: [{ value: 'auth' }, { value: 'storage' }, { value: 'middleware' }] }, { type: 'input', name: 'name', require: true, message: `What's the plugin name? The prefix (verdaccio-xxx) will be added automatically`, default: 'customname', validate: function (input) { if (input.startsWith('verdaccio-')) { return false; } else if (input === '') { return false; } return true; } }, { type: 'input', name: 'description', message: 'Please, describe your plugin', default: 'An amazing verdaccio plugin' }, { name: 'githubUsername', message: 'GitHub username or Organization', validate: function (input) { return input !== ''; } }, { name: 'authorName', message: "Author's Name", store: true }, { name: 'authorEmail', message: "Author's Email", store: true }, { name: 'keywords', message: 'Key your keywords (comma to split)', filter: function (keywords) { return _lodash.default.uniq(_lodash.default.words(keywords).concat(['verdaccio-'])); } }]; return this.prompt(prompts).then(function (_props) { // To access props later use this.props.someAnswer; // @ts-ignore this.props = _props; const { name, githubUsername } = _props; // @ts-ignore this.props.license = 'MIT'; if (githubUsername) { // @ts-ignore this.props.repository = githubUsername + '/' + name; } // @ts-ignore this.projectName = `verdaccio-${name}`; // @ts-ignore this.destinationPathName = (0, _path.resolve)(this.projectName); // @ts-ignore this.props.name = this.projectName; }.bind(this)); } packageJSON() { const { pluginType } = this.props; const pkgJsonLocation = `${pluginType}/_package.json`; this.fs.copyTpl(this.templatePath(pkgJsonLocation), this.destinationPath((0, _path.resolve)(this.destinationPathName, 'package.json')), this.props); } writing() { this.fs.copy(this.templatePath(`common/gitignore`), this.destinationPath((0, _path.resolve)(this.destinationPathName, '.gitignore'))); this.fs.copy(this.templatePath(`common/npmignore`), this.destinationPath((0, _path.resolve)(this.destinationPathName, '.npmignore'))); this.fs.copy(this.templatePath(`common/jest.config.js`), this.destinationPath((0, _path.resolve)(this.destinationPathName, 'jest.config.js'))); this.fs.copyTpl(this.templatePath(`common/README.md`), this.destinationPath((0, _path.resolve)(this.destinationPathName, 'README.md')), this.props); this.fs.copyTpl(this.templatePath(`common/eslintrc`), this.destinationPath((0, _path.resolve)(this.destinationPathName, '.eslintrc')), this.props); this.fs.copyTpl(this.templatePath(`common/eslintignore`), this.destinationPath((0, _path.resolve)(this.destinationPathName, '.eslintignore')), this.props); this.fs.copy(this.templatePath(`${this.props.pluginType}/src`), this.destinationPath((0, _path.resolve)(this.destinationPathName, 'src'))); this.fs.copy(this.templatePath(`common/index.js`), this.destinationPath((0, _path.resolve)(this.destinationPathName, `index.js`))); this.fs.copy(this.templatePath(`common/tsconfig.json`), this.destinationPath((0, _path.resolve)(this.destinationPathName, 'tsconfig.json'))); this.fs.copy(this.templatePath(`${this.props.pluginType}/types`), this.destinationPath((0, _path.resolve)(this.destinationPathName, 'types'))); this.fs.copy(this.templatePath(`common/editorconfig`), this.destinationPath((0, _path.resolve)(this.destinationPathName, '.editorconfig'))); } install() { process.chdir(this.projectName); // this.installDependencies({ npm: true, bower: false }); } } var _default = exports.default = PluginGenerator; //# sourceMappingURL=index.js.map