Skip to content
This repository has been archived by the owner on Jul 8, 2020. It is now read-only.

Commit

Permalink
work on #177: cordova 5.0 - readme update, update plugin names, gitig…
Browse files Browse the repository at this point in the history
…nore, remove gulp cordova-install, better platform/plugin save implementation
  • Loading branch information
gruppjo committed May 4, 2015
1 parent 877776d commit 2e72aab
Show file tree
Hide file tree
Showing 7 changed files with 44 additions and 163 deletions.
72 changes: 24 additions & 48 deletions README.md
Expand Up @@ -71,15 +71,15 @@ Many many tools and tweaks for your convenience:
### Prerequisites
- Installation and **fair knowledge** of:
- node & npm - http://nodejs.org/download/
- yo: `npm install -g yo` - http://yeoman.io/
- gulp: `npm install -g gulp` - http://gulpjs.com/
- bower: `npm install -g bower` - http://bower.io/
- yo: `npm i -g yo` - http://yeoman.io/
- gulp: `npm i -g gulp` - http://gulpjs.com/
- bower: `npm i -g bower` - http://bower.io/
- Sass
- ruby - https://www.ruby-lang.org/en/installation/
- sass - http://sass-lang.com/install
- Want to test your app on a device ? - Then you'll need:
- Platform SDKs for cordova
- cordova documentation: [Platform Guides](http://cordova.apache.org/docs/en/4.0.0/guide_platforms_index.md.html#Platform%20Guides)
- cordova documentation: [http://cordova.apache.org/docs/en/edge/guide_platforms_index.md.html#Platform%20Guides)
- cordova cli readme: [Requirements](https://github.com/apache/cordova-cli/)

### Generator
Expand Down Expand Up @@ -156,7 +156,7 @@ A local wrapper for cordova cli (allows to use different cordova CLI versions in
```sh
gulp --cordova 'plugin ls'
```
Head over to the [cordova cli documentation](http://cordova.apache.org/docs/en/4.0.0/guide_cli_index.md.html) or their [github page](https://github.com/apache/cordova-cli/) to learn how to use the cordova cli. Remember that when using generator-m you don't need to install cordova globally!
Head over to the [cordova cli documentation](http://cordova.apache.org/docs/en/edge/guide_cli_index.md.html#The%20Command-Line%20Interface) or their [github page](https://github.com/apache/cordova-cli/) to learn how to use the cordova cli. Remember that when using generator-m you don't need to install cordova globally!

#### gulp --cordova 'build-related task'

Expand Down Expand Up @@ -259,7 +259,7 @@ gulp config --setName='hello world' # USE WITH CARE! (see below)
gulp config --setDescription='a small app to make the world a happy place'
gulp config --setAuthor='Your Name---your@mail.com---http://yourwebsite.com'
```
**Important**: When **changing the name** or **bundle identifier** of your project, it may lead to problems with the platform projects. This can be avoided by re-adding your platforms and plugins: `gulp cordova-install`. Check out the full description of this command further down in the section **Git integration**.
**Important**: When **changing the name** or **bundle identifier** of your project, it may lead to problems with the platform projects. If you have your plugins and platforms managed in the `config.xml` you can avoid this by deleting your `plugins/` and `platforms/` folders and installing them again using `gulp --cordova 'prepare'`. For more information see the **Git integration** section in this document.

## Running on Windows
The generator should work just like on unix/mac except there's one difference, when running `gulp --cordova` tasks. They need doublequotes. So write this:
Expand All @@ -284,7 +284,7 @@ gulp --cordova 'run android' # won't work on windows
'<newModuleName>'
]);
```
3. navigate to `http://localhost:9000/#/<module-name-in-snake-case>` in your browser.
3. navigate to `http://localhost:9000/#/<module-name-in-kebap-case>` in your browser.
4. **Done!** - see your new module in action!


Expand All @@ -310,59 +310,35 @@ Leaving them as they are generated, you will allow git to exclude all of the 3rd
- no cordova platforms and plugins

### After git clone
Since all these files are excluded from git you need to install all of them when you start with a fresh clone of your project. In order to do so, run the following commands in that order:
Since all these files are excluded from git, you need to install all of them when you start with a fresh clone of your project. In order to do so, run the following commands in that order:
```sh
npm install # installs all node modules including cordova, gulp and all that
bower install # install all bower components including angular, ionic, ng-cordova, ...
gulp cordova-install # install all cordova platforms and plugins
gulp --cordova 'prepare' # install all cordova platforms and plugins from the config.xml
```

### gulp cordova-install
Both npm and bower keep track of the installed packages and their versions using the `package.json` and `bower.json` respectively. Unfortunately cordova does not provide a ~~`cordova install`~~ command and no ~~`cordova.json`~~ file to keep track of the installed platforms, plugins and their versions. We think it should, that's why we created an [issue for that](https://issues.apache.org/jira/browse/CB-8539) in the cordova project. We'll keep you updated!
### Platforms and plugins in config.xml
Since `cordova 5.0` all platforms and plugins you install can be added to the `config.xml`.

For now you can run our custom `gulp cordova-install` which will install all platforms and plugins. Unfortunately, for now, with no guarantee of version. This means, that cordova will always install the latest versions. Sometimes, especially with plugins, this can lead to code incompatibilities.
Release notes:
https://cordova.apache.org/news/2015/04/21/tools-release.html

### cordova versions in `.yo-rc.json`
If you care a lot about the stability of your code (like we do), keep reading!
> Added the ability to manage your plugin and platform dependencies in your project’s `config.xml`. When adding plugins or platforms, use the `--save` flag to add them to `config.xml`. Ex: `cordova platform add android --save`. Existing projects can use `cordova plugin save` and `cordova platform save` commands to save all previously installed plugins and platforms into your project’s `config.xml`. Platforms and plugins will be autorestored when `cordova prepare` is run. This allows developers to easily manage and share their dependenceis among different development enviroments and with their coworkers.
>
In order to be able to manage your cordova platform and plugin versions at all, we built in a little workaround. It's not great but it does it's duty until there's a better solution. For every platform and plugin you install with `gulp --cordova` you can add a version to the `.yo-rc.json` file. For instance, you'd install the splashscreen plugin and the android platform via:
```sh
gulp --cordova 'plugin add org.apache.cordova.splashscreen'
gulp --cordova 'platform add android'
```
Then you check their versions by running:
```sh
gulp --cordova 'plugin ls' # let's say splashscreen version is 1.0.0
gulp --cordova 'platform ls' # let's say android version is 3.6.4
```
Modify the `.yo-rc.json` to look something like this:
```js
{
"generator-m": {
"answers": {
// ...
],
"platforms": [
"ios", // will install newest version
"android@3.6.4" // will install 3.6.4
],
"plugins": [
"org.apache.cordova.device", // will install newest version
"org.apache.cordova.dialogs", // will install newest version
"org.apache.cordova.splashscreen@1.0.0", // will install 1.0.0
]
}
}
}
Since your projects `.gitignore` will completely ignore the `platforms/` and `plugins/` folders, it's important to make sure your `config.xml` contains all the plugins and platforms required by your project. As explained above this can either be achieved by always using the `--save` options when adding/removing platforms:

```sh
gulp --cordova 'platform add ios --save'
gulp --cordova 'plugin remove cordova-plugin-camera --save'
```
Now running `gulp cordova-install` will install all the appropriate versions.

or by typing the following commands every time before you commit:

It's **important** to note that:
- The versions you supply in `.yo-rc.json` do not take effect until you have manually installed the platforms and plugins with the respective `gulp --cordova` command.
- If you want to version control plugins that were installed via their git repository, (e.g. `https://github.com/EddyVerbruggen/cordova-plugin-actionsheet.git`) you need to do so using their cordova plugin registry id (e.g. `l.x-services.plugins.actionsheet`), which can be found in the `plugins/fetch.json` file
- Plugins that aren't published in the cordova registry and thus don't have a cordova plugin registry id cannot bet version controlled.
```sh
gulp --cordova 'platform save'
gulp --cordova 'plugin save'
```

## Troubleshooting
If you're experiencing difficulties using the generator please refer to the [Troubleshooting](https://github.com/mwaylabs/generator-m/wiki/Troubleshooting) section in our wiki or [create an issue](https://github.com/mwaylabs/generator-m/issues/new)!
Expand Down
22 changes: 5 additions & 17 deletions app/index.js
Expand Up @@ -137,24 +137,24 @@ var MGenerator = yeoman.generators.Base.extend({
var done = this.async(); // wait with subsequent tasks since cordova needs an empty folder
// cordova project
cordova.create('.', this.answers.appId, this.answers.appName)
// add platforms
// add platforms and save to config.xml
.then(function () {
this.log(chalk.green('Created cordova project'));
if (this.options['skip-sdk'] || !this.answers.platforms.length) {
return true;
}
else {
return cordova.platform('add', this.answers.platforms);
return cordova.platform('add', this.answers.platforms, { save: true });
}
}.bind(this))
// add plugins
// add plugins and save to config.xml
.then(function () {
this.log(chalk.green('Added platforms: ' + this.answers.platforms.join(', ')));
if (this.options['skip-sdk'] || !this.answers.plugins.length) {
return true;
}
else {
return cordova.plugin('add', this.answers.plugins);
return cordova.plugin('add', this.answers.plugins, { save: true });
}
}.bind(this))
// all
Expand Down Expand Up @@ -225,19 +225,7 @@ var MGenerator = yeoman.generators.Base.extend({
this.installDependencies({
npm: true,
bower: true,
skipInstall: this.options['skip-install'],
callback: this.options['skip-sdk'] ? undefined : function () {

// save platforms and plugins to config.xml
var done = this.async();
return cordova.platform('save')
.then(function () {
return cordova.plugin('save');
})
.then(function () {
done();
});
}.bind(this)
skipInstall: this.options['skip-install']
});
},

Expand Down
24 changes: 12 additions & 12 deletions app/sources/cordova-config.js
Expand Up @@ -18,29 +18,29 @@ module.exports = {
plugins: [
new inquirer.Separator('-------'),
{
value: 'org.apache.cordova.device',
name: 'Device - org.apache.cordova.device',
value: 'cordova-plugin-device',
name: 'Device - cordova-plugin-device',
checked: true
},
{
value: 'org.apache.cordova.dialogs',
name: 'Dialogs - org.apache.cordova.dialogs'
value: 'cordova-plugin-dialogs',
name: 'Dialogs - cordova-plugin-dialogs'
},
{
value: 'org.apache.cordova.inappbrowser',
name: 'In App Browser - org.apache.cordova.inappbrowser'
value: 'cordova-plugin-inappbrowser',
name: 'In App Browser - cordova-plugin-inappbrowser'
},
{
value: 'org.apache.cordova.network-information',
name: 'Network - org.apache.cordova.network-information'
value: 'cordova-plugin-network-information',
name: 'Network - cordova-plugin-network-information'
},
{
value: 'org.apache.cordova.splashscreen',
name: 'Splashscreen - org.apache.cordova.splashscreen'
value: 'cordova-plugin-splashscreen',
name: 'Splashscreen - cordova-plugin-splashscreen'
},
{
value: 'org.apache.cordova.statusbar',
name: 'Statusbar - org.apache.cordova.statusbar'
value: 'cordova-plugin-statusbar',
name: 'Statusbar - cordova-plugin-statusbar'
},
]
};
4 changes: 2 additions & 2 deletions app/sources/sample-answers.js
Expand Up @@ -22,8 +22,8 @@ module.exports = {
'android'
],
plugins: [
'org.apache.cordova.device',
'org.apache.cordova.dialogs'
'cordova-plugin-device',
'cordova-plugin-dialogs'
]
},

Expand Down
1 change: 0 additions & 1 deletion app/templates/_package.json
Expand Up @@ -35,7 +35,6 @@
"minimist": "^1.1.0",
"opn": "^1.0.1",
"require-dir": "^0.1.0",
"rimraf": "^2.2.8",
"serve-static": "^1.9.1",
"vinyl-paths": "^1.0.0",
"wiredep": "^2.2.2",
Expand Down
3 changes: 1 addition & 2 deletions app/templates/gitignore
Expand Up @@ -12,8 +12,7 @@

# cordova
/platforms/
/plugins/**
!/plugins/*.json
/plugins/

# build folder
/www/**
Expand Down
81 changes: 0 additions & 81 deletions app/templates/gulp_tasks/cordova.js
Expand Up @@ -7,9 +7,7 @@ var options = gulp.options;
// plugins
var $ = require('gulp-load-plugins')();
// packages
var fs = require('fs');
var path = require('path');
var rimraf = require('rimraf');

var runCordova = function (command, stream) {
// allow to overwrite command from option.cordova with parameter
Expand All @@ -25,82 +23,3 @@ var runCordova = function (command, stream) {

gulp.task('cordova', runCordova);
gulp.task('cordova-with-build', ['build'], runCordova);

// removes platform and all plugin dirs and then
// adds platforms and plugins based on <platform>.jsons
gulp.task('cordova-install', function () {

var pluginsDir = 'plugins/';
var dirs = ['platforms'];
var install = {
platforms: [],
plugins: []
};

// read files
var yoRcAnswers = JSON.parse(fs.readFileSync('.yo-rc.json', 'utf8'))['generator-m'].answers;
var plugins = JSON.parse(fs.readFileSync(pluginsDir + 'fetch.json', 'utf8'));

var platforms = fs.readdirSync(pluginsDir) // all plugin files
// only filter json files, and populate dirs array
.filter(function (fileName) {
if (fileName.indexOf('.json') !== -1 && fileName.indexOf('fetch') === -1) {
// all platforms but ignore fetch.json
return true;
}
else {
// push directories to dirs array
var stat = fs.statSync(pluginsDir + fileName);
if (stat.isDirectory()) {
dirs.push(pluginsDir + fileName);
}
return false;
}
})
// extract platform
.map(function (fileName) {
return /(.*)\.json$/ig.exec(fileName)[1];
});

// remove all dirs (platforms and plugins)
dirs.forEach(function (dir) {
rimraf.sync(dir);
});

var stream = gulp.src('');
// add platforms
platforms.forEach(function (platform) {
// delete .json file, so plugins get added after platforms (errors otherwise!)
fs.unlinkSync(pluginsDir + platform + '.json');
// add platform
for (var i = 0, yoPlatform; (yoPlatform = yoRcAnswers.platforms[i]); i++) {
// replace with platform from yorcjson (which may contain version)
if (yoPlatform.indexOf(platform) === 0) {
platform = yoPlatform;
}
}
// wait with execution until previous command has finished
stream = runCordova('platform add ' + platform, stream);
install.platforms.push(platform);
});

// add plugins
for (var plugin in plugins) {
for (var j = 0, yoPlugin; (yoPlugin = yoRcAnswers.plugins[j]); j++) {
// replace with plugin from .yo-rc.json (which may contain version)
if (yoPlugin.indexOf(plugin) === 0) {
plugin = yoPlugin;
}
}
// if no version control in .yo-rc.json install via url if possible
if (plugin.indexOf('@') === -1) {
if (plugins[plugin].source.type === 'git') {
plugin = plugins[plugin].source.url;
}
}
// wait with execution until previous command has finished
stream = runCordova('plugin add ' + plugin, stream);
install.plugins.push(plugin);
}
console.log(JSON.stringify(install, null, 2));
});

0 comments on commit 2e72aab

Please sign in to comment.