diff options
Diffstat (limited to 'openecomp-ui/tools/gulp/deployment')
-rw-r--r-- | openecomp-ui/tools/gulp/deployment/gulpfile.js | 28 | ||||
-rw-r--r-- | openecomp-ui/tools/gulp/deployment/package.json | 23 | ||||
-rw-r--r-- | openecomp-ui/tools/gulp/deployment/tools/gulp/tasks/i18nUpdate.js | 166 |
3 files changed, 0 insertions, 217 deletions
diff --git a/openecomp-ui/tools/gulp/deployment/gulpfile.js b/openecomp-ui/tools/gulp/deployment/gulpfile.js deleted file mode 100644 index bf127e6d19..0000000000 --- a/openecomp-ui/tools/gulp/deployment/gulpfile.js +++ /dev/null @@ -1,28 +0,0 @@ -/*! - * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express - * or implied. See the License for the specific language governing - * permissions and limitations under the License. - */ -var gulp = require('gulp'); -var i18nUpdateTask = require('./tools/gulp/tasks/i18nUpdate'); - -gulp.task('i18nUpdate', function() { - - return i18nUpdateTask({ - warDir: process.cwd(), - lang: 'en' - }); -}); - -gulp.task('default', ['i18nUpdate']); - diff --git a/openecomp-ui/tools/gulp/deployment/package.json b/openecomp-ui/tools/gulp/deployment/package.json deleted file mode 100644 index 5f049057fc..0000000000 --- a/openecomp-ui/tools/gulp/deployment/package.json +++ /dev/null @@ -1,23 +0,0 @@ -{ - "name": "sdc-client-tools", - "version": "9.3.0", - "description": "Service Designer & Catalog Client Tools", - "dependencies": {}, - "devDependencies": { - "bluebird": "^2.10.1", - "gulp": "^3.9.0", - "gulp-rename": "^1.2.2", - "gulp-replace": "^0.5.4", - "prompt": "^0.2.14" - }, - "author": "OPENECOMP", - "license": "LicenseRef-LICENSE", - "scripts": { - "start": "gulp run", - "test": "echo \"Error: no test specified\" && exit 1" - }, - "engines": { - "node": ">=0.12.7", - "npm": ">=2.11.3" - } -} diff --git a/openecomp-ui/tools/gulp/deployment/tools/gulp/tasks/i18nUpdate.js b/openecomp-ui/tools/gulp/deployment/tools/gulp/tasks/i18nUpdate.js deleted file mode 100644 index d35ae2dafc..0000000000 --- a/openecomp-ui/tools/gulp/deployment/tools/gulp/tasks/i18nUpdate.js +++ /dev/null @@ -1,166 +0,0 @@ -/*! - * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express - * or implied. See the License for the specific language governing - * permissions and limitations under the License. - */ -var gulp, replace, rename, fs, prompt, Promise; - -function mergePromptOptions(options) { - - return new Promise(function(resolve, reject) { - var lang = options.lang; - var warDir = options.warDir; - prompt.start(); - prompt.get([ - { - description: 'Enter war directory', - default: warDir, - name: 'warDir' - }, - { - description: 'Enter locale.json parent directory name', - default: lang, - name: 'lang' - } - ], function (err, result) { - - if(err) { - reject(new Error('mergePromptOptions::>\n ' + err)); - return; - } - - var warDir = result.warDir; - var lang = result.lang; - - console.log('\nlocale.json parent directory name> "' + lang + '"'); - console.log('war director>"' + warDir + '"'); - - resolve({ - warDir: warDir, - lang: lang - }); - }); - }); -} - -function isBundleExists(path) { - return new Promise(function(resolve) { - fs.stat(path, function(err) { - resolve(null == err); - /*if null == err then file exists.*/ - }); - }); -} - -function copyEnglishBundle(enBundlePath, lang) { - return new Promise(function(resolve, reject) { - gulp.src(enBundlePath, {base: './'}) - .pipe(rename({basename: 'bundle_' + lang})) - .pipe(gulp.dest('./')) - .on('end', function() { - resolve(); - }) - .on('error', function(err) { - reject(new Error('copyEnglishBundle::>\n ' + err)); - }); - }); -} - -function getLocaleContent(localePath) { - - return new Promise(function(resolve, reject) { - fs.readFile(localePath, {encoding: 'utf-8'}, function(err,data){ - if(err) { - reject('getLocaleContent()::>\n ' + err); - return; - } - resolve(data); - }); - }); - -} - -function extractLocaleJsonContent(localeDataStr) { - - var localeJsonStrI18nStartIdx = localeDataStr.indexOf('I18N_IDENTIFIER_START'); - var localeJsonStrI18nEndIdx = localeDataStr.indexOf('I18N_IDENTIFIER_END'); - - if(-1 === localeJsonStrI18nStartIdx || -1 === localeJsonStrI18nEndIdx) { - return Promise.reject(new Error('extractLocaleJsonContent::> localeDataStr must contain %I18N_IDENTIFIER_START% and %I18N_IDENTIFIER_END%')); - } - - var localeJsonStr = localeDataStr.substring( - localeDataStr.indexOf('{', localeJsonStrI18nStartIdx), - localeDataStr.lastIndexOf('}', localeJsonStrI18nEndIdx) + 1 - ); - - try { - JSON.parse(localeJsonStr); - } catch(e) { - return Promise.reject(new Error('extractLocaleJsonContent::> localeDataStr must contain a valid json between %I18N_IDENTIFIER_START% and %I18N_IDENTIFIER_END%=>' + e)); - } - - return Promise.resolve(localeJsonStr); -} - -function setBundleLocaleContent(bundlePath, localeJsonStr) { - return new Promise(function(resolve, reject) { - gulp.src(bundlePath, {base: './'}) - .pipe(replace(/I18N_IDENTIFIER_START(.|[\r\n])*?I18N_IDENTIFIER_END/i, function(expr) { - return expr.substring(0, expr.indexOf('{')) + localeJsonStr + expr.substring(expr.lastIndexOf('}') + 1); - })) - .pipe(gulp.dest('./')) - .on('end', function() { - resolve(); - }) - .on('error', function(err) { - reject(new Error('setBundleLocaleContent::>\n ' + err)); - }); - }); -} - - -function update(options) { - - gulp = require('gulp'); - replace = require('gulp-replace'); - rename = require('gulp-rename'); - fs = require('fs'); - prompt = require('prompt'); - Promise = require('bluebird'); - - return mergePromptOptions(options).then(function(mergedOptions) { - var lang = mergedOptions.lang; - var warDir = mergedOptions.warDir; - - var bundlePath = warDir + '/js/bundle_' + lang + '.js'; - var localePath = warDir + '/i18n/' + lang + '/locale.json'; - - return isBundleExists(bundlePath) - .then(function(isBundleExist) { - var englishBundlePath; - if(!isBundleExist) { - englishBundlePath = warDir + '/js/bundle_en.js'; - return copyEnglishBundle(englishBundlePath, lang); - } - }) - .then(getLocaleContent.bind(null, localePath)) - .then(extractLocaleJsonContent) - .then(setBundleLocaleContent.bind(null, bundlePath)); - }); - -} - - - -module.exports = update;
\ No newline at end of file |