Skip to content

Commit

Permalink
Merge pull request #1 from mcfly-io/feat-app
Browse files Browse the repository at this point in the history
  • Loading branch information
thaiat committed Jan 26, 2016
2 parents 9338cdb + 9434eb9 commit 89a00b2
Show file tree
Hide file tree
Showing 34 changed files with 1,866 additions and 87 deletions.
4 changes: 2 additions & 2 deletions .eslintrc → .eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,14 +30,14 @@
"dot-notation": 2,
"eol-last": 0,
"eqeqeq": [2, "smart"],
"indent": [0, 4, {"SwitchCase": 1}],
"indent": [0, 1, {"SwitchCase": 1}],
"nodeca/indent": [2, "spaces", 4 ],
"max-depth": [0, 4],
"max-len": [0, 80, 4],
"max-nested-callbacks": [0, 2],
"max-params": [0, 15],
"max-statements": [0, 10],
"new-cap": [2],
"new-cap": [0],
"new-parens": 2,
"no-alert": 2,
"no-array-constructor": 2,
Expand Down
19 changes: 16 additions & 3 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,24 @@ node_js:
- v4
- '0.12'

env:
global:
secure: ACshkxhxRWLhktp4pgSkdM3PDh9+/JaMt/Mm8Bf70Nl9WCQLwqS7peuVPn3A3bX52UfaIuvIZ2T9PSIsO59V7nXTSVBZmfBdcK1Sg5IuL4A+FTtWN+G30CS7yPhQHuiyMf7j3rtpcUMCrQZrmSBpVbU1bUvNIyCGPa71PrLOoa9Is64HygIfZtwhfxbCeHGH9c7BshKGXyNaMAPXhcnEZbe6mrDsd44EwyP6Iw42maKfcjKEELug/cXhX8cnsJhNEsvQhmLdP+mqAKQPNsds8Ww+8WUqetQNeczYK/etkMDCVskEzdmh+NQFbwi0XtA8C8aeCithmvM722FdjXRrMhOrBP+AKvHOAW2YEWt9wsO49x3PkobbxGyUD6vsfkwI/mjWxgQBYzGiXzspPAQRrtOw3KH56RVuCoVJD6D1p3g8UKOc3GQUqaALKD7mDeldbAZcFRUMRGn+VUAbIiCg9DvneKPolyapwCaVa2CCUkTRDFgoB/aGV97KAnHVjyZfWdldc5j+yHKYyG4XuzSvxWxQHA9q9dMyg36evQNz5Qtu96+CemT/u/CIYUzity98qWvVfdoRDYp19VZme6ipHwpcS7poM0LeJgKLhdp0W35Y/qBxWqwXRTdlJbERdiU4NSnXYWIW7eLEB5XKFkg9IwNMsai/8Nm78We5aWfbNz8=

cache:
directories:
- node_modules
- bower_components
directories:
- node_modules
- bower_components

after_success:
- cat ./coverage/mocha/lcov.info | ./node_modules/coveralls/bin/coveralls.js --verbose

