-
Notifications
You must be signed in to change notification settings - Fork 1.4k
/
Copy pathseed.config.ts
895 lines (801 loc) · 24.5 KB
/
seed.config.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
import { join } from 'path';
import * as slash from 'slash';
import { argv } from 'yargs';
const magicImporter = require('node-sass-magic-importer');
import {
BuildType,
ExtendPackages,
InjectableDependency,
SourceMapExplorerOutputFormat
} from './seed.config.interfaces';
/************************* DO NOT CHANGE ************************
*
* DO NOT make any changes in this file because it will
* make your migration to newer versions of the seed harder.
*
* Your application-specific configurations should be
* in project.config.ts. If you need to change any tasks
* from "./tasks" overwrite them by creating a task with the
* same name in "./projects". For further information take a
* look at the documentation:
*
* 1) https://github.com/mgechev/angular-seed/tree/master/tools
* 2) https://github.com/mgechev/angular-seed/wiki
*
*****************************************************************/
/**
* The enumeration of available environments.
* @type {Environments}
*/
export const BUILD_TYPES: BuildType = {
DEVELOPMENT: 'dev',
PRODUCTION: 'prod'
};
/**
* The enumeration of available source-map-explorer output formats.
* @type {SourceMapExplorerOutputFormats}
*/
export const SME_OUTPUT_FORMATS: SourceMapExplorerOutputFormat = {
HTML: 'html',
JSON: 'json',
TSV: 'tsv'
};
/**
* This class represents the basic configuration of the seed.
* It provides the following:
* - Constants for directories, ports, versions etc.
* - Injectable NPM dependencies
* - Injectable application assets
* - Temporary editor files to be ignored by the watcher and asset builder
* - SystemJS configuration
* - Autoprefixer configuration
* - BrowserSync configuration
* - Utilities
*/
export class SeedConfig {
/**
* The port where the application will run.
* The default port is `5555`, which can be overriden by the `--port` flag when running `npm start`.
* @type {number}
*/
PORT = argv['port'] || 5555;
/**
* The root folder of the project (up two levels from the current directory).
*/
PROJECT_ROOT = join(__dirname, '../..');
/**
* The current build type.
* The default build type is `dev`, which can be overriden by the `--build-type dev|prod` flag when running `npm start`.
*/
BUILD_TYPE = getBuildType();
/**
* The flag to determine preserving source maps on build or not.
* The default value is `false`, which can be overriden by the `--preserve-source-maps` flag when running `npm start`.
*/
PRESERVE_SOURCE_MAPS = argv['preserve-source-maps'] || false;
/**
* The current source-map-explorer output format.
* The default value is `html`, which can be overriden by the `--sme-out-format html|json|tsv` flag when running `npm run sme`.
*/
SME_OUT_FORMAT = getSmeOutFormat();
/**
* The current source-map-explorer output folder.
*/
SME_DIR = 'sme';
/**
* The flag for the debug option of the application.
* The default value is `false`, which can be overriden by the `--debug` flag when running `npm start`.
* @type {boolean}
*/
DEBUG = argv['debug'] || false;
/**
* The port where the documentation application will run.
* The default docs port is `4003`, which can be overriden by the `--docs-port` flag when running `npm start`.
* @type {number}
*/
DOCS_PORT = argv['docs-port'] || 4003;
/**
* The port where the unit test coverage report application will run.
* The default coverage port is `4004`, which can by overriden by the `--coverage-port` flag when running `npm start`.
* @type {number}
*/
COVERAGE_PORT = argv['coverage-port'] || 4004;
/**
* The path to the coverage output
* NB: this must match what is configured in ./karma.conf.js
*/
COVERAGE_DIR = 'coverage_js';
COVERAGE_TS_DIR = 'coverage';
/**
* The path for the base of the application at runtime.
* The default path is based on the environment '/',
* which can be overriden by the `--base` flag when running `npm start`.
* @type {string}
*/
APP_BASE = argv['base'] || '/';
/**
* The base path of node modules.
* @type {string}
*/
NPM_BASE = slash(join('.', this.APP_BASE, 'node_modules/'));
/**
* The build interval which will force the TypeScript compiler to perform a typed compile run.
* Between the typed runs, a typeless compile is run, which is typically much faster.
* For example, if set to 5, the initial compile will be typed, followed by 5 typeless runs,
* then another typed run, and so on.
* If a compile error is encountered, the build will use typed compilation until the error is resolved.
* The default value is `0`, meaning typed compilation will always be performed.
* @type {number}
*/
TYPED_COMPILE_INTERVAL = 0;
/**
* The directory where the bootstrap file is located.
* The default directory is `app`.
* @type {string}
*/
BOOTSTRAP_DIR = argv['app'] || 'app';
/**
* The directory where the client files are located.
* The default directory is `client`.
* @type {string}
*/
APP_CLIENT = argv['client'] || 'client';
/**
* The bootstrap file to be used to boot the application.
* @type {string}
*/
BOOTSTRAP_MODULE = `${this.BOOTSTRAP_DIR}/main`;
BOOTSTRAP_PROD_MODULE = `${this.BOOTSTRAP_DIR}/` + 'main';
NG_FACTORY_FILE = 'main-prod';
BOOTSTRAP_FACTORY_PROD_MODULE = `${this.BOOTSTRAP_DIR}/${this
.NG_FACTORY_FILE}`;
/**
* The default title of the application as used in the `<title>` tag of the
* `index.html`.
* @type {string}
*/
APP_TITLE = 'Welcome to angular-seed!';
/**
* Tracking ID.
* @type {string}
*/
GOOGLE_ANALYTICS_ID = 'UA-XXXXXXXX-X';
/**
* The base folder of the applications source files.
* @type {string}
*/
APP_SRC = `src/${this.APP_CLIENT}`;
/**
* The name of the TypeScript project file
* @type {string}
*/
APP_PROJECTNAME = 'tsconfig.json';
/**
* The folder of the applications asset files.
* @type {string}
*/
ASSETS_SRC = `${this.APP_SRC}/assets`;
/**
* The folder of the applications css files.
* @type {string}
*/
CSS_SRC = `${this.APP_SRC}/css`;
/**
* The folder of the e2e specs and framework
*/
E2E_SRC = 'src/e2e';
/**
* The folder of the applications scss files.
* @type {string}
*/
SCSS_SRC = `${this.APP_SRC}/scss`;
/**
* The directory of the applications tools
* @type {string}
*/
TOOLS_DIR = 'tools';
/**
* The directory of the tasks provided by the seed.
*/
SEED_TASKS_DIR = join(process.cwd(), this.TOOLS_DIR, 'tasks', 'seed');
/**
* Seed tasks which are composition of other tasks.
*/
SEED_COMPOSITE_TASKS = join(
process.cwd(),
this.TOOLS_DIR,
'config',
'seed.tasks.json'
);
/**
* Project tasks which are composition of other tasks
* and aim to override the tasks defined in
* SEED_COMPOSITE_TASKS.
*/
PROJECT_COMPOSITE_TASKS = join(
process.cwd(),
this.TOOLS_DIR,
'config',
'project.tasks.json'
);
/**
* The destination folder for the generated documentation.
* @type {string}
*/
DOCS_DEST = 'docs';
/**
* The base folder for built files.
* @type {string}
*/
DIST_DIR = 'dist';
/**
* The folder for built files in the `dev` environment.
* @type {string}
*/
DEV_DEST = `${this.DIST_DIR}/dev`;
/**
* The folder for the built files in the `prod` environment.
* @type {string}
*/
PROD_DEST = `${this.DIST_DIR}/prod`;
/**
* The folder for the built files of the e2e-specs.
* @type {string}
*/
E2E_DEST = `${this.DIST_DIR}/e2e`;
/**
* The folder for the built translation file.
* @type {string}
*/
LOCALE_DEST = `${this.DIST_DIR}/locale`;
/**
* The folder for temporary files.
* @type {string}
*/
TMP_DIR = `${this.DIST_DIR}/tmp`;
/**
* The folder for the built files, corresponding to the current environment.
* @type {string}
*/
APP_DEST = this.BUILD_TYPE === BUILD_TYPES.DEVELOPMENT
? this.DEV_DEST
: this.PROD_DEST;
/**
* The folder for the built CSS files.
* @type {strings}
*/
CSS_DEST = `${this.APP_DEST}/css`;
/**
* The folder for the built JavaScript files.
* @type {string}
*/
JS_DEST = `${this.APP_DEST}/js`;
/**
* The version of the application as defined in the `package.json`.
*/
VERSION = appVersion();
/**
* The name of the bundle file to includes all CSS files.
* @type {string}
*/
CSS_BUNDLE_NAME = 'main';
/**
* The name of the bundle file to include all JavaScript shims.
* @type {string}
*/
JS_PROD_SHIMS_BUNDLE = 'shims.js';
/**
* The name of the bundle file to include all JavaScript application files.
* @type {string}
*/
JS_PROD_APP_BUNDLE = 'app.js';
/**
* The required NPM version to run the application.
* @type {string}
*/
VERSION_NPM = '2.14.2';
/**
* The required NodeJS version to run the application.
* @type {string}
*/
VERSION_NODE = '4.0.0';
/**
* Enable SCSS stylesheet compilation.
* Set ENABLE_SCSS environment variable to 'true' or '1'
* @type {boolean}
*/
ENABLE_SCSS = ['true', '1'].indexOf(
`${process.env.ENABLE_SCSS}`.toLowerCase()
) !== -1 ||
argv['scss'] ||
false;
/**
* Enable tslint emit error by setting env variable FORCE_TSLINT_EMIT_ERROR
* @type {boolean}
*/
FORCE_TSLINT_EMIT_ERROR = !!process.env.FORCE_TSLINT_EMIT_ERROR;
/**
* Extra paths for the gulp process to watch for to trigger compilation.
* @type {string[]}
*/
EXTRA_WATCH_PATHS: string[] = [];
/**
* Defines the template config.
*/
TEMPLATE_CONFIG = {
/**
* Used to detect `data` property values to be HTML-escaped.
*
* @memberOf _.templateSettings
* @type {RegExp}
*/
escape: /<%-([\s\S]+?)%>/g,
/**
* Used to detect code to be evaluated.
*
* @memberOf _.templateSettings
* @type {RegExp}
*/
evaluate: /<%([\s\S]+?)%>/g,
/**
* Used to detect `data` property values to inject.
*
* @memberOf _.templateSettings
* @type {RegExp}
*/
interpolate: /<%=([\s\S]+?)%>/g,
/**
* Used to reference the data object in the template text.
*
* @memberOf _.templateSettings
* @type {string}
*/
variable: ''
};
/**
* The list of NPM dependcies to be injected in the `index.html`.
* @type {InjectableDependency[]}
*/
NPM_DEPENDENCIES: InjectableDependency[] = [
{ src: 'core-js/client/shim.min.js', inject: 'shims' },
{ src: 'zone.js/dist/zone.js', inject: 'libs' },
{
src: 'zone.js/dist/long-stack-trace-zone.js',
inject: 'libs',
buildType: BUILD_TYPES.DEVELOPMENT
},
{ src: 'intl/dist/Intl.min.js', inject: 'shims' },
{
src: 'systemjs/dist/system.src.js',
inject: 'shims',
buildType: BUILD_TYPES.DEVELOPMENT
},
];
/**
* The list of local files to be injected in the `index.html`.
* @type {InjectableDependency[]}
*/
APP_ASSETS: InjectableDependency[] = [];
/**
* The list of editor temporary files to ignore in watcher and asset builder.
* @type {string[]}
*/
TEMP_FILES: string[] = ['**/*___jb_tmp___', '**/*~'];
/**
* List of directories to include in commonjs
* @type {string[]}
*/
ROLLUP_INCLUDE_DIR: string[] = ['node_modules/**'];
/**
* List of named export Object key value pairs
* key: dependencie file
* value: exported Objects
*/
ROLLUP_NAMED_EXPORTS: any[] = [];
/**
* Returns the array of injectable dependencies (npm dependencies and assets).
* @return {InjectableDependency[]} The array of npm dependencies and assets.
*/
get DEPENDENCIES(): InjectableDependency[] {
return normalizeDependencies(
this.NPM_DEPENDENCIES.filter(filterDependency.bind(null, this.BUILD_TYPE))
).concat(
this._APP_ASSETS.filter(filterDependency.bind(null, this.BUILD_TYPE))
);
}
/**
* The configuration of SystemJS for the `dev` environment.
* @type {any}
*/
SYSTEM_CONFIG_DEV: any = {
bundles: {
'node_modules/.tmp/Rx.min.js': [
'rxjs',
'rxjs/*'
]
},
paths: {
[this.BOOTSTRAP_MODULE]: `${this.APP_BASE}${this.BOOTSTRAP_MODULE}`,
'@angular/animations':
'node_modules/@angular/animations/bundles/animations.umd.js',
'@angular/platform-browser/animations':
'node_modules/@angular/platform-browser/bundles/platform-browser-animations.umd.js',
'@angular/common': 'node_modules/@angular/common/bundles/common.umd.js',
'@angular/common/http': 'node_modules/@angular/common/bundles/common-http.umd.js',
'@angular/compiler':
'node_modules/@angular/compiler/bundles/compiler.umd.js',
'@angular/core': 'node_modules/@angular/core/bundles/core.umd.js',
'@angular/forms': 'node_modules/@angular/forms/bundles/forms.umd.js',
'@angular/platform-browser':
'node_modules/@angular/platform-browser/bundles/platform-browser.umd.js',
'@angular/platform-browser-dynamic':
'node_modules/@angular/platform-browser-dynamic/bundles/platform-browser-dynamic.umd.js',
'@angular/router': 'node_modules/@angular/router/bundles/router.umd.js',
'@angular/animations/browser':
'node_modules/@angular/animations/bundles/animations-browser.umd.js',
'@angular/service-worker':
'node_modules/@angular/service-worker/bundles/service-worker.umd.js',
'tslib': 'node_modules/tslib/tslib.js',
'@angular/common/testing':
'node_modules/@angular/common/bundles/common-testing.umd.js',
'@angular/common/http/testing':
'node_modules/@angular/common/bundles/common-http-testing.umd.js',
'@angular/compiler/testing':
'node_modules/@angular/compiler/bundles/compiler-testing.umd.js',
'@angular/core/testing':
'node_modules/@angular/core/bundles/core-testing.umd.js',
'@angular/platform-browser/testing':
'node_modules/@angular/platform-browser/bundles/platform-browser-testing.umd.js',
'@angular/platform-browser-dynamic/testing':
'node_modules/@angular/platform-browser-dynamic/bundles/platform-browser-dynamic-testing.umd.js',
'@angular/router/testing':
'node_modules/@angular/router/bundles/router-testing.umd.js',
'app/': `${this.APP_BASE}app/`,
// For test config
'dist/dev/': '/base/dist/dev/',
'': 'node_modules/',
},
packages: {
[this.BOOTSTRAP_DIR]: {
defaultExtension: 'js'
}
}
};
/**
* The configuration of SystemJS of the application.
* Per default, the configuration of the `dev` environment will be used.
* @type {any}
*/
SYSTEM_CONFIG: any = this.SYSTEM_CONFIG_DEV;
/**
* The system builder configuration of the application.
* @type {any}
*/
SYSTEM_BUILDER_CONFIG: any = {
defaultJSExtensions: true,
base: this.PROJECT_ROOT,
packageConfigPaths: [
join('node_modules', '*', 'package.json'),
join('node_modules', '@angular', '*', 'package.json')
// for other modules like @ngx-translate the package.json path needs to updated here
// otherwise npm run build.prod would fail
// join('node_modules', '@ngx-translate', '*', 'package.json')
],
paths: {
// Note that for multiple apps this configuration need to be updated
// You will have to include entries for each individual application in
// `src/client`.
[join(this.TMP_DIR, this.BOOTSTRAP_DIR, '*')]: `${this.TMP_DIR}/${this
.BOOTSTRAP_DIR}/*`,
'@angular/platform-browser/animations':
'node_modules/@angular/platform-browser/bundles/platform-browser-animations.umd.js',
'@angular/animations/browser':
'node_modules/@angular/animations/bundles/animations-browser.umd.js',
'@angular/common/http':
'node_modules/@angular/common/bundles/common-http.umd.js',
'tslib': 'node_modules/tslib/tslib.js',
'rxjs': 'node_modules/rxjs',
'dist/tmp/node_modules/*': 'dist/tmp/node_modules/*',
'node_modules/*': 'node_modules/*',
'*': 'node_modules/*'
},
packages: {
'@angular/animations': {
main: 'bundles/animations.umd.js',
defaultExtension: 'js'
},
'@angular/common': {
main: 'bundles/common.umd.js',
defaultExtension: 'js'
},
'@angular/compiler': {
main: 'bundles/compiler.umd.js',
defaultExtension: 'js'
},
'@angular/core/testing': {
main: 'bundles/core-testing.umd.js',
defaultExtension: 'js'
},
'@angular/core': {
main: 'bundles/core.umd.js',
defaultExtension: 'js'
},
'@angular/forms': {
main: 'bundles/forms.umd.js',
defaultExtension: 'js'
},
'@angular/platform-browser': {
main: 'bundles/platform-browser.umd.js',
defaultExtension: 'js'
},
'@angular/platform-browser-dynamic': {
main: 'bundles/platform-browser-dynamic.umd.js',
defaultExtension: 'js'
},
'@angular/router': {
main: 'bundles/router.umd.js',
defaultExtension: 'js'
},
'@angular/service-worker': {
main: 'bundles/service-worker.umd.js',
defaultExtension: 'js'
},
'rxjs': {
main: 'index.js',
defaultExtension: 'js'
},
'rxjs/ajax': {
main: 'index.js',
defaultExtension: 'js'
},
'rxjs/operators': {
main: 'index.js',
defaultExtension: 'js'
},
'rxjs/testing': {
main: 'index.js',
defaultExtension: 'js'
},
'rxjs/webSocket': {
main: 'index.js',
defaultExtension: 'js'
}
}
};
/**
* The Autoprefixer configuration for the application.
* @type {Array}
*/
BROWSER_LIST = [
'ie >= 10',
'ie_mob >= 10',
'ff >= 30',
'chrome >= 34',
'safari >= 7',
'opera >= 23',
'ios >= 7',
'android >= 4.4',
'bb >= 10'
];
/**
* White list for CSS color guard
* @type {[string, string][]}
*/
COLOR_GUARD_WHITE_LIST: [string, string][] = [];
/**
* Browser-sync middleware configurations array.
* @type {Array}
*/
PROXY_MIDDLEWARE: any[] = [];
/**
* Configurations for NPM module configurations. Add to or override in project.config.ts.
* @type {any}
*/
PLUGIN_CONFIGS: any = {};
/**
* Generates the query string which should be appended to the end of the URLs in dev mode.
*/
QUERY_STRING_GENERATOR = () => {
return Date.now().toString();
}
/**
* Returns the array of injectable dependencies (the list of local files to be injected in the `index.html`).
* @return {InjectableDependency[]}
*/
private get _APP_ASSETS(): InjectableDependency[] {
return [
...this.APP_ASSETS,
{
src: `${this.CSS_SRC}/${this
.CSS_BUNDLE_NAME}.${this.getInjectableStyleExtension()}`,
inject: true,
vendor: false
}
];
}
/**
* Returns the configuration object for NPM module configurations.
*/
private get _PLUGIN_CONFIGS(): any {
/**
* The BrowserSync configuration of the application.
* The default open behavior is to open the browser. To prevent the browser from opening use the `--b` flag when
* running `npm start` (tested with serve.dev).
* Example: `npm start -- --b`
* @return {any}
*/
const defaults = {
'browser-sync': {
middleware: [
require('connect-history-api-fallback')({
index: `${this.APP_BASE}index.html`
}),
...this.PROXY_MIDDLEWARE
],
port: this.PORT,
startPath: this.APP_BASE,
open: argv['b'] ? false : true,
injectChanges: false,
server: {
baseDir: `${this.DIST_DIR}/empty/`,
routes: {
[`${this.APP_BASE}${this.APP_SRC}`]: this.APP_SRC,
[`${this.APP_BASE}${this.APP_DEST}`]: this.APP_DEST,
[`${this.APP_BASE}node_modules`]: 'node_modules',
[`${this.APP_BASE.replace(/\/$/, '')}`]: this.APP_DEST
}
}
},
// Note: you can customize the location of the file
'environment-config': join(this.PROJECT_ROOT, this.TOOLS_DIR, 'env'),
/**
* The options to pass to gulp-sass (and then to node-sass).
* Reference: https://github.com/sass/node-sass#options
* @type {object}
*/
'gulp-sass': {
includePaths: ['./node_modules/'],
importer: magicImporter()
},
/**
* The options to pass to gulp-concat-css
* Reference: https://github.com/mariocasciaro/gulp-concat-css
* @type {object}
*/
'gulp-concat-css': {
targetFile: `${this.CSS_BUNDLE_NAME}.css`,
options: {
rebaseUrls: false
}
}
};
this.mergeObject(defaults, this.PLUGIN_CONFIGS);
return defaults;
}
/**
* Karma reporter configuration
*/
getKarmaReporters(): any {
return {
preprocessors: {
'dist/**/!(*spec|index|*.module|*.routes).js': ['coverage']
},
reporters: ['mocha', 'coverage', 'karma-remap-istanbul'],
coverageReporter: {
dir: this.COVERAGE_DIR + '/',
reporters: [
{ type: 'json', subdir: '.', file: 'coverage-final.json' },
{ type: 'html', subdir: '.' }
]
},
remapIstanbulReporter: {
reports: {
html: this.COVERAGE_TS_DIR
}
}
};
}
/**
* Recursively merge source onto target.
* @param {any} target The target object (to receive values from source)
* @param {any} source The source object (to be merged onto target)
*/
mergeObject(target: any, source: any) {
const deepExtend = require('deep-extend');
deepExtend(target, source);
}
/**
* Locate a plugin configuration object by plugin key.
* @param {any} pluginKey The object key to look up in PLUGIN_CONFIGS.
*/
getPluginConfig(pluginKey: string): any {
if (this._PLUGIN_CONFIGS[pluginKey]) {
return this._PLUGIN_CONFIGS[pluginKey];
}
return null;
}
getInjectableStyleExtension() {
return this.BUILD_TYPE === BUILD_TYPES.PRODUCTION && this.ENABLE_SCSS
? 'scss'
: 'css';
}
addPackageBundles(pack: ExtendPackages) {
if (pack.path) {
this.SYSTEM_CONFIG_DEV.paths[pack.name] = pack.path;
this.SYSTEM_BUILDER_CONFIG.paths[pack.name] = pack.path;
}
if (pack.packageMeta) {
this.SYSTEM_CONFIG_DEV.packages[pack.name] = pack.packageMeta;
this.SYSTEM_BUILDER_CONFIG.packages[pack.name] = pack.packageMeta;
}
}
addPackagesBundles(packs: ExtendPackages[]) {
packs.forEach((pack: ExtendPackages) => {
this.addPackageBundles(pack);
});
}
/**
* Convert named rollup array to object
*/
getRollupNamedExports() {
let namedExports = {};
this.ROLLUP_NAMED_EXPORTS.map(namedExport => {
namedExports = Object.assign(namedExports, namedExport);
});
return namedExports;
}
}
/**
* Normalizes the given `deps` to skip globs.
* @param {InjectableDependency[]} deps - The dependencies to be normalized.
*/
export function normalizeDependencies(deps: InjectableDependency[]) {
deps
.filter((d: InjectableDependency) => !/\*/.test(d.src)) // Skip globs
.forEach((d: InjectableDependency) => (d.src = require.resolve(d.src)));
return deps;
}
/**
* Returns if the given dependency is used in the given environment.
* @param {string} env - The environment to be filtered for.
* @param {InjectableDependency} d - The dependency to check.
* @return {boolean} `true` if the dependency is used in this environment, `false` otherwise.
*/
function filterDependency(type: string, d: InjectableDependency): boolean {
const t = d.buildType || d.env;
d.buildType = t;
if (!t) {
d.buildType = Object.keys(BUILD_TYPES).map(k => BUILD_TYPES[k]);
}
if (!(d.buildType instanceof Array)) {
(<any>d).env = [d.buildType];
}
return d.buildType.indexOf(type) >= 0;
}
/**
* Returns the applications version as defined in the `package.json`.
* @return {number} The applications version.
*/
function appVersion(): number | string {
const pkg = require('../../package.json');
return pkg.version;
}
/**
* Returns the application build type.
*/
function getBuildType() {
const type = (argv['build-type'] || argv['env'] || '').toLowerCase();
const base: string[] = argv['_'];
const prodKeyword = !!base
.filter(o => o.indexOf(BUILD_TYPES.PRODUCTION) >= 0)
.pop();
if ((base && prodKeyword) || type === BUILD_TYPES.PRODUCTION) {
return BUILD_TYPES.PRODUCTION;
} else {
return BUILD_TYPES.DEVELOPMENT;
}
}
function getSmeOutFormat() {
const format = (argv['sme-out-format'] || '').toUpperCase();
return SME_OUTPUT_FORMATS[format] || SME_OUTPUT_FORMATS.HTML;
}