Skip to content

Commit

Permalink
Merge pull request #2102 from sjiang-cb/g11n-js-client
Browse files Browse the repository at this point in the history
[JSCLient]Improve CLI Script on adding encoding source string feature.
  • Loading branch information
sjiang-cb authored Mar 20, 2023
2 parents 9f304f8 + ea4d481 commit f051dbb
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 60 deletions.
35 changes: 31 additions & 4 deletions cli/collect-source-bundle.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#!/usr/bin/env node

/*
* Copyright 2019-2022 VMware, Inc.
* Copyright 2019-2023 VMware, Inc.
* SPDX-License-Identifier: EPL-2.0
*/

Expand All @@ -13,14 +13,15 @@ const ts = require('typescript');
const ArgumentParser = require('argparse').ArgumentParser;

class CollectSourceBundle {
constructor(logger, vipService, vipConfig) {
constructor(logger, vipService, vipConfig, cliOptions) {
this.logger = logger;
this.vipService = vipService;
this.vipConfig = vipConfig;
this.progress = {
total: 0,
current: []
};
this.cliOptions = cliOptions;
}
isSourceBundle(file) {
return file.match(/l10n\.(ts|js)$/);
Expand All @@ -30,16 +31,25 @@ class CollectSourceBundle {
return this.vipService.collectSources(sourceSet);
}
convertDataForVIP(data) {
const isEncode = this.cliOptions.encode ? true : false;
const sourceFormat = isEncode ? this.cliOptions.encode + ",STRING" : "STRING";
var sourceSet = [];
for (let i in data) {
const source = isEncode ? this.encodeString(data[i]) : data[i];
sourceSet.push({
commentForSource: '',
key: i,
source: data[i]
source,
sourceFormat,
});
}
return sourceSet;
}
encodeString(str) {
var buff = Buffer.from(str);
var res = buff.toString(this.cliOptions.encode);
return res;
}
throttleCollectSources(dataObject, stepSize, file) {
var data = this.convertDataForVIP(dataObject);
if (data.length === 0) {
Expand Down Expand Up @@ -141,6 +151,14 @@ function run() {
}
);

parser.addArgument(
['--encode'],
{
help: 'Encode the resource.',
required: false,
}
);

parser.addArgument(
['--moduletype'],
{
Expand All @@ -163,7 +181,16 @@ function run() {
try {
let vipConfig = new VIPConfig(args.host, args.product, args.version, args.component);
let vipService = new VIPService(vipConfig, logger, null);
let collectSourceBundle = new CollectSourceBundle(logger, vipService, vipConfig);
let encode = args.encode && args.encode.toUpperCase();
if (encode && encode !== "BASE64") {
logger.error("The encoding type '" + encode + "' is not supported.");
return;
}
const cliOptions = {
encode: encode,
};

let collectSourceBundle = new CollectSourceBundle(logger, vipService, vipConfig, cliOptions);
walkDirectory(args.source_dir, function (files) {
logger.debug('walkDirectory resolve files', files);
files.forEach(function (file) {
Expand Down
54 changes: 0 additions & 54 deletions cli/translation-service.js

This file was deleted.

11 changes: 10 additions & 1 deletion package.client.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@vip/vip-core-sdk",
"version": "0.5.5",
"version": "0.5.6",
"publishConfig": {
"registry": ""
},
Expand Down Expand Up @@ -54,6 +54,15 @@
"webpack-cli": "^3.3.0"
},
"changelogHistory": [
{
"date": "02/22/23",
"version": "0.5.6",
"notes": [
{
"description": "Improve CLI Script on adding encoding source string feature."
}
]
},
{
"date": "08/30/22",
"version": "0.5.5",
Expand Down
11 changes: 10 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@vip/vip-core-sdk-server",
"version": "0.5.5",
"version": "0.5.6",
"publishConfig": {
"registry": ""
},
Expand Down Expand Up @@ -54,6 +54,15 @@
"webpack-cli": "^3.3.0"
},
"changelogHistory": [
{
"date": "02/22/23",
"version": "0.5.6",
"notes": [
{
"description": "Improve CLI Script on adding encoding source string feature."
}
]
},
{
"date": "08/30/22",
"version": "0.5.5",
Expand Down

0 comments on commit f051dbb

Please sign in to comment.