-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit b65ea2d
Showing
34 changed files
with
5,131 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
const fs = require('fs'); | ||
|
||
const Generator = require('../../utils/generator'); | ||
|
||
const opts = require('./options.json'); | ||
|
||
module.exports = class extends Generator { | ||
initializing() { | ||
const isRepoInited = fs.existsSync(this.destinationPath('.git')); | ||
|
||
opts.INIT_REPO.prompt.when = !isRepoInited; | ||
|
||
this.addOptions(opts); | ||
} | ||
|
||
prompting() { | ||
const preselected = this.config.get(opts.PACKAGE_MANAGER.name); | ||
|
||
if (preselected) { | ||
opts.PACKAGE_MANAGER.default = preselected; | ||
} | ||
|
||
return this.prompt(this.promptsFromOptions(opts)).then(answers => { | ||
this.answers = answers; | ||
}); | ||
} | ||
|
||
configuring() { | ||
const answers = this.answers; | ||
const features = answers[opts.FEATURES.name]; | ||
const initRepo = answers[opts.INIT_REPO.name]; | ||
const pkgName = answers[opts.PACKAGE_MANAGER.name]; | ||
|
||
if (initRepo) { | ||
this.spawnCommandSync('git', ['init']); | ||
} | ||
|
||
this.config.set(opts.PACKAGE_MANAGER.name, pkgName); | ||
|
||
this.composeWith(require.resolve('../package')); | ||
|
||
const featuresGenerators = [ | ||
'editorconfig', | ||
'gitignore', | ||
'eslint', | ||
'conventional-commits', | ||
'test-mocha' | ||
]; | ||
|
||
featuresGenerators.forEach(name => { | ||
if (features.includes('editorconfig')) { | ||
this.composeWith(require.resolve(`../${name}`)); | ||
} | ||
}); | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
{ | ||
"INIT_REPO": { | ||
"name": "initRepo", | ||
"desc": "Do you want to initialize empty git repository", | ||
"type": "boolean", | ||
"prompt": { | ||
"type": "confirm" | ||
} | ||
}, | ||
"PACKAGE_MANAGER": { | ||
"name": "packageManager", | ||
"desc": "Package manager", | ||
"type": "string", | ||
"default": "npm", | ||
"prompt": { | ||
"type": "list", | ||
"choices": [ | ||
{ | ||
"name": "NPM", | ||
"value": "npm" | ||
}, | ||
{ | ||
"name": "Yarn", | ||
"value": "yarn" | ||
} | ||
] | ||
} | ||
}, | ||
"FEATURES": { | ||
"name": "features", | ||
"desc": "Select what to setup", | ||
"type": "array", | ||
"prompt": { | ||
"type": "checkbox", | ||
"choices": [ | ||
{ | ||
"name": ".editorconfig", | ||
"value": "editorconfig", | ||
"checked": true | ||
}, | ||
{ | ||
"name": ".gitignore", | ||
"value": "gitignore", | ||
"checked": true | ||
}, | ||
{ | ||
"name": "Eslint preset", | ||
"value": "eslint", | ||
"checked": true | ||
}, | ||
{ | ||
"name": "Conventional commits", | ||
"value": "conventional-commits", | ||
"checked": true | ||
}, | ||
{ | ||
"name": "Generic testing env (mocha + chai)", | ||
"value": "test-mocha", | ||
"checked": true | ||
} | ||
] | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
const Generator = require('../../utils/generator'); | ||
|
||
module.exports = class extends Generator { | ||
writing() { | ||
if (this.isPackageJsonExist()) { | ||
const pkg = this.readPackageJson(); | ||
const config = pkg.config || {}; | ||
|
||
config.commitizen = { path: 'node_modules/cz-customizable' }; | ||
config['cz-customizable'] = { config: '.cz-config.js' }; | ||
|
||
pkg.scripts.commit = 'git-cz'; | ||
pkg.scripts.commitmsg = 'cz-customizable-ghooks'; | ||
|
||
this.writePackageJson(pkg); | ||
} | ||
|
||
this.copy('.commitizen.config.js'); | ||
} | ||
|
||
install() { | ||
this.i([ | ||
'commitizen', | ||
'cz-customizable', | ||
'cz-customizable-ghooks', | ||
'husky' | ||
]); | ||
} | ||
|
||
end() { | ||
// Setup husky manually | ||
this.spawnCommandSync('node', ['node_modules/husky/bin/install.js']); | ||
} | ||
}; |
44 changes: 44 additions & 0 deletions
44
generators/conventional-commits/templates/.commitizen.config.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
/** | ||
* @see https://github.com/leonardoanalista/cz-customizable#options | ||
*/ | ||
module.exports = { | ||
types: [ | ||
{value: 'feat', name: 'feat: A new feature'}, | ||
{value: 'fix', name: 'fix: A bug fix'}, | ||
{value: 'docs', name: 'docs: Documentation changes'}, | ||
{value: 'style', name: 'style: Changes that do not affect the meaning of the code (white-space, formatting, missing semi-colons, etc)'}, | ||
{value: 'refactor', name: 'refactor: A code change that neither fixes a bug nor adds a feature'}, | ||
{value: 'perf', name: 'perf: A code change that improves performance'}, | ||
{value: 'test', name: 'test: Adding missing tests or update existing'}, | ||
{value: 'chore', name: 'chore: Changes to the build process or auxiliary tools and libraries such as documentation generation'}, | ||
{value: 'ci', name: 'ci: Continuous intergation related changes'}, | ||
{value: 'scripts', name: 'scripts: Scripts related changes'}, | ||
{value: 'revert', name: 'revert: Revert to a commit'}, | ||
{value: 'WIP', name: 'WIP: Work in progress'} | ||
], | ||
|
||
/** | ||
* Specify the scopes for your particular project. Eg.: for some banking system: ["acccounts", "payments"]. | ||
* For another travelling application: ["bookings", "search", "profile"]. | ||
*/ | ||
scopes: [], | ||
|
||
/** | ||
* It needs to match the value for field type. | ||
* @example | ||
* scopeOverrides: { | ||
* fix: [ | ||
* {name: 'merge'}, | ||
* {name: 'style'}, | ||
* {name: 'e2eTest'}, | ||
* {name: 'unitTest'} | ||
* ] | ||
* } | ||
*/ | ||
scopeOverrides: {}, | ||
allowCustomScopes: true, | ||
allowBreakingChanges: ['feat', 'fix'], | ||
appendBranchNameToCommitMessage: false, | ||
breakingPrefix: 'BREAKING CHANGE:', | ||
footerPrefix: 'ISSUES CLOSED:' | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
const Generator = require('../../utils/generator'); | ||
|
||
module.exports = class extends Generator { | ||
writing() { | ||
this.copy('.editorconfig'); | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
root = true | ||
|
||
[*] | ||
indent_style = space | ||
indent_size = 2 | ||
end_of_line = lf | ||
charset = utf-8 | ||
trim_trailing_whitespace = true | ||
insert_final_newline = true |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
const Generator = require('../../utils/generator'); | ||
|
||
const opts = require('./options.json'); | ||
|
||
module.exports = class extends Generator { | ||
initializing() { | ||
opts.ADD_PRECOMMIT_HOOK.prompt.when = answers => answers[opts.ADD_LINT_SCRIPT.name] === true; | ||
this.addOptions(opts); | ||
} | ||
|
||
prompting() { | ||
return this.prompt(this.promptsFromOptions(opts)).then(answers => { | ||
this.answers = answers; | ||
}); | ||
} | ||
|
||
writing() { | ||
const { answers } = this; | ||
|
||
if (this.isPackageJsonExist() && answers[opts.ADD_LINT_SCRIPT.name]) { | ||
const pkg = this.readPackageJson(); | ||
|
||
pkg.scripts.lint = 'eslint .'; | ||
|
||
if (answers[opts.ADD_PRECOMMIT_HOOK.name]) { | ||
pkg.scripts.precommit = `${this.getPackageManager()} run lint`; | ||
} | ||
|
||
this.writePackageJson(pkg); | ||
} | ||
|
||
this.copy('.eslintrc'); | ||
this.copy('.eslintrc-test'); | ||
this.copy('.eslintignore'); | ||
} | ||
|
||
install() { | ||
this.i([ | ||
'eslint', | ||
'@kisenka/eslint-config' | ||
]); | ||
} | ||
}; | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
{ | ||
"ADD_LINT_SCRIPT": { | ||
"name": "addLintScript", | ||
"desc": "Add \"lint\" script to package.json", | ||
"type": "boolean", | ||
"default": true, | ||
"prompt": true | ||
}, | ||
"ADD_PRECOMMIT_HOOK": { | ||
"name": "addPrecommitHook", | ||
"desc": "Add \"precommit\" hook which runs \"lint\" npm script", | ||
"type": "boolean", | ||
"default": true, | ||
"prompt": { | ||
"type": "confirm" | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
build | ||
dist | ||
coverage |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
{ | ||
"root": true, | ||
"extends": [ | ||
"@kisenka/eslint-config" | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
{ | ||
"extends": [ | ||
"@kisenka/eslint-config/test", | ||
"./.eslintrc" | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
const Generator = require('../../utils/generator'); | ||
|
||
module.exports = class extends Generator { | ||
initializing() { | ||
this.argument('name', { | ||
type: String, | ||
required: true, | ||
desc: 'Generator name' | ||
}); | ||
} | ||
|
||
writing() { | ||
const { options } = this; | ||
|
||
this.copy('index.js', `generators/${options.name}/index.js`); | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
const Generator = require('../../utils/generator'); | ||
|
||
const opts = require('./options.json'); | ||
|
||
module.exports = class extends Generator { | ||
initializing() { | ||
this.printIntro( | ||
'Intro text' | ||
); | ||
|
||
// Here you can override `opts` object | ||
|
||
this.deps = []; | ||
this.addOptions(opts); | ||
} | ||
|
||
prompting() { | ||
return this.prompt(this.promptsFromOptions(opts)).then(answers => { | ||
this.answers = answers; | ||
}); | ||
} | ||
|
||
writing() { | ||
const { answers } = this; | ||
|
||
if (this.isPackageJsonExist()) { | ||
const pkg = this.readPackageJson(); | ||
|
||
// Do something... | ||
|
||
this.writePackageJson(pkg); | ||
} | ||
|
||
this.copy('some-file'); | ||
} | ||
|
||
install() { | ||
this.i(this.deps); | ||
} | ||
|
||
end() { | ||
const { answers } = this; | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
const Generator = require('../../utils/generator'); | ||
|
||
module.exports = class extends Generator { | ||
writing() { | ||
this.copy('.gitignore'); | ||
} | ||
}; |
Oops, something went wrong.