Skip to content

Commit

Permalink
feat(new): add --commit-message-conventions options
Browse files Browse the repository at this point in the history
Closes #15
  • Loading branch information
Kevin Grandemange committed Apr 4, 2017
1 parent 21cc310 commit 106c260
Show file tree
Hide file tree
Showing 6 changed files with 39 additions and 4 deletions.
4 changes: 3 additions & 1 deletion bin/clea-init.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ program
.option('--make-it-progressive', 'add the default configuration for a Progressive Web App (defaults to: false)')
.option('--skip-install', 'skip installing packages (defaults to: false)')
.option('--skip-git', 'skip initializing a git repository (defaults to: false)')
.option('--commit-message-conventions', 'add commit-msg hook to force use of the Google message conventions (defaults to: false)')
.action((name) => {
if (!InitProject.UI_FRAMEWORKS.includes(program.uiFramework)) {
logger.error(`"${program.uiFramework}" ui framework is not allowed. ${chalk.blue.bold('clea help new')} to see allowed types.`);
Expand All @@ -30,7 +31,8 @@ program
uiFramework : program.uiFramework,
makeItProgressive: program.makeItProgressive !== undefined,
skipInstall : program.skipInstall !== undefined,
skipGit : program.skipGit !== undefined
skipGit : program.skipGit !== undefined,
commitMessageConventions: program.commitMessageConventions !== undefined
});
initProject.start().catch((err) => {
debug(err);
Expand Down
4 changes: 3 additions & 1 deletion bin/clea-new.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ program
.option('--make-it-progressive', 'add the default configuration for a Progressive Web App (defaults to: false)')
.option('--skip-install', 'skip installing packages (defaults to: false)')
.option('--skip-git', 'skip initializing a git repository (defaults to: false)')
.option('--commit-message-conventions', 'add commit-msg hook to force use of the Google message conventions (defaults to: false)')
.action((name) => {
if (!InitProject.UI_FRAMEWORKS.includes(program.uiFramework)) {
logger.error(`"${program.uiFramework}" ui framework is not allowed. ${chalk.blue.bold('clea help new')} to see allowed types.`);
Expand All @@ -29,7 +30,8 @@ program
uiFramework : program.uiFramework,
makeItProgressive: program.makeItProgressive !== undefined,
skipInstall : program.skipInstall !== undefined,
skipGit : program.skipGit !== undefined
skipGit : program.skipGit !== undefined,
commitMessageConventions: program.commitMessageConventions !== undefined
});
initProject.createFolder();
initProject.start().catch((err) => {
Expand Down
16 changes: 16 additions & 0 deletions bin/postinstall.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#!/usr/bin/env node

const fs = require('fs-extra'),
logger = require('../vendors/logger');

fs.copy('./tools/git/commit-msg.js', '.git/hooks/commit-msg', (err) => {
if (err) {
return logger.error(err);
}

fs.chmod('.git/hooks/commit-msg', '755', (err) => {
if (err) {
return logger.error(err);
}
});
});
2 changes: 2 additions & 0 deletions docs/new.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ clea help new

`--skip-git` skip initializing a git repository (defaults to: **false**).

`--commit-message-conventions` add commit-msg hook to force use of the [Google message conventions](../templates/application/COMMITS-CONVENTION.md) (defaults to: **false**).

### Library

You can also scaffold a new library instead of an application.
Expand Down
14 changes: 13 additions & 1 deletion lib/commands/init-project.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,13 +69,21 @@ class InitProject {
]);
}

// To copy only if `--commit-message-conventions` option has been used
if (!this.options.commitMessageConventions) {
excludedFiles = excludedFiles.concat([
'postinstall.js'
]);
}

return this.copyStaticFiles(excludedFiles)
.then(() => this.copyFiles({
appName : this.name,
slugifiedName: slugify(this.name),
ngMaterial : this.options.uiFramework === 'material',
bootstrap : this.options.uiFramework === 'bootstrap',
pwa : this.options.makeItProgressive
pwa : this.options.makeItProgressive,
commitMessageConventions : this.options.commitMessageConventions
}, excludedFiles))
.then(() => (this.options.skipGit) ? Promise.resolve() : this.initializeGit())
.then(() => (this.options.skipInstall) ? Promise.resolve() : this.installDependencies())
Expand Down Expand Up @@ -164,6 +172,10 @@ class InitProject {
.then(() => logger.info('Successfully initialized git.'));
}

addPostInstall () {
return
}

installDependencies () {
return new Promise((resolve, reject) => {
logger.info(`Installing packages for tooling via NPM.`);
Expand Down
3 changes: 2 additions & 1 deletion templates/application/_package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@
"build:prod": "clea build --target production --doc",
"test": "clea test",
"lint": "clea lint",
"sonar:reporters": "sreporter"
"sonar:reporters": "sreporter"<% if (commitMessageConventions) { %>,
"postinstall": "node ./node_modules/@clea/cli/bin/postinstall.js"<% } %>
},
"dependencies": {
"angular": "^1.6.2",
Expand Down

0 comments on commit 106c260

Please sign in to comment.