/
output-utils.ts
164 lines (123 loc) · 6.65 KB
/
output-utils.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
import * as d from '../../declarations';
import { basename, dirname, join, relative } from 'path';
import { flatOne, normalizePath, sortBy } from '@utils';
export const relativeImport = (pathFrom: string, pathTo: string, ext?: string, addPrefix = true) => {
let relativePath = relative(dirname(pathFrom), dirname(pathTo));
if (addPrefix) {
if (relativePath === '') {
relativePath = '.';
} else if (relativePath[0] !== '.') {
relativePath = './' + relativePath;
}
}
return normalizePath(`${relativePath}/${basename(pathTo, ext)}`);
};
export const getDistEsmDir = (outputTarget: d.OutputTargetDist, sourceTarget?: d.SourceTarget) => join(outputTarget.buildDir, 'esm', sourceTarget || '');
export const getDistEsmComponentsDir = (outputTarget: d.OutputTargetDist, sourceTarget: d.SourceTarget) => join(getDistEsmDir(outputTarget, sourceTarget), 'build');
export const getDistEsmIndexPath = (outputTarget: d.OutputTargetDist, sourceTarget?: d.SourceTarget) => join(getDistEsmDir(outputTarget, sourceTarget), 'index.js');
export const getDefineCustomElementsPath = (config: d.Config, outputTarget: d.OutputTargetDist, sourceTarget: d.SourceTarget) =>
join(getDistEsmDir(outputTarget, sourceTarget), getDefineEsmFilename(config));
export const getComponentsEsmBuildPath = (config: d.Config, outputTarget: d.OutputTargetDist, sourceTarget: d.SourceTarget) =>
join(getDistEsmDir(outputTarget, sourceTarget), getComponentsEsmFileName(config));
export const getCoreEsmFileName = (config: d.Config) => `${config.fsNamespace}.core.js`;
export const getDefineEsmFilename = (config: d.Config) => `${config.fsNamespace}.define.js`;
export const getComponentsEsmFileName = (config: d.Config) => `${config.fsNamespace}.components.js`;
export const getLoaderEsmPath = (outputTarget: d.OutputTargetDist) => join(outputTarget.buildDir, outputTarget.esmLoaderPath);
export const getComponentsDtsSrcFilePath = (config: d.Config) => join(config.srcDir, GENERATED_DTS);
export const getComponentsDtsTypesFilePath = (outputTarget: d.OutputTargetDist | d.OutputTargetDistTypes) => join(outputTarget.typesDir, GENERATED_DTS);
export const isOutputTargetDist = (o: d.OutputTarget): o is d.OutputTargetDist => o.type === DIST;
export const isOutputTargetDistCollection = (o: d.OutputTarget): o is d.OutputTargetDistCollection => o.type === DIST_COLLECTION;
export const isOutputTargetDistCustomElements = (o: d.OutputTarget): o is d.OutputTargetDistCustomElements => o.type === DIST_CUSTOM_ELEMENTS;
export const isOutputTargetDistCustomElementsBundle = (o: d.OutputTarget): o is d.OutputTargetDistCustomElementsBundle =>
o.type === DIST_CUSTOM_ELEMENTS_BUNDLE || o.type === EXPERIMENTAL_DIST_MODULE;
export const isOutputTargetCopy = (o: d.OutputTarget): o is d.OutputTargetCopy => o.type === COPY;
export const isOutputTargetDistLazy = (o: d.OutputTarget): o is d.OutputTargetDistLazy => o.type === DIST_LAZY;
export const isOutputTargetAngular = (o: d.OutputTarget): o is d.OutputTargetAngular => o.type === ANGULAR;
export const isOutputTargetDistLazyLoader = (o: d.OutputTarget): o is d.OutputTargetDistLazyLoader => o.type === DIST_LAZY_LOADER;
export const isOutputTargetDistGlobalStyles = (o: d.OutputTarget): o is d.OutputTargetDistGlobalStyles => o.type === DIST_GLOBAL_STYLES;
export const isOutputTargetDistSelfContained = (o: d.OutputTarget): o is d.OutputTargetDistSelfContained => o.type === DIST_SELF_CONTAINED;
export const isOutputTargetHydrate = (o: d.OutputTarget): o is d.OutputTargetHydrate => o.type === DIST_HYDRATE_SCRIPT;
export const isOutputTargetCustom = (o: d.OutputTarget): o is d.OutputTargetCustom => o.type === CUSTOM;
export const isOutputTargetDocs = (o: d.OutputTarget): o is d.OutputTargetDocsJson | d.OutputTargetDocsReadme | d.OutputTargetDocsVscode | d.OutputTargetDocsCustom =>
o.type === DOCS_README || o.type === DOCS_JSON || o.type === DOCS_CUSTOM || o.type === DOCS_VSCODE;
export const isOutputTargetDocsReadme = (o: d.OutputTarget): o is d.OutputTargetDocsReadme => o.type === DOCS_README;
export const isOutputTargetDocsJson = (o: d.OutputTarget): o is d.OutputTargetDocsJson => o.type === DOCS_JSON;
export const isOutputTargetDocsCustom = (o: d.OutputTarget): o is d.OutputTargetDocsCustom => o.type === DOCS_CUSTOM;
export const isOutputTargetDocsVscode = (o: d.OutputTarget): o is d.OutputTargetDocsVscode => o.type === DOCS_VSCODE;
export const isOutputTargetWww = (o: d.OutputTarget): o is d.OutputTargetWww => o.type === WWW;
export const isOutputTargetStats = (o: d.OutputTarget): o is d.OutputTargetStats => o.type === STATS;
export const isOutputTargetDistTypes = (o: d.OutputTarget): o is d.OutputTargetDistTypes => o.type === DIST_TYPES;
export const getComponentsFromModules = (moduleFiles: d.Module[]) => sortBy(flatOne(moduleFiles.map(m => m.cmps)), (c: d.ComponentCompilerMeta) => c.tagName);
export const canSkipOutputTargets = (buildCtx: d.BuildCtx) => {
if (buildCtx.components.length === 0) {
return true;
}
if (buildCtx.requiresFullBuild) {
return false;
}
if (buildCtx.isRebuild && (buildCtx.hasScriptChanges || buildCtx.hasStyleChanges || buildCtx.hasHtmlChanges)) {
return false;
}
return true;
};
export const ANGULAR = `angular`;
export const COPY = 'copy';
export const CUSTOM = `custom`;
export const DIST = `dist`;
export const DIST_COLLECTION = `dist-collection`;
export const DIST_CUSTOM_ELEMENTS = `dist-custom-elements`;
export const DIST_CUSTOM_ELEMENTS_BUNDLE = `dist-custom-elements-bundle`;
export const EXPERIMENTAL_DIST_MODULE = `experimental-dist-module`;
export const DIST_TYPES = `dist-types`;
export const DIST_HYDRATE_SCRIPT = `dist-hydrate-script`;
export const DIST_LAZY = `dist-lazy`;
export const DIST_LAZY_LOADER = `dist-lazy-loader`;
export const DIST_SELF_CONTAINED = `dist-self-contained`;
export const DIST_GLOBAL_STYLES = 'dist-global-styles';
export const DOCS_CUSTOM = 'docs-custom';
export const DOCS_JSON = `docs-json`;
export const DOCS_README = `docs-readme`;
export const DOCS_VSCODE = `docs-vscode`;
export const STATS = `stats`;
export const WWW = `www`;
export const VALID_TYPES = [
ANGULAR,
COPY,
CUSTOM,
DIST,
DIST_COLLECTION,
DIST_CUSTOM_ELEMENTS,
EXPERIMENTAL_DIST_MODULE,
DIST_GLOBAL_STYLES,
DIST_HYDRATE_SCRIPT,
DIST_LAZY,
DIST_SELF_CONTAINED,
DOCS_JSON,
DOCS_README,
DOCS_VSCODE,
DOCS_CUSTOM,
STATS,
WWW,
];
export const VALID_TYPES_NEXT = [
// DIST
WWW,
DIST,
DIST_COLLECTION,
// DIST_CUSTOM_ELEMENTS,
DIST_CUSTOM_ELEMENTS_BUNDLE,
EXPERIMENTAL_DIST_MODULE,
DIST_LAZY,
DIST_HYDRATE_SCRIPT,
// DOCS
DOCS_JSON,
DOCS_README,
DOCS_VSCODE,
DOCS_CUSTOM,
// MISC
ANGULAR,
COPY,
CUSTOM,
STATS,
];
export const GENERATED_DTS = 'components.d.ts';