Skip to content

Commit

Permalink
Updates to latest i18next version (^3.1.0) and adds unit test.
Browse files Browse the repository at this point in the history
  • Loading branch information
grizio committed May 27, 2016
1 parent fc25dcc commit 2443e35
Show file tree
Hide file tree
Showing 9 changed files with 626 additions and 106 deletions.
9 changes: 6 additions & 3 deletions bower.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "kwc-i18next",
"version": "0.1.1",
"version": "0.1.3",
"description": "A web component used to manage internationalization – replaces kwc-i18n",
"license": "MIT",
"main": "kwc-i18next.html",
Expand All @@ -19,10 +19,13 @@
],
"dependencies": {
"polymer": "Polymer/polymer#^1.0.0",
"i18next": "^2.5.1"
"i18next": "^3.1.0"
},
"homepage": "https://github.com/successk/kwc-i18next",
"authors": [
"Gaëtan Rizio <[email protected]>"
]
],
"devDependencies": {
"i18next-xhr-backend": "^0.5.4"
}
}
231 changes: 129 additions & 102 deletions gulpfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,53 +5,59 @@ const gutil = require("gulp-util");
const watch = require("gulp-watch");
const babel = require("gulp-babel");
const webserver = require("gulp-webserver");
var uglify = require("gulp-uglify");
var minifyInline = require("gulp-minify-inline");
var htmlmin = require("gulp-htmlmin");
var inlinesource = require("gulp-inline-source");
const uglify = require("gulp-uglify");
const minifyInline = require("gulp-minify-inline");
const htmlmin = require("gulp-htmlmin");
const inlinesource = require("gulp-inline-source");
const wct = require("web-component-tester");

/// Constants
const tasks = Object.freeze({
devHTML: "compileHTML",
devSrcHTML: "devSrcHTML",
devDemoHTML: "devDemoHTML",
devJS: "compileJS",
devSrcJS: "devSrcJS",
devDemoJS: "devDemoJS",
devDemoJSON: "devDemoJSON",
devDependencies: "devDependencies",
dev: "dev",

buildHTML: "buildHTML",
buildJS: "buildJS",
// Build
compileHtml: "compileHtml",
compileJs: "compileJs",
inline: "inline",

// Minify
minify: "minify",
minifyInline: "minifyInline",
build: "build",

// used to check validity of built version
verifyBuild: "verifyBuild",
verifyDependencies: "verifyDependencies",
verifyDemoHTML: "verifyDemoHTML",
verifyDemoJS: "verifyDemoJS",
verifyDemoJSON: "verifyDemoJSON",
verify: "verify"
// Manual test
copyTestToTest: "copyTestToTest",
copyDependenciesToTest: "copyDependenciesToTest",
copyToTest: "copyToTest",

// Demo
copyToDemo: "copyToDemo",
copyDependenciesToDemo: "copyDependenciesToDemo",
copyDemoToDemo: "copyDemoToDemo",
demo: "demo",

// Tests
manualTest: "manualTest"
});

const paths = Object.freeze({
src: "src/**",
srcHTML: "src/*.html",
srcJS: "src/*.js",
demoHTML: "demo/**/*.html",
demoJS: "demo/**/*.js",
demoJSON: "demo/**/*.json",

dev: "build/dev",
devComponent: "build/dev/" + bowerConfig.name,
devDemo: "build/dev/demo",

build: "build/compile",
builtHTML: "build/compile/*.html",

verifyDemo: "build/verify/demo",
verify: "build/verify"
buildHTML: "build/compile/*.html",
buildFiles: "build/compile/**",

// Manual test files
testSrc: "test/**",
test: "build/test",
testComponent: "build/test/" + bowerConfig.name,
testTest: "build/test/test",

// Demo files
demoSrc: "demo/**",
demo: "build/demo",
demoComponent: "build/demo/" + bowerConfig.name,
demoDemo: "build/demo/demo"
});

