diff --git a/.eslintrc b/.eslintrc new file mode 100644 index 0000000..e7822e5 --- /dev/null +++ b/.eslintrc @@ -0,0 +1,22 @@ +{ + "env": { + "browser": false, + "amd": false, + "es6": true, + "node": true, + "mocha": true + }, + "rules": { + "comma-dangle": 1, + "quotes": [ 1, "single" ], + "no-undef": 1, + "global-strict": 0, + "no-extra-semi": 1, + "no-underscore-dangle": 0, + "no-console": 0, + "no-unused-vars": 1, + "no-trailing-spaces": [1, { "skipBlankLines": true }], + "no-unreachable": 1, + "no-alert": 0 + } +} diff --git a/generators/app/index.js b/generators/app/index.js new file mode 100644 index 0000000..c9ff210 --- /dev/null +++ b/generators/app/index.js @@ -0,0 +1,40 @@ +'use strict'; + +let generator = require('yeoman-generator'); + +module.exports = generator.Base.extend({ + + constructor: function() { + generator.Base.apply(this, arguments); + + this.option('skip-install'); + }, + + install: function() { + + if(!this.options['skip-install']) { + this.installDependencies({ bower: false }); + } + + // Run the base react-webpack generator, then run the dispatcher + this.composeWith( + 'react-webpack', + { + options: { + 'skip-install': this.options['skip-install'] + } + }, + { + local: require.resolve('generator-react-webpack'), + link: 'strong' + } + ).on('end', () => { + + // Run the create dispatcher method + this.composeWith('react-webpack-alt:dispatcher', { + options: {}, + args: ['Dispatcher'] + }); + }); + } +}); diff --git a/generators/dispatcher/index.js b/generators/dispatcher/index.js new file mode 100644 index 0000000..64ddf91 --- /dev/null +++ b/generators/dispatcher/index.js @@ -0,0 +1,16 @@ +'use strict'; +let generator = require('yeoman-generator'); + +module.exports = generator.NamedBase.extend({ + + constructor: function() { + generator.NamedBase.apply(this, arguments); + }, + + writing: function() { + this.fs.copyTpl( + this.templatePath('Dispatcher.js'), + this.destinationPath(`src/components/${this.name}.js`) + ); + } +}); diff --git a/generators/dispatcher/templates/Dispatcher.js b/generators/dispatcher/templates/Dispatcher.js new file mode 100644 index 0000000..baa5fef --- /dev/null +++ b/generators/dispatcher/templates/Dispatcher.js @@ -0,0 +1,4 @@ +var Alt = require('alt'); +var alt = new Alt(); + +module.exports = alt; diff --git a/package.json b/package.json new file mode 100644 index 0000000..e165f55 --- /dev/null +++ b/package.json @@ -0,0 +1,42 @@ +{ + "name": "generator-react-webpack-alt", + "version": "0.0.1", + "description": "Yeoman generator for ReactJS and Webpack with Alt.js", + "keywords": [ + "yeoman-generator", + "reactjs", + "webpack", + "alt.js", + "scaffold", + "front-end" + ], + "homepage": "https://github.com/weblogixx/generator-react-webpack-alt", + "bugs": "https://github.com/weblogixx/generator-react-webpack-altissues", + "author": { + "name": "Christian Schilling", + "email": "cs@weblogixx.de", + "url": "https://github.com/weblogixx" + }, + "main": "generators/action/index.js", + "repository": { + "type": "git", + "url": "git://github.com/weblogixx/generator-react-webpack-alt.git" + }, + "scripts": { + "test": "mocha" + }, + "dependencies": { + "yeoman-generator": "^0.20.3", + "yeoman-welcome": "^1.0.1", + "generator-react-webpack": "https://github.com/weblogixx/generator-react-webpack.git#rewrite" + }, + "devDependencies": { + "chai": "^3.2.0", + "mocha": "^2.3.2" + }, + "engines": { + "node": ">=4.0.0", + "iojs": ">=1.1.0" + }, + "license": "MIT" +} diff --git a/test/generators/dispatcher/indexTest.js b/test/generators/dispatcher/indexTest.js new file mode 100644 index 0000000..90a7eac --- /dev/null +++ b/test/generators/dispatcher/indexTest.js @@ -0,0 +1,34 @@ +'use strict'; +let path = require('path'); +let assert = require('yeoman-generator').assert; +let helpers = require('yeoman-generator').test + +describe('react-webpack-alt:dispatcher', () => { + + let generatorDispatcher = path.join(__dirname, '../../../generators/dispatcher'); + + /** + * Return a newly generated dispatcher with given name + * @param {String} name + * @param {Function} callback + */ + function createGeneratedDispatcher(name, callback) { + helpers.run(generatorDispatcher) + .withArguments([name]) + .on('end', callback); + } + + it('should create the new ALT dispatcher when invoked', (done) => { + + createGeneratedDispatcher('Dispatcher', () => { + + assert.file([ + 'src/components/Dispatcher.js' + ]); + assert.fileContent('src/components/Dispatcher.js', 'var Alt = require(\'alt\');'); + + done(); + }); + }); + +}); diff --git a/test/mocha.opts b/test/mocha.opts new file mode 100644 index 0000000..3629c7a --- /dev/null +++ b/test/mocha.opts @@ -0,0 +1,2 @@ +--reporter spec +--recursive