-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor(sub-generators): refactor to sub-generators
- Loading branch information
Showing
32 changed files
with
467 additions
and
365 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 |
---|---|---|
@@ -1,4 +1,4 @@ | ||
src/app/templates | ||
**/templates/** | ||
./app/ | ||
coverage/ | ||
package-lock.json | ||
|
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 |
---|---|---|
@@ -1,5 +1,6 @@ | ||
# Source | ||
src | ||
scripts | ||
|
||
# Logs | ||
logs | ||
|
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
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,5 @@ | ||
#!/bin/bash | ||
|
||
cp -r ./src/app/generators/project/templates ./app/generators/project/templates | ||
cp -r ./src/app/generators/github/templates ./app/generators/github/templates | ||
cp -r ./src/app/generators/travis/templates ./app/generators/travis/templates |
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,13 @@ | ||
const Generator = require('yeoman-generator'); | ||
|
||
const options = require('../options'); | ||
|
||
module.exports = class extends Generator { | ||
constructor(...args) { | ||
super(...args); | ||
|
||
for (const [name, value] of Object.entries(options)) { | ||
this.option(name, value); | ||
} | ||
} | ||
}; |
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,37 @@ | ||
const BaseGenerator = require('../base-generator'); | ||
|
||
const github = require('../../lib/github'); | ||
|
||
module.exports = class extends BaseGenerator { | ||
writing() { | ||
if (this.options.githubTemplates) { | ||
const templatesToCopy = [ | ||
{ templatePath: '_github', destinationPath: '.github' }, | ||
{ templatePath: 'other', destinationPath: 'other' }, | ||
{ templatePath: 'contributing.md', destinationPath: 'contributing.md' }, | ||
]; | ||
|
||
templatesToCopy.forEach(({ templatePath, destinationPath }) => | ||
this.fs.copyTpl( | ||
this.templatePath(templatePath), | ||
this.destinationPath(destinationPath), | ||
this.options | ||
) | ||
); | ||
} | ||
} | ||
|
||
async end() { | ||
if (this.options.createGithubRepository) { | ||
const { | ||
data: { html_url: url }, | ||
} = await github.createRepository({ | ||
name: this.options.projectName, | ||
description: this.options.description, | ||
}); | ||
|
||
this.log('\n\n'); | ||
this.log(`Repository created: ${url}`); | ||
} | ||
} | ||
}; |
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
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,101 @@ | ||
const path = require('path'); | ||
const chalk = require('chalk'); | ||
const commandExists = require('command-exists'); | ||
const findUp = require('find-up'); | ||
const makeDir = require('make-dir'); | ||
|
||
const BaseGenerator = require('../base-generator'); | ||
|
||
module.exports = class extends BaseGenerator { | ||
/* | ||
Run Loop | ||
*/ | ||
|
||
configuring() { | ||
if (path.basename(this.destinationRoot()) !== this.options.projectName) { | ||
return makeDir(this.options.projectName).then(path => { | ||
this.destinationRoot(path); | ||
this.log(`\nGenerating a new project in ${chalk.green(path)}\n`); | ||
}); | ||
} | ||
} | ||
|
||
writing() { | ||
const templatesToCopy = [ | ||
{ templatePath: '_babelrc', destinationPath: '.babelrc' }, | ||
{ templatePath: '_editorconfig', destinationPath: '.editorconfig' }, | ||
{ templatePath: '_eslintignore', destinationPath: '.eslintignore' }, | ||
{ templatePath: '_eslintrc', destinationPath: '.eslintrc' }, | ||
{ templatePath: '_gitattributes', destinationPath: '.gitattributes' }, | ||
{ templatePath: '_gitignore', destinationPath: '.gitignore' }, | ||
{ templatePath: '_npmignore', destinationPath: '.npmignore' }, | ||
{ templatePath: '_package.json', destinationPath: 'package.json' }, | ||
{ templatePath: 'license', destinationPath: 'license' }, | ||
{ templatePath: 'readme.md', destinationPath: 'readme.md' }, | ||
{ templatePath: 'src', destinationPath: 'src' }, | ||
]; | ||
|
||
templatesToCopy.forEach(({ templatePath, destinationPath }) => | ||
this.fs.copyTpl( | ||
this.templatePath(templatePath), | ||
this.destinationPath(destinationPath), | ||
this.options | ||
) | ||
); | ||
} | ||
|
||
async install() { | ||
this._installNpmDeps(); | ||
} | ||
|
||
async end() { | ||
await this._removeYoRc(); | ||
|
||
this._createGit(); | ||
} | ||
|
||
/* | ||
Private Methods | ||
*/ | ||
|
||
_installNpmDeps() { | ||
const hasYarn = commandExists.sync('yarn'); | ||
|
||
this.installDependencies({ | ||
bower: false, | ||
npm: !hasYarn, | ||
yarn: hasYarn, | ||
}); | ||
} | ||
|
||
_createGit() { | ||
const { repository } = this.options; | ||
|
||
this.spawnCommandSync('git', ['init', '--quiet']); | ||
this.spawnCommandSync('git', [ | ||
'remote', | ||
'add', | ||
'origin', | ||
`git@github.com:${repository}.git`, | ||
]); | ||
this.spawnCommandSync('git', ['add', '.']); | ||
this.spawnCommandSync('git', [ | ||
'commit', | ||
'-m', | ||
'Generated by generator-node-mdl 🔥', | ||
'--quiet', | ||
]); | ||
} | ||
|
||
async _removeYoRc() { | ||
const yoRC = await findUp('.yo-rc.json'); | ||
|
||
if (yoRC) { | ||
this.fs.delete(yoRC); | ||
|
||
await new Promise((resolve, reject) => { | ||
this.fs.commit(() => resolve()); | ||
}); | ||
} | ||
} | ||
}; |
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
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
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
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,38 @@ | ||
const BaseGenerator = require('../base-generator'); | ||
|
||
module.exports = class extends BaseGenerator { | ||
writing() { | ||
this.fs.copyTpl( | ||
this.templatePath('_travis.yml'), | ||
this.destinationPath('.travis.yml'), | ||
this.options | ||
); | ||
} | ||
|
||
async install() { | ||
if (process.env.NODE_ENV === 'test') return; | ||
|
||
const { repository, npmDeploy, npmToken } = this.props; | ||
|
||
this.spawnCommandSync('gem', [ | ||
'install', | ||
'travis', | ||
'--no-ri', | ||
'--no-rdoc', | ||
'--quiet', | ||
]); | ||
this.spawnCommandSync('travis', ['login', '--auto']); | ||
this.spawnCommandSync('travis', ['enable', '-r', repository]); | ||
|
||
if (npmDeploy) { | ||
this.spawnCommandSync('travis', [ | ||
'env', | ||
'set', | ||
'NPM_TOKEN', | ||
npmToken, | ||
'-r', | ||
repository, | ||
]); | ||
} | ||
} | ||
}; |
File renamed without changes.
Oops, something went wrong.