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

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: 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 ignoreFolders = new Set(['polymer', 'polymer-externs']);
6 var srcDir = path.resolve(path.join(__dirname, 'components-chromium'));
7
8 var folders = fs.readdirSync(srcDir).filter(function(folder) {
9 return !ignoreFolders.has(folder);
10 }).map(function(folder) {
11 return path.join(srcDir, folder);
12 });
13
14 var chromiumHeader =
15 '# Copyright 2016 The Chromium Authors. All rights reserved.\n' +
16 '# Use of this source code is governed by a BSD-style license that can be\n' +
17 '# found in the LICENSE file.\n';
18
19 var ignoreFiles = new Set(['index']);
20 function processFolder(folder) {
21
22 var htmlFiles = glob(folder + '/**/*.html').filter(function(file) {
23 return !ignoreFiles.has(path.basename(file, '.html'));
24 });
25 var targets = htmlFiles.map(function(file) {
26 return createTarget(file, detectDependencies(file));
27 });
28 //console.log(
29 // JSON.stringify({targets: targets}, undefined, 2));
30 var compiledResourcesContents = chromiumHeader +
31 JSON.stringify({targets: targets}, undefined, 2).replace(/"/g, '\'');
32 fs.writeFileSync(
33 path.join(folder, 'compiled_resources2.gyp'),
34 compiledResourcesContents);
35 }
36
37 function detectDependencies(file) {
38 var fileContents = fs.readFileSync(file, {encoding: 'utf8'});
39 var regexp = /^<link rel="import" href="(.*)"/;
Dan Beam 2016/02/16 07:01:08 BeautifulSoup is a better candidate for this, IMO:
40 var lines = fileContents.split('\n');
41 var dependencies = [];
42 lines.forEach(function(line) {
43 var results = regexp.exec(line);
44 if (results && results[1].indexOf('/polymer.html') == -1) {
45 dependencies.push(results[1]);
46 }
47 });
48 return dependencies;
49 }
50
51
52 folders.forEach(processFolder);
53
54 function fileToTarget(file) {
55 return path.basename(file, '.html') + '-extracted';
56 }
57
58 function createTarget(file, fileDependencies) {
59 var gypDependencies = fileDependencies.map(function(dep) {
60 var parts = dep.split(path.sep);
61 if (parts.length == 1) {
62 return fileToTarget(parts[0]);
63 }
64 return path.join(parts[0], parts[1], 'compiled_resources2.gyp:') +
65 fileToTarget(parts[parts.length -1]);
66 });
67 var obj = {
68 target_name: fileToTarget(file),
69 };
70 if (gypDependencies.length > 0) {
71 obj.dependencies = gypDependencies;
72 }
73 obj.includes = ['../../../../closure_compiler/compile_js2.gypi'];
74 return obj;
75 }
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