-
Notifications
You must be signed in to change notification settings - Fork 295
/
options.di.ts
37 lines (30 loc) · 1.12 KB
/
options.di.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
import findCacheDirectory from 'find-cache-dir';
import { InjectionToken, Provider, ValueProvider } from 'injection-js';
import { tmpdir } from 'os';
import { resolve } from 'path';
export const OPTIONS_TOKEN = new InjectionToken<NgPackagrOptions>(`ng.v5.options`);
export interface NgPackagrOptions {
/** Whether or not ng-packagr will watch for file changes and perform an incremental build. */
watch?: boolean;
cacheEnabled?: boolean;
cacheDirectory?: string;
}
export const provideOptions = (options: NgPackagrOptions = {}): ValueProvider => ({
provide: OPTIONS_TOKEN,
useValue: normalizeOptions(options),
});
export const DEFAULT_OPTIONS_PROVIDER: Provider = provideOptions();
function normalizeOptions(options: NgPackagrOptions = {}) {
const ciEnv = process.env['CI'];
const isCI = ciEnv?.toLowerCase() === 'true' || ciEnv === '1';
const { cacheEnabled = !isCI, cacheDirectory = findCachePath() } = options;
return {
...options,
cacheEnabled,
cacheDirectory,
};
}
function findCachePath(): string {
const name = 'ng-packagr';
return findCacheDirectory({ name }) || resolve(tmpdir(), name);
}