Skip to content

Commit 7e5b7f4

Browse files
Add initial iOS commands (#2)
* Start iOS commands * Lowercase ios * Add ios:build command
1 parent 649b507 commit 7e5b7f4

File tree

6 files changed

+104
-1
lines changed

6 files changed

+104
-1
lines changed

index.js

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,16 @@
11
'use strict';
22

33
module.exports = {
4-
name: require('./package').name
4+
name: require('./package').name,
5+
6+
includedCommands() {
7+
return {
8+
'ios:build': require('./lib/commands/ios-build'),
9+
'ios:serve': require('./lib/commands/ios-serve')
10+
};
11+
},
12+
13+
isDevelopingAddon() {
14+
return true;
15+
}
516
};

lib/commands/base.js

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
'use strict';
2+
3+
const Command = require('ember-cli/lib/models/command');
4+
const iOSBuildTask = require('../tasks/ios-build');
5+
const iOSServeTask = require('../tasks/ios-serve');
6+
7+
module.exports = Command.extend({
8+
init() {
9+
this._super(...arguments);
10+
11+
Object.assign(this.tasks, {
12+
'ios:build': iOSBuildTask,
13+
'ios:serve': iOSServeTask
14+
});
15+
}
16+
});

lib/commands/ios-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: 'ios:build',
8+
description: 'Builds your app for iOS',
9+
async run(commandOptions) {
10+
return await this.runTask('ios:build', commandOptions);
11+
}
12+
});

lib/commands/ios-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: 'ios:serve',
8+
description: 'Builds your app and launches iOS w/ live reload.',
9+
async run(commandOptions) {
10+
return await this.runTask('ios:serve', commandOptions);
11+
}
12+
});

lib/tasks/ios-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 iOSBuildTask extends Task {
9+
async run() {
10+
let { ui } = this;
11+
12+
ui.writeLine(chalk.green('iOS Build: Ember build'), chalk.green('.'));
13+
execSync('ember build --environment=production');
14+
15+
ui.writeLine(chalk.green('iOS Build: Sync'), chalk.green('.'));
16+
execSync('npx cap sync ios');
17+
18+
ui.writeLine(chalk.green('iOS Build: Opening Xcode'), chalk.green('.'));
19+
execSync('npx cap open ios');
20+
}
21+
}
22+
23+
module.exports = iOSBuildTask;

lib/tasks/ios-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 iOSServeTask extends Task {
9+
async run() {
10+
let { ui } = this;
11+
12+
ui.startProgress(chalk.green('iOS Serve: ember build'), chalk.green('.'));
13+
execSync('ember build --environment=development');
14+
ui.stopProgress();
15+
16+
ui.startProgress(chalk.green('iOS Serve: npx cap sync ios'), chalk.green('.'));
17+
execSync('npx cap sync ios');
18+
ui.stopProgress();
19+
20+
ui.startProgress(chalk.green('iOS Serve: npx cap open ios'), chalk.green('.'));
21+
execSync('npx cap open ios');
22+
ui.stopProgress();
23+
24+
ui.writeLine(chalk.green('iOS Serve: Serving Ember app in Xcode'));
25+
execSync('ember serve');
26+
}
27+
}
28+
29+
module.exports = iOSServeTask;

0 commit comments

Comments
 (0)