1 | ;
|
2 | /**
|
3 | * @license
|
4 | * Copyright (c) 2016 The Polymer Project Authors. All rights reserved.
|
5 | * This code may only be used under the BSD style license found at
|
6 | * http://polymer.github.io/LICENSE.txt
|
7 | * The complete set of authors may be found at
|
8 | * http://polymer.github.io/AUTHORS.txt
|
9 | * The complete set of contributors may be found at
|
10 | * http://polymer.github.io/CONTRIBUTORS.txt
|
11 | * Code distributed by Google as part of the polymer project is also
|
12 | * subject to an additional IP rights grant found at
|
13 | * http://polymer.github.io/PATENTS.txt
|
14 | */
|
15 | Object.defineProperty(exports, "__esModule", { value: true });
|
16 | const logging = require("plylog");
|
17 | const polymer_project_config_1 = require("polymer-project-config");
|
18 | const vinyl_fs_1 = require("vinyl-fs");
|
19 | const analyzer_1 = require("./analyzer");
|
20 | const base_tag_updater_1 = require("./base-tag-updater");
|
21 | const bundle_1 = require("./bundle");
|
22 | const custom_elements_es5_adapter_1 = require("./custom-elements-es5-adapter");
|
23 | const inject_babel_helpers_1 = require("./inject-babel-helpers");
|
24 | const prefetch_links_1 = require("./prefetch-links");
|
25 | const push_manifest_1 = require("./push-manifest");
|
26 | const logger = logging.getLogger('polymer-project');
|
27 | class PolymerProject {
|
28 | constructor(config) {
|
29 | if (config.constructor.name === 'ProjectConfig') {
|
30 | this.config = config;
|
31 | }
|
32 | else if (typeof config === 'string') {
|
33 | const maybeConfig = polymer_project_config_1.ProjectConfig.loadConfigFromFile(config);
|
34 | if (maybeConfig == null) {
|
35 | throw new Error(`Unable to load config from file: ${config}`);
|
36 | }
|
37 | this.config = maybeConfig;
|
38 | }
|
39 | else {
|
40 | this.config = new polymer_project_config_1.ProjectConfig(config);
|
41 | }
|
42 | logger.debug(`build config loaded:`, this.config);
|
43 | this.analyzer = new analyzer_1.BuildAnalyzer(this.config);
|
44 | }
|
45 | /**
|
46 | * Returns a `Transform` stream that modifies the files that pass through it
|
47 | * based on the dependency analysis done by the `analyzer` transform. It
|
48 | * "bundles" a project by injecting its dependencies into the application
|
49 | * fragments themselves, so that a minimum number of requests need to be made
|
50 | * to load.
|
51 | *
|
52 | * (NOTE: The analyzer stream must be in the pipeline somewhere before this.)
|
53 | */
|
54 | bundler(options) {
|
55 | return new bundle_1.BuildBundler(this.config, this.analyzer, options);
|
56 | }
|
57 | /**
|
58 | * Returns the analyzer's stream of this project's source files - files
|
59 | * matched by the project's `config.sources` value.
|
60 | */
|
61 | sources() {
|
62 | return this.analyzer.sources();
|
63 | }
|
64 | /**
|
65 | * Returns the analyzer's stream of this project's dependency files - files
|
66 | * loaded inside the analyzed project that are not considered source files.
|
67 | */
|
68 | dependencies() {
|
69 | let dependenciesStream = this.analyzer.dependencies();
|
70 | // If we need to include additional dependencies, create a new vinyl
|
71 | // source stream and pipe our default dependencyStream through it to
|
72 | // combine.
|
73 | if (this.config.extraDependencies.length > 0) {
|
74 | const includeStream = vinyl_fs_1.src(this.config.extraDependencies, {
|
75 | cwdbase: true,
|
76 | nodir: true,
|
77 | passthrough: true,
|
78 | });
|
79 | dependenciesStream = dependenciesStream.pipe(includeStream);
|
80 | }
|
81 | return dependenciesStream;
|
82 | }
|
83 | /**
|
84 | * Returns a stream transformer that injects 'prefetch' link tags into HTML
|
85 | * documents based on the transitive dependencies of the document.
|
86 | * For entrypoint documents without `<base>` tag, absolute urls are used in
|
87 | * prefetch link hrefs. In all other cases, link hrefs will be relative urls.
|
88 | */
|
89 | addPrefetchLinks() {
|
90 | return new prefetch_links_1.AddPrefetchLinks(this.config);
|
91 | }
|
92 | /**
|
93 | * Returns a stream transformer that adds a push manifest file to the set
|
94 | * of all input files that pass through.
|
95 | */
|
96 | addPushManifest(outPath, basePath) {
|
97 | return new push_manifest_1.AddPushManifest(this.config, outPath, basePath);
|
98 | }
|
99 | /**
|
100 | * Returns a stream transformer that injects `custom-elements-es5-adapter.js`
|
101 | * into the entry point HTML file. This adapter is needed when serving ES5
|
102 | * to browsers that support the native Custom Elements API.
|
103 | */
|
104 | addCustomElementsEs5Adapter() {
|
105 | return new custom_elements_es5_adapter_1.CustomElementsEs5AdapterInjector();
|
106 | }
|
107 | addBabelHelpersInEntrypoint(entrypoint = this.config.entrypoint) {
|
108 | return new inject_babel_helpers_1.BabelHelpersInjector(entrypoint);
|
109 | }
|
110 | /**
|
111 | * Return a stream transformer that updates the `<base>` tag of the project's
|
112 | * entrypoint HTML file with the given new value. No change is made if a
|
113 | * `<base>` tag does not already exist.
|
114 | */
|
115 | updateBaseTag(baseHref) {
|
116 | return new base_tag_updater_1.BaseTagUpdater(this.config.entrypoint, baseHref);
|
117 | }
|
118 | }
|
119 | exports.PolymerProject = PolymerProject;
|
120 | //# sourceMappingURL=polymer-project.js.map |
\ | No newline at end of file |