/// Helpers
Expand All @@ -60,108 +66,129 @@ function handleError(e) {
this.emit("end");
}

function compileJS(source, dest) {
"use strict";
return gulp.src(source)
/// Demo tasks
gulp.task(tasks.compileJs, () =>
gulp.src(paths.srcJS)
.pipe(babel({
presets: ["es2015"]
}))
.on("error", handleError)
.pipe(gulp.dest(dest));
}

function compileHTML(source, dest) {
"use strict";
return gulp.src(source)
.on("error", handleError)
.pipe(gulp.dest(dest));
}
.pipe(gulp.dest(paths.build))
);

function dependencies(dest) {
"use strict";
return gulp.src("bower_components/**/*")
gulp.task(tasks.compileHtml, () =>
gulp.src(paths.srcHTML)
.on("error", handleError)
.pipe(gulp.dest(dest));
}

/// Dev tasks
gulp.task(tasks.devSrcJS, () => compileJS(paths.srcJS, paths.devComponent));
.pipe(gulp.dest(paths.build))
);

gulp.task(tasks.devDemoJS, () => compileJS(paths.demoJS, paths.devDemo));
gulp.task(tasks.inline, [tasks.compileHtml, tasks.compileJs], () =>
gulp.src(paths.buildHTML)
.pipe(inlinesource())
.pipe(gulp.dest(paths.build))
);

gulp.task(tasks.devDemoJSON, () => gulp.src(paths.demoJSON).pipe(gulp.dest(paths.devDemo)));
gulp.task(tasks.minifyInline, [tasks.inline], () =>
gulp.src(paths.buildHTML)
.pipe(minifyInline())
.pipe(gulp.dest(paths.build))
);

gulp.task(tasks.devSrcHTML, () => compileHTML(paths.srcHTML, paths.devComponent));
gulp.task(tasks.minify, [tasks.minifyInline], () =>
gulp.src(paths.buildHTML)
.pipe(htmlmin({collapseWhitespace: true}))
.pipe(gulp.dest(paths.build))
);

gulp.task(tasks.devDemoHTML, () => compileHTML(paths.demoHTML, paths.devDemo));
gulp.task(tasks.build, [tasks.minify], () =>
gulp.src(paths.buildHTML)
.pipe(gulp.dest("."))
);

gulp.task(tasks.devDependencies, () => dependencies(paths.dev));
// Automatic tests
wct.gulp.init(gulp, [tasks.build]);

