Skip to content

Commit

Permalink
chore: initial
Browse files Browse the repository at this point in the history
  • Loading branch information
kisenka committed Oct 9, 2017
0 parents commit b65ea2d
Show file tree
Hide file tree
Showing 34 changed files with 5,131 additions and 0 deletions.
56 changes: 56 additions & 0 deletions generators/app/index.js
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}`));
}
});
}
};
64 changes: 64 additions & 0 deletions generators/app/options.json
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
}
]
}
}
}
34 changes: 34 additions & 0 deletions generators/conventional-commits/index.js
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 generators/conventional-commits/templates/.commitizen.config.js
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:'
};
7 changes: 7 additions & 0 deletions generators/editorconfig/index.js
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');
}
};
9 changes: 9 additions & 0 deletions generators/editorconfig/templates/.editorconfig
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
45 changes: 45 additions & 0 deletions generators/eslint/index.js
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'
]);
}
};


18 changes: 18 additions & 0 deletions generators/eslint/options.json
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"
}
}
}
3 changes: 3 additions & 0 deletions generators/eslint/templates/.eslintignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
build
dist
coverage
6 changes: 6 additions & 0 deletions generators/eslint/templates/.eslintrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"root": true,
"extends": [
"@kisenka/eslint-config"
]
}
6 changes: 6 additions & 0 deletions generators/eslint/templates/.eslintrc-test
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"extends": [
"@kisenka/eslint-config/test",
"./.eslintrc"
]
}
17 changes: 17 additions & 0 deletions generators/generator/index.js
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`);
}
};
44 changes: 44 additions & 0 deletions generators/generator/templates/index.js
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;
}
};
7 changes: 7 additions & 0 deletions generators/gitignore/index.js
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');
}
};

0 comments on commit b65ea2d

Please sign in to comment.