Skip to content

Commit

Permalink
First useful commit. Generator now runs cordova create and then copie…
Browse files Browse the repository at this point in the history
…s files from the ionic seed project (for now) and sets up a Grunt build system.
  • Loading branch information
diegonetto committed Feb 27, 2014
1 parent 692f195 commit 53c39f4
Show file tree
Hide file tree
Showing 68 changed files with 711 additions and 68 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
node_modules/
temp/
*.DS_Store
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
Copyright 2013 Diego Netto
Copyright 2014 Diego Netto

Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
Expand Down
62 changes: 34 additions & 28 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,46 +1,52 @@
# generator-ionic [![Build Status](https://secure.travis-ci.org/diegonetto/generator-ionic.png?branch=master)](https://travis-ci.org/diegonetto/generator-ionic)
![](http://i.imgur.com/Cedw75X.png)

A generator for [Yeoman](http://yeoman.io).
# Ionic Framework generator

> Yeoman generator for Ionic - lets you quickly set up a hybrid mobile app project
## Getting Started

### What is Yeoman?

Trick question. It's not a thing. It's this guy:

![](http://i.imgur.com/JHaAlBJ.png)

Basically, he wears a top hat, lives in your computer, and waits for you to tell him what kind of application you wish to create.

Not every new computer comes with a Yeoman pre-installed. He lives in the [npm](https://npmjs.org) package repository. You only have to ask for him once, then he packs up and moves into your hard drive. *Make sure you clean up, he likes new and shiny things.*
**This is currently under active development.**

## Usage
Install [Cordova CLI](http://cordova.apache.org/docs/en/3.0.0/guide_cli_index.md.html)
```
$ npm install -g yo
npm install -g cordova
```

### Yeoman Generators

Yeoman travels light. He didn't pack any generators when he moved in. You can think of a generator like a plug-in. You get to choose what type of application you wish to create, such as a Backbone application or even a Chrome extension.

To install generator-ionic from npm, run:

Install `generator-ionic`:
```
$ npm install -g generator-ionic
npm install -g generator-ionic
```

Finally, initiate the generator:

Make a new directory, and `cd` into it:
```
$ yo ionic
mkdir my-ionic-project && cd $_
```

### 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.
Run `yo ionic`
```
yo ionic
```

If you'd like to get to know Yeoman better and meet some of his friends, [Grunt](http://gruntjs.com) and [Bower](http://bower.io), check out the complete [Getting Started Guide](https://github.com/yeoman/yeoman/wiki/Getting-Started).
Spin up a `connect` server with `watch` and `livereload` for developing in a browser
```
grunt serve
```

## TODO
1. Building / Emulating doc section
2. Better starting app using SideBar and a few other components
3. Workflow doc section
4. SCSS / LESS support prompt options
5. Decide if we should use imagemin + svgmin
6. Add testing support using Karma and integrate with Grunt
7. Consider pulling in generator-angular as a subgenerator
8. Add Mocha generator unit tests
9. Contributing doc section

## Thanks
Special thanks to the following projects for inspiration:
1. [AngularJS Generator](https://github.com/yeoman/generator-angular)
2. [Ionic Seed Project](https://github.com/driftyco/ionic-angular-cordova-seed)

## License

Expand Down
85 changes: 62 additions & 23 deletions app/index.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,23 @@
'use strict';
var util = require('util');
var fs = require('fs');
var path = require('path');
var spawn = require('child_process').spawn;
var yeoman = require('yeoman-generator');
var mout = require('mout').string;
var chalk = require('chalk');
var xml2js = require('xml2js');


var IonicGenerator = module.exports = function IonicGenerator(args, options, config) {
yeoman.generators.Base.apply(this, arguments);

this.argument('appName', { type: String, required: false });
this.appName = this.appName || path.basename(process.cwd());
this.appName = mout.pascalCase(this.appName);
this.appPath = 'app';
this.root = process.cwd();

this.on('end', function () {
this.installDependencies({ skipInstall: options['skip-install'] });
});
Expand All @@ -16,35 +27,63 @@ var IonicGenerator = module.exports = function IonicGenerator(args, options, con

util.inherits(IonicGenerator, yeoman.generators.Base);

IonicGenerator.prototype.askFor = function askFor() {
var cb = this.async();
IonicGenerator.prototype.cordovaInit = function cordovaInit() {
var done = this.async();

// have Yeoman greet the user.
console.log(this.yeoman);
var cordova = spawn('cordova', ['create', '.', 'com.ionicframework.' + mout.camelCase(this.appName), this.appName])
cordova.stdout.on('data', function(data) {
console.log(chalk.yellow(data.toString('utf8')));
});
cordova.stderr.on('data', function(data) {
console.log(chalk.red(data.toString('utf8')));
});
cordova.on('close', function(code) {
done();
});
};

var prompts = [{
type: 'confirm',
name: 'someOption',
message: 'Would you like to enable this option?',
default: true
}];
IonicGenerator.prototype.setupEnv = function setupEnv() {
// Copies the contents of the generator example app
// directory into your users new application path
this.sourceRoot(path.join(__dirname, '../templates/'));
this.directory('common/root', '.', true);
};

this.prompt(prompts, function (props) {
this.someOption = props.someOption;
IonicGenerator.prototype.packageFiles = function packageFiles() {
this.template('common/_bower.json', 'bower.json');
this.template('common/_bowerrc', '.bowerrc');
this.template('common/_package.json', 'package.json');
this.template('common/Gruntfile.js', 'Gruntfile.js');
this.template('common/_gitignore', '.gitignore');
};

cb();
}.bind(this));
IonicGenerator.prototype.appFiles = function appFiles() {
this.template('javascript/app.js', 'app/scripts/app.js');
this.template('javascript/controllers.js', 'app/scripts/controllers.js');
this.template('javascript/services.js', 'app/scripts/services.js');
this.template('views/index.html', 'app/index.html');
};

IonicGenerator.prototype.app = function app() {
this.mkdir('app');
this.mkdir('app/templates');
IonicGenerator.prototype.updateCordovaConfig = function updateCordovaConfig() {
console.log(chalk.yellow('Attemping to overwrite Cordova generated files with example app skeleton.'));
console.log(chalk.yellow('Type "y" and hit Enter to confirm overwrites:'));
var parser = new xml2js.Parser({ normalize: true });
var builder = new xml2js.Builder();
var configPath = path.join(this.root, 'config.xml');
var done = this.async();

this.copy('_package.json', 'package.json');
this.copy('_bower.json', 'bower.json');
fs.readFile(configPath, function(err, data) {
parser.parseString(data, function(err, config) {
config.widget.preference = [
{ '$': { name: 'fullscreen', value: 'true' } },
{ '$': { name: 'webviewbounce', value: 'false' } },
{ '$': { name: 'UIWebViewBounce', value: 'false' } },
{ '$': { name: 'DisallowOverscroll', value: 'true' } }
];
this.write(configPath, builder.buildObject(config));
done();
}.bind(this));
}.bind(this));
};

IonicGenerator.prototype.projectfiles = function projectfiles() {
this.copy('editorconfig', '.editorconfig');
this.copy('jshintrc', '.jshintrc');
};

6 changes: 0 additions & 6 deletions app/templates/_bower.json

This file was deleted.

5 changes: 0 additions & 5 deletions app/templates/_package.json

This file was deleted.

18 changes: 14 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,9 +1,16 @@
{
"name": "generator-ionic",
"version": "0.0.0",
"description": "A generator for Yeoman",
"version": "0.0.1",
"description": "A generator for the Ionic Framework",
"keywords": [
"yeoman-generator"
"yeoman-generator",
"ionic",
"framework",
"ionicframework",
"angularjs",
"hybrid",
"mobile",
"app"
],
"homepage": "https://github.com/diegonetto/generator-ionic",
"bugs": "https://github.com/diegonetto/generator-ionic/issues",
Expand All @@ -21,7 +28,10 @@
"test": "mocha"
},
"dependencies": {
"yeoman-generator": "~0.14.0"
"yeoman-generator": "~0.14.0",
"xml2js": "~0.4.1",
"mout": "~0.9.0",
"chalk": "~0.4.0"
},
"devDependencies": {
"mocha": "~1.14.0"
Expand Down
Loading

0 comments on commit 53c39f4

Please sign in to comment.