-
Notifications
You must be signed in to change notification settings - Fork 0
/
common_info_builder.js
135 lines (127 loc) · 6.05 KB
/
common_info_builder.js
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
// eslint-disable-next-line no-unused-vars
import AbstractExternalPackage from "./abstract_external_package"
import CommonInfo from "./common_info"
import ImportedExternalPackage from "./external_package/imported_external_package"
import LinkedExternalPackage from "./external_package/linked_external_package"
import NamedSourceFile from "./source_file/named_source_file"
import RebundledExternalPackage from "./external_package/rebundled_external_package"
import RelativePathPairBuilder from "./source_file/relative_path_pair_builder"
import SourceDirectory from "./source_file/source_directory"
import UnnamedSourceFile from "./source_file/unnamed_source_file"
/**
* Represents a builder which contains common information for configurations that will be created.
*/
export default class CommonInfoBuilder {
/**
* Creates the builder.
* @param {string} inputDirectory Directory of source files.
* @param {string} outputDirectory Directory of bundled files.
* @param {string} outputFormat Output format for bundled files.
*/
constructor(inputDirectory, outputDirectory, outputFormat) {
this._commonInfo = new CommonInfo(inputDirectory, outputDirectory, outputFormat)
}
/**
* Creates a representation of named source file.
* @param {string} name Name of the bundle.
* @param {string} file The path of the source file to be bundled relative to the
* `inputDirectory` of this class.
* @param {any[]} plugins Plugins that will be used to bundle the source file.
* @param {AbstractExternalPackage[]} [externals=[]] Optional. Array of external packages that
* will not be included in the bundle.
* @returns {NamedSourceFile} A representation of named source file.
*/
configureNamedSource(name, file, plugins, externals = []) {
return new NamedSourceFile(this._commonInfo, name, file, plugins, externals)
}
/**
* Creates a representation of unnamed source file.
* @param {string} file The path of the source file to be bundled relative to the
* `inputDirectory` of this class.
* @param {any[]} plugins Plugins that will be used to bundle the source file.
* @param {AbstractExternalPackage[]} [externals=[]] Optional. Array of external packages that
* will not be included in the bundle.
* @returns {UnnamedSourceFile} A representation of unnamed source files.
*/
configureUnnamedSource(file, plugins, externals = []) {
return new UnnamedSourceFile(this._commonInfo, file, plugins, externals)
}
/**
* Creates a representation of source directory.
* @param {any[]|((RelativePathPair) => any[])} plugins Common plugins to be applied to the
* source files found in the input directory
* or a function that recieves a path pair
* and outputs an array of plugins.
* @param {AbstractExternalPackage[]} [externals=[]] Optional. Array of common external packages
* that will not be included in the configuration of each
* source file.
* @param {RelativePathPairBuilder} pathPairBuilder Builder instance to create relative paths.
* @returns {SourceDirectory} A representation of source directory.
*/
configureSourceDirectory(
plugins,
externals = [],
pathPairBuilder = new RelativePathPairBuilder()
) {
return new SourceDirectory(this._commonInfo, plugins, externals, pathPairBuilder)
}
/**
* Creates a representation of imported external package.
* @param {string} externalName The name of the imported external package.
* @param {string} globalName The global variable that identifies the imported external package.
* @param {string} file The path of the source file which imports the external package.
* @param {any[]} plugins Plugins that will be used to bundle the external package.
* @param {AbstractExternalPackage[]} [externals=[]] Optional. Array of external packages that
* will not be included in the bundle.
* @returns {ImportedExternalPackage} A representation of imported external package.
*/
importExternalPackage(externalName, globalName, file, plugins, externals = []) {
return new ImportedExternalPackage(
this._commonInfo,
externalName,
globalName,
file,
plugins,
externals
)
}
/**
* Creates a representation of linked external package.
* @param {string} externalName The name of the external package linked by CDN or others.
* @param {string} globalName The global variable that identifies the linked external package.
* @returns {LinkedExternalPackage} A representation of linked external package.
*/
linkExternalPackage(externalName, globalName) {
return new LinkedExternalPackage(externalName, globalName)
}
/**
* Creates a representation of rebundled external packages.
* @param {string} globalName The global identifier representing the rebundled external packages.
* @param {Object} subglobals Pairs of external name (key) and global variable (value) of
* external packages.
* @param {string} file The path of the source file which imports the external packages to be
* rebundled.
* @param {any[]} plugins Plugins that will be used to rebundle the external packages.
* @param {AbstractExternalPackage[]} [externals=[]] Optional. Array of external packages that
* will not be included in the rebundling process.
* @returns {RebundledExternalPackage} A representation of imported external package.
*/
rebundleExternalPackages(globalName, subglobals, file, plugins, externals = []) {
return new RebundledExternalPackage(
this._commonInfo,
globalName,
subglobals,
file,
plugins,
externals
)
}
/**
* Get the common information that used to create other configurations and link external
* packages.
* @returns {CommonInfo} The common info used to pass to other classes.
*/
get commonInfo() {
return this._commonInfo
}
}