summaryrefslogtreecommitdiffstats
path: root/testing/web-platform/tests/css/css-writing-modes/tools/generators/gulpfile.js
blob: f364024084dc0c24d00bc417ab252feb9f8b1418 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
'use strict';

var browserSync = null;
var gulp = require("gulp");
var ejs = require("gulp-ejs");
var rename = require("gulp-rename");
var minimist = require('minimist');
var argv = minimist(process.argv.slice(2));

gulp.task("default", [
  "orthogonal-parent-shrink-to-fit",
]);

gulp.task("test", ["browser-sync", "watch"]);

gulp.task("watch", function () {
  gulp.watch("orthogonal-parent-shrink-to-fit.ejs", ["orthogonal-parent-shrink-to-fit"]);
});

gulp.task("browser-sync", function () {
  if (!browserSync)
    browserSync = require("browser-sync");
  browserSync({
    server: {
      baseDir: "../../..",
      directory: true,
    },
    startPath: "css-writing-modes-3/",
  });
});

function reload() {
  if (browserSync)
    browserSync.reload();
}

gulp.task("server", function () {
  var connect = require("connect");
  var serveIndex = require("serve-index");
  var serveStatic = require("serve-static");
  var directory = "../../..";
  var port = 8000;
  connect()
    .use(serveIndex(directory))
    .use(serveStatic(directory))
    .listen(port);
  console.log("Listening on port " + port);
})

gulpTaskFromTemplateWithAffixes("orthogonal-parent-shrink-to-fit", "-001", -1, 24);

gulp.task("update", function () {
  const unicodeData = require('./unicode-data.js');
  unicodeData.copyToLocal();
});

function gulpTaskFromTemplateWithAffixes(name, suffix, min, lim) {
  if (argv.nocombo && min < 0)
    min = 0;
  if (argv.nochild && lim > 0)
    lim = 0;
  gulp.task(name, function () {
    for (var i = min; i < lim; ++i) {
      gulp.src(name + ".ejs")
        .pipe(ejs({ index: i }))
        .pipe(rename(name + suffix + affixFromIndex(i) + ".html"))
        .pipe(gulp.dest("../.."));
    }
    reload();
  });
}

function affixFromIndex(index) {
  if (index < 0)
    return "";
  if (index >= 26)
    throw new Error("Affix index too large (" + index + ")");
  return String.fromCharCode("a".charCodeAt(0) + index);
}