2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
6 * ================================================================================
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
18 * ============LICENSE_END=========================================================
21 var gulp = require('gulp');
22 var fs = require('fs');
23 var replace = require('gulp-replace');
24 var clean = require('gulp-clean');
25 var mkdirp = require('mkdirp');
29 * @param options.outputPath
30 * @param options.localesPath
31 * @param options.lang = options.lang
35 function composeLocalesDirPath(options) {
36 return options.outputPath + options.localesPath + options.lang;
41 * @param options.outputPath
42 * @param options.localesPath
47 function composeLocaleFilePath(options) {
48 return composeLocalesDirPath(options) + '/locale.json';
54 * @param options.outputPath
55 * @param options.localesPath
56 * @param options.lang = options.lang
59 function ensureLocalesDir(options) {
61 return new Promise(function (resolve, reject) {
62 mkdirp(composeLocalesDirPath(options), function (err) {
77 * @param options.outputPath
78 * @param options.localesPath
79 * @param options.lang = options.lang
82 function i18nTask(options) {
86 function addWord(expr) {
87 var word = expr.substring('i18n(\''.length, expr.length - 1);
88 i18nJson[word] = word;
92 return ensureLocalesDir(options).then(function () {
93 return new Promise(function(resolve, reject) {
94 gulp.src(options.outputPath + '**/*.js', {base: './'})
95 .pipe(replace(/i18n\('.*?'/g, addWord))
97 .pipe(gulp.dest('./'))
98 .on('end', function () {
100 var i18nJsonWrapper = { dataWrapperArr: ["I18N_IDENTIFIER_START", i18nJson, "I18N_IDENTIFIER_END"] , i18nDataIdx: 1};
102 fs.writeFile(composeLocaleFilePath(options), JSON.stringify(i18nJsonWrapper), function (err) {
108 }).on('error', function (err) {
115 module.exports = i18nTask;