gulp.task(tasks.dev, [tasks.devSrcJS, tasks.devDemoJS, tasks.devDemoJSON, tasks.devSrcHTML, tasks.devDemoHTML, tasks.devDependencies], function () {
gulp.watch(paths.demoJS, [tasks.devDemoJS]);
gulp.watch(paths.demoJSON, [tasks.devDemoJSON]);
gulp.watch(paths.srcJS, [tasks.devSrcJS]);
gulp.watch(paths.demoHTML, [tasks.devDemoHTML]);
gulp.watch(paths.srcHTML, [tasks.devSrcHTML]);
// Manual tests
gulp.task(tasks.manualTest, [tasks.build], () => {
gulp.watch(paths.demoJS, [tasks.build]);
gulp.watch(paths.srcJS, [tasks.build]);
gulp.watch(paths.demoHTML, [tasks.build]);
gulp.watch(paths.srcHTML, [tasks.build]);

gulp.src(paths.dev)
gulp.src(".")
.pipe(webserver({
host: "localhost",
port: 8000,
livereload: true,
directoryListing: true,
open: "http://localhost:8000/demo"
open: "http://localhost:8000/test/manual"
}));
});

/// Build tasks
gulp.task(tasks.buildHTML, () =>
gulp.src(paths.srcHTML)
.pipe(minifyInline())
.pipe(htmlmin({collapseWhitespace: true}))
.pipe(gulp.dest(paths.build))
);
// Manual tests
gulp.task(tasks.copyTestToTest, () => {
return gulp.src(paths.testSrc)
.on("error", handleError)
.pipe(gulp.dest(paths.testTest));
});

gulp.task(tasks.buildJS, () =>
gulp.src(paths.srcJS)
.pipe(babel({
presets: ["es2015"]
}))
.pipe(uglify())
.pipe(gulp.dest(paths.build))
gulp.task(tasks.copyDependenciesToTest, () =>
gulp.src("bower_components/**/*")
.on("error", handleError)
.pipe(gulp.dest(paths.test))
);

gulp.task(tasks.inline, [tasks.buildHTML, tasks.buildJS], () =>
gulp.src(paths.builtHTML)
.pipe(inlinesource())
.pipe(gulp.dest(paths.build))
gulp.task(tasks.copyToTest, [tasks.compileHtml, tasks.compileJs], () =>
gulp.src(paths.buildFiles)
.on("error", handleError)
.pipe(gulp.dest(paths.testComponent))
);

gulp.task(tasks.build, [tasks.inline], () =>
gulp.src(paths.builtHTML)
.pipe(gulp.dest("."))
);
gulp.task(tasks.manualTest, [tasks.copyToTest, tasks.copyTestToTest, tasks.copyDependenciesToTest], () => {
const dep = [tasks.copyToTest, tasks.copyTestToTest, tasks.copyDependenciesToTest];
gulp.watch(paths.src, dep);
gulp.watch(paths.testSrc, dep);

gulp.task(tasks.verifyBuild, [tasks.build], () =>
gulp.src("./*.html")
.pipe(gulp.dest("bower_components/" + bowerConfig.name))
);
gulp.src(paths.test)
.pipe(webserver({
host: "localhost",
port: 8000,
livereload: true,
directoryListing: true,
open: "http://localhost:8000/test/manual"
}));
});

gulp.task(tasks.verifyDependencies, [tasks.verifyBuild], () => dependencies(paths.verify));
// Demo
gulp.task(tasks.copyDemoToDemo, () => {
return gulp.src(paths.demoSrc)
.on("error", handleError)
.pipe(gulp.dest(paths.demoDemo));
});

gulp.task(tasks.verifyDemoJS, () => compileJS(paths.demoJS, paths.verifyDemo));
gulp.task(tasks.copyDependenciesToDemo, () =>
gulp.src("bower_components/**/*")
.on("error", handleError)
.pipe(gulp.dest(paths.demo))
);

gulp.task(tasks.verifyDemoJSON, () => gulp.src(paths.demoJSON).pipe(gulp.dest(paths.verifyDemo)));
gulp.task(tasks.copyToDemo, [tasks.build], () =>
gulp.src(paths.buildHTML)
.on("error", handleError)
.pipe(gulp.dest(paths.demoComponent))
);

gulp.task(tasks.verifyDemoHTML, () => compileHTML(paths.demoHTML, paths.verifyDemo));
gulp.task(tasks.demo, [tasks.copyToDemo, tasks.copyDemoToDemo, tasks.copyDependenciesToDemo], () => {
const dep = [tasks.copyToDemo, tasks.copyDemoToDemo, tasks.copyDependenciesToDemo]
gulp.watch(paths.src, dep);
gulp.watch(paths.demoSrc, dep);

gulp.task(tasks.verify, [tasks.verifyDependencies, tasks.verifyDemoJS, tasks.verifyDemoJSON, tasks.verifyDemoHTML], () =>
gulp.src(paths.verify)
gulp.src(paths.demo)
.pipe(webserver({
host: "localhost",
port: 8000,
livereload: false,
livereload: true,
directoryListing: true,
open: "http://localhost:8000/demo"
}))
);
}));
});
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
"gulp-uglify": "^1.5.3",
"gulp-util": "^3.0.7",
"gulp-watch": "^4.3.5",
"gulp-webserver": "^0.9.1"
"gulp-webserver": "^0.9.1",
"web-component-tester": "^4.2.2"
}
}
Loading

0 comments on commit 2443e35

Please sign in to comment.