aboutsummaryrefslogtreecommitdiffstats
path: root/openecomp-ui/tools
diff options
context:
space:
mode:
authorMichael Lando <ml636r@att.com>2017-02-19 12:57:33 +0200
committerMichael Lando <ml636r@att.com>2017-02-19 13:47:13 +0200
commitefa037d34be7b1570efdc767c79fad8d4005f10e (patch)
treecf1036ba2728dea8a61492b678fa91954e629403 /openecomp-ui/tools
parentf5f13c4f6b6fe3b4d98e349dfd7db59339803436 (diff)
Add new code new version
Change-Id: Ic02a76313503b526f17c3df29eb387a29fe6a42a Signed-off-by: Michael Lando <ml636r@att.com>
Diffstat (limited to 'openecomp-ui/tools')
-rw-r--r--openecomp-ui/tools/gulp/deployment/gulpfile.js33
-rw-r--r--openecomp-ui/tools/gulp/deployment/package.json23
-rw-r--r--openecomp-ui/tools/gulp/deployment/tools/gulp/tasks/i18nUpdate.js171
-rw-r--r--openecomp-ui/tools/gulp/tasks/i18n.js115
-rw-r--r--openecomp-ui/tools/gulp/tasks/prod.js100
-rw-r--r--openecomp-ui/tools/webpack/config-json-loader/index.js26
6 files changed, 468 insertions, 0 deletions
diff --git a/openecomp-ui/tools/gulp/deployment/gulpfile.js b/openecomp-ui/tools/gulp/deployment/gulpfile.js
new file mode 100644
index 0000000000..99389108bb
--- /dev/null
+++ b/openecomp-ui/tools/gulp/deployment/gulpfile.js
@@ -0,0 +1,33 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * SDC
+ * ================================================================================
+ * 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.
+ * ============LICENSE_END=========================================================
+ */
+
+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
new file mode 100644
index 0000000000..3bad0374bf
--- /dev/null
+++ b/openecomp-ui/tools/gulp/deployment/package.json
@@ -0,0 +1,23 @@
+{
+ "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": "ECOMP",
+ "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
new file mode 100644
index 0000000000..a3cae5b018
--- /dev/null
+++ b/openecomp-ui/tools/gulp/deployment/tools/gulp/tasks/i18nUpdate.js
@@ -0,0 +1,171 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * SDC
+ * ================================================================================
+ * 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.
+ * ============LICENSE_END=========================================================
+ */
+
+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;
diff --git a/openecomp-ui/tools/gulp/tasks/i18n.js b/openecomp-ui/tools/gulp/tasks/i18n.js
new file mode 100644
index 0000000000..38b2a02dcc
--- /dev/null
+++ b/openecomp-ui/tools/gulp/tasks/i18n.js
@@ -0,0 +1,115 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * SDC
+ * ================================================================================
+ * 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.
+ * ============LICENSE_END=========================================================
+ */
+
+var gulp = require('gulp');
+var fs = require('fs');
+var replace = require('gulp-replace');
+var clean = require('gulp-clean');
+var mkdirp = require('mkdirp');
+
+/**
+ *
+ * @param options.outputPath
+ * @param options.localesPath
+ * @param options.lang = options.lang
+ *
+ * @returns {string}
+ */
+function composeLocalesDirPath(options) {
+ return options.outputPath + options.localesPath + options.lang;
+}
+
+/**
+ *
+ * @param options.outputPath
+ * @param options.localesPath
+ * @param options.lang
+ *
+ * @returns {string}
+ */
+function composeLocaleFilePath(options) {
+ return composeLocalesDirPath(options) + '/locale.json';
+}
+
+
+/**
+ * @param options
+ * @param options.outputPath
+ * @param options.localesPath
+ * @param options.lang = options.lang
+ *
+ */
+function ensureLocalesDir(options) {
+
+ return new Promise(function (resolve, reject) {
+ mkdirp(composeLocalesDirPath(options), function (err) {
+ if (err) {
+ reject(err);
+ }
+ else {
+ resolve();
+ }
+ });
+ });
+
+}
+
+/**
+ *
+ * @param options
+ * @param options.outputPath
+ * @param options.localesPath
+ * @param options.lang = options.lang
+ *
+ */
+function i18nTask(options) {
+
+ var i18nJson = {};
+
+ function addWord(expr) {
+ var word = expr.substring('i18n(\''.length, expr.length - 1);
+ i18nJson[word] = word;
+ return expr;
+ }
+
+ return ensureLocalesDir(options).then(function () {
+ return new Promise(function(resolve, reject) {
+ gulp.src(options.outputPath + '**/*.js', {base: './'})
+ .pipe(replace(/i18n\('.*?'/g, addWord))
+ .pipe(clean())
+ .pipe(gulp.dest('./'))
+ .on('end', function () {
+
+ var i18nJsonWrapper = { dataWrapperArr: ["I18N_IDENTIFIER_START", i18nJson, "I18N_IDENTIFIER_END"] , i18nDataIdx: 1};
+
+ fs.writeFile(composeLocaleFilePath(options), JSON.stringify(i18nJsonWrapper), function (err) {
+ if (err) {
+ reject(err);
+ }
+ else resolve();
+ });
+ }).on('error', function (err) {
+ reject(err);
+ });
+ });
+ });
+}
+
+module.exports = i18nTask;
diff --git a/openecomp-ui/tools/gulp/tasks/prod.js b/openecomp-ui/tools/gulp/tasks/prod.js
new file mode 100644
index 0000000000..d66b841d2a
--- /dev/null
+++ b/openecomp-ui/tools/gulp/tasks/prod.js
@@ -0,0 +1,100 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * SDC
+ * ================================================================================
+ * 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.
+ * ============LICENSE_END=========================================================
+ */
+
+var gulp, replace, Promise, webpack, webpackProductionConfig;
+
+var supportedLanguages = ['en'];
+
+function start(options) {
+
+ var promises = [buildIndex(options)];
+ supportedLanguages.forEach(function (lang) {
+ promises.push(bundleJS(options, lang));
+ });
+ return Promise.all(promises);
+}
+
+function bundleJS(options, lang) {
+ return new Promise(function (resolve, reject) {
+ var prodConfig = webpackProductionConfig;
+ prodConfig.resolve.alias.i18nJson = options.outDir + '/i18n/' + lang + '/locale.json';
+ prodConfig.output.filename = jsFileByLang(options.outFileName, lang);
+ webpack(prodConfig, function (err, stats) {
+ console.log('[webpack:build]', stats.toString());
+ if (err || stats.hasErrors()) {
+ console.log('bundleJS : Failure!!', '\n -language: ', lang);
+ reject(err || stats.toJson().errors);
+ }
+ else {
+ console.log('bundleJS : Done', '\n -language: ', lang);
+ resolve();
+ }
+ });
+ });
+}
+
+function buildIndex(options) {
+
+ return new Promise(function (resolve, reject) {
+
+ var stream = gulp.src(options.outDir + '/index.html');
+
+ stream.pipe(replace(/\/\/<!--prod:delete-->(.|[\r\n])*?<!--\/prod:delete-->/g, ''))//in script occurrences.
+ .pipe(replace(/<!--prod:delete-->(.|[\r\n])*?<!--\/prod:delete-->/g, ''))//out of script occurrences.
+ .pipe(replace(/<!--prod:add(-->)?/g, ''))
+ .pipe(replace(/\/\/<!--prod:supported-langs-->(.|[\r\n])*?<!--\/prod:supported-langs-->/g, supportedLanguages.map(function (val) {
+ return "'" + val + "'";
+ }).toString()))
+ .pipe(gulp.dest(options.outDir))
+ .on('end', function () {
+ console.log('buildIndex : Done');
+ resolve();
+ })
+ .on('error', function (e) {
+ console.log('buildIndex : Failure!!');
+ reject(e);
+ });
+ });
+
+}
+
+function jsFileByLang(fileName, lang) {
+ return fileName.replace(/.js$/, '_' + lang + '.js');
+}
+
+/**
+ * @param options
+ * @param options.outFileName optional <default build>
+ */
+function prodTask(options) {
+
+ gulp = require('gulp');
+ replace = require('gulp-replace');
+ Promise = require('bluebird');
+ webpack = require('webpack');
+ webpackProductionConfig = options.webpackProductionConfig;
+
+ return start({
+ outFileName: options.outFileName || '[name].js',
+ outDir: options.outDir
+ });
+}
+
+module.exports = prodTask;
diff --git a/openecomp-ui/tools/webpack/config-json-loader/index.js b/openecomp-ui/tools/webpack/config-json-loader/index.js
new file mode 100644
index 0000000000..bf34533f67
--- /dev/null
+++ b/openecomp-ui/tools/webpack/config-json-loader/index.js
@@ -0,0 +1,26 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * SDC
+ * ================================================================================
+ * 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.
+ * ============LICENSE_END=========================================================
+ */
+
+module.exports = function(content) {
+ var config = JSON.parse(content);
+ var build = process.env.BUILD_NUMBER || '0';
+ config.build = build;
+ return JSON.stringify(config);
+};