From 714f65f2c50970f527161bc28d38324351ade70b Mon Sep 17 00:00:00 2001 From: Yohan Lasorsa Date: Mon, 24 Jul 2017 18:08:44 +0200 Subject: [PATCH] Added support for multiple targets (closes #105) --- generators/app/index.js | 2 +- generators/app/prompts.js | 57 +++++++++++++++++++ generators/app/prompts.json | 47 --------------- generators/app/templates/_.angular-cli.json | 4 +- ...bile._config.xml => __cordova._config.xml} | 0 generators/app/templates/_browserslist | 2 +- generators/app/templates/_package.json | 6 +- generators/app/templates/src/_index.html | 6 +- .../templates/src/app/_app.component.spec.ts | 4 +- .../app/templates/src/app/_app.component.ts | 12 ++-- .../app/templates/src/app/_app.module.ts | 4 +- package.json | 2 +- .../ionic-authentication.json | 2 +- scripts/tests/{mobile => cordova}/ionic.json | 2 +- .../tests/web/bootstrap-authentication.json | 2 +- scripts/tests/web/bootstrap.json | 2 +- 16 files changed, 82 insertions(+), 72 deletions(-) create mode 100755 generators/app/prompts.js delete mode 100755 generators/app/prompts.json rename generators/app/templates/{__mobile._config.xml => __cordova._config.xml} (100%) rename scripts/tests/{mobile => cordova}/ionic-authentication.json (59%) rename scripts/tests/{mobile => cordova}/ionic.json (59%) diff --git a/generators/app/index.js b/generators/app/index.js index 22235b1e..b5a2f46e 100755 --- a/generators/app/index.js +++ b/generators/app/index.js @@ -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 { diff --git a/generators/app/prompts.js b/generators/app/prompts.js new file mode 100755 index 00000000..9d23c9ce --- /dev/null +++ b/generators/app/prompts.js @@ -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 + } +]; diff --git a/generators/app/prompts.json b/generators/app/prompts.json deleted file mode 100755 index d01d93d7..00000000 --- a/generators/app/prompts.json +++ /dev/null @@ -1,47 +0,0 @@ -[ - { - "type": "input", - "name": "appName", - "message": "What's the name of your app?" - }, - { - "type": "list", - "name": "target", - "message": "What kind of app do you want to create?", - "choices": [ - { - "value": "web", - "name": "Web" - }, - { - "value": "mobile", - "name": "Mobile" - }, - { - "value": "both", - "name": "Web + mobile" - } - ] - }, - { - "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 - } -] diff --git a/generators/app/templates/_.angular-cli.json b/generators/app/templates/_.angular-cli.json index 7aab3e80..78331c50 100644 --- a/generators/app/templates/_.angular-cli.json +++ b/generators/app/templates/_.angular-cli.json @@ -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" diff --git a/generators/app/templates/__mobile._config.xml b/generators/app/templates/__cordova._config.xml similarity index 100% rename from generators/app/templates/__mobile._config.xml rename to generators/app/templates/__cordova._config.xml diff --git a/generators/app/templates/_browserslist b/generators/app/templates/_browserslist index b29066da..297da254 100644 --- a/generators/app/templates/_browserslist +++ b/generators/app/templates/_browserslist @@ -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 diff --git a/generators/app/templates/_package.json b/generators/app/templates/_package.json index 9b72806c..6761938d 100644 --- a/generators/app/templates/_package.json +++ b/generators/app/templates/_package.json @@ -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", @@ -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", @@ -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", diff --git a/generators/app/templates/src/_index.html b/generators/app/templates/src/_index.html index 00a5ff6f..24df1604 100644 --- a/generators/app/templates/src/_index.html +++ b/generators/app/templates/src/_index.html @@ -3,7 +3,7 @@ <%= props.appName %> -<% if (props.target === 'mobile') { -%> +<% if (props.target.includes('cordova')) { -%> @@ -16,7 +16,7 @@ -<% if (props.target === 'web') { -%> +<% if (props.target.includes('web')) { -%> <% } -%> -<% if (props.target === 'mobile') { -%> +<% if (props.target.includes('cordova')) { -%>