Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(12)

Side by Side Diff: third_party/polymer/v1_0/gendeps.js

Issue 1695663004: Adding GYP V2 targets for all Polymer code (with a script!). Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Adding JSDoc. Created 4 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « third_party/polymer/v1_0/components-chromium/paper-tooltip/compiled_resources2.gyp ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 var fs = require('fs');
2 var path = require('path');
3 var glob = require('glob').sync;
4
5 var chromiumHeader =
6 '# Copyright 2016 The Chromium Authors. All rights reserved.\n' +
7 '# Use of this source code is governed by a BSD-style license that can be\n' +
8 '# found in the LICENSE file.\n';
9 var ignoreFiles = new Set(['index']);
10
11 /**
12 * Generates a compiled_resources2.gyp file for all elements defined under the
13 * given folder.
14 * @param {string} folder
15 */
16 function processFolder(folder) {
17 var htmlFiles = glob(folder + '/**/*.html').filter(function(file) {
18 return !ignoreFiles.has(path.basename(file, '.html'));
19 });
20 var targets = htmlFiles.map(function(file) {
21 return createTarget(file, detectDependencies(file));
22 });
23 var compiledResourcesContents = chromiumHeader +
24 JSON.stringify({targets: targets}, undefined, 2).replace(/"/g, '\'');
25 fs.writeFileSync(
26 path.join(folder, 'compiled_resources2.gyp'),
27 compiledResourcesContents);
28 }
29
30 /**
31 * Detects the dependencies of the given HTML file.
32 * @param {string} file
33 * @return {!Array<string>}
34 */
35 function detectDependencies(file) {
36 var fileContents = fs.readFileSync(file, {encoding: 'utf8'});
37 var regexp = /^<link rel="import" href="(.*)"/;
38 var lines = fileContents.split('\n');
39 var dependencies = [];
40 lines.forEach(function(line) {
41 var results = regexp.exec(line);
42 if (results && results[1].indexOf('/polymer.html') == -1) {
43 dependencies.push(results[1]);
44 }
45 });
46 return dependencies;
47 }
48
49 /**
50 * Converts a file name to a GYP target name.
51 * @param {string} file
52 * @return {string}
53 */
54 function fileToTarget(file) {
55 return path.basename(file, '.html') + '-extracted';
56 }
57
58
59 /**
60 * Creates a GYP target for the given file.
61 * @param {string} file
62 * @param {!Array<string>} fileDependencies
63 * @return {{target_name: string, dependencies: !Array<string>, includes: string }}
64 */
65 function createTarget(file, fileDependencies) {
66 var gypDependencies = fileDependencies.map(function(dep) {
67 var parts = dep.split(path.sep);
68 if (parts.length == 1) {
69 return fileToTarget(parts[0]);
70 }
71 return path.join(parts[0], parts[1], 'compiled_resources2.gyp:') +
72 fileToTarget(parts[parts.length -1]);
73 });
74 var obj = {
75 target_name: fileToTarget(file),
76 };
77 if (gypDependencies.length > 0) {
78 obj.dependencies = gypDependencies;
79 }
80 obj.includes = ['../../../../closure_compiler/compile_js2.gypi'];
81 return obj;
82 }
83
84 var ignoreFolders = new Set(['polymer', 'polymer-externs']);
85 var srcDir = path.resolve(path.join(__dirname, 'components-chromium'));
86
87 fs.readdirSync(srcDir).filter(function(folder) {
88 return !ignoreFolders.has(folder);
89 }).map(function(folder) {
90 return path.join(srcDir, folder);
91 }).forEach(processFolder);
OLDNEW
« no previous file with comments | « third_party/polymer/v1_0/components-chromium/paper-tooltip/compiled_resources2.gyp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698