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

Side by Side Diff: lib/src/prism/gulpfile.js

Issue 1418513006: update elements and fix some bugs (Closed) Base URL: git@github.com:dart-lang/polymer_elements.git@master
Patch Set: code review updates Created 5 years, 1 month 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 | « lib/src/prism/components/prism-yaml.min.js ('k') | lib/src/prism/package.json » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 var gulp = require('gulp'), 1 var gulp = require('gulp'),
2 rename = require('gulp-rename'), 2 rename = require('gulp-rename'),
3 uglify = require('gulp-uglify'), 3 uglify = require('gulp-uglify'),
4 header = require('gulp-header'), 4 header = require('gulp-header'),
5 concat = require('gulp-concat'), 5 concat = require('gulp-concat'),
6 replace = require('gulp-replace'),
7 fs = require('fs'),
6 8
7 paths = { 9 paths = {
10 componentsFile: 'components.js',
8 components: ['components/**/*.js', '!components/**/*.min.js'], 11 components: ['components/**/*.js', '!components/**/*.min.js'],
9 main: [ 12 main: [
10 'components/prism-core.js', 13 'components/prism-core.js',
11 'components/prism-markup.js', 14 'components/prism-markup.js',
12 'components/prism-css.js', 15 'components/prism-css.js',
13 'components/prism-clike.js', 16 'components/prism-clike.js',
14 'components/prism-javascript.js', 17 'components/prism-javascript.js',
15 'plugins/file-highlight/prism-file-highlight.js' 18 'plugins/file-highlight/prism-file-highlight.js'
16 ], 19 ],
17 » » plugins: ['plugins/**/*.js', '!plugins/**/*.min.js'] 20 » » plugins: ['plugins/**/*.js', '!plugins/**/*.min.js'],
21 » » showLanguagePlugin: 'plugins/show-language/prism-show-language.j s',
22 » » autoloaderPlugin: 'plugins/autoloader/prism-autoloader.js'
18 }; 23 };
19 24
20 gulp.task('components', function() { 25 gulp.task('components', function() {
21 return gulp.src(paths.components) 26 return gulp.src(paths.components)
22 .pipe(uglify()) 27 .pipe(uglify())
23 .pipe(rename({ suffix: '.min' })) 28 .pipe(rename({ suffix: '.min' }))
24 .pipe(gulp.dest('components')); 29 .pipe(gulp.dest('components'));
25 }); 30 });
26 31
27 gulp.task('build', function() { 32 gulp.task('build', function() {
28 return gulp.src(paths.main) 33 return gulp.src(paths.main)
29 .pipe(header('\n/* ********************************************* *\n' + 34 .pipe(header('\n/* ********************************************* *\n' +
30 ' Begin <%= file.relative %>\n' + 35 ' Begin <%= file.relative %>\n' +
31 '********************************************** */\n\n') ) 36 '********************************************** */\n\n') )
32 .pipe(concat('prism.js')) 37 .pipe(concat('prism.js'))
33 .pipe(gulp.dest('./')); 38 .pipe(gulp.dest('./'));
34 }); 39 });
35 40
36 gulp.task('plugins', function() { 41 gulp.task('plugins', ['languages-plugins'], function() {
37 return gulp.src(paths.plugins) 42 return gulp.src(paths.plugins)
38 .pipe(uglify()) 43 .pipe(uglify())
39 .pipe(rename({ suffix: '.min' })) 44 .pipe(rename({ suffix: '.min' }))
40 .pipe(gulp.dest('plugins')); 45 .pipe(gulp.dest('plugins'));
41 }); 46 });
42 47
43 gulp.task('watch', function() { 48 gulp.task('watch', function() {
44 gulp.watch(paths.components, ['components', 'build']); 49 gulp.watch(paths.components, ['components', 'build']);
45 gulp.watch(paths.plugins, ['plugins', 'build']); 50 gulp.watch(paths.plugins, ['plugins', 'build']);
46 }); 51 });
47 52
53 gulp.task('languages-plugins', function (cb) {
54 fs.readFile(paths.componentsFile, {
55 encoding: 'utf-8'
56 }, function (err, data) {
57 if (!err) {
58 data = data.replace(/^var\s+components\s*=\s*|;\s*$/g, ' ');
59 try {
60 data = JSON.parse(data);
61
62 var languagesMap = {};
63 var dependenciesMap = {};
64 for (var p in data.languages) {
65 if (p !== 'meta') {
66 var title = data.languages[p].di splayTitle || data.languages[p].title;
67 var ucfirst = p.substring(0, 1). toUpperCase() + p.substring(1);
68 if (title !== ucfirst) {
69 languagesMap[p] = title;
70 }
71
72 if(data.languages[p].require) {
73 dependenciesMap[p] = dat a.languages[p].require;
74 }
75 }
76 }
77
78 var jsonLanguagesMap = JSON.stringify(languagesM ap);
79 var jsonDependenciesMap = JSON.stringify(depende nciesMap);
80
81 var tasks = [
82 {plugin: paths.showLanguagePlugin, map: jsonLanguagesMap},
83 {plugin: paths.autoloaderPlugin, map: js onDependenciesMap}
84 ];
85
86 var cpt = 0;
87 var l = tasks.length;
88 var done = function() {
89 cpt++;
90 if(cpt === l) {
91 cb && cb();
92 }
93 };
94
95 tasks.forEach(function(task) {
96 var stream = gulp.src(task.plugin)
97 .pipe(replace(
98 /\/\*languages_placehold er\[\*\/[\s\S]*?\/\*\]\*\//,
99 '/*languages_placeholder [*/' + task.map + '/*]*/'
100 ))
101 .pipe(gulp.dest(task.plugin.subs tring(0, task.plugin.lastIndexOf('/'))));
102
103 stream.on('error', done);
104 stream.on('end', done);
105 });
106
107 } catch (e) {
108 cb(e);
109 }
110 } else {
111 cb(err);
112 }
113 });
114 });
115
48 gulp.task('default', ['components', 'plugins', 'build']); 116 gulp.task('default', ['components', 'plugins', 'build']);
OLDNEW
« no previous file with comments | « lib/src/prism/components/prism-yaml.min.js ('k') | lib/src/prism/package.json » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698