-
Notifications
You must be signed in to change notification settings - Fork 20
/
index.js
132 lines (112 loc) · 4.59 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
'use strict';
var util = require('util');
var path = require('path');
var yeoman = require('yeoman-generator');
var cordova = require('cordova');
var colors = require('colors');
var CordovaGenerator = module.exports = function CordovaGenerator(args, options, config) {
yeoman.generators.Base.apply(this, arguments);
this.on('end', function () {
var howTo = '\n' +
'\nAwesome!'.yellow + ' yeoman should now have scaffolded a cordova framework for you.' +
'\n' +
'\n You can add more plaforms to cordova using: ' + '`cordova platform add <platform>`'.cyan +
'\n' +
'\n To deploy as local web server and watch for changes requires the installation of ' + 'http://livereload.com/'.magenta + ' browser extension.' +
'\n This prepares and serves the application as a local web server to ' + 'http://localhost:8000/'.magenta + ', watching for changes then preparing/redeploying the web server.' +
'\n' +
'\n `grunt serve --platform=ios`'.cyan +
'\n' +
'\n To build and emulate all installed platforms, run:' +
'\n' +
'\n `grunt emulate`'.cyan +
'\n' +
'\n To build and emulate all installed platforms, watching for changes then building/redeploying the emulator:' +
'\n' +
'\n `grunt liveemulate`'.cyan +
'\n' +
'\n To set a specific platform to emulate, run with the following options:' +
'\n' +
'\n `--platform`'.cyan + ': sets a platform to build/emulate. eg. ' + '`--platform=ios`'.cyan +
'\n `--family`'.cyan + ': sets a family to build/emulate. eg. ' + '`--family=ipad`'.cyan +
'\n' +
'\n For example, to build and emulate the ' + '`ios`'.magenta + ' platform using the ' + '`ipad`'.magenta + ' family:' +
'\n' +
'\n `grunt liveemulate --platform='.cyan + 'ios'.magenta + ' --family='.cyan + 'ipad'.magenta + '`'.cyan +
'\n';
this.installDependencies({
skipInstall: options['skip-install'],
callback: function () {
console.log(howTo);
}
});
});
this.pkg = JSON.parse(this.readFileAsString(path.join(__dirname, '../package.json')));
};
util.inherits(CordovaGenerator, yeoman.generators.Base);
CordovaGenerator.prototype.askFor = function askFor() {
var cb = this.async();
// have Yeoman greet the user.
console.log(this.yeoman);
var prompts = [
{
name: 'appName',
message: 'What\'s your app called?',
default: 'HelloCordova'
},
{
name: 'packageName',
message: 'What\'s the package name of your app?',
default: 'io.cordova.hellocordova'
},
{
type: 'confirm',
name: 'ios',
message: 'Would you like to deploy to iOS?',
default: true
},
{
type: 'confirm',
name: 'android',
message: 'Would you like to deploy to android?',
default: true
}
];
this.prompt(prompts, function (props) {
this.appName = props.appName;
this.packageName = props.packageName;
this.platforms = [];
if (props.ios) this.platforms.push('ios');
if (props.android) this.platforms.push('android');
cb();
}.bind(this));
};
CordovaGenerator.prototype.cordovaCreate = function cordovaCreate() {
console.log("Creating cordova app: " + this.appName);
cordova.create(process.cwd(), this.packageName, this.appName, this.async());
};
CordovaGenerator.prototype.cordovaAddPlatforms = function cordovaAddPlatforms() {
if (this.platforms.length > 0) {
var done = this.async();
console.log("Adding cordova platforms: " + this.platforms.join(', '));
cordova.platform('add', this.platforms, function(err) {
if(err) {
console.log('Hmm. It looks like you need to install an SDK: '.yellow + err.red);
process.exit(1);
}
done();
});
}
};
CordovaGenerator.prototype.app = function app() {
this.mkdir('app');
this.mkdir('app/templates');
this.copy('_package.json', 'package.json');
this.copy('_bower.json', 'bower.json');
};
CordovaGenerator.prototype.projectfiles = function projectfiles() {
this.copy('editorconfig', '.editorconfig');
this.copy('jshintrc', '.jshintrc');
this.copy('bowerrc', '.bowerrc');
this.template('Gruntfile.js');
};