~didrocks/+junk/face-detection-15.04

« back to all changes in this revision

Viewing changes to facedetection/www/bower_components/prism/gulpfile.js

  • Committer: Didier Roche
  • Date: 2016-05-10 23:09:11 UTC
  • Revision ID: didier.roche@canonical.com-20160510230911-c7xr490zrj3yrzxd
New version

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
var gulp   = require('gulp'),
 
2
        rename = require('gulp-rename'),
 
3
        uglify = require('gulp-uglify'),
 
4
        header = require('gulp-header'),
 
5
        concat = require('gulp-concat'),
 
6
        replace = require('gulp-replace'),
 
7
        fs = require('fs'),
 
8
 
 
9
        paths  = {
 
10
                componentsFile: 'components.js',
 
11
                components: ['components/**/*.js', '!components/**/*.min.js'],
 
12
                main: [
 
13
                        'components/prism-core.js',
 
14
                        'components/prism-markup.js',
 
15
                        'components/prism-css.js',
 
16
                        'components/prism-clike.js',
 
17
                        'components/prism-javascript.js',
 
18
                        'plugins/file-highlight/prism-file-highlight.js'
 
19
                ],
 
20
                plugins: ['plugins/**/*.js', '!plugins/**/*.min.js'],
 
21
                showLanguagePlugin: 'plugins/show-language/prism-show-language.js',
 
22
                autoloaderPlugin: 'plugins/autoloader/prism-autoloader.js',
 
23
                changelog: 'CHANGELOG.md'
 
24
        };
 
25
 
 
26
gulp.task('components', function() {
 
27
        return gulp.src(paths.components)
 
28
                .pipe(uglify())
 
29
                .pipe(rename({ suffix: '.min' }))
 
30
                .pipe(gulp.dest('components'));
 
31
});
 
32
 
 
33
gulp.task('build', function() {
 
34
        return gulp.src(paths.main)
 
35
                .pipe(header('\n/* **********************************************\n' +
 
36
                        '     Begin <%= file.relative %>\n' +
 
37
                        '********************************************** */\n\n'))
 
38
                .pipe(concat('prism.js'))
 
39
                .pipe(gulp.dest('./'));
 
40
});
 
41
 
 
42
gulp.task('plugins', ['languages-plugins'], function() {
 
43
        return gulp.src(paths.plugins)
 
44
                .pipe(uglify())
 
45
                .pipe(rename({ suffix: '.min' }))
 
46
                .pipe(gulp.dest('plugins'));
 
47
});
 
48
 
 
49
gulp.task('watch', function() {
 
50
        gulp.watch(paths.components, ['components', 'build']);
 
51
        gulp.watch(paths.plugins, ['plugins', 'build']);
 
52
});
 
53
 
 
54
gulp.task('languages-plugins', function (cb) {
 
55
        fs.readFile(paths.componentsFile, {
 
56
                encoding: 'utf-8'
 
57
        }, function (err, data) {
 
58
                if (!err) {
 
59
                        data = data.replace(/^var\s+components\s*=\s*|;\s*$/g, '');
 
60
                        try {
 
61
                                data = JSON.parse(data);
 
62
 
 
63
                                var languagesMap = {};
 
64
                                var dependenciesMap = {};
 
65
                                for (var p in data.languages) {
 
66
                                        if (p !== 'meta') {
 
67
                                                var title = data.languages[p].displayTitle || data.languages[p].title;
 
68
                                                var ucfirst = p.substring(0, 1).toUpperCase() + p.substring(1);
 
69
                                                if (title !== ucfirst) {
 
70
                                                        languagesMap[p] = title;
 
71
                                                }
 
72
 
 
73
                                                if(data.languages[p].require) {
 
74
                                                        dependenciesMap[p] = data.languages[p].require;
 
75
                                                }
 
76
                                        }
 
77
                                }
 
78
 
 
79
                                var jsonLanguagesMap = JSON.stringify(languagesMap);
 
80
                                var jsonDependenciesMap = JSON.stringify(dependenciesMap);
 
81
 
 
82
                                var tasks = [
 
83
                                        {plugin: paths.showLanguagePlugin, map: jsonLanguagesMap},
 
84
                                        {plugin: paths.autoloaderPlugin, map: jsonDependenciesMap}
 
85
                                ];
 
86
 
 
87
                                var cpt = 0;
 
88
                                var l = tasks.length;
 
89
                                var done = function() {
 
90
                                        cpt++;
 
91
                                        if(cpt === l) {
 
92
                                                cb && cb();
 
93
                                        }
 
94
                                };
 
95
 
 
96
                                tasks.forEach(function(task) {
 
97
                                        var stream = gulp.src(task.plugin)
 
98
                                                .pipe(replace(
 
99
                                                        /\/\*languages_placeholder\[\*\/[\s\S]*?\/\*\]\*\//,
 
100
                                                        '/*languages_placeholder[*/' + task.map + '/*]*/'
 
101
                                                ))
 
102
                                                .pipe(gulp.dest(task.plugin.substring(0, task.plugin.lastIndexOf('/'))));
 
103
 
 
104
                                        stream.on('error', done);
 
105
                                        stream.on('end', done);
 
106
                                });
 
107
 
 
108
                        } catch (e) {
 
109
                                cb(e);
 
110
                        }
 
111
                } else {
 
112
                        cb(err);
 
113
                }
 
114
        });
 
115
});
 
116
 
 
117
gulp.task('changelog', function (cb) {
 
118
        return gulp.src(paths.changelog)
 
119
                .pipe(replace(
 
120
                        /#(\d+)(?![\d\]])/g,
 
121
                        '[#$1](https://github.com/PrismJS/prism/issues/$1)'
 
122
                ))
 
123
                .pipe(replace(
 
124
                        /\[[\da-f]+(?:, *[\da-f]+)*\]/g,
 
125
                        function (match) {
 
126
                                return match.replace(/([\da-f]{7})[\da-f]*/g, '[`$1`](https://github.com/PrismJS/prism/commit/$1)');
 
127
                        }
 
128
                ))
 
129
                .pipe(gulp.dest('.'));
 
130
});
 
131
 
 
132
gulp.task('default', ['components', 'plugins', 'build']);