Skip to content

Commit

Permalink
Added support for multiple targets (closes #105)
Browse files Browse the repository at this point in the history
  • Loading branch information
sinedied committed Jul 24, 2017
1 parent cab7917 commit 714f65f
Show file tree
Hide file tree
Showing 16 changed files with 82 additions and 72 deletions.
2 changes: 1 addition & 1 deletion generators/app/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ const Insight = require('insight');
const Generator = require('@ngx-rocket/core');
const asciiLogo = require('@ngx-rocket/ascii-logo');

const prompts = require('./prompts');
const options = require('./options.json');
const prompts = require('./prompts.json');
const pkg = require('../../package.json');

class NgxGenerator extends Generator {
Expand Down
57 changes: 57 additions & 0 deletions generators/app/prompts.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
'use strict';

module.exports = [
{
type: 'input',
name: 'appName',
message: 'What\'s the name of your app?'
},
{
type: 'checkbox',
name: 'target',
message: 'What kind of app do you want to create?',
choices: [
{
value: 'web',
name: 'Responsive web app',
checked: true
},
{
value: 'mobile',
name: 'Mobile app (using Cordova)'
}
// {
// value: 'electron',
// name: 'Desktop app (using Cordova)'
// }
]
},
// {
// type: 'confirm',
// name: 'pwa',
// message: 'Do you want progressive web app support? (manifest and service worker)',
// default: true,
// when: props => props.target.includes('web')
// },
{
type: 'list',
name: 'ui',
message: 'Which UI framework do you want?',
choices: [
{
value: 'bootstrap',
name: 'Bootstrap (more website-oriented)'
},
{
value: 'ionic',
name: 'Ionic (more mobile-oriented)'
}
]
},
{
type: 'confirm',
name: 'auth',
message: 'Do you want authentication?',
default: true
}
];
47 changes: 0 additions & 47 deletions generators/app/prompts.json

This file was deleted.

4 changes: 2 additions & 2 deletions generators/app/templates/_.angular-cli.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@
"apps": [
{
"root": "src",
"outDir": "<%= props.target === 'mobile' ? 'www' : 'dist' %>",
"outDir": "<%= props.target.includes('cordova') ? 'www' : 'dist' %>",
"assets": [
"assets",
"favicon.ico",
<% if (props.target === 'pwa') { -%>
<% if (props.pwa) { -%>
"manifest.json",
<% } -%>
"robots.txt"
Expand Down
2 changes: 1 addition & 1 deletion generators/app/templates/_browserslist
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# See https://github.com/ai/browserslist

Last 2 versions
<% if (props.target === 'mobile') { -%>
<% if (props.target.includes('cordova')) { -%>
iOS >= 8
Android >= 4.4
Explorer >= 11
Expand Down
6 changes: 3 additions & 3 deletions generators/app/templates/_package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
"translations:extract": "ngx-translate-extract --input ./src --output ./src/translations/template.json --format=json --clean -sort --marker extract",
"docs": "hads ./docs -o",
"env": "ngx-scripts env2json npm_package_version",
<% if (props.target === 'mobile') { -%>
<% if (props.target.includes('cordova')) { -%>
"prepare": "ngx-scripts unpin-ionic-dependencies",
"cordova:prepare": "ngx-scripts cordova prepare",
"cordova:package": "ngx-scripts cordova build --device --release --copy dist",
Expand All @@ -34,7 +34,7 @@
"@angular/platform-browser-dynamic": "^4.2.6",
"@angular/router": "^4.2.6",
"@ngx-translate/core": "^7.0.0",
<% if (props.target === 'mobile') { -%>
<% if (props.target.includes('cordova')) { -%>
"@ionic-native/core": "^4.0.0",
"@ionic-native/keyboard": "^4.0.0",
"@ionic-native/splash-screen": "^4.0.0",
Expand All @@ -55,7 +55,7 @@
"zone.js": "^0.8.12"
},
"devDependencies": {
<% if (props.target === 'mobile') { -%>
<% if (props.target.includes('cordova')) { -%>
"cordova": "^7.0.0",
<% } -%>
"@angular/cli": "^1.2.3",
Expand Down
6 changes: 3 additions & 3 deletions generators/app/templates/src/_index.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<head>
<meta charset="utf-8"/>
<title><%= props.appName %></title>
<% if (props.target === 'mobile') { -%>
<% if (props.target.includes('cordova')) { -%>
<base href="./"/>
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no"/>
<meta name="msapplication-tap-highlight" content="no"/>
Expand All @@ -16,15 +16,15 @@
<link rel="icon" type="image/x-icon" href="favicon.ico"/>
</head>
<body>
<% if (props.target === 'web') { -%>
<% if (props.target.includes('web')) { -%>
<!--[if lt IE 10]>
<p>
You are using an <strong>outdated</strong> browser.
Please <a href="http://browsehappy.com/">upgrade your browser</a> to improve your experience.
</p>
<![endif]-->
<% } -%>
<% if (props.target === 'mobile') { -%>
<% if (props.target.includes('cordova')) { -%>
<!-- Include Cordova script only when needed -->
<script>
if (!/^http/.test(location.protocol)) {
Expand Down
4 changes: 2 additions & 2 deletions generators/app/templates/src/app/_app.component.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { TranslateModule } from '@ngx-translate/core';
<% if (props.ui === 'ionic') { -%>
import { IonicModule } from 'ionic-angular';
<% } -%>
<% if (props.target === 'mobile') { -%>
<% if (props.target.includes('cordova')) { -%>
import { Keyboard } from '@ionic-native/keyboard';
import { StatusBar } from '@ionic-native/status-bar';
import { SplashScreen } from '@ionic-native/splash-screen';
Expand All @@ -25,7 +25,7 @@ describe('AppComponent', () => {
CoreModule
],
declarations: [AppComponent],
<% if (props.target === 'mobile') { -%>
<% if (props.target.includes('cordova')) { -%>
providers: [
Keyboard,
StatusBar,
Expand Down
12 changes: 6 additions & 6 deletions generators/app/templates/src/app/_app.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,13 @@ import { Title } from '@angular/platform-browser';
import { TranslateService } from '@ngx-translate/core';
import { Observable } from 'rxjs/Observable';
<% if (props.ui === 'ionic') { -%>
<% if (props.target === 'mobile') { -%>
<% if (props.target.includes('cordova')) { -%>
import { IonicApp, Nav, Platform } from 'ionic-angular';
<% } else { -%>
import { IonicApp, Nav } from 'ionic-angular';
<% } -%>
<% } -%>
<% if (props.target === 'mobile') { -%>
<% if (props.target.includes('cordova')) { -%>
import { Keyboard } from '@ionic-native/keyboard';
import { StatusBar } from '@ionic-native/status-bar';
import { SplashScreen } from '@ionic-native/splash-screen';
Expand All @@ -47,7 +47,7 @@ export class AppComponent implements OnInit {
private activatedRoute: ActivatedRoute,
private titleService: Title,
private translateService: TranslateService,
<% if (props.target === 'mobile') { -%>
<% if (props.target.includes('cordova')) { -%>
<% if (props.ui === 'ionic') { -%>
private platform: Platform,
<% } else { %>
Expand Down Expand Up @@ -93,19 +93,19 @@ export class AppComponent implements OnInit {

// Bind Ionic navigation to Angular router events
onNavigationEnd.subscribe(() => this.updateNav(this.activatedRoute));
<% if (props.target === 'mobile') { -%>
<% if (props.target.includes('cordova')) { -%>

// Cordova platform and plugins initialization
this.platform.ready().then(() => this.onCordovaReady());
<% } -%>
<% } else if (props.target === 'mobile') { -%>
<% } else if (props.target.includes('cordova')) { -%>
// Cordova platform and plugins initialization
document.addEventListener('deviceready', () => {
this.zone.run(() => this.onCordovaReady());
}, false);
<% } -%>
}
<% if (props.target === 'mobile') { -%>
<% if (props.target.includes('cordova')) { -%>

private onCordovaReady() {
if (window['cordova']) {
Expand Down
4 changes: 2 additions & 2 deletions generators/app/templates/src/app/_app.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import { NgbModule } from '@ng-bootstrap/ng-bootstrap';
import { IonicModule } from 'ionic-angular';
import { LocationStrategy, PathLocationStrategy } from '@angular/common';
<% } -%>
<% if (props.target === 'mobile') { -%>
<% if (props.target.includes('cordova')) { -%>
import { Keyboard } from '@ionic-native/keyboard';
import { StatusBar } from '@ionic-native/status-bar';
import { SplashScreen } from '@ionic-native/splash-screen';
Expand Down Expand Up @@ -48,7 +48,7 @@ import { LoginModule } from './login/login.module';
],
declarations: [AppComponent],
providers: [
<% if (props.target === 'mobile') { -%>
<% if (props.target.includes('cordova')) { -%>
Keyboard,
StatusBar,
<% if (props.ui === 'ionic') { -%>
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
},
"dependencies": {
"@ngx-rocket/ascii-logo": "^1.0.0",
"@ngx-rocket/core": "^1.2.1",
"@ngx-rocket/core": "^2.0.0",
"chalk": "^2.0.1",
"insight": "^0.8.4"
},
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"target": "mobile",
"target": ["cordova"],
"ui": "ionic",
"auth": true
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"target": "mobile",
"target": ["cordova"],
"ui": "ionic",
"auth": false
}
2 changes: 1 addition & 1 deletion scripts/tests/web/bootstrap-authentication.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"target": "web",
"target": ["web"],
"ui": "bootstrap",
"auth": true
}
2 changes: 1 addition & 1 deletion scripts/tests/web/bootstrap.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"target": "web",
"target": ["web"],
"ui": "bootstrap",
"auth": false
}

0 comments on commit 714f65f

Please sign in to comment.