1 | const yeoman = require('yeoman-generator');
|
2 | const resolveNodeVersion = require('resolve-node-version');
|
3 | const _ = require('lodash');
|
4 | const gitConfig = require('parse-git-config');
|
5 | const githubUrl = require('github-url-to-object');
|
6 |
|
7 | module.exports = yeoman.Base.extend({
|
8 | initializing() {
|
9 | this.composeWith('@travi/git', {options: this.options}, {
|
10 | local: require.resolve('@travi/generator-git/app')
|
11 | });
|
12 |
|
13 | this.originUrl = gitConfig.sync()['remote "origin"'].url;
|
14 |
|
15 | return new Promise((resolve, reject) => {
|
16 | resolveNodeVersion('*', (err, version) => {
|
17 | this.nodeVersion = version;
|
18 |
|
19 | resolve();
|
20 | });
|
21 | });
|
22 | },
|
23 |
|
24 | prompting() {
|
25 | return this.prompt([{
|
26 | message: 'A brief description of this project',
|
27 | name: 'description'
|
28 | }]).then(props => {
|
29 | _.merge(this.options, props);
|
30 | })
|
31 | },
|
32 |
|
33 | configuring() {
|
34 | this.copy('_gitignore', '.gitignore');
|
35 | this.copy('_eslintignore', '.eslintignore');
|
36 | this.template('_nvmrc', '.nvmrc');
|
37 | this.copy('_markdownlintrc', '.markdownlintrc');
|
38 | this.copy('_nycrc', '.nycrc');
|
39 | this.copy('_npmrc', '.npmrc');
|
40 |
|
41 | this.copy('test/_mocha.opts', 'test/mocha.opts');
|
42 | this.copy('test/_canary-test.js', 'test/unit/canary-test.js');
|
43 | },
|
44 |
|
45 | writing() {
|
46 | const githubDetails = githubUrl(this.originUrl);
|
47 |
|
48 | const pkg = {
|
49 | name: this.options.projectName,
|
50 | description: this.options.description,
|
51 | license: this.options.license,
|
52 | author: this.options.fullName,
|
53 | repository: `${githubDetails.user}/${githubDetails.repo}`,
|
54 | bugs: `https://github.com/${githubDetails.user}/${githubDetails.repo}/issues`,
|
55 | homepage: `https://github.com/${githubDetails.user}/${githubDetails.repo}#readme`,
|
56 | scripts: {
|
57 | 'lint:md': 'globstar --node -- markdownlint **/*.md',
|
58 | 'tests:unit': 'mocha --recursive test/unit',
|
59 | test: 'run-s lint:* coverage',
|
60 | coverage: 'nyc run-s tests:unit',
|
61 | commitmsg: 'validate-commit-msg',
|
62 | precommit: 'npm test'
|
63 | },
|
64 | config: {
|
65 | commitizen: {
|
66 | path: './node_modules/cz-conventional-changelog'
|
67 | }
|
68 | }
|
69 | };
|
70 |
|
71 | if ('UNLICENSED' === this.options.license) {
|
72 | pkg.private = true;
|
73 | }
|
74 |
|
75 | this.fs.extendJSON(this.destinationPath('package.json'), pkg);
|
76 |
|
77 | this.fs.write(this.destinationPath('README.md'), `${this.fs.read(this.destinationPath('README.md'))}
|
78 | ${this.options.description}
|
79 |
|
80 | [![Commitizen friendly](https://img.shields.io/badge/commitizen-friendly-brightgreen.svg)](http://commitizen.github.io/cz-cli/)
|
81 | `)
|
82 | },
|
83 |
|
84 | install() {
|
85 | this.npmInstall([
|
86 | 'npm-run-all',
|
87 | 'husky',
|
88 | 'validate-commit-msg',
|
89 | 'cz-conventional-changelog',
|
90 | 'mocha',
|
91 | 'chai',
|
92 | '@travi/any',
|
93 | 'markdownlint-cli',
|
94 | 'globstar',
|
95 | 'nyc'
|
96 | ], {saveDev: true});
|
97 | }
|
98 | });
|