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

Unified 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, 2 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 side-by-side diff with in-line comments
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 »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: lib/src/prism/gulpfile.js
diff --git a/lib/src/prism/gulpfile.js b/lib/src/prism/gulpfile.js
index 25de6e500dfa33f610a39aea3fe9917b03b6e13e..25757dba5c5b28462f3514ac02d4e45013330e34 100644
--- a/lib/src/prism/gulpfile.js
+++ b/lib/src/prism/gulpfile.js
@@ -3,8 +3,11 @@ var gulp = require('gulp'),
uglify = require('gulp-uglify'),
header = require('gulp-header'),
concat = require('gulp-concat'),
+ replace = require('gulp-replace'),
+ fs = require('fs'),
paths = {
+ componentsFile: 'components.js',
components: ['components/**/*.js', '!components/**/*.min.js'],
main: [
'components/prism-core.js',
@@ -14,7 +17,9 @@ var gulp = require('gulp'),
'components/prism-javascript.js',
'plugins/file-highlight/prism-file-highlight.js'
],
- plugins: ['plugins/**/*.js', '!plugins/**/*.min.js']
+ plugins: ['plugins/**/*.js', '!plugins/**/*.min.js'],
+ showLanguagePlugin: 'plugins/show-language/prism-show-language.js',
+ autoloaderPlugin: 'plugins/autoloader/prism-autoloader.js'
};
gulp.task('components', function() {
@@ -33,7 +38,7 @@ gulp.task('build', function() {
.pipe(gulp.dest('./'));
});
-gulp.task('plugins', function() {
+gulp.task('plugins', ['languages-plugins'], function() {
return gulp.src(paths.plugins)
.pipe(uglify())
.pipe(rename({ suffix: '.min' }))
@@ -45,4 +50,67 @@ gulp.task('watch', function() {
gulp.watch(paths.plugins, ['plugins', 'build']);
});
+gulp.task('languages-plugins', function (cb) {
+ fs.readFile(paths.componentsFile, {
+ encoding: 'utf-8'
+ }, function (err, data) {
+ if (!err) {
+ data = data.replace(/^var\s+components\s*=\s*|;\s*$/g, '');
+ try {
+ data = JSON.parse(data);
+
+ var languagesMap = {};
+ var dependenciesMap = {};
+ for (var p in data.languages) {
+ if (p !== 'meta') {
+ var title = data.languages[p].displayTitle || data.languages[p].title;
+ var ucfirst = p.substring(0, 1).toUpperCase() + p.substring(1);
+ if (title !== ucfirst) {
+ languagesMap[p] = title;
+ }
+
+ if(data.languages[p].require) {
+ dependenciesMap[p] = data.languages[p].require;
+ }
+ }
+ }
+
+ var jsonLanguagesMap = JSON.stringify(languagesMap);
+ var jsonDependenciesMap = JSON.stringify(dependenciesMap);
+
+ var tasks = [
+ {plugin: paths.showLanguagePlugin, map: jsonLanguagesMap},
+ {plugin: paths.autoloaderPlugin, map: jsonDependenciesMap}
+ ];
+
+ var cpt = 0;
+ var l = tasks.length;
+ var done = function() {
+ cpt++;
+ if(cpt === l) {
+ cb && cb();
+ }
+ };
+
+ tasks.forEach(function(task) {
+ var stream = gulp.src(task.plugin)
+ .pipe(replace(
+ /\/\*languages_placeholder\[\*\/[\s\S]*?\/\*\]\*\//,
+ '/*languages_placeholder[*/' + task.map + '/*]*/'
+ ))
+ .pipe(gulp.dest(task.plugin.substring(0, task.plugin.lastIndexOf('/'))));
+
+ stream.on('error', done);
+ stream.on('end', done);
+ });
+
+ } catch (e) {
+ cb(e);
+ }
+ } else {
+ cb(err);
+ }
+ });
+});
+
gulp.task('default', ['components', 'plugins', 'build']);
« 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