From 6326840eb8d0ea91613f43db1df08be62fa78404 Mon Sep 17 00:00:00 2001 From: MURAKAMI Masahiko Date: Thu, 9 Aug 2018 09:26:06 +0900 Subject: [PATCH] Add babel subgenerator --- generators/app/index.js | 42 +++-------------- generators/babel/index.js | 46 +++++++++++++++++++ generators/{app => babel}/templates/README.md | 0 generators/{app => babel}/templates/_babelrc | 0 .../{app => babel}/templates/_clasp.json | 0 .../{app => babel}/templates/_eslintrc.json | 0 .../{app => babel}/templates/_gitignore | 0 .../{app => babel}/templates/_package.json | 0 .../{app => babel}/templates/src/hello.js | 0 .../{app => babel}/templates/src/index.js | 0 10 files changed, 53 insertions(+), 35 deletions(-) create mode 100644 generators/babel/index.js rename generators/{app => babel}/templates/README.md (100%) rename generators/{app => babel}/templates/_babelrc (100%) rename generators/{app => babel}/templates/_clasp.json (100%) rename generators/{app => babel}/templates/_eslintrc.json (100%) rename generators/{app => babel}/templates/_gitignore (100%) rename generators/{app => babel}/templates/_package.json (100%) rename generators/{app => babel}/templates/src/hello.js (100%) rename generators/{app => babel}/templates/src/index.js (100%) diff --git a/generators/app/index.js b/generators/app/index.js index d120602..a3c59bb 100644 --- a/generators/app/index.js +++ b/generators/app/index.js @@ -35,40 +35,12 @@ module.exports = class extends Generator { }); } - writing() { - this.fs.copyTpl( - this.templatePath('**'), - this.destinationPath(), - { - appName: this.props.appName, - githubUsername: this.props.githubUsername, - name: this.user.git.name(), - email: this.user.git.email() - } - ); - this.fs.move( - this.destinationPath('_package.json'), - this.destinationPath('package.json') - ); - this.fs.move( - this.destinationPath('_babelrc'), - this.destinationPath('.babelrc') - ); - this.fs.move( - this.destinationPath('_gitignore'), - this.destinationPath('.gitignore') - ); - this.fs.move( - this.destinationPath('_eslintrc.json'), - this.destinationPath('.eslintrc.json') - ); - this.fs.move( - this.destinationPath('_clasp.json'), - this.destinationPath('.clasp.json') - ); - } - - install() { - this.installDependencies({bower: false}); + configuring() { + this.composeWith(require.resolve('../babel'), { + appName: this.props.appName, + githubUsername: this.props.githubUsername, + name: this.user.git.name(), + email: this.user.git.email() + }); } }; diff --git a/generators/babel/index.js b/generators/babel/index.js new file mode 100644 index 0000000..0e95b00 --- /dev/null +++ b/generators/babel/index.js @@ -0,0 +1,46 @@ +'use strict'; +const Generator = require('yeoman-generator'); + +module.exports = class extends Generator { + + constructor(args, opts) { + super(args, opts); + } + + writing() { + this.fs.copyTpl( + this.templatePath('**'), + this.destinationPath(), + { + appName: this.options.appName, + githubUsername: this.options.githubUsername, + name: this.options.name, + email: this.options.email + } + ); + this.fs.move( + this.destinationPath('_package.json'), + this.destinationPath('package.json') + ); + this.fs.move( + this.destinationPath('_babelrc'), + this.destinationPath('.babelrc') + ); + this.fs.move( + this.destinationPath('_gitignore'), + this.destinationPath('.gitignore') + ); + this.fs.move( + this.destinationPath('_eslintrc.json'), + this.destinationPath('.eslintrc.json') + ); + this.fs.move( + this.destinationPath('_clasp.json'), + this.destinationPath('.clasp.json') + ); + } + + install() { + this.installDependencies({bower: false}); + } +}; diff --git a/generators/app/templates/README.md b/generators/babel/templates/README.md similarity index 100% rename from generators/app/templates/README.md rename to generators/babel/templates/README.md diff --git a/generators/app/templates/_babelrc b/generators/babel/templates/_babelrc similarity index 100% rename from generators/app/templates/_babelrc rename to generators/babel/templates/_babelrc diff --git a/generators/app/templates/_clasp.json b/generators/babel/templates/_clasp.json similarity index 100% rename from generators/app/templates/_clasp.json rename to generators/babel/templates/_clasp.json diff --git a/generators/app/templates/_eslintrc.json b/generators/babel/templates/_eslintrc.json similarity index 100% rename from generators/app/templates/_eslintrc.json rename to generators/babel/templates/_eslintrc.json diff --git a/generators/app/templates/_gitignore b/generators/babel/templates/_gitignore similarity index 100% rename from generators/app/templates/_gitignore rename to generators/babel/templates/_gitignore diff --git a/generators/app/templates/_package.json b/generators/babel/templates/_package.json similarity index 100% rename from generators/app/templates/_package.json rename to generators/babel/templates/_package.json diff --git a/generators/app/templates/src/hello.js b/generators/babel/templates/src/hello.js similarity index 100% rename from generators/app/templates/src/hello.js rename to generators/babel/templates/src/hello.js diff --git a/generators/app/templates/src/index.js b/generators/babel/templates/src/index.js similarity index 100% rename from generators/app/templates/src/index.js rename to generators/babel/templates/src/index.js