diff --git a/README.md b/README.md index 5f6df4699..3f24aa4fd 100644 --- a/README.md +++ b/README.md @@ -11,7 +11,7 @@ # Introduction -Bootstrap and package your project with Angular 5(+) and Electron (Typescript + SASS + Hot Reload) for creating Desktop applications. +Bootstrap and package your project with Angular 6(+) and Electron (Typescript + SASS + Hot Reload) for creating Desktop applications. Currently runs with: diff --git a/angular.json b/angular.json index 9d8756423..df1d20294 100644 --- a/angular.json +++ b/angular.json @@ -30,6 +30,23 @@ "scripts": [] }, "configurations": { + "dev": { + "optimization": false, + "outputHashing": "all", + "sourceMap": true, + "extractCss": true, + "namedChunks": false, + "aot": false, + "extractLicenses": true, + "vendorChunk": false, + "buildOptimizer": false, + "fileReplacements": [ + { + "replace": "src/environments/environment.ts", + "with": "src/environments/environment.dev.ts" + } + ] + }, "production": { "optimization": true, "outputHashing": "all", @@ -40,7 +57,12 @@ "extractLicenses": true, "vendorChunk": false, "buildOptimizer": true, - "fileReplacements": [] + "fileReplacements": [ + { + "replace": "src/environments/environment.ts", + "with": "src/environments/environment.prod.ts" + } + ] } } }, @@ -50,6 +72,9 @@ "browserTarget": "angular-electron:build" }, "configurations": { + "dev": { + "browserTarget": "angular-electron:build:dev" + }, "production": { "browserTarget": "angular-electron:build:production" } diff --git a/hooks/environments/README.md b/hooks/environments/README.md deleted file mode 100644 index 62e58b486..000000000 --- a/hooks/environments/README.md +++ /dev/null @@ -1,196 +0,0 @@ - -# Cordova Hooks - -Cordova Hooks represent special scripts which could be added by application and plugin developers or even by your own build system to customize cordova commands. Hook scripts could be defined by adding them to the special predefined folder (`/hooks`) or via configuration files (`config.xml` and `plugin.xml`) and run serially in the following order: -* Application hooks from `/hooks`; -* Application hooks from `config.xml`; -* Plugin hooks from `plugins/.../plugin.xml`. - -__Remember__: Make your scripts executable. - -__Note__: `.cordova/hooks` directory is also supported for backward compatibility, but we don't recommend using it as it is deprecated. - -## Supported hook types -The following hook types are supported: - - after_build/ - after_compile/ - after_docs/ - after_emulate/ - after_platform_add/ - after_platform_rm/ - after_platform_ls/ - after_plugin_add/ - after_plugin_ls/ - after_plugin_rm/ - after_plugin_search/ - after_plugin_install/ <-- Plugin hooks defined in plugin.xml are executed exclusively for a plugin being installed - after_prepare/ - after_run/ - after_serve/ - before_build/ - before_compile/ - before_docs/ - before_emulate/ - before_platform_add/ - before_platform_rm/ - before_platform_ls/ - before_plugin_add/ - before_plugin_ls/ - before_plugin_rm/ - before_plugin_search/ - before_plugin_install/ <-- Plugin hooks defined in plugin.xml are executed exclusively for a plugin being installed - before_plugin_uninstall/ <-- Plugin hooks defined in plugin.xml are executed exclusively for a plugin being uninstalled - before_prepare/ - before_run/ - before_serve/ - pre_package/ <-- Windows 8 and Windows Phone only. - -## Ways to define hooks -### Via '/hooks' directory -To execute custom action when corresponding hook type is fired, use hook type as a name for a subfolder inside 'hooks' directory and place you script file here, for example: - - # script file will be automatically executed after each build - hooks/after_build/after_build_custom_action.js - - -### Config.xml - -Hooks can be defined in project's `config.xml` using `` elements, for example: - - - - - - - - - - ... - - - - - - - ... - - -### Plugin hooks (plugin.xml) - -As a plugin developer you can define hook scripts using `` elements in a `plugin.xml` like that: - - - - - - - - ... - - -`before_plugin_install`, `after_plugin_install`, `before_plugin_uninstall` plugin hooks will be fired exclusively for the plugin being installed/uninstalled. - -## Script Interface - -### Javascript - -If you are writing hooks in Javascript you should use the following module definition: -```javascript -module.exports = function(context) { - ... -} -``` - -You can make your scipts async using Q: -```javascript -module.exports = function(context) { - var Q = context.requireCordovaModule('q'); - var deferral = new Q.defer(); - - setTimeout(function(){ - console.log('hook.js>> end'); - deferral.resolve(); - }, 1000); - - return deferral.promise; -} -``` - -`context` object contains hook type, executed script full path, hook options, command-line arguments passed to Cordova and top-level "cordova" object: -```json -{ - "hook": "before_plugin_install", - "scriptLocation": "c:\\script\\full\\path\\appBeforePluginInstall.js", - "cmdLine": "The\\exact\\command\\cordova\\run\\with arguments", - "opts": { - "projectRoot":"C:\\path\\to\\the\\project", - "cordova": { - "platforms": ["wp8"], - "plugins": ["com.plugin.withhooks"], - "version": "0.21.7-dev" - }, - "plugin": { - "id": "com.plugin.withhooks", - "pluginInfo": { - ... - }, - "platform": "wp8", - "dir": "C:\\path\\to\\the\\project\\plugins\\com.plugin.withhooks" - } - }, - "cordova": {...} -} - -``` -`context.opts.plugin` object will only be passed to plugin hooks scripts. - -You can also require additional Cordova modules in your script using `context.requireCordovaModule` in the following way: -```javascript -var Q = context.requireCordovaModule('q'); -``` - -__Note__: new module loader script interface is used for the `.js` files defined via `config.xml` or `plugin.xml` only. -For compatibility reasons hook files specified via `/hooks` folders are run via Node child_process spawn, see 'Non-javascript' section below. - -### Non-javascript - -Non-javascript scripts are run via Node child_process spawn from the project's root directory and have the root directory passes as the first argument. All other options are passed to the script using environment variables: - -* CORDOVA_VERSION - The version of the Cordova-CLI. -* CORDOVA_PLATFORMS - Comma separated list of platforms that the command applies to (e.g.: android, ios). -* CORDOVA_PLUGINS - Comma separated list of plugin IDs that the command applies to (e.g.: org.apache.cordova.file, org.apache.cordova.file-transfer) -* CORDOVA_HOOK - Path to the hook that is being executed. -* CORDOVA_CMDLINE - The exact command-line arguments passed to cordova (e.g.: cordova run ios --emulate) - -If a script returns a non-zero exit code, then the parent cordova command will be aborted. - -## Writing hooks - -We highly recommend writing your hooks using Node.js so that they are -cross-platform. Some good examples are shown here: - -[http://devgirl.org/2013/11/12/three-hooks-your-cordovaphonegap-project-needs/](http://devgirl.org/2013/11/12/three-hooks-your-cordovaphonegap-project-needs/) - -Also, note that even if you are working on Windows, and in case your hook scripts aren't bat files (which is recommended, if you want your scripts to work in non-Windows operating systems) Cordova CLI will expect a shebang line as the first line for it to know the interpreter it needs to use to launch the script. The shebang line should match the following example: - - #!/usr/bin/env [name_of_interpreter_executable] diff --git a/hooks/environments/app.config.ts.tpl b/hooks/environments/app.config.ts.tpl deleted file mode 100644 index b44526075..000000000 --- a/hooks/environments/app.config.ts.tpl +++ /dev/null @@ -1,23 +0,0 @@ -import { CONF_LOCAL } from '../environments/environment.local'; -import { CONF_DEV } from '../environments/environment.dev'; -import { CONF_PROD } from '../environments/environment.prod'; - -const ENV = 'PROFILE'; - -const LOCAL: String = 'local'; -const DEV: String = 'dev'; -const PROD: String = 'prod'; - -let conf: any; - -console.log('Env', ENV); - -if (ENV === PROD) { - conf = CONF_PROD; -} else if (ENV === DEV) { - conf = CONF_DEV; -} else { - conf = CONF_LOCAL; -} - -export const AppConfig = Object.assign({}, conf); diff --git a/hooks/environments/set_profile.js b/hooks/environments/set_profile.js deleted file mode 100644 index 58d69871c..000000000 --- a/hooks/environments/set_profile.js +++ /dev/null @@ -1,20 +0,0 @@ -// require: -var replace = require("replace"); -var fs = require('fs-extra'); -var path = require('path'); - -// use: -var profile = process.env.ENV ? process.env.ENV : 'local'; - -console.log('Déplacement du template de fichier de détection de configuration ...'); -fs.copySync(path.resolve(__dirname,'./app.config.ts.tpl'), path.resolve(__dirname,'../../src/app/app.config.ts')); - -console.log('Application du profil : ' + profile); - -replace({ - regex: "'PROFILE'", - replacement: "'" + profile + "'", - paths: ['src/app/app.config.ts'], - recursive: true, - silent: true, -}); diff --git a/hooks/src/app/app.config.ts b/hooks/src/app/app.config.ts deleted file mode 100644 index b44526075..000000000 --- a/hooks/src/app/app.config.ts +++ /dev/null @@ -1,23 +0,0 @@ -import { CONF_LOCAL } from '../environments/environment.local'; -import { CONF_DEV } from '../environments/environment.dev'; -import { CONF_PROD } from '../environments/environment.prod'; - -const ENV = 'PROFILE'; - -const LOCAL: String = 'local'; -const DEV: String = 'dev'; -const PROD: String = 'prod'; - -let conf: any; - -console.log('Env', ENV); - -if (ENV === PROD) { - conf = CONF_PROD; -} else if (ENV === DEV) { - conf = CONF_DEV; -} else { - conf = CONF_LOCAL; -} - -export const AppConfig = Object.assign({}, conf); diff --git a/hooks/src/app/appconfig.ts b/hooks/src/app/appconfig.ts deleted file mode 100644 index b44526075..000000000 --- a/hooks/src/app/appconfig.ts +++ /dev/null @@ -1,23 +0,0 @@ -import { CONF_LOCAL } from '../environments/environment.local'; -import { CONF_DEV } from '../environments/environment.dev'; -import { CONF_PROD } from '../environments/environment.prod'; - -const ENV = 'PROFILE'; - -const LOCAL: String = 'local'; -const DEV: String = 'dev'; -const PROD: String = 'prod'; - -let conf: any; - -console.log('Env', ENV); - -if (ENV === PROD) { - conf = CONF_PROD; -} else if (ENV === DEV) { - conf = CONF_DEV; -} else { - conf = CONF_LOCAL; -} - -export const AppConfig = Object.assign({}, conf); diff --git a/package.json b/package.json index 774f77a73..46e334d58 100644 --- a/package.json +++ b/package.json @@ -19,9 +19,10 @@ "scripts": { "postinstall": "npx electron-builder install-app-deps", "ng": "ng", - "start": "node hooks/environments/set_profile.js && npm-run-all -p ng:serve electron:serve", - "build": "node hooks/environments/set_profile.js && ng build && npm run electron:tsc", - "build:prod": "node hooks/environments/set_profile.js && ng build -c production && npm run electron:tsc", + "start": "npm-run-all -p ng:serve electron:serve", + "build": "npm run electron:tsc && ng build", + "build:dev": "npm run build -- -c dev", + "build:prod": "npm run build -- -c production", "ng:serve": "ng serve -o", "electron:tsc": "tsc main.ts", "electron:serve": "wait-on http-get://localhost:4200/ && npm run electron:tsc && electron . --serve", diff --git a/src/app/app.component.ts b/src/app/app.component.ts index 3354da3ea..11b2b55f3 100644 --- a/src/app/app.component.ts +++ b/src/app/app.component.ts @@ -1,7 +1,7 @@ import { Component } from '@angular/core'; import { ElectronService } from './providers/electron.service'; import { TranslateService } from '@ngx-translate/core'; -import { AppConfig } from './app.config'; +import { AppConfig } from '../environments/environment'; @Component({ selector: 'app-root', diff --git a/src/app/app.config.ts b/src/app/app.config.ts deleted file mode 100644 index ae0e97c13..000000000 --- a/src/app/app.config.ts +++ /dev/null @@ -1,23 +0,0 @@ -import { CONF_LOCAL } from '../environments/environment.local'; -import { CONF_DEV } from '../environments/environment.dev'; -import { CONF_PROD } from '../environments/environment.prod'; - -const ENV = 'prod'; - -const LOCAL: String = 'local'; -const DEV: String = 'dev'; -const PROD: String = 'prod'; - -let conf: any; - -console.log('Env', ENV); - -if (ENV === PROD) { - conf = CONF_PROD; -} else if (ENV === DEV) { - conf = CONF_DEV; -} else { - conf = CONF_LOCAL; -} - -export const AppConfig = Object.assign({}, conf); diff --git a/src/environments/environment.dev.ts b/src/environments/environment.dev.ts index 3621f0435..7953ebf84 100644 --- a/src/environments/environment.dev.ts +++ b/src/environments/environment.dev.ts @@ -3,7 +3,7 @@ // `ng build --env=prod` then `index.prod.ts` will be used instead. // The list of which env maps to which file can be found in `.angular-cli.json`. -export const CONF_DEV = { +export const AppConfig = { production: false, environment: 'DEV' }; diff --git a/src/environments/environment.prod.ts b/src/environments/environment.prod.ts index 7f65d3351..047b3fce6 100644 --- a/src/environments/environment.prod.ts +++ b/src/environments/environment.prod.ts @@ -1,4 +1,4 @@ -export const CONF_PROD = { +export const AppConfig = { production: true, environment: 'PROD' }; diff --git a/src/environments/environment.local.ts b/src/environments/environment.ts similarity index 62% rename from src/environments/environment.local.ts rename to src/environments/environment.ts index 165339ff5..ca0b6a9cb 100644 --- a/src/environments/environment.local.ts +++ b/src/environments/environment.ts @@ -1,4 +1,4 @@ -export const CONF_LOCAL = { +export const AppConfig = { production: false, environment: 'LOCAL' }; diff --git a/src/main.ts b/src/main.ts index 989d9a30c..6ad7b1007 100644 --- a/src/main.ts +++ b/src/main.ts @@ -2,7 +2,7 @@ import { enableProdMode } from '@angular/core'; import { platformBrowserDynamic } from '@angular/platform-browser-dynamic'; import { AppModule } from './app/app.module'; -import { AppConfig } from './app/app.config'; +import { AppConfig } from './environments/environment'; if (AppConfig.production) { enableProdMode();