deploy:
provider: npm
email: [email protected]
api_key: $NPM_API_KEY
on:
tags: true
all_branches: true
node: '0.12'
repo: mcfly-io/generator-mcfly-ng2
47 changes: 43 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,13 @@ Then generate your new project:
yo mcfly-ng2
```

## Testing
```sh
npm run test # lint + unit tests
npm run mocha # to run without linting first
npm run mocha.watch # to run in watch mode
```

## Getting To Know Yeoman

Yeoman has a heart of gold. He's a person with feelings and opinions, but he's very easy to work with. If you think he's too opinionated, he can be easily convinced. Feel free to [learn more about him](http://yeoman.io/).
Expand All @@ -25,18 +32,50 @@ Yeoman has a heart of gold. He's a person with feelings and opinions, but he

MIT

## Yeoman stuff
### create directory
## Yeoman notes
### Create directory
```js
var mkdirp = require('mkdirp');
mkdirp.sync(this.templatePath('xxx'));
var mixinFile = require('../../libs/mixinFile');
var utils = {};
mixinFile.extend(utils);
var body = utils.mixins.mkdirp.sync(this.destinationPath('path_to_create'));
```

### Write file from string
```js
this.fs.write(this.destinationPath('xxx'), content);
```

### Read scaffolded file in test
```js
var mixinFile = require('../../libs/mixinFile');
var utils = {};
mixinFile.extend(utils);
var body = utils.mixins.readTextFile('./package.json');
```

or we can use the testHelper
```js
var testHelper = require('./testHelper');
var body = testHelper.mixins.readTextFile('./.yo-rc.json');
```

### Test regex on file content
```js
var expectedContents = [
['package.json', /"name": "name_x"/],
['tsconfig.json', new RegExp('\"' + clientFolder + /\/\*\*\/\*\.ts/.source)]
];
assert.fileContent(expectedContents);
```

### Test object on JSON file content
```js
assert.JSONFileContent('package.json', {
name: 'name-x'
});
```

[npm-image]: https://badge.fury.io/js/generator-mcfly-ng2.svg
[npm-url]: https://npmjs.org/package/generator-mcfly-ng2
[travis-image]: https://travis-ci.org/mcfly-io/generator-mcfly-ng2.svg?branch=master
Expand Down
117 changes: 92 additions & 25 deletions generators/app/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,9 @@ var yosay = require('yosay');
var path = require('path');
var mixinLodash = require('../../libs/mixinLodash');
var mixinBeautify = require('../../libs/mixinBeautify');
var mixinReadFile = require('../../libs/mixinReadFile');
var mixinFile = require('../../libs/mixinFile');
var mixinNotifier = require('../../libs/mixinNotifier');
var mixinInspector = require('../../libs/mixinInspector');

module.exports = generators.Base.extend({
constructor: function() {
Expand All @@ -15,8 +16,9 @@ module.exports = generators.Base.extend({
// applying mixins
mixinLodash.extend(this);
mixinBeautify.extend(this);
mixinReadFile.extend(this);
mixinFile.extend(this);
mixinNotifier.extend(this);
mixinInspector.extend(this);

// Registering file transforms
this.mixins.beautifyJson();
Expand All @@ -34,14 +36,6 @@ module.exports = generators.Base.extend({
defaults: this.appname
});

this.argument('mobile', {
desc: 'Indicates that the app is a mobile app',
type: Boolean,
optional: true,
required: false,
defaults: false
});

this.appname = this.mixins.camelize(this.appname);
// ***** arguments ********

Expand All @@ -52,54 +46,127 @@ module.exports = generators.Base.extend({
type: Boolean,
defaults: false
});
this.option('mobile', {
desc: 'Indicates that the app is a mobile app',
type: Boolean,
defaults: false
});

this.option('target', {
desc: 'The name of the default target',
type: String,
defaults: 'app'
});
// ****** options *********

},

initializing: function() {
this.pkg = this.mixins.readJsonFile('../../package.json', __dirname);
this.mixins.notifyUpdate(this.pkg);
},

configuring: function() {

this.composeWith(this.mixins.getGeneratorShortname() + ':target', {
args: [this.options.target]
});
},

prompting: function() {
this.log('prompting');
var done = this.async();

// Have Yeoman greet the user.
this.log(yosay('Welcome to the awesome ' + chalk.yellow('generator-mcfly-ng2') + ' generator!'));
this.log(yosay('Welcome to the awesome ' + chalk.yellow(this.mixins.getGeneratorFullname()) + ' generator!'));

var done = this.async();
var prompts = [{
type: 'input',
name: 'name',
message: 'Your project name',
message: 'What is your project name?',
default: this.appname
}, {
type: 'input',
name: 'clientFolder',
message: 'What is your client folder?',
default: 'client'
}];

this.prompt(prompts, function(answers) {
this.answers = answers;
// To access answers later use this.answers.someOption;
// To access answers later use this.answers.someAnswer;
this.answers.clientFolder = this.mixins.dasherize(this.answers.clientFolder);
done();
}.bind(this));
},

configuring: function() {
this.config.set('filenameCase', this.filenameCase);
this.config.set('filenameSuffix', this.filenameSuffix);
this.config.set('appname', this.appname);
this.config.set('clientFolder', this.answers.clientFolder);

},

writing: function() {
this.log('writing', this.answers.name);

this.mixins.mkdirp.sync(this.destinationPath(this.answers.clientFolder));

this.fs.copyTpl(
this.templatePath('.eslintignore'),
this.destinationPath('.eslintignore')
);
this.fs.copyTpl(
this.templatePath('.eslintrc.json'),
this.destinationPath('.eslintrc.json')
);
this.fs.copyTpl(
this.templatePath('.gitignore'),
this.destinationPath('.gitignore')
);
this.fs.copyTpl(
this.templatePath('package.json'),
this.templatePath('.jsbeautifyrc'),
this.destinationPath('.jsbeautifyrc')
);
this.fs.copyTpl(
this.templatePath('.npmrc'),
this.destinationPath('.npmrc')
);
this.fs.copyTpl(
this.templatePath('_package.json'),
this.destinationPath('package.json'), {
appname: this.appname
appname: this.mixins.dasherize(this.appname),
clientFolder: this.answers.clientFolder
}
);
this.fs.copyTpl(
this.templatePath('_README.md'),
this.destinationPath('README.md'), {
appname: this.mixins.dasherize(this.appname)
}
);
this.fs.copyTpl(
this.templatePath('_spec-bundle.js'),
this.destinationPath('spec-bundle.js')
);
this.fs.copyTpl(
this.templatePath('_tsconfig.json'),
this.destinationPath('tsconfig.json'), {
clientFolder: this.answers.clientFolder
}
);
this.fs.copyTpl(
this.templatePath('karma.conf.js'),
this.destinationPath('karma.conf.js')
);
this.fs.copyTpl(
this.templatePath('tslint.json'),
this.destinationPath('tslint.json')
);
this.fs.copyTpl(
this.templatePath('webpack.config.js'),
this.destinationPath('webpack.config.js')
);

},

conflicts: function() {
this.log('conflicts');

},

install: function() {
Expand All @@ -110,6 +177,6 @@ module.exports = generators.Base.extend({
},

end: function() {
this.log('end');
this.log(chalk.green('Woot!!! It appears that everything installed correctly.'));
}
});
});
5 changes: 5 additions & 0 deletions generators/app/templates/.eslintignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
node_modules/**
bower_components/**
dist/**
coverage/**
spec-bundle.js
Loading

0 comments on commit 89a00b2

Please sign in to comment.