Skip to content

Commit 75faff0

Browse files
Add android commands
1 parent 7dadeb7 commit 75faff0

File tree

9 files changed

+114
-8
lines changed

9 files changed

+114
-8
lines changed

README.md

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
ember-cli-capacitor
22
==============================================================================
33

4-
This addon integrates Ember and Capacitor.
4+
This addon integrates Ember and [Capacitor](https://capacitorjs.com/).
5+
It supports building and live reload for iOS, Android, and Electron.
56

67

78
Compatibility
@@ -23,8 +24,20 @@ ember install ember-cli-capacitor
2324
Usage
2425
------------------------------------------------------------------------------
2526

27+
### Blueprints
28+
29+
The default `ember-cli-capacitor` blueprint will run when you first install
30+
the addon, but if you want to run it again, either to update to the latest
31+
blueprints or to add support for more platforms, you can run it with:
32+
33+
```
34+
ember g ember-cli-capacitor
35+
```
36+
2637
### Commands
2738

39+
#### iOS
40+
2841
```
2942
ember ios:serve
3043
```
@@ -33,6 +46,16 @@ ember ios:serve
3346
ember ios:build
3447
```
3548

49+
#### Android
50+
51+
```
52+
ember android:serve
53+
```
54+
55+
```
56+
ember android:build
57+
```
58+
3659

3760
Contributing
3861
------------------------------------------------------------------------------

index.js

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,10 @@ module.exports = {
55

66
includedCommands() {
77
return {
8+
'android:build': require('./lib/commands/android-build'),
9+
'android:serve': require('./lib/commands/android-serve'),
810
'ios:build': require('./lib/commands/ios-build'),
911
'ios:serve': require('./lib/commands/ios-serve')
1012
};
11-
},
12-
13-
isDevelopingAddon() {
14-
return true;
1513
}
1614
};

lib/commands/android-build.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
2+
'use strict';
3+
4+
const BaseCommand = require('./base');
5+
6+
module.exports = BaseCommand.extend({
7+
name: 'android:build',
8+
description: 'Builds your app for Android',
9+
async run(commandOptions) {
10+
return await this.runTask('android:build', commandOptions);
11+
}
12+
});

lib/commands/android-serve.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
2+
'use strict';
3+
4+
const BaseCommand = require('./base');
5+
6+
module.exports = BaseCommand.extend({
7+
name: 'android:serve',
8+
description: 'Builds your app and launches Android w/ live reload.',
9+
async run(commandOptions) {
10+
return await this.runTask('android:serve', commandOptions);
11+
}
12+
});

lib/commands/base.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
'use strict';
22

33
const Command = require('ember-cli/lib/models/command');
4+
const AndroidBuildTask = require('../tasks/android-build');
5+
const AndroidServeTask = require('../tasks/android-serve');
46
const iOSBuildTask = require('../tasks/ios-build');
57
const iOSServeTask = require('../tasks/ios-serve');
68

@@ -9,6 +11,8 @@ module.exports = Command.extend({
911
this._super(...arguments);
1012

1113
Object.assign(this.tasks, {
14+
'android:build': AndroidBuildTask,
15+
'android:serve': AndroidServeTask,
1216
'ios:build': iOSBuildTask,
1317
'ios:serve': iOSServeTask
1418
});

lib/tasks/android-build.js

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
'use strict';
2+
3+
const chalk = require('chalk');
4+
const Task = require('ember-cli/lib/models/task');
5+
// const Builder = require('ember-cli/lib/models/builder');
6+
const { execSync } = require('child_process');
7+
8+
class AndroidBuildTask extends Task {
9+
async run() {
10+
let { ui } = this;
11+
12+
ui.writeLine(chalk.green('Android Build: Ember build'), chalk.green('.'));
13+
execSync('ember build --environment=production');
14+
15+
ui.writeLine(chalk.green('Android Build: Sync'), chalk.green('.'));
16+
execSync('npx cap sync android');
17+
18+
ui.writeLine(chalk.green('Android Build: Opening Android Studio'), chalk.green('.'));
19+
execSync('npx cap open android');
20+
}
21+
}
22+
23+
module.exports = AndroidBuildTask;

lib/tasks/android-serve.js

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
'use strict';
2+
3+
const chalk = require('chalk');
4+
const Task = require('ember-cli/lib/models/task');
5+
// const Builder = require('ember-cli/lib/models/builder');
6+
const { execSync } = require('child_process');
7+
8+
class AndroidServeTask extends Task {
9+
async run() {
10+
let { ui } = this;
11+
12+
ui.startProgress(chalk.green('Android Serve: ember build'), chalk.green('.'));
13+
execSync('ember build --environment=development');
14+
ui.stopProgress();
15+
16+
ui.startProgress(chalk.green('Android Serve: npx cap sync android'), chalk.green('.'));
17+
execSync('npx cap sync android');
18+
ui.stopProgress();
19+
20+
ui.startProgress(chalk.green('Android Serve: npx cap open android'), chalk.green('.'));
21+
execSync('npx cap open android');
22+
ui.stopProgress();
23+
24+
ui.writeLine(chalk.green('Android Serve: Serving Ember app'));
25+
execSync('ember serve');
26+
}
27+
}
28+
29+
module.exports = AndroidServeTask;

lib/tasks/ios-serve.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@ const Task = require('ember-cli/lib/models/task');
66
const { execSync } = require('child_process');
77

88
class iOSServeTask extends Task {
9-
async run() {
9+
async run(options) {
10+
console.log(options);
1011
let { ui } = this;
1112

1213
ui.startProgress(chalk.green('iOS Serve: ember build'), chalk.green('.'));

package.json

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,13 @@
11
{
22
"name": "ember-cli-capacitor",
33
"version": "0.0.3",
4-
"description": "Add capacitor to your Ember apps.",
4+
"description": "Adds native iOS, Android, and Electron support to Ember with Capacitor.",
55
"keywords": [
6-
"ember-addon"
6+
"ember-addon",
7+
"capacitor",
8+
"iOS",
9+
"android",
10+
"electron"
711
],
812
"repository": {
913
"type": "git",

0 commit comments

Comments
 